Expressions

Head[{1,2,3}]

FullForm[x+y]

Head[x]

FullForm[2]

Head[2]

ToString[2]

FullForm[%]

TreeForm[a-2b^2]

SymmetricPolynomial[2,Symbol/@CharacterRange["a","z"]]

?Notebook

Quick Start

Equal signs

(a+b)^2=a^2+2*a*b+b^2

(a+b)^2==a^2+2*a*b+b^2

Simplify[%]

(a+b)^2===a^2+2*a*b+b^2

test:=Print["this is a test"]

test

Programming constructs

If[2>3,"true","false"]

If[x==y,"true","false","don't know"]

Do[Print[n],{n,0,3}]

Concepts

List operations

matrix-vector multiplication:

{{1,2},{0,1}}.{2,-1}

Table[2*n,{n,1,10}]

Range[10]^3

{1,2,3}*{7,8,9}

{1,2,3}^{7,8,9}

MapThread[Append, {{{1,2},{0,1}},{2,-1}}]

Riffle[{a,b,c},{x,y,z}]

PadLeft[{a,b,c},10,{x,y,z},2]

Tally[Table[RandomInteger[9],{1000}]]

Structural operations for general expressions

expr=a+b+c

Length[expr]

Append[expr,d]

Map[Sqrt,expr]

expr[[2]]

Pattern Matching

{f,f[x],f[x,y],f[2]}/.f->g

{f,f[x],f[x,y],f[2]}/.f[x]->g[x]

{f,f[x],f[x,y],f[2]}/.f[x_]->g[x]

{f,f[x],f[x,y],f[2]}/.f[x_Integer]->g[x]

Cases[Sin[x-2y^2],a_[___]->a,{0,Infinity}]

de=D[x^2*y^2*f[x,y],x,x,y,y,y]

de/.f[x,y]->1/.Derivative[a__][f][x,y]:>(Times@@({Dx,Dy}^{a}))

Visualization

ListPlot[IntegerExponent[Table[Binomial[200,k],{k,0,200}],2]]

ListPlot[IntegerExponent[Table[Binomial[200,k],{k,0,200}],2],Joined->True]

Plot[Table[BesselJ[n,x],{n,0,5}],{x,-10,10}]

Manipulate[ContourPlot[(x^2+y^2)^2==x^2+a*y^2,{x,-1,1},{y,-1,1}],{a,-1,1}]

Plot3D[x^2/y^2,{x,-1,1},{y,-1,1}]

Graphics[Table[Circle[{x,0},x^2],{x,-2,2,.1}]]

Functional Programming

f=Function[x,x^2]

f'[3]

Clear[f]

D[f[x]*g[x],x]

Solve[f[x]==y,x]

FullForm[%]

f[InverseFunction[f,1,1][x]]

FixedPoint[Sin[#]+Cos[#]&,0.1]

Nest[f,x,5]

MapIndexed[{#1,#2-1}&,CoefficientList[x^3+y^2+2*x*y,{x,y}],{2}]

DeleteCases[Flatten[%,1],{0,_}]

Some Exercises

Generate a list of all positive rationals with numerator and denominator not greater than 10!

Union[Flatten[Table[n/d,{n,0,10},{d,10}]]]

All cubes of the smallest totally symmetric plane partition generated by some points:

p={{1,1,3},{2,2,2}}

Union[Flatten[Table[{a,b,c},{a,#[[1]]},{b,#[[2]]},{c,#[[3]]}]&/@Flatten[Permutations/@p,1],3]]

Union[Flatten[Table@@@(Prepend[Transpose[{{a,b,c},#}],{a,b,c}]&/@Flatten[Permutations/@p,1]),3]]

Select[Flatten[With[{m=Max[Flatten[p]]},Table[{a,b,c},{a,m},{b,m},{c,m}]],2],Function[point,Or@@((And@@Thread[point≤#])&/@Flatten[Permutations/@p,1])]]