"Simpler" bigfloat and complex bigfloat arithmetic
Subject: "Simpler" bigfloat and complex bigfloat arithmetic
From: Raymond Toy
Date: Fri, 02 Jan 2009 11:56:59 -0500
I think a long time ago, I talked with Barton about this, and have now
finally gotten a round to implementing it.
I've written a set of CLOS classes to make working with bigfloat and
complex bigfloat numbers easier. It's a new package "NUMERIC" where the
standard Lisp operations have been shadowed to work with a new bigfloat
and complex-bigfloat numbers.
The source is available at http://common-lisp.net/~rtoy/numeric.lisp.
If you want to try it you'll need to modify maxima-package.lisp and
maxima.system a bit. Instructions included in numeric.lisp.
Here's a quick example what you can do:
:lisp (numeric:sqrt (numeric:bigfloat -8))
0.0b0 + %i* 2.82842712474619b0
(numeric:bigfloat converts a float or integer to a bigfloat object)
Here is the ascending-transform from ellipt.lisp, for double-floats:
(defun ascending-transform (u m)
(let* ((root-m (cl:sqrt m))
(mu (/ (* 4 root-m)
(cl:expt (1+ root-m) 2)))
(root-mu1 (/ (- 1 root-m) (+ 1 root-m)))
(v (/ u (1+ root-mu1))))
(values v mu root-mu1)))
The equivalent that would for double-floats, bigfloats, or
complex-bigfloats is:
(defun ascending-transform (u m)
(let* ((root-m (numeric:sqrt m))
(mu (numeric:/ (numeric:* 4 root-m)
(numeric:expt (numeric:1+ root-m) 2)))
(root-mu1 (numeric:/ (numeric:- 1 root-m) (numeric:+ 1 root-m)))
(v (numeric:/ u (numeric:1+ root-mu1))))
(values v mu root-mu1)))
Of course, if you really needed max speed with just double-float, you
need to write a special version for that, but at least this package
makes it easy to write one version that will handle double-float,
bigfloat or complex bigfloats.
If people find this useful, perhaps it can be added to maxima.
The routines still need some work, and not all corresponding Lisp
arithmetic functions have been implemented yet. One side benefit is
that the bigfloat operations have been abstracted out, so we can easily
replace Maxima's current bigfloat implementation with a different
implementation like GMP or MPFR.
Ray