VandenBroeck and Keller, Equation (6)

Percentage Accurate: 76.7% → 99.1%
Time: 18.2s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \end{array} \]
(FPCore (F l)
 :precision binary64
 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
double code(double F, double l) {
	return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
public static double code(double F, double l) {
	return (Math.PI * l) - ((1.0 / (F * F)) * Math.tan((Math.PI * l)));
}
def code(F, l):
	return (math.pi * l) - ((1.0 / (F * F)) * math.tan((math.pi * l)))
function code(F, l)
	return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l))))
end
function tmp = code(F, l)
	tmp = (pi * l) - ((1.0 / (F * F)) * tan((pi * l)));
end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 76.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right) \end{array} \]
(FPCore (F l)
 :precision binary64
 (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))
double code(double F, double l) {
	return (((double) M_PI) * l) - ((1.0 / (F * F)) * tan((((double) M_PI) * l)));
}
public static double code(double F, double l) {
	return (Math.PI * l) - ((1.0 / (F * F)) * Math.tan((Math.PI * l)));
}
def code(F, l):
	return (math.pi * l) - ((1.0 / (F * F)) * math.tan((math.pi * l)))
function code(F, l)
	return Float64(Float64(pi * l) - Float64(Float64(1.0 / Float64(F * F)) * tan(Float64(pi * l))))
end
function tmp = code(F, l)
	tmp = (pi * l) - ((1.0 / (F * F)) * tan((pi * l)));
end
code[F_, l_] := N[(N[(Pi * l), $MachinePrecision] - N[(N[(1.0 / N[(F * F), $MachinePrecision]), $MachinePrecision] * N[Tan[N[(Pi * l), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\pi \cdot \ell - \frac{1}{F \cdot F} \cdot \tan \left(\pi \cdot \ell\right)
\end{array}

Alternative 1: 99.1% accurate, 0.8× speedup?

\[\begin{array}{l} l_m = \left|\ell\right| \\ l_s = \mathsf{copysign}\left(1, \ell\right) \\ l_s \cdot \begin{array}{l} \mathbf{if}\;\pi \cdot l_m \leq 50000000000:\\ \;\;\;\;\pi \cdot l_m - \frac{\frac{\tan \left(\pi \cdot l_m\right)}{F}}{F}\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot l_m\\ \end{array} \end{array} \]
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= (* PI l_m) 50000000000.0)
    (- (* PI l_m) (/ (/ (tan (* PI l_m)) F) F))
    (* PI l_m))))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if ((((double) M_PI) * l_m) <= 50000000000.0) {
		tmp = (((double) M_PI) * l_m) - ((tan((((double) M_PI) * l_m)) / F) / F);
	} else {
		tmp = ((double) M_PI) * l_m;
	}
	return l_s * tmp;
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	double tmp;
	if ((Math.PI * l_m) <= 50000000000.0) {
		tmp = (Math.PI * l_m) - ((Math.tan((Math.PI * l_m)) / F) / F);
	} else {
		tmp = Math.PI * l_m;
	}
	return l_s * tmp;
}
l_m = math.fabs(l)
l_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	tmp = 0
	if (math.pi * l_m) <= 50000000000.0:
		tmp = (math.pi * l_m) - ((math.tan((math.pi * l_m)) / F) / F)
	else:
		tmp = math.pi * l_m
	return l_s * tmp
l_m = abs(l)
l_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (Float64(pi * l_m) <= 50000000000.0)
		tmp = Float64(Float64(pi * l_m) - Float64(Float64(tan(Float64(pi * l_m)) / F) / F));
	else
		tmp = Float64(pi * l_m);
	end
	return Float64(l_s * tmp)
end
l_m = abs(l);
l_s = sign(l) * abs(1.0);
function tmp_2 = code(l_s, F, l_m)
	tmp = 0.0;
	if ((pi * l_m) <= 50000000000.0)
		tmp = (pi * l_m) - ((tan((pi * l_m)) / F) / F);
	else
		tmp = pi * l_m;
	end
	tmp_2 = l_s * tmp;
end
l_m = N[Abs[l], $MachinePrecision]
l_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[N[(Pi * l$95$m), $MachinePrecision], 50000000000.0], N[(N[(Pi * l$95$m), $MachinePrecision] - N[(N[(N[Tan[N[(Pi * l$95$m), $MachinePrecision]], $MachinePrecision] / F), $MachinePrecision] / F), $MachinePrecision]), $MachinePrecision], N[(Pi * l$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)

\\
l_s \cdot \begin{array}{l}
\mathbf{if}\;\pi \cdot l_m \leq 50000000000:\\
\;\;\;\;\pi \cdot l_m - \frac{\frac{\tan \left(\pi \cdot l_m\right)}{F}}{F}\\

\mathbf{else}:\\
\;\;\;\;\pi \cdot l_m\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 98.1% accurate, 1.0× speedup?

\[\begin{array}{l} l_m = \left|\ell\right| \\ l_s = \mathsf{copysign}\left(1, \ell\right) \\ l_s \cdot \begin{array}{l} \mathbf{if}\;\pi \cdot l_m \leq 0.005:\\ \;\;\;\;\pi \cdot l_m - \frac{\pi}{F} \cdot \frac{l_m}{F}\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot l_m\\ \end{array} \end{array} \]
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= (* PI l_m) 0.005) (- (* PI l_m) (* (/ PI F) (/ l_m F))) (* PI l_m))))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if ((((double) M_PI) * l_m) <= 0.005) {
		tmp = (((double) M_PI) * l_m) - ((((double) M_PI) / F) * (l_m / F));
	} else {
		tmp = ((double) M_PI) * l_m;
	}
	return l_s * tmp;
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	double tmp;
	if ((Math.PI * l_m) <= 0.005) {
		tmp = (Math.PI * l_m) - ((Math.PI / F) * (l_m / F));
	} else {
		tmp = Math.PI * l_m;
	}
	return l_s * tmp;
}
l_m = math.fabs(l)
l_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	tmp = 0
	if (math.pi * l_m) <= 0.005:
		tmp = (math.pi * l_m) - ((math.pi / F) * (l_m / F))
	else:
		tmp = math.pi * l_m
	return l_s * tmp
