Sage Quick Reference (Basic Math)Peter Jipsen, version 1.1 (w/modiﬁcation by nu)
latest version at wiki.sagemath.org/quickref
GNU Free Document License, extend for your own use
Aim: map standard math notation to Sage commands

函数定義: e.g. f (x) = x2
(微分等ができるシンボリックな) 函数として: f(x)=x^2
Python 関数として定義する: f=lambda x: x^2 またはdef f(x): return x^2Constants: π = pi e = e i = i ∞ = oo
Approximate: pi.n(digits=18) = 3.14159265358979324
Functions: sin cos tan sec csc cot sinh cosh tanh sech cschcoth log ln exp√
aab = a*b= a/b ab = a^bx = sqrt(x)b√nx = x^(1/n) |x| = abs(x) logb (x) = log(x,b)
Symbolic variables: e.g. t,u,v,y = var(’t u v y’)Deﬁne function: e.g. f (x) = x2
As symbolic function (can integrate, etc): f(x)=x^2 or
As Python function: f=lambda x: x^2 or
def f(x): return x^2

Notebook(とコマンドライン) Notebook (and commandline)
セルの評価: hshift-enteri
comhtabi command と補完しようとする.
command ?htabi ドキュメントを表示command ??htabi ソースを表示
a.htabi オブジェクト a のメソッドを表示 (more: dir(a))
search doc(’string or regexp’) ドキュメントへのリンク
search src(’string or regexp’) ソースへのリンクを表示 式に対する操作 Operations on expressions
lprint() LATEX 形式の出力に切替える
factor(...)
expand(...)(...).simplify ...
version() Sage のバージョンを表示
シンボリックな等式: f(x)==g(x)Insert cell: セルの間の青い線をクリック
は直前の出力
Delete cell: 内容を消してから backspace+a-a*a/a で等式を操作できる
Evaluate cell: hshift-enteri
f (x) = g(x) を解く: solve(f(x)==g(x),x)
comhtabi tries to complete commandsolve([f(x,y)==0, g(x,y)==0], x,y)command?htabi shows documentationcommand??htabi shows sourcex ∈ [a, b] s.t. f (x) ≈ 0 を探す: find root(f(x), a, b)
a.htabi shows all methods for object a (more: dir(a))
nXsearch doc(’string or regexp’) shows links to docs
f (i) = sum([f(i) for i in [k..n]])search src(’string or regexp’) shows links to source
lprint() toggle LATEX output modeversion() print version of Sage
Insert cell: click on blue line between cells
Delete cell: delete content then backspace

i=kn
Yf (i) = prod([f(i) for i in [k..n]])i=kfactor(...)
expand(...)(...).simplify ...
Symbolic equations: f(x)==g(x)is previous output+a-a*a/a manipulates equation
Solve f (x) = g(x): solve(f(x)==g(x),x)
solve([f(x,y)==0, g(x,y)==0], x,y)find root(f(x), a, b) ﬁnd x ∈ [a, b] s.t. f (x) ≈ 0nX
f (i) = sum([f(i) for i in [k..n]])数の型 Numerical types
整数: Z = ZZ e.g. -2 -1 0 1 10^100
有理数: Q = QQ e.g. 1/2 1/1000 314/100 -42
小数: R ≈ RR e.g. .5 0.001 3.14 -42
複素数: C ≈ CC e.g. 1+i 2.5-3*iIntegers: Z = ZZ e.g. -2 -1 0 1 10^100Rationals: Q = QQ e.g. 1/2 1/1000 314/100 -42Decimals: R ≈ RR e.g. .5 0.001 3.14 -42Complex: C ≈ CC e.g. 1+i 2.5-3*i

