There is already a "routine" called coercion
sage: P = QQ['x','y','z']['u','v']['a']['s','t']
sage: R = QQ['x']['y']['z']['u']['v']['a']['s']['t']
Generators of P:
sage: Px,Py,Pz,Pu,Pv,Pa,Ps,Pt = map(P, 'xyzuvast')
Generators of R:
sage: Rx,Ry,Rz,Ru,Rv,Ra,Rs,Rt = map(R, 'xyzuvast')
A polynomial on P
sage: p = (Px + Pu*(Py*Pz +Pa)) * (1 + Ps + Pt) * (1 + Px)
Its equivalent on R
sage: r = R(p)
Of course, this is not completely automatic like
sage: p.as_I_want()
Note that the data structure used for the above polynomial r will be
*very* slow compared to using directly the multivariate polynomial ring
QQ['x','y','z','u','v','a','s','t']. So I would rather advice you to try
hard using this one instead of the recursive version.
Vincent