CoCalc Public FilesSageMath demo.ipynb
Author: Peter Bruin
Views : 236

SageMath/CoCalc demo

In [1]:
%display latex

In [2]:
2 * 3

$6$
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()

$\Bold{Z}$
In [6]:
ZZ

$\Bold{Z}$
In [7]:
Rationals()

$\Bold{Q}$
In [8]:
QQ

$\Bold{Q}$
In [9]:
RealField(100)

$\Bold{R}$
In [10]:
str(_)

$\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)

$\ZZ/17\ZZ$
In [12]:
F = FiniteField(3^4, 'g')

In [13]:
F

$\Bold{F}_{3^{4}}$
In [14]:
str(F)

$\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()

$g^{4} + 2 g^{3} + 2$
In [16]:
R = PolynomialRing(Integers(), 'x')

In [17]:
R

$\Bold{Z}[x]$
In [18]:
R.gen()

$x$
In [19]:
ZZ['x']

$\Bold{Z}[x]$
In [20]:
FunctionField(QQ, 'x')

$\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(_)

$\verb|Modular|\phantom{\verb!x!}\verb|Group|\phantom{\verb!x!}\verb|SL(2,Z)|$
In [23]:
SL2Z.gens()

$\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

$\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()

$1$
In [27]:
M4.q_expansion_basis()

$\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

$\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())

$126$
In [31]:
S12 = CuspForms(SL2Z, 12)

In [32]:
S12

$\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)

$\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()

$\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 + 24q^{2} + 24q^{4} + O(q^{6})$
In [37]:
g

$q + 4q^{3} + 6q^{5} + O(q^{6})$
In [38]:
type(f)

$\verb||$
In [39]:
f.parent()

$\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

$q$
In [42]:
theta = 1 + 2*q + 2*q^4 + 2*q^9 + 2*q^16 + O(q^25)

In [43]:
theta^4

$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()

$\Bold{Z}[[q]]$
In [45]:
theta^4 == (f + 8*g).q_expansion(25)

$\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()

$\left[0, 1, 2, \infty\right]$

Hecke operators

In [50]:
M = ModularForms(SL2Z, 12)
M

$\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

$T_{2}$
In [53]:
T2.matrix()

$\left(\begin{array}{rr} -24 & 0 \\ 0 & 2049 \end{array}\right)$
In [54]:
M = ModularForms(Gamma1(7), 3)

In [55]:
M

$\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

$\langle 3 \rangle$
In [57]:
d3.matrix()

$\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

$\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()

$\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

$\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

$\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 [ ]: