VandenBroeck and Keller, Equation (20)

Percentage Accurate: 6.6% → 96.2%
Time: 27.6s
Alternatives: 3
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 3 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.6% 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.2% accurate, 2.0× speedup?

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

\\
-\mathsf{fma}\left(0.08333333333333333, \pi \cdot \left(f \cdot f\right), \frac{\log \left(\frac{4}{\pi \cdot f}\right)}{\pi \cdot 0.25}\right)
\end{array}
Derivation
  1. Initial program 5.1%

    \[-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}{e^{\frac{\pi}{4} \cdot f} - e^{-\frac{\pi}{4} \cdot f}}\right) \]
  2. Taylor expanded in f around 0 97.2%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \color{blue}{\left(\log \left(\frac{2}{0.25 \cdot \pi - -0.25 \cdot \pi}\right) + \left(-1 \cdot \log f + \left(0.5 \cdot \left(f \cdot \left(\left(-0.25 \cdot \frac{\pi}{0.25 \cdot \pi - -0.25 \cdot \pi} + 0.25 \cdot \frac{\pi}{0.25 \cdot \pi - -0.25 \cdot \pi}\right) \cdot \left(0.25 \cdot \pi - -0.25 \cdot \pi\right)\right)\right) + 0.5 \cdot \left({f}^{2} \cdot \left(-0.25 \cdot \left({\left(-0.25 \cdot \frac{\pi}{0.25 \cdot \pi - -0.25 \cdot \pi} + 0.25 \cdot \frac{\pi}{0.25 \cdot \pi - -0.25 \cdot \pi}\right)}^{2} \cdot {\left(0.25 \cdot \pi - -0.25 \cdot \pi\right)}^{2}\right) + \left(0.0625 \cdot \frac{{\pi}^{2}}{0.25 \cdot \pi - -0.25 \cdot \pi} - 2 \cdot \frac{0.0026041666666666665 \cdot {\pi}^{3} - -0.0026041666666666665 \cdot {\pi}^{3}}{{\left(0.25 \cdot \pi - -0.25 \cdot \pi\right)}^{2}}\right) \cdot \left(0.25 \cdot \pi - -0.25 \cdot \pi\right)\right)\right)\right)\right)\right)} \]
  3. Simplified97.2%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{{\pi}^{3}}{{\pi}^{2}} \cdot 0.020833333333333332, -2, \frac{0.0625 \cdot \pi}{0.5} \cdot 1\right), \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right)} \]
  4. Step-by-step derivation
    1. fma-udef97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\left(\frac{{\pi}^{3}}{{\pi}^{2}} \cdot 0.020833333333333332\right) \cdot -2 + \frac{0.0625 \cdot \pi}{0.5} \cdot 1}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    2. pow-div97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\color{blue}{{\pi}^{\left(3 - 2\right)}} \cdot 0.020833333333333332\right) \cdot -2 + \frac{0.0625 \cdot \pi}{0.5} \cdot 1, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    3. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left({\pi}^{\color{blue}{1}} \cdot 0.020833333333333332\right) \cdot -2 + \frac{0.0625 \cdot \pi}{0.5} \cdot 1, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    4. pow197.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\color{blue}{\pi} \cdot 0.020833333333333332\right) \cdot -2 + \frac{0.0625 \cdot \pi}{0.5} \cdot 1, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    5. *-rgt-identity97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \color{blue}{\frac{0.0625 \cdot \pi}{0.5}}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    6. div-inv97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \color{blue}{\left(0.0625 \cdot \pi\right) \cdot \frac{1}{0.5}}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    7. *-commutative97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \color{blue}{\left(\pi \cdot 0.0625\right)} \cdot \frac{1}{0.5}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    8. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \left(\pi \cdot 0.0625\right) \cdot \color{blue}{2}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
  5. Applied egg-rr97.2%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \left(\pi \cdot 0.0625\right) \cdot 2}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
  6. Step-by-step derivation
    1. associate-*l*97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\pi \cdot \left(0.020833333333333332 \cdot -2\right)} + \left(\pi \cdot 0.0625\right) \cdot 2, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    2. associate-*l*97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi \cdot \left(0.020833333333333332 \cdot -2\right) + \color{blue}{\pi \cdot \left(0.0625 \cdot 2\right)}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    3. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi \cdot \left(0.020833333333333332 \cdot -2\right) + \pi \cdot \color{blue}{0.125}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    4. distribute-lft-out97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\pi \cdot \left(0.020833333333333332 \cdot -2 + 0.125\right)}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    5. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi \cdot \left(\color{blue}{-0.041666666666666664} + 0.125\right), \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    6. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi \cdot \color{blue}{0.08333333333333333}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
  7. Simplified97.2%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\pi \cdot 0.08333333333333333}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
  8. Taylor expanded in f around 0 97.3%

    \[\leadsto -\color{blue}{\left(0.08333333333333333 \cdot \left({f}^{2} \cdot \pi\right) + 4 \cdot \frac{\log \left(\frac{4}{\pi}\right) - \log f}{\pi}\right)} \]
  9. Simplified97.3%

    \[\leadsto -\color{blue}{\mathsf{fma}\left(0.08333333333333333, \pi \cdot \left(f \cdot f\right), \frac{\log \left(\frac{4}{\pi \cdot f}\right)}{\pi \cdot 0.25}\right)} \]
  10. Final simplification97.3%

    \[\leadsto -\mathsf{fma}\left(0.08333333333333333, \pi \cdot \left(f \cdot f\right), \frac{\log \left(\frac{4}{\pi \cdot f}\right)}{\pi \cdot 0.25}\right) \]

