In [1]:
1+1


Out[1]:
2

In [2]:
20/3


Out[2]:
6

In [3]:
20.0/3


Out[3]:
6.666666666666667

In [6]:
type (20.0 / 3)


Out[6]:
float

Let's load SageMath's hooks


In [7]:
%load_ext sage

In [8]:
1+1


Out[8]:
2

In [9]:
type(20.0/3)


Out[9]:
<type 'sage.rings.real_mpfr.RealNumber'>

Algebraic Structures


In [10]:
ZZ, QQ, RR, CC


Out[10]:
(Integer Ring,
 Rational Field,
 Real Field with 53 bits of precision,
 Complex Field with 53 bits of precision)

In [11]:
Zmod(30)


Out[11]:
Ring of integers modulo 30

In [12]:
GF(31)


Out[12]:
Finite Field of size 31

Most algebraic structures are organised as parent/elements


In [13]:
GF(17).list()


Out[13]:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]

In [14]:
a = 2

In [15]:
a.parent()


Out[15]:
Integer Ring

In [16]:
ZZ is a.parent()


Out[16]:
True

In [17]:
a.is_unit()


Out[17]:
False

Conversions


In [18]:
b = QQ(a)

In [19]:
b == a


Out[19]:
True

In [20]:
b.parent()


Out[20]:
Rational Field

In [21]:
b.is_unit()


Out[21]:
True

Working with notebooks


In [22]:
a, b = 2, 3

In [23]:
c = a + b

In [24]:
c


Out[24]:
5

Exploring objects

Completion


In [ ]:
ZZ.<tab>

Documentation


In [ ]:
ZZ.CartesianProduct?

In [ ]:
ZZ.cardinality??

Polynomial rings


In [33]:
a = x^2 - 1

In [34]:
b = (x-1)*(x+1)
b


Out[34]:
(x + 1)*(x - 1)

In [35]:
a == b


Out[35]:
x^2 - 1 == (x + 1)*(x - 1)

In [36]:
bool(a == b)


Out[36]:
True

x is just a variable name


In [37]:
x = 2

In [38]:
x^2 - 1


Out[38]:
3

Forget about x!

We don't need symbolic calculus, we need polynomials We can reset symbolic variables with x = SR.var('x')


In [39]:
QQ['x']


Out[39]:
Univariate Polynomial Ring in x over Rational Field

In [40]:
R.<x> = QQ[]
R


Out[40]:
Univariate Polynomial Ring in x over Rational Field

In [41]:
a = x^2 -1
a


Out[41]:
x^2 - 1

In [42]:
a.parent()


Out[42]:
Univariate Polynomial Ring in x over Rational Field

In [43]:
b = (x-1)*(x+1)
b


Out[43]:
x^2 - 1

In [44]:
a == b


Out[44]:
True

Finite fields


In [46]:
p = next_prime(2^20)
R.<x> = GF(p)[]
R


Out[46]:
Univariate Polynomial Ring in x over Finite Field of size 1048583

In [48]:
P = R.irreducible_element(20)
P


Out[48]:
x^20 + x^19 + 1048569*x^18 + 1048575*x^17 + 99*x^16 + 44*x^15 + 1048224*x^14 + 1048469*x^13 + 907*x^12 + 268*x^11 + 1047424*x^10 + 1048551*x^9 + 1552*x^8 + 299*x^7 + 1047653*x^6 + 1047736*x^5 + 3036*x^4 + 38*x^3 + 172*x^2 + 1048279*x + 991

In [49]:
K.<z> = GF(p^20, modulus=P)
K


Out[49]:
Finite Field in z of size 1048583^20

In [50]:
z^20


Out[50]:
1048582*z^19 + 14*z^18 + 8*z^17 + 1048484*z^16 + 1048539*z^15 + 359*z^14 + 114*z^13 + 1047676*z^12 + 1048315*z^11 + 1159*z^10 + 32*z^9 + 1047031*z^8 + 1048284*z^7 + 930*z^6 + 847*z^5 + 1045547*z^4 + 1048545*z^3 + 1048411*z^2 + 304*z + 1047592

