Hello,
I am very new with SymPy. I have an expression that, once expressed in
terms to an other expression, should become very nice.
The problem is that I don't know how to "force" to express the original
expression in terms of the other one.
This is a basic example:
import sympy as sp
sp.init_printing(use_unicode=True)
a,b,c = sp.symbols('a b c')
A = a+b+c
B = a+c
C = A.subs(a+c,B) # Expected/wanted: C = B+b
C
*a+b+c*
A.rewrite(B)
<https://lh3.googleusercontent.com/-dTFaV4UBdfQ/WHzSGKF7OEI/AAAAAAAAX0Q/9mD09Zlc5ckKd5eNggKriOONIFPYCXnTwCLcB/s1600/Screenshot%2Bfrom%2B2017-01-16%2B14-19-24.png>
A and B could be rather complex expressions. For reference, this is my
real-case scenario:
import sympy as sp
sp.init_printing(use_unicode=True)
t, w, r = sp.symbols('t w r')
S = sp.Function('S')(t)
V = (S-w*(1+r)**t)/(((1+r)**t)-1)
V
<https://lh3.googleusercontent.com/-bh_H9tFHIlg/WHzSBxDRejI/AAAAAAAAX0M/ziZoZ6qpYHYJpyB6M_BNol25QOByjFFLwCLcB/s1600/Screenshot%2Bfrom%2B2017-01-16%2B14-24-06.png>
St = -(r + 1)**t*(w - S)*sp.log(r + 1)/((r + 1)**t - 1)
St
<https://lh3.googleusercontent.com/-Q8Bm_MpdWFQ/WHzRQ9hQlFI/AAAAAAAAXz8/3kWRSBBsKSYTXPO1wmHljrxM_wTtf0pcQCLcB/s1600/Screenshot%2Bfrom%2B2017-01-16%2B14-19-24.png>
<https://lh3.googleusercontent.com/-WcqzVsyk7Rg/WHzTwp1OkAI/AAAAAAAAX0c/w4kWfvKqjNAvD91MJte6A1-c5bK8FroUQCLcB/s1600/Screenshot%2Bfrom%2B2017-01-16%2B14-24-28.png>
Once I can write St in terms of V, I should be able to simplify it to get
just
*St = rS(t)+rV*
But I am unable to do it in SymPy. Any hint?
Kind regards,
Antonello Lobianco
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/8777385e-f91a-4e0d-a176-380ce0fe5f34%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.