Executing g=R(f) calls the __call__ method for the ring R. You should read the documentation for this (by executing R.__call__?). In summary: given two polynomial rings U and R, if every generator of U is a generator for R, then R(f) does the obvious thing, mapping each generator of U to the generator of R with the same name. Otherwise, if U has at most as many generators as R, then map the ith generator of U to the ith generator of R. Otherwise, U must have more generators, so raise an error. Your case fits into this last situation.