VandenBroeck and Keller, Equation (20)

Percentage Accurate: 6.9% → 99.1%
Time: 29.6s
Alternatives: 6
Speedup: 4.8×

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 6 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: 99.1% accurate, 2.5× speedup?

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

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

    \[-\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. Add Preprocessing
  3. Taylor expanded in f around inf 6.4%

    \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}\right)}{\pi}} \]
  4. Step-by-step derivation
    1. clear-num6.4%

      \[\leadsto -4 \cdot \frac{\log \color{blue}{\left(\frac{1}{\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}}\right)}}{\pi} \]
    2. log-rec6.4%

      \[\leadsto -4 \cdot \frac{\color{blue}{-\log \left(\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}\right)}}{\pi} \]
    3. +-commutative6.4%

      \[\leadsto -4 \cdot \frac{-\log \left(\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{\color{blue}{e^{0.25 \cdot \left(f \cdot \pi\right)} + e^{-0.25 \cdot \left(f \cdot \pi\right)}}}\right)}{\pi} \]
    4. tanh-undef98.4%

      \[\leadsto -4 \cdot \frac{-\log \color{blue}{\tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}}{\pi} \]
    5. associate-*r*98.4%

      \[\leadsto -4 \cdot \frac{-\log \tanh \color{blue}{\left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi} \]
  5. Applied egg-rr98.4%

    \[\leadsto -4 \cdot \frac{\color{blue}{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi} \]
  6. Final simplification98.4%

    \[\leadsto 4 \cdot \frac{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}{\pi} \]
  7. Add Preprocessing

Alternative 2: 97.9% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;f \leq 1.5:\\ \;\;\;\;4 \cdot \frac{-\log \left(\frac{\frac{4}{\pi}}{f}\right)}{\pi}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi} \cdot \left(-4\right)\\ \end{array} \end{array} \]
(FPCore (f)
 :precision binary64
 (if (<= f 1.5)
   (* 4.0 (/ (- (log (/ (/ 4.0 PI) f))) PI))
   (* (/ (log (tanh (* 0.25 (* f PI)))) PI) (- 4.0))))
double code(double f) {
	double tmp;
	if (f <= 1.5) {
		tmp = 4.0 * (-log(((4.0 / ((double) M_PI)) / f)) / ((double) M_PI));
	} else {
		tmp = (log(tanh((0.25 * (f * ((double) M_PI))))) / ((double) M_PI)) * -4.0;
	}
	return tmp;
}
public static double code(double f) {
	double tmp;
	if (f <= 1.5) {
		tmp = 4.0 * (-Math.log(((4.0 / Math.PI) / f)) / Math.PI);
	} else {
		tmp = (Math.log(Math.tanh((0.25 * (f * Math.PI)))) / Math.PI) * -4.0;
	}
	return tmp;
}
def code(f):
	tmp = 0
	if f <= 1.5:
		tmp = 4.0 * (-math.log(((4.0 / math.pi) / f)) / math.pi)
	else:
		tmp = (math.log(math.tanh((0.25 * (f * math.pi)))) / math.pi) * -4.0
	return tmp
function code(f)
	tmp = 0.0
	if (f <= 1.5)
		tmp = Float64(4.0 * Float64(Float64(-log(Float64(Float64(4.0 / pi) / f))) / pi));
	else
		tmp = Float64(Float64(log(tanh(Float64(0.25 * Float64(f * pi)))) / pi) * Float64(-4.0));
	end
	return tmp
end
function tmp_2 = code(f)
	tmp = 0.0;
	if (f <= 1.5)
		tmp = 4.0 * (-log(((4.0 / pi) / f)) / pi);
	else
		tmp = (log(tanh((0.25 * (f * pi)))) / pi) * -4.0;
	end
	tmp_2 = tmp;
