From eb4bfa5fef477c824508dbfabb73a80155b13f27 Mon Sep 17 00:00:00 2001 From: Kris Katterjohn Date: Fri, 18 Mar 2022 07:19:58 -0400 Subject: [PATCH] Fix bug #3934: expand(1/(1+%i)^4) => (-4)^(-1) (unsimplified) This is an ancient bug that was present in Macsyma. EXPANDEXPT has been constructing MEXPT expressions marked with the SIMP flag when there is no reason to assume that expression is actually simplified. The expression is of the form ((MEXPT SIMP) E -1) where E is the result of EXPONENTIATE-SUM. (%i1) expand((1+%i)^-2); (%o1) 1/(2*%i) (%i2) expand(%); (%o2) -%i/2 Now we just use INV instead of manually constructing the MEXPT expression with the bogus SIMP flag. No problems with the test suite or share test suite. New tests have been added to rtest16. --- ChangeLog | 1 + src/simp.lisp | 2 +- tests/rtest16.mac | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index f4772eff6..c5792a6ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -54,6 +54,7 @@ Bug fixes for numbered bugs: * \#3881: plot2d not ignoring errors within functions * \#3883: plot creates invalid gnuplot command * \#3907: gnuplot_postamble not actually the last Gnuplot output before plot + * \#3934: expand(1/(1+%i)^4) => (-4)^(-1) (unsimplified) * \#3936: plot2d sends invalid file to gnuplot * \#3950: letsimp confuses symbols and nullary applications * \#3952: plot2d clipping warnings not appearing diff --git a/src/simp.lisp b/src/simp.lisp index 3552a8a6b..67482956a 100644 --- a/src/simp.lisp +++ b/src/simp.lisp @@ -3287,7 +3287,7 @@ (declare (fixnum power)) (let ((expansion (exponentiate-sum (cdr sum) (abs power)))) (cond ((plusp power) expansion) - (t `((mexpt simp) ,expansion -1))))) + (t (inv expansion))))) (defun exponentiate-sum (terms rpower) (declare (fixnum rpower)) diff --git a/tests/rtest16.mac b/tests/rtest16.mac index 91aba4b03..4846c7a0d 100644 --- a/tests/rtest16.mac +++ b/tests/rtest16.mac @@ -2756,3 +2756,20 @@ facts (); featurep (I, irrational)]; [false, false, false, false]; +/* Bug #3934: expand(1/(1+%i)^4) => (-4)^(-1) (unsimplified) */ + +expand((1+%i)^-2); +-%i/2; + +expand(1/(1+%i)^4); +-1/4; + +expand(4/(%i+1)^4)+1; +0; + +expand(1/(1+%i)^8-1/16); +0; + +expand((sqrt(-1/2)+sqrt(1/2))^-8); +1; + -- 2.11.4.GIT