Quiet@Remove["Global`*"];
$HistoryLength=2;
SetDirectory[NotebookDirectory[]];

ClearAll[testPsi];
testPsi[x_]:=Tanh[(0.123+x)];

(*puleni intervalu*)
ClearAll[f];
f[psi_,pocint:{a_,b_},Δ_]:=Module[{test,newInterval},

newInterval[{a1_,b1_}]:=Module[{fa1,fb1,pul,fpul},
fa1=psi[a1];
fb1=psi[b1];
pul=0.5*(a1+b1);
fpul=psi[pul];
Which[fa1*fpul<0,{a1,pul},fb1*fpul<0,{pul,b1}]
];

test[{a1_,b1_}]:=Abs[b1-a1]>Δ;
NestWhileList[newInterval,pocint,test][[-1]]
];
f[testPsi,{-1,1},0.01]
Abs[{1,-1}.%]

(*Newton*)
ClearAll[f2];
f2[psi_,a_,Δ_]:=Module[{test,derivace,newX},
test[x_]:=Abs[psi[x]]>Δ;
derivace=psi';
newX[oldX_]:=oldX-((psi[oldX])/(derivace[oldX]));
NestWhileList[newX,a,test]
];
f2[testPsi,-0.5,0.01]

ClearAll[f2];
f2[psi_,a_,Δ_]:=Module[{derivace},
derivace=psi';
NestWhileList[#-((psi[#])/(derivace[#]))&,a,Abs[psi[#]]>Δ&]
];
f2[testPsi,-0.5,0.01]

(*prosta iterace*)
ClearAll[f3];
f3[psi_,a_,Δ_]:=Module[{test,newX},
test[x_]:=Abs[psi[x]]>Δ;
newX[oldX_]:=psi[oldX];
NestWhileList[newX,a,test]
];
f3[testPsi,-0.5,0.015]

test[x_]:=x>0;
NestWhileList[Log,100,test]
%//N

h[{a_,b_}]:=Which[a>b,{a,b},a<b,{b,a}]
h[{1,2}]

g[x_]:=Module[{pom1,pom2},
pom1=x+1.;
pom2=Log[2pom1];
pom1+pom2
]
g[6]