depends and diff with ver 5.22.1 batch file



Am Dienstag, den 12.10.2010, 13:22 -0700 schrieb Edwin Woollett:

The following shows the results with the current CVS Version of Maxima.
I think all is correct and we get the expected results.

*****************************************************

Maxima version: 5.22post
Maxima build date: 17:59 10/12/2010
Host type: i686-pc-linux-gnu
Lisp implementation type: SBCL
Lisp implementation version: 1.0.40

(%i2) batch("depends.mac");
read and interpret
file: /home/dieter/workspace/mymaxima/depends/depends.mac
(%i3) display2d:false
(%i4) "spherical polar coordinates (r,theta,phi ) = (r,t,p)  "
(%i5) assume(r > 0,sin(t) > 0)
(%i6) " define drdz and dtdz replacements "
(%i7) gradef(r,z,cos(t))
(%i8) gradef(t,z,(-sin(t))/r)
(%i9) " p = phi does not depend on z "
(%i10) depends([r,t],[x,y,z])
(%i11) depends(p,[x,y])
(%i12) " let bp(r,t,p) be a field component"
(%i13) " depending on r,t,and p "
(%i14) depends(bp,[r,t,p])
(%i15) " look at some derivatives w.r.t. z "
(%i16) diff(cos(p),z)
(%o16) 0
(%i17) diff(bp,z)
(%o17) 'diff(bp,r,1)*cos(t)-'diff(bp,t,1)*sin(t)/r
(%i18) diff(cos(p)*bp,z)
(%o18) cos(p)*('diff(bp,r,1)*cos(t)-'diff(bp,t,1)*sin(t)/r)
(%i19) diff(bp*cos(p),z)
(%o19) cos(p)*('diff(bp,r,1)*cos(t)-'diff(bp,t,1)*sin(t)/r)
(%o19) "/home/dieter/workspace/mymaxima/depends/depends.mac"

*****************************************************

The problem of version Maxima 5.22 is, that I have overseen, that the
old code does not look into indirect dependencies. I have specialized
the code to remove the behavior that any dependency causes that a symbol
depends on any other symbol too. But I have not generalized the code to
look into indirect dependencies.

Meanwhile this has been corrected too. The correction is part of Maxima
5.22post. You can load the following patch to get a correct function
depends:

(defun depends (e x &aux l)
  (setq e (specrepcheck e))
  (cond ((alike1 e x) t)
        ((mnump e) nil)
        ((and (symbolp e) (setq l (mget e 'depends)))
         ;; Go recursively through the list of dependencies.
         ;; This code detects indirect dependencies like a(x) and x(t).
         (dependsl l x))
        ((atom e) nil)
        (t (or (depends (caar e) x)
               (dependsl (cdr e) x)))))

Please, try it.

Dieter Kaiser