Fix bug #2709: `letsimp' is wrong if `ratexpand' is called
commit08d17ea8c93ccfddef683f26af2641f75c3f0dfc
authorKris Katterjohn <katterjohn@gmail.com>
Sun, 28 Nov 2021 20:03:06 +0000 (28 15:03 -0500)
committerKris Katterjohn <katterjohn@gmail.com>
Sun, 28 Nov 2021 20:03:06 +0000 (28 15:03 -0500)
tree9272b1101f320239ce53aaf1f7d74836d78485e2
parent225bf871044c426b647674a73e40b1b089745e4f
Fix bug #2709: `letsimp' is wrong if `ratexpand' is called

This is an ancient bug that was present in Macsyma.

When NISLETSIMPRAT was given a CRE c it would perform actions on the
numerator and denominator of c separately.  It first constructed a
new CRE based on the numerator of c, then it disrepped this new CRE
and then it called NISLETSIMP with this result.  After that it did
the same thing with the denominator of c.

The problem is that the construction of the new CREs would use the
current value of VARLIST and GENVAR, and NISLETSIMP can change these
values.  So even though the numerator and denominator both came from
the same CRE, they could be constructed and disrepped in different
VARLIST and GENVAR contexts.

(%i1) let (U, T)$

(%i2) letsimp (U / n); /* correct */
(%o2) T/n

(%i3) ratexpand (a * b * c)$

(%i4) letsimp (U / n); /* wrong */
(%o4) 1

The use of ratexpand simply changes the global VARLIST and GENVAR in
such a way that this bug shows up.  ratexpand isn't special; other
functions such as rat could cause the same problem.

Now the numerator and denominator are both constructed and disrepped
in the same VARLIST and GENVAR context, namely the one given by the
original CRE c.  Both of these are done before calling NISLETSIMP on
the results.

No problems with the test suite or share test suite.  New tests have
been added to rtest12.
src/nisimp.lisp
tests/rtest12.mac