I am trying to simplify a large expression by substitution of common smaller expressions.
Here is the full expression:
For instance, I would like to do:
exp.subs(L_r*cos(alpha)-L_p*sin(alpha),L_r_tilde))
The expression can be found twice in the 1. I also tried to substitute a smaller expression with the same approach, but SymPy requires factorization in the first step to perform the substitution.
This one works:
small_exp = L_p*sin(alpha)**2-L_r*sin(alpha)*cos(alpha)
small_exp_factorized = small_exp.factor()
small_exp_factorized.subs(L_p*sin(alpha)-L_r*cos(alpha),L_r_tilde)
leading to L_r_tilde*sin(alpha)
but without prior factorization SymPy fails to substitute.
Is it possible to substitute all common expressions without factorization or further manipulation of the large expression from above?