Alternative 2: 95.7% accurate, 3.3× speedup?

\[\begin{array}{l} \\ 4 \cdot \frac{-\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(4.0 * Float64(Float64(-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[(4.0 * N[((-N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
4 \cdot \frac{-\log \left(\frac{4}{\pi \cdot f}\right)}{\pi}
\end{array}
Derivation
  1. Initial program 5.1%

    \[-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}{e^{\frac{\pi}{4} \cdot f} - e^{-\frac{\pi}{4} \cdot f}}\right) \]
  2. Taylor expanded in f around 0 97.0%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \log \color{blue}{\left(\frac{2}{f \cdot \left(0.25 \cdot \pi - -0.25 \cdot \pi\right)}\right)} \]
  3. Step-by-step derivation
    1. *-commutative97.0%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{2}{\color{blue}{\left(0.25 \cdot \pi - -0.25 \cdot \pi\right) \cdot f}}\right) \]
    2. associate-/r*97.0%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \log \color{blue}{\left(\frac{\frac{2}{0.25 \cdot \pi - -0.25 \cdot \pi}}{f}\right)} \]
    3. distribute-rgt-out--97.0%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{\frac{2}{\color{blue}{\pi \cdot \left(0.25 - -0.25\right)}}}{f}\right) \]
    4. metadata-eval97.0%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{\frac{2}{\pi \cdot \color{blue}{0.5}}}{f}\right) \]
  4. Simplified97.0%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \log \color{blue}{\left(\frac{\frac{2}{\pi \cdot 0.5}}{f}\right)} \]
  5. Taylor expanded in f around 0 97.1%

    \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{4}{\pi}\right) + -1 \cdot \log f}{\pi}} \]
  6. Step-by-step derivation
    1. associate-*r/97.1%

      \[\leadsto -\color{blue}{\frac{4 \cdot \left(\log \left(\frac{4}{\pi}\right) + -1 \cdot \log f\right)}{\pi}} \]
    2. neg-mul-197.1%

      \[\leadsto -\frac{4 \cdot \left(\log \left(\frac{4}{\pi}\right) + \color{blue}{\left(-\log f\right)}\right)}{\pi} \]
    3. +-commutative97.1%

      \[\leadsto -\frac{4 \cdot \color{blue}{\left(\left(-\log f\right) + \log \left(\frac{4}{\pi}\right)\right)}}{\pi} \]
    4. log-rec97.1%

      \[\leadsto -\frac{4 \cdot \left(\color{blue}{\log \left(\frac{1}{f}\right)} + \log \left(\frac{4}{\pi}\right)\right)}{\pi} \]
    5. log-rec97.1%

      \[\leadsto -\frac{4 \cdot \left(\color{blue}{\left(-\log f\right)} + \log \left(\frac{4}{\pi}\right)\right)}{\pi} \]
    6. +-commutative97.1%

      \[\leadsto -\frac{4 \cdot \color{blue}{\left(\log \left(\frac{4}{\pi}\right) + \left(-\log f\right)\right)}}{\pi} \]
    7. remove-double-neg97.1%

      \[\leadsto -\frac{4 \cdot \left(\log \left(\frac{4}{\pi}\right) + \color{blue}{\left(-\left(-\left(-\log f\right)\right)\right)}\right)}{\pi} \]
    8. mul-1-neg97.1%

      \[\leadsto -\frac{4 \cdot \left(\log \left(\frac{4}{\pi}\right) + \left(-\color{blue}{-1 \cdot \left(-\log f\right)}\right)\right)}{\pi} \]
    9. log-rec97.1%

      \[\leadsto -\frac{4 \cdot \left(\log \left(\frac{4}{\pi}\right) + \left(--1 \cdot \color{blue}{\log \left(\frac{1}{f}\right)}\right)\right)}{\pi} \]
    10. sub-neg97.1%

      \[\leadsto -\frac{4 \cdot \color{blue}{\left(\log \left(\frac{4}{\pi}\right) - -1 \cdot \log \left(\frac{1}{f}\right)\right)}}{\pi} \]
    11. *-commutative97.1%

      \[\leadsto -\frac{\color{blue}{\left(\log \left(\frac{4}{\pi}\right) - -1 \cdot \log \left(\frac{1}{f}\right)\right) \cdot 4}}{\pi} \]
    12. associate-*l/97.1%

      \[\leadsto -\color{blue}{\frac{\log \left(\frac{4}{\pi}\right) - -1 \cdot \log \left(\frac{1}{f}\right)}{\pi} \cdot 4} \]
  7. Simplified97.2%

    \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{4}{f \cdot \pi}\right)}{\pi}} \]
  8. Final simplification97.2%

    \[\leadsto 4 \cdot \frac{-\log \left(\frac{4}{\pi \cdot f}\right)}{\pi} \]

