# Kernel for maps into iterated PolynomialRings

It's often convenient to construct quotient rings in an iterated fashion, e.g. when localizing a polynomial ring:

B.<x>=QQ[]
C.<y>=B[]


However, Sage complains when I am trying to calculate a kernel of a homomorphism into such an iteratively constructed ring:

A.<a,b>=QQ[]
f=A.hom([x,y],C)
f.kernel()


Here, Sage treats B as the base ring for C and QQ as the base ring for A and kernel() is not implemented for different base rings. I know, that I could simply construct C as

C.<x,y>=QQ[]


to overcome the problem, but in practice B might be the argument of a method and it would be convenient to extend the ring B instead of having to unpick its construction and create a new ring from scratch.

Is there a way to make this work? E.g. by "flattening" such an iterated construction in an automated fashion?

edit retag close merge delete

Sort by ยป oldest newest most voted

Would the following 'flatten' function do the job?

def flatten(R):
v = []
while True:
g = R.gens()
if g[0].is_unit():
break
v.extend(g)
R = R.base_ring()
return PolynomialRing(R,v)

more

Technically this answers my question. Although I was hoping for some built-in solution, which also works when B is not just a PolynomialRing, but a quotient of a PolynomialRing (or a localization). I guess, I will have to unpick these constructions by hand and construct a new ring as in your answer.

( 2023-03-28 08:37:13 +0200 )edit