Sage Quick Reference (Basic Math) Peter Jipsen, version 1.1 (w/modification 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

Notebook(とコマンドライン) Notebook (and commandline)

セルの評価: ⟨shift-enter⟩ com⟨tab⟩ command と補完しようとする. command?⟨tab⟩ ドキュメントを表示 command??⟨tab⟩ ソースを表示 a.⟨tab⟩ オブジェクト a のメソッドを表示 (more: dir(a)) search doc('string or regexp') ドキュメントへのリンク search src('string or regexp') ソースへのリンクを表示 lprint() L^{A}TEX 形式の出力に切替える version() Sage のバージョンを表示 Insert cell: セルの間の青い線をクリック Delete cell: 内容を消してから backspace

Evaluate cell: ⟨shift-enter⟩ com⟨tab⟩ tries to complete command command?⟨tab⟩ shows documentation command??⟨tab⟩ shows source a.⟨tab⟩ shows all methods for object a (more: dir(a)) search doc('string or regexp') shows links to docs search src('string or regexp') shows links to source lprint() toggle L^{A}TEX output mode version() print version of Sage Insert cell: click on blue line between cells Delete cell: delete content then backspace

数の型 Numerical types

整数: ℤ = ZZ e.g. -2 -1 0 1 10^100
有理数: ℚ = QQ e.g. 1/2 1/1000 314/100 -42
小数: ℝ ≈ RR e.g. .5 0.001 3.14 -42
複素数: ℂ ≈ CC e.g. 1+i 2.5-3*i

Integers: ℤ = ZZ e.g. -2 -1 0 1 10^100

Rationals: ℚ = QQ e.g. 1/2 1/1000 314/100 -42
Decimals: ℝ ≈ RR e.g. .5 0.001 3.14 -42

Complex: ℂ ≈ 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 csch
coth log ln exp
ab = a*b   \frac{a}{b} = a/b a^{b} = a^b   \sqrt{x} = sqrt(x)
\sqrt[n]{x} = x^(1/n) |x| = abs(x) log_{b}(x) = log(x,b)
不定元: e.g. t,u,v,y = var('t u v y')

函数定義: e.g. f(x) = x^{2} (微分等ができるシンボリックな) 函数として: f(x)=x^2 Python 関数として定義する: f=lambda x: x^2 または

def f(x): return x^2

Constants: π = pi e = e i = i ∞ = oo Approximate: pi.n(digits=18) = 3.14159265358979324

Functions: sin cos tan sec csc cot sinh cosh tanh sech csch
coth log ln exp
ab = a*b   \frac{a}{b} = a/b a^{b} = a^b   \sqrt{x} = sqrt(x)
\sqrt[n]{x} = x^(1/n) |x| = abs(x) log_{b}(x) = log(x,b)

Symbolic variables: e.g. t,u,v,y = var('t u v y') Define function: e.g. f(x) = x^{2}

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

式に対する操作 Operations on expressions

factor(...)    expand(...)    (...).simplify ...
シンボリックな等式: f(x)==g(x)

は直前の出力 +a -a *a /a で等式を操作できる

f(x) = g(x) を解く: solve(f(x)==g(x),x)
solve([f(x,y)==0, g(x,y)==0], x,y)

x ∈ [a, b] s.t. f(x) ≈ 0 を探す: find root(f(x), a, b)

∑_{i=k}^{n} f(i) = sum([f(i) for i in [k..n]])
∏_{i=k}^{n} f(i) = prod([f(i) for i in [k..n]])
factor(...)    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) find x ∈ [a, b] s.t. f(x) ≈ 0

∑_{i=k}^{n} f(i) = sum([f(i) for i in [k..n]])
∏_{i=k}^{n} f(i) = prod([f(i) for i in [k..n]])

微分積分 Calculus

lim_{x→a} f(x) = limit(f(x), x=a)
lim_{x→a^{−}} f(x) = limit(f(x), x=a, dir='minus')
lim_{x→a^{+}} f(x) = limit(f(x), x=a, dir='plus')
\frac{d}{dx}(f(x)) = diff(f(x),x)
\frac{∂}{∂x}(f(x, y)) = diff(f(x,y),x)
diff = differentiate = derivative

∫ f(x)dx = integral(f(x),x)
integral = integrate
∫_{a}^{b} f(x)dx = integral(f(x),x,a,b)

