answered 2 years ago
Sage's symbolic ring has "wildcards" for advanced substitutions.
For example, starting from the expression in the question:
sage: w0 = SR.wild(0) sage: a.subs({sin(w0)/cos(w0): tan(w0)}) tan(x^2 + x + 1)