Difference between "batch" and command line input



On Thu, Jan 22, 2009 at 3:05 AM, Chris Sangwin
<sangwinc at for.mat.bham.ac.uk> wrote:

> I create a file on Maxima's path, e.g. "test.mac", with the following
> lines
>
> simp:false;
> a1 : 1;
> a2 : ev(-20,simp);
> errcatch(a1+a2);
>
> In a clean Maxima session I execute this file with "batch"
>
> batch("test.mac");
>
> The last output is [1-20] as expected.
>
> Now, at the command line I type in
> errcatch(a1+a2);
>
> The output is now [1+-20] which is different.

This behavior appears to be a symptom of a bug in the display code.
The presence of extra stuff in the operator of an expression,
such as line number info emplaced by the batch code,
causes the display code to treat -20 differently.

(%i1) :lisp (displa '((mplus) 1 -20))
1 + (- 20)
NIL
(%i1) :lisp (displa '((mplus foo) 1 -20))
1 - 20
NIL

The batch code puts in stuff like (17 "foo.mac" SRC) but from
what I can tell, it doesn't matter what the stuff is; FOO has the
same effect.

I'll take a look at the display code. I think the correct output for
the second example above would be the same as the first.

> Also, how should I avoid an ugly "1+-20" expression, but without
> performing the subtraction?

Well, 1 + (- 20) looks correct to me; after all simp:false prevents
Maxima from applying identities such as x + (- y) = x - y.
Perhaps you want to apply just that one identity -- there may be
a way to do it, but I wonder if it's worth the trouble.
I'll let you be the judge of that. Let me know how you want to proceed.

best

Robert Dodier