end
code[f_] := If[LessEqual[f, 1.5], N[(4.0 * N[((-N[Log[N[(N[(4.0 / Pi), $MachinePrecision] / f), $MachinePrecision]], $MachinePrecision]) / Pi), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[N[Tanh[N[(0.25 * N[(f * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] * (-4.0)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.5:\\
\;\;\;\;4 \cdot \frac{-\log \left(\frac{\frac{4}{\pi}}{f}\right)}{\pi}\\

\mathbf{else}:\\
\;\;\;\;\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi} \cdot \left(-4\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if f < 1.5

    1. Initial program 6.6%

      \[-\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. Add Preprocessing
    3. Taylor expanded in f around 0 98.2%

      \[\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)} \]
    4. Step-by-step derivation
      1. *-commutative98.2%

        \[\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*98.2%

        \[\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--98.2%

        \[\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-eval98.2%

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

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

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

      \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{4}{\pi}\right) + -1 \cdot \log f}{\pi}} \]
    7. Step-by-step derivation
      1. neg-mul-198.4%

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

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

      \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{4}{\pi}\right) - \log f}{\pi}} \]
    9. Taylor expanded in f around inf 98.4%

      \[\leadsto -4 \cdot \color{blue}{\frac{\log \left(\frac{4}{\pi}\right) - -1 \cdot \log \left(\frac{1}{f}\right)}{\pi}} \]
    10. Step-by-step derivation
      1. log-rec98.4%

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

        \[\leadsto -4 \cdot \frac{\log \left(\frac{4}{\pi}\right) - \color{blue}{\left(-\left(-\log f\right)\right)}}{\pi} \]
      3. remove-double-neg98.4%

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

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

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

    if 1.5 < f

    1. Initial program 1.5%

      \[-\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. Add Preprocessing
    3. Taylor expanded in f around inf 1.5%

      \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}\right)}{\pi}} \]
    4. Step-by-step derivation
      1. clear-num1.5%

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

        \[\leadsto -4 \cdot \frac{\color{blue}{-\log \left(\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}\right)}}{\pi} \]
      3. +-commutative1.5%

        \[\leadsto -4 \cdot \frac{-\log \left(\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{\color{blue}{e^{0.25 \cdot \left(f \cdot \pi\right)} + e^{-0.25 \cdot \left(f \cdot \pi\right)}}}\right)}{\pi} \]
      4. tanh-undef71.5%

        \[\leadsto -4 \cdot \frac{-\log \color{blue}{\tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}}{\pi} \]
      5. associate-*r*71.5%

        \[\leadsto -4 \cdot \frac{-\log \tanh \color{blue}{\left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi} \]
    5. Applied egg-rr71.5%

      \[\leadsto -4 \cdot \frac{\color{blue}{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi} \]
    6. Step-by-step derivation
      1. expm1-log1p-u71.5%

        \[\leadsto -4 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}{\pi}\right)\right)} \]
      2. expm1-udef71.5%

        \[\leadsto -4 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}{\pi}\right)} - 1\right)} \]
      3. add-sqr-sqrt71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)} \cdot \sqrt{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
      4. sqrt-unprod71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\left(-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)\right) \cdot \left(-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)\right)}}}{\pi}\right)} - 1\right) \]
      5. sqr-neg71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\sqrt{\color{blue}{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right) \cdot \log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
      6. sqrt-unprod71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)} \cdot \sqrt{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
      7. add-sqr-sqrt71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi}\right)} - 1\right) \]
      8. associate-*l*71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\log \tanh \color{blue}{\left(0.25 \cdot \left(f \cdot \pi\right)\right)}}{\pi}\right)} - 1\right) \]
    7. Applied egg-rr71.5%

      \[\leadsto -4 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-def71.5%

        \[\leadsto -4 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}\right)\right)} \]
      2. expm1-log1p71.5%

        \[\leadsto -4 \cdot \color{blue}{\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}} \]
    9. Simplified71.5%

      \[\leadsto -4 \cdot \color{blue}{\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;f \leq 1.5:\\ \;\;\;\;4 \cdot \frac{-\log \left(\frac{\frac{4}{\pi}}{f}\right)}{\pi}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi} \cdot \left(-4\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 97.9% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;f \leq 1.5:\\ \;\;\;\;4 \cdot \frac{\log f - \log \left(\frac{4}{\pi}\right)}{\pi}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi} \cdot \left(-4\right)\\ \end{array} \end{array} \]
(FPCore (f)
 :precision binary64
 (if (<= f 1.5)
   (* 4.0 (/ (- (log f) (log (/ 4.0 PI))) PI))
   (* (/ (log (tanh (* 0.25 (* f PI)))) PI) (- 4.0))))
