Search code examples
symbolic-mathmaple

Extract complete argument and function name(s) from the Expression, (standard mathematical functions only) MAPLE


For expressions like

a1 := sin(1+a/b);
a2 := log(1+ a*b);
a3 := abs(a^2+b);

how can I get expressions of respective functions. For example

someCommand(a1)  # should get an output 1+a/b
someCommand(a2)  # should get an output 1+a*b
someCommand(a3)  # should get an output a^2+b

I have tried to get related topics from maple documentation but unfortunately am not able to get exactly.

edited: Also how is it possible to get list (in sequence)of functions used

let

a :=sin(log(abs(a+b)));# functions can be of more than two
someCommand(a) # have to return [{sin, log, abs}, a+b]

Solution

  • In your followup comment to another Answer you gave the further example of sin(log(abs(a+b))). I suspect that you want to be able to slice and dice even more complicated examples.

    You haven't really told use what your final goal is. Perhaps you're trying to build an expression tree. Or perhaps you're evenutally planning on doing something else with this analysis. It'd really help if you told us the final goal.

    Having said that, the following might be of some use to you.

    restart;
    
    ee := "sin(log(abs(a+b))) + sin(s+t) + abs(log(v+w))":
    
    P:=InertForm:-Parse(ee):
    
    lprint(P);
    
    
     `%+`(%sin(%log(%abs(`%+`(a,b)))),%sin(`%+`(s,t)),
          %abs(%log(`%+`(v,w))))
    

    It may be that the above inert form is something you can work with, for whatever your goal might be.

    indets(P, specfunc(name,`%+`));
    
                {a %+ b, s %+ t, v %+ w}
    
    indets(P, specfunc(anything,%abs));
    
           {%abs(a %+ b), %abs(%log(v %+ w))}
    
    indets(P, specfunc(specfunc(name,`%+`),%abs));
    
                    {%abs(a %+ b)}
    
    indets(P, specfunc(specfunc(name,`%+`),%log));
    
                    {%log(v %+ w)}
    

    Using a routine limke from my earlier Answer,

    W := (ee,nm) -> [op(map(`[]`@op,indets(ee,':-specfunc'(nm))))]:
    
    W( indets(P, specfunc(specfunc(name,`%+`),%log)), `%+` );
    
                       [[v, w]]
    
    W( indets(P, specfunc(specfunc(name,`%+`),%sin)), `%+` );
    
                       [[s, t]]
    
    W( indets(P, specfunc(specfunc(name,`%+`),%abs)), `%+` );
    
                       [[a, b]]
    

    There are other ways to get those last results (using something like W on an actual expression and not its inert form, say). I'm just trying to show you how you can do a bit more with it all.