[Maxima] A simple way to parse/check equations?
Juhana Antero Yrjölä
jayrjola at cc.hut.fi
Tue Oct 9 09:59:22 CDT 2007
I have s problem and I was wondering that is there an easy
solution to the following problem.
I have some kind of Maxima equation with functions and possible variables.
Now I need to determine that all function calls are correct and if not
then display the incorrect function name with call parameters (call
parameters are not mandatory but it would be nice).
For example if we have the equation sin(ex(x)+1)+2, where the ex() is an
unknown incorrect function, then the right output would be ex(x). Note
that since sin is correct and it has right number of parameters it
should not display sin(ex(x)+1) . Also note that when testing
the validity of these functions, all validity tests must be done with
original parameter set, for example
diff(x,x,1); is valid but
diff(x,1) is not (this is gives an error, but could be any function
So it is not enough just parse the function names in a list without call
parameters. (The biggest problem with a text parse is that it is difficult
to say which parentheses closes the function call, since there could be
quite many parentheses)
This function must be able to work with more complicated logic as
and recursion must go all the way down.
Unknown()-function in Maxima is very useful but it is not enough. I need
to form a tree(or something like that) and possible even replace some
functions in order to evaluate these (how to replace functions? String
parse?). For example in equation sin(ex(x)+1)+2, it is not enough to just
simply parse the equation into
sin(ex(x)+1) is not valid according to unknown() because of
ex()-function. So we need to make some kind of substitution that would
transform sin(ex(x)+1) into sin(z+1) and then use unknown()-function.
(z is some kind of symbol).
Trust me this is not a joke. As a matter a fact I have implemented this
in a clever way but unfortunately it did not meet all the above
requirements so it was rejected. Any solution to this problem must comply
with all the conditions given above(well a small improvement is better
than nothing). So therefore I am asking your help. Can anyone help me?
I might be able to patch my original code to work if there exist a
Maxima function that is able to say if system has some function. This
function must work with strings. Strings are essential since they are the
only objects that are easily extractable by function
tokens(string,alphacharp), For example to check if system has a function
cos(x) i have the string "cos".
More information about the Maxima