double code(double f) {
	double tmp;
	if (f <= 1.5) {
		tmp = 4.0 * ((log(f) - log((4.0 / ((double) M_PI)))) / ((double) M_PI));
	} else {
		tmp = (log(tanh((0.25 * (f * ((double) M_PI))))) / ((double) M_PI)) * -4.0;
	}
	return tmp;
}
public static double code(double f) {
	double tmp;
	if (f <= 1.5) {
		tmp = 4.0 * ((Math.log(f) - Math.log((4.0 / Math.PI))) / Math.PI);
	} else {
		tmp = (Math.log(Math.tanh((0.25 * (f * Math.PI)))) / Math.PI) * -4.0;
	}
	return tmp;
}
def code(f):
	tmp = 0
	if f <= 1.5:
		tmp = 4.0 * ((math.log(f) - math.log((4.0 / math.pi))) / math.pi)
	else:
		tmp = (math.log(math.tanh((0.25 * (f * math.pi)))) / math.pi) * -4.0
	return tmp
function code(f)
	tmp = 0.0
	if (f <= 1.5)
		tmp = Float64(4.0 * Float64(Float64(log(f) - log(Float64(4.0 / pi))) / pi));
	else
		tmp = Float64(Float64(log(tanh(Float64(0.25 * Float64(f * pi)))) / pi) * Float64(-4.0));
	end
	return tmp
end
function tmp_2 = code(f)
	tmp = 0.0;
	if (f <= 1.5)
		tmp = 4.0 * ((log(f) - log((4.0 / pi))) / pi);
	else
		tmp = (log(tanh((0.25 * (f * pi)))) / pi) * -4.0;
	end
	tmp_2 = tmp;
