> tolerance := 0.01;
tolerance := .01
> WhatAmI := proc (f, x, y)
local x2, y2;
global tolerance;
x2 := evalf(x); y2 := evalf(y);
if abs (x2-y2) < tolerance and abs(f(x2)-f(y2)) < tolerance then
RETURN ((f(x2)+f(y2))*(y2-x2)/2);
else
RETURN (WhatAmI (f, x2, (x2+y2)/2) + WhatAmI(f, (x2+y2)/2, y2));
fi;
end:
> WhatAmI(cos, 0, 1);
.8414667052
>