Introduction to Algebraic Number Theory Calculations Using Sage

Math 581b, 2010-10-20

William Stein

{{{id=5| /// }}}

Defining Number Fields

{{{id=97| NumberField /// }}} {{{id=24| # or you can do "x = var('x')", which is different but will also work x = polygen(QQ,'x') R. = PolynomialRing(QQ) R. = QQ[] K. = NumberField(x^4 - 2*x^2 - 1) K /// Number Field in a with defining polynomial x^4 - 2*x^2 - 1 }}} {{{id=26| a^4 - 2*a^2 - 1 /// 0 }}} {{{id=90| K = NumberField(x^4 - 2*x^2 - 1, 'alpha') /// }}} {{{id=89| K /// Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 }}} {{{id=91| alpha /// Traceback (most recent call last): File "", line 1, in File "_sage_input_15.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("YWxwaGE="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in File "/private/var/folders/7y/7y-O1iZOGTmMUMnLq7otq++++TI/-Tmp-/tmpMfLU4t/___code___.py", line 2, in exec compile(u'alpha' + '\n', '', 'single') File "", line 1, in NameError: name 'alpha' is not defined }}} {{{id=92| K.gen() /// alpha }}} {{{id=94| K.0 /// alpha }}} {{{id=93| alpha = K.0 s = (1+1/alpha)^10; s /// -120*alpha^3 + 164*alpha^2 + 336*alpha - 324 }}} {{{id=96| s.norm() /// 1024 }}} {{{id=95| show(s) ///
\newcommand{\Bold}[1]{\mathbf{#1}}-120 \alpha^{3} + 164 \alpha^{2} + 336 \alpha - 324
}}}

Remark: Magma (which you may also want to learn) is very similar.

{{{id=86| %magma R := PolynomialRing(RationalField()); K
:= NumberField(x^4 - 2*x^2 - 1); print K; /// Number Field with defining polynomial x^4 - 2*x^2 - 1 over the Rational Field }}} {{{id=98| %magma R := PolynomialRing(RationalField()); K := NumberField(x^4 - 2*x^2 - 17); print K; /// Number Field with defining polynomial x^4 - 2*x^2 - 17 over the Rational Field }}} {{{id=99| %magma K.1 /// K.1 }}} {{{id=100| %magma NumberField(x^4 + 17).1 /// $.1 }}} {{{id=144| print magma_free(r""" R := PolynomialRing(RationalField()); K := NumberField(x^4 - 2*x^2 - 1); print K; print ClassGroup(K);""") /// Number Field with defining polynomial x^4 - 2*x^2 - 1 over the Rational Field Abelian Group of order 1 Mapping from: Abelian Group of order 1 to Set of ideals of Maximal Equation Order with defining polynomial x^4 - 2*x^2 - 1 over its ground order }}} {{{id=143| /// }}}

Remark: Pari (which you also want to learn something of) is different.

{{{id=101| gp.nfinit? /// }}} {{{id=84| %gp k = nfinit(x^4 - 2*x^2 - 1); k /// [x^4 - 2*x^2 - 1, [2, 1], -1024, 1, [[1, -1.5537739740300373073441589530631469482, -0.64359425290558262473544343741820980891, 1.4142135623730950488016887242096980786; 1, 1.5537739740300373073441589530631469482, 0.64359425290558262473544343741820980891, 1.4142135623730950488016887242096980786; 1, 0.E-38 - 0.64359425290558262473544343741820980893*I, 0.E-38 + 1.5537739740300373073441589530631469482*I, -1.4142135623730950488016887242096980786 + 0.E-38*I], [1, -1.5537739740300373073441589530631469482, -0.64359425290558262473544343741820980891, 1.4142135623730950488016887242096980786; 1, 1.5537739740300373073441589530631469482, 0.64359425290558262473544343741820980891, 1.4142135623730950488016887242096980786; 1, -0.64359425290558262473544343741820980893, 1.5537739740300373073441589530631469482, -1.4142135623730950488016887242096980786; 1, 0.64359425290558262473544343741820980893, -1.5537739740300373073441589530631469482, -1.4142135623730950488016887242096980786], [1, -2, -1, 1; 1, 2, 1, 1; 1, -1, 2, -1; 1, 1, -2, -1], [4, 0, 0, 0; 0, 4, 4, 0; 0, 4, -4, 0; 0, 0, 0, 8], [8, 0, 0, 0; 0, 8, 4, 0; 0, 0, 4, 0; 0, 0, 0, 4], [2, 0, 0, 0; 0, 1, 1, 0; 0, 1, -1, 0; 0, 0, 0, 1], [2, [0, 2, 0, 0; 1, 0, 0, 2; 1, 0, 0, 0; 0, 1, 1, 0]]], [-1.5537739740300373073441589530631469482, 1.5537739740300373073441589530631469482, 0.E-38 - 0.64359425290558262473544343741820980893*I], [1, x, x^3 - 2*x, x^2 - 1], [1, 0, 1, 0; 0, 1, 0, 2; 0, 0, 0, 1; 0, 0, 1, 0], [1, 0, 0, 0, 0, 1, 1, 0, 0, 1, -1, 0, 0, 0, 0, 2; 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0; 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, -1, 0, 1, -1, 0; 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0]] }}} {{{id=83| gp.nfbasis? /// }}}

Special kinds of number fields:

{{{id=25| K.
= QuadraticField(5); K /// Number Field in a with defining polynomial x^2 - 5 }}} {{{id=4| a^2 /// 5 }}} {{{id=28| K = CyclotomicField(15); K /// Cyclotomic Field of order 15 and degree 8 }}} {{{id=27| z = K.gen(); z /// zeta15 }}} {{{id=29| z^15 /// 1 }}} {{{id=104| 1/((1+2*z)^3) /// -8878336/36264691*zeta15^7 + 14376704/36264691*zeta15^6 - 12283104/36264691*zeta15^5 + 5069520/36264691*zeta15^4 + 870160/36264691*zeta15^3 - 9827128/36264691*zeta15^2 + 10831182/36264691*zeta15 - 5302797/36264691 }}} {{{id=103| /// }}}

Relative extensions (warning -- basic arithmetic is very slow in some relative extensions, due to the toy implementation.  See trac 9541.)

{{{id=108| K. =NumberField(x^2-5) /// }}} {{{id=110| R. = PolynomialRing(K) /// }}} {{{id=109| L. = K.extension(T^2 - c); L /// Number Field in b with defining polynomial T^2 - c over its base field }}} {{{id=111| b^4 /// 5 }}} {{{id=31| K. = NumberField([x^2 - 2, x^2 - 3, x^2 - 5]); K /// Number Field in a with defining polynomial x^2 - 2 over its base field }}} {{{id=106| b^2 /// 3 }}} {{{id=105| a^2 /// 2 }}} {{{id=107| c^2 /// 5 }}} {{{id=30| a^2 + b^2 + c^2 /// 10 }}} {{{id=34| 1/(a+b+c) /// (-1/12*c*b + 1/4)*a + 1/6*b }}} {{{id=32| K.base_field() /// Number Field in b with defining polynomial x^2 - 3 over its base field }}} {{{id=33| K.base_field().base_field() /// Number Field in c with defining polynomial x^2 - 5 }}} {{{id=17| /// }}}

Elements

  • define
  • do arithmetic
  • compute norm, trace, minpoly, charpoly
  • compute embeddings into C
{{{id=37| var('x') K. = NumberField(x^4 - 2*x^2 - 1); K /// Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 }}} {{{id=36| z = 3*alpha^2 + 5*alpha - 7; z /// 3*alpha^2 + 5*alpha - 7 }}} {{{id=35| show(z) ///
\newcommand{\Bold}[1]{\mathbf{#1}}3 \alpha^{2} + 5 \alpha - 7
}}} {{{id=113| latex(z) /// 3 \alpha^{2} + 5 \alpha - 7 }}} {{{id=39| z^10 /// -828907050*alpha^3 + 1165556429*alpha^2 + 2164036050*alpha - 1977685370 }}} {{{id=63| z.complex_embeddings(200) /// [-7.5262291830309013903157285926866405051139018709206949621333, -8.2426406871192851464050661726290942357090156261308442195300 - 3.2179712645279131236772171870910490446210137122200382557808*I, -8.2426406871192851464050661726290942357090156261308442195300 + 3.2179712645279131236772171870910490446210137122200382557808*I, 8.0115105572694716831258609379448289765319331231823834011934] }}} {{{id=64| @interact def f(n=z): show(points(n.complex_embeddings(), pointsize=50)) /// }}} {{{id=114| phi = K.embeddings(RR); phi /// [ Ring morphism: From: Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 To: Real Field with 53 bits of precision Defn: alpha |--> -1.55377397403004, Ring morphism: From: Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 To: Real Field with 53 bits of precision Defn: alpha |--> 1.55377397403004 ] }}} {{{id=115| phi[0] /// Ring morphism: From: Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 To: Real Field with 53 bits of precision Defn: alpha |--> -1.55377397403004 }}} {{{id=116| phi = K.embeddings(K); phi /// [ Ring endomorphism of Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 Defn: alpha |--> alpha, Ring endomorphism of Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 Defn: alpha |--> -alpha ] }}} {{{id=117| K /// Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 }}} {{{id=118| f = phi[1]; f /// Ring endomorphism of Number Field in alpha with defining polynomial x^4 - 2*x^2 - 1 Defn: alpha |--> -alpha }}} {{{id=119| f(K.0) /// -alpha }}} {{{id=120| /// }}} {{{id=41| z.norm() /// -4721 }}} {{{id=42| z.trace() /// -16 }}} {{{id=43| z.minpoly() /// x^4 + 16*x^3 + 10*x^2 - 1032*x - 4721 }}} {{{id=56| z.charpoly() /// x^4 + 16*x^3 + 10*x^2 - 1032*x - 4721 }}} {{{id=121| alpha.minpoly() /// x^4 - 2*x^2 - 1 }}} {{{id=44| w = alpha^2 /// }}} {{{id=57| w.charpoly() /// x^4 - 4*x^3 + 2*x^2 + 4*x + 1 }}} {{{id=59| w.minpoly() /// x^2 - 2*x - 1 }}} {{{id=122| K.power_basis() /// [1, alpha, alpha^2, alpha^3] }}} {{{id=123| mat = alpha.matrix(); mat /// [0 1 0 0] [0 0 1 0] [0 0 0 1] [1 0 2 0] }}} {{{id=60| mat = w.matrix(); mat /// [0 0 1 0] [0 0 0 1] [1 0 2 0] [0 1 0 2] }}} {{{id=58| mat.charpoly() /// x^4 - 4*x^3 + 2*x^2 + 4*x + 1 }}} {{{id=61| /// }}} {{{id=11| /// }}}

Fractional Ideals

  • define
  • factor as product of prime ideals
  • norm
  • reduce elements modulo
{{{id=55| K. = QuadraticField(-6); K /// Number Field in a with defining polynomial x^2 + 6 }}} {{{id=145| K.ideal(2).factor() /// (Fractional ideal (2, a))^2 }}} {{{id=147| Primes() /// Set of all prime numbers: 2, 3, 5, 7, ... }}} {{{id=148| K.disc() /// -24 }}} {{{id=151| OK = K.ring_of_integers(); OK /// Maximal Order in Number Field in a with defining polynomial x^2 + 6 }}} {{{id=150| I = OK.ideal([6, a]); I /// Fractional ideal (a) }}} {{{id=149| I.factor() /// (Fractional ideal (2, a)) * (Fractional ideal (3, a)) }}} {{{id=152| I*I /// Fractional ideal (6) }}} {{{id=153| 1/I /// Fractional ideal (1/6*a) }}} {{{id=154| (1/I)^(-1) /// Fractional ideal (a) }}} {{{id=155| F = (I^3).factor(); F /// (Fractional ideal (2, a))^3 * (Fractional ideal (3, a))^3 }}} {{{id=156| list(F) /// [(Fractional ideal (2, a), 3), (Fractional ideal (3, a), 3)] }}} {{{id=157| F[0] /// (Fractional ideal (2, a), 3) }}} {{{id=158| F[0][0] /// Fractional ideal (2, a) }}} {{{id=159| F[0][1] /// 3 }}} {{{id=160| F[0][0].basis() /// [2, a] }}} {{{id=161| F[0][0].free_module() /// Free module of degree 2 and rank 2 over Integer Ring User basis matrix: [2 0] [0 1] }}} {{{id=162| (1/I).free_module() /// Free module of degree 2 and rank 2 over Integer Ring User basis matrix: [ 1 0] [ 0 1/6] }}} {{{id=146| for p in Primes(): print p, K.ideal(p).factor() /// WARNING: Output truncated! full_output.txt 2 (Fractional ideal (2, a))^2 3 (Fractional ideal (3, a))^2 5 (Fractional ideal (5, a + 2)) * (Fractional ideal (5, a - 2)) 7 (Fractional ideal (a + 1)) * (Fractional ideal (-a + 1)) 11 (Fractional ideal (11, a + 4)) * (Fractional ideal (11, a - 4)) 13 Fractional ideal (13) 17 Fractional ideal (17) 19 Fractional ideal (19) 23 Fractional ideal (23) 29 (Fractional ideal (29, a - 9)) * (Fractional ideal (29, a + 9)) 31 (Fractional ideal (a - 5)) * (Fractional ideal (a + 5)) 37 Fractional ideal (37) 41 Fractional ideal (41) 43 Fractional ideal (43) 47 Fractional ideal (47) 53 (Fractional ideal (53, a + 10)) * (Fractional ideal (53, a - 10)) 59 (Fractional ideal (59, a + 17)) * (Fractional ideal (59, a - 17)) 61 Fractional ideal (61) 67 Fractional ideal (67) 71 Fractional ideal (71) 73 (Fractional ideal (-2*a + 7)) * (Fractional ideal (2*a + 7)) 79 (Fractional ideal (-3*a - 5)) * (Fractional ideal (3*a - 5)) 83 (Fractional ideal (83, a + 34)) * (Fractional ideal (83, a - 34)) 89 Fractional ideal (89) 97 (Fractional ideal (-4*a + 1)) * (Fractional ideal (4*a + 1)) 101 (Fractional ideal (101, a + 14)) * (Fractional ideal (101, a - 14)) 103 (Fractional ideal (-3*a + 7)) * (Fractional ideal (3*a + 7)) 107 (Fractional ideal (107, a + 23)) * (Fractional ideal (107, a - 23)) 109 Fractional ideal (109) 113 Fractional ideal (113) 127 (Fractional ideal (a - 11)) * (Fractional ideal (a + 11)) 131 (Fractional ideal (131, a - 16)) * (Fractional ideal (131, a + 16)) 137 Fractional ideal (137) 139 Fractional ideal (139) 149 (Fractional ideal (149, a - 21)) * (Fractional ideal (149, a + 21)) 151 (Fractional ideal (5*a + 1)) * (Fractional ideal (-5*a + 1)) 157 Fractional ideal (157) 163 Fractional ideal (163) 167 Fractional ideal (167) 173 (Fractional ideal (173, a - 72)) * (Fractional ideal (173, a + 72)) 179 (Fractional ideal (179, a - 50)) * (Fractional ideal (179, a + 50)) 181 Fractional ideal (181) 191 Fractional ideal (191) 193 (Fractional ideal (2*a + 13)) * (Fractional ideal (-2*a + 13)) 197 (Fractional ideal (197, a - 83)) * (Fractional ideal (197, a + 83)) 199 (Fractional ideal (5*a - 7)) * (Fractional ideal (5*a + 7)) 211 Fractional ideal (211) 223 (Fractional ideal (3*a + 13)) * (Fractional ideal (-3*a + 13)) 227 (Fractional ideal (227, a - 69)) * (Fractional ideal (227, a + 69)) 229 Fractional ideal (229) 233 Fractional ideal (233) 239 Fractional ideal (239) 241 (Fractional ideal (6*a - 5)) * (Fractional ideal (-6*a - 5)) 251 (Fractional ideal (251, a + 112)) * (Fractional ideal (251, a - 112)) 257 Fractional ideal (257) 263 Fractional ideal (263) 269 (Fractional ideal (269, a - 97)) * (Fractional ideal (269, a + 97)) 271 (Fractional ideal (5*a + 11)) * (Fractional ideal (-5*a + 11)) 277 Fractional ideal (277) ... 2549 (Fractional ideal (2549, a + 1053)) * (Fractional ideal (2549, a - 1053)) 2551 (Fractional ideal (5*a - 49)) * (Fractional ideal (-5*a - 49)) 2557 Fractional ideal (2557) 2579 (Fractional ideal (2579, a + 190)) * (Fractional ideal (2579, a - 190)) 2591 Fractional ideal (2591) 2593 (Fractional ideal (8*a - 47)) * (Fractional ideal (-8*a - 47)) 2609 Fractional ideal (2609) 2617 (Fractional ideal (6*a + 49)) * (Fractional ideal (-6*a + 49)) 2621 (Fractional ideal (2621, a - 362)) * (Fractional ideal (2621, a + 362)) 2633 Fractional ideal (2633) 2647 (Fractional ideal (-21*a + 1)) * (Fractional ideal (21*a + 1)) 2657 Fractional ideal (2657) 2659 Fractional ideal (2659) 2663 Fractional ideal (2663) 2671 (Fractional ideal (21*a - 5)) * (Fractional ideal (21*a + 5)) 2677 Fractional ideal (2677) 2683 Fractional ideal (2683) 2687 Fractional ideal (2687) 2689 (Fractional ideal (-20*a + 17)) * (Fractional ideal (-20*a - 17)) 2693 (Fractional ideal (2693, a - 307)) * (Fractional ideal (2693, a + 307)) 2699 (Fractional ideal (2699, a - 501)) * (Fractional ideal (2699, a + 501)) 2707 Fractional ideal (2707) 2711 Fractional ideal (2711) 2713 (Fractional ideal (12*a + 43)) * (Fractional ideal (-12*a + 43)) 2719 (Fractional ideal (15*a - 37)) * (Fractional ideal (15*a + 37)) 2729 Fractional ideal (2729) 2731 Fractional ideal (2731) 2741 (Fractional ideal (2741, a - 74)) * (Fractional ideal (2741, a + 74)) 2749 Fractional ideal (2749) 2753 Fractional ideal (2753) 2767 (Fractional ideal (-21*a - 11)) * (Fractional ideal (-21*a + 11)) 2777 Fractional ideal (2777) 2789 (Fractional ideal (2789, a - 988)) * (Fractional ideal (2789, a + 988)) 2791 (Fractional ideal (19*a - 25)) * (Fractional ideal (19*a + 25)) 2797 Fractional ideal (2797) 2801 Fractional ideal (2801) 2803 Fractional ideal (2803) 2819 (Fractional ideal (2819, a + 1079)) * (Fractional ideal (2819, a - 1079)) 2833 (Fractional ideal (-2*a + 53)) * (Fractional ideal (-2*a - 53)) 2837 (Fractional ideal (2837, a + 1359)) * (Fractional ideal (2837, a - 1359)) 2843 (Fractional ideal (2843, a - 908)) * (Fractional ideal (2843, a + 908)) 2851 Fractional ideal (2851) 2857 (Fractional ideal (-14*a - 41)) * (Fractional ideal (14*a - 41)) 2861 (Fractional ideal (2861, a - 887)) * (Fractional ideal (2861, a + 887)) ^C - 55)) Traceback (most recent call last): File "", line 1, in File "_sage_input_13.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("Zm9yIHAgaW4gUHJpbWVzKCk6CiAgICBwcmludCBwLCBLLmlkZWFsKHApLmZhY3Rvcigp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in File "/private/var/folders/7y/7y-O1iZOGTmMUMnLq7otq++++TI/-Tmp-/tmp_bNkRu/___code___.py", line 2, in exec compile(u'for p in Primes():\n print p, K.ideal(p).factor()' + '\n', '', 'single') File "", line 2, in File "/Users/wstein/purple/psage-10.09.30/local/lib/python2.6/site-packages/sage/interfaces/get_sigs.py", line 9, in my_sigint raise KeyboardInterrupt KeyboardInterrupt __SAGE__ }}} {{{id=65| I = K.ideal(6); I /// Fractional ideal (6) }}} {{{id=54| F = I.factor(); F /// (Fractional ideal (2, a))^2 * (Fractional ideal (3, a))^2 }}} {{{id=66| P = F[0][0]; P /// Fractional ideal (2, a) }}} {{{id=67| P.is_principal() /// False }}} {{{id=68| P.norm() /// 2 }}} {{{id=124| for p in primes(30): print [P for P, e in K.ideal(p).factor()] /// [Fractional ideal (2, a)] [Fractional ideal (3, a)] [Fractional ideal (5, a + 2), Fractional ideal (5, a - 2)] [Fractional ideal (a + 1), Fractional ideal (-a + 1)] [Fractional ideal (11, a + 4), Fractional ideal (11, a - 4)] [Fractional ideal (13)] [Fractional ideal (17)] [Fractional ideal (19)] [Fractional ideal (23)] [Fractional ideal (29, a - 9), Fractional ideal (29, a + 9)] }}} {{{id=71| Q = F[1][0]; Q /// Fractional ideal (3, a) }}} {{{id=69| k = Q.residue_field(); k /// Residue field of Fractional ideal (3, a) }}} {{{id=72| k.cardinality() /// 3 }}} {{{id=70| k(2+a) /// 2 }}} {{{id=10| parent(k(2).lift()) /// Integer Ring }}} {{{id=74| /// }}}

The Ring $\mathcal{O}_K$ of Integers

  • Compute basis
  • Discriminant
{{{id=47| K. = QuadraticField(-5); K /// Number Field in a with defining polynomial x^2 + 5 }}} {{{id=163| K.class_number() /// 2 }}} {{{id=169| K.disc([2,a+3]) /// -80 }}} {{{id=164| z = K(33) /// }}} {{{id=168| z.factor() /// Traceback (most recent call last): File "", line 1, in File "_sage_input_58.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ei5mYWN0b3IoKQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in File "/private/var/folders/7y/7y-O1iZOGTmMUMnLq7otq++++TI/-Tmp-/tmpyMJYzU/___code___.py", line 2, in exec compile(u'z.factor()' + '\n', '', 'single') File "", line 1, in File "number_field_element.pyx", line 1009, in sage.rings.number_field.number_field_element.NumberFieldElement.factor (sage/rings/number_field/number_field_element.cpp:9018) ValueError: Non-principal ideal in factorization }}} {{{id=48| OK = K.maximal_order(); OK /// Maximal Order in Number Field in a with defining polynomial x^2 - 5 }}} {{{id=166| OK(33).factor() /// (-3/2*a + 1/2) * (-3/2*a - 1/2) * 3 }}} {{{id=167| K.factor(33) /// (Fractional ideal (-3/2*a + 1/2)) * (Fractional ideal (-3/2*a - 1/2)) * (Fractional ideal (3)) }}} {{{id=49| OK.basis() /// [1/2*a + 1/2, a] }}} {{{id=45| var('x') K. = NumberField(x^3 + x^2 - 2*x + 8); K /// Number Field in alpha with defining polynomial x^3 + x^2 - 2*x + 8 }}} {{{id=46| OK = K.maximal_order(); OK /// Maximal Order in Number Field in alpha with defining polynomial x^3 + x^2 - 2*x + 8 }}} {{{id=19| OK.basis() /// [1, 1/2*alpha^2 + 1/2*alpha, alpha^2] }}} {{{id=53| K.ring_of_integers() /// Maximal Order in Number Field in alpha with defining polynomial x^3 + x^2 - 2*x + 8 }}} {{{id=52| /// }}} {{{id=51| /// }}}

Class Groups

{{{id=75| var('x') K. = NumberField(x^3 + x^2 - 2*x + 8); K /// Number Field in alpha with defining polynomial x^3 + x^2 - 2*x + 8 }}} {{{id=76| K.class_group() /// Class group of order 1 with structure of Number Field in alpha with defining polynomial x^3 + x^2 - 2*x + 8 }}}

(Bug in how the class group prints above: see trac 10141.)

{{{id=21| a = sqrt(1+sqrt(2)) f = RR(a).algdep(4); f /// x^4 - 2*x^2 - 1 }}} {{{id=23| K. = NumberField(f); K /// Number Field in a with defining polynomial x^4 - 2*x^2 - 1 }}} {{{id=22| K.class_number() /// 1 }}} {{{id=9| /// }}}

(Massive) Efficiency Tricks

  • Assume GRH+
  • Avoid factoring the discriminant (may require Sage >= 4.6.x)
{{{id=15| # This can make some number field computations, especially of # class groups, *massively* faster: proof.number_field(False) /// }}} {{{id=171| proof. /// }}} {{{id=79| p = next_prime(10^50); q = next_prime(10^60) /// }}} {{{id=8| K.
= NumberField(x^2 - p*q, maximize_at_primes=[p,q]) /// }}} {{{id=3| K.maximal_order() /// Maximal Order in Number Field in a with defining polynomial x^2 - 100000000000000000000000000000000000000000000000151000000000700000000000000000000000000000000000000000000001057 }}} {{{id=80| K. = NumberField(x^2 - p*q) /// }}}

This would take forever:

{{{id=81| K.maximal_order() /// ^CTraceback (most recent call last): File "", line 1, in File "_sage_input_80.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("Sy5tYXhpbWFsX29yZGVyKCk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))' + '\n', '', 'single') File "", line 1, in File "/private/var/folders/7y/7y-O1iZOGTmMUMnLq7otq++++TI/-Tmp-/tmp0bfJiG/___code___.py", line 2, in exec compile(u'K.maximal_order()' + '\n', '', 'single') File "", line 1, in File "/Users/wstein/purple/psage-10.09.30/local/lib/python2.6/site-packages/sage/rings/number_field/number_field.py", line 5330, in maximal_order B = map(self, self._pari_integral_basis(v = v)) File "/Users/wstein/purple/psage-10.09.30/local/lib/python2.6/site-packages/sage/rings/number_field/number_field.py", line 3746, in _pari_integral_basis B = f.nfbasis(1 if self._assume_disc_small else 0) KeyboardInterrupt __SAGE__ }}} {{{id=126| /// }}}

Unit Groups of Number Fields

Recall Dirichlet's Theorem, which I have stated, but not yet proved.  

Theorem: The group $U_K$ of units of $\mathcal{O}_K$ is a finite (cyclic) torsion group times a free abelian group of rank $r+s-1$, where $r$ is the number of real embeddings and $2s$ is the numbers of complex embeddings of $K$.

{{{id=125| x = var('x') K.
= NumberField(x^3 + x^2 - 2*x + 8) U = K.unit_group() U /// Unit group with structure C2 x Z of Number Field in a with defining polynomial x^3 + x^2 - 2*x + 8 }}} {{{id=131| U.gens() /// [-1, 3*a^2 + 13*a + 13] }}} {{{id=130| g = U.gens()[1]; g /// 3*a^2 + 13*a + 13 }}} {{{id=129| g.norm() /// -1 }}}

 Note: Units need not lie on the unit circle!

{{{id=139| points(g.complex_embeddings(), pointsize=50) /// }}} {{{id=142| /// }}}

Fundamental Units (i.e., the best generators) can be very big:

{{{id=141| K.
= QuadraticField(2011) K.unit_group().gens() /// [-1, 510732021116138713675018566232201605320997*a + 22903355954053525066202335319378237605968890] }}}

(See Lenstra's article for a fun related discussion.)

{{{id=138| /// }}} {{{id=137| /// }}}

An Infamous Gotcha's

Here's something that confused the heck out of me once.

{{{id=128| %magma R := PolynomialRing(RationalField()); K := NumberField(x^3 + x^2 - 2*x + 8); Discriminant(MaximalOrder(K)) /// -503 }}} {{{id=82| x = var('x') K. = NumberField(x^3 + x^2 - 2*x + 8) K.discriminant() /// -503 }}} {{{id=170| K.defining_polynomial().disc() /// -2012 }}} {{{id=134| %gp nfdisc(x^3 + x^2 - 2*x + 8) /// -503 }}}

WTF: The issue is that Magma defines the discriminant of a number field to be the discriminant of the defining polynomial for the field.   This directly conflicts with all standard usage in mathematics literature.  So watch out.  Always check documentation (in this the builtin docs don't help) and do consistency checks.

{{{id=133| magma.Discriminant? ///

File: /Users/wstein/purple/psage-10.09.30/local/lib/python2.6/site-packages/sage/interfaces/magma.py

Type: <class 'sage.interfaces.magma.MagmaFunction'>

Definition: magma.Discriminant(*args, **kwds)

Docstring:


Intrinsic 'Discriminant'

Signatures:

( O) -> RngOrdIdl
[
Recompute
]

The discriminant of the order O with respect to the trace on its container
algebra. Set Recompute to true to force a recomputation.

( O) -> RngIntElt

Discriminant of the order O.

( A) -> RngOrdIdl, SeqEnum

Returns the ideal of finite places and the sequence of real places where A is
ramified.

( A) -> RngElt
( A) -> RngElt

The reduced discriminant.

( C) -> RngIntElt

The discriminant of the plane conic curve C.

( E) -> RngElt

The discriminant of the elliptic curve E.

( C) -> RngElt

The discriminant of the curve C.

( F) -> RngOrdIdl, SeqEnum

The discriminant of the FldAb F.

( K) -> RngIntElt

The discriminant for the field K.

( S,  R) -> RngPadElt

Discriminant of the extension S/R.

( K) -> RngIntElt

The discriminant for the field K.

( H) -> FldRatElt, AlgMatElt
( M) -> RngIntElt

The discriminant of H with respect to the trace pairing matrix.

( model) -> RngElt

The discriminant Delta of the given genus one model.

( Q) -> RngIntElt

The discriminant which the forms in Q share.

( x) -> RngIntElt

The discriminant for the quadratic form x.

( O) -> .

The discriminant of the order O.

( R) -> RngIntElt

The discriminant of the order O in an algebraic field.

( L) -> RngElt

Discriminant of the local ring L.

( f,  v) -> RngMPolElt

The discriminant of the polynomial f with respect to the v-th variable.

( f,  V) -> RngMPolElt

The discriminant of the polynomial f with respect to variable V.

( O) -> .

The discriminant of the order O in an algebraic field.

( R) -> RngPadElt

Discriminant of R/BaseRing(R).

( S,  R) -> RngPadElt

Discriminant of the extension S/R.

( I) -> RngIntElt

The discriminant of the quadratic ideal.

( f) -> RngElt

The discriminant of the univariate polynomial f.
}}} {{{id=136| /// }}}