基本的な定数と函数 Basic constants and functions
定数: π = pi e = e i = i ∞ = oo
近似値: pi.n(digits=18) = 3.14159265358979324
函数: sin cos tan sec csc cot sinh cosh tanh sech cschcoth log ln exp√
ab = a*b ab = a/b ab = a^bx = sqrt(x)√nx = x^(1/n) |x| = abs(x) logb (x) = log(x,b)
不定元: e.g. t,u,v,y = var(’t u v y’)

i=kn
Yf (i) = prod([f(i) for i in [k..n]])i=k微分積分 Calculus
lim f (x) = limit(f(x), x=a)x→aR

f (x)dx = integral(f(x),x)
integral = integrate
Rbf (x)dx = integral(f(x),x,a,b)a次数 n の a に関する Taylor 多項式: taylor(f(x),x,a,n)
lim f (x) = limit(f(x), x=a)x→alim f (x) = limit(f(x), x=a, dir=’minus’)x→a−lim f (x) = limit(f(x), x=a, dir=’plus’)

x→a+d(f (x)) = diff(f(x),x)dx∂(f (x, y)) = diff(f(x,y),x)∂xdiff = differentiate = derivativeRf (x)dx = integral(f(x),x)
integral = integrate
Rba f (x)dx = integral(f(x),x,a,b)Taylor polynomial, deg n about a: taylor(f(x),x,a,n)二次元グラフィックス 2d graphics
line([(x1 ,y1 ),. . .,(xn ,yn )],options)polygon([(x1 ,y1 ),. . .,(xn ,yn )],options)circle((x,y),r,options)text("txt",(x,y),options)
options は plot.options にあるものを使用,
例 thickness=pixel , rgbcolor=(r,g,b), hue=h(ただし 0 ≤ r, b, g, h ≤ 1)
縦横比の調整には figsize=[w,h]plot(f(x),xmin ,xmax ,options)parametric plot((f(t),g(t)),tmin ,tmax ,options)polar plot(f(t),tmin ,tmax ,options)
グラフの結合: circle((1,1),1)+line([(0,0),(2,2)])
animate(list of graphics objects ,options).show(delay=20)
line([(x1 ,y1 ),. . .,(xn ,yn )],options)polygon([(x1 ,y1 ),. . .,(xn ,yn )],options)circle((x,y),r,options)text("txt",(x,y),options)
options as in plot.options,e.g. thickness=pixel, rgbcolor=(r,g,b), hue=h,where 0 ≤ r, b, g, h ≤ 1
use option figsize=[w,h] to adjust aspect ratioplot(f(x),xmin ,xmax ,options)parametric plot((f(t),g(t)),tmin ,tmax ,options)polar plot(f(t),tmin ,tmax ,options)combine graphs: circle((1,1),1)+line([(0,0),(2,2)])
animate(list of graphics objects ,options).show(delay=20)

lim f (x) = limit(f(x), x=a, dir=’minus’)x→a−lim f (x) = limit(f(x), x=a, dir=’plus’)x→a+ddx (f (x)) = diff(f(x),x)∂∂x (f (x, y)) = diff(f(x,y),x)diff = differentiate = derivative

三次元グラフィックス 3d graphics
line3d([(x1 ,y1 ,z1 ),. . .,(xn ,yn ,zn )],options)sphere((x,y,z),r,options)tetrahedron((x,y,z),size,options)cube((x,y,z),size,options)octahedron((x,y,z),size,options)dodecahedron((x,y,z),size,options)
icosahedron((x,y,z),size,options)
options の例 aspect ratio=[1,1,1] color=’red’ opacity
plot3d(f(x,y),[xb ,xe ],[yb ,ye ],options)
オプションに plot points=[m, n] or plot3d adaptive を使う
parametric plot3d((f(t),g(t),h(t)),[tb ,te ],options)parametric plot3d((f(u,v),g(u,v),h(u,v)),[ub ,ue ],[vb ,ve ],options)graphics objects を結合するには + を使う
line3d([(x1 ,y1 ,z1 ),. . .,(xn ,yn ,zn )],options)sphere((x,y,z),r,options)tetrahedron((x,y,z),size,options)cube((x,y,z),size,options)octahedron((x,y,z),size,options)dodecahedron((x,y,z),size,options)
icosahedron((x,y,z),size,options)
options e.g. aspect ratio=[1,1,1] color=’red’ opacity
plot3d(f(x,y),[xb ,xe ],[yb ,ye ],options)add option plot points=[m, n] or use plot3d adaptive
parametric plot3d((f(t),g(t),h(t)),[tb ,te ],options)parametric plot3d((f(u,v),g(u,v),h(u,v)),[ub ,ue ],[vb ,ve ],options)use + to combine graphics objects

