Ask Your Question
0

Auto-substitute complex term to ease numeric evaluation

asked 2013-08-07 12:55:00 +0100

Wrzlprmft gravatar image

updated 2013-08-07 12:55:32 +0100

I have a very large symbolic term (mainly composed of sums, products and divisions) and, using substitutions, I want to reformulate it in a way that avoids repetitions and thus can be evaluated using less arithmetic operations.

For example, if I have a term like

X = (d*(a-b)/(1 + a-b))^2 + d*(a-b)/(1 + a-b) + exp(d*(a-b)/(1 + a-b)) + a-b,

I want a function that returns something like:

S1 = a-b
S2 = d*S1/(1+S1)
X  = S2^2 + S2 + exp(S2) + S1

Giving me instructions how to more efficiently calculate X: First calculate S1, then S2 using S1 and finally X using S1 and S2.

My actual problem is much nastier and I do not need optimal or near-optimal results, but any way of automatising such substitutions.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-08-07 21:56:55 +0100

calc314 gravatar image

With some algebraic manipulation and the substitute command, you can partly get what you want. Of course, I think it will depend on how big of a mess the expressions are. For your example above, the following works for me:

X=X.subs(a==S1+b)
X=X.subs(d == S2*1/S1*(1+S1)).simplify()

As you wanted, this produces S2^2 + S1 + S2 + e^S2. Unfortunately, this approach still leaves you to manually determine what S1 and S2 should be, which is not what you wanted. I'm not sure how to automate this completely as you suggest.

edit flag offensive delete link more

Comments

Thank you, but unfortunately, the automatisation (or more specifically the automatic detection of possible substitutions) is what I really need.

Wrzlprmft gravatar imageWrzlprmft ( 2013-08-08 13:02:54 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-08-07 12:55:00 +0100

Seen: 421 times

Last updated: Aug 07 '13