def make_cyclo_field_elem(coeffs, n): """ Takes a list of (coefficient, power) pairs and a positive integer n and returns an element of the nth cyclotomic field Input: - coeffs: a list of pairs [(a_1, e_1), ... , (a_k, d_k)] of integers - n: an integer specifying the root of unity Output: A field element a_1 * z^e_1 + ... a_k * z^d_k where z is the primitive nth root of unity Example: sage: coeffs = [(5, 4), (1, 2), (3, 0)] sage: n = 7 sage: make_cyclo_field_elem(coeffs, n) 5*zeta_7^4 + zeta_7^2 + 3 """ k = CyclotomicField(n) zeta = k.gen() result = k(0) for coeff, exponent in coeffs: result += k(coeff * zeta^exponent) return result
# Compute (zeta_7^3 + zeta_7^2 - zeta_7) + (2 * zeta_5^3) + (zeta_11^9 + 1) typeset_mode(True) #don't type this if using from the command line # elems is a representation of the elements as lists of (coefficient, power) pairs # could get this from stdin or something or read from file. print('elems =') elems = [ ([(1, 3), (1, 2), (-1, 1)], 7), ([(2, 3)], 5), ([(1, 9), (1, 0)], 10) ]; elems #convert list of pairs into field elements print("field_elems =") field_elems = [make_cyclo_field_elem(coeffs, n) for coeffs, n in elems]; field_elems #make a common field print("m =") m = lcm(elem[1] for elem in elems); m print("L =") L = CyclotomicField(m); L print("common_field_elems =") common_field_elems = [L(x) for x in field_elems]; common_field_elems # add them all together print('sum = ') sum(common_field_elems)
elems =
[([(1, 3), (1, 2), (−1, 1)], 7), ([(2, 3)], 5), ([(1, 9), (1, 0)], 10)]
field_elems =
[ζ73+ζ72−ζ7, 2ζ53, −ζ103+ζ102−ζ10+2]
m =
70
L =
Q(ζ70)
common_field_elems =
[ζ7023+ζ7020−ζ7016−ζ7010+ζ709−ζ702, −2ζ707, −ζ7021+ζ7014−ζ707+2]
sum =
ζ7023−ζ7021+ζ7020−ζ7016+ζ7014−ζ7010+ζ709−3ζ707−ζ702+2