Finite difference calculus

Assumptions

$Assumptions= h>0;
x∈Reals;

fdSort[expr_]:=Assuming[{h>0,x>0},Sort[Level[expr,1],Level[#1,{Depth[#1]-1}]<Level[#2,{Depth[#2]-1}] &]]

Operator definitions

Δ[f_[x_]]:=f[x+h]-f[x]
V[f_[x_]]:=f[x]-f[x-h]
δ[f_[x_]]:=f[x+h/2]-f[x-h/2]
μ[f_[x_]]:=(1/2)(f[x+h/2]+f[x-h/2])

Operator properties

Δ[a_ f_[x_]]:=a Δ[f[x]]
Δ[a_+b_]:=Δ[a]+Δ[b]
Δ[a_ (b_+c_)]:=a Δ[b]+a Δ[c]
Δ[a_]:=0

Table[Expand[Nest[Δ,f[x],k]],{k,1,3}] // TableForm // TraditionalForm

Table[fdSort[Expand[Nest[Δ,f[x],k]]],{k,1,3}] // TableForm // TraditionalForm

δ[a_ f_[x_]]:=a δ[f[x]]
δ[a_+b_]:=δ[a]+δ[b]
δ[a_ (b_+c_)]:=a δ[b]+a δ[c]
δ[a_]:= 0

Table[Expand[Nest[δ,f[x],k]],{k,1,3}] // TableForm // TraditionalForm

Table[fdSort[Expand[Nest[δ,f[x],k]]],{k,1,3}] // TableForm // TraditionalForm

Finite difference approximation of differentiation

Forward finite differences

ΔD[f_[x_],k_]:=Together[Normal[(1/h)Series[Log[1+z],{z,0,k}]] /. Table[(z^j)->Nest[Δ,f[x],j],{j,1,k}]]

Table[ΔD[f[x],k],{k,1,4}] // TableForm // TraditionalForm

Table[FortranForm[ΔD[f[x],k]],{k,1,4}] // TableForm

Table[TeXForm[ΔD[f[x],k]],{k,1,4}] // TableForm

Table[Series[ΔD[f[x],k],{h,0,k}],{k,1,4}] // TableForm // TraditionalForm

F[x_]=Sin[x];

Table[Plot[Evaluate[Table[(ΔD[f[x],k]-D[F[x],x])/(h^k)/. f->F,{k,1,3}] /. h->(2^(-p))],{x,0,2π},PlotRange->All],{p,3,10}]

Centered finite differences

δD[f_[x_],k_]:=Together[Normal[(2/h)Series[ArcSinh[(z/2)],{z,0,2k-1}]] /. Table[(z^j)->Nest[δ,f[x],j],{j,1,2k-1}]]

Table[δD[f[x],k],{k,1,3}] // TableForm // TraditionalForm

Table[Series[δD[f[x],k],{h,0,2k-1}],{k,1,3}] // TableForm // TraditionalForm

F[x_]=Sin[x];

Table[Plot[Evaluate[Table[(δD[f[x],k]-D[F[x],x])/(h^(2k)) /. f->F
,{k,1,3}] /. h->(2^(-p))],{x,0,2π},PlotRange->All],{p,3,10}]