CoCalc Public FilesSageMath demo.ipynbOpen in with one click!
Author: Peter Bruin
Views : 183

SageMath/CoCalc demo

In [1]:
%display latex
In [2]:
2 * 3
66
In [3]:
if 57.is_prime(): print('57 is prime') else: print('57 is composite')
57 is composite
In [4]:
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]
In [5]:
Integers()
Z\Bold{Z}
In [6]:
ZZ
Z\Bold{Z}
In [7]:
Rationals()
Q\Bold{Q}
In [8]:
QQ
Q\Bold{Q}
In [9]:
RealField(100)
R\Bold{R}
In [10]:
str(_)
RealxFieldxwithx100xbitsxofxprecision\verb|Real|\phantom{\verb!x!}\verb|Field|\phantom{\verb!x!}\verb|with|\phantom{\verb!x!}\verb|100|\phantom{\verb!x!}\verb|bits|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|precision|
In [11]:
Zmod(17)
Z/17Z\ZZ/17\ZZ
In [12]:
F = FiniteField(3^4, 'g')
In [13]:
F
F34\Bold{F}_{3^{4}}
In [14]:
str(F)
FinitexFieldxinxgxofxsizex3^4\verb|Finite|\phantom{\verb!x!}\verb|Field|\phantom{\verb!x!}\verb|in|\phantom{\verb!x!}\verb|g|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|size|\phantom{\verb!x!}\verb|3^4|
In [15]:
F.polynomial()
g4+2g3+2g^{4} + 2 g^{3} + 2
In [16]:
R = PolynomialRing(Integers(), 'x')
In [17]:
R
Z[x]\Bold{Z}[x]
In [18]:
R.gen()
xx
In [19]:
ZZ['x']
Z[x]\Bold{Z}[x]
In [20]:
FunctionField(QQ, 'x')
RationalxfunctionxfieldxinxxxoverxRationalxField\verb|Rational|\phantom{\verb!x!}\verb|function|\phantom{\verb!x!}\verb|field|\phantom{\verb!x!}\verb|in|\phantom{\verb!x!}\verb|x|\phantom{\verb!x!}\verb|over|\phantom{\verb!x!}\verb|Rational|\phantom{\verb!x!}\verb|Field|

Modular forms

