kalix
kalix

Reputation: 210

side-effects using declare(var,constant) in Maxima

In maxima, is the following behavior intended?

First example:

(%i1) declare(a,constant);
(%o1)                                done
(%i2) constantp(a);
(%o2)                                true
(%i3) square(a):=a^2;

define: in definition of square, found bad argument a
 -- an error. To debug this try: debugmode(true);
(%i4) load("linearalgebra.mac");

define: in definition of dotproduct, found bad argument a
 -- an error. To debug this try: debugmode(true);

Second example:

(%i1) a:5;
(%o1)                                  5
(%i2) constantp(a);
(%o2)                                true
(%i3) square(a):=a^2;
                                              2
(%o3)                           square(a) := a
(%i4) square(a);
(%o4)                                 25

Third example:

(%i1) declare(a,scalar);
(%o1)                                done
(%i2) mat_f(a,b):=a.b - b.a;
(%o2)                    mat_f(a, b) := a . b - b . a
(%i4) mat_f(matrix([1,2],[3,4]),matrix([3,4],[1,2]));
                                [ - 10  - 14 ]
(%o4)                           [            ]
                                [  6     10  ]

It seems like declare(a,constant) has a global effect which to me seems strange in maxima. The second and third example work exactly how I would expect it.

Also are there any similar cases where something like this happens in maxima?

Upvotes: 1

Views: 1074

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17577

Maxima has a very weak notion of scope. Essentially all symbols are in the same scope, so when you make a declaration about a, it is about all instances of a, even the ones which are function arguments.

Maxima is actually a very old program and this is one of those aspects which has never been updated. There is discussion about giving Maxima a stronger notion of scope, but that will take some time.

Upvotes: 2

Related Questions