Ticket #12032 (new defect)
Symbolics code passes ungrammatical expressions to maxima
|Reported by:||nbruin||Owned by:||burcin|
Eviatar reports sage-devel thread:
sage: find_maximum_on_interval(-x^2 + 9*x, 4.4, 8) RuntimeError: ECL says: THROW: The catch MACSYMA-QUIT is undefined.
A little investigation with pdb.pm() shows that the error occurs in sage.interfaces.maxima_lib line 420
if statement: result = ((result + '\n') if result else '') + max_to_string(maxima_eval("#$%s$"%statement))
where statement has the value
which is not a valid Maxima expression. The real error is in the code that causes this to happen.
The function maxima_eval is an ECL function, so its parameter gets converted by ECL-lib, outside maxima_lib's control. The string contains a #$...$ reader-macro, which causes the maxima-parser to handle the string. It finds the syntax error and signals it by throwing an uncaught "catch".
Invoking maxima_eval this way isn't particularly wrong, but one should ensure that the expression passed in is at least syntactically correct. If an error condition arises when *evaluating* the expression using maxima_eval, errors are caught more gracefully.
Digging a little deeper shows that find_maximum should not be called with symbolic arguments, so this particular error could be caught earlier. However, I think the symptom shows that the symbolics code should vet its expression a little better before passing it to maxima: The expression isn't accepted by maxima as grammatical.