If we don't care about the modulus


In [51]:
L.<z> = GF(p^2)
L


Out[51]:
Finite Field in z of size 1048583^2

In [52]:
L.modulus()


Out[52]:
x^2 + x + 1

In [53]:
z.multiplicative_order()


Out[53]:
3

In [54]:
z^3


Out[54]:
1

In [56]:
e = L.primitive_element()
e.multiplicative_order()


Out[56]:
1099526307888

In [57]:
e


Out[57]:
z + 5

In [58]:
e.minpoly()


Out[58]:
x^2 + 1048574*x + 21

Elliptic Curves


In [59]:
E = EllipticCurve([1,2])
E


Out[59]:
Elliptic Curve defined by y^2 = x^3 + x + 2 over Rational Field

In [60]:
E.j_invariant()


Out[60]:
432/7

In [61]:
E.torsion_order()


Out[61]:
4

In [62]:
E.torsion_points()


Out[62]:
[(-1 : 0 : 1), (0 : 1 : 0), (1 : -2 : 1), (1 : 2 : 1)]

In [64]:
G = E.torsion_subgroup()
G


Out[64]:
Torsion Subgroup isomorphic to Z/4 associated to the Elliptic Curve defined by y^2 = x^3 + x + 2 over Rational Field

In [65]:
G.gens()


Out[65]:
((1 : 2 : 1),)

Elliptic curves over finite fields


In [67]:
E = EllipticCurve(GF(p), [0, 1, 0, 2, 3])
E


Out[67]:
Elliptic Curve defined by y^2 = x^3 + x^2 + 2*x + 3 over Finite Field of size 1048583

In [68]:
E.cardinality().factor()


Out[68]:
3^3 * 7 * 23 * 241

In [70]:
P = E.random_point()
Q = E.lift_x(123)
P, Q


Out[70]:
((866576 : 1022542 : 1), (123 : 70573 : 1))

In [71]:
P+Q


Out[71]:
(986279 : 792082 : 1)

In [72]:
Q.order().factor()


Out[72]:
3^3 * 23 * 241

In [75]:
R = 9*23*241*Q
R


Out[75]:
(1048581 : 818907 : 1)

Isogenies


In [77]:
phi = E.isogeny([R])
phi


Out[77]:
Isogeny of degree 3 from Elliptic Curve defined by y^2 = x^3 + x^2 + 2*x + 3 over Finite Field of size 1048583 to Elliptic Curve defined by y^2 = x^3 + x^2 + 1048485*x + 343 over Finite Field of size 1048583

In [78]:
S = phi(P)
S


Out[78]:
(871094 : 464333 : 1)

In [79]:
S.parent()


Out[79]:
Abelian group of points on Elliptic Curve defined by y^2 = x^3 + x^2 + 1048485*x + 343 over Finite Field of size 1048583

In [80]:
phi(R)


Out[80]:
(0 : 1 : 0)

In [81]:
phi.rational_maps()


Out[81]:
((x^3 + 4*x^2 + 24*x + 20)/(x^2 + 4*x + 4),
 (x^3*y + 6*x^2*y - 8*x*y + 8*y)/(x^3 + 6*x^2 + 12*x + 8))

In [82]:
phi.kernel_polynomial()


Out[82]:
x + 2

In [83]:
phi.kernel_polynomial()(R[0])


Out[83]:
0

Pairings


In [89]:
L.<z> = GF(p^2)
EE = E.change_ring(L)
EE


Out[89]:
Elliptic Curve defined by y^2 = x^3 + x^2 + 2*x + 3 over Finite Field in z of size 1048583^2

In [90]:
EE.cardinality().factor()


Out[90]:
3^4 * 7 * 19 * 23 * 241 * 18413

In [92]:
T = EE.lift_x(912851*z + 87136)
T.order()


Out[92]:
3

In [93]:
w = T.weil_pairing(EE(R), 3)
w


Out[93]:
1048582*z + 1048582

In [94]:
w.multiplicative_order()


Out[94]:
3

In [95]:
T.weil_pairing(2*T, 3)


Out[95]:
1

In [ ]: