#1197 gradef for variables: not used in diff

Lisp Core (472)

Consider the following:

(%i13) gradef(Vb, R, Sb) $
(%i14) diff(Vb);
(%o14) Sb del(R)
(%i15) diff(3*Vb);
(%o15) 3 del(Vb)

Instead of %o15 I would have expected 3*Sb*del(R).

In functional notation showing the dependency on R, things
seem to work:

(%i21) gradef(Va(R), Sa) $

(%i22) diff(Va(R));
(%o22) Sa del(R)
(%i23) diff(3*Va(R));
(%o23) 3 Sa del(R)

This behavior may be related to the fact that
%i13 does not update gradefs.

On the mailing list, Robert Dodier mentioned the following:

This behavior seems to be intentional, but certainly is confusing.
The available documentation for gradef (probably derived from
the union of old documentation and what could be puzzled out
by reading the code) seems to distinguish gradef(F(x), ...) from
gradef(F, x, ...) although the intended effect of this distinction
is obscure.

Certainly the two cases are treated differently by the code.

gradef (Va(R), Sa);
=> Va(R)
:lisp (symbol-plist '|$Va|)
=> (GRAD ((r) $Sa))
gradef (Vb, R, Sa);
=> Vb
:lisp (symbol-plist '|$Vb|)
=> (MPROPS (NIL DEPENDS ($r) $ATOMGRAD (($r . $Sa))))
=> [Va(R)]

An easy fix would be to cause the two forms of gradef to
assign the same properties. But I don't know what else
that would break.


  • Robert Dodier
    Robert Dodier

    • labels: --> Lisp Core
  • Dieter Kaiser
    Dieter Kaiser

    Again the problem which is a bit reformulated:

    (%i1) depends(f,[x,y])$

    This is the correct total differential:

    (%i2) diff(f);
    (%o2) 'diff(f,y,1)*del(y)+'diff(f,x,1)*del(x)

    But it does not work when we have an expression with the symbol f:

    (%i3) diff(3*f);
    (%o3) 3*del(f)

    (%i4) diff(a*f);
    (%o4) a*del(f)+f*del(a)

    The problem is in the routine extractvars, which is called from the routine stotaldiff. This routine only collects the variables of the expression we have passed to the routine stotaldiff, but does not take into account the dependencies. This can be corrected and we get the expected results:

    (%i6) diff(3*f);
    (%o6) 3*'diff(f,y,1)*del(y)+3*'diff(f,x,1)*del(x)

    (%i7) diff(a*f);
    (%o7) a*'diff(f,y,1)*del(y)+a*'diff(f,x,1)*del(x)+f*del(a)

    Dieter Kaiser

  • Dieter Kaiser
    Dieter Kaiser

    This bug has been fixed in the routine extracvars in the file comm2.lisp revision 1.34.
    Closing this bug report as fixed.
    Dieter Kaiser

  • Dieter Kaiser
    Dieter Kaiser

    • status: open --> closed