l_m = abs(l)
l_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (Float64(pi * l_m) <= 0.005)
		tmp = Float64(Float64(pi * l_m) - Float64(Float64(pi / F) * Float64(l_m / F)));
	else
		tmp = Float64(pi * l_m);
	end
	return Float64(l_s * tmp)
end
l_m = abs(l);
l_s = sign(l) * abs(1.0);
function tmp_2 = code(l_s, F, l_m)
	tmp = 0.0;
	if ((pi * l_m) <= 0.005)
		tmp = (pi * l_m) - ((pi / F) * (l_m / F));
	else
		tmp = pi * l_m;
	end
	tmp_2 = l_s * tmp;
end
l_m = N[Abs[l], $MachinePrecision]
l_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[N[(Pi * l$95$m), $MachinePrecision], 0.005], N[(N[(Pi * l$95$m), $MachinePrecision] - N[(N[(Pi / F), $MachinePrecision] * N[(l$95$m / F), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Pi * l$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)

\\
l_s \cdot \begin{array}{l}
\mathbf{if}\;\pi \cdot l_m \leq 0.005:\\
\;\;\;\;\pi \cdot l_m - \frac{\pi}{F} \cdot \frac{l_m}{F}\\

\mathbf{else}:\\
\;\;\;\;\pi \cdot l_m\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 92.3% accurate, 1.0× speedup?

\[\begin{array}{l} l_m = \left|\ell\right| \\ l_s = \mathsf{copysign}\left(1, \ell\right) \\ l_s \cdot \begin{array}{l} \mathbf{if}\;\pi \cdot l_m \leq 0.005:\\ \;\;\;\;\left(\pi \cdot l_m\right) \cdot \left(1 - {F}^{-2}\right)\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot l_m\\ \end{array} \end{array} \]
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= (* PI l_m) 0.005) (* (* PI l_m) (- 1.0 (pow F -2.0))) (* PI l_m))))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if ((((double) M_PI) * l_m) <= 0.005) {
		tmp = (((double) M_PI) * l_m) * (1.0 - pow(F, -2.0));
	} else {
		tmp = ((double) M_PI) * l_m;
	}
	return l_s * tmp;
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	double tmp;
	if ((Math.PI * l_m) <= 0.005) {
		tmp = (Math.PI * l_m) * (1.0 - Math.pow(F, -2.0));
	} else {
		tmp = Math.PI * l_m;
	}
	return l_s * tmp;
}
l_m = math.fabs(l)
l_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	tmp = 0
	if (math.pi * l_m) <= 0.005:
		tmp = (math.pi * l_m) * (1.0 - math.pow(F, -2.0))
	else:
		tmp = math.pi * l_m
	return l_s * tmp
