
(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 7 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
(*
(/
(+
(* f (* f (* PI (* 0.5 (* (* PI 0.5) 0.08333333333333333)))))
(log (/ (/ 4.0 f) PI)))
PI)
(- 4.0)))
double code(double f) {
return (((f * (f * (((double) M_PI) * (0.5 * ((((double) M_PI) * 0.5) * 0.08333333333333333))))) + log(((4.0 / f) / ((double) M_PI)))) / ((double) M_PI)) * -4.0;
}
public static double code(double f) {
return (((f * (f * (Math.PI * (0.5 * ((Math.PI * 0.5) * 0.08333333333333333))))) + Math.log(((4.0 / f) / Math.PI))) / Math.PI) * -4.0;
}
def code(f): return (((f * (f * (math.pi * (0.5 * ((math.pi * 0.5) * 0.08333333333333333))))) + math.log(((4.0 / f) / math.pi))) / math.pi) * -4.0
function code(f) return Float64(Float64(Float64(Float64(f * Float64(f * Float64(pi * Float64(0.5 * Float64(Float64(pi * 0.5) * 0.08333333333333333))))) + log(Float64(Float64(4.0 / f) / pi))) / pi) * Float64(-4.0)) end
function tmp = code(f) tmp = (((f * (f * (pi * (0.5 * ((pi * 0.5) * 0.08333333333333333))))) + log(((4.0 / f) / pi))) / pi) * -4.0; end
code[f_] := N[(N[(N[(N[(f * N[(f * N[(Pi * N[(0.5 * N[(N[(Pi * 0.5), $MachinePrecision] * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Log[N[(N[(4.0 / f), $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision] * (-4.0)), $MachinePrecision]
\begin{array}{l}
\\
\frac{f \cdot \left(f \cdot \left(\pi \cdot \left(0.5 \cdot \left(\left(\pi \cdot 0.5\right) \cdot 0.08333333333333333\right)\right)\right)\right) + \log \left(\frac{\frac{4}{f}}{\pi}\right)}{\pi} \cdot \left(-4\right)
\end{array}
Initial program 7.2%
Taylor expanded in f around 0 96.5%
Simplified96.5%
*-un-lft-identity96.5%
fma-udef96.5%
div-inv96.5%
metadata-eval96.5%
associate-*l/96.5%
div-inv96.5%
metadata-eval96.5%
Applied egg-rr96.5%
expm1-log1p-u96.5%
expm1-udef96.5%
fma-def96.5%
times-frac96.5%
metadata-eval96.5%
Applied egg-rr96.5%
expm1-def96.5%
expm1-log1p96.5%
fma-udef96.5%
+-commutative96.5%
fma-udef96.5%
unpow396.5%
unpow296.5%
*-commutative96.5%
times-frac96.5%
*-inverses96.5%
*-commutative96.5%
associate-*l*96.5%
metadata-eval96.5%
Simplified96.5%
clear-num96.5%
distribute-lft-in96.3%
associate-/r*96.3%
Applied egg-rr96.3%
Simplified96.5%
Final simplification96.5%
(FPCore (f) :precision binary64 (- (fma 4.0 (/ (log (/ (/ 4.0 f) PI)) PI) (* PI (* 0.08333333333333333 (* f f))))))
double code(double f) {
return -fma(4.0, (log(((4.0 / f) / ((double) M_PI))) / ((double) M_PI)), (((double) M_PI) * (0.08333333333333333 * (f * f))));
}
function code(f) return Float64(-fma(4.0, Float64(log(Float64(Float64(4.0 / f) / pi)) / pi), Float64(pi * Float64(0.08333333333333333 * Float64(f * f))))) end
code[f_] := (-N[(4.0 * N[(N[Log[N[(N[(4.0 / f), $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] + N[(Pi * N[(0.08333333333333333 * N[(f * f), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision])
\begin{array}{l}
\\
-\mathsf{fma}\left(4, \frac{\log \left(\frac{\frac{4}{f}}{\pi}\right)}{\pi}, \pi \cdot \left(0.08333333333333333 \cdot \left(f \cdot f\right)\right)\right)
\end{array}
Initial program 7.2%
Taylor expanded in f around 0 96.5%
Simplified96.5%
*-un-lft-identity96.5%
fma-udef96.5%
div-inv96.5%
metadata-eval96.5%
associate-*l/96.5%
div-inv96.5%
metadata-eval96.5%
Applied egg-rr96.5%
expm1-log1p-u96.5%
expm1-udef96.5%
fma-def96.5%
times-frac96.5%
metadata-eval96.5%
Applied egg-rr96.5%
expm1-def96.5%
expm1-log1p96.5%
fma-udef96.5%
+-commutative96.5%
fma-udef96.5%
unpow396.5%
unpow296.5%
*-commutative96.5%
times-frac96.5%
*-inverses96.5%
*-commutative96.5%
associate-*l*96.5%
metadata-eval96.5%
Simplified96.5%
Taylor expanded in f around 0 96.5%
fma-def96.5%
log-div96.5%
associate-/r*96.5%
associate-/l/96.5%
unpow296.5%
*-commutative96.5%
distribute-rgt-out96.5%
associate-*l*96.5%
metadata-eval96.5%
Simplified96.5%
Final simplification96.5%
(FPCore (f) :precision binary64 (* -4.0 (/ (+ (log (/ 1.0 f)) (log (/ 4.0 PI))) PI)))
double code(double f) {
return -4.0 * ((log((1.0 / f)) + log((4.0 / ((double) M_PI)))) / ((double) M_PI));
}
public static double code(double f) {
return -4.0 * ((Math.log((1.0 / f)) + Math.log((4.0 / Math.PI))) / Math.PI);
}
def code(f): return -4.0 * ((math.log((1.0 / f)) + math.log((4.0 / math.pi))) / math.pi)
function code(f) return Float64(-4.0 * Float64(Float64(log(Float64(1.0 / f)) + log(Float64(4.0 / pi))) / pi)) end
function tmp = code(f) tmp = -4.0 * ((log((1.0 / f)) + log((4.0 / pi))) / pi); end
code[f_] := N[(-4.0 * N[(N[(N[Log[N[(1.0 / f), $MachinePrecision]], $MachinePrecision] + N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \frac{\log \left(\frac{1}{f}\right) + \log \left(\frac{4}{\pi}\right)}{\pi}
\end{array}
Initial program 7.2%
*-commutative7.2%
distribute-rgt-neg-in7.2%
Simplified7.2%
Taylor expanded in f around 0 95.9%
*-commutative95.9%
associate-*l/95.9%
mul-1-neg95.9%
unsub-neg95.9%
distribute-rgt-out--95.9%
metadata-eval95.9%
Simplified95.9%
Taylor expanded in f around 0 95.9%
div-sub95.8%
metadata-eval95.8%
associate-/r*95.8%
*-commutative95.8%
div-sub95.9%
log-div95.9%
*-commutative95.9%
associate-/r*95.9%
metadata-eval95.9%
associate-/r*95.9%
Simplified95.9%
Taylor expanded in f around inf 95.9%
Final simplification95.9%
(FPCore (f) :precision binary64 (/ (* -4.0 (- (log (/ 4.0 PI)) (log f))) PI))
double code(double f) {
return (-4.0 * (log((4.0 / ((double) M_PI))) - log(f))) / ((double) M_PI);
}
public static double code(double f) {
return (-4.0 * (Math.log((4.0 / Math.PI)) - Math.log(f))) / Math.PI;
}
def code(f): return (-4.0 * (math.log((4.0 / math.pi)) - math.log(f))) / math.pi
function code(f) return Float64(Float64(-4.0 * Float64(log(Float64(4.0 / pi)) - log(f))) / pi) end
function tmp = code(f) tmp = (-4.0 * (log((4.0 / pi)) - log(f))) / pi; end
code[f_] := N[(N[(-4.0 * N[(N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision] - N[Log[f], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]
\begin{array}{l}
\\
\frac{-4 \cdot \left(\log \left(\frac{4}{\pi}\right) - \log f\right)}{\pi}
\end{array}
Initial program 7.2%
*-commutative7.2%
distribute-rgt-neg-in7.2%
Simplified7.2%
Taylor expanded in f around 0 95.9%
*-commutative95.9%
associate-*l/95.9%
mul-1-neg95.9%
unsub-neg95.9%
distribute-rgt-out--95.9%
metadata-eval95.9%
Simplified95.9%
log-div95.9%
Applied egg-rr95.9%
log-div95.9%
*-commutative95.9%
associate-/r*95.9%
metadata-eval95.9%
Simplified95.9%
Final simplification95.9%
(FPCore (f) :precision binary64 (* -4.0 (/ (log (/ 4.0 (* f PI))) PI)))
double code(double f) {
return -4.0 * (log((4.0 / (f * ((double) M_PI)))) / ((double) M_PI));
}
public static double code(double f) {
return -4.0 * (Math.log((4.0 / (f * Math.PI))) / Math.PI);
}
def code(f): return -4.0 * (math.log((4.0 / (f * math.pi))) / math.pi)
function code(f) return Float64(-4.0 * Float64(log(Float64(4.0 / Float64(f * pi))) / pi)) end
function tmp = code(f) tmp = -4.0 * (log((4.0 / (f * pi))) / pi); end
code[f_] := N[(-4.0 * N[(N[Log[N[(4.0 / N[(f * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \frac{\log \left(\frac{4}{f \cdot \pi}\right)}{\pi}
\end{array}
Initial program 7.2%
*-commutative7.2%
distribute-rgt-neg-in7.2%
Simplified7.2%
Taylor expanded in f around 0 95.9%
*-commutative95.9%
associate-*l/95.9%
mul-1-neg95.9%
unsub-neg95.9%
distribute-rgt-out--95.9%
metadata-eval95.9%
Simplified95.9%
Taylor expanded in f around 0 95.9%
div-sub95.8%
metadata-eval95.8%
associate-/r*95.8%
*-commutative95.8%
div-sub95.9%
log-div95.9%
*-commutative95.9%
associate-/r*95.9%
metadata-eval95.9%
associate-/r*95.9%
Simplified95.9%
Final simplification95.9%
(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(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}
Initial program 7.2%
*-commutative7.2%
distribute-rgt-neg-in7.2%
Simplified7.2%
Taylor expanded in f around 0 95.9%
*-commutative95.9%
associate-*l/95.9%
mul-1-neg95.9%
unsub-neg95.9%
distribute-rgt-out--95.9%
metadata-eval95.9%
Simplified95.9%
Taylor expanded in f around 0 95.9%
div-sub95.8%
metadata-eval95.8%
associate-/r*95.8%
*-commutative95.8%
div-sub95.9%
log-div95.9%
*-commutative95.9%
associate-/r*95.9%
metadata-eval95.9%
associate-/r*95.9%
Simplified95.9%
Taylor expanded in f around 0 95.9%
mul-1-neg95.9%
unsub-neg95.9%
log-div95.9%
associate--r+95.7%
log-prod95.8%
log-div95.9%
rem-log-exp95.9%
*-rgt-identity95.9%
associate-*r/95.7%
exp-to-pow95.7%
metadata-eval95.7%
associate-/r*95.7%
*-commutative95.7%
associate-*r*95.7%
Simplified95.9%
Final simplification95.9%
(FPCore (f) :precision binary64 (* f (* f (* PI (- 0.08333333333333333)))))
double code(double f) {
return f * (f * (((double) M_PI) * -0.08333333333333333));
}
public static double code(double f) {
return f * (f * (Math.PI * -0.08333333333333333));
}
def code(f): return f * (f * (math.pi * -0.08333333333333333))
function code(f) return Float64(f * Float64(f * Float64(pi * Float64(-0.08333333333333333)))) end
function tmp = code(f) tmp = f * (f * (pi * -0.08333333333333333)); end
code[f_] := N[(f * N[(f * N[(Pi * (-0.08333333333333333)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
f \cdot \left(f \cdot \left(\pi \cdot \left(-0.08333333333333333\right)\right)\right)
\end{array}
Initial program 7.2%
Taylor expanded in f around 0 96.5%
Simplified96.5%
*-un-lft-identity96.5%
fma-udef96.5%
div-inv96.5%
metadata-eval96.5%
associate-*l/96.5%
div-inv96.5%
metadata-eval96.5%
Applied egg-rr96.5%
expm1-log1p-u96.5%
expm1-udef96.5%
fma-def96.5%
times-frac96.5%
metadata-eval96.5%
Applied egg-rr96.5%
expm1-def96.5%
expm1-log1p96.5%
fma-udef96.5%
+-commutative96.5%
fma-udef96.5%
unpow396.5%
unpow296.5%
*-commutative96.5%
times-frac96.5%
*-inverses96.5%
*-commutative96.5%
associate-*l*96.5%
metadata-eval96.5%
Simplified96.5%
Taylor expanded in f around inf 4.3%
unpow24.3%
*-commutative4.3%
metadata-eval4.3%
associate-*l*4.3%
fma-def4.3%
*-commutative4.3%
associate-*l*4.3%
fma-def4.3%
associate-*l*4.3%
metadata-eval4.3%
distribute-lft-out4.3%
metadata-eval4.3%
Simplified4.3%
Final simplification4.3%
herbie shell --seed 2023287
(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)))))))))