CoCalc Public FilesIntegral Representations of Z_23.sagews
Author: Marek Kaluba
Views : 87
Compute Environment: Ubuntu 18.04 (Deprecated)
def degree(elt, ring=None):
if ring is None:
return elt.polynomial().degree()
if ring is not None:
try:
elt = elt.base_extend(ring)
except TypeError as err:
print(err)
print("Define a coercion homomorphism from " + str(elt.parent()) + " to " + str(ring))
else:
return elt.polynomial().degree()

K.<t> = CyclotomicField(23)

assert degree(t^13 + 11*t) == 13, "13"
assert degree(3/4*t^6 + 12*t^8+3*t * t^9) == 10, "10"
assert degree(K(1/3)) == 0, "0"
degree(sqrt(2), ring=K)

no base extension defined Define a coercion homomorphism from Symbolic Ring to Cyclotomic Field of order 23 and degree 22
def coefficient(elt,basis_vector):
higher_powers = elt.list()[degree(basis_vector)+1:]
if sum([abs(x) for x in higher_powers]):
raise Exception("Possible non-unique decomposition! "+ str(higher_powers))
if elt.list()[degree(basis_vector)] == 0:
return 0
coeff_elt = elt.list()[degree(basis_vector)]
highest_coeff_basis_vect = basis_vector.list()[degree(basis_vector)]
coeff = coeff_elt/highest_coeff_basis_vect
return coeff

K.<t> = CyclotomicField(5)
basis = [t^2 + 1, t^4 + 2, t^3 + t + 2]
elt = basis[0] + 3/4*basis[1]
assert coefficient(elt, basis[1]) == 3/4, "3/4"
elt = elt - coefficient(elt, basis[1])*basis[1]
assert coefficient(elt, basis[0]) == 1, "1"
assert coefficient(elt, basis[2]) == 0, "0"

def decompose(elt, basis, integer=True):
decomposition_vector = [0 for _ in basis]

while elt != 0:
for index, basis_elt in enumerate(basis):
if degree(basis_elt) == degree(elt):
break
else:
raise Exception("Cannot decompose " + str(elt)  + ": no polynomial of matching degree in basis!\n" + str(basis))

coeff = coefficient(elt, basis_elt)
if integer:
assert coeff.is_integer(), str(elt) + " is NOT decomposable over integers!"
assert decomposition_vector[index] == 0, "Non-unique decomposition!"
decomposition_vector[index] = coeff
# print(elt, coeff,basis_elt)
elt -= coeff*basis_elt
# print(decomposition_vector)

return decomposition_vector

K.<t> = NumberField(cyclotomic_polynomial(23))
basis = [t^5 + 2, 13*t -5, 6*t^2+ 2*t + 3]
elt_coords = [-2,3,1]
dot = lambda a,b : sum([x[0]*x[1] for x in zip(a,b)])
elt = dot(basis,elt_coords)
assert decompose(elt, basis) == elt_coords, str(basis)

assert decompose(t^13+11*t, K.ideal((47, t + 20)).integral_basis()) == [-5, 11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], "t^13 + 11*t"

try:
decompose(1/3*t^5 + 5*t^8, K.ideal((47, t + 20)).integral_basis())
except AssertionError as err:
print(err)
try:
decompose(3*basis[0] -2*basis[2] - t^4, basis)
except Exception as exc:
print(exc)

decompose(3*basis[0] -2*basis[2] + basis[1], basis)

1/3*t^5 - 220 is NOT decomposable over integers! Cannot decompose -t^4 - 12*t^2 - 4*t - 6: no polynomial of matching degree in basis! [t^5 + 2, 13*t - 5, 6*t^2 + 2*t + 3] [3, 1, -2]
def matrix_from_ideal(ideal):
basis = ideal.integral_basis()
t = ideal.ring().gen()
shifted_basis = [t*v for v in basis]
m = matrix([decompose(elt, basis) for elt in shifted_basis])
return m

K.<t> = CyclotomicField(11)
I = K.ideal(1)
I.gens()
matrix_from_ideal(I)

