solve bug
- Subject: solve bug
- From: Richard Fateman
- Date: Sun, 14 Oct 2001 09:24:31 -0700
The correct input and output from simpnrt and solvequad
from commercial Macsyma...
I am not at a machine with Maxima installed, but going
into lisp maybe by to_lisp()
and typing (trace solvequad simpnrt)
should get you similar results.
1 Enter SOLVEQUAD (G24 2 (G25 2 1 0 1) 1 (G25 1 1) 0 (G25 1 1))
;;note: G24 is a synonym for x; G25 for a. This is
;;the internal polynomial form for (x^2)*(1*a^2+1*a^0) + (x^1)*(1*a^1)
;;+(x^0)*(1*a^1).
| 1 Enter SIMPNRT ((MPLUS SIMP) ((MTIMES SIMP RATSIMP) -4 $A) ((MEXPT
SIMP RATSIMP) $A 2) ((MTIMES SIMP) -4 ((MEXPT SIMP RATSIMP) $A 3))) 2
;; the input is -4a+a^2-4a^3 ... we want the 1/2th root of this,
simplified.
| 1 Exit SIMPNRT (((MTIMES SIMP) ((MEXPT SIMP) ((MTIMES SIMP) -1 $A)
((RAT SIMP) 1 2)) ((MEXPT SIMP) ((MPLUS SIMP) 4 ((MTIMES SIMP RATSIMP)
-1 $A) ((MTIMES SIMP) 4 ((MEXPT SIMP RATSIMP) $A 2))) ((RAT SIMP) 1 2)))
;; (-a)^(1/2) * (4 +(-a)+4*a^2)^(1/2)
1 Exit SOLVEQUAD (((MEQUAL SIMP) $X ((MTIMES SIMP) -1 ((MEXPT SIMP)
((MPLUS SIMP) 2 ((MTIMES SIMP) 2 ((MEXPT SIMP RATSIMP) $A 2))) -1)
((MPLUS SIMP) $A ((MTIMES SIMP RATSIMP) ((MEXPT SIMP) ((MTIMES SIMP
RATSIMP) -1 $A) ((RAT SIMP) 1 2)) ((MEXPT SIMP) ((MPLUS SIMP) 4 ((MTIMES
SIMP RATSIMP) -1 $A) ((MTIMES SIMP) 4 ((MEXPT SIMP RATSIMP) $A 2)))
((RAT SIMP) 1 2)))))) 1 ((MEQUAL SIMP) $X ((MTIMES SIMP) ((MEXPT SIMP)
((MPLUS SIMP) 2 ((MTIMES SIMP) 2 ((MEXPT SIMP RATSIMP) $A 2))) -1)
((MPLUS SIMP) ((MTIMES SIMP RATSIMP) -1 $A) ((MTIMES SIMP RATSIMP)
((MEXPT SIMP) ((MTIMES SIMP RATSIMP) -1 $A) ((RAT SIMP) 1 2)) ((MEXPT
SIMP) ((MPLUS SIMP) 4 ((MTIMES SIMP RATSIMP) -1 $A) ((MTIMES SIMP) 4
((MEXPT SIMP RATSIMP) $A 2))) ((RAT SIMP) 1 2)))))) 1)
willisb@unk.edu wrote:
> This isn't a fix for the solve bug,
>
> (C4) SOLVE((a^2+1)*x^2+a*x+a,x);
> quotient is not exact
> -- an error. Quitting. To debug this try DEBUGMODE(TRUE);)
>
> but it may help somebody find it. I believe the bug is caused by
> what simpnrt returns in the function solvequad. It is the function
> fullratsimp following simpnrt that never returns a value; simpnrt
> appears to be okay, but fullratsimp doesn't like what it returns.
> Replacing
>
> (DEFUN SOLVEQUAD (EXP &AUX DISCRIM A B C)
> (SETQ A (CADDR EXP))
> (SETQ B (PTERM (CDR EXP) 1.))
> (SETQ C (PTERM (CDR EXP) 0.))
> (SETQ DISCRIM (SIMPLIFY (PDIS (PPLUS (PEXPT B 2.)
> (PMINUS (PTIMES 4. (PTIMES A C)))))))
> (SETQ B (PDIS (PMINUS B)))
> (SETQ A (PDIS (PTIMES 2. A)))
> ;; At this point, everything is back in general representation.
> (COND ((EQUAL 0. DISCRIM)
> (SOLVE3 (FULLRATSIMP `((MQUOTIENT) ,B ,A))
> (TIMES 2. MULT)))
> (T (SETQ DISCRIM (SIMPNRT DISCRIM 2.))
> (SOLVE3 (FULLRATSIMP `((MQUOTIENT) ((MPLUS) ,B ,DISCRIM) ,A))
> MULT)
> (SOLVE3 (FULLRATSIMP `((MQUOTIENT) ((MPLUS) ,B ((MMINUS) ,DISCRIM)) ,A))
> MULT))))
>
>
> with
>
> (DEFUN SOLVEQUAD (EXP &AUX DISCRIM A B C)
> (SETQ A (CADDR EXP))
> (SETQ B (PTERM (CDR EXP) 1.))
> (SETQ C (PTERM (CDR EXP) 0.))
> (SETQ DISCRIM (SIMPLIFY (PDIS (PPLUS (PEXPT B 2.)
> (PMINUS (PTIMES 4. (PTIMES A C)))))))
> (SETQ B (PDIS (PMINUS B)))
> (SETQ A (PDIS (PTIMES 2. A)))
> ;; At this point, everything is back in general representation.
> (COND ((EQUAL 0. DISCRIM)
> (SOLVE3 (FULLRATSIMP `((MQUOTIENT) ,B ,A))
> (TIMES 2. MULT)))
> (T (SETQ DISCRIM `((mexpt) ,DISCRIM ,(rat 1 2))) ;; only change
> (SOLVE3 `((MQUOTIENT) ((MPLUS) ,B ,DISCRIM) ,A)
> MULT)
> (SOLVE3 `((MQUOTIENT) ((MPLUS) ,B ((MMINUS) ,DISCRIM)) ,A)
> MULT))))
>
> eliminates the bug:
>
> (C8) load("solve_crusty.lisp")$
>
> (C9) solve((a^2+1)*x^2 + a*x+a,x);
> (D9) [x = (-SQRT(-4*a^3+a^2-4*a)-a)/(2*a^2+2),
> x = (SQRT(-4*a^3+a^2-4*a)-a)/(2*a^2+2)]
>
> My maxima is 5.6; my Lisp is GCL 2.4.0; and my OS is Redhat 6.1.
>
> Barton
>
>
> _______________________________________________
> Maxima mailing list
> Maxima@www.math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>