Hi again
Thank you for your speedy responses. This is not a school work is a real
job related stuff. This function is needed in an online learning
enviroment, where it checks that student has valid answer(no wrong
function calls and stuff like that). So it takes about pretty much any
equation, with right syntax(this can be assumed) and
then displays the problem parts to a student.
I was kind of hoping a quick solution to this since I have only 4 workdays
to do this, and I have plenty of other stuff to do (I am leaving the
university so 4 days to do this and many other stuff too).
I am not that fond of writing maxima code and my lisp is bit rusty atm.
Thank you Stavoros Macrakis for very polite answer.
On Tue, 9 Oct 2007, Stavros Macrakis wrote:
> On 10/9/07, Juhana Antero Yrj?l? <jayrjola at cc.hut.fi> wrote:
>> 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
>
> You have two issues here: one is parsing, the other is analysis.
>
> Maxima already does the parsing for you:
>
> EX: x^2-1$
> op(EX) => "+" (Maxima treats the expressions as x^2 + (-1) )
> args(EX) => [ x^2 , -1 ]
>
> (you might also want to look at inflag if you care about the
> underlying internal representations)
>
> As for the analysis, what is your definition of "correct"? In your
> example below, how do you know that ex is "incorrect"? It seems that
> you want to check not only the number but the type of arguments. In
> this case, you will need to build some sort of structure defining
> correct types, e.g.
> argtypes[sin]: [ [ scalar ] ] $
> argtypes[diff]: [ [any, variable], [any, variable, integer]
> ] $ -- Two possibilities
>
> This is not built in to Maxima -- type checking is done by each
> function in an ad hoc way.
>
> Then you code to check the type. And you need to define a policy about
> the interpretation of variables: clearly diff(x,'x,1) is legal, but
> how about diff(Q,R,S)? And your system will probably not want to
> handle all cases: for example, there is no Q such that diff(Q,Q,Q) is
> legal, since Q can't be both an integer and a variable).
>
>> ...recursion must go all the way down.
>
> Maxima (like all modern languages) supports recursion. For example,
> to see if an expression includes the variable Q, you can write
>
> includes_Q(expr):=
> if expr=Q then true
> elseif atom(expr) then false
> else member(true,maplist(includes_Q,expr))$
>
> Good luck. When is the assignment due?
>
> -s
>