Open with one click!
%typeset_mode True

Basic commands

1 + 1
2\displaystyle 2
print("hello world")
hello world

Programming

if 57.is_prime(): print("57 is a prime number") else: print("57 is composite")
57 is composite
for p in primes(25): print([p, p^2 - 1])
[2, 3] [3, 8] [5, 24] [7, 48] [11, 120] [13, 168] [17, 288] [19, 360] [23, 528]

Mathematical objects

Integers(), str(Integers())
(Z\displaystyle \Bold{Z}, Integer Ring)
ZZ
Z\displaystyle \Bold{Z}
Rationals(), str(Rationals())
(Q\displaystyle \Bold{Q}, Rational Field)
ComplexField(200), str(ComplexField(200))
(C\displaystyle \Bold{C}, Complex Field with 200 bits of precision)
Zmod(16)
Z/16Z\displaystyle \ZZ/16\ZZ
F = FiniteField(3^4, 'g') F, str(F)
(F34\displaystyle \Bold{F}_{3^{4}}, Finite Field in g of size 3^4)
F.polynomial()
g4+2g3+2\displaystyle g^{4} + 2 g^{3} + 2
R = PolynomialRing(Integers(), 'x') R R.gen()
Z[x]\displaystyle \Bold{Z}[x]
x\displaystyle x
ZZ['x']
Z[x]\displaystyle \Bold{Z}[x]
FunctionField(QQ, 'x')
Rational function field in x over Rational Field

Modular forms

str(SL2Z)
'Modular Group SL(2,Z)'
SL2Z.gens()
([ 0 -1] [ 1 0], [1 1] [0 1])
M4 = ModularForms(SL2Z, 4) M4
Modular Forms space of dimension 1 for Modular Group SL(2,Z) of weight 4 over Rational Field
M4.dimension()
1
M4.q_expansion_basis()
[ 1 + 240*q + 2160*q^2 + 6720*q^3 + 17520*q^4 + 30240*q^5 + O(q^6) ]
f = M4.q_expansion_basis()[0]/240 f
1/240 + q + 9*q^2 + 28*q^3 + 73*q^4 + 126*q^5 + O(q^6)
sum(d^3 for d in 5.divisors())
126
S12 = CuspForms(SL2Z, 12) S12
Cuspidal subspace of dimension 1 of Modular Forms space of dimension 2 for Modular Group SL(2,Z) of weight 12 over Rational Field
S12.q_expansion_basis(prec=20)
[ q - 24*q^2 + 252*q^3 - 1472*q^4 + 4830*q^5 - 6048*q^6 - 16744*q^7 + 84480*q^8 - 113643*q^9 - 115920*q^10 + 534612*q^11 - 370944*q^12 - 577738*q^13 + 401856*q^14 + 1217160*q^15 + 987136*q^16 - 6905934*q^17 + 2727432*q^18 + 10661420*q^19 + O(q^20) ]
EisensteinForms(SL2Z,16).q_expansion_basis()
[ 1 + 16320/3617*q + 534790080/3617*q^2 + 234174178560/3617*q^3 + 17524001357760/3617*q^4 + 498046875016320/3617*q^5 + O(q^6) ]
f, g = ModularForms(Gamma1(4), 2).basis() f, g type(f) f.parent()
(1 + 24*q^2 + 24*q^4 + O(q^6), q + 4*q^3 + 6*q^5 + O(q^6)) <class 'sage.modular.modform.ambient_g1.ModularFormsAmbient_g1_Q_with_category.element_class'> Modular Forms space of dimension 2 for Congruence Subgroup Gamma1(4) of weight 2 over Rational Field
f.q_expansion(20)
1 + 24*q^2 + 24*q^4 + 96*q^6 + 24*q^8 + 144*q^10 + 96*q^12 + 192*q^14 + 24*q^16 + 312*q^18 + O(q^20)
# Create a power series ring R.<q> = ZZ[[]] R
Power Series Ring in q over Integer Ring
theta = 1 + 2*q + 2*q^4 + 2*q^9 + 2*q^16 + O(q^25)
theta^4
1 + 8*q + 24*q^2 + 32*q^3 + 24*q^4 + 48*q^5 + 96*q^6 + 64*q^7 + 24*q^8 + 104*q^9 + 144*q^10 + 96*q^11 + 96*q^12 + 112*q^13 + 192*q^14 + 192*q^15 + 24*q^16 + 144*q^17 + 312*q^18 + 160*q^19 + 144*q^20 + 256*q^21 + 288*q^22 + 192*q^23 + 96*q^24 + O(q^25)
theta^4 == (f + 8*g).q_expansion(25)
True

