how to use "maxima --batch" *reliably* ??



On Tue, Feb 26, 2008 at 01:13:34PM -0800, Mike Hansen wrote:
> >  Oliver, you might take a look at the list of related projects,
> >  http://maxima.sourceforge.net/relatedprojects.shtml
> >  Various kinds of systems which use Maxima as a computational
> >  engine have been implemented.
> 
> In particular, you may want to look at Sage which provides a Python
> interface to Maxima (amongst other things).  If a situation arises
> where Maxima needs additional input, an exception is raised.  If that
> exception is not handled, then the Python script will exit with a
> status of 1.  Here is an example of how to use the interface in the
> most basic/explicit way:
> 
> sage: maxima.eval('2+2')
> '4'
> sage: maxima.eval('integrate((1+v^2/c^2)^3/(1-v^2/c^2)^(3/2),v)')
> Traceback (most recent call last):
> ...
> ValueError: Computation failed since Maxima requested additional
> constraints (use assume):
> Is  c  zero or nonzero?
> 
> It is also used behind the scenes  for things like the following:
> sage: integrate(x^2,x)
> x^3/3
>

Thanks, this might be useful for the future (though I actually wanted
to escape Sage by using the involved computer-algebra systems (like
Maxima) directly, avoiding this further level of indirection --- however
my system also uses Sage, and so it's there anyway).

Yet I'll solve the problem as follows:

My context is actually rather restricted, since I do not want to run
computations, but I just want to run the (Maxima) higher-order unit test system
I've written (run by the bigger system, of which the Maxima-level is only
a part). So all the errors are actually created by a Maxima-assert-function,
and this assert-function shall then in case of an error write to some
file, so that the build system (of *my* system) can catch the error.
(As an aside, "higher-order unit test system" means among other things
that test-functions are part of the library provided, they state generic
axioms, and can use other test-functions.)

I'll also redirect the output to some log-file, and from time to time it
needs to be inspected (perhaps it's also parsed automatically for some
key words).

Thanks Richard and Stavros for pointing out problems, but it seems that
in my case those aren't show-stoppers:

1) "Maxima often asks questions in the middle of a calculation (e.g. Is
    x>0?)."

I don't know what happens in batch-mode, but if it stops execution, fine, then
the person running the automatic test will become aware of the problem,
or otherwise hopefully my assert will trigger.

2) "Maxima errors are not designed for consumption by other programs."

My system just needs to become aware that something is wrong, and then
good old manual inspection is performed.

3) "Some errors are not clean."

Hopefully the same as 2): I just need to find out some "something" happened.

4) "Startup time is long."

Sure, from a program which wants to send every millisecond some task to Maxima
that looks bad, but for the testing-purposes that seems negligible.

Thanks for the useful replies!

Oliver