EDIT: I am not asking how to solve the equation in terms of this variable (as in this supposed duplicate question ), but how to present the expression in the conditions of another, as indicated in the question. I believe the “duplicate” question has a misleading title.
I am very new to SymPy. I have an expression that, once expressed in terms of another expression, should become very pleasant. The problem is that I don’t know how to “force” to express the original expression in terms of another.
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)
C

A.rewrite(B)

A and B can be quite complex expressions. For reference, this is my real 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

St = -(r + 1)**t*(w - S)*sp.log(r + 1)/((r + 1)**t - 1)
St

As soon as I write St in terms of V, I should be able to simplify to get just
St = rS (t) + rV
SymPy.