/*
* Compare brent() and bent() on a few simple functions. Comparison is based
* on CPU time and on number of function evaluations.
*/
batch("d:\\paul\\paper\\brent.mac");
batch("d:\\paul\\paper\\bent.mac");
eps:10^(1-bfprecision);
/*
* The first function is a "nasty" function with lots of zero-crossings.
*/
func1(x):=-cos(x)+1.b-2*x;
func1p(x):=(print(x),func1(x));
funclowlist[func1]:0.b0;
funchighlist[func1]:100.b0;
/*
* The second function is a "nice" smooth function, but rather expensive,
* at least when using bfloat in Macsyma.
*/
func2(x):=sin(x)-cos(x);
func2p(x):=(print(x),func2(x));
funclowlist[func2]:0.b0;
funchighlist[func2]:2.b0;
/*
* The third function is not only "nice", but also cheap to compute.
*/
func3(x):=x*x*x - 2.b0;
func3p(x):=(print(x),func3(x));
funclowlist[func3]:0.b0;
funchighlist[func3]:2.b0;
/*
* The fourth function has very large third derivatives.
*/
func4(x):=x*x*x*x*x*x - x - 1.b0;
func4p(x):=(print(x),func4(x));
funclowlist[func4]:0.b0;
funchighlist[func4]:2.b0;
/*
* The fifth function has very large third derivatives combined with
* a root of the fourth derivative.
*/
func5(x):=((x^2 / 120.b0) + 50.b0 * x /3.b0) * x^2;
func5p(x):=(print(x),func5(x));
funclowlist[func5]:-2.b-1;
funchighlist[func5]:5.b-1;
/*
* The following four functions are cases 1 through 4 from pp 77-78 of
* Atkinson's "An Introduction to Numerical Analysis", Wiley, 1978.
*/
case1(x):=(x-1.b0)*(1.b0+(x-1.b0)^2);
case1p(x):=(print(x),case1(x));
funclowlist[case1]:0.b0;
funchighlist[case1]:3.b0;
case2(x):=x^2-1.b0;
case2p(x):=(print(x),case2(x));
funclowlist[case2]:9.b-1;
funchighlist[case2]:2.b0;
case3(x):=-1.b0+x*(3.b0+x*(-3.b0+x));
case3p(x):=(print(x),case3(x));
funclowlist[case3]:3.b0;
funchighlist[case3]:0.b0;
case4(x):=if abs(x-1.b0) < 1.b-1 then 0.b0 else (x-1.b0)*%e^(-1.b0/(x-1.b0)^2);
case4p(x):=(print(x),case4(x));
funclowlist[case4]:0.b0;
funchighlist[case4]:3.b0;