end
code[f_] := If[LessEqual[f, 1.5], N[(4.0 * N[(N[(N[Log[f], $MachinePrecision] - N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[N[Tanh[N[(0.25 * N[(f * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] * (-4.0)), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.5:\\
\;\;\;\;4 \cdot \frac{\log f - \log \left(\frac{4}{\pi}\right)}{\pi}\\

\mathbf{else}:\\
\;\;\;\;\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi} \cdot \left(-4\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if f < 1.5

    1. Initial program 6.6%

      \[-\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. Add Preprocessing
    3. Taylor expanded in f around 0 98.2%

      \[\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)} \]
    4. Step-by-step derivation
      1. *-commutative98.2%

        \[\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*98.2%

        \[\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--98.2%

        \[\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-eval98.2%

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

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

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

      \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{4}{\pi}\right) + -1 \cdot \log f}{\pi}} \]
    7. Step-by-step derivation
      1. neg-mul-198.4%

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

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

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

    if 1.5 < f

    1. Initial program 1.5%

      \[-\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. Add Preprocessing
    3. Taylor expanded in f around inf 1.5%

      \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}\right)}{\pi}} \]
    4. Step-by-step derivation
      1. clear-num1.5%

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

        \[\leadsto -4 \cdot \frac{\color{blue}{-\log \left(\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}\right)}}{\pi} \]
      3. +-commutative1.5%

        \[\leadsto -4 \cdot \frac{-\log \left(\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{\color{blue}{e^{0.25 \cdot \left(f \cdot \pi\right)} + e^{-0.25 \cdot \left(f \cdot \pi\right)}}}\right)}{\pi} \]
      4. tanh-undef71.5%

        \[\leadsto -4 \cdot \frac{-\log \color{blue}{\tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}}{\pi} \]
      5. associate-*r*71.5%

        \[\leadsto -4 \cdot \frac{-\log \tanh \color{blue}{\left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi} \]
    5. Applied egg-rr71.5%

      \[\leadsto -4 \cdot \frac{\color{blue}{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi} \]
    6. Step-by-step derivation
      1. expm1-log1p-u71.5%

        \[\leadsto -4 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}{\pi}\right)\right)} \]
      2. expm1-udef71.5%

        \[\leadsto -4 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}{\pi}\right)} - 1\right)} \]
      3. add-sqr-sqrt71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)} \cdot \sqrt{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
      4. sqrt-unprod71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\left(-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)\right) \cdot \left(-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)\right)}}}{\pi}\right)} - 1\right) \]
      5. sqr-neg71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\sqrt{\color{blue}{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right) \cdot \log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
      6. sqrt-unprod71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)} \cdot \sqrt{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
      7. add-sqr-sqrt71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi}\right)} - 1\right) \]
      8. associate-*l*71.5%

        \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\log \tanh \color{blue}{\left(0.25 \cdot \left(f \cdot \pi\right)\right)}}{\pi}\right)} - 1\right) \]
    7. Applied egg-rr71.5%

      \[\leadsto -4 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}\right)} - 1\right)} \]
    8. Step-by-step derivation
      1. expm1-def71.5%

        \[\leadsto -4 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}\right)\right)} \]
      2. expm1-log1p71.5%

        \[\leadsto -4 \cdot \color{blue}{\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}} \]
    9. Simplified71.5%

      \[\leadsto -4 \cdot \color{blue}{\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;f \leq 1.5:\\ \;\;\;\;4 \cdot \frac{\log f - \log \left(\frac{4}{\pi}\right)}{\pi}\\ \mathbf{else}:\\ \;\;\;\;\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi} \cdot \left(-4\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 1.6% accurate, 4.8× speedup?

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

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

    \[-\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. Add Preprocessing
  3. Taylor expanded in f around inf 6.4%

    \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}\right)}{\pi}} \]
  4. Step-by-step derivation
    1. clear-num6.4%

      \[\leadsto -4 \cdot \frac{\log \color{blue}{\left(\frac{1}{\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}}\right)}}{\pi} \]
    2. log-rec6.4%

      \[\leadsto -4 \cdot \frac{\color{blue}{-\log \left(\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{e^{-0.25 \cdot \left(f \cdot \pi\right)} + e^{0.25 \cdot \left(f \cdot \pi\right)}}\right)}}{\pi} \]
    3. +-commutative6.4%

      \[\leadsto -4 \cdot \frac{-\log \left(\frac{e^{0.25 \cdot \left(f \cdot \pi\right)} - e^{-0.25 \cdot \left(f \cdot \pi\right)}}{\color{blue}{e^{0.25 \cdot \left(f \cdot \pi\right)} + e^{-0.25 \cdot \left(f \cdot \pi\right)}}}\right)}{\pi} \]
    4. tanh-undef98.4%

      \[\leadsto -4 \cdot \frac{-\log \color{blue}{\tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}}{\pi} \]
    5. associate-*r*98.4%

      \[\leadsto -4 \cdot \frac{-\log \tanh \color{blue}{\left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi} \]
  5. Applied egg-rr98.4%

    \[\leadsto -4 \cdot \frac{\color{blue}{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi} \]
  6. Step-by-step derivation
    1. expm1-log1p-u97.2%

      \[\leadsto -4 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}{\pi}\right)\right)} \]
    2. expm1-udef97.2%

      \[\leadsto -4 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}{\pi}\right)} - 1\right)} \]
    3. add-sqr-sqrt97.1%

      \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)} \cdot \sqrt{-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
    4. sqrt-unprod97.2%

      \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\left(-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)\right) \cdot \left(-\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)\right)}}}{\pi}\right)} - 1\right) \]
    5. sqr-neg97.2%

      \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\sqrt{\color{blue}{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right) \cdot \log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
    6. sqrt-unprod2.8%

      \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\sqrt{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)} \cdot \sqrt{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}}{\pi}\right)} - 1\right) \]
    7. add-sqr-sqrt2.8%

      \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\color{blue}{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}}{\pi}\right)} - 1\right) \]
    8. associate-*l*2.8%

      \[\leadsto -4 \cdot \left(e^{\mathsf{log1p}\left(\frac{\log \tanh \color{blue}{\left(0.25 \cdot \left(f \cdot \pi\right)\right)}}{\pi}\right)} - 1\right) \]
  7. Applied egg-rr2.8%

    \[\leadsto -4 \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}\right)} - 1\right)} \]
  8. Step-by-step derivation
    1. expm1-def2.8%

      \[\leadsto -4 \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}\right)\right)} \]
    2. expm1-log1p4.3%

      \[\leadsto -4 \cdot \color{blue}{\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}} \]
  9. Simplified4.3%

    \[\leadsto -4 \cdot \color{blue}{\frac{\log \tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}{\pi}} \]
  10. Taylor expanded in f around 0 1.6%

    \[\leadsto -4 \cdot \color{blue}{\frac{\log f + \log \left(0.25 \cdot \pi\right)}{\pi}} \]
  11. Step-by-step derivation
    1. log-prod1.6%

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

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

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

      \[\leadsto -4 \cdot \frac{\color{blue}{\log \left(\left(f \cdot 0.25\right) \cdot \pi\right)}}{\pi} \]
    5. associate-*l*1.6%

      \[\leadsto -4 \cdot \frac{\log \color{blue}{\left(f \cdot \left(0.25 \cdot \pi\right)\right)}}{\pi} \]
  12. Simplified1.6%

    \[\leadsto -4 \cdot \color{blue}{\frac{\log \left(f \cdot \left(0.25 \cdot \pi\right)\right)}{\pi}} \]
  13. Final simplification1.6%

    \[\leadsto \frac{\log \left(f \cdot \left(0.25 \cdot \pi\right)\right)}{\pi} \cdot \left(-4\right) \]
  14. Add Preprocessing

