Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
186 views
ubuntu2404
1
## -*- encoding: utf-8 -*-
2
3
4
# This file was *autogenerated* from the file main.sagetex.sage
5
from sage.all_cmdline import * # import sage library
6
7
_sage_const_226 = Integer(226); _sage_const_1 = Integer(1); _sage_const_21 = Integer(21); _sage_const_13 = Integer(13); _sage_const_254 = Integer(254); _sage_const_277 = Integer(277); _sage_const_6 = Integer(6); _sage_const_8 = Integer(8); _sage_const_12 = Integer(12); _sage_const_15 = Integer(15); _sage_const_0 = Integer(0); _sage_const_105 = Integer(105); _sage_const_210 = Integer(210); _sage_const_420 = Integer(420); _sage_const_20 = Integer(20); _sage_const_308 = Integer(308); _sage_const_314 = Integer(314); _sage_const_16 = Integer(16); _sage_const_323 = Integer(323); _sage_const_348 = Integer(348); _sage_const_17 = Integer(17); _sage_const_396 = Integer(396); _sage_const_408 = Integer(408); _sage_const_2 = Integer(2); _sage_const_3 = Integer(3); _sage_const_5 = Integer(5); _sage_const_7 = Integer(7); _sage_const_11 = Integer(11); _sage_const_24 = Integer(24); _sage_const_449 = Integer(449); _sage_const_468 = Integer(468); _sage_const_513 = Integer(513); _sage_const_524 = Integer(524); _sage_const_45 = Integer(45); _sage_const_9 = Integer(9); _sage_const_566 = Integer(566); _sage_const_576 = Integer(576); _sage_const_101 = Integer(101); _sage_const_30 = Integer(30); _sage_const_10 = Integer(10); _sage_const_50 = Integer(50); _sage_const_40 = Integer(40); _sage_const_634 = Integer(634)## This file (main.sagetex.sage) was *autogenerated* from main.tex with sagetex.sty version 2021/10/16 v3.6.
8
import sagetex
9
_st_ = sagetex.SageTeXProcessor('main', version='2021/10/16 v3.6', version_check=True)
10
_st_.current_tex_line = _sage_const_226
11
_st_.blockbegin()
12
try:
13
# Compute cyclotomic polynomials for n = 1 to 20
14
cyclotomic_data = {}
15
for n in range(_sage_const_1 , _sage_const_21 ):
16
phi_n = cyclotomic_polynomial(n)
17
degree = phi_n.degree()
18
coeffs = phi_n.coefficients(sparse=False)
19
20
cyclotomic_data[n] = {
21
'polynomial': phi_n,
22
'degree': degree,
23
'coefficients': coeffs,
24
'euler_phi': euler_phi(n)
25
}
26
27
# Display cyclotomic polynomials for small n
28
print("Cyclotomic Polynomials Φ_n(x) for n = 1 to 12:")
29
for n in range(_sage_const_1 , _sage_const_13 ):
30
phi_n = cyclotomic_data[n]['polynomial']
31
degree = cyclotomic_data[n]['degree']
32
print(f"Φ_{n}(x) = {phi_n}, degree = {degree}")
33
34
# Verify that degree equals Euler's totient function
35
print("\nVerification: deg(Φ_n) = φ(n)")
36
for n in range(_sage_const_1 , _sage_const_13 ):
37
degree = cyclotomic_data[n]['degree']
38
euler_val = cyclotomic_data[n]['euler_phi']
39
print(f"n = {n}: deg(Φ_{n}) = {degree}, φ({n}) = {euler_val}, Equal: {degree == euler_val}")
40
except:
41
_st_.goboom(_sage_const_254 )
42
_st_.blockend()
43
_st_.current_tex_line = _sage_const_277
44
_st_.blockbegin()
45
try:
46
# Verify the fundamental identity for several values of n
47
print(r"Verification of $x^n - 1 = \prod_{d \mid n} \Phi_d(x)$:")
48
49
for n in [_sage_const_6 , _sage_const_8 , _sage_const_12 , _sage_const_15 ]:
50
# Left side: x^n - 1
51
left_side = x**n - _sage_const_1
52
53
# Right side: product of \Phi_d(x) for all d dividing n
54
divisors = [d for d in range(_sage_const_1 , n+_sage_const_1 ) if n % d == _sage_const_0 ]
55
right_side = _sage_const_1
56
for d in divisors:
57
right_side *= cyclotomic_polynomial(d)
58
59
# Verify equality (no need to expand - SageMath polynomials are already expanded)
60
equality = (left_side == right_side)
61
62
print(f"n = {n}: divisors = {divisors}")
63
print(f" x^{n} - 1 = {left_side}")
64
print(f" Product = {right_side}")
65
print(f" Equal: {equality}")
66
67
# Analyze coefficient patterns in cyclotomic polynomials
68
print("\nCoefficient analysis:")
69
for n in [_sage_const_105 , _sage_const_210 , _sage_const_420 ]: # Cases where coefficients exceed ±1
70
if n <= _sage_const_20 : # Only for computed cases
71
continue
72
phi_n = cyclotomic_polynomial(n)
73
coeffs = phi_n.coefficients(sparse=False)
74
max_coeff = max(abs(c) for c in coeffs)
75
print(f"\\Phi_{n}(x): max |coefficient| = {max_coeff}")
76
except:
77
_st_.goboom(_sage_const_308 )
78
_st_.blockend()
79
_st_.current_tex_line = _sage_const_314
80
_st_.blockbegin()
81
try:
82
# Analysis of roots structure for visualization
83
print("Roots of Unity Analysis:")
84
for n in [_sage_const_6 , _sage_const_8 , _sage_const_12 , _sage_const_16 ]:
85
all_roots = n
86
primitive_roots = euler_phi(n)
87
print(f"n = {n}: Total {n}-th roots of unity: {all_roots}")
88
print(f" Primitive {n}-th roots of unity: {primitive_roots}")
89
print(f" Cyclotomic polynomial Φ_{n}(x) has degree {primitive_roots}")
90
except:
91
_st_.goboom(_sage_const_323 )
92
_st_.blockend()
93
_st_.current_tex_line = _sage_const_348
94
_st_.blockbegin()
95
try:
96
# Analyze Galois groups for cyclotomic fields
97
print("Galois Groups of Cyclotomic Fields Q(ζ_n)/Q:")
98
99
galois_data = {}
100
for n in range(_sage_const_1 , _sage_const_17 ):
101
# Units group (Z/nZ)*
102
units_group = Integers(n).unit_group()
103
group_order = units_group.order()
104
group_structure = units_group.invariants()
105
106
# Field degree [Q(ζ_n) : Q] = φ(n)
107
field_degree = euler_phi(n)
108
109
galois_data[n] = {
110
'field_degree': field_degree,
111
'group_order': group_order,
112
'group_structure': group_structure,
113
'units_group': units_group
114
}
115
116
print(f"n = {n:2d}: [Q(ζ_{n}) : Q] = {field_degree:2d}, "
117
f"|Gal| = {group_order:2d}, structure = {group_structure}")
118
119
# Detailed analysis for specific cases
120
print("\nDetailed Galois group analysis:")
121
122
interesting_cases = [_sage_const_8 , _sage_const_12 , _sage_const_15 , _sage_const_16 , _sage_const_20 ]
123
for n in interesting_cases:
124
if n >= len(galois_data):
125
continue
126
127
units = Integers(n).unit_group()
128
elements = [a for a in range(_sage_const_1 , n) if gcd(a, n) == _sage_const_1 ]
129
130
print(f"\nn = {n}: Q(ζ_{n})/Q")
131
print(f" Units (Z/{n}Z)* = {{{', '.join(map(str, elements))}}}")
132
print(f" Group structure: {units.invariants()}")
133
print(f" Cyclic: {units.is_cyclic()}")
134
135
# Generator information for cyclic groups
136
if units.is_cyclic():
137
# Find a generator
138
for a in elements:
139
order = Integers(n)(a).multiplicative_order()
140
if order == len(elements):
141
print(f" Generator: {a} (order {order})")
142
break
143
except:
144
_st_.goboom(_sage_const_396 )
145
_st_.blockend()
146
_st_.current_tex_line = _sage_const_408
147
_st_.blockbegin()
148
try:
149
# Analyze ramification patterns
150
print("Ramification Analysis in Cyclotomic Fields:")
151
152
def analyze_ramification(n):
153
"""Analyze ramification of primes in Q(ζ_n)"""
154
print(f"\nQ(ζ_{n})/Q ramification:")
155
156
# Get prime divisors of n
157
n_factorization = factor(n)
158
ramified_primes = [p for p, e in n_factorization]
159
160
print(f" n = {n} = {n_factorization}")
161
print(f" Ramified primes: {ramified_primes}")
162
163
# Analyze each small prime
164
for p in [_sage_const_2 , _sage_const_3 , _sage_const_5 , _sage_const_7 , _sage_const_11 ]:
165
if p > n:
166
break
167
168
if p not in ramified_primes:
169
# Unramified case - compute splitting behavior
170
if gcd(p, n) == _sage_const_1 :
171
f = Integers(n)(p).multiplicative_order()
172
else:
173
f = "undefined"
174
print(f" p = {p}: unramified, inertia degree f = {f}")
175
else:
176
# Ramified case - find the exponent of p in the factorization
177
ramification_index = _sage_const_0
178
for prime, exp in n_factorization:
179
if prime == p:
180
ramification_index = exp
181
break
182
totally_ramified = ramification_index == _sage_const_1
183
print(f" p = {p}: ramified (e = {ramification_index}), "
184
f"totally ramified: {totally_ramified}")
185
186
# Analyze several cyclotomic fields
187
for n in [_sage_const_8 , _sage_const_12 , _sage_const_15 , _sage_const_20 , _sage_const_24 ]:
188
analyze_ramification(n)
189
except:
190
_st_.goboom(_sage_const_449 )
191
_st_.blockend()
192
_st_.current_tex_line = _sage_const_468
193
_st_.blockbegin()
194
try:
195
import os
196
if not os.path.exists('figures'):
197
os.makedirs('figures')
198
199
# Demonstrate quadratic reciprocity computations
200
print("Quadratic Reciprocity Examples:")
201
202
def legendre_symbol(a, p):
203
"""Compute Legendre symbol (a/p)"""
204
return kronecker_symbol(a, p)
205
206
def verify_reciprocity(p, q):
207
"""Verify quadratic reciprocity for primes p, q"""
208
left_side = legendre_symbol(p, q) * legendre_symbol(q, p)
209
right_side = (-_sage_const_1 )**((p-_sage_const_1 )//_sage_const_2 * (q-_sage_const_1 )//_sage_const_2 )
210
return left_side == right_side
211
212
# Test quadratic reciprocity for several prime pairs
213
prime_pairs = [(_sage_const_3 , _sage_const_5 ), (_sage_const_3 , _sage_const_7 ), (_sage_const_5 , _sage_const_7 ), (_sage_const_7 , _sage_const_11 ), (_sage_const_11 , _sage_const_13 ), (_sage_const_13 , _sage_const_17 )]
214
215
for p, q in prime_pairs:
216
leg_p_q = legendre_symbol(p, q)
217
leg_q_p = legendre_symbol(q, p)
218
product = leg_p_q * leg_q_p
219
expected = (-_sage_const_1 )**((p-_sage_const_1 )//_sage_const_2 * (q-_sage_const_1 )//_sage_const_2 )
220
verified = verify_reciprocity(p, q)
221
222
print(f"p = {p}, q = {q}: ({p}/{q}) = {leg_p_q:2d}, ({q}/{p}) = {leg_q_p:2d}")
223
print(f" Product = {product:2d}, Expected = {expected:2d}, Verified: {verified}")
224
225
# Analysis summary for the visualization
226
print("\nQuadratic reciprocity visualization generated showing Legendre symbols.")
227
print("The reciprocity pattern demonstrates the fundamental law:")
228
print("For distinct odd primes p, q: (p/q)(q/p) = (-1)^((p-1)/2 * (q-1)/2)")
229
230
# Additional analysis of specific cases
231
print("\nDetailed reciprocity analysis:")
232
small_primes = [_sage_const_3 , _sage_const_5 , _sage_const_7 , _sage_const_11 , _sage_const_13 ]
233
for i, p in enumerate(small_primes):
234
for j, q in enumerate(small_primes):
235
if i < j: # Only examine pairs once
236
symbol_pq = legendre_symbol(p, q)
237
symbol_qp = legendre_symbol(q, p)
238
print(f"({p}/{q}) = {symbol_pq:2d}, ({q}/{p}) = {symbol_qp:2d}, Product = {symbol_pq * symbol_qp:2d}")
239
except:
240
_st_.goboom(_sage_const_513 )
241
_st_.blockend()
242
_st_.current_tex_line = _sage_const_524
243
_st_.blockbegin()
244
try:
245
# Investigate cyclotomic class numbers
246
print("Class Numbers of Cyclotomic Fields:")
247
248
def compute_cyclotomic_info(n):
249
"""Compute information about the n-th cyclotomic field"""
250
# For computational feasibility, we focus on small n
251
if n > _sage_const_20 :
252
return None
253
254
field_degree = euler_phi(n)
255
discriminant_factor_count = len([p for p, e in factor(n)])
256
257
return {
258
'n': n,
259
'degree': field_degree,
260
'conductor': n,
261
'discriminant_complexity': discriminant_factor_count
262
}
263
264
# Analyze cyclotomic fields
265
cyclotomic_info = []
266
for n in range(_sage_const_1 , _sage_const_21 ):
267
info = compute_cyclotomic_info(n)
268
if info:
269
cyclotomic_info.append(info)
270
271
print("Cyclotomic Field Data:")
272
print("n degree conductor discriminant_complexity")
273
print("-" * _sage_const_45 )
274
for info in cyclotomic_info:
275
print(f"{info['n']:2d} {info['degree']:3d} {info['conductor']:3d} {info['discriminant_complexity']:3d}")
276
277
# Focus on specific interesting cases
278
interesting_fields = [_sage_const_7 , _sage_const_8 , _sage_const_9 , _sage_const_12 , _sage_const_15 , _sage_const_16 , _sage_const_20 ]
279
print(f"\nDetailed analysis for selected cyclotomic fields:")
280
281
for n in interesting_fields:
282
if n <= _sage_const_20 :
283
phi_n = euler_phi(n)
284
units_structure = Integers(n).unit_group().invariants()
285
print(f"Q(ζ_{n}): degree {phi_n}, Gal ≅ {units_structure}")
286
except:
287
_st_.goboom(_sage_const_566 )
288
_st_.blockend()
289
_st_.current_tex_line = _sage_const_576
290
_st_.blockbegin()
291
try:
292
# Analyze computational complexity of cyclotomic polynomial operations
293
print("Computational Complexity Analysis:")
294
295
def time_cyclotomic_computation(n_max):
296
"""Analyze timing for cyclotomic polynomial computations"""
297
import time
298
299
timing_data = []
300
301
for n in range(_sage_const_1 , min(n_max + _sage_const_1 , _sage_const_101 )): # Limit for computational feasibility
302
start_time = time.time()
303
304
# Compute cyclotomic polynomial
305
phi_n = cyclotomic_polynomial(n)
306
degree = phi_n.degree()
307
height = max(abs(c) for c in phi_n.coefficients(sparse=False))
308
309
end_time = time.time()
310
computation_time = end_time - start_time
311
312
timing_data.append({
313
'n': int(n),
314
'degree': int(degree),
315
'height': int(height),
316
'time': float(computation_time)
317
})
318
319
if n <= _sage_const_30 or n % _sage_const_10 == _sage_const_0 :
320
print(f"n = {n:3d}: degree = {degree:3d}, "
321
f"height = {height:4d}, time = {computation_time:.4f}s")
322
323
return timing_data
324
325
# Perform timing analysis for moderate values
326
print("Timing analysis for cyclotomic polynomial computation:")
327
timing_results = time_cyclotomic_computation(_sage_const_50 )
328
329
# Summary analysis of complexity results
330
print("\nComplexity Analysis Summary:")
331
print(f"Analyzed cyclotomic polynomials for n = 1 to {len(timing_results)}")
332
333
n_values = [data['n'] for data in timing_results]
334
degrees = [data['degree'] for data in timing_results]
335
heights = [data['height'] for data in timing_results]
336
times = [data['time'] for data in timing_results]
337
338
print(f"Maximum degree observed: {max(degrees)} (for n = {n_values[degrees.index(max(degrees))]})")
339
print(f"Maximum coefficient height: {max(heights)} (for n = {n_values[heights.index(max(heights))]})")
340
print(f"Total computation time: {sum(times):.4f} seconds")
341
342
# Highlight some interesting cases
343
interesting_n = [_sage_const_12 , _sage_const_15 , _sage_const_20 , _sage_const_24 , _sage_const_30 , _sage_const_40 ]
344
print("\nComplexity for selected values:")
345
for n in interesting_n:
346
if n <= len(timing_results):
347
idx = n - _sage_const_1
348
print(f"n = {n:2d}: degree = {degrees[idx]:2d}, height = {heights[idx]:3d}, time = {times[idx]:.4f}s")
349
except:
350
_st_.goboom(_sage_const_634 )
351
_st_.blockend()
352
_st_.endofdoc()
353
354
355