Some pictures of fundamental domains

(warning: not of the same type as in the lectures)

SL2Z.farey_symbol().fundamental_domain()
Gamma0(2).farey_symbol().fundamental_domain()
Gamma(3).farey_symbol().fundamental_domain()
Gamma(3).cusps()
[0\displaystyle 0, 1\displaystyle 1, 2\displaystyle 2, \displaystyle \infty]

Hecke operators

M = ModularForms(SL2Z, 12) M
Modular Forms space of dimension 2 for Modular Group SL(2,Z) of weight 12 over Rational Field
T2 = M.hecke_operator(2) T2 T2.matrix()
T2\displaystyle T_{2}
(24002049)\displaystyle \left(\begin{array}{rr} -24 & 0 \\ 0 & 2049 \end{array}\right)
M = ModularForms(Gamma1(7), 3) M
Modular Forms space of dimension 7 for Congruence Subgroup Gamma1(7) of weight 3 over Rational Field
d3 = M.diamond_bracket_operator(3) d3 d3.matrix()
3\displaystyle \langle 3 \rangle
(10000000271262947702142352805638520053014452408011314226623339201331151870147206711201326153456)\displaystyle \left(\begin{array}{rrrrrrr} -1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 27 & 126 & 294 & 770 & 2142 & 3528 \\ 0 & \frac{56}{3} & 85 & 200 & 530 & 1445 & 2408 \\ 0 & \frac{11}{3} & 14 & 22 & 66 & 233 & 392 \\ 0 & -1 & -3 & -3 & -11 & -51 & -87 \\ 0 & -1 & -4 & -7 & -20 & -67 & -112 \\ 0 & -\frac{1}{3} & -2 & -6 & -15 & -34 & -56 \end{array}\right)
d3.matrix()^6
(1000000010000000100000001000000010000000100000001)\displaystyle \left(\begin{array}{rrrrrrr} 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 1 \end{array}\right)
T2 = M.hecke_operator(2) T2.matrix()
(30000000285011765609072705605563076498235945454301363118423531448116201204815384300012047193763010830122038863)\displaystyle \left(\begin{array}{rrrrrrr} -3 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 285 & 0 & 1176 & 560 & 9072 & 7056 \\ 0 & \frac{556}{3} & 0 & 764 & \frac{982}{3} & 5945 & 4543 \\ 0 & \frac{136}{3} & 1 & 184 & \frac{235}{3} & 1448 & 1162 \\ 0 & -12 & 0 & -48 & -15 & -384 & -300 \\ 0 & -12 & 0 & -47 & -19 & -376 & -301 \\ 0 & -\frac{8}{3} & 0 & -12 & -\frac{20}{3} & -88 & -63 \end{array}\right)
(T2*d3) (T2*d3-d3*T2).matrix()
(3000000023294214236268190655205632001441248555254618011322233329902409013516319539017679826013901363467130148)\displaystyle \left(\begin{array}{rrrrrrr} 3 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 23 & 294 & 2142 & 3626 & 8190 & 6552 \\ 0 & \frac{56}{3} & 200 & 1441 & 2485 & 5525 & 4618 \\ 0 & \frac{11}{3} & 22 & 233 & 329 & 902 & 409 \\ 0 & -1 & -3 & -51 & -63 & -195 & -39 \\ 0 & -1 & -7 & -67 & -98 & -260 & -139 \\ 0 & -\frac{1}{3} & -6 & -34 & -67 & -130 & -148 \end{array}\right)
(0000000000000000000000000000000000000000000000000)\displaystyle \left(\begin{array}{rrrrrrr} 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 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 0 & 0 \end{array}\right)

Old and new subspaces

