From f1ccc679dadd3ec78491a8ed47f8f2b34e13ead5 Mon Sep 17 00:00:00 2001 From: Kris Katterjohn Date: Tue, 19 Apr 2022 06:49:49 -0400 Subject: [PATCH] Fix bug #608: taylor(x^a,[x],0,1) unsimplified Also bug #545: multivar taylor gives 1^2 This is an ancient bug that was present in Macsyma. SETUP-MULTIVAR-DISREP gives genvars that are associated with multivars the DISREP property so they disrep to 1. These genvars raised to powers could be visible as unsimplified 1s raised to powers in output: (%i1) taylor(x^a,[x],0,1); (%o1) +1^2*x^a (%i2) taylor((x*y)^a,[x,y],0,1); (%o2) +1^4*(x*y)^a (%i3) taylor(x^a+y^a,[x,y],0,1); (%o3) +(1^2*y^a+1^2*x^a) Prior to commit 38d4b2fd the internal genvars themselves could be made visible by using taytorat: (%i1) taylor(x^a,[x],0,1); (%o1) +1^2*x^a (%i2) taytorat(%); (%o2) (g137^a)^2*x^a Now we add to PDISREP! the knowledge that 1^x is equal to 1 for any x, which prevents the construction of factors like 1^2 above. (PDISREP! already knows that x^0 is equal to 1 and x^1 is equal to x for any x.) No problems with the test suite or share test suite. New tests have been added to rtest_taylor. --- src/rat3e.lisp | 1 + tests/rtest_taylor.mac | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/rat3e.lisp b/src/rat3e.lisp index 99a8eb594..6ede4611c 100644 --- a/src/rat3e.lisp +++ b/src/rat3e.lisp @@ -924,6 +924,7 @@ (eq (caar var) 'mplus)) (copy-list var)) (t var))) + ((eql var 1) 1) (t (list '(mexpt ratsimp) var n)))) (defun pdisrep+ (p) diff --git a/tests/rtest_taylor.mac b/tests/rtest_taylor.mac index c826d8be7..72dd58045 100644 --- a/tests/rtest_taylor.mac +++ b/tests/rtest_taylor.mac @@ -635,3 +635,15 @@ taytorat (taylor (taylor (x + y, [x], 0, 1), [y], 0, 1)); horner (taylor (x, [x], 0, 1)); x; + +/* Bug #608: taylor(x^a,[x],0,1) unsimplified + * Bug #545: multivar taylor gives 1^2 + */ + +/* This used to yield "+1^2*x^a" */ +string(taylor(x^a,[x],0,1)); +"+x^a"; + +/* This used to yield "+1^4*(x*y)^a" */ +string(taylor((x*y)^a,[x,y],0,1)); +"+(x*y)^a"; -- 2.11.4.GIT