
(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:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (f)
:precision binary64
(-
(fma
2.0
(fma
(/
(fma
(* PI 0.5)
(fma 0.0625 (/ PI 0.5) (/ -2.0 (* (/ (pow PI 2.0) (pow PI 3.0)) 48.0)))
0.0)
PI)
(* f f)
0.0)
(/ (* (- (log (/ 2.0 (* PI 0.5))) (log f)) 4.0) PI))))
double code(double f) {
return -fma(2.0, fma((fma((((double) M_PI) * 0.5), fma(0.0625, (((double) M_PI) / 0.5), (-2.0 / ((pow(((double) M_PI), 2.0) / pow(((double) M_PI), 3.0)) * 48.0))), 0.0) / ((double) M_PI)), (f * f), 0.0), (((log((2.0 / (((double) M_PI) * 0.5))) - log(f)) * 4.0) / ((double) M_PI)));
}
function code(f) return Float64(-fma(2.0, fma(Float64(fma(Float64(pi * 0.5), fma(0.0625, Float64(pi / 0.5), Float64(-2.0 / Float64(Float64((pi ^ 2.0) / (pi ^ 3.0)) * 48.0))), 0.0) / pi), Float64(f * f), 0.0), Float64(Float64(Float64(log(Float64(2.0 / Float64(pi * 0.5))) - log(f)) * 4.0) / pi))) end
code[f_] := (-N[(2.0 * N[(N[(N[(N[(Pi * 0.5), $MachinePrecision] * N[(0.0625 * N[(Pi / 0.5), $MachinePrecision] + N[(-2.0 / N[(N[(N[Power[Pi, 2.0], $MachinePrecision] / N[Power[Pi, 3.0], $MachinePrecision]), $MachinePrecision] * 48.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision] / Pi), $MachinePrecision] * N[(f * f), $MachinePrecision] + 0.0), $MachinePrecision] + N[(N[(N[(N[Log[N[(2.0 / N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[Log[f], $MachinePrecision]), $MachinePrecision] * 4.0), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision])
\begin{array}{l}
\\
-\mathsf{fma}\left(2, \mathsf{fma}\left(\frac{\mathsf{fma}\left(\pi \cdot 0.5, \mathsf{fma}\left(0.0625, \frac{\pi}{0.5}, \frac{-2}{\frac{{\pi}^{2}}{{\pi}^{3}} \cdot 48}\right), 0\right)}{\pi}, f \cdot f, 0\right), \frac{\left(\log \left(\frac{2}{\pi \cdot 0.5}\right) - \log f\right) \cdot 4}{\pi}\right)
\end{array}
Initial program 7.0%
Taylor expanded in f around 0 96.7%
Simplified96.7%
Final simplification96.7%
(FPCore (f) :precision binary64 (let* ((t_0 (* f (* PI 0.25))) (t_1 (cbrt (cosh t_0)))) (/ (- (log (* (pow t_1 2.0) (/ t_1 (sinh t_0))))) (* PI 0.25))))
double code(double f) {
double t_0 = f * (((double) M_PI) * 0.25);
double t_1 = cbrt(cosh(t_0));
return -log((pow(t_1, 2.0) * (t_1 / sinh(t_0)))) / (((double) M_PI) * 0.25);
}
public static double code(double f) {
double t_0 = f * (Math.PI * 0.25);
double t_1 = Math.cbrt(Math.cosh(t_0));
return -Math.log((Math.pow(t_1, 2.0) * (t_1 / Math.sinh(t_0)))) / (Math.PI * 0.25);
}
function code(f) t_0 = Float64(f * Float64(pi * 0.25)) t_1 = cbrt(cosh(t_0)) return Float64(Float64(-log(Float64((t_1 ^ 2.0) * Float64(t_1 / sinh(t_0))))) / Float64(pi * 0.25)) end
code[f_] := Block[{t$95$0 = N[(f * N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[Cosh[t$95$0], $MachinePrecision], 1/3], $MachinePrecision]}, N[((-N[Log[N[(N[Power[t$95$1, 2.0], $MachinePrecision] * N[(t$95$1 / N[Sinh[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := f \cdot \left(\pi \cdot 0.25\right)\\
t_1 := \sqrt[3]{\cosh t_0}\\
\frac{-\log \left({t_1}^{2} \cdot \frac{t_1}{\sinh t_0}\right)}{\pi \cdot 0.25}
\end{array}
\end{array}
Initial program 7.0%
Taylor expanded in f around inf 7.0%
exp-prod7.0%
*-commutative7.0%
distribute-lft-neg-in7.0%
metadata-eval7.0%
*-commutative7.0%
Simplified7.0%
associate-*l/7.0%
Applied egg-rr96.6%
Simplified96.6%
add-exp-log96.6%
Applied egg-rr96.6%
add-cube-cbrt96.6%
add-exp-log96.7%
*-un-lft-identity96.7%
times-frac96.7%
pow296.7%
Applied egg-rr96.7%
Final simplification96.7%
(FPCore (f) :precision binary64 (let* ((t_0 (* 0.25 (* PI f)))) (* (log (/ (cosh t_0) (sinh t_0))) (/ (- 4.0) PI))))
double code(double f) {
double t_0 = 0.25 * (((double) M_PI) * f);
return log((cosh(t_0) / sinh(t_0))) * (-4.0 / ((double) M_PI));
}
public static double code(double f) {
double t_0 = 0.25 * (Math.PI * f);
return Math.log((Math.cosh(t_0) / Math.sinh(t_0))) * (-4.0 / Math.PI);
}
def code(f): t_0 = 0.25 * (math.pi * f) return math.log((math.cosh(t_0) / math.sinh(t_0))) * (-4.0 / math.pi)
function code(f) t_0 = Float64(0.25 * Float64(pi * f)) return Float64(log(Float64(cosh(t_0) / sinh(t_0))) * Float64(Float64(-4.0) / pi)) end
function tmp = code(f) t_0 = 0.25 * (pi * f); tmp = log((cosh(t_0) / sinh(t_0))) * (-4.0 / pi); end
code[f_] := Block[{t$95$0 = N[(0.25 * N[(Pi * f), $MachinePrecision]), $MachinePrecision]}, N[(N[Log[N[(N[Cosh[t$95$0], $MachinePrecision] / N[Sinh[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-4.0) / Pi), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.25 \cdot \left(\pi \cdot f\right)\\
\log \left(\frac{\cosh t_0}{\sinh t_0}\right) \cdot \frac{-4}{\pi}
\end{array}
\end{array}
Initial program 7.0%
Taylor expanded in f around inf 7.0%
exp-prod7.0%
*-commutative7.0%
distribute-lft-neg-in7.0%
metadata-eval7.0%
*-commutative7.0%
Simplified7.0%
associate-*l/7.0%
Applied egg-rr96.6%
Simplified96.6%
add-exp-log96.6%
Applied egg-rr96.6%
expm1-log1p-u95.4%
expm1-udef95.4%
Applied egg-rr95.4%
expm1-def95.4%
expm1-log1p96.6%
*-commutative96.6%
associate-*l/96.6%
associate-*r/96.4%
associate-*r*96.4%
*-commutative96.4%
associate-*r*96.4%
*-commutative96.4%
Simplified96.4%
Final simplification96.4%
(FPCore (f) :precision binary64 (let* ((t_0 (* f (* PI 0.25)))) (/ (- (log (/ (cosh t_0) (sinh t_0)))) (* PI 0.25))))
double code(double f) {
double t_0 = f * (((double) M_PI) * 0.25);
return -log((cosh(t_0) / sinh(t_0))) / (((double) M_PI) * 0.25);
}
public static double code(double f) {
double t_0 = f * (Math.PI * 0.25);
return -Math.log((Math.cosh(t_0) / Math.sinh(t_0))) / (Math.PI * 0.25);
}
def code(f): t_0 = f * (math.pi * 0.25) return -math.log((math.cosh(t_0) / math.sinh(t_0))) / (math.pi * 0.25)
function code(f) t_0 = Float64(f * Float64(pi * 0.25)) return Float64(Float64(-log(Float64(cosh(t_0) / sinh(t_0)))) / Float64(pi * 0.25)) end
function tmp = code(f) t_0 = f * (pi * 0.25); tmp = -log((cosh(t_0) / sinh(t_0))) / (pi * 0.25); end
code[f_] := Block[{t$95$0 = N[(f * N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]}, N[((-N[Log[N[(N[Cosh[t$95$0], $MachinePrecision] / N[Sinh[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := f \cdot \left(\pi \cdot 0.25\right)\\
\frac{-\log \left(\frac{\cosh t_0}{\sinh t_0}\right)}{\pi \cdot 0.25}
\end{array}
\end{array}
Initial program 7.0%
Taylor expanded in f around inf 7.0%
exp-prod7.0%
*-commutative7.0%
distribute-lft-neg-in7.0%
metadata-eval7.0%
*-commutative7.0%
Simplified7.0%
associate-*l/7.0%
Applied egg-rr96.6%
Simplified96.6%
Final simplification96.6%
(FPCore (f) :precision binary64 (/ (- (fabs (log (/ (/ 4.0 f) PI)))) (* PI 0.25)))
double code(double f) {
return -fabs(log(((4.0 / f) / ((double) M_PI)))) / (((double) M_PI) * 0.25);
}
public static double code(double f) {
return -Math.abs(Math.log(((4.0 / f) / Math.PI))) / (Math.PI * 0.25);
}
def code(f): return -math.fabs(math.log(((4.0 / f) / math.pi))) / (math.pi * 0.25)
function code(f) return Float64(Float64(-abs(log(Float64(Float64(4.0 / f) / pi)))) / Float64(pi * 0.25)) end
function tmp = code(f) tmp = -abs(log(((4.0 / f) / pi))) / (pi * 0.25); end
code[f_] := N[((-N[Abs[N[Log[N[(N[(4.0 / f), $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]) / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-\left|\log \left(\frac{\frac{4}{f}}{\pi}\right)\right|}{\pi \cdot 0.25}
\end{array}
Initial program 7.0%
Taylor expanded in f around inf 7.0%
exp-prod7.0%
*-commutative7.0%
distribute-lft-neg-in7.0%
metadata-eval7.0%
*-commutative7.0%
Simplified7.0%
associate-*l/7.0%
Applied egg-rr96.6%
Simplified96.6%
Taylor expanded in f around 0 95.7%
associate-/r*95.7%
Simplified95.7%
add-sqr-sqrt95.1%
sqrt-unprod95.8%
pow295.8%
div-inv95.8%
frac-times95.8%
metadata-eval95.8%
Applied egg-rr95.8%
unpow295.8%
rem-sqrt-square95.8%
associate-/r*95.8%
Simplified95.8%
Final simplification95.8%
(FPCore (f) :precision binary64 (/ (* 4.0 (- (log f) (log (/ 4.0 PI)))) PI))
double code(double f) {
return (4.0 * (log(f) - log((4.0 / ((double) M_PI))))) / ((double) M_PI);
}
public static double code(double f) {
return (4.0 * (Math.log(f) - Math.log((4.0 / Math.PI)))) / Math.PI;
}
def code(f): return (4.0 * (math.log(f) - math.log((4.0 / math.pi)))) / math.pi
function code(f) return Float64(Float64(4.0 * Float64(log(f) - log(Float64(4.0 / pi)))) / pi) end
function tmp = code(f) tmp = (4.0 * (log(f) - log((4.0 / pi)))) / pi; end
code[f_] := N[(N[(4.0 * N[(N[Log[f], $MachinePrecision] - N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \left(\log f - \log \left(\frac{4}{\pi}\right)\right)}{\pi}
\end{array}
Initial program 7.0%
Taylor expanded in f around 0 95.5%
associate-/r*95.5%
distribute-rgt-out--95.5%
metadata-eval95.5%
associate-/r*95.5%
Simplified95.5%
Taylor expanded in f around 0 96.1%
associate-*r/96.1%
+-commutative96.1%
metadata-eval96.1%
associate-*l/96.1%
mul-1-neg96.1%
sub-neg96.1%
associate-*l/96.1%
metadata-eval96.1%
Simplified96.1%
Final simplification96.1%
(FPCore (f) :precision binary64 (* (log (/ (/ 4.0 f) PI)) (/ (- 4.0) PI)))
double code(double f) {
return log(((4.0 / f) / ((double) M_PI))) * (-4.0 / ((double) M_PI));
}
public static double code(double f) {
return Math.log(((4.0 / f) / Math.PI)) * (-4.0 / Math.PI);
}
def code(f): return math.log(((4.0 / f) / math.pi)) * (-4.0 / math.pi)
function code(f) return Float64(log(Float64(Float64(4.0 / f) / pi)) * Float64(Float64(-4.0) / pi)) end
function tmp = code(f) tmp = log(((4.0 / f) / pi)) * (-4.0 / pi); end
code[f_] := N[(N[Log[N[(N[(4.0 / f), $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision] * N[((-4.0) / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log \left(\frac{\frac{4}{f}}{\pi}\right) \cdot \frac{-4}{\pi}
\end{array}
Initial program 7.0%
Taylor expanded in f around inf 7.0%
exp-prod7.0%
*-commutative7.0%
distribute-lft-neg-in7.0%
metadata-eval7.0%
*-commutative7.0%
Simplified7.0%
associate-*l/7.0%
Applied egg-rr96.6%
Simplified96.6%
add-exp-log96.6%
Applied egg-rr96.6%
Taylor expanded in f around 0 96.1%
associate-*r/96.1%
mul-1-neg96.1%
log-rec96.1%
log-rec96.1%
mul-1-neg96.1%
+-commutative96.1%
mul-1-neg96.1%
unsub-neg96.1%
metadata-eval96.1%
associate-*r/96.1%
log-div95.7%
associate-*r/95.7%
Simplified95.5%
Final simplification95.5%
(FPCore (f) :precision binary64 (/ (- (log (/ 4.0 (* PI f)))) (* PI 0.25)))
double code(double f) {
return -log((4.0 / (((double) M_PI) * f))) / (((double) M_PI) * 0.25);
}
public static double code(double f) {
return -Math.log((4.0 / (Math.PI * f))) / (Math.PI * 0.25);
}
def code(f): return -math.log((4.0 / (math.pi * f))) / (math.pi * 0.25)
function code(f) return Float64(Float64(-log(Float64(4.0 / Float64(pi * f)))) / Float64(pi * 0.25)) end
function tmp = code(f) tmp = -log((4.0 / (pi * f))) / (pi * 0.25); end
code[f_] := N[((-N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-\log \left(\frac{4}{\pi \cdot f}\right)}{\pi \cdot 0.25}
\end{array}
Initial program 7.0%
Taylor expanded in f around 0 95.5%
associate-/r*95.5%
distribute-rgt-out--95.5%
metadata-eval95.5%
associate-/r*95.5%
Simplified95.5%
Taylor expanded in f around 0 96.1%
Simplified95.7%
Final simplification95.7%
(FPCore (f) :precision binary64 (* (/ (log 7.62939453125e-6) PI) (- 4.0)))
double code(double f) {
return (log(7.62939453125e-6) / ((double) M_PI)) * -4.0;
}
public static double code(double f) {
return (Math.log(7.62939453125e-6) / Math.PI) * -4.0;
}
def code(f): return (math.log(7.62939453125e-6) / math.pi) * -4.0
function code(f) return Float64(Float64(log(7.62939453125e-6) / pi) * Float64(-4.0)) end
function tmp = code(f) tmp = (log(7.62939453125e-6) / pi) * -4.0; end
code[f_] := N[(N[(N[Log[7.62939453125e-6], $MachinePrecision] / Pi), $MachinePrecision] * (-4.0)), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left( 7.62939453125 \cdot 10^{-6} \right)}{\pi} \cdot \left(-4\right)
\end{array}
Initial program 7.0%
Applied egg-rr1.6%
Taylor expanded in f around 0 1.6%
Final simplification1.6%
herbie shell --seed 2023217
(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)))))))))