public static function solve(callable $function, $a, $b, $tol)
{
// Validate input arguments
self::validate($function, $a, $b, $tol);
do {
$f⟮a⟯ = $function($a);
$p = ($a + $b) / 2;
// construct the midpoint
$f⟮p⟯ = $function($p);
$dif = abs($f⟮p⟯);
// the magnitude of our function at the midpoint
if (Special::sgn($f⟮p⟯) !== Special::sgn($f⟮a⟯)) {
$b = $p;
// the new endpoint is our original midpoint
} else {
$a = $p;
// the new startpoint is our original endpoint
}
} while ($dif > $tol);
return $p;
}