Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
248 views
in Technique[技术] by (71.8m points)

symbolic math - how to construct sub-expressions with only two variables and one arithmatic operation from complex Expression Maple/Matlab?

let the Symbolic expression is as below.

y = s + (a/b)*log((a+c)/(b*a)); %# it can be any type of expression

how can I get all possible sub-expressions with two variables and one operator between them.

subExpression1 = b*a;
subExpression2 = a/b;

I got stuck whlie extracting sub-expressions based on operator. if I read one operator I have to study its LHS and RHS and verify that it operates just on one variable but not a other subexpression.

Is there a way to study both LHS and RHS of a operator ??

any comments and suggestions would be very helpful

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Firstly, there is no subexpression a*b in your expression. Inside the call to log in your unparsed input there appears a subterm c/b*a. But in Maple's syntax that gets parsed to something mathematically equivalent to (c*a)/b and not c/(b*a).

But your question contains other ambiguity. Let's consider a few examples:

restart;

expr1 := y = s + (a/b)*log(a+c/b*a);

                                  c a
                         a ln(a + ---)
                                   b
        expr1 := y = s + -------------
                               b

expr2 := y = s + a*log(a+c/b*a)/b;

                                  c a
                         a ln(a + ---)
                                   b
        expr2 := y = s + -------------
                               b

expr2 - expr1;

                    0 = 0

So the expr1 and expr2 are mathematically equivalent. Maple is even holding their structures the same, internally. (You can check that using both the lprint and the dismantle commands.)

So you appear to be asking for a/b to be recognized in either, after parsing the input, even though that term does not appear indentically in the verbatim input (before parsing). That's not wrong, per se, but we'll need to know that it's part of your expectation. If a/b is to be recognized as a candidate subpression of that value, regardless of whether it's entered like expr1 or expr2, then that is a key detail. If that is not your desire then you will really have to justify how they could be distinguished from each other after parsing (since they may parse to the same thing, depending on what's occurred already in the Maple session!).

Also, how do you intend on handling something which is mathematically equivalent to (a*s)/(b)? Do you want code that returns all possible arithmetic pairings, eg. a*s, a/b, s/b? Or do you want just a*s, or just a/b, or just s/b?

Now consider another example:

expr3 := a+c*a/b;

                            c a
               expr3 := a + ---
                             b

normal(expr3);

                   a (b + c)
                   ---------
                       b

Those are mathematically equivalent, though stored differently. Depending on your definition of acceptable "sub-expression" you may or may not want want a/b, or c/b, or b+c, in your results.

I think that you'll probably need to resolve what precisely you want, in at least these three example's ambiguous situations above, before your question could be resolved sensibly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...