Вы находитесь на странице: 1из 2

Sage Quick Reference

William Stein (based on work of P. Jipsen) Arithmetic 2D graphics


GNU Free Document License, extend for your own use √
ab = a*b ab = a/b ab = a^b x = sqrt(x) 1
0.75
√ 0.5
0.25
n
x = x^(1/n) |x| = abs(x) logb (x) = log(x,b) -6 -4 -2 -0.25 2 4 6
Notebook n
-0.5
-0.75
X -1
Sums: f (i) = sum(f(i) for i in (k..n))
i=k line([(x1 ,y1 ),. . .,(xn ,yn )],options)
n
Y polygon([(x1 ,y1 ),. . .,(xn ,yn )],options)
Products: f (i) = prod(f(i) for i in (k..n)) circle((x,y),r,options)
i=k
text("txt",(x,y),options)
Evaluate cell: hshift-enteri
Constants and functions options as in plot.options, e.g. thickness=pixel ,
Evaluate cell creating new cell: halt-enteri
Constants: π = pi e = e i = i ∞ = oo rgbcolor=(r,g,b), hue=h where 0 ≤ r, b, g, h ≤ 1
Split cell: hcontrol-;i
φ = golden_ratio γ = euler_gamma show(graphic, options)
Join cells: hcontrol-backspacei
Approximate: pi.n(digits=18) = 3.14159265358979324 use figsize=[w,h] to adjust size
Insert math cell: click blue line between cells
Functions: sin cos tan sec csc cot sinh cosh tanh use aspect_ratio=number to adjust aspect ratio
Insert text/HTML cell: shift-click blue line between cells sech csch coth log ln exp ...
plot(f(x),(x, xmin , xmax ),options)
Delete cell: delete content then backspace Python function: def f(x): return x^2
parametric plot((f(t),g(t)),(t, tmin , tmax ),options)
Command line polar plot(f(t),(t, tmin , tmax ),options)
Interactive functions
comhtabi complete command combine: circle((1,1),1)+line([(0,0),(2,2)])
Put @interact before function (vars determine controls)
*bar *? list command names containing “bar” animate(list of graphics, options).show(delay=20)
@interact
command ?htabi shows documentation def f(n=[0..4], s=(1..5), c=Color("red")):
3D graphics
command ??htabi shows source code var("x");show(plot(sin(n+x^s),-pi,pi,color=c))
a.htabi shows methods for object a (more: dir(a))
a._htabi shows hidden methods for object a Symbolic expressions
search_doc("string or regexp") fulltext search of docs Define new symbolic variables: var("t u v y z")
search_src("string or regexp") search source code Symbolic function: e.g. f (x) = x2 f(x)=x^2
_ is previous output Relations: f==g f<=g f>=g f<g f>g
Solve f = g: solve(f(x)==g(x), x)
Numbers line3d([(x1 ,y1 ,z1 ),. . .,(xn ,yn ,zn )],options)
solve([f(x,y)==0, g(x,y)==0], x,y)
Integers: Z = ZZ e.g. -2 -1 0 1 10^100 sphere((x,y,z),r,options)
factor(...) expand(...) (...).simplify_...
Rationals: Q = QQ e.g. 1/2 1/1000 314/100 -2/1 text3d("txt", (x,y,z), options)
find_root(f(x), a, b) find x ∈ [a, b] s.t. f (x) ≈ 0
Reals: R ≈ RR e.g. .5 0.001 3.14 1.23e10000 tetrahedron((x,y,z),size,options)
Complex: C ≈ CC e.g. CC(1,1) CC(2.5,-3) Calculus cube((x,y,z),size,options)
Double precision: RDF and CDF e.g. CDF(2.1,3) lim f (x) = limit(f(x), x=a) octahedron((x,y,z),size,options)
x→a
Mod n: Z/nZ = Zmod e.g. Mod(2,3) Zmod(3)(2) d
dodecahedron((x,y,z),size,options)
dx (f (x)) = diff(f(x),x)
icosahedron((x,y,z),size,options)
Finite fields: Fq = GF e.g. GF(3)(2) GF(9,"a").0 ∂
Polynomials: R[x, y] e.g. S.<x,y>=QQ[] x+2*y^3 ∂x (f (x, y))= diff(f(x,y),x) plot3d(f(x, y),(x, xb , xe ), (y, yb , ye ),options)
diff = differentiate = derivative parametric plot3d((f,g,h),(t, tb , te ),options)
Series: R[[t]] e.g. S.<t>=QQ[[]] 1/2+2*t+O(t^2) R
f (x)dx = integral(f(x),x) parametric plot3d((f(u, v),g(u, v),h(u, v)),
p-adic numbers: Zp ≈Zp, Qp ≈Qp e.g. 2+3*5+O(5^2) Rb
Algebraic closure: Q = QQbar e.g. QQbar(2^(1/5)) a
f (x)dx = integral(f(x),x,a,b) (u, ub , ue ),(v, vb , ve ),options)
Rb
Interval arithmetic: RIF e.g. sage: RIF((1,1.00001)) a
f (x)dx ≈ numerical_integral(f(x),a,b) options: aspect ratio=[1, 1, 1], color="red"
Number field: R.<x>=QQ[];K.<a>=NumberField(x^3+x+1) Taylor polynomial, deg n about a: taylor(f(x),x,a,n) opacity=0.5, figsize=6, viewer="tachyon"
Crystals: CrystalOfTableaux(["A",3], shape=[3,2])
Discrete math Lattice Polytopes: A=random_matrix(ZZ,3,6,x=7) Numerical mathematics
bxc = floor(x) dxe = ceil(x) L=LatticePolytope(A) L.npoints() L.plot3d() Packages: import numpy, scipy, cvxopt
Remainder of n divided by k = n%k k|n iff n%k==0 Minimization: var("x y z")
x Matrix algebra

