accessing GMP, MPFR, was Re: generating C or Java,
Subject: accessing GMP, MPFR, was Re: generating C or Java,
From: Richard Fateman
Date: Thu, 10 Feb 2011 06:41:57 -0800
On 2/10/2011 5:02 AM, Leo T Butler wrote:
...
>
> Jon Wilkening at Berkeley has written a nice C++ wrapper around GMP,
> so that the code can look quite natural unlike C code using GMP.
>
> http://math.berkeley.edu/~wilken/code/gmpfrxx/
>
...
This might be useful, but I will mention once again, the possibility of
just using lisp.
Loading in the generic arithmetic package (which could be loaded into
Maxima,
though not the GCL/Windows version), and loading the appropriate mpfr.dll ,
one can do this in Lisp...
(use-package :mpfr)
(set-prec 100)
(setf r (into 1/3))
3.3333333333333333333333333333346^-1 ; I've
indented the output
(+ r r r)
1.
(sin r)
3.2719469679615224417334408526792^-1 ; yes, sine,
etc is there.
etc.
That is, the "wrapping" is done rather completely. The cost of calling
mpfr from lisp is a small percentage of the cost of the mpfr calculation
itself.
If there is considerable "other" code written in Java or C, then this is
not a good idea. If, however, most of the code is being "automatically
generated" then this might be quite feasible. In case you haven't
encountered it, Lisp has features like
(loop for i from 1 to n do (print (* i i))
and arrays etc. Though the array referencing and setting code looks like
(setf (aref b i) (+ (aref c j)(aref c k)))
this can be easily covered over by writing a few macros; if everything
is properly declared, it should be not much different from Fortran or C
in speed.
I'm not saying this would be trivial for you to do; I don't know enough
about your calculation and your environment, and obviously you'd
need to learn more about lisps and find a suitable one for your
setup.
I'm guessing you really want bigfloats (MPFR), but if you want
integers (GMP) , that's written out, too, since the lisp I was using
has its own different bignum integer package. Some lisps already use GMP
and you need to do nothing special to access them.
RJF