次数 n の a に関する Taylor 多項式: taylor(f(x),x,a,n)

lim_{x→a} f(x) = limit(f(x), x=a)
lim_{x→a^{−}} f(x) = limit(f(x), x=a, dir='minus')
lim_{x→a^{+}} f(x) = limit(f(x), x=a, dir='plus')
\frac{d}{dx} (f(x)) = diff(f(x),x)
\frac{∂}{∂x} (f(x, y)) = diff(f(x,y),x)
diff = differentiate = derivative
∫ f(x)dx = integral(f(x),x)
integral = integrate
∫_{a}^{b} f(x)dx = integral(f(x),x,a,b)

Taylor polynomial, deg n about a: taylor(f(x),x,a,n)

二次元グラフィックス 2d graphics line([(x_{1},y_{1}),…,(x_{n},y_{n})],options)

polygon([(x_{1},y_{1}),. . .,(x_{n},y_{n})],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),x_{min},x_{max},options)

parametric plot((f(t),g(t)),t_{min},t_{max},options)
polar plot(f(t),t_{min},t_{max},options)
グラフの結合: circle((1,1),1)+line([(0,0),(2,2)])

animate(list of graphics objects ,options).show(delay=20)

line([(x_{1},y_{1}),…,(x_{n},y_{n})],options)

polygon([(x_{1},y_{1}),. . .,(x_{n},y_{n})],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 ratio plot(f(x),x_{min},x_{max},options)

parametric plot((f(t),g(t)),t_{min},t_{max},options)
polar plot(f(t),t_{min},t_{max},options)
combine graphs: circle((1,1),1)+line([(0,0),(2,2)])

animate(list of graphics objects ,options).show(delay=20)

三次元グラフィックス 3d graphics line3d([(x_{1},y_{1},z_{1}),…,(x_{n},y_{n},z_{n})],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),[x_{b},x_{e}],[y_{b},y_{e}],options)
オプションに plot points=[m, n] or plot3d adaptive を使う
parametric plot3d((f(t),g(t),h(t)),[t_{b},t_{e}],options)
parametric plot3d((f(u,v),g(u,v),h(u,v)),

[u_{b},u_{e}],[v_{b},v_{e}],options)

graphics objects を結合するには + を使う

line3d([(x_{1},y_{1},z_{1}),…,(x_{n},y_{n},z_{n})],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),[x_{b},x_{e}],[y_{b},y_{e}],options)
add option plot points=[m, n] or use plot3d adaptive
parametric plot3d((f(t),g(t),h(t)),[t_{b},t_{e}],options)
parametric plot3d((f(u,v),g(u,v),h(u,v)),

[u_{b},u_{e}],[v_{b},v_{e}],options)

use + to combine graphics objects

離散数学 Discrete math

⌊x⌋ = floor(x) ⌈x⌉ = ceil(x)

n を k で割った余り = n%k k|n iff n%k==0

n! = factorial(n)    \binom{x}{m} = binomial(x,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 x⟩0])
⌊x⌋ = floor(x) ⌈x⌉ = ceil(x)

Remainder of n divided by k = n%k k|n iff n%k==0

n! = factorial(n)     \binom{x}{m} = binomial(x,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 x⟩0])

線形代数 Linear algebra

                                                (\begin{matrix}1 \\ 2 \end{matrix}) = vector([1,2])

                                                (\begin{matrix}1 & 2 \\ 3 & 4 \end{matrix}) = matrix([[1,2],[3,4]])

                                                |\begin{matrix}1 & 2 \\ 3 & 4 \end{matrix}| = det(matrix([[1,2],[3,4]]))
                                                Av = A*v A^{−1} = A^-1 A^{t} = A.transpose()
                                                methods: nrows() ncols() nullity() rank() trace()...

                                                                  (\begin{matrix}1 \\ 2 \end{matrix}) = vector([1,2])

                                                                  (\begin{matrix}1 & 2 \\ 3 & 4 \end{matrix}) = matrix([[1,2],[3,4]])

                                                                  |\begin{matrix}1 & 2 \\ 3 & 4 \end{matrix}| = det(matrix([[1,2],[3,4]]))
                                                                  Av = A*v A^{−1} = A^-1 A^{t} = 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.⟨tab⟩ 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.⟨tab⟩ 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 command to show timing information