(1,) [ 0 1 0 0 0 0 0 0 0 0] [ 0 0 1 0 0 0 0 0 0 0] [ 0 0 0 1 0 0 0 0 0 0] [ 0 0 0 0 1 0 0 0 0 0] [ 0 0 0 0 0 1 0 0 0 0] [ 0 0 0 0 0 0 1 0 0 0] [ 0 0 0 0 0 0 0 1 0 0] [ 0 0 0 0 0 0 0 0 1 0] [ 0 0 0 0 0 0 0 0 0 1] [-1 -1 -1 -1 -1 -1 -1 -1 -1 -1]
show(cyclotomic_polynomial(23))
K.<t> = CyclotomicField(23)
K_IdealClassGrp = K.class_group(proof=False);

## takes ~ 1.5h to compute with proof=True (default)
# K_IdealClassGrp = K.class_group();

I = K_IdealClassGrp.gen();
show(I.gens())

m = matrix_from_ideal((I^1).ideal())
assert m^23 == matrix.identity(22)
assert [QQ(round(x^23,6)) for x in m.eigenvalues()] == 22*[1]

$\displaystyle x^{22} + x^{21} + x^{20} + x^{19} + x^{18} + x^{17} + x^{16} + x^{15} + x^{14} + x^{13} + x^{12} + x^{11} + x^{10} + x^{9} + x^{8} + x^{7} + x^{6} + x^{5} + x^{4} + x^{3} + x^{2} + x + 1$
($\displaystyle 47$, $\displaystyle t + 30$, $\displaystyle t^{2} + 40$, $\displaystyle t^{3} + 22$, $\displaystyle t^{4} + 45$, $\displaystyle t^{5} + 13$, $\displaystyle t^{6} + 33$, $\displaystyle t^{7} + 44$, $\displaystyle t^{8} + 43$, $\displaystyle t^{9} + 26$, $\displaystyle t^{10} + 19$, $\displaystyle t^{11} + 41$, $\displaystyle t^{12} + 39$, $\displaystyle t^{13} + 5$, $\displaystyle t^{14} + 38$, $\displaystyle t^{15} + 35$, $\displaystyle t^{16} + 31$, $\displaystyle t^{17} + 10$, $\displaystyle t^{18} + 29$, $\displaystyle t^{19} + 23$, $\displaystyle t^{20} + 15$, $\displaystyle t^{21} + 20$)
(I^1).ideal().integral_basis()
(I^2).ideal().integral_basis()
(I^3).ideal().integral_basis()

[47, t + 30, t^2 + 40, t^3 + 22, t^4 + 45, t^5 + 13, t^6 + 33, t^7 + 44, t^8 + 43, t^9 + 26, t^10 + 19, t^11 + 41, t^12 + 39, t^13 + 5, t^14 + 38, t^15 + 35, t^16 + 31, t^17 + 10, t^18 + 29, t^19 + 23, t^20 + 15, t^21 + 20] [47, t + 44, t^2 + 38, t^3 + 20, t^4 + 13, t^5 + 39, t^6 + 23, t^7 + 22, t^8 + 19, t^9 + 10, t^10 + 30, t^11 + 43, t^12 + 35, t^13 + 11, t^14 + 33, t^15 + 5, t^16 + 15, t^17 + 45, t^18 + 41, t^19 + 29, t^20 + 40, t^21 + 26] [1, t, t^2, t^3, t^4, t^5, t^6, t^7, t^8, t^9, t^10, t^11, t^12, t^13, t^14, t^15, t^16, t^17, t^18, t^19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CyclotomicField(29)
L_class_g = L.class_group(proof=False);
L_class_g
L_class_g.gens()

Class group of order 8 with structure C2 x C2 x C2 of Cyclotomic Field of order 29 and degree 28 (Fractional ideal class (59, t - 26), Fractional ideal class (59, t - 20), Fractional ideal class (59, t - 7))
m = matrix_from_ideal(L_class_g.1.ideal())

show(m)

$\displaystyle \left(\begin{array}{rrrrrrrrrrrrrrrrrrrrrrrrrrrr} -39 & 59 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ -26 & 39 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ -9 & 13 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ -16 & 24 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ -6 & 8 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ -28 & 42 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ -10 & 14 & 0 & 0 & 0 & 0 & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ -30 & 44 & 0 &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