VandenBroeck and Keller, Equation (20)

Percentage Accurate: 6.9% → 96.8%
Time: 40.4s
Alternatives: 10
Speedup: 3.3×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\pi}{4} \cdot f\\ t_1 := e^{t_0}\\ t_2 := e^{-t_0}\\ -\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{t_1 + t_2}{t_1 - t_2}\right) \end{array} \end{array} \]
(FPCore (f)
 :precision binary64
 (let* ((t_0 (* (/ PI 4.0) f)) (t_1 (exp t_0)) (t_2 (exp (- t_0))))
   (- (* (/ 1.0 (/ PI 4.0)) (log (/ (+ t_1 t_2) (- t_1 t_2)))))))
double code(double f) {
	double t_0 = (((double) M_PI) / 4.0) * f;
	double t_1 = exp(t_0);
	double t_2 = exp(-t_0);
	return -((1.0 / (((double) M_PI) / 4.0)) * log(((t_1 + t_2) / (t_1 - t_2))));
}
public static double code(double f) {
	double t_0 = (Math.PI / 4.0) * f;
	double t_1 = Math.exp(t_0);
	double t_2 = Math.exp(-t_0);
	return -((1.0 / (Math.PI / 4.0)) * Math.log(((t_1 + t_2) / (t_1 - t_2))));
}
def code(f):
	t_0 = (math.pi / 4.0) * f
	t_1 = math.exp(t_0)
	t_2 = math.exp(-t_0)
	return -((1.0 / (math.pi / 4.0)) * math.log(((t_1 + t_2) / (t_1 - t_2))))
function code(f)
	t_0 = Float64(Float64(pi / 4.0) * f)
	t_1 = exp(t_0)
	t_2 = exp(Float64(-t_0))
	return Float64(-Float64(Float64(1.0 / Float64(pi / 4.0)) * log(Float64(Float64(t_1 + t_2) / Float64(t_1 - t_2)))))
end
function tmp = code(f)
	t_0 = (pi / 4.0) * f;
	t_1 = exp(t_0);
	t_2 = exp(-t_0);
	tmp = -((1.0 / (pi / 4.0)) * log(((t_1 + t_2) / (t_1 - t_2))));
