# [Maxima] Disabled function evaluations

Robert Dodier robert.dodier at gmail.com
Wed Jul 16 22:59:25 CDT 2008

On Wed, Jul 16, 2008 at 3:11 PM, Nathaniel E. Powell
<nathan.powell at agilix.com> wrote:

> I am writing a program which uses Maxima for processing, but I also want
> people to be able to typeset expressions / equations in Maxima syntax. I
> want it to be typeset exactly as they type it in rather than being an
> evaluated or simplified version. One solution to this problem I've found is
> to turn off simplification:
>
> simp : false;
>
> and then prepending all of the function calls with the ' operator, which
> prevents things like 1+1 or integrate(x,x) from being simplified. Then, I
> put this expression inside of the Tex function call.
>
> I am wondering if there is a way to avoid having to search for all of the
> function calls and prepend them with a '. In order for them to be properly
> unevaluated (but still properly converted to Tex). I'm wondering if there is
> a global variable switch that does this. I looked around the documentation,
> but I must have missed it if it's there.
>
> I have tried surrounding the expression with '(), but this results in the
> function calls not being converted to Tex properly.

To prevent evaluation, try reading an expression from the console
MREAD takes one argument which is an input stream,
*STANDARD-INPUT* or some stream opened by the Maxima
function openr.

About needing the ' to get appropriate tex output, what's going on here
is that so-called verb operators do not have the same TeX properties as
the corresponding nouns. I think that's a bug.

I thought about ways to work around that and copying TeX properties
doesn't work as expected. The following is the best I could come up with.

nounify_stuff (e) :=
(for x in '[diff, product, sum, integrate, binomial, limit]
do e : subst (nounify (x), verbify (x), e), e)\$

which has the effect of sticking the ' on the operators listed there.
(I picked those 6 because they are the only ones, so far as I can tell,
which need nounification for TeX. There could be others, I guess.)

So here's what I get ...

simp : false;
1 + 1 + sin(x) + diff(sin(x), x, 1) + integrate(sin(x), x);    <--- I
typed it in
tex (foo);
=>  $$1+1+\sin x+{\it diff}\left(\sin x , x , 1\right)+{\it integrate} \left(\sin x , x\right)$$

tex (nounify_stuff (foo));
=>  $$1+1+\sin x+{{d+^{1}}\over{d\,x^1}}\,\sin x+\int {\sin x}{\;dx}$$

Note that the diff expression has to be written with the explicit
degree 1 (which is ordinarily tacked on by simplification).
Without the degree, the TeX code for diff gets confused.

I don't know what you'e doing exactly, but I'll guess that you might
want to just write a custom top-level read-print loop in Lisp to get
more predictable control over simplification and evaluation.

In any event, HTH.

best

Robert Dodier