%typeset_mode True # Eisenstein subspace and cuspidal subspace M = ModularForms(Gamma1(14), 4) E = M.eisenstein_submodule() S = CuspForms(Gamma1(14), 4) S == M.cuspidal_submodule() M.dimension() (E.dimension(), S.dimension())
True\displaystyle \mathrm{True}
24\displaystyle 24
(12\displaystyle 12, 12\displaystyle 12)
# Old and new subspaces Sold = S.old_submodule() Snew = S.new_submodule() (Sold.dimension(), Snew.dimension())
(6\displaystyle 6, 6\displaystyle 6)
# Check consistency with dimensions of spaces of lower level CuspForms(Gamma1(2), 4).dimension() CuspForms(Gamma1(7), 4).dimension()
0\displaystyle 0
3\displaystyle 3
S.old_submodule(2)
Modular Forms subspace of dimension 6 of Modular Forms space of dimension 24 for Congruence Subgroup Gamma1(14) of weight 4 over Rational Field
# An example of a non-diagonalisable Hecke operator. This shows that the # decomposition of the new subspace into simultaneous eigenspaces for the # T_m with m coprime to the level does not extend directly to all the T_m. S = CuspForms(Gamma0(16), 4) T2 = S.hecke_matrix(2) T2 T2.jordan_form()
(000104000)\displaystyle \left(\begin{array}{rrr} 0 & 0 & 0 \\ 1 & 0 & -4 \\ 0 & 0 & 0 \end{array}\right)
(010000000)\displaystyle \left(\begin{array}{rr|r} 0 & 1 & 0 \\ 0 & 0 & 0 \\ \hline 0 & 0 & 0 \end{array}\right)

Newforms

# We can compute the set of newforms (primitive forms) of a given level and weight. S = CuspForms(Gamma1(15), 2) NF = S.newforms() NF Newforms(Gamma1(15), 2) == NF
[qq2q3q4+q5+O(q6)\displaystyle q - q^{2} - q^{3} - q^{4} + q^{5} + O(q^{6})]
True\displaystyle \mathrm{True}
# An example with multiple newforms Newforms(Gamma0(26), 2)
[qq2+q3+q43q5+O(q6)\displaystyle q - q^{2} + q^{3} + q^{4} - 3q^{5} + O(q^{6}), q+q23q3+q4q5+O(q6)\displaystyle q + q^{2} - 3q^{3} + q^{4} - q^{5} + O(q^{6})]
# We have to be careful when the newforms don't have rational coefficients Newforms(Gamma1(26), 2)
Error in lines 1-1 Traceback (most recent call last): File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1234, in execute flags=compile_flags), namespace, locals) File "", line 1, in <module> File "/ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/modular/modform/constructor.py", line 467, in Newforms return CuspForms(group, weight, base_ring).newforms(names) File "/ext/sage/sage-8.9_1804/local/lib/python2.7/site-packages/sage/modular/modform/space.py", line 1642, in newforms raise ValueError("Please specify a name to be used when generating names for generators of Hecke eigenvalue fields corresponding to the newforms.") ValueError: Please specify a name to be used when generating names for generators of Hecke eigenvalue fields corresponding to the newforms.
# In this case we have to specify a "names" parameter. NF = Newforms(Gamma1(26), 2, names='a') NF
[qq2+q3+q43q5+O(q6)\displaystyle q - q^{2} + q^{3} + q^{4} - 3q^{5} + O(q^{6}), q+q23q3+q4q5+O(q6)\displaystyle q + q^{2} - 3q^{3} + q^{4} - q^{5} + O(q^{6}), q+a2q2+(a21)q4q5+O(q6)\displaystyle q + a_{2}q^{2} + \left(-a_{2} - 1\right)q^{4} - q^{5} + O(q^{6}), q+a3q2q3q43a3q5+O(q6)\displaystyle q + a_{3}q^{2} - q^{3} - q^{4} - 3 a_{3}q^{5} + O(q^{6})]
# Every newform has a character [f.character() for f in NF]
[, , , ]
# Compare our list of newforms with the dimension of the new subspace: S = CuspForms(Gamma1(26), 2) Sold = S.old_submodule() Snew = S.new_submodule() (Sold.dimension(), Snew.dimension())
(4\displaystyle 4, 6\displaystyle 6)
# Sage only gives 4 newforms, but the new subspace has dimension 6. # This is explained by the fact that two of the forms have larger coefficient fields. # The following computation shows that the coefficient fields of the last two forms # are Q(\sqrt{-3}) and Q(\sqrt{-1}), respectively. [f.base_ring() for f in NF]
[Q\displaystyle \Bold{Q}, Q\displaystyle \Bold{Q}, Q[a2]/(a22+a2+1)\displaystyle \Bold{Q}[a_{2}]/(a_{2}^{2} + a_{2} + 1), Q[a3]/(a32+1)\displaystyle \Bold{Q}[a_{3}]/(a_{3}^{2} + 1)]

