[Maxima] Small improvement of algsys
drdieterkaiser at web.de
Sun Jan 18 07:17:51 CST 2009
I had a look at algsys because of Lisp Errors for some problems. The
related bug reports are SF, SF and SF. In all
cases the routine PUNIVARP is called with the number ZERO which causes
the Lisp Error. A simple change to prevent the Lisp Error would be to
add a check to the routine PUNIVARP:
(defun punivarp (poly)
;; Check if called with the number zero, return nil.
;; Related bugs: SF, SF, SF
(when (and (numberp poly) (= poly 0)) (return-from punivarp nil))
(do ((l (cdr poly) (cddr l)))
((null l) t)
(or (numberp (cadr l))
(and (eq (caadr l) *ivar*)
(punivarp (cadr l)))
With this change to PUNIVARP the algorithm returns the message:
`algsys' cannot solve - system too complicated.
-- an error. To debug this try debugmode(true);
This change does not improve algsys to get more solutions. The problem
is that the algorithm of algsys does not always do the best substitution
of the parameters.
This can be improved switching the flag $algebraic on. If we set in
addition $algebraic to TRUE in the function $algsys we get more
solutions. This are the examples already shown in the bug reports which
will give the following solutions:
(%o10) [[a = %r57,b = -(sqrt(2-3*%r57^2)+%r57)/2,
c = (sqrt(2-3*%r57^2)-%r57)/2],
[a = %r58,b = (sqrt(2-3*%r58^2)-%r58)/2,
c = -(sqrt(2-3*%r58^2)+%r58)/2]]
(%o11) [[a = -sqrt(%r59*%r60),b = %r59,c = %r60,
d = sqrt(%r59)*sqrt(%r60)],
[a = sqrt(%r61*%r62),b = %r61,c = %r62,
d = -sqrt(%r61)*sqrt(%r62)]]
(%o12) [[a = -(sqrt(1-4*%r63*%r64)-1)/2,b = %r63,c = %r64,
d = (sqrt(1-4*%r63*%r64)+1)/2],
[a = (sqrt(1-4*%r65*%r66)+1)/2,b = %r65,c = %r66,
d = -(sqrt(1-4*%r65*%r66)-1)/2],[a = 0,b = %r67,c = 0,d = 1],
[a = 1,b = %r68,c = 0,d = 0],[a = 1,b = 0,c = 0,d = 1],
[a = 0,b = 0,c = 0,d = 0]]
The testsuite will have no problems. Two results are mathematically
equivalent, but look a bit different.
These are the two options I would like to suggest to close the bug
1. Add a test to punivarp to prevent a fatal Lisp error.
2. Setting the flag $algebraic to TRUE in the routine $algsys.
What do you think. Should we do both changes or only the first one, to
prevent the fatal Lisp error.
More information about the Maxima