AbbreviationsPatterns [DC, Tut] Mathematicacommands summary (cheat sheet) approx Approximation Blank: any expr arg Argument Hugo Touchette char Character Double blank: any seq of expr School of Mathematical Sciences, Queen Mary University of London cnt Counter Last updated: October 8, 2010cond ConditionTriple blank: zero or more args dist Distribution xAny expr namedx elem Element Equalities, assignments [DC] x hExpr namedxwith headh eqn Equation eval EvaluationxExact matchingx =Assign value expr Expression x+2/.x->2Output: 4 :=Also used for repeated evalDelayed eval fct Function x:pattNamed expr matchingpatt ==Equalitypatt Pattern f[aˆ b]/.f[x:ˆ ]->p[x]Output:p[aˆ b] rand Random =.Clear valueSame asClear str String x :vOptional arg with default valv ===Same asBoolean testSameQ val Value var Variablex h:vTyped arg with optional valv f[x ]:=f[x]=...Remember computed vals f[n ]fwith any named argn Rules and replacements [DC, Tut] f[n ,n ]fwith identical args xˆ nxto any named powern patt->exprTransformation ruleCan be assigned to names x ˆnAny expr to any power patt:->exprSame asDelayed rule:> a +bSum of two named exprs expr/.ruleReplacement SameasReplaceAll {a1 ,a2}List of two named exprs 1+2 x/.x->3Output: 7 patt/;condPattern with condRead:pattsuch thatcond expr/.{rule1,rule2}Multiple replacements (x /;NumberQ[x]&&Im[x]==0)Any real number expr//.ruleSame asReplace until no changesReplaceRepeated rule/;condRule with cond Applications, functions and maps [DC, Tut]patt?testPattern matching boolean test f[x ?NumberQ]:=x+2 f@exprPrefix formf[expr] (patt1|patt2|...) patt1orpatt2or ... expr//fPostfix formf[expr] {1,x,xˆ 2,yˆ 3})->q/.(x|xˆ nOutput:{1,q,q,yˆ 3} x˜f˜yInfix formf[x,y] expr/.ruleReplacement inexprwithrule f@@exprReplaces the head ofexprbyfSame asApply[f,expr] x+2/.x->2Output: 4 Plus@@{1,2}Output:1 + 2 = 3 f[a]+f[b]/.f[x ]->xˆ2Output:aˆ 2+bˆ 2 Similar to:f[x]/.f->gOutput:g[x] Position[f[a],g[b],f[b],f[x ]]Output:{{1},{2}} f/@listMapfonlistSame asMap[f,list] {1,x,xˆ 2,xˆ 3}->r[n]/.xˆ nOutput:{1,x,r[2],r[3]} f/@exprMapfon parts ofexpr Except[c]Anything exceptc Map[f,a+b]Output:f[a]+f[b] Except[c,patt]Patternpattexceptc Function[x,body]Function with argxSame as pure functions 2Cases[{1,0,2},Except[0]]Output:{1,2} Function[x,xˆ 2][n]Output:n 2 2Cases[{1,x,0},Except[0, Integer]]Output:{1} Map[Function[x,xˆ 2],a+b]Output:a+b Function[{vars},...]Many args Type specificationFiles [DC] body&Pure (anonymous) function IntegerNEsc-dsN-Esc Import["file"]Import file or url (#ˆ 2&)[5]Output: 25 RealREsc-dsR-Esc 2 2 Export["file",expr]Exportexprin file Map[#ˆ 2&,a+b]Output:a+b ComplexCEsc-dsC-Esc ImageResolution->ptsImage resolution in pts (1+g[#])&/@{1,2}Output:{1+g[1],1+g[2]} RationalZEsc-dsZ-Esc ReadList["file"]Returns list from file #nnth arg in pure function ListList type or head <<File‘Load content of file ##Seq of all args SymbolAny symbol StringString type of head Formatting [DC]Shortcuts [DC] √ HeadTypeHead Ctrl-@∙ FullFormDisplay full head form MatchQ[xˆ 2,Power] Ctrl-/Fraction MatrixFormDisplay in matrix form Ctrl-ˆSuperscript ColumnDisplay in column form Ctrl-Subscript TableFormDisplay in tabular form Ctrl-EnterNew row TreeFormDisplay in tree structure Ctrl-,New column
Sum Product Remainder ofm/n Solves polynomial eqn Expand polynomialp Factorizep Number of elems inexpr Numerator ofexpr Denominator ofexpr Display options forcmd Set options forcmd Explicit eval Piecewise definition Inverse fct n-fold fct composition List of compositions Iterate until fixed point Iteration list While iteration While iteration list Linear model Nonlinear model Graph (network) for adjacencym Graph withname Financial data fromdate Country data Weather data
Probability and statistics [DC] RandomReal[{a,b}]Uniform rand real in[a, b] RandomReal[dist]Rand real fromdist RandomInteger[{i,j}]Uniform integer in[i, j] RandomInteger[dist]Rand integer fromdist RandomSample[list,n]nsamples fromlist RandomSeed[]Reset seed PDF[dist,x]Density fct ofdist CDF[dist,x]Cumulant density fct ofdist Histogram[list,w]Histogram (bin widthw)