In [21]:
SL2Z
In [22]:
str(_)
ModularxGroupxSL(2,Z)\verb|Modular|\phantom{\verb!x!}\verb|Group|\phantom{\verb!x!}\verb|SL(2,Z)|
In [23]:
SL2Z.gens()
((0110),(1101))\left(\left(\begin{array}{rr} 0 & -1 \\ 1 & 0 \end{array}\right), \left(\begin{array}{rr} 1 & 1 \\ 0 & 1 \end{array}\right)\right)
In [24]:
M4 = ModularForms(SL2Z, 4)
In [25]:
M4
ModularxFormsxspacexofxdimensionx1xforxModularxGroupxSL(2,Z)xofxweightx4xoverxRationalxField\verb|Modular|\phantom{\verb!x!}\verb|Forms|\phantom{\verb!x!}\verb|space|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|dimension|\phantom{\verb!x!}\verb|1|\phantom{\verb!x!}\verb|for|\phantom{\verb!x!}\verb|Modular|\phantom{\verb!x!}\verb|Group|\phantom{\verb!x!}\verb|SL(2,Z)|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|weight|\phantom{\verb!x!}\verb|4|\phantom{\verb!x!}\verb|over|\phantom{\verb!x!}\verb|Rational|\phantom{\verb!x!}\verb|Field|
In [26]:
M4.dimension()
11
In [27]:
M4.q_expansion_basis()
[1+240q+2160q2+6720q3+17520q4+30240q5+O(q6)]\left[1 + 240q + 2160q^{2} + 6720q^{3} + 17520q^{4} + 30240q^{5} + O(q^{6})\right]
In [28]:
f = M4.q_expansion_basis()[0]/240
In [29]:
f
1240+q+9q2+28q3+73q4+126q5+O(q6)\frac{1}{240} + q + 9q^{2} + 28q^{3} + 73q^{4} + 126q^{5} + O(q^{6})
In [30]:
sum(d^3 for d in 5.divisors())
126126
In [31]:
S12 = CuspForms(SL2Z, 12)
In [32]:
S12
Cuspidalxsubspacexofxdimensionx1xofxModularxFormsxspacexofxdimensionx2xforxModularxGroupxSL(2,Z)xofxweightx12xoverxRationalxField\verb|Cuspidal|\phantom{\verb!x!}\verb|subspace|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|dimension|\phantom{\verb!x!}\verb|1|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|Modular|\phantom{\verb!x!}\verb|Forms|\phantom{\verb!x!}\verb|space|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|dimension|\phantom{\verb!x!}\verb|2|\phantom{\verb!x!}\verb|for|\phantom{\verb!x!}\verb|Modular|\phantom{\verb!x!}\verb|Group|\phantom{\verb!x!}\verb|SL(2,Z)|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|weight|\phantom{\verb!x!}\verb|12|\phantom{\verb!x!}\verb|over|\phantom{\verb!x!}\verb|Rational|\phantom{\verb!x!}\verb|Field|
In [33]:
S12.q_expansion_basis(prec=20)
[q24q2+252q31472q4+4830q56048q616744q7+84480q8113643q9115920q10+534612q11370944q12577738q13+401856q14+1217160q15+987136q166905934q17+2727432q18+10661420q19+O(q20)]\left[q - 24q^{2} + 252q^{3} - 1472q^{4} + 4830q^{5} - 6048q^{6} - 16744q^{7} + 84480q^{8} - 113643q^{9} - 115920q^{10} + 534612q^{11} - 370944q^{12} - 577738q^{13} + 401856q^{14} + 1217160q^{15} + 987136q^{16} - 6905934q^{17} + 2727432q^{18} + 10661420q^{19} + O(q^{20})\right]
In [34]:
EisensteinForms(SL2Z, 16).q_expansion_basis()
[1+163203617q+5347900803617q2+2341741785603617q3+175240013577603617q4+4980468750163203617q5+O(q6)]\left[1 + \frac{16320}{3617}q + \frac{534790080}{3617}q^{2} + \frac{234174178560}{3617}q^{3} + \frac{17524001357760}{3617}q^{4} + \frac{498046875016320}{3617}q^{5} + O(q^{6})\right]
In [35]:
f, g = ModularForms(Gamma1(4), 2).basis()
In [36]:
f
1+24q2+24q4+O(q6)1 + 24q^{2} + 24q^{4} + O(q^{6})
In [37]:
g
q+4q3+6q5+O(q6)q + 4q^{3} + 6q^{5} + O(q^{6})
In [38]:
type(f)
<classx'sage.modular.modform.ambient_g1.ModularFormsAmbient_g1_Q_with_category.element_class'>\verb|<class|\phantom{\verb!x!}\verb|'sage.modular.modform.ambient_g1.ModularFormsAmbient_g1_Q_with_category.element_class'>|
In [39]:
f.parent()
ModularxFormsxspacexofxdimensionx2xforxCongruencexSubgroupxGamma1(4)xofxweightx2xoverxRationalxField\verb|Modular|\phantom{\verb!x!}\verb|Forms|\phantom{\verb!x!}\verb|space|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|dimension|\phantom{\verb!x!}\verb|2|\phantom{\verb!x!}\verb|for|\phantom{\verb!x!}\verb|Congruence|\phantom{\verb!x!}\verb|Subgroup|\phantom{\verb!x!}\verb|Gamma1(4)|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|weight|\phantom{\verb!x!}\verb|2|\phantom{\verb!x!}\verb|over|\phantom{\verb!x!}\verb|Rational|\phantom{\verb!x!}\verb|Field|
In [40]:
R.<q> = ZZ[[]]
In [41]:
q
qq
In [42]:
theta = 1 + 2*q + 2*q^4 + 2*q^9 + 2*q^16 + O(q^25)
In [43]:
theta^4
1+8q+24q2+32q3+24q4+48q5+96q6+64q7+24q8+104q9+144q10+96q11+96q12+112q13+192q14+192q15+24q16+144q17+312q18+160q19+144q20+256q21+288q22+192q23+96q24+O(q25)1 + 8q + 24q^{2} + 32q^{3} + 24q^{4} + 48q^{5} + 96q^{6} + 64q^{7} + 24q^{8} + 104q^{9} + 144q^{10} + 96q^{11} + 96q^{12} + 112q^{13} + 192q^{14} + 192q^{15} + 24q^{16} + 144q^{17} + 312q^{18} + 160q^{19} + 144q^{20} + 256q^{21} + 288q^{22} + 192q^{23} + 96q^{24} + O(q^{25})
In [44]:
(theta^4).parent()
Z[[q]]\Bold{Z}[[q]]
In [45]:
theta^4 == (f + 8*g).q_expansion(25)
True\mathrm{True}