Alternative 3: 4.2% accurate, 9.6× speedup?

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

\\
0.08333333333333333 \cdot \left(f \cdot \left(\pi \cdot \left(-f\right)\right)\right)
\end{array}
Derivation
  1. Initial program 5.1%

    \[-\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}{e^{\frac{\pi}{4} \cdot f} - e^{-\frac{\pi}{4} \cdot f}}\right) \]
  2. Taylor expanded in f around 0 97.2%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \color{blue}{\left(\log \left(\frac{2}{0.25 \cdot \pi - -0.25 \cdot \pi}\right) + \left(-1 \cdot \log f + \left(0.5 \cdot \left(f \cdot \left(\left(-0.25 \cdot \frac{\pi}{0.25 \cdot \pi - -0.25 \cdot \pi} + 0.25 \cdot \frac{\pi}{0.25 \cdot \pi - -0.25 \cdot \pi}\right) \cdot \left(0.25 \cdot \pi - -0.25 \cdot \pi\right)\right)\right) + 0.5 \cdot \left({f}^{2} \cdot \left(-0.25 \cdot \left({\left(-0.25 \cdot \frac{\pi}{0.25 \cdot \pi - -0.25 \cdot \pi} + 0.25 \cdot \frac{\pi}{0.25 \cdot \pi - -0.25 \cdot \pi}\right)}^{2} \cdot {\left(0.25 \cdot \pi - -0.25 \cdot \pi\right)}^{2}\right) + \left(0.0625 \cdot \frac{{\pi}^{2}}{0.25 \cdot \pi - -0.25 \cdot \pi} - 2 \cdot \frac{0.0026041666666666665 \cdot {\pi}^{3} - -0.0026041666666666665 \cdot {\pi}^{3}}{{\left(0.25 \cdot \pi - -0.25 \cdot \pi\right)}^{2}}\right) \cdot \left(0.25 \cdot \pi - -0.25 \cdot \pi\right)\right)\right)\right)\right)\right)} \]
  3. Simplified97.2%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(\frac{{\pi}^{3}}{{\pi}^{2}} \cdot 0.020833333333333332, -2, \frac{0.0625 \cdot \pi}{0.5} \cdot 1\right), \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right)} \]
  4. Step-by-step derivation
    1. fma-udef97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\left(\frac{{\pi}^{3}}{{\pi}^{2}} \cdot 0.020833333333333332\right) \cdot -2 + \frac{0.0625 \cdot \pi}{0.5} \cdot 1}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    2. pow-div97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\color{blue}{{\pi}^{\left(3 - 2\right)}} \cdot 0.020833333333333332\right) \cdot -2 + \frac{0.0625 \cdot \pi}{0.5} \cdot 1, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    3. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left({\pi}^{\color{blue}{1}} \cdot 0.020833333333333332\right) \cdot -2 + \frac{0.0625 \cdot \pi}{0.5} \cdot 1, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    4. pow197.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\color{blue}{\pi} \cdot 0.020833333333333332\right) \cdot -2 + \frac{0.0625 \cdot \pi}{0.5} \cdot 1, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    5. *-rgt-identity97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \color{blue}{\frac{0.0625 \cdot \pi}{0.5}}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    6. div-inv97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \color{blue}{\left(0.0625 \cdot \pi\right) \cdot \frac{1}{0.5}}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    7. *-commutative97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \color{blue}{\left(\pi \cdot 0.0625\right)} \cdot \frac{1}{0.5}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    8. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \left(\pi \cdot 0.0625\right) \cdot \color{blue}{2}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
  5. Applied egg-rr97.2%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\left(\pi \cdot 0.020833333333333332\right) \cdot -2 + \left(\pi \cdot 0.0625\right) \cdot 2}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
  6. Step-by-step derivation
    1. associate-*l*97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\pi \cdot \left(0.020833333333333332 \cdot -2\right)} + \left(\pi \cdot 0.0625\right) \cdot 2, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    2. associate-*l*97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi \cdot \left(0.020833333333333332 \cdot -2\right) + \color{blue}{\pi \cdot \left(0.0625 \cdot 2\right)}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    3. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi \cdot \left(0.020833333333333332 \cdot -2\right) + \pi \cdot \color{blue}{0.125}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    4. distribute-lft-out97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\pi \cdot \left(0.020833333333333332 \cdot -2 + 0.125\right)}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    5. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi \cdot \left(\color{blue}{-0.041666666666666664} + 0.125\right), \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
    6. metadata-eval97.2%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\pi \cdot \color{blue}{0.08333333333333333}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
  7. Simplified97.2%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \mathsf{fma}\left(\mathsf{fma}\left(\color{blue}{\pi \cdot 0.08333333333333333}, \left(\pi \cdot 0.5\right) \cdot \left(f \cdot f\right), 0\right), 0.5, \log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \]
  8. Taylor expanded in f around inf 4.0%

    \[\leadsto -\color{blue}{0.08333333333333333 \cdot \left({f}^{2} \cdot \pi\right)} \]
  9. Step-by-step derivation
    1. *-commutative4.0%

      \[\leadsto -0.08333333333333333 \cdot \color{blue}{\left(\pi \cdot {f}^{2}\right)} \]
    2. unpow24.0%

      \[\leadsto -0.08333333333333333 \cdot \left(\pi \cdot \color{blue}{\left(f \cdot f\right)}\right) \]
  10. Simplified4.0%

    \[\leadsto -\color{blue}{0.08333333333333333 \cdot \left(\pi \cdot \left(f \cdot f\right)\right)} \]
  11. Taylor expanded in f around 0 4.0%

    \[\leadsto -0.08333333333333333 \cdot \color{blue}{\left({f}^{2} \cdot \pi\right)} \]
  12. Step-by-step derivation
    1. unpow24.0%

      \[\leadsto -0.08333333333333333 \cdot \left(\color{blue}{\left(f \cdot f\right)} \cdot \pi\right) \]
    2. associate-*l*4.0%

      \[\leadsto -0.08333333333333333 \cdot \color{blue}{\left(f \cdot \left(f \cdot \pi\right)\right)} \]
  13. Simplified4.0%

    \[\leadsto -0.08333333333333333 \cdot \color{blue}{\left(f \cdot \left(f \cdot \pi\right)\right)} \]
  14. Final simplification4.0%

    \[\leadsto 0.08333333333333333 \cdot \left(f \cdot \left(\pi \cdot \left(-f\right)\right)\right) \]

Reproduce

?
herbie shell --seed 2023291 
(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)))))))))