Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

## #124 Fatal error in solve/algsys

closed
nobody
5
2009-01-25
2002-09-15
Stavros Macrakis
No

solve(
[ a^2+b^2+c^2-1,
c*f+b*d+a*b,
c*g+b*f+a*c,
c*f+b*d+a*b,
b^2+d^2+f^2-1,
f*g+d*f+b*c,
c*g+b*f+a*c,
f*g+d*f+b*c,
g^2+f^2+c^2-1],
[a,b,c,d,f,g])

gives &quot;Caught fatal error&quot;.

## Discussion

• Logged In: YES
user_id=588346

A simpler fatal error.

solve([a+b+c=0,a^2+b^2+c^2=1],[a,b,c])

• Robert Dodier
2006-06-26

Logged In: YES
user_id=501686

Observed in 5.9.3.

• Robert Dodier
2006-06-26

• labels: --> 460522

• Robert Dodier
2006-08-27

• labels: 460522 --> Lisp Core - Solving equations

• Barton Willis
2006-09-10

Logged In: YES
user_id=895922

These errors don't happen if algebraic == true. We could
locally set algebraic to true in solve / algsys, but I doubt
that fix the real bug.

• Logged In: YES
user_id=588346
Originator: YES

An even simpler fatal error:

solve([a*d+b*c,a+d],[a,b,c,d]) => Fatal error

solve([a*d+b*c,a+d],[a,b,c,d]), algebraic => OK

(in 5.13.0)

• Dieter Kaiser
2009-01-02

This is going on in algsys for the given example (I have added debugging code):

(%i17) algebraic:false\$

(%i18) solve([a*d+b*c,a+d],[a,b,c,d]);

/* The first equation: Maxima gets two solutions */
2
in CALLSOLVE: call solve with a - c b
and var = a
: roots =
(((MEQUAL SIMP) \$A
((MTIMES SIMP RATSIMP) -1
((MEXPT SIMP) ((MTIMES SIMP) \$B \$C) ((RAT SIMP) 1 2))))
1 ((MEQUAL SIMP) \$A ((MEXPT SIMP) ((MTIMES SIMP) \$B \$C) ((RAT SIMP) 1 2))) 1)
: fail = NIL

/* This is the second equation. This simplifies to 0. Maxima does not
find roots. */
2 2
in CALLSOLVE: call solve with c b - sqrt(b) sqrt(c)
and var = b
: roots = NIL
: fail = (((MEQUAL SIMP) \$B \$B) 1)
: q = ((MEQUAL SIMP) \$B \$B)
: = 0

/* Solve has not found roots, the algorithm now calls the routine
CALLAPPRS with a zero argument. This zero argument is passed to the
function PUNIVARP which generates a fatal error, because it can
handle only lists (Here the code is corrected.) */

CALLAPPRS with 0
`algsys' cannot solve - system too complicated.
-- an error. To debug this try debugmode(true);

This is the same example with the algebraic flag enabled:

(%i19) algebraic:true;
(%o19) true
(%i20) solve([a*d+b*c,a+d],[a,b,c,d]);
2
in CALLSOLVE: call solve with a - c b
and var = a
: roots =
(((MEQUAL SIMP) \$A
((MTIMES SIMP RATSIMP) -1
((MEXPT SIMP) ((MTIMES SIMP) \$B \$C) ((RAT SIMP) 1 2))))
1 ((MEQUAL SIMP) \$A ((MEXPT SIMP) ((MTIMES SIMP) \$B \$C) ((RAT SIMP) 1 2))) 1)
: fail = NIL

/* Now Maxima take another equation and find more solutions */

in CALLSOLVE: call solve with d + sqrt(b) sqrt(c)
and var = d
: roots =
(((MEQUAL SIMP) \$D
((MTIMES SIMP RATSIMP) -1 ((MEXPT SIMP) \$B ((RAT SIMP) 1 2))
((MEXPT SIMP) \$C ((RAT SIMP) 1 2))))
1)
: fail = NIL

/* Maxima calls again with the second root from the first equation */

in CALLSOLVE: call solve with d - sqrt(b) sqrt(c)
and var = d
: roots =
(((MEQUAL SIMP) \$D
((MTIMES SIMP RATSIMP) ((MEXPT SIMP) \$B ((RAT SIMP) 1 2))
((MEXPT SIMP) \$C ((RAT SIMP) 1 2))))
1)
: fail = NIL

(%o20) [[a = - sqrt(%r12 %r13), b = %r12, c = %r13,
d = sqrt(%r12) sqrt(%r13)], [a = sqrt(%r14 %r15), b = %r14, c = %r15,
d = - sqrt(%r14) sqrt(%r15)]]

I have not tried to improve the algorithm, but to understand what is going on.

We have two possibilities to correct the Lisp error:

(1) Do not call PUNIVARP with a zero argument:

(or (and (numberp poly) (= poly 0)) ; Check zero argument
(punivarp poly)
(merror "`algsys' cannot solve - system too complicated."))

With this correction the algorithm goes on. The result would be an empty list.

(2) Add a test to the routine PUNIVARP:

(defun punivarp (poly)
;; Test if called with the number zero, return NIL
(when (and (numberp poly) (= poly 0)) (return-from punivarp nil))

The example above is shown with this correction. ALGSYS returns with an error and displays: `algsys' cannot solve - system too complicated. Perhaps we can add a message like "Try again with algebraic:true". PUNIVARP is only called within the file algsys.lisp. Thus no other code depends directly on a change of PUNIVARP.

The testsuite has no problems with both solutions.

I think I would prefer the second solution to avoid the Lisp Error. It is not very nice to get the error message for simple equations, but perhaps we can improve the algorithm of algsys later.

The following two bugs report the same problem:
SF[1663399 ] solve/algsys bug
SF[1430379 ] algsys & algebraic == true / FIX

Should we correct the Lisp Error and close the related bug reports?

Dieter Kaiser

• Dieter Kaiser
2009-01-25

• status: open --> closed

• Dieter Kaiser
2009-01-25

The suggested check for a number zero in a call to punivarp has been checked in.
Maxima no longer gets a fatal Lisp error for the examples given in this bug report, but returns an error message:

`algsys' cannot solve - system too complicated.
-- an error. To debug this try debugmode(true);

As further suggested algsys can find more solutions when the flag \$algebraic is TRUE.

Closing this bug report, because the initial Lisp error has been fixed.