end
code[f_] := Block[{t$95$0 = N[(N[(Pi / 4.0), $MachinePrecision] * f), $MachinePrecision]}, Block[{t$95$1 = N[Exp[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-t$95$0)], $MachinePrecision]}, (-N[(N[(1.0 / N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision] * N[Log[N[(N[(t$95$1 + t$95$2), $MachinePrecision] / N[(t$95$1 - t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision])]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\pi}{4} \cdot f\\
t_1 := e^{t_0}\\
t_2 := e^{-t_0}\\
-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{t_1 + t_2}{t_1 - t_2}\right)
\end{array}
\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 10 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: 6.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{\pi}{4} \cdot f\\ t_1 := e^{t_0}\\ t_2 := e^{-t_0}\\ -\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{t_1 + t_2}{t_1 - t_2}\right) \end{array} \end{array} \]
(FPCore (f)
 :precision binary64
 (let* ((t_0 (* (/ PI 4.0) f)) (t_1 (exp t_0)) (t_2 (exp (- t_0))))
   (- (* (/ 1.0 (/ PI 4.0)) (log (/ (+ t_1 t_2) (- t_1 t_2)))))))
double code(double f) {
	double t_0 = (((double) M_PI) / 4.0) * f;
	double t_1 = exp(t_0);
	double t_2 = exp(-t_0);
	return -((1.0 / (((double) M_PI) / 4.0)) * log(((t_1 + t_2) / (t_1 - t_2))));
}
public static double code(double f) {
	double t_0 = (Math.PI / 4.0) * f;
	double t_1 = Math.exp(t_0);
	double t_2 = Math.exp(-t_0);
	return -((1.0 / (Math.PI / 4.0)) * Math.log(((t_1 + t_2) / (t_1 - t_2))));
}
def code(f):
	t_0 = (math.pi / 4.0) * f
	t_1 = math.exp(t_0)
	t_2 = math.exp(-t_0)
	return -((1.0 / (math.pi / 4.0)) * math.log(((t_1 + t_2) / (t_1 - t_2))))
function code(f)
	t_0 = Float64(Float64(pi / 4.0) * f)
	t_1 = exp(t_0)
	t_2 = exp(Float64(-t_0))
	return Float64(-Float64(Float64(1.0 / Float64(pi / 4.0)) * log(Float64(Float64(t_1 + t_2) / Float64(t_1 - t_2)))))
end
function tmp = code(f)
	t_0 = (pi / 4.0) * f;
	t_1 = exp(t_0);
	t_2 = exp(-t_0);
	tmp = -((1.0 / (pi / 4.0)) * log(((t_1 + t_2) / (t_1 - t_2))));
end
code[f_] := Block[{t$95$0 = N[(N[(Pi / 4.0), $MachinePrecision] * f), $MachinePrecision]}, Block[{t$95$1 = N[Exp[t$95$0], $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-t$95$0)], $MachinePrecision]}, (-N[(N[(1.0 / N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision] * N[Log[N[(N[(t$95$1 + t$95$2), $MachinePrecision] / N[(t$95$1 - t$95$2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision])]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{\pi}{4} \cdot f\\
t_1 := e^{t_0}\\
t_2 := e^{-t_0}\\
-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{t_1 + t_2}{t_1 - t_2}\right)
\end{array}
\end{array}

Alternative 1: 96.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{f \cdot \frac{\pi}{4}}\\ t_1 := e^{f \cdot \frac{-\pi}{4}}\\ \mathbf{if}\;\frac{t_0 + t_1}{t_0 - t_1} \leq 200:\\ \;\;\;\;\frac{-4}{\pi} \cdot \log \left(\frac{e^{\frac{\pi}{\frac{-4}{f}}} + t_0}{t_0 - e^{{\left(\sqrt[3]{\pi \cdot \left(f \cdot -0.25\right)}\right)}^{3}}}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-4, \frac{\log \left(\frac{4}{\pi}\right) - \log f}{\pi}, \mathsf{fma}\left(-2, \frac{{f}^{2}}{\frac{\pi}{\mathsf{fma}\left(0.5, {\pi}^{2} \cdot 0.08333333333333333, 0\right)}}, \frac{f}{\frac{\pi}{0}}\right)\right)\\ \end{array} \end{array} \]
(FPCore (f)
 :precision binary64
 (let* ((t_0 (exp (* f (/ PI 4.0)))) (t_1 (exp (* f (/ (- PI) 4.0)))))
   (if (<= (/ (+ t_0 t_1) (- t_0 t_1)) 200.0)
     (*
      (/ -4.0 PI)
      (log
       (/
        (+ (exp (/ PI (/ -4.0 f))) t_0)
        (- t_0 (exp (pow (cbrt (* PI (* f -0.25))) 3.0))))))
     (fma
      -4.0
      (/ (- (log (/ 4.0 PI)) (log f)) PI)
      (fma
       -2.0
       (/
        (pow f 2.0)
        (/ PI (fma 0.5 (* (pow PI 2.0) 0.08333333333333333) 0.0)))
       (/ f (/ PI 0.0)))))))
double code(double f) {
	double t_0 = exp((f * (((double) M_PI) / 4.0)));
	double t_1 = exp((f * (-((double) M_PI) / 4.0)));
	double tmp;
	if (((t_0 + t_1) / (t_0 - t_1)) <= 200.0) {
		tmp = (-4.0 / ((double) M_PI)) * log(((exp((((double) M_PI) / (-4.0 / f))) + t_0) / (t_0 - exp(pow(cbrt((((double) M_PI) * (f * -0.25))), 3.0)))));
	} else {
		tmp = fma(-4.0, ((log((4.0 / ((double) M_PI))) - log(f)) / ((double) M_PI)), fma(-2.0, (pow(f, 2.0) / (((double) M_PI) / fma(0.5, (pow(((double) M_PI), 2.0) * 0.08333333333333333), 0.0))), (f / (((double) M_PI) / 0.0))));
	}
	return tmp;
}
function code(f)
	t_0 = exp(Float64(f * Float64(pi / 4.0)))
	t_1 = exp(Float64(f * Float64(Float64(-pi) / 4.0)))
	tmp = 0.0
	if (Float64(Float64(t_0 + t_1) / Float64(t_0 - t_1)) <= 200.0)
		tmp = Float64(Float64(-4.0 / pi) * log(Float64(Float64(exp(Float64(pi / Float64(-4.0 / f))) + t_0) / Float64(t_0 - exp((cbrt(Float64(pi * Float64(f * -0.25))) ^ 3.0))))));
	else
		tmp = fma(-4.0, Float64(Float64(log(Float64(4.0 / pi)) - log(f)) / pi), fma(-2.0, Float64((f ^ 2.0) / Float64(pi / fma(0.5, Float64((pi ^ 2.0) * 0.08333333333333333), 0.0))), Float64(f / Float64(pi / 0.0))));
	end
	return tmp
end
code[f_] := Block[{t$95$0 = N[Exp[N[(f * N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(f * N[((-Pi) / 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(t$95$0 + t$95$1), $MachinePrecision] / N[(t$95$0 - t$95$1), $MachinePrecision]), $MachinePrecision], 200.0], N[(N[(-4.0 / Pi), $MachinePrecision] * N[Log[N[(N[(N[Exp[N[(Pi / N[(-4.0 / f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + t$95$0), $MachinePrecision] / N[(t$95$0 - N[Exp[N[Power[N[Power[N[(Pi * N[(f * -0.25), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(N[(N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision] - N[Log[f], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision] + N[(-2.0 * N[(N[Power[f, 2.0], $MachinePrecision] / N[(Pi / N[(0.5 * N[(N[Power[Pi, 2.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision] + 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(f / N[(Pi / 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{f \cdot \frac{\pi}{4}}\\
t_1 := e^{f \cdot \frac{-\pi}{4}}\\
\mathbf{if}\;\frac{t_0 + t_1}{t_0 - t_1} \leq 200:\\
\;\;\;\;\frac{-4}{\pi} \cdot \log \left(\frac{e^{\frac{\pi}{\frac{-4}{f}}} + t_0}{t_0 - e^{{\left(\sqrt[3]{\pi \cdot \left(f \cdot -0.25\right)}\right)}^{3}}}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-4, \frac{\log \left(\frac{4}{\pi}\right) - \log f}{\pi}, \mathsf{fma}\left(-2, \frac{{f}^{2}}{\frac{\pi}{\mathsf{fma}\left(0.5, {\pi}^{2} \cdot 0.08333333333333333, 0\right)}}, \frac{f}{\frac{\pi}{0}}\right)\right)\\


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

Alternative 2: 96.8% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{f \cdot \frac{\pi}{4}}\\ t_1 := e^{\left(\pi \cdot f\right) \cdot -0.25}\\ t_2 := e^{f \cdot \frac{-\pi}{4}}\\ t_3 := e^{0.25 \cdot \left(\pi \cdot f\right)}\\ \mathbf{if}\;\frac{t_0 + t_2}{t_0 - t_2} \leq 200:\\ \;\;\;\;\frac{1}{-0.25 \cdot \frac{\pi}{\log \left(\frac{t_1 + t_3}{t_3 - t_1}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-4, \frac{\log \left(\frac{4}{\pi}\right) - \log f}{\pi}, \mathsf{fma}\left(-2, \frac{{f}^{2}}{\frac{\pi}{\mathsf{fma}\left(0.5, {\pi}^{2} \cdot 0.08333333333333333, 0\right)}}, \frac{f}{\frac{\pi}{0}}\right)\right)\\ \end{array} \end{array} \]
(FPCore (f)
 :precision binary64
 (let* ((t_0 (exp (* f (/ PI 4.0))))
        (t_1 (exp (* (* PI f) -0.25)))
        (t_2 (exp (* f (/ (- PI) 4.0))))
        (t_3 (exp (* 0.25 (* PI f)))))
   (if (<= (/ (+ t_0 t_2) (- t_0 t_2)) 200.0)
     (/ 1.0 (* -0.25 (/ PI (log (/ (+ t_1 t_3) (- t_3 t_1))))))
     (fma
      -4.0
      (/ (- (log (/ 4.0 PI)) (log f)) PI)
      (fma
       -2.0
       (/
        (pow f 2.0)
        (/ PI (fma 0.5 (* (pow PI 2.0) 0.08333333333333333) 0.0)))
       (/ f (/ PI 0.0)))))))
double code(double f) {
	double t_0 = exp((f * (((double) M_PI) / 4.0)));
	double t_1 = exp(((((double) M_PI) * f) * -0.25));
	double t_2 = exp((f * (-((double) M_PI) / 4.0)));
	double t_3 = exp((0.25 * (((double) M_PI) * f)));
	double tmp;
	if (((t_0 + t_2) / (t_0 - t_2)) <= 200.0) {
		tmp = 1.0 / (-0.25 * (((double) M_PI) / log(((t_1 + t_3) / (t_3 - t_1)))));
	} else {
		tmp = fma(-4.0, ((log((4.0 / ((double) M_PI))) - log(f)) / ((double) M_PI)), fma(-2.0, (pow(f, 2.0) / (((double) M_PI) / fma(0.5, (pow(((double) M_PI), 2.0) * 0.08333333333333333), 0.0))), (f / (((double) M_PI) / 0.0))));
	}
	return tmp;
}
function code(f)
	t_0 = exp(Float64(f * Float64(pi / 4.0)))
	t_1 = exp(Float64(Float64(pi * f) * -0.25))
	t_2 = exp(Float64(f * Float64(Float64(-pi) / 4.0)))
	t_3 = exp(Float64(0.25 * Float64(pi * f)))
	tmp = 0.0
	if (Float64(Float64(t_0 + t_2) / Float64(t_0 - t_2)) <= 200.0)
		tmp = Float64(1.0 / Float64(-0.25 * Float64(pi / log(Float64(Float64(t_1 + t_3) / Float64(t_3 - t_1))))));
	else
		tmp = fma(-4.0, Float64(Float64(log(Float64(4.0 / pi)) - log(f)) / pi), fma(-2.0, Float64((f ^ 2.0) / Float64(pi / fma(0.5, Float64((pi ^ 2.0) * 0.08333333333333333), 0.0))), Float64(f / Float64(pi / 0.0))));
	end
	return tmp
end
code[f_] := Block[{t$95$0 = N[Exp[N[(f * N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(N[(Pi * f), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Exp[N[(f * N[((-Pi) / 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Exp[N[(0.25 * N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(t$95$0 + t$95$2), $MachinePrecision] / N[(t$95$0 - t$95$2), $MachinePrecision]), $MachinePrecision], 200.0], N[(1.0 / N[(-0.25 * N[(Pi / N[Log[N[(N[(t$95$1 + t$95$3), $MachinePrecision] / N[(t$95$3 - t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(N[(N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision] - N[Log[f], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision] + N[(-2.0 * N[(N[Power[f, 2.0], $MachinePrecision] / N[(Pi / N[(0.5 * N[(N[Power[Pi, 2.0], $MachinePrecision] * 0.08333333333333333), $MachinePrecision] + 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(f / N[(Pi / 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{f \cdot \frac{\pi}{4}}\\
t_1 := e^{\left(\pi \cdot f\right) \cdot -0.25}\\
t_2 := e^{f \cdot \frac{-\pi}{4}}\\
t_3 := e^{0.25 \cdot \left(\pi \cdot f\right)}\\
\mathbf{if}\;\frac{t_0 + t_2}{t_0 - t_2} \leq 200:\\
\;\;\;\;\frac{1}{-0.25 \cdot \frac{\pi}{\log \left(\frac{t_1 + t_3}{t_3 - t_1}\right)}}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-4, \frac{\log \left(\frac{4}{\pi}\right) - \log f}{\pi}, \mathsf{fma}\left(-2, \frac{{f}^{2}}{\frac{\pi}{\mathsf{fma}\left(0.5, {\pi}^{2} \cdot 0.08333333333333333, 0\right)}}, \frac{f}{\frac{\pi}{0}}\right)\right)\\


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

Alternative 3: 96.8% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{f \cdot \frac{\pi}{4}}\\ t_1 := e^{\left(\pi \cdot f\right) \cdot -0.25}\\ t_2 := e^{f \cdot \frac{-\pi}{4}}\\ t_3 := e^{0.25 \cdot \left(\pi \cdot f\right)}\\ \mathbf{if}\;\frac{t_0 + t_2}{t_0 - t_2} \leq 200:\\ \;\;\;\;\frac{1}{-0.25 \cdot \frac{\pi}{\log \left(\frac{t_1 + t_3}{t_3 - t_1}\right)}}\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \frac{\log \left(\mathsf{fma}\left(f, \pi \cdot 0.08333333333333333, \frac{4}{\pi \cdot f}\right)\right)}{\pi}\\ \end{array} \end{array} \]
(FPCore (f)
 :precision binary64
 (let* ((t_0 (exp (* f (/ PI 4.0))))
        (t_1 (exp (* (* PI f) -0.25)))
        (t_2 (exp (* f (/ (- PI) 4.0))))
        (t_3 (exp (* 0.25 (* PI f)))))
   (if (<= (/ (+ t_0 t_2) (- t_0 t_2)) 200.0)
     (/ 1.0 (* -0.25 (/ PI (log (/ (+ t_1 t_3) (- t_3 t_1))))))
     (*
      -4.0
      (/ (log (fma f (* PI 0.08333333333333333) (/ 4.0 (* PI f)))) PI)))))
double code(double f) {
	double t_0 = exp((f * (((double) M_PI) / 4.0)));
	double t_1 = exp(((((double) M_PI) * f) * -0.25));
	double t_2 = exp((f * (-((double) M_PI) / 4.0)));
	double t_3 = exp((0.25 * (((double) M_PI) * f)));
	double tmp;
	if (((t_0 + t_2) / (t_0 - t_2)) <= 200.0) {
		tmp = 1.0 / (-0.25 * (((double) M_PI) / log(((t_1 + t_3) / (t_3 - t_1)))));
	} else {
		tmp = -4.0 * (log(fma(f, (((double) M_PI) * 0.08333333333333333), (4.0 / (((double) M_PI) * f)))) / ((double) M_PI));
	}
	return tmp;
}
function code(f)
	t_0 = exp(Float64(f * Float64(pi / 4.0)))
	t_1 = exp(Float64(Float64(pi * f) * -0.25))
	t_2 = exp(Float64(f * Float64(Float64(-pi) / 4.0)))
	t_3 = exp(Float64(0.25 * Float64(pi * f)))
	tmp = 0.0
	if (Float64(Float64(t_0 + t_2) / Float64(t_0 - t_2)) <= 200.0)
		tmp = Float64(1.0 / Float64(-0.25 * Float64(pi / log(Float64(Float64(t_1 + t_3) / Float64(t_3 - t_1))))));
	else
		tmp = Float64(-4.0 * Float64(log(fma(f, Float64(pi * 0.08333333333333333), Float64(4.0 / Float64(pi * f)))) / pi));
	end
	return tmp
end
code[f_] := Block[{t$95$0 = N[Exp[N[(f * N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Exp[N[(N[(Pi * f), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Exp[N[(f * N[((-Pi) / 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Exp[N[(0.25 * N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(t$95$0 + t$95$2), $MachinePrecision] / N[(t$95$0 - t$95$2), $MachinePrecision]), $MachinePrecision], 200.0], N[(1.0 / N[(-0.25 * N[(Pi / N[Log[N[(N[(t$95$1 + t$95$3), $MachinePrecision] / N[(t$95$3 - t$95$1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(N[Log[N[(f * N[(Pi * 0.08333333333333333), $MachinePrecision] + N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{f \cdot \frac{\pi}{4}}\\
t_1 := e^{\left(\pi \cdot f\right) \cdot -0.25}\\
t_2 := e^{f \cdot \frac{-\pi}{4}}\\
t_3 := e^{0.25 \cdot \left(\pi \cdot f\right)}\\
\mathbf{if}\;\frac{t_0 + t_2}{t_0 - t_2} \leq 200:\\
\;\;\;\;\frac{1}{-0.25 \cdot \frac{\pi}{\log \left(\frac{t_1 + t_3}{t_3 - t_1}\right)}}\\

\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{\log \left(\mathsf{fma}\left(f, \pi \cdot 0.08333333333333333, \frac{4}{\pi \cdot f}\right)\right)}{\pi}\\


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

Alternative 4: 96.2% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \left(\log \left({\left(e^{\frac{\pi}{-4}}\right)}^{f} + {\left(e^{\pi}\right)}^{\left(f \cdot 0.25\right)}\right) - \log \left(\mathsf{fma}\left(f, \pi \cdot 0.5, \mathsf{fma}\left({f}^{5}, {\pi}^{5} \cdot 1.6276041666666666 \cdot 10^{-5}, 0.005208333333333333 \cdot {\left(\pi \cdot f\right)}^{3}\right)\right)\right)\right) \cdot \frac{-4}{\pi} \end{array} \]
(FPCore (f)
 :precision binary64
 (*
  (-
   (log (+ (pow (exp (/ PI -4.0)) f) (pow (exp PI) (* f 0.25))))
   (log
    (fma
     f
     (* PI 0.5)
     (fma
      (pow f 5.0)
      (* (pow PI 5.0) 1.6276041666666666e-5)
      (* 0.005208333333333333 (pow (* PI f) 3.0))))))
  (/ -4.0 PI)))
double code(double f) {
	return (log((pow(exp((((double) M_PI) / -4.0)), f) + pow(exp(((double) M_PI)), (f * 0.25)))) - log(fma(f, (((double) M_PI) * 0.5), fma(pow(f, 5.0), (pow(((double) M_PI), 5.0) * 1.6276041666666666e-5), (0.005208333333333333 * pow((((double) M_PI) * f), 3.0)))))) * (-4.0 / ((double) M_PI));
}
function code(f)
	return Float64(Float64(log(Float64((exp(Float64(pi / -4.0)) ^ f) + (exp(pi) ^ Float64(f * 0.25)))) - log(fma(f, Float64(pi * 0.5), fma((f ^ 5.0), Float64((pi ^ 5.0) * 1.6276041666666666e-5), Float64(0.005208333333333333 * (Float64(pi * f) ^ 3.0)))))) * Float64(-4.0 / pi))
end
code[f_] := N[(N[(N[Log[N[(N[Power[N[Exp[N[(Pi / -4.0), $MachinePrecision]], $MachinePrecision], f], $MachinePrecision] + N[Power[N[Exp[Pi], $MachinePrecision], N[(f * 0.25), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Log[N[(f * N[(Pi * 0.5), $MachinePrecision] + N[(N[Power[f, 5.0], $MachinePrecision] * N[(N[Power[Pi, 5.0], $MachinePrecision] * 1.6276041666666666e-5), $MachinePrecision] + N[(0.005208333333333333 * N[Power[N[(Pi * f), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-4.0 / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(\log \left({\left(e^{\frac{\pi}{-4}}\right)}^{f} + {\left(e^{\pi}\right)}^{\left(f \cdot 0.25\right)}\right) - \log \left(\mathsf{fma}\left(f, \pi \cdot 0.5, \mathsf{fma}\left({f}^{5}, {\pi}^{5} \cdot 1.6276041666666666 \cdot 10^{-5}, 0.005208333333333333 \cdot {\left(\pi \cdot f\right)}^{3}\right)\right)\right)\right) \cdot \frac{-4}{\pi}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 96.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \frac{-4}{\pi} \cdot \log \left(\frac{e^{\frac{\pi}{\frac{-4}{f}}} + e^{f \cdot \frac{\pi}{4}}}{\mathsf{fma}\left(f, \pi \cdot 0.5, \mathsf{fma}\left({f}^{5}, {\pi}^{5} \cdot 1.6276041666666666 \cdot 10^{-5}, 0.005208333333333333 \cdot {\left(\pi \cdot f\right)}^{3}\right)\right)}\right) \end{array} \]
(FPCore (f)
 :precision binary64
 (*
  (/ -4.0 PI)
  (log
   (/
    (+ (exp (/ PI (/ -4.0 f))) (exp (* f (/ PI 4.0))))
    (fma
     f
     (* PI 0.5)
     (fma
      (pow f 5.0)
      (* (pow PI 5.0) 1.6276041666666666e-5)
      (* 0.005208333333333333 (pow (* PI f) 3.0))))))))
double code(double f) {
	return (-4.0 / ((double) M_PI)) * log(((exp((((double) M_PI) / (-4.0 / f))) + exp((f * (((double) M_PI) / 4.0)))) / fma(f, (((double) M_PI) * 0.5), fma(pow(f, 5.0), (pow(((double) M_PI), 5.0) * 1.6276041666666666e-5), (0.005208333333333333 * pow((((double) M_PI) * f), 3.0))))));
}
function code(f)
	return Float64(Float64(-4.0 / pi) * log(Float64(Float64(exp(Float64(pi / Float64(-4.0 / f))) + exp(Float64(f * Float64(pi / 4.0)))) / fma(f, Float64(pi * 0.5), fma((f ^ 5.0), Float64((pi ^ 5.0) * 1.6276041666666666e-5), Float64(0.005208333333333333 * (Float64(pi * f) ^ 3.0)))))))
end
code[f_] := N[(N[(-4.0 / Pi), $MachinePrecision] * N[Log[N[(N[(N[Exp[N[(Pi / N[(-4.0 / f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(f * N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(f * N[(Pi * 0.5), $MachinePrecision] + N[(N[Power[f, 5.0], $MachinePrecision] * N[(N[Power[Pi, 5.0], $MachinePrecision] * 1.6276041666666666e-5), $MachinePrecision] + N[(0.005208333333333333 * N[Power[N[(Pi * f), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{-4}{\pi} \cdot \log \left(\frac{e^{\frac{\pi}{\frac{-4}{f}}} + e^{f \cdot \frac{\pi}{4}}}{\mathsf{fma}\left(f, \pi \cdot 0.5, \mathsf{fma}\left({f}^{5}, {\pi}^{5} \cdot 1.6276041666666666 \cdot 10^{-5}, 0.005208333333333333 \cdot {\left(\pi \cdot f\right)}^{3}\right)\right)}\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 96.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ -4 \cdot \frac{\log \left(\frac{e^{\left(\pi \cdot f\right) \cdot -0.25} + e^{0.25 \cdot \left(\pi \cdot f\right)}}{\mathsf{fma}\left(f, \pi \cdot 0.5, 0.005208333333333333 \cdot {\left(\pi \cdot f\right)}^{3}\right)}\right)}{\pi} \end{array} \]
(FPCore (f)
 :precision binary64
 (*
  -4.0
  (/
   (log
    (/
     (+ (exp (* (* PI f) -0.25)) (exp (* 0.25 (* PI f))))
     (fma f (* PI 0.5) (* 0.005208333333333333 (pow (* PI f) 3.0)))))
   PI)))
double code(double f) {
	return -4.0 * (log(((exp(((((double) M_PI) * f) * -0.25)) + exp((0.25 * (((double) M_PI) * f)))) / fma(f, (((double) M_PI) * 0.5), (0.005208333333333333 * pow((((double) M_PI) * f), 3.0))))) / ((double) M_PI));
}
function code(f)
	return Float64(-4.0 * Float64(log(Float64(Float64(exp(Float64(Float64(pi * f) * -0.25)) + exp(Float64(0.25 * Float64(pi * f)))) / fma(f, Float64(pi * 0.5), Float64(0.005208333333333333 * (Float64(pi * f) ^ 3.0))))) / pi))
end
code[f_] := N[(-4.0 * N[(N[Log[N[(N[(N[Exp[N[(N[(Pi * f), $MachinePrecision] * -0.25), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(0.25 * N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(f * N[(Pi * 0.5), $MachinePrecision] + N[(0.005208333333333333 * N[Power[N[(Pi * f), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-4 \cdot \frac{\log \left(\frac{e^{\left(\pi \cdot f\right) \cdot -0.25} + e^{0.25 \cdot \left(\pi \cdot f\right)}}{\mathsf{fma}\left(f, \pi \cdot 0.5, 0.005208333333333333 \cdot {\left(\pi \cdot f\right)}^{3}\right)}\right)}{\pi}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 96.1% accurate, 2.0× speedup?

\[\begin{array}{l} \\ -4 \cdot \frac{\log \left(\mathsf{fma}\left(f, \pi \cdot 0.08333333333333333, \frac{4}{\pi \cdot f}\right)\right)}{\pi} \end{array} \]
(FPCore (f)
 :precision binary64
 (* -4.0 (/ (log (fma f (* PI 0.08333333333333333) (/ 4.0 (* PI f)))) PI)))
double code(double f) {
	return -4.0 * (log(fma(f, (((double) M_PI) * 0.08333333333333333), (4.0 / (((double) M_PI) * f)))) / ((double) M_PI));
}
function code(f)
	return Float64(-4.0 * Float64(log(fma(f, Float64(pi * 0.08333333333333333), Float64(4.0 / Float64(pi * f)))) / pi))
end
code[f_] := N[(-4.0 * N[(N[Log[N[(f * N[(Pi * 0.08333333333333333), $MachinePrecision] + N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-4 \cdot \frac{\log \left(\mathsf{fma}\left(f, \pi \cdot 0.08333333333333333, \frac{4}{\pi \cdot f}\right)\right)}{\pi}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 95.6% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \frac{-4 \cdot \log \left(\frac{\frac{2}{\pi}}{f \cdot 0.5}\right)}{\pi} \end{array} \]
(FPCore (f) :precision binary64 (/ (* -4.0 (log (/ (/ 2.0 PI) (* f 0.5)))) PI))
double code(double f) {
	return (-4.0 * log(((2.0 / ((double) M_PI)) / (f * 0.5)))) / ((double) M_PI);
}
public static double code(double f) {
	return (-4.0 * Math.log(((2.0 / Math.PI) / (f * 0.5)))) / Math.PI;
}
def code(f):
	return (-4.0 * math.log(((2.0 / math.pi) / (f * 0.5)))) / math.pi
function code(f)
	return Float64(Float64(-4.0 * log(Float64(Float64(2.0 / pi) / Float64(f * 0.5)))) / pi)
end
function tmp = code(f)
	tmp = (-4.0 * log(((2.0 / pi) / (f * 0.5)))) / pi;
end
code[f_] := N[(N[(-4.0 * N[Log[N[(N[(2.0 / Pi), $MachinePrecision] / N[(f * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]
\begin{array}{l}

\\
\frac{-4 \cdot \log \left(\frac{\frac{2}{\pi}}{f \cdot 0.5}\right)}{\pi}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 95.5% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \frac{-4}{\pi} \cdot \log \left(\frac{4}{\pi \cdot f}\right) \end{array} \]
(FPCore (f) :precision binary64 (* (/ -4.0 PI) (log (/ 4.0 (* PI f)))))
double code(double f) {
	return (-4.0 / ((double) M_PI)) * log((4.0 / (((double) M_PI) * f)));
}
public static double code(double f) {
	return (-4.0 / Math.PI) * Math.log((4.0 / (Math.PI * f)));
}
def code(f):
	return (-4.0 / math.pi) * math.log((4.0 / (math.pi * f)))
function code(f)
	return Float64(Float64(-4.0 / pi) * log(Float64(4.0 / Float64(pi * f))))
end
function tmp = code(f)
	tmp = (-4.0 / pi) * log((4.0 / (pi * f)));
end
code[f_] := N[(N[(-4.0 / Pi), $MachinePrecision] * N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{-4}{\pi} \cdot \log \left(\frac{4}{\pi \cdot f}\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 95.6% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \frac{-4 \cdot \log \left(\frac{4}{\pi \cdot f}\right)}{\pi} \end{array} \]
(FPCore (f) :precision binary64 (/ (* -4.0 (log (/ 4.0 (* PI f)))) PI))
double code(double f) {
	return (-4.0 * log((4.0 / (((double) M_PI) * f)))) / ((double) M_PI);
}
public static double code(double f) {
	return (-4.0 * Math.log((4.0 / (Math.PI * f)))) / Math.PI;
}
def code(f):
	return (-4.0 * math.log((4.0 / (math.pi * f)))) / math.pi
function code(f)
	return Float64(Float64(-4.0 * log(Float64(4.0 / Float64(pi * f)))) / pi)
end
function tmp = code(f)
	tmp = (-4.0 * log((4.0 / (pi * f)))) / pi;
end
code[f_] := N[(N[(-4.0 * N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]
\begin{array}{l}

\\
\frac{-4 \cdot \log \left(\frac{4}{\pi \cdot f}\right)}{\pi}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

?
herbie shell --seed 2023343 
(FPCore (f)
  :name "VandenBroeck and Keller, Equation (20)"
  :precision binary64
  (- (* (/ 1.0 (/ PI 4.0)) (log (/ (+ (exp (* (/ PI 4.0) f)) (exp (- (* (/ PI 4.0) f)))) (- (exp (* (/ PI 4.0) f)) (exp (- (* (/ PI 4.0) f)))))))))