gcl-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: $gensym


From: Camm Maguire
Subject: Re: $gensym
Date: Fri, 10 Nov 2023 15:09:39 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)

Greetings!

Robert Dodier <robert.dodier@gmail.com> writes:

> On Sun, Nov 5, 2023 at 7:06 AM Camm Maguire <camm@maguirefamily.org> wrote:
>
> What is the test case which shows Maxima gensym not working correctly?
> Maybe it's serious enough after all.
>

Having spent some time to see if I could cache gensyms in setf
expansions for performance reasons, (I am currently convinced this is
not possible), I strongly suspect $gensym suffers from the same logical
failure, as common usage always assumes a fresh sym, but the interning
introduced is a form of caching.  The comment at the head of the
function implies someone introduced this to avoid confusion in printed
representations:

;;; Return a Maxima gensym.
;;;
;;; N.B. Maxima gensyms are interned, so they are not Lisp gensyms.
;;; This function can return the same symbol multiple times, it can
;;; return a symbol that was created and used elsewhere, etc.
;;;
;;; Maxima produces some expressions that contain Maxima gensyms, so
;;; the use of uninterned symbols instead can cause confusion (since
;;; these print like any other symbol).

Take care,

=============================================================================
ds.l
=============================================================================
(in-package :maxima)

(setq decf-gensym nil)

(defun alike7 (x y &aux (cx (memqarr x))(cy (memqarr y)))
  (when decf-gensym (decf *gensym-counter* (random 10)))
  (eq cx cy))