l_m = abs(l)
l_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (Float64(pi * l_m) <= 0.005)
		tmp = Float64(Float64(pi * l_m) * Float64(1.0 - (F ^ -2.0)));
	else
		tmp = Float64(pi * l_m);
	end
	return Float64(l_s * tmp)
end
l_m = abs(l);
l_s = sign(l) * abs(1.0);
function tmp_2 = code(l_s, F, l_m)
	tmp = 0.0;
	if ((pi * l_m) <= 0.005)
		tmp = (pi * l_m) * (1.0 - (F ^ -2.0));
	else
		tmp = pi * l_m;
	end
	tmp_2 = l_s * tmp;
end
l_m = N[Abs[l], $MachinePrecision]
l_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[N[(Pi * l$95$m), $MachinePrecision], 0.005], N[(N[(Pi * l$95$m), $MachinePrecision] * N[(1.0 - N[Power[F, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Pi * l$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)

\\
l_s \cdot \begin{array}{l}
\mathbf{if}\;\pi \cdot l_m \leq 0.005:\\
\;\;\;\;\left(\pi \cdot l_m\right) \cdot \left(1 - {F}^{-2}\right)\\

\mathbf{else}:\\
\;\;\;\;\pi \cdot l_m\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 49.7% accurate, 1.4× speedup?

\[\begin{array}{l} l_m = \left|\ell\right| \\ l_s = \mathsf{copysign}\left(1, \ell\right) \\ l_s \cdot \begin{array}{l} \mathbf{if}\;F \leq 1.95 \cdot 10^{-259}:\\ \;\;\;\;\frac{-1}{F \cdot \frac{F}{\pi \cdot l_m}}\\ \mathbf{elif}\;F \leq 1.3 \cdot 10^{-208}:\\ \;\;\;\;\pi \cdot l_m\\ \mathbf{elif}\;F \leq 1.2 \cdot 10^{-186}:\\ \;\;\;\;\frac{\frac{-l_m}{\frac{F}{\pi}}}{F}\\ \mathbf{elif}\;F \leq 5.5 \cdot 10^{-153} \lor \neg \left(F \leq 4.2 \cdot 10^{-133}\right):\\ \;\;\;\;\pi \cdot l_m\\ \mathbf{else}:\\ \;\;\;\;\frac{-l_m}{\frac{{F}^{2}}{\pi}}\\ \end{array} \end{array} \]
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= F 1.95e-259)
    (/ -1.0 (* F (/ F (* PI l_m))))
    (if (<= F 1.3e-208)
      (* PI l_m)
      (if (<= F 1.2e-186)
        (/ (/ (- l_m) (/ F PI)) F)
        (if (or (<= F 5.5e-153) (not (<= F 4.2e-133)))
          (* PI l_m)
          (/ (- l_m) (/ (pow F 2.0) PI))))))))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if (F <= 1.95e-259) {
		tmp = -1.0 / (F * (F / (((double) M_PI) * l_m)));
	} else if (F <= 1.3e-208) {
		tmp = ((double) M_PI) * l_m;
	} else if (F <= 1.2e-186) {
		tmp = (-l_m / (F / ((double) M_PI))) / F;
	} else if ((F <= 5.5e-153) || !(F <= 4.2e-133)) {
		tmp = ((double) M_PI) * l_m;
	} else {
		tmp = -l_m / (pow(F, 2.0) / ((double) M_PI));
	}
	return l_s * tmp;
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	double tmp;
	if (F <= 1.95e-259) {
		tmp = -1.0 / (F * (F / (Math.PI * l_m)));
	} else if (F <= 1.3e-208) {
		tmp = Math.PI * l_m;
	} else if (F <= 1.2e-186) {
		tmp = (-l_m / (F / Math.PI)) / F;
	} else if ((F <= 5.5e-153) || !(F <= 4.2e-133)) {
		tmp = Math.PI * l_m;
	} else {
		tmp = -l_m / (Math.pow(F, 2.0) / Math.PI);
	}
	return l_s * tmp;
}
l_m = math.fabs(l)
l_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	tmp = 0
	if F <= 1.95e-259:
		tmp = -1.0 / (F * (F / (math.pi * l_m)))
	elif F <= 1.3e-208:
		tmp = math.pi * l_m
	elif F <= 1.2e-186:
		tmp = (-l_m / (F / math.pi)) / F
	elif (F <= 5.5e-153) or not (F <= 4.2e-133):
		tmp = math.pi * l_m
	else:
		tmp = -l_m / (math.pow(F, 2.0) / math.pi)
	return l_s * tmp