LL-functions

# Here is a newform of which we are going to compute the L-series. f = Newforms(Gamma1(14), 2)[0]; f
qq22q3+q4+O(q6)\displaystyle q - q^{2} - 2q^{3} + q^{4} + O(q^{6})
Lf = f.lseries() Lf
L-series associated to the cusp form q - q^2 - 2*q^3 + q^4 + O(q^6)
# We can evaluate L-series both inside and outside the # right half-plane where the Dirichlet series converges. Lf(3) Lf(3+2*I) Lf(-2-I)
0.826125962101783\displaystyle 0.826125962101783
0.995825161298581+0.180645100106889i\displaystyle 0.995825161298581 + 0.180645100106889i
1.257373212670290.432187040382323i\displaystyle 1.25737321267029 - 0.432187040382323i
# The L-function is holomorphic. Lf.poles
[]
# Like the Riemann zeta function, it has some 'trivial' zeroes. [Lf(s) for s in [-4..-1]]
[0.000000000000000\displaystyle 0.000000000000000, 0.000000000000000\displaystyle 0.000000000000000, 0.000000000000000\displaystyle 0.000000000000000, 0.000000000000000\displaystyle 0.000000000000000]
# Sign of the functional equation Lf.eps
1.00000000000000\displaystyle 1.00000000000000
Lf.conductor Lf.weight
14\displaystyle 14
2\displaystyle 2
# Completed L-function attached to L(s) def Lambda(L, s): return gamma(s)*L.conductor^(s/2)/(2*pi.n())^s * L(s)
# Check numerically that the completed L-function # satisfies the expected functional equation. s = 1.43250982 + .435873*I Lambda(Lf, s) Lambda(Lf, 2 - s)
0.196288571460192+0.0108503534364708i\displaystyle 0.196288571460192 + 0.0108503534364708i
0.196288571460192+0.0108503534364707i\displaystyle 0.196288571460192 + 0.0108503534364707i
# There is also a quicker (but more obscure) way: Lf.check_functional_equation() # answer should be a small number
1.68051336735253×1018\displaystyle -1.68051336735253 \times 10^{-18}
# An example with non-rational coefficients g = Newforms(Gamma1(16), 2, names='a')[0] g g.base_ring()
q+a0q2+(a02)q3+(2a02)q4+a0q5+O(q6)\displaystyle q + a_{0}q^{2} + \left(-a_{0} - 2\right)q^{3} + \left(-2 a_{0} - 2\right)q^{4} + a_{0}q^{5} + O(q^{6})
Q[a0]/(a02+2a0+2)\displaystyle \Bold{Q}[a_{0}]/(a_{0}^{2} + 2 a_{0} + 2)
Lg = g.lseries() Lgstar = g.lseries(embedding=1) Lg(2) Lgstar(2) (Lg.eps, Lg.eps.abs()) (Lgstar.eps, Lgstar.eps.abs()) Lg.conductor
0.6689618127188350.0905917403031900i\displaystyle 0.668961812718835 - 0.0905917403031900i
0.668961812718835+0.0905917403031900i\displaystyle 0.668961812718835 + 0.0905917403031900i
(0.9238795325112870.382683432365090i\displaystyle 0.923879532511287 - 0.382683432365090i, 1.00000000000000\displaystyle 1.00000000000000)
(0.923879532511287+0.382683432365090i\displaystyle 0.923879532511287 + 0.382683432365090i, 1.00000000000000\displaystyle 1.00000000000000)
16\displaystyle 16
s = 0.520934 - 2.230498*I Lambda(Lg, 2 - s) Lg.eps * Lambda(Lgstar, s) Lg.check_functional_equation()
0.0875461953458519+0.0205215759552274i\displaystyle 0.0875461953458519 + 0.0205215759552274i
0.0875461953458519+0.0205215759552274i\displaystyle 0.0875461953458519 + 0.0205215759552274i
1.28423747330908×1016+6.45303580536216×1017i\displaystyle -1.28423747330908 \times 10^{-16} + 6.45303580536216 \times 10^{-17}i