I thought this was fun; maybe it is useful too.
tocl (share/contrib/tocl.lisp) is a Maxima to Common Lisp
translator. By changing symbol properties for mtimes, mplus, ..., tocl
will generate code appropriate for the bigfloat package. An example:
the trapezoid rule using rational, binary64, and bigfloat numbers
(%i4) trap_bigfloat(lambda([x], 1/x),1,2,10);
(%o4) 161504821/232792560
(%i5) trap_bigfloat(lambda([x], asin(x)),1,2,100);
(%o5) 1.570796326794894-0.90157583206333*%i
(%i6) trap_bigfloat(lambda([x], asin(x)),1.0b0,2,100),fpprec : 42;
(%o6) 1.57079632679489661892515999185291314779206b0-9.01575832063334506308235596167851968757257b-1*%i
The file trap.lisp (mostly untested):
(in-package :maxima)
($load "tocl")
(setf (get '%asin 'cl-function) 'bigfloat::asin)
(setf (get '%acos 'cl-function) 'bigfloat::acos)
(setf (get '%cos 'cl-function) 'bigfloat::cos)
(setf (get '%sin 'cl-function) 'bigfloat::sin)
(setf (get 'mplus 'cl-function) 'bigfloat::+)
(setf (get 'mminus 'cl-function) 'bigfloat::-)
(setf (get 'mtimes 'cl-function) 'bigfloat::*)
(setf (get 'mquotient 'cl-function) 'bigfloat::/)
(setf (get 'mexpt 'cl-function) 'bigfloat::expt)
(defun $trap_bigfloat (f a b n)
(maxima::to (bigfloat::trap-bigfloat (expr-to-cl f) (bigfloat::to a) (bigfloat::to b) (bigfloat::to n))))
(in-package #-gcl #:bigfloat #+gcl "BIGFLOAT")
(defun trap-bigfloat (f a b n)
(let ((s (/ (+ (funcall f a) (funcall f b)) 2)) (h (/ (- b a) n)))
(do ((k 1 (+ k 1))) ((>= k n) (* h s))
(setq s (+ s (funcall f (+ a (* h k))))))))
(in-package :maxima)
--Barton