Sage - Camp

advertisement
Pure and Applied Number Theory School
2015.8.11
Cheolmin Park
NIMS
 SAGE
(System for Algebra and
Geometry Experimentation):
open-source mathematics
software

Sage is a free open-source mathematics
software system licensed under the GPL. It
combines the power of many existing opensource packages into a common Pythonbased interface.
◦ Mission: Creating a viable free open source
alternative to Magma, Maple, Mathematica and
Matlab.



http://www.sagemath.org/
Current version: 6.8
Free, open source

Sage provides
◦ Basic Algebra and Calculus
 Solving Equations, Differentiation, …
◦
◦
◦
◦

Plotting 2,3-dimensional plots
Linear Algebra, Polynomials, Groups
p-adic numbers
Elliptic Curve, …
Easy to use




SAGE is Linux based software.
If you want to use SAGE on Window OS,
you need to install VirtualBox for Window
which can run linux in Window OS.
Refer to “install guide” in www.sagemath.org/
We use SAGE Online!!!
◦ https://cloud.sagemath.com/

IE9 cannot connect to this site.
In this case, use higher version of IE or chrome
browser.

If you already have account, sign in

If not, you need to create account.

◦
◦
◦
◦
It is for free.
Click item “First, agree to the Terms of Service”
Write Name/Email/ Choose a password
Click item “Create account for free”

Create New Project…

Title…and click “create project”

Click item “⨁New”

Click “Sage Worksheet”
A
very brief Tour of Sage

Run code: click
or shift+Enter
◦ e.g. 2+3 shift+Enter



Sage uses = for assignment
Comparison check: ==, <=, >=, <, >
Basic arithmetic
◦
◦
◦
◦
**, ^: exponentiation ( 2^3 == 2**3)
%: remainder (10%3)
//: quotient
sqrt(10), sin(5), sin(pi)

Sage use for calling function
◦ variable.function() or function(variable)
◦ (eg1) n=2015 n.factor() factor(n)
◦ (eg2) M=matrix(2, 2, [1,pi, e,5]) M.det()

det(M)
For defining function,
(eg1)def f(a,b):
return a+b
(eg2)def fm(a,b):
if a >=b: c=a
else: c=b
return c
Note: indentation is important.







var('x y')
f = x^3 * e^(y*x) * sin(y*x);
f.diff(x)
latex(f.diff(x))
show(f.diff(x))
f(x,3): You can evaluate f at y=3
plot(f(x,3))









CC: complex field
RR: real field
QQ: rational field
ZZ: integer ring
Integers(n): ring Z/nZ of integers modulo n
GF(p): finite field of order p
GF(p^n): finite field of order p^n
QQ[x]: Univariate Polynomial Ring in x over
Rational Field
QQ[x,y]: Multivariate Polynomial Ring in x, y over
Rational Field

k.<x> = CC[] (k is univariate polynomial
ring in x over complex field)
f=x^3+x
factor(f)
f.roots()

Change field and try factor(f), f.roots()



EllipticCurve(fields(rings),[a1,a2,a3,a4,a5]):
Elliptic Curve defined by y^2 + a1*x*y + a3*y
= x^3 + a2*x^2 + a4*x + a5 over Fields


Example
◦
◦
◦
◦
EllipticCurve(QQ,[10,20,30,40,50])
k=EllipticCurve(GF(127),[10,20,30,40,50])
k.order(), P=k.random_point(), Q=k(75,4)
123*P, P+Q





mod(8+5, 7) == (8+5)%7 : (8+5) mod 7
pow(3,6,11) : 3^6 mod 11
inverse_mod(2,19): 2^-1 mod 19
gcd(12, 36); xgcd(3,5)
functions related to prime
◦ prime_factor(n), divisors(n), next_prime(n),
nth_prime(i), is_prime(n), prime_pi(n) (# of primes
less than n), euler_phi(n), primitive_root(p)…

x=crt(y1,y2,p1,p2): x mod p1 =y1, x mod p2
=y2



P.<x>=QQ[]
K.<a>=NumberField(x^2+1)
R.<y> = K[]

f = y^2 + y + 1
L.<b> = K.extension(f)

S.<c>=CyclotomicField(n)






P.<x>=QQ[]
K.<a>=NumberField(x^2+1)
OK=K.ring_of_integers()
O3 = K.order(3*a); O3 #Z+3aZ
O3.gens()









K.<a> = NumberField(x^2 + 23)
I = K.fractional_ideal(2, 1/2*a - 1/2)
J = I^2
I*J
factor(I) factor(J)
is_prime(I)
I = K.fractional_ideal(2)
I.factor()
K.class_group()

You can use reference manual or quick search
in www.sage.org

use help() in Sage

function??: can see source code of function
◦ factor??

Tab completion: Type obj followed by tab to
see all completions of obj.
◦ fac+tab
Thank you!
Download