離散数学 Discrete mathbxc = floor(x) dxe = ceil(x)n を k で割った余り = n%kk|n iﬀ n%k==0¡x¢n! = factorial(n)=binomial(x,m)
m
φ = golden ratio
φ(n) = euler phi(n)文字列: 例 s = ’Hello’ = "Hello" = ""+"He"+’llo’
s[0]=’H’s[-1]=’o’s[1:3]=’el’s[3:]=’lo’
リスト: 例 [1,’Hello’,x] = []+[1,’Hello’]+[x]タプル: 例 (1,’Hello’,x) (immutable)
集合: 例 {1, 2, 1, a} = Set([1,2,1,’a’]) (= {1, 2, a})集合の内包的記法 ≈ リストの内包表記, 例{f (x) : x ∈ X, x > 0} = Set([f(x) for x in X if xi0])
bxc = floor(x) dxe = ceil(x)Remainder of n divided `by ´k = n%kk|n iﬀ n%k==0
xn! = factorial(n)= binomial(x,m)
m
φ = golden ratio
φ(n) = euler phi(n)Strings: e.g. s = ’Hello’ = "Hello" = ""+"He"+’llo’
s[0]=’H’s[-1]=’o’s[1:3]=’el’s[3:]=’lo’
Lists: e.g. [1,’Hello’,x] = []+[1,’Hello’]+[x]Tuples: e.g. (1,’Hello’,x) (immutable)
Sets: e.g. {1, 2, 1, a} = Set([1,2,1,’a’]) (= {1, 2, a})
List comprehension ≈ set builder notation, e.g.
{f (x) : x ∈ X, x > 0} = Set([f(x) for x in X if xi0])

線形代数

Linear algebraµ ¶1= vector([1,2])2µ¶
1 2= matrix([[1,2],[3,4]])3 4¯¯¯1 2 ¯¯¯¯3 4¯ = det(matrix([[1,2],[3,4]]))
Av = A*v A−1 = A^-1 At = A.transpose()
methods:nrows() ncols() nullity() rank() trace()...
„ «1= vector([1,2])2„«
1 2= matrix([[1,2],[3,4]])
˛ 3 4˛˛1 2˛˛˛
˛3 4˛ = det(matrix([[1,2],[3,4]]))
Av = A*v A−1 = A^-1 At = A.transpose()
methods: nrows() ncols() nullity() rank() trace()...

Sage のモジュールとパッケージ Sage modules and packages
from module name import *(多くが既に読み込み済)
例 calculus coding combinat crypto functions games
geometry graphs groups logic matrix numerical plot
probability rings sets stats
sage.module name.all.htabi export されたコマンドを表示
Std packages: Maxima GP/PARI GAP Singular R Shell...
Opt packages: Biopython Fricas(Axiom) Gnuplot Kash...
%package name then use package command syntax
time command timing information を表示
from module name import *(many preloaded)e.g. calculus coding combinat crypto functions games geometry
graphs groups logic matrix numerical plot probability rings
sets stats
sage.module name.all.htabi shows exported commands
Std packages: Maxima GP/PARI GAP Singular R Shell...
Opt packages: Biopython Fricas(Axiom) Gnuplot Kash...
%package name then use package command syntax
time commandto show timing information