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

前端 未结 3 395
谎友^
谎友^ 2021-01-29 09:20

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

3条回答
  •  执念已碎
    2021-01-29 09:58

    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.

提交回复
热议问题