Bug in mring.lisp? was: Need help with Maxima (please help)
Subject: Bug in mring.lisp? was: Need help with Maxima (please help)
From: Barton Willis
Date: Tue, 27 Apr 2010 12:17:31 -0500
Leo,
Thanks for the patch--it looks fine. I can't test it right now, but please
go ahead an commit it
(assuming the share testsuite shows no new bugs.)
And thanks for asking before committing.
--Barton
Leo Butler <l.butler at ed.ac.uk> wrote on 04/27/2010 09:50:33 AM:
> [image removed]
>
> Bug in mring.lisp? was: Need help with Maxima (please help)
>
> Leo Butler
>
> to:
>
> Barton Willis
>
> 04/27/2010 09:56 AM
>
> Cc:
>
> "'Maxima List'"
>
>
>
> On Tue, 27 Apr 2010, Sheldon Newhouse wrote:
>
> I tried to do the problem
> <
> <
"diff(arccos(x^2+8.363+267)/(sqrt(x^2-4.29x+1042)(x^2+12.8102x+1177))),
x);"
> <
> <
> < in Maple with the correct version of parentheses, etc. It computed the
> < derivative fine (as maxima does), but it failed to find the zero.
>
> I believe that there is a bug in the present mring.lisp which prevents
> this probblem, and similar ones, from being solved by mnewton. The basic
> problem is that in trying to create CL complex numbers from a Maxima
> expression, float is being called too late. I include the patch below.
>
> (%i1) load(mnewton)$
> (%i2) f:diff(acos(x^2+8.363+267)/(sqrt(x^2-4.29*x+1042)*(x^2+12.
> 8102*x+1177)),x)$
> (%i3) mnewton(f,x,-5.0);
>
> Unable to convert
> %i*(2.9524823745650125e-8*sin(1.5*%pi)+1.7009864675953376e-7*sin(0.
> 5*%pi)-4.375144669837393e-7)-2.9524823745650125e-8*cos(1.5*%pi)
> %to a complex long fl\
> oat
> #0:
> solve_by_lu(eqs=[(-4.375144669837393e-7*%i-1.7009864675953376e-7/
> (-1)^0.5-2.9524823745650125e-8/(-1)^1.5)*h[1]+6.978...,vars=[h
> [1]],field=complexfield)
> #1:
> mnewton(funclist=-(2*x-4.29)*acos(x^2+275.363)/(2*(x^2-4.29*x+1042)^
> (3/2)*(x^2+12.8102*x+1177))-(2*x+12.8102)*acos
> (x^...,varlist=x,guesslist=-5.0)(mnewton.mac
> line 1\
> 13)
> -- an error. To debug this try: debugmode(true);
> (%i4)
load("/home/work/maxima/sandbox/maxima/share/linearalgebra/mring.lisp")$
> (%i5) mnewton(f,x,-5.0);
> (%o5) [[x = 2.013631497110261e-16*%i-5.626466372928149]]
>
> Here is the patch which does the trick
>
> Index: mring.lisp
> ===================================================================
> RCS file: /cvsroot/maxima/maxima/share/linearalgebra/mring.lisp,v
> retrieving revision 1.24
> diff -u -r1.24 mring.lisp
> --- mring.lisp 14 Feb 2008 01:31:37 -0000 1.24
> +++ mring.lisp 27 Apr 2010 14:44:58 -0000
> @@ -114,10 +114,10 @@
> :mring-to-maxima #'(lambda (s) (add (realpart s) (mult '$%i
> (imagpart s)))) ;; was complexify
> :maxima-to-mring #'(lambda (s)
> (progn
> - (setq s ($rectform (meval s)))
> + (setq s ($float ($rectform (meval s))))
> (if (complex-number-p s 'float-or-rational-p)
> - (complex ($float ($realpart s)) ($float
> ($imagpart s)))
> - (merror "Unable to convert ~:M to a complex
> long float" s))))))
> + (complex ($realpart s) ($imagpart s))
> + (merror "Unable to convert ~:M to a
> complex long float" s))))))
>
>
> --
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>