
(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 5 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 (let* ((t_0 (* (* PI 0.25) f))) (* 4.0 (/ (log (/ (sinh t_0) (cosh t_0))) PI))))
double code(double f) {
double t_0 = (((double) M_PI) * 0.25) * f;
return 4.0 * (log((sinh(t_0) / cosh(t_0))) / ((double) M_PI));
}
public static double code(double f) {
double t_0 = (Math.PI * 0.25) * f;
return 4.0 * (Math.log((Math.sinh(t_0) / Math.cosh(t_0))) / Math.PI);
}
def code(f): t_0 = (math.pi * 0.25) * f return 4.0 * (math.log((math.sinh(t_0) / math.cosh(t_0))) / math.pi)
function code(f) t_0 = Float64(Float64(pi * 0.25) * f) return Float64(4.0 * Float64(log(Float64(sinh(t_0) / cosh(t_0))) / pi)) end
function tmp = code(f) t_0 = (pi * 0.25) * f; tmp = 4.0 * (log((sinh(t_0) / cosh(t_0))) / pi); end
code[f_] := Block[{t$95$0 = N[(N[(Pi * 0.25), $MachinePrecision] * f), $MachinePrecision]}, N[(4.0 * N[(N[Log[N[(N[Sinh[t$95$0], $MachinePrecision] / N[Cosh[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\pi \cdot 0.25\right) \cdot f\\
4 \cdot \frac{\log \left(\frac{\sinh t_0}{\cosh t_0}\right)}{\pi}
\end{array}
\end{array}
Initial program 5.6%
expm1-log1p-u5.6%
expm1-udef5.6%
Applied egg-rr97.4%
expm1-def97.3%
expm1-log1p98.6%
*-lft-identity98.6%
*-commutative98.6%
times-frac98.6%
metadata-eval98.6%
Simplified98.6%
clear-num98.6%
log-rec98.6%
div-inv98.6%
metadata-eval98.6%
div-inv98.6%
metadata-eval98.6%
Applied egg-rr98.6%
Final simplification98.6%
(FPCore (f) :precision binary64 (let* ((t_0 (* f (/ PI 4.0)))) (* 4.0 (/ (- (log (/ (cosh t_0) (sinh t_0)))) PI))))
double code(double f) {
double t_0 = f * (((double) M_PI) / 4.0);
return 4.0 * (-log((cosh(t_0) / sinh(t_0))) / ((double) M_PI));
}
public static double code(double f) {
double t_0 = f * (Math.PI / 4.0);
return 4.0 * (-Math.log((Math.cosh(t_0) / Math.sinh(t_0))) / Math.PI);
}
def code(f): t_0 = f * (math.pi / 4.0) return 4.0 * (-math.log((math.cosh(t_0) / math.sinh(t_0))) / math.pi)
function code(f) t_0 = Float64(f * Float64(pi / 4.0)) return Float64(4.0 * Float64(Float64(-log(Float64(cosh(t_0) / sinh(t_0)))) / pi)) end
function tmp = code(f) t_0 = f * (pi / 4.0); tmp = 4.0 * (-log((cosh(t_0) / sinh(t_0))) / pi); end
code[f_] := Block[{t$95$0 = N[(f * N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision]}, N[(4.0 * N[((-N[Log[N[(N[Cosh[t$95$0], $MachinePrecision] / N[Sinh[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / Pi), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := f \cdot \frac{\pi}{4}\\
4 \cdot \frac{-\log \left(\frac{\cosh t_0}{\sinh t_0}\right)}{\pi}
\end{array}
\end{array}
Initial program 5.6%
expm1-log1p-u5.6%
expm1-udef5.6%
Applied egg-rr97.4%
expm1-def97.3%
expm1-log1p98.6%
*-lft-identity98.6%
*-commutative98.6%
times-frac98.6%
metadata-eval98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (f) :precision binary64 (- (fabs (* 4.0 (/ (log (/ 2.0 (* PI (* f 0.5)))) PI)))))
double code(double f) {
return -fabs((4.0 * (log((2.0 / (((double) M_PI) * (f * 0.5)))) / ((double) M_PI))));
}
public static double code(double f) {
return -Math.abs((4.0 * (Math.log((2.0 / (Math.PI * (f * 0.5)))) / Math.PI)));
}
def code(f): return -math.fabs((4.0 * (math.log((2.0 / (math.pi * (f * 0.5)))) / math.pi)))
function code(f) return Float64(-abs(Float64(4.0 * Float64(log(Float64(2.0 / Float64(pi * Float64(f * 0.5)))) / pi)))) end
function tmp = code(f) tmp = -abs((4.0 * (log((2.0 / (pi * (f * 0.5)))) / pi))); end
code[f_] := (-N[Abs[N[(4.0 * N[(N[Log[N[(2.0 / N[(Pi * N[(f * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])
\begin{array}{l}
\\
-\left|4 \cdot \frac{\log \left(\frac{2}{\pi \cdot \left(f \cdot 0.5\right)}\right)}{\pi}\right|
\end{array}
Initial program 5.6%
Taylor expanded in f around 0 97.6%
distribute-rgt-out--97.6%
metadata-eval97.6%
Simplified97.6%
add-sqr-sqrt97.2%
sqrt-unprod97.7%
pow297.7%
associate-*l/97.8%
div-inv97.8%
metadata-eval97.8%
*-commutative97.8%
times-frac97.8%
metadata-eval97.8%
associate-/r*97.8%
Applied egg-rr97.8%
unpow297.8%
rem-sqrt-square97.8%
log-div97.8%
log-div97.8%
*-commutative97.8%
associate--r+97.8%
Simplified97.8%
Final simplification97.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(4.0 * Float64(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[(4.0 * N[(N[(N[Log[f], $MachinePrecision] - N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{\log f - \log \left(\frac{4}{\pi}\right)}{\pi}
\end{array}
Initial program 5.6%
expm1-log1p-u5.6%
expm1-udef5.6%
Applied egg-rr97.4%
expm1-def97.3%
expm1-log1p98.6%
*-lft-identity98.6%
*-commutative98.6%
times-frac98.6%
metadata-eval98.6%
Simplified98.6%
Taylor expanded in f around 0 97.7%
mul-1-neg97.7%
unsub-neg97.7%
Simplified97.7%
Final simplification97.7%
(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}
Initial program 5.6%
expm1-log1p-u5.6%
expm1-udef5.6%
Applied egg-rr97.4%
expm1-def97.3%
expm1-log1p98.6%
*-lft-identity98.6%
*-commutative98.6%
times-frac98.6%
metadata-eval98.6%
Simplified98.6%
Taylor expanded in f around 0 97.7%
*-commutative97.7%
Simplified97.7%
Final simplification97.7%
herbie shell --seed 2023187
(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)))))))))