l_m = abs(l)
l_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (F <= 1.95e-259)
		tmp = Float64(-1.0 / Float64(F * Float64(F / Float64(pi * l_m))));
	elseif (F <= 1.3e-208)
		tmp = Float64(pi * l_m);
	elseif (F <= 1.2e-186)
		tmp = Float64(Float64(Float64(-l_m) / Float64(F / pi)) / F);
	elseif ((F <= 5.5e-153) || !(F <= 4.2e-133))
		tmp = Float64(pi * l_m);
	else
		tmp = Float64(Float64(-l_m) / Float64((F ^ 2.0) / pi));
	end
	return Float64(l_s * tmp)
end
l_m = abs(l);
l_s = sign(l) * abs(1.0);
function tmp_2 = code(l_s, F, l_m)
	tmp = 0.0;
	if (F <= 1.95e-259)
		tmp = -1.0 / (F * (F / (pi * l_m)));
	elseif (F <= 1.3e-208)
		tmp = pi * l_m;
	elseif (F <= 1.2e-186)
		tmp = (-l_m / (F / pi)) / F;
	elseif ((F <= 5.5e-153) || ~((F <= 4.2e-133)))
		tmp = pi * l_m;
	else
		tmp = -l_m / ((F ^ 2.0) / pi);
	end
	tmp_2 = l_s * tmp;
