# Interpreting an element of CyclotomicField as an element of polynomial ring

I am trying to write a function that sums up numbers in different cyclotomic field formally, i.e., as expressions in $z$ where $z$ is the corresponding primitive root of unity. I run into a type error, however, as sage wouldn't let me sum elements of two different cyclotomic fields. Is there a way to typecast an expression in one cyclotomic field into the other, or, better yet, to a polynomial ring?

edit retag close merge delete

Sort by » oldest newest most voted

Hello,

In Sage there is the universal cyclotomic field implemented. It would be much faster than QQbar as proposed by @tmonteil

sage: UCF = UniversalCyclotomicField()
sage: UCF.gen(3)
E(3)
sage: e3 = UCF.gen(3)
sage: e4 = UCF.gen(4)
sage: e3 + e4
E(12)^4 - E(12)^7 - E(12)^11


Vincent

more

Weird, in particular the special case of cyclotomic fields, there is a map from them to QQbar, just do:

sage: C3 = CyclotomicField(3)
sage: z3 = C3.gen()
sage: Z3 = QQbar(UniversalCyclotomicField()(z3))
sage: Z3
-0.500000000000000? + 0.866025403784439?*I


There is definitely an issue with embedded number fields.

( 2015-03-04 04:25:07 -0500 )edit

Indeed! There is a problem

sage: C3 = CyclotomicField(3)
sage: UCF = UniversalCyclotomicField()
sage: UCF.has_coerce_map_from(C3)
True
sage: QQbar.has_coerce_map_from(UCF)
True
sage: QQbar.has_coerce_map_from(C3)
False

( 2015-03-04 04:35:30 -0500 )edit

EDIT: The comment of @BGS indicates that the question migh be understood as follows : given an element of a cyclotomic field, how to recover it as a polynomial of the generator, so that we can "recast" the generator into a generator of another cyclotomic field. Here is a simple solution, involving the .polynomial() method of cyclotomic field elements.

Finding the polynomial:

sage: C7 = CyclotomicField(7)
sage: z7 = C7.gen()
sage: a7 = z7 + 3*z7^2 + 1
sage: a7.polynomial()
x^3 + 3*x^2 + 1
sage: a7.polynomial().parent()
Univariate Polynomial Ring in x over Rational Field


Recasting into another cyclotomic field:

sage: C5 = CyclotomicField(5)
sage: z5 = C5.gen()
sage: a5 = a7.polynomial()(z5)
sage: a5
zeta5^3 + 3*zeta5^2 + 1


That said, the polynomial is not uniquely determined (unless you need the minimal one) and the recasting will depend on the polynomial, since for example:

sage: z5^5 + z5 == z5 + 1
True
sage: z7^5 + z7 == z7 + 1
False


The problem is that the cyclotomic field is not well embedded into the complex plane (more precisely into the field of complex algebraic numbers), see my answer of ask question 25822 for more details about this.

sage: CC(z3)
-0.500000000000000 + 0.866025403784439*I
sage: C3 = CyclotomicField(3)
sage: z3 = C3.gen()
sage: z3
zeta3
sage: CC(z3)
-0.500000000000000 + 0.866025403784439*I


but

sage: QQbar(z3)
TypeError: Illegal initializer for algebraic number


Which is a pity. Let me propose the following fix:

sage: def repair(z):
....:     F = z.parent()
....:     for f in F.embeddings(QQbar):
....:         if CLF(f.im_gens()[0]) - CLF(z) < 1e-14:
....:             return f(z)


The function repair put an generator of some cyclotomic field into the algebraic field QQbar (if n is not too big, so that two generators are at distance larger than 2e-14, but you can adapt the bound if needed).

So you can do:

sage: C3 = CyclotomicField(3)
sage: z3 = C3.gen()
sage: Z3 = repair(z3)
sage: Z3
-0.50000000000000000? - 0.866025403784439?*I
sage: Z3.parent()
Algebraic Field

sage: C4 = CyclotomicField(4)
sage: z4 = C4.gen()
sage: Z4 = repair(z4)
sage: Z4
-1*I
sage: Z4.parent()
Algebraic Field


Then you can do:

sage: Z3 + Z4
-0.50000000000000000? - 1.866025403784439?*I
sage: (Z3^2 + 2*Z3 + 1) + (Z4^3 + 7)
6.5000000000000000? + 0.1339745962155614?*I
sage: ((Z3^2 + 2*Z3 + 1) + (Z4^3 + 7)).minpoly()
x^4 - 26*x^3 + 257*x^2 - 1144*x + 1933

more

Thank you for your prompt reply. This is useful to know, but I had in mind something else. Specifically, what I was trying to do was to recast Z3 as the generator of Z4. I am trying to compute a certain semiclassical approximation, i.e., I try to successively recast a given expression in z as expressions in various cyclotomic fields.

( 2015-03-03 15:04:35 -0500 )edit

I do not understand, Z3 is different from Z4, it is not even an element of C4. Could you please give a concrete example of the behavior you would like to see, so that i can understand ? I edited my answer according to how i understand the question now.

( 2015-03-04 04:08:37 -0500 )edit