f[x_/;0≤x≤2Pi]:=Sin[x]

f[x_/;2Pi≤x]:=(x-2Pi)

f[x_/;x≤0]:=x

Plot[f[x],{x,-Pi,3 Pi}]

Clear[g]

g[x_,y_]/;Sqrt[x^2+y^2]≤ 2 Pi:=Sin[Sqrt[x^2  + y^2]]

g[x_,y_]/;Sqrt[x^2+y^2]>2 Pi:=Sqrt[x^2  + y^2]-2 Pi

Plot3D[g[x,y],{x,-3Pi,3Pi},{y,-3Pi,3Pi}]

Clear[plusH]

plusH[a_,b_]:=HoldForm[a+b]
plusH[a_,b_,c__]:=plusH[plusH[a,b],c]
plusH[a_,0]:=a
plusH[0,b_]:=b

plusH[a___,0,b___]:=plusH[a,b]
plusH[a_,b_]:=HoldForm[a+b]
plusH[a_,b_,c__]:=plusH[plusH[a,b],c]

plusH[4]
plusH[1,3]
plusH[0,0,0]
plusH[4,3,0,1]
plusH[4,5,5,5]

Clear[plusH]

plusH[a_]:=a

plusH[a_,b_,c___]:=plusH[HoldForm[a+b],c]
plusH[a_,0,c___]:=plusH[a,c]
plusH[0,b_,c___]:=plusH[b,c]

plusH[4]
plusH[1,3]
plusH[4,3,0,1]
plusH[4,5,5,5]

Clear[times]

times[a_]:=a
times[c__/;MemberQ[{c},0]]:=0
times[a_,b_,c___]:=times[HoldForm[a b],c]
times[a_,1,c___]:=times[a ,c]
times[1,b_,c___]:=times[b,c]

Clear[times]

times[a_]:=a
times[a___,0,b___]:=0
times[a___,1,b___]:=times[a,b]
times[a_,b_,c___]:=times[HoldForm[a b],c]

times[4]
times[3,4]
times[3,4,1,2]
times[3,4,0,1]
times[0,3,4]
times[1,3,4,1,2,1,1,1,1]

Clear[times]

times[a_]:=a
times[c__/;MemberQ[{c},0]]:=0
times[a___,1,b___]:=times[a,b]
times[a_,b_,c___]:=times[HoldForm[a b],c]

times[a__,plusH[b_,c__]]:=
plus[times[a,b],times[a,c]]

times[x,y,plusH[a,b,c]]

times[1,1,1,1]

?times

exp=plusH[a,b,times[c,a],a]

FullForm[exp]

TreeForm[exp]

c[a]:=0;
c[x_]:=1;
c[plusH[a_,b_]]:=10+c[a]+c[b]
c[times[a_,b_]]:=100+c[a]+c[b]

exp
c[exp]

Clear[fun]

fun[a___,r_,b___,l_,c___]/;r>l:=fun[a,l,b,r,c]

fun[1,5,3,4,1]

f[a___,r_,b___,l_,c___]/;l<r:=(Print["r:",r," l:",l];f[a,l,b,r,c])

f[a___]:={a}

f[1,3,5,9,7,4,2]

f[{a___,r_,b___,l_,c___}]/;l<r:=f[{a,l,b,r,c}]
f[a_]:=a

(tab=Table[{{1,2},{3,RandomInteger[10],5}},{10}])//TreeForm

sortTab[{a___,{{1,2},{3,r_,5}},b___,{{1,2},{3,l_,5}},c___}]/;
l<r:=sortTab[{a,{{1,2},{3,l,5}},b,{{1,2},{3,r,5}},c}]
sortTab[a_]:=a

sortTab[tab]//ColumnForm

Clear[sortTabs]

sortTabs2[
{a___,
p1:{{_,_},{_,l_,_}},
b___,
p2:{{_,_},{_,r_,_}},
c___}
]/;l>r:=sortTabs2[{a,p2,b,p1,c}]
sortTabs2[l_]:=l

sortTabs[tab]//TableForm

Clear[plus]

plus[a___,"hold"]:=plusH[a]
plus[a___,"arith"]:=Plus[a]
plus[a___,"eps"]:=plusE[a]

Clear[plusE]

plusE[a_]:=a
plusE[a_,b_,c___]:=plusE[a+b,c](1+ϵ)
plusE[a_,0,c___]:=plusE[a,c]
plusE[0,b_,c___]:=plusE[b,c]

plus[a,b,a,a,"eps"]

plusE[a,b,a,a]//Trace