Ramzan Altair
Ramzan Altair

Reputation: 97

Maxima: Calling "assume()" in a function

Defining the function

foo(a, b) := apply('assume, [a < b])$

do

facts();
  -> []

foo(0, a);
  -> [inconsistent]  /* why? */

foo(b, a);
  -> [b > a]  /* instead [a > b] */

foo(d, c);
  -> [c > d]

assume(0 < a);
  -> [a > 0]

Why is there inconsistent? Is it possible to fix this somehow without changing the name of the function variables foo(aa, bb)? How does it work?

Upvotes: 2

Views: 261

Answers (1)

Robert Dodier
Robert Dodier

Reputation: 17575

The problem is that Maxima cannot distinguish the function argument symbols a and b from global variables with the same names. At present the only way to work around it is to give the function arguments names which are considered to be infrequently used, such as a% and b%.

I am working on implementing lexical scope for Maxima, which makes local variables distinct from all other variables with the same names. It seems plausible that might make its way into a Maxima release some time next year. In the meantime, you'll have to work around the problem.

Another aspect of this problem is that function arguments are supposed to be evaluated exactly once, and assume is somewhere evaluating the arguments again. On looking at it for a minute, it appears that the code to handle "<" is evaluating again -- this is a bug, which triggers the other bug about symbols not being distinct.

Upvotes: 3

Related Questions