end
l_m = N[Abs[l], $MachinePrecision]
l_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[F, 1.95e-259], N[(-1.0 / N[(F * N[(F / N[(Pi * l$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 1.3e-208], N[(Pi * l$95$m), $MachinePrecision], If[LessEqual[F, 1.2e-186], N[(N[((-l$95$m) / N[(F / Pi), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision], If[Or[LessEqual[F, 5.5e-153], N[Not[LessEqual[F, 4.2e-133]], $MachinePrecision]], N[(Pi * l$95$m), $MachinePrecision], N[((-l$95$m) / N[(N[Power[F, 2.0], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]]]), $MachinePrecision]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)

\\
l_s \cdot \begin{array}{l}
\mathbf{if}\;F \leq 1.95 \cdot 10^{-259}:\\
\;\;\;\;\frac{-1}{F \cdot \frac{F}{\pi \cdot l_m}}\\

\mathbf{elif}\;F \leq 1.3 \cdot 10^{-208}:\\
\;\;\;\;\pi \cdot l_m\\

\mathbf{elif}\;F \leq 1.2 \cdot 10^{-186}:\\
\;\;\;\;\frac{\frac{-l_m}{\frac{F}{\pi}}}{F}\\

\mathbf{elif}\;F \leq 5.5 \cdot 10^{-153} \lor \neg \left(F \leq 4.2 \cdot 10^{-133}\right):\\
\;\;\;\;\pi \cdot l_m\\

\mathbf{else}:\\
\;\;\;\;\frac{-l_m}{\frac{{F}^{2}}{\pi}}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 49.7% accurate, 1.4× speedup?

\[\begin{array}{l} l_m = \left|\ell\right| \\ l_s = \mathsf{copysign}\left(1, \ell\right) \\ l_s \cdot \begin{array}{l} \mathbf{if}\;F \leq 4.5 \cdot 10^{-259}:\\ \;\;\;\;\frac{-1}{F \cdot \frac{F}{\pi \cdot l_m}}\\ \mathbf{elif}\;F \leq 1.35 \cdot 10^{-208}:\\ \;\;\;\;\pi \cdot l_m\\ \mathbf{elif}\;F \leq 1.7 \cdot 10^{-186}:\\ \;\;\;\;\frac{\frac{-l_m}{\frac{F}{\pi}}}{F}\\ \mathbf{elif}\;F \leq 3.3 \cdot 10^{-156} \lor \neg \left(F \leq 1.9 \cdot 10^{-133}\right):\\ \;\;\;\;\pi \cdot l_m\\ \mathbf{else}:\\ \;\;\;\;\frac{l_m \cdot \left(-\pi\right)}{{F}^{2}}\\ \end{array} \end{array} \]
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (<= F 4.5e-259)
    (/ -1.0 (* F (/ F (* PI l_m))))
    (if (<= F 1.35e-208)
      (* PI l_m)
      (if (<= F 1.7e-186)
        (/ (/ (- l_m) (/ F PI)) F)
        (if (or (<= F 3.3e-156) (not (<= F 1.9e-133)))
          (* PI l_m)
          (/ (* l_m (- PI)) (pow F 2.0))))))))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if (F <= 4.5e-259) {
		tmp = -1.0 / (F * (F / (((double) M_PI) * l_m)));
	} else if (F <= 1.35e-208) {
		tmp = ((double) M_PI) * l_m;
	} else if (F <= 1.7e-186) {
		tmp = (-l_m / (F / ((double) M_PI))) / F;
	} else if ((F <= 3.3e-156) || !(F <= 1.9e-133)) {
		tmp = ((double) M_PI) * l_m;
	} else {
		tmp = (l_m * -((double) M_PI)) / pow(F, 2.0);
	}
	return l_s * tmp;
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	double tmp;
	if (F <= 4.5e-259) {
		tmp = -1.0 / (F * (F / (Math.PI * l_m)));
	} else if (F <= 1.35e-208) {
		tmp = Math.PI * l_m;
	} else if (F <= 1.7e-186) {
		tmp = (-l_m / (F / Math.PI)) / F;
	} else if ((F <= 3.3e-156) || !(F <= 1.9e-133)) {
		tmp = Math.PI * l_m;
	} else {
		tmp = (l_m * -Math.PI) / Math.pow(F, 2.0);
	}
	return l_s * tmp;
}
l_m = math.fabs(l)
l_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	tmp = 0
	if F <= 4.5e-259:
		tmp = -1.0 / (F * (F / (math.pi * l_m)))
	elif F <= 1.35e-208:
		tmp = math.pi * l_m
	elif F <= 1.7e-186:
		tmp = (-l_m / (F / math.pi)) / F
	elif (F <= 3.3e-156) or not (F <= 1.9e-133):
		tmp = math.pi * l_m
	else:
		tmp = (l_m * -math.pi) / math.pow(F, 2.0)
	return l_s * tmp
l_m = abs(l)
l_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if (F <= 4.5e-259)
		tmp = Float64(-1.0 / Float64(F * Float64(F / Float64(pi * l_m))));
	elseif (F <= 1.35e-208)
		tmp = Float64(pi * l_m);
	elseif (F <= 1.7e-186)
		tmp = Float64(Float64(Float64(-l_m) / Float64(F / pi)) / F);
	elseif ((F <= 3.3e-156) || !(F <= 1.9e-133))
		tmp = Float64(pi * l_m);
	else
		tmp = Float64(Float64(l_m * Float64(-pi)) / (F ^ 2.0));
	end
	return Float64(l_s * tmp)
end
l_m = abs(l);
l_s = sign(l) * abs(1.0);
function tmp_2 = code(l_s, F, l_m)
	tmp = 0.0;
	if (F <= 4.5e-259)
		tmp = -1.0 / (F * (F / (pi * l_m)));
	elseif (F <= 1.35e-208)
		tmp = pi * l_m;
	elseif (F <= 1.7e-186)
		tmp = (-l_m / (F / pi)) / F;
	elseif ((F <= 3.3e-156) || ~((F <= 1.9e-133)))
		tmp = pi * l_m;
	else
		tmp = (l_m * -pi) / (F ^ 2.0);
	end
	tmp_2 = l_s * tmp;
end
l_m = N[Abs[l], $MachinePrecision]
l_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[LessEqual[F, 4.5e-259], N[(-1.0 / N[(F * N[(F / N[(Pi * l$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[F, 1.35e-208], N[(Pi * l$95$m), $MachinePrecision], If[LessEqual[F, 1.7e-186], N[(N[((-l$95$m) / N[(F / Pi), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision], If[Or[LessEqual[F, 3.3e-156], N[Not[LessEqual[F, 1.9e-133]], $MachinePrecision]], N[(Pi * l$95$m), $MachinePrecision], N[(N[(l$95$m * (-Pi)), $MachinePrecision] / N[Power[F, 2.0], $MachinePrecision]), $MachinePrecision]]]]]), $MachinePrecision]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)

\\
l_s \cdot \begin{array}{l}
\mathbf{if}\;F \leq 4.5 \cdot 10^{-259}:\\
\;\;\;\;\frac{-1}{F \cdot \frac{F}{\pi \cdot l_m}}\\

\mathbf{elif}\;F \leq 1.35 \cdot 10^{-208}:\\
\;\;\;\;\pi \cdot l_m\\

\mathbf{elif}\;F \leq 1.7 \cdot 10^{-186}:\\
\;\;\;\;\frac{\frac{-l_m}{\frac{F}{\pi}}}{F}\\

\mathbf{elif}\;F \leq 3.3 \cdot 10^{-156} \lor \neg \left(F \leq 1.9 \cdot 10^{-133}\right):\\
\;\;\;\;\pi \cdot l_m\\

\mathbf{else}:\\
\;\;\;\;\frac{l_m \cdot \left(-\pi\right)}{{F}^{2}}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 49.7% accurate, 2.6× speedup?

\[\begin{array}{l} l_m = \left|\ell\right| \\ l_s = \mathsf{copysign}\left(1, \ell\right) \\ l_s \cdot \begin{array}{l} \mathbf{if}\;F \leq 4.6 \cdot 10^{-259} \lor \neg \left(F \leq 4.4 \cdot 10^{-209}\right) \land \left(F \leq 1.12 \cdot 10^{-185} \lor \neg \left(F \leq 3.1 \cdot 10^{-152}\right) \land F \leq 1.5 \cdot 10^{-133}\right):\\ \;\;\;\;\frac{-1}{F \cdot \frac{F}{\pi \cdot l_m}}\\ \mathbf{else}:\\ \;\;\;\;\pi \cdot l_m\\ \end{array} \end{array} \]
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
 :precision binary64
 (*
  l_s
  (if (or (<= F 4.6e-259)
          (and (not (<= F 4.4e-209))
               (or (<= F 1.12e-185)
                   (and (not (<= F 3.1e-152)) (<= F 1.5e-133)))))
    (/ -1.0 (* F (/ F (* PI l_m))))
    (* PI l_m))))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double tmp;
	if ((F <= 4.6e-259) || (!(F <= 4.4e-209) && ((F <= 1.12e-185) || (!(F <= 3.1e-152) && (F <= 1.5e-133))))) {
		tmp = -1.0 / (F * (F / (((double) M_PI) * l_m)));
	} else {
		tmp = ((double) M_PI) * l_m;
	}
	return l_s * tmp;
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	double tmp;
	if ((F <= 4.6e-259) || (!(F <= 4.4e-209) && ((F <= 1.12e-185) || (!(F <= 3.1e-152) && (F <= 1.5e-133))))) {
		tmp = -1.0 / (F * (F / (Math.PI * l_m)));
	} else {
		tmp = Math.PI * l_m;
	}
	return l_s * tmp;
}
l_m = math.fabs(l)
l_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	tmp = 0
	if (F <= 4.6e-259) or (not (F <= 4.4e-209) and ((F <= 1.12e-185) or (not (F <= 3.1e-152) and (F <= 1.5e-133)))):
		tmp = -1.0 / (F * (F / (math.pi * l_m)))
	else:
		tmp = math.pi * l_m
	return l_s * tmp
l_m = abs(l)
l_s = copysign(1.0, l)
function code(l_s, F, l_m)
	tmp = 0.0
	if ((F <= 4.6e-259) || (!(F <= 4.4e-209) && ((F <= 1.12e-185) || (!(F <= 3.1e-152) && (F <= 1.5e-133)))))
		tmp = Float64(-1.0 / Float64(F * Float64(F / Float64(pi * l_m))));
	else
		tmp = Float64(pi * l_m);
	end
	return Float64(l_s * tmp)
end
l_m = abs(l);
l_s = sign(l) * abs(1.0);
function tmp_2 = code(l_s, F, l_m)
	tmp = 0.0;
	if ((F <= 4.6e-259) || (~((F <= 4.4e-209)) && ((F <= 1.12e-185) || (~((F <= 3.1e-152)) && (F <= 1.5e-133)))))
		tmp = -1.0 / (F * (F / (pi * l_m)));
	else
		tmp = pi * l_m;
	end
	tmp_2 = l_s * tmp;
end
l_m = N[Abs[l], $MachinePrecision]
l_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * If[Or[LessEqual[F, 4.6e-259], And[N[Not[LessEqual[F, 4.4e-209]], $MachinePrecision], Or[LessEqual[F, 1.12e-185], And[N[Not[LessEqual[F, 3.1e-152]], $MachinePrecision], LessEqual[F, 1.5e-133]]]]], N[(-1.0 / N[(F * N[(F / N[(Pi * l$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(Pi * l$95$m), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)

\\
l_s \cdot \begin{array}{l}
\mathbf{if}\;F \leq 4.6 \cdot 10^{-259} \lor \neg \left(F \leq 4.4 \cdot 10^{-209}\right) \land \left(F \leq 1.12 \cdot 10^{-185} \lor \neg \left(F \leq 3.1 \cdot 10^{-152}\right) \land F \leq 1.5 \cdot 10^{-133}\right):\\
\;\;\;\;\frac{-1}{F \cdot \frac{F}{\pi \cdot l_m}}\\

\mathbf{else}:\\
\;\;\;\;\pi \cdot l_m\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 49.7% accurate, 2.6× speedup?

\[\begin{array}{l} l_m = \left|\ell\right| \\ l_s = \mathsf{copysign}\left(1, \ell\right) \\ \begin{array}{l} t_0 := \frac{-1}{F \cdot \frac{F}{\pi \cdot l_m}}\\ l_s \cdot \begin{array}{l} \mathbf{if}\;F \leq 2.9 \cdot 10^{-258}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;F \leq 1.3 \cdot 10^{-208}:\\ \;\;\;\;\pi \cdot l_m\\ \mathbf{elif}\;F \leq 3.7 \cdot 10^{-187}:\\ \;\;\;\;\frac{\frac{-l_m}{\frac{F}{\pi}}}{F}\\ \mathbf{elif}\;F \leq 8.5 \cdot 10^{-155} \lor \neg \left(F \leq 5.5 \cdot 10^{-132}\right):\\ \;\;\;\;\pi \cdot l_m\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \end{array} \end{array} \]
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m)
 :precision binary64
 (let* ((t_0 (/ -1.0 (* F (/ F (* PI l_m))))))
   (*
    l_s
    (if (<= F 2.9e-258)
      t_0
      (if (<= F 1.3e-208)
        (* PI l_m)
        (if (<= F 3.7e-187)
          (/ (/ (- l_m) (/ F PI)) F)
          (if (or (<= F 8.5e-155) (not (<= F 5.5e-132))) (* PI l_m) t_0)))))))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	double t_0 = -1.0 / (F * (F / (((double) M_PI) * l_m)));
	double tmp;
	if (F <= 2.9e-258) {
		tmp = t_0;
	} else if (F <= 1.3e-208) {
		tmp = ((double) M_PI) * l_m;
	} else if (F <= 3.7e-187) {
		tmp = (-l_m / (F / ((double) M_PI))) / F;
	} else if ((F <= 8.5e-155) || !(F <= 5.5e-132)) {
		tmp = ((double) M_PI) * l_m;
	} else {
		tmp = t_0;
	}
	return l_s * tmp;
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	double t_0 = -1.0 / (F * (F / (Math.PI * l_m)));
	double tmp;
	if (F <= 2.9e-258) {
		tmp = t_0;
	} else if (F <= 1.3e-208) {
		tmp = Math.PI * l_m;
	} else if (F <= 3.7e-187) {
		tmp = (-l_m / (F / Math.PI)) / F;
	} else if ((F <= 8.5e-155) || !(F <= 5.5e-132)) {
		tmp = Math.PI * l_m;
	} else {
		tmp = t_0;
	}
	return l_s * tmp;
}
l_m = math.fabs(l)
l_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	t_0 = -1.0 / (F * (F / (math.pi * l_m)))
	tmp = 0
	if F <= 2.9e-258:
		tmp = t_0
	elif F <= 1.3e-208:
		tmp = math.pi * l_m
	elif F <= 3.7e-187:
		tmp = (-l_m / (F / math.pi)) / F
	elif (F <= 8.5e-155) or not (F <= 5.5e-132):
		tmp = math.pi * l_m
	else:
		tmp = t_0
	return l_s * tmp
l_m = abs(l)
l_s = copysign(1.0, l)
function code(l_s, F, l_m)
	t_0 = Float64(-1.0 / Float64(F * Float64(F / Float64(pi * l_m))))
	tmp = 0.0
	if (F <= 2.9e-258)
		tmp = t_0;
	elseif (F <= 1.3e-208)
		tmp = Float64(pi * l_m);
	elseif (F <= 3.7e-187)
		tmp = Float64(Float64(Float64(-l_m) / Float64(F / pi)) / F);
	elseif ((F <= 8.5e-155) || !(F <= 5.5e-132))
		tmp = Float64(pi * l_m);
	else
		tmp = t_0;
	end
	return Float64(l_s * tmp)
end
l_m = abs(l);
l_s = sign(l) * abs(1.0);
function tmp_2 = code(l_s, F, l_m)
	t_0 = -1.0 / (F * (F / (pi * l_m)));
	tmp = 0.0;
	if (F <= 2.9e-258)
		tmp = t_0;
	elseif (F <= 1.3e-208)
		tmp = pi * l_m;
	elseif (F <= 3.7e-187)
		tmp = (-l_m / (F / pi)) / F;
	elseif ((F <= 8.5e-155) || ~((F <= 5.5e-132)))
		tmp = pi * l_m;
	else
		tmp = t_0;
	end
	tmp_2 = l_s * tmp;
end
l_m = N[Abs[l], $MachinePrecision]
l_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := Block[{t$95$0 = N[(-1.0 / N[(F * N[(F / N[(Pi * l$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(l$95$s * If[LessEqual[F, 2.9e-258], t$95$0, If[LessEqual[F, 1.3e-208], N[(Pi * l$95$m), $MachinePrecision], If[LessEqual[F, 3.7e-187], N[(N[((-l$95$m) / N[(F / Pi), $MachinePrecision]), $MachinePrecision] / F), $MachinePrecision], If[Or[LessEqual[F, 8.5e-155], N[Not[LessEqual[F, 5.5e-132]], $MachinePrecision]], N[(Pi * l$95$m), $MachinePrecision], t$95$0]]]]), $MachinePrecision]]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)

\\
\begin{array}{l}
t_0 := \frac{-1}{F \cdot \frac{F}{\pi \cdot l_m}}\\
l_s \cdot \begin{array}{l}
\mathbf{if}\;F \leq 2.9 \cdot 10^{-258}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;F \leq 1.3 \cdot 10^{-208}:\\
\;\;\;\;\pi \cdot l_m\\

\mathbf{elif}\;F \leq 3.7 \cdot 10^{-187}:\\
\;\;\;\;\frac{\frac{-l_m}{\frac{F}{\pi}}}{F}\\

\mathbf{elif}\;F \leq 8.5 \cdot 10^{-155} \lor \neg \left(F \leq 5.5 \cdot 10^{-132}\right):\\
\;\;\;\;\pi \cdot l_m\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 73.5% accurate, 3.0× speedup?

\[\begin{array}{l} l_m = \left|\ell\right| \\ l_s = \mathsf{copysign}\left(1, \ell\right) \\ l_s \cdot \left(\pi \cdot l_m\right) \end{array} \]
l_m = (fabs.f64 l)
l_s = (copysign.f64 1 l)
(FPCore (l_s F l_m) :precision binary64 (* l_s (* PI l_m)))
l_m = fabs(l);
l_s = copysign(1.0, l);
double code(double l_s, double F, double l_m) {
	return l_s * (((double) M_PI) * l_m);
}
l_m = Math.abs(l);
l_s = Math.copySign(1.0, l);
public static double code(double l_s, double F, double l_m) {
	return l_s * (Math.PI * l_m);
}
l_m = math.fabs(l)
l_s = math.copysign(1.0, l)
def code(l_s, F, l_m):
	return l_s * (math.pi * l_m)
l_m = abs(l)
l_s = copysign(1.0, l)
function code(l_s, F, l_m)
	return Float64(l_s * Float64(pi * l_m))
end
l_m = abs(l);
l_s = sign(l) * abs(1.0);
function tmp = code(l_s, F, l_m)
	tmp = l_s * (pi * l_m);
end
l_m = N[Abs[l], $MachinePrecision]
l_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[l]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[l$95$s_, F_, l$95$m_] := N[(l$95$s * N[(Pi * l$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
l_m = \left|\ell\right|
\\
l_s = \mathsf{copysign}\left(1, \ell\right)

\\
l_s \cdot \left(\pi \cdot l_m\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

?
herbie shell --seed 2023348 
(FPCore (F l)
  :name "VandenBroeck and Keller, Equation (6)"
  :precision binary64
  (- (* PI l) (* (/ 1.0 (* F F)) (tan (* PI l)))))