n! = factorial(n) m = binomial(x,m)   minimize(x^2+x*y^3+(1-z)^2-1, [1,1,1])
φ(n) = euler phi(n) 1
= vector([1,2])
Strings: e.g. s = "Hello" = "He"+’llo’ 2 Number theory
 
1 2
s[0]="H" s[-1]="o" s[1:3]="el" s[3:]="lo" = matrix(QQ,[[1,2],[3,4]], sparse=False) Primes: prime_range(n,m), is_prime, next_prime
3 4 Factor: factor(n), qsieve(n), ecm.factor(n)
Lists: e.g. [1,"Hello",x] = []+[1,"Hello"]+[x]  
1 2 3 symbol: ab = kronecker symbol(a,b)

Tuples: e.g. (1,"Hello",x) (immutable) = matrix(QQ,2,3,[1,2,3, 4,5,6]) Kronecker
4 5 6 Continued fractions: continued_fraction(x)
Sets: e.g. {1, 2, 1, a} = Set([1,2,1,"a"]) (= {1, 2, a})
1 2
List comprehension ≈ set builder notation, e.g. Bernoulli numbers: bernoulli(n), bernoulli mod p(p)
3 4 = det(matrix(QQ,[[1,2],[3,4]]))

{f (x) : x ∈ X, x > 0} = Set([f(x) for x in X if x>0]) Elliptic curves: EllipticCurve([a1 , a2 , a3 , a4 , a6 ])
Av = A*v A−1 = A^-1 At = A.transpose() Dirichlet characters: DirichletGroup(N)
Graph theory Solve Ax = v: A\v or A.solve_right(v) Modular forms: ModularForms(level, weight)
Solve xA = v: A.solve_left(v) Modular symbols: ModularSymbols(level, weight, sign)
Reduced row echelon form: A.echelon_form() Brandt modules: BrandtModule(level, weight)
Rank and nullity: A.rank() A.nullity() Modular abelian varieties: J0(N), J1(N)
Hessenberg form: A.hessenberg_form()
Characteristic polynomial: A.charpoly() Group theory
Graph: G = Graph({0:[1,2,3], 2:[4]}) Eigenvalues: A.eigenvalues() G = PermutationGroup([[(1,2,3),(4,5)],[(3,4)]])
Directed Graph: DiGraph(dictionary) Eigenvectors: A.eigenvectors_right() (also left) SymmetricGroup(n), AlternatingGroup(n)
Graph families: graphs.htabi Gram-Schmidt: A.gram_schmidt() Abelian groups: AbelianGroup([3,15])
Invariants: G.chromatic polynomial(), G.is planar() Visualize: A.plot() Matrix groups: GL, SL, Sp, SU, GU, SO, GO
Paths: G.shortest path() LLL reduction: matrix(ZZ,...).LLL() Functions: G.sylow subgroup(p), G.character table(),
Visualize: G.plot(), G.plot3d() Hermite form: matrix(ZZ,...).hermite_form() G.normal subgroups(), G.cayley graph()
Automorphisms: G.automorphism group(),
G1.is isomorphic(G2), G1.is subgraph(G2) Linear algebra Noncommutative rings
Quaternions: Q.<i,j,k> = QuaternionAlgebra(a,b)
Combinatorics Free algebra: R.<a,b,c> = FreeAlgebra(QQ, 3)

Python modules
import module name
Vector space K n = K^n e.g. QQ^3 RR^2 CC^4
module_name.htabi and help(module_name)
Integer sequences: sloane find(list), sloane.htabi Subspace: span(vectors, field )
Partitions: P=Partitions(n) P.count() E.g., span([[1,2,3], [2,3,5]], QQ) Profiling and debugging
Combinations: C=Combinations(list) C.list() Kernel: A.right_kernel() (also left) time command : show timing information
Cartesian product: CartesianProduct(P,C) Sum and intersection: V + W and V.intersection(W) timeit("command"): accurately time command
Tableau: Tableau([[1,2,3],[4,5]]) Basis: V.basis() t = cputime(); cputime(t): elapsed CPU time
Words: W=Words("abc"); W("aabca") Basis matrix: V.basis_matrix() t = walltime(); walltime(t): elapsed wall time
Posets: Poset([[1,2],[4],[3],[4],[]]) Restrict matrix to subspace: A.restrict(V) %pdb: turn on interactive debugger (command line only)
Root systems: RootSystem(["A",3]) Vector in terms of basis: V.coordinates(vector) %prun command: profile command (command line only)

Вам также может понравиться