Intro_NumThy_Sage_2

50 days ago by kast5807

This is a follow-up worksheet for Sage.  if you've done the basic worksheet then you might want to know more number theory commands and fun examples.

Fields and Rings you may Like

You can work with finite field using the GF() ("Galois field") syntax.

F = GF(7) F(3)^(-1) 
       
5
5

When doing field extensions, you need syntax to name the extending element.  If you leave Sage to do it by itself, it will pick the minimal polynomial for you.

F.<a> = GF(7^2) F(a).minimal_polynomial() 
       
x^2 + 6*x + 3
x^2 + 6*x + 3
a + a^(-1) 
       
6*a
6*a

Here's how you pick your own.  The variable 'x' is reserved as a "general variable' for polynomials etc. in Sage unless you assign it something, in which case this syntax will get screwed up.

F.<a> = GF(7^2, modulus = x^2 - 3) F(a).minimal_polynomial() 
       
x^2 + 4
x^2 + 4

Number fields are similar. 

F.<a> = NumberField(x^2+1) R = F.ring_of_integers() R(5).factor() 
       
(a) * (-a - 2) * (2*a + 1)
(a) * (-a - 2) * (2*a + 1)

You can also define p-adics by specifying a prime.  You can then set precision and p-adics are printed as series up to some big O term.

F = Qp(7) F(1/2) 
       
4 + 3*7 + 3*7^2 + 3*7^3 + 3*7^4 + 3*7^5 + 3*7^6 + 3*7^7 + 3*7^8 + 3*7^9
+ 3*7^10 + 3*7^11 + 3*7^12 + 3*7^13 + 3*7^14 + 3*7^15 + 3*7^16 + 3*7^17
+ 3*7^18 + 3*7^19 + O(7^20)
4 + 3*7 + 3*7^2 + 3*7^3 + 3*7^4 + 3*7^5 + 3*7^6 + 3*7^7 + 3*7^8 + 3*7^9 + 3*7^10 + 3*7^11 + 3*7^12 + 3*7^13 + 3*7^14 + 3*7^15 + 3*7^16 + 3*7^17 + 3*7^18 + 3*7^19 + O(7^20)

Elliptic Curves

You can define elliptic curves from $j$-invariant, coefficients, or database entry name.

E = EllipticCurve(j=1728) E 
       
Elliptic Curve defined by y^2 = x^3 - x over Rational Field
Elliptic Curve defined by y^2 = x^3 - x over Rational Field
E.torsion_points() 
       
[(-1 : 0 : 1), (0 : 0 : 1), (0 : 1 : 0), (1 : 0 : 1)]
[(-1 : 0 : 1), (0 : 0 : 1), (0 : 1 : 0), (1 : 0 : 1)]

Here's how you can specify a point on a curve (we use projective coordinates).

P = E([-1,0,1]) P 
       
(-1 : 0 : 1)
(-1 : 0 : 1)

This happens to be a 2-torsion point, so when I multiply it by 2, I get the identity (0:1:0).

2*P 
       
(0 : 1 : 0)
(0 : 1 : 0)

Always fun to draw a picture!

E.plot() 
       

How about over a finite field?  I'm sure such a plot can be improved somehow.

E = EllipticCurve(GF(7),j=1728) E.plot()