Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Half of your question is easier to answer. I bet if you do

var('theta,x,Psi')
y=cos(theta)^2*sin(theta)^2*cos(Psi)
y.subs_expr(cos(theta)^2*sin(theta)^2==x)

you won't get the theta |--> bit. That is because you are defining a function, not just an expression, in your example.

For substituting more advanced expressions, you will probably have to use wildcards. Note that

sage: y.subs_expr(cos(theta)^2==x)
x*cos(Psi)*sin(theta)^2

works; it's the fact that your expression isn't just one thing, but a product, that probably messes things up.

sage: y.subs({cos(theta)^2*sin(theta)^2*w0:x*w0})
x*cos(Psi)

but keep in mind that for your more complex expression you may need to have a more complicated use of wildcards. Good luck!