Menu

#4796 reflect0 (not user-level) function returns unsimplified expression

None
open
nobody
5
2026-06-22
2026-06-22
No

The functions relect0 and reflect can return unsimplified expressions. I have no evidence that this causes any bugs, but one experiment shows that at least for the testsuite, it does not.

Unless I'm mistaken, this behavior is harmless, so this is a (very) low priority bug. (I don't know if this means priority 1 or 9, so I'm leaving the priority as 5.)

The current functions are:

(defun reflect0 (exp var val)
  (cond ((atom exp) exp)
    ((and (eq (caar exp) 'mfactorial)
          (let ((argval (limit (cadr exp) var val 'think)))
        (or (eq argval '$minf)
            (and (numberp argval)
             (> 0 argval)))))
     (reflect (cadr exp)))
    (t (cons (operator-with-array-flag exp)
         (mapcar (function
              (lambda (term)
               (reflect0 term var val)))
             (cdr exp))))))
(defun reflect (arg)
  (m* -1
      '$%pi
      (m^ (list (ncons 'mfactorial)
        (m+ -1
            (m* -1 arg)))
      -1)
      (m^ (list (ncons '%sin)
        (m* '$%pi arg))
      -1)))

For amusement, I (quickly) rewrote these functions as:

(defun reflect0 (exp var val)
  (flet ((recur (q) (reflect0 q var val)))
    (cond (($mapatom exp)
           exp)

          ((eq 'mfactorial (caar exp))
           (let* ((z (cadr exp))
                  (lim (limit z var val 'think)))
             (if (or (eq lim '$minf) (and (numberp lim) (< lim 0)))
                 (reflect z)
                 (ftake 'mfactorial (recur z)))))

          (($subvarp (mop exp))
           (subfunmake (subfunname exp)
                       (mapcar #'recur (subfunsubs exp))
                       (mapcar #'recur (subfunargs exp))))
          (t
           (fapply (caar exp) (mapcar #'recur (cdr exp)))))))

(defun reflect (arg)
  (mul -1 '$%pi
       (power (ftake 'mfactorial (add -1 (mul -1 arg))) -1)
       (power (ftake '%sin (mul '$%pi arg)) -1)))

But these definitions don't fix any bugs that I know of.

These functions are not minimal patches that correct the problem of returning un simplified expressions, and they are not semantically the same. Maybe it would be more wise to stick to a minimal patch.

Discussion


Log in to post a comment.

Auth0 Logo