Fundamental domains

In [46]:
SL2Z.farey_symbol().fundamental_domain()
In [47]:
Gamma0(2).farey_symbol().fundamental_domain()
In [48]:
Gamma(3).farey_symbol().fundamental_domain()
In [49]:
Gamma(3).cusps()
[0,1,2,]\left[0, 1, 2, \infty\right]

Hecke operators

In [50]:
M = ModularForms(SL2Z, 12) M
ModularxFormsxspacexofxdimensionx2xforxModularxGroupxSL(2,Z)xofxweightx12xoverxRationalxField\verb|Modular|\phantom{\verb!x!}\verb|Forms|\phantom{\verb!x!}\verb|space|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|dimension|\phantom{\verb!x!}\verb|2|\phantom{\verb!x!}\verb|for|\phantom{\verb!x!}\verb|Modular|\phantom{\verb!x!}\verb|Group|\phantom{\verb!x!}\verb|SL(2,Z)|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|weight|\phantom{\verb!x!}\verb|12|\phantom{\verb!x!}\verb|over|\phantom{\verb!x!}\verb|Rational|\phantom{\verb!x!}\verb|Field|
In [51]:
T2 = M.hecke_operator(2)
In [52]:
T2
T2T_{2}
In [53]:
T2.matrix()
(24002049)\left(\begin{array}{rr} -24 & 0 \\ 0 & 2049 \end{array}\right)
In [54]:
M = ModularForms(Gamma1(7), 3)
In [55]:
M
ModularxFormsxspacexofxdimensionx7xforxCongruencexSubgroupxGamma1(7)xofxweightx3xoverxRationalxField\verb|Modular|\phantom{\verb!x!}\verb|Forms|\phantom{\verb!x!}\verb|space|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|dimension|\phantom{\verb!x!}\verb|7|\phantom{\verb!x!}\verb|for|\phantom{\verb!x!}\verb|Congruence|\phantom{\verb!x!}\verb|Subgroup|\phantom{\verb!x!}\verb|Gamma1(7)|\phantom{\verb!x!}\verb|of|\phantom{\verb!x!}\verb|weight|\phantom{\verb!x!}\verb|3|\phantom{\verb!x!}\verb|over|\phantom{\verb!x!}\verb|Rational|\phantom{\verb!x!}\verb|Field|
In [56]:
d3 = M.diamond_bracket_operator(3) d3
3\langle 3 \rangle
In [57]:
d3.matrix()
(10000000271262947702142352805638520053014452408011314226623339201331151870147206711201326153456)\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)
In [58]:
d3.matrix()^6
(1000000010000000100000001000000010000000100000001)\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)
In [59]:
T2 = M.hecke_operator(2) T2.matrix()
(30000000285011765609072705605563076498235945454301363118423531448116201204815384300012047193763010830122038863)\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)
In [60]:
T2*d3
(3000000023294214236268190655205632001441248555254618011322233329902409013516319539017679826013901363467130148)\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)
In [61]:
T2*d3-d3*T2
(0000000000000000000000000000000000000000000000000)\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)
In [ ]: