answered 1 year ago
Lazy alternative
sage: P._sympy_().subs(sympy.sympify({ x*y: w }))._sage_() 7*w^2 + 5*w*x + 6*w*y + 4*w + x + 2*y + 3*z
HTH,