Clear[a,b,c,d,e,f]

f[x_]:=x^2

?f

f        function name
x_     argument  (pattern)
:=     delayed assignment
x^2  definition

f[3]

f[a]

f[{1,2,3}]

??Power

f[{3,b}]

f[3,b]

?f

Syntax

fun[argument]
fun@argument
argument//fun

fun[arg1,arg2]
arg1~fun~arg2 
Apply[fun,{arg1,arg2}]
fun@@{arg1,arg2}

sol=Integrate[Sin[2 x] Cos[x/2], {x, 0, 1}]

N[sol]
sol//N
N@sol

Table[Sin[(i+j)^-1],{i,4},{j,3}]//MatrixForm

(Sqrt[Table[Sin[(i+j)^-1],{i,4},{j,3}][[2]]]//N)[[3]]

How to define a function for different datatypes?

g on real numbers :  identity function 
g on integers : factorial
g on lists : Length

?Switch

Head[{3,4,5}]

FullForm[{3,4,5}]

Head[Pi]

Clear[g]

g[x_]:=
Switch[ Head[x],
Integer, x!,
Real, x,
List, Length[x],
_, Print["something else"]; (* Abort[] ?  Hold[g[x]] *)
]

g[3.1415]

g[Pi]

g[5]

g[{1,2,{3,4},{}}]

g["s"]

?x

g[x]

Patterns with data type

Clear[g]

g[x_Real]:=x

g[x_Integer]:= x!

g[x_List]:= Length[x]

g[x]

g[Pi]

g[N[Pi]]

?g

Types: Integer, Real, Complex, Symbol, List

Clear[f]

f[x_]:=Sin[x]/x

Plot[f[x],{x,-5,5}]

f[0]

?f

f[0]:=1;

Limit[Sin[x]/x,x->0]

->

?Limit

Clear[f]

f[0]:=Limit[Sin[x]/x,x->0]

f[0]

?f

f[2]

f[x_]:=Sin[x]/x

f[2]

?f

f[0]

Better idea?

:= vs =

f[0]=Limit[Sin[x]/x,x->0]

?f

More examples

Clear[h]

h[x_,y_]:=x+y

{h[1,2],
h[2,2],
h[2,{2}],
h[Pi,{1,2}],
h[{Pi},{1,2}],
h[{1,2},{1,2}],
h[Pi,E,1,2]
}//ColumnForm

h[x_,x_]:=x

?h

{h[1,2],
h[2,2],
h[2,{2}],
h[Pi,{1,2}],
h[{Pi},{1,2}],
h[{1,2},{1,2}],
h[Pi,E,1,2]
}//ColumnForm

l={101,202,303,404}

l[[4]]

l[[-1]]

l//FullForm

l[[0]]

Head[l]

l[[5]]

?Random

?h

h[x,{1,2}]

h[x_,{1,2}]:=  {1,2}[[Random[Integer]+1]]

?h

{h[1,2],
h[2,2],
h[2,{2}],
h[Pi,{1,2}],
h[{Pi},{1,2}],
h[{1,2},{1,2}],
h[Pi,E,1,2]
}//ColumnForm

h[{x,y},{1,2}]:=  {1,2}[[Random[Integer]+1]]

?h

Clear[g]

g[x_,{1,2}]:=  {1,2}[[Random[Integer]+1]]

g[x_,x_]:=x

?g

g[{1,2},{1,2}]

NOTE: The order and the generality of the definitions is crucial. The more specific a definition, the earlier is tested: a definition for x_Integer is tested before a definition for x_.

ff[x_]:=x^2

ff[x_Integer]:=x

?ff

ff[4.]

gg[x_Integer]:=x

gg[x_]:=x^2

gg[4]

?gg

gg[x_Paolo]:= Pi

?gg

gg[Paolo[5]]

For overlapping definitions with the same level of generality, the earlier the definition is evaluated the earlier it gets tested.

Clear[ff,gg]

ff[x_/;x<4]:=x

ff[x_/;x>2]:=x^2

Plot[ff[t],{t,0,6}]

ff[4]

gg[x_/;x>2]:=x^2

gg[x_/;x<4]:=x

Plot[{gg[t],ff[t]},{t,0,6}]

gg[2]

?ff

?gg

Clear[f]

f[x_,2 x_]:=x

{
f[Pi,2 Pi],
f[2,2 2],
f[x,2 x],
f[Sin[1], 2 Sin[1]]
}

FullForm[Pi]
FullForm[ 2Pi]
FullForm[2 2]

g[x_,y_]/; y==2x:=x

g[2,4]

FullForm[2 x_]