"matrix([matrix([" returned with mat_function (Was: Re: Symbolic matrix power)
Subject: "matrix([matrix([" returned with mat_function (Was: Re: Symbolic matrix power)
From: Robert Dodier
Date: Mon, 28 Oct 2013 18:25:56 +0000 (UTC)
> 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