Alternative 5: 95.7% accurate, 4.8× speedup?

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

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

    \[-\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. Add Preprocessing
  3. Taylor expanded in f around 0 94.5%

    \[\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)} \]
  4. Step-by-step derivation
    1. *-commutative94.5%

      \[\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*94.5%

      \[\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--94.5%

      \[\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-eval94.5%

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

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

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

    \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{4}{\pi}\right) + -1 \cdot \log f}{\pi}} \]
  7. Step-by-step derivation
    1. neg-mul-194.7%

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

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

    \[\leadsto -\color{blue}{4 \cdot \frac{\log \left(\frac{4}{\pi}\right) - \log f}{\pi}} \]
  9. Taylor expanded in f around inf 94.7%

    \[\leadsto -4 \cdot \color{blue}{\frac{\log \left(\frac{4}{\pi}\right) - -1 \cdot \log \left(\frac{1}{f}\right)}{\pi}} \]
  10. Step-by-step derivation
    1. log-rec94.7%

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

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

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

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

    \[\leadsto -4 \cdot \color{blue}{\frac{\log \left(\frac{\frac{4}{\pi}}{f}\right)}{\pi}} \]
  12. Final simplification94.6%

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

Alternative 6: 1.6% accurate, 5.0× speedup?

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

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

    \[-\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. Add Preprocessing
  3. Applied egg-rr1.6%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \log \left(\frac{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}{\color{blue}{16}}\right) \]
  4. Step-by-step derivation
    1. clear-num1.6%

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

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \color{blue}{\left(\log 1 - \log \left(\frac{16}{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}\right)\right)} \]
    3. metadata-eval1.6%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \left(\color{blue}{0} - \log \left(\frac{16}{e^{\frac{\pi}{4} \cdot f} + e^{-\frac{\pi}{4} \cdot f}}\right)\right) \]
    4. cosh-undef1.6%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \left(0 - \log \left(\frac{16}{\color{blue}{2 \cdot \cosh \left(\frac{\pi}{4} \cdot f\right)}}\right)\right) \]
    5. div-inv1.6%

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

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \left(0 - \log \left(\frac{16}{2 \cdot \cosh \left(\left(\pi \cdot \color{blue}{0.25}\right) \cdot f\right)}\right)\right) \]
  5. Applied egg-rr1.6%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \color{blue}{\left(0 - \log \left(\frac{16}{2 \cdot \cosh \left(\left(\pi \cdot 0.25\right) \cdot f\right)}\right)\right)} \]
  6. Step-by-step derivation
    1. neg-sub01.6%

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

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \left(-\log \color{blue}{\left(\frac{\frac{16}{2}}{\cosh \left(\left(\pi \cdot 0.25\right) \cdot f\right)}\right)}\right) \]
    3. metadata-eval1.6%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \left(-\log \left(\frac{\color{blue}{8}}{\cosh \left(\left(\pi \cdot 0.25\right) \cdot f\right)}\right)\right) \]
    4. *-commutative1.6%

      \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \left(-\log \left(\frac{8}{\cosh \color{blue}{\left(f \cdot \left(\pi \cdot 0.25\right)\right)}}\right)\right) \]
  7. Simplified1.6%

    \[\leadsto -\frac{1}{\frac{\pi}{4}} \cdot \color{blue}{\left(-\log \left(\frac{8}{\cosh \left(f \cdot \left(\pi \cdot 0.25\right)\right)}\right)\right)} \]
  8. Taylor expanded in f around 0 1.6%

    \[\leadsto -\color{blue}{-4 \cdot \frac{\log 8}{\pi}} \]
  9. Final simplification1.6%

    \[\leadsto \frac{\log 8}{\pi} \cdot \left(--4\right) \]
  10. Add Preprocessing

Reproduce

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