The Semantics of EV (part 1)



Below find a write-up about the semantics of EV.  I am mailing it in two
parts, because (a) the Maxima list limits messages to 40kb (until the
moderator approves it, and I think Jim is going to be away for a while);
and (b) Microsoft's HTML is incredibly bloated, so what is 7kb in plain
ASCII becomes 43kb when lightly formatted for legibility in HTML mail
(and goddamn Outlook doesn't work properly with standard HTML).  Let me
know if the result is at least reasonably legible on your end.

 _____

In private email, Dan Stanger asked about the semantics of ev; since the
answer may be of general interest, I$B!G(Bm sending it to the list.

Here$B!G(Bs the specific issue that Dan came up against.  The following
sequence works as expected:

nounversion: 'integrate(x,x)$
verbversion: subst(verbify('integrate),nounify('integrate),nounversion)$
ev(verbversion);
   $B"*(B x^2/2

but if you try to combine the last two steps, it doesn$B!G(Bt:

ev(subst(verbify('integrate),nounify('integrate),nounversion))
   $B"*(B 'integrate(x,x)

So how can you combine the last two steps? ... Well, the quick answer
is:

ev(subst(verbify('integrate),nounify('integrate),nounversion),eval)
   $B"*(B x^2/2

Using the command-line notation:

subst(verbify('integrate),nounify('integrate),nounversion),eval
   $B"*(B x^2/2

But why should this be true? Understanding it requires some discussion
of the semantics (if you can call them that) of ev.
 _____

The first thing to know about ev is that the command line ...,... is
precisely equivalent to ev(...,...).   Nota bene: the ...,... syntax for
ev is not available anywhere else in Maxima.  Also, the command line ...
(with no commas) is confusingly not in general equivalent to ev(...).

The basic intuition behind ev is not evaluation, despite its name.  It
is modification of evaluation.  That is, x^2,x=3 or ev(x^2,x=3)should be
thought of as something like: interpret the expression x^2 in the
context where x=3. A better name for ev might have been with_modifiers.
But  ev actually has a very broad range of functions, all based on the
convenience of the "," syntax.

For the remainder of this mail, I use the syntax ev(x,y) instead of the
command-line syntax x,y for clarity.

The documentation says that ev $B!H(Bis one of MACSYMA$B!G(Bs [sic] most
powerful and versatile commands.$B!I(B Spin-free version: it is sprawling,
confusing, and inconsistent, full of
<http://developer.syndetic.org/query_jargon.pl?term=feature>;
misfeatures, warts, and bells and whistles. The documentation describes
these inconsistencies pretty accurately, so you can$B!G(Bt call them bugs (a
documented bug is a feature, after all). But I would certainly call them
errors at the conceptual or design level.

The confusing thing in Dan's example is that one might expect ev to be
the Maxima equivalent of Lisp eval; it is not. Its main argument is
normally only evaluated once (with caveats, see below). Let me
demonstrate. I$B!G(Bll define a function which helps count evaluations:

counteval(n):= funmake('counteval,[n+1])$

Now, with normal evaluation:

 counteval(0)  $B"*(B counteval(1)
'counteval(0)  $B"*(B counteval(0)

And with ev:

ev(counteval(0))  $B"*(B counteval(1)

In addition, ev lets you control evaluation more finely (I have set
noundisp:true so that noun forms are displayed with a quotation mark '):

ev(counteval(0),noeval) $B"*(B counteval(0)
ev(counteval(0),eval) $B"*(B counteval(2)
    Note that you can$B!G(Bt use ev(ev(x)) instead of ev(x,eval).
ev(counteval(0),eval,eval) $B"*(B counteval(3)
ev(counteval(0),infeval) $B"*(B infinite loop
ev('counteval(0)) $B"*(B 'counteval(0)
ev('counteval(0),eval) $B"*(B 'counteval(0)
        eval doesn$B!G(Bt affect nouns; recall that 'f(x) means
   apply(nounify('f),[x]), which is different from
   ('f)(x), which means apply('f,[x]).
ev('counteval(0),counteval) $B"*(B counteval(1)
   Think of this as meaning "evaluate ... while treating the noun-form
of
        counteval as a verb form".
ev('counteval(0),nouns) $B"*(B counteval(1)

<<< Continued in part 2 >>>