Ask Your Question

# Revision history [back]

You can "collect" terms for a symbolic variable, so if you temporarily replace sqrt(2) with a symbol, you're good to go:

sage: var('R')
R
sage: trm.expand().subs(sqrt(2)==R).collect(R).subs(R=sqrt(2))
sqrt(2)*(3*b + 2*c + d) + 3*a + c + 4*d