Menu

#3526 inconsistent treatment of simple and subscripted assignments in ev

None
wont-fix
nobody
5
2019-02-03
2019-02-03
No

ev handles assignments to simple variables differently than assignments to subscripted variables. Assignments to simple variables are handled by binding (via MBIND) the variables. Assignments to subscripted variables are handled by substituting the value for the subscripted variable in the input expression, and then evaluating the expression.

Since the subscripted variables are not bound, any further occurence of the subscripted variables in the evaluation won't make use of the assigned value. Here is an example, take from [1].

(%i1) f(x) := a[0]*x $

(%i2) ev (f(z), a[0]=99);
(%o2)                                a  z
                                      0

But if the variable is a0 instead of a[0] the result is what you'd expect from dynamic binding:

(%i3) g(x) := a0*x $

(%i4) ev (g(z), a0=99);
(%o4)                                99 z

The behavior of ev is actually documented: "If 'V' is a non-atomic expression then a substitution rather than a binding is performed." But I think the current behavior is a bug anyway, since it is counterintuitive at best.

[1] https://stackoverflow.com/questions/54300600/maxima-indexed-variables-assigned-in-evaluation-of-function

Discussion

  • Robert Dodier

    Robert Dodier - 2019-02-03
    • status: open --> wont-fix
     
  • Robert Dodier

    Robert Dodier - 2019-02-03

    I'm closing this one as won't-fix since changing ev(..., a[0]=b) to use binding instead of substitution breaks the existing use of temporary assignment in ev to effect substitutions. It turns out there are many instances of that in the test suite -- stuff like ev(..., laplace(expr, u, v) = ...). I don't think there's any comprehensible way to distinguish assignments which can succeed from ones, like the laplace example, which can't, so at this point I think using binding instead of substitution can't work.

     

Log in to post a comment.