CoCalc Public Files
Author: William A. Stein
1Demo -- 20071031
2system:sage
3
4{{{id=0|
5version()
6///
7'SAGE Version 2.8.9, Release Date: 2007-10-25'
8}}}
9
10{{{id=8|
11
12}}}
13
14<h1> Ideal Congruence </h1>
15
16{{{id=1|
17K.<i> = NumberField(x^2 + 1)
18I = K.fractional_ideal(3 + 4*i)
19I
20///
21Fractional ideal (4*i + 3)
22}}}
23
24{{{id=2|
25# Test to see if (1+2*i) and (4+6*i) are congruent modulo the ideal I:
26(1 + 2*i) - (4 + 6*i) in I
27///
28True
29}}}
30
31{{{id=26|
32# They are.  Test another congruence, where they aren't.
33(3 + 2*i) - (4 + 6*i) in I
34///
35False
36}}}
37
38{{{id=29|
39# Test to see if (1+2*i) and (4+6*i) are congruent modulo the ideal I^2:
40(1 + 2*i) - (4 + 6*i) in I^2
41///
42False
43}}}
44
45{{{id=31|
46
47}}}
48
49{{{id=28|
50
51}}}
52
53{{{id=3|
54
55}}}
56
57<h1> Fractional Ideal Factorization </h1>
58
59{{{id=5|
60K.<a> = NumberField(x^3 + x^2 - 2*x + 8); K
61///
62Number Field in a with defining polynomial x^3 + x^2 - 2*x + 8
63}}}
64
65{{{id=32|
66I = K.fractional_ideal(2)
67}}}
68
69{{{id=33|
70F = I.factor(); F
71///
72(Fractional ideal (1/2*a^2 - 1/2*a + 1)) * (Fractional ideal (a^2 - 2*a + 3)) * (Fractional ideal (3/2*a^2 - 5/2*a + 4))
73}}}
74
75{{{id=34|
76J = F[0][0]; J
77///
78Fractional ideal (1/2*a^2 - 1/2*a + 1)
79}}}
80
81{{{id=36|
82J.is_prime()
83///
84True
85}}}
86
87{{{id=38|
88J.residue_class_degree()
89///
901
91}}}
92
93{{{id=35|
94M = K.fractional_ideal(17) * F[1][0]^5; M
95///
96Fractional ideal (-17*a^2 - 34*a + 51)
97}}}
98
99{{{id=6|
100M.factor()[0][0]
101///
102Fractional ideal (a^2 + 11*a + 23)
103}}}
104
105{{{id=41|
106
107}}}
108
109{{{id=40|
110
111}}}
112
113{{{id=39|
114
115}}}
116
117{{{id=7|
118
119}}}
120
121<h1> Computation of Rings of Integers</h1>
122
123{{{id=43|
124K.<a> = NumberField(x^3 + x^2 - 2*x + 8); K
125///
126Number Field in a with defining polynomial x^3 + x^2 - 2*x + 8
127}}}
128
129{{{id=42|
130R = K.maximal_order(); R
131///
132Maximal Order in Number Field in a with defining polynomial x^3 + x^2 - 2*x + 8
133}}}
134
135{{{id=9|
136R.basis()
137///
138[1, 1/2*a^2 + 1/2*a, a^2]
139}}}
140
141{{{id=49|
142
143}}}
144
145{{{id=70|
146# Try a ring of integers where factoring is clearly the bottleneck.
147}}}
148
149{{{id=48|
150p = next_prime(10^24); q = next_prime(10^26); D = p*q; D
151///
152100000000000000000000000767000000000000000000000469
153}}}
154
155{{{id=47|
156time K.<b> = NumberField(x^2 - D)
157///
158CPU time: 2.36 s,  Wall time: 2.83 s
159}}}
160
161{{{id=44|
162# Computing just the p-maximal order is fast.
163time K.maximal_order(p).basis()
164///
165[1, b]
166Time: CPU 0.01 s, Wall: 0.01 s
167}}}
168
169{{{id=45|
170time K.maximal_order(q).basis()
171///
172[1, b]
173CPU time: 0.01 s,  Wall time: 0.01 s
174}}}
175
176{{{id=51|
177time K.maximal_order().basis()
178///
179[1/2*b + 1/2, b]
180CPU time: 2.37 s,  Wall time: 2.85 s
181}}}
182
183{{{id=50|
184time factor(D)
185///
1861000000000000000000000007 * 100000000000000000000000067
187CPU time: 2.36 s,  Wall time: 2.87 s
188}}}
189
190{{{id=46|
191
192}}}
193
194{{{id=10|
195
196}}}
197
198<h1> Construction of General Orders</h1>
199
200{{{id=55|
201K.<c> = NumberField(x^3 - 2); K
202///
203Number Field in c with defining polynomial x^3 - 2
204}}}
205
206{{{id=54|
207c^3
208///
2092
210}}}
211
212{{{id=53|
213R = K.order([2*c]); R
214///
215Order in Number Field in c with defining polynomial x^3 - 2
216}}}
217
218{{{id=12|
219R.basis()
220///
221[1, 2*c, 4*c^2]
222}}}
223
224{{{id=58|
225factor( R.discriminant() )
226///
227-1 * 2^8 * 3^3
228}}}
229
230{{{id=57|
231factor( K.discriminant() )
232///
233-1 * 2^2 * 3^3
234}}}
235
236{{{id=60|
237R = K.order([13*c + 169*c^2]); R
238///
239Order in Number Field in c with defining polynomial x^3 - 2
240}}}
241
242{{{id=62|
243R.basis()
244///
245[1, 169*c^2 + 13*c, 742417*c^2]
246}}}
247
248{{{id=63|
249n = R.index_in(K.order([2*c])); n
250///
2519651421/8
252}}}
253
254{{{id=61|
255factor(n)
256///
2572^-3 * 13^3 * 23 * 191
258}}}
259
260{{{id=65|
261
262}}}
263
264{{{id=64|
265
266}}}
267
268{{{id=13|
269
270}}}
271
272<h1> Complex Embeddings </h1>
273
274{{{id=67|
275K.<a> = NumberField(x^2 - 5)
276}}}
277
278{{{id=68|
279sigma = K.real_embeddings(); sigma
280///
281[Ring morphism:
282  From: Number Field in a with defining polynomial x^2 - 5
283  To:   Real Double Field
284  Defn: a |--> -2.2360679775, Ring morphism:
285  From: Number Field in a with defining polynomial x^2 - 5
286  To:   Real Double Field
287  Defn: a |--> 2.2360679775]
288}}}
289
290{{{id=69|
291# Plot image of 1 and a under the map z |---> (sigma_0(z), sigma_1(z))
292
293def sig(z):
294    return (sigma[0](z), sigma[1](z))
295
296show(points([sig(1), sig(a)], pointsize=30))
297}}}
298
299{{{id=66|
300# Plot a bunch of points in the ring of integers.
301B = K.maximal_order().basis(); B
302///
303[1/2*a + 1/2, a]
304}}}
305
306{{{id=72|
307# A bug!!  :-(
308z = [sig(i*B[0] + j*B[1]) for i in [-3..3] for j in [-3..3]]
309
310# CRASH...
311///
312Traceback (most recent call last):
313  File "<stdin>", line 1, in <module>
314  File "/home/was/books/ant/sage_notebook/worksheets/admin/5/code/53.py", line 7, in <module>
315    z = [sig(i*B[Integer(0)] + j*B[Integer(1)]) for i in (ellipsis_range(-Integer(3),Ellipsis,Integer(3))) for j in (ellipsis_range(-Integer(3),Ellipsis,Integer(3)))]
316NameError: name 'sig' is not defined
317}}}
318
319{{{id=18|
320
321}}}
322
323{{{id=19|
324
325}}}
326
327<h1> Ideal Norms </h1>
328
329{{{id=75|
330K.<a> = NumberField(x^2 - 5)
331I = K.fractional_ideal(a)
332I.norm()
333///
3345
335}}}
336
337{{{id=74|
338J = K.fractional_ideal(17)
339J.norm()
340///
341289
342}}}
343
344{{{id=21|
345(I*J).norm()
346///
3471445
348}}}
349
350{{{id=83|
351Z =I/J; Z
352///
353Fractional ideal (-1/17*a)
354}}}
355
356{{{id=82|
357Z.norm()
358///
3595/289
360}}}
361
362{{{id=85|
363
364}}}
365
366{{{id=84|
367
368}}}
369
370{{{id=22|
371
372}}}
373
374<h1> Class Groups </h1>
375
376{{{id=24|
377K.<a> = NumberField(x^2 + 23)
378}}}
379
380{{{id=76|
381C = K.class_group()
382}}}
383
384{{{id=77|
385C
386///
387Class group of order 3 with structure C3 of Number Field in a with defining polynomial x^2 + 23
388}}}
389
390{{{id=25|
391G = C.gens(); G
392///
393[Fractional ideal class (2, 1/2*a - 1/2)]
394}}}
395
396{{{id=78|
397I = G[0]; I
398///
399Fractional ideal class (2, 1/2*a - 1/2)
400}}}
401
402{{{id=79|
403I^2
404///
405Fractional ideal class (2, 1/2*a + 1/2)
406}}}
407
408{{{id=80|
409I^3
410///
411Trivial principal fractional ideal class
412}}}
413
414{{{id=81|
415
416}}}
417