(defun alike1 (x y)
  ;; Clauses are ordered based on frequency of the case
  ;; cons, integer, and symbol are very common
  ;; everything else is rare
  (cond ((eq x y) t)
        ((consp x)
         (if (and (consp y)
                  (not (atom (car x)))
                  (not (atom (car y)))
                  (eq (caar x) (caar y)))
             (cond
              ((eq (caar x) 'mrat) (like x y))
              ((eq (caar x) 'mpois) (equal (cdr x) (cdr y)))
              ((alike7 (cdar x) (cdar y));(eq (mmemqarr (cdar x)) (mmemqarr 
(cdar y)))
               (alike (cdr x) (cdr y)))
              (t nil)
              )
             nil))
        ((or (symbolp x) (symbolp y)) nil)
        ((integerp x) (and (integerp y) (= x y)))
        ;; uncommon cases from here down
        ((floatp x) (and (floatp y) (= x y)))
        ((stringp x) (and (stringp y) (string= x y)))
        ((vectorp x) (and (vectorp y) (lisp-vector-alike1 x y)))
        ((arrayp x) (and (arrayp y) (lisp-array-alike1 x y)))
        (t nil)
        ))

=============================================================================
rtest_integrate.mac
=============================================================================
/* A collection of about 730 integrals with power functions.
   The integrals are taken from functions.wolfram.com

   OK   - The integral is solved by Maxima
   NEW  - Solution after extension of the integrator (rev. 1.34)
   NOUN - No solution a noun form is returned.  
*/

(kill(all),
  declare(z,complex,n,integer),
  assume(n>0),
  assume(notequal(v,0)),
  domain:complex,
  radexpand:true,
  
  /* This function checks if we get back the integrand.
   *
   * integral is the result of an integration, 
   * var the integration variable, and
   * simplifier a simplifying function. 
   */
  diffcheck(integral,var,simplifier):=
     if op(integral)=nounify(integrate) then
        integral
     else 
        simplifier(diff(integral,var)),
        
  factor_radcan(expr):=factor(radcan(expr)),
  done);
done;

/* Problem 204: NEW 6 */
niceindices(niceindices(integrate(z^n*d^(b*z+a*sqrt(z)),z)));
log(d)^(-2*(n+1)+2*n+1)*2^(-n-1)
                       *('sum(4^j*binomial(n,j)
                                 *'sum(a^(2*n-j-i)*(-1)^(i-j)*binomial(j,i)
                                                  *(2*b*sqrt(z)+a)^(j+i)
                                                  *(a*log(d)
                                                     *gamma_incomplete(
                                                      (j+i+1)/2,
                                                      -log(d)
                                                       *(2*b*sqrt(z)+a)^2
                                                       /(4*b))*(2*b*sqrt(z)+a)
                                                   +2*b
                                                     *gamma_incomplete(
                                                      (j+i+2)/2,
                                                      -log(d)
                                                       *(2*b*sqrt(z)+a)^2
                                                       /(4*b))
                                                     *sqrt(
                                                      -log(d)
                                                       *(2*b*sqrt(z)+a)^2
                                                       /b))
                                        /(-log(d)*(2*b*sqrt(z)+a)^2/b)
                                         ^((j+i+1)/2),i,0,j),j,0,n))
 /(b^(2*(n+1))*d^(a^2/(4*b)));

/* ----- End of file -------------------------------------------------------- */
=============================================================================
transcript
=============================================================================
Starting program: /mnt/sda4/debian/maxima-code/src/binary-gcl/maxima -eval 
'(run)'
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching after vfork from child process 3636862]
[Detaching after vfork from child process 3636863]
[Detaching after vfork from child process 3636864]
;; Loading "/home/camm/debian/maxima-code/doc/info/./maxima-index.lisp"
;; Finished loading "/home/camm/debian/maxima-code/doc/info/./maxima-index.lisp"
;; Loading "/home/camm/debian/maxima-code/doc/info/./maxima-index-html.lisp"
;; Finished loading 
"/home/camm/debian/maxima-code/doc/info/./maxima-index-html.lisp"
Warning: argument a not recognized.
Maxima branch_5_46_base_1821_gb6d66ad4e_dirty https://maxima.sourceforge.io
using Lisp GNU Common Lisp (GCL) GCL 2.7.0 git tag NIL
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.
(%i1) :lisp (load "~/debian/gclm3/ds.l")
;; Loading "~/debian/gclm3/ds.l"
;; Finished loading "~/debian/gclm3/ds.l"
T
(%i1) run_testsuite(tests=[rtest_integrate]);
Testsuite run for GNU Common Lisp (GCL) GCL 2.7.0 git tag NIL:
Running tests in rtest_integrate: 2/2 tests passed


No unexpected errors found out of 2 tests.
real time       :      0.170 secs
run-gbc time    :      0.160 secs
child run time  :      0.000 secs
gbc time        :      0.000 secs
(%o0)                                done
(%i1) run_testsuite(tests=[rtest_integrate]);
Testsuite run for GNU Common Lisp (GCL) GCL 2.7.0 git tag NIL:
Running tests in rtest_integrate: 2/2 tests passed


No unexpected errors found out of 2 tests.
real time       :      0.190 secs
run-gbc time    :      0.160 secs
child run time  :      0.000 secs
gbc time        :      0.000 secs
(%o0)                                done
(%i1) run_testsuite(tests=[rtest_integrate]);
Testsuite run for GNU Common Lisp (GCL) GCL 2.7.0 git tag NIL:
Running tests in rtest_integrate: 2/2 tests passed


No unexpected errors found out of 2 tests.
real time       :      0.200 secs
run-gbc time    :      0.170 secs
child run time  :      0.000 secs
gbc time        :      0.000 secs
(%o0)                                done
(%i1) :lisp (setq decf-gensym t)

T
(%i1) run_testsuite(tests=[rtest_integrate]);
Testsuite run for GNU Common Lisp (GCL) GCL 2.7.0 git tag NIL:
Running tests in rtest_integrate: 
********************** Problem 2 (line 33) ***************
Input:
                                   n  b z + a sqrt(z)
niceindices(niceindices(integrate(z  d               , z)))


Result:
                                       n
                                      ====
       - 2 (n + 1) + 2 n + 1  - n - 1 \      j
(log(d)                      2         >    4  binomial(n, j)
                                      /
                                      ====
                                      j = 0
  j
 ====
 \       2 n - j - i      j - i                                 j + i
  >    (a            (- 1)      binomial(j, i) (2 b sqrt(z) + a)
 /
 ====
 i = 0
                                                                 2
                            j + i + 1    log(d) (2 b sqrt(z) + a)
 (a log(d) gamma_incomplete(---------, - -------------------------)
                                2                   4 b
                                          j + i + 2
 (2 b sqrt(z) + a) + 2 b gamma_incomplete(---------, 
                                              2
                          2                                 2
  log(d) (2 b sqrt(z) + a)          log(d) (2 b sqrt(z) + a)
- -------------------------) sqrt(- -------------------------)))
             4 b                                b
                                                       2
                              j + i + 1               a
                            2 ---------               ---
    log(d) (2 b sqrt(z) + a)      2        2 (n + 1)  4 b
/(- -------------------------)         )/(b          d   )
                b

This differed from the expected result:
                                       n
                                      ====
       - 2 (n + 1) + 2 n + 1  - n - 1 \      j
(log(d)                      2         >    4  binomial(n, j)
                                      /
                                      ====
                                      j = 0
  j
 ====
 \       2 n - j - i      i - j                                 j + i
  >    (a            (- 1)      binomial(j, i) (2 b sqrt(z) + a)
 /
 ====
 i = 0
                                                                 2
                            j + i + 1  - log(d) (2 b sqrt(z) + a)
 (a log(d) gamma_incomplete(---------, ---------------------------)
                                2                  4 b
                                          j + i + 2
 (2 b sqrt(z) + a) + 2 b gamma_incomplete(---------, 
                                              2
                          2                                 2
- log(d) (2 b sqrt(z) + a)        - log(d) (2 b sqrt(z) + a)
---------------------------) sqrt(---------------------------)))
            4 b                                b
                                                       2
                              j + i + 1               a
                            2 ---------               ---
  - log(d) (2 b sqrt(z) + a)      2        2 (n + 1)  4 b
/(---------------------------)         )/(b          d   )
               b

1/2 tests passed

The following 1 problem failed: (2)

Error summary:
Error(s) found:
  /home/camm/debian/maxima-code/tests/rtest_integrate.mac problem:
    (2)
1 test failed out of 2 total tests.
real time       :      0.210 secs
run-gbc time    :      0.200 secs
child run time  :      0.000 secs
gbc time        :      0.000 secs
(%o0)                                done
(%i1)
=============================================================================


-- 
Camm Maguire                                        camm@maguirefamily.org
==========================================================================
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah



reply via email to

[Prev in Thread] Current Thread [Next in Thread]