"trigrat" caught in infinite loop - depending on how you call it



I think I've fixed the bug which trigrat exposed -- actually the problem
is that some functions related to rational expressions don't bind
VARLIST, so it leaks from one call into the next. I found this bug in
rat, ratexpand, and the simplifications for plus and times (all exposed
by the examples posted in this thread), but there may be others; I
didn't carry out an exhaustive search.

Patch shown below and some test cases were committed as c36715e95ed.

Robert Dodier

PS.

diff --git a/src/rat3e.lisp b/src/rat3e.lisp
index 89426f3..f873a26 100644
--- a/src/rat3e.lisp
+++ b/src/rat3e.lisp
@@ -170,14 +170,14 @@
        (reverse (mapfr1 cdrl nil))))
 
 (defmfun $rat (e &rest vars)
-  (cond ((not (null vars))
-        (let (varlist)
+  (let (varlist)
+    (cond ((not (null vars))
           (joinvarlist vars)
           (lnewvar e)
-          (rat0 e)))
+          (rat0 e))
        (t
         (lnewvar e)
-        (rat0 e))))
+        (rat0 e)))))
 
 (defun rat0 (exp)                      ;SIMP FLAGS?
   (if (mbagp exp)
@@ -952,7 +952,7 @@
 (defmfun $ratexpand (x)
   (if (mbagp x)
       (cons (car x) (mapcar '$ratexpand (cdr x)))
-      (let (($ratexpand t) ($ratfac nil))
+      (let (($ratexpand t) ($ratfac nil) varlist)
        (ratdisrep (ratf x)))))
 
 (defun pdisrep*expand (a b)
diff --git a/src/simp.lisp b/src/simp.lisp
index 78d5fc8..6157622 100644
--- a/src/simp.lisp
+++ b/src/simp.lisp
@@ -960,7 +960,8 @@
   st1
      (cond ((atom w) nil)
            ((eq (caar w) 'mrat)
-            (cond ((or eqnflag
+            (let (varlist)
+              (cond ((or eqnflag
                        matrixflag
                        (and sumflag
                             (not (member 'trunc (cdar w) :test #'eq)))
@@ -971,7 +972,7 @@
                    (return
                      (ratf (cons '(mplus)
                                  (nconc (mapcar #'simplify (cons w (cdr
x)))
-                                        (cdr res))))))))
+                                        (cdr res)))))))))
            ((eq (caar w) 'mequal)
             (setq eqnflag
                   (if (not eqnflag)
@@ -1633,7 +1634,8 @@
   st1
      (cond ((atom w) nil)
           ((eq (caar w) 'mrat)
-           (cond ((or eqnflag matrixflag
+           (let (varlist) 
+             (cond ((or eqnflag matrixflag
                       (and sumflag
                            (not (member 'trunc (cdar w) :test #'eq)))
                       (spsimpcases (cdr x) w))
@@ -1643,7 +1645,7 @@
                   (return 
                     (ratf (cons '(mtimes)
                                 (nconc (mapcar #'simplify (cons w (cdr
x)))
-                                       (cdr res))))))))
+                                       (cdr res)))))))))
           ((eq (caar w) 'mequal)
            (setq eqnflag
                  (if (not eqnflag)