/*
* bisection. Returns false if bad params.
* Returns [x,y] of solution otherwise.
*/
bisect(bisect_func_name,lo,hi):=
block([res,hix:hi,hiy:bisect_func_name(hi),
lox:lo,loy:bisect_func_name(lo),midx,midy],
num_bisect_func_evals:2,
/* print("hix=",hix," hiy=",hiy,
"lox=",lox," loy=",loy), */
if sign(loy) = sign(hiy) then return(false),
return (do (
midx:(hix+lox)/2,
midy:bisect_func_name(midx),
num_bisect_func_evals:num_bisect_func_evals + 1,
/* print("hix=",hix," hiy=",hiy,'
"lox=",lox," loy=",loy,
"midx=",midx," midy=",midy), */
if (midy=0) then return([midx,midy]),
if sign(midy)=sign(hiy) then (
hiy:midy,hix:midx,
0) else (
lox:midx,loy:midy,
0),
if abs(midy) < bisection_dep_toler then (
return([midx,midy]),
0),
if abs(hix-lox) < bisection_indep_toler then (
return([midx,midy]),
0),
0)),
0)$
if not member('bisection_dep_toler,values) then bisection_dep_toler:0$
if not member('bisection_indep_toler,values) then bisection_indep_toler:0$