Ask Your Question

Revision history [back]

The problem is that the cyclotomic field is not well embedded into the complex plane, see my answer of this ask question 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 element 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

sage: Z3 + Z4
-0.50000000000000000? - 1.866025403784439?*I

The problem is that the cyclotomic field is not well embedded into the complex plane, see my answer of this ask question 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 element 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

sage: Z3 + Z4
-0.50000000000000000? - 1.866025403784439?*I

The problem is that the cyclotomic field is not well embedded into the complex plane, see my answer of this ask question 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^4 + 7) 7.5000000000000000? - 0.866025403784439?*I

The problem is that the cyclotomic field is not well embedded into the complex plane, see my answer of this ask questionquestion 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^4 + 7)
7.5000000000000000? - 0.866025403784439?*I

The problem is that the cyclotomic field is not well embedded into the complex plane, 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^4 + 7)
7.5000000000000000? - 0.866025403784439?*I

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^4 (Z4^3 + 7)
7.5000000000000000? - 0.866025403784439?*I
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

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

PREVIOUS ANSWER

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

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

PREVIOUS ANSWER (answering a question about embedding cyclotomic field generators into the algebraic field)

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

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

PREVIOUS ANSWER (answering a question about embedding cyclotomic field generators into the algebraic field)

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