"matrix([matrix([" returned with mat_function (Was: Re: Symbolic matrix power)
Subject: "matrix([matrix([" returned with mat_function (Was: Re: Symbolic matrix power)
From: Stavros Macrakis
Date: Mon, 28 Oct 2013 15:15:15 -0400
It is true that lexical scope rules (or changing the variable name) would
fix this.
But that only matters if an object is being *evaluated* where it shouldn't
be. And sure enough, applying the 'matrix' function incorrectly
re-evaluates its arguments. Here is a simple example:
q: '[[x]]$
x: 3$
apply('matrix,q) => matrix([3]) !!!! should be matrix([x])
This extra evaluation is a bug in 'apply'.
-s
On Mon, Oct 28, 2013 at 2:25 PM, Robert Dodier <robert.dodier at gmail.com>wrote:
> > On 10/25/2013 08:26 PM, andre maute wrote:
>
> >> (%i2) A : matrix([a,b],[c,d]);
> >>
> >> (%o2) matrix([a,b],[c,d])
> >> (%i3) load("diag");
> >>
> >> (%o3) "/home/user/opt/maxima/share/maxima/5.30.0/share/contrib/diag.mac"
> >> (%i4) integer_pow(x) := block ([k], declare (k, integer), x^k);
> >>
> >> (%o4) integer_pow(x):=block([k],declare(k,integer),x^k)
> >> (%i5) mat_function (integer_pow, A);
> >>
> >> (%o5) matrix([matrix([(sqrt(d^2-2*a*d+4*b*c+a^2)-d-a)^k* ...
>
> This is due to Maxima's dynamic binding policy -- there is a local
> variable in diag_mode_matrix named 'a' which is bound to the value of
> the user variable 'A'. Try it again w/ A : matrix([b, c], [d, e]) --
> I think you'll get a different result.
>
> This particular bug could be fixed by changing 'a' to 'a%' or something
> to reduce the chance of a name collision, but it doesn't seem worth the
> trouble -- every local variable really needs the same treatment, and
> anyway the problem will reappear if someone uses an "unlikely" name.
> The only way to really fix it is to make local variables lexical instead
> of dynamic -- I'm in favor of that, for the record.
>
> best
>
> Robert Dodier
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>