
(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 6 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 (* 4.0 (/ (log (tanh (* (* PI 0.25) f))) PI)))
double code(double f) {
return 4.0 * (log(tanh(((((double) M_PI) * 0.25) * f))) / ((double) M_PI));
}
public static double code(double f) {
return 4.0 * (Math.log(Math.tanh(((Math.PI * 0.25) * f))) / Math.PI);
}
def code(f): return 4.0 * (math.log(math.tanh(((math.pi * 0.25) * f))) / math.pi)
function code(f) return Float64(4.0 * Float64(log(tanh(Float64(Float64(pi * 0.25) * f))) / pi)) end
function tmp = code(f) tmp = 4.0 * (log(tanh(((pi * 0.25) * f))) / pi); end
code[f_] := N[(4.0 * N[(N[Log[N[Tanh[N[(N[(Pi * 0.25), $MachinePrecision] * f), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{\log \tanh \left(\left(\pi \cdot 0.25\right) \cdot f\right)}{\pi}
\end{array}
Initial program 5.4%
Taylor expanded in f around inf 5.4%
expm1-log1p-u5.5%
expm1-udef5.4%
Applied egg-rr98.0%
expm1-def97.9%
expm1-log1p99.2%
associate-*r*99.2%
*-commutative99.2%
Simplified99.2%
Final simplification99.2%
(FPCore (f) :precision binary64 (if (<= f 1.52) (/ (* (log (/ (/ 4.0 f) PI)) (- 4.0)) PI) (* (/ (log (tanh (/ PI (/ 4.0 f)))) PI) (- 4.0))))
double code(double f) {
double tmp;
if (f <= 1.52) {
tmp = (log(((4.0 / f) / ((double) M_PI))) * -4.0) / ((double) M_PI);
} else {
tmp = (log(tanh((((double) M_PI) / (4.0 / f)))) / ((double) M_PI)) * -4.0;
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.52) {
tmp = (Math.log(((4.0 / f) / Math.PI)) * -4.0) / Math.PI;
} else {
tmp = (Math.log(Math.tanh((Math.PI / (4.0 / f)))) / Math.PI) * -4.0;
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.52: tmp = (math.log(((4.0 / f) / math.pi)) * -4.0) / math.pi else: tmp = (math.log(math.tanh((math.pi / (4.0 / f)))) / math.pi) * -4.0 return tmp
function code(f) tmp = 0.0 if (f <= 1.52) tmp = Float64(Float64(log(Float64(Float64(4.0 / f) / pi)) * Float64(-4.0)) / pi); else tmp = Float64(Float64(log(tanh(Float64(pi / Float64(4.0 / f)))) / pi) * Float64(-4.0)); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.52) tmp = (log(((4.0 / f) / pi)) * -4.0) / pi; else tmp = (log(tanh((pi / (4.0 / f)))) / pi) * -4.0; end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.52], N[(N[(N[Log[N[(N[(4.0 / f), $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision] * (-4.0)), $MachinePrecision] / Pi), $MachinePrecision], N[(N[(N[Log[N[Tanh[N[(Pi / N[(4.0 / f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] * (-4.0)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.52:\\
\;\;\;\;\frac{\log \left(\frac{\frac{4}{f}}{\pi}\right) \cdot \left(-4\right)}{\pi}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \tanh \left(\frac{\pi}{\frac{4}{f}}\right)}{\pi} \cdot \left(-4\right)\\
\end{array}
\end{array}
if f < 1.52Initial program 5.6%
Taylor expanded in f around 0 99.3%
associate-*r/99.3%
mul-1-neg99.3%
unsub-neg99.3%
distribute-rgt-out--99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in f around 0 99.3%
log-div99.2%
associate-/r*99.2%
*-commutative99.2%
associate-/r*99.2%
Simplified99.2%
if 1.52 < f Initial program 0.5%
Taylor expanded in f around inf 0.5%
expm1-log1p-u0.5%
expm1-udef0.5%
Applied egg-rr86.2%
expm1-def86.2%
expm1-log1p86.2%
associate-*r*86.2%
*-commutative86.2%
Simplified86.2%
expm1-log1p-u86.2%
expm1-udef86.2%
Applied egg-rr86.2%
expm1-def86.2%
expm1-log1p86.2%
associate-*r*86.2%
*-commutative86.2%
metadata-eval86.2%
associate-/r/86.2%
*-commutative86.2%
associate-/r*86.2%
associate-/l*86.2%
*-lft-identity86.2%
Simplified86.2%
Final simplification98.9%
(FPCore (f) :precision binary64 (if (<= f 1.52) (* (/ 4.0 PI) (- (log f) (log (/ 4.0 PI)))) (* (/ (log (tanh (/ PI (/ 4.0 f)))) PI) (- 4.0))))
double code(double f) {
double tmp;
if (f <= 1.52) {
tmp = (4.0 / ((double) M_PI)) * (log(f) - log((4.0 / ((double) M_PI))));
} else {
tmp = (log(tanh((((double) M_PI) / (4.0 / f)))) / ((double) M_PI)) * -4.0;
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.52) {
tmp = (4.0 / Math.PI) * (Math.log(f) - Math.log((4.0 / Math.PI)));
} else {
tmp = (Math.log(Math.tanh((Math.PI / (4.0 / f)))) / Math.PI) * -4.0;
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.52: tmp = (4.0 / math.pi) * (math.log(f) - math.log((4.0 / math.pi))) else: tmp = (math.log(math.tanh((math.pi / (4.0 / f)))) / math.pi) * -4.0 return tmp
function code(f) tmp = 0.0 if (f <= 1.52) tmp = Float64(Float64(4.0 / pi) * Float64(log(f) - log(Float64(4.0 / pi)))); else tmp = Float64(Float64(log(tanh(Float64(pi / Float64(4.0 / f)))) / pi) * Float64(-4.0)); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.52) tmp = (4.0 / pi) * (log(f) - log((4.0 / pi))); else tmp = (log(tanh((pi / (4.0 / f)))) / pi) * -4.0; end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.52], N[(N[(4.0 / Pi), $MachinePrecision] * N[(N[Log[f], $MachinePrecision] - N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Log[N[Tanh[N[(Pi / N[(4.0 / f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] * (-4.0)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.52:\\
\;\;\;\;\frac{4}{\pi} \cdot \left(\log f - \log \left(\frac{4}{\pi}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \tanh \left(\frac{\pi}{\frac{4}{f}}\right)}{\pi} \cdot \left(-4\right)\\
\end{array}
\end{array}
if f < 1.52Initial program 5.6%
Taylor expanded in f around 0 99.3%
associate-*r/99.3%
associate-/l*99.1%
associate-/r/99.2%
mul-1-neg99.2%
unsub-neg99.2%
distribute-rgt-out--99.2%
*-commutative99.2%
associate-/r*99.2%
metadata-eval99.2%
metadata-eval99.2%
Simplified99.2%
if 1.52 < f Initial program 0.5%
Taylor expanded in f around inf 0.5%
expm1-log1p-u0.5%
expm1-udef0.5%
Applied egg-rr86.2%
expm1-def86.2%
expm1-log1p86.2%
associate-*r*86.2%
*-commutative86.2%
Simplified86.2%
expm1-log1p-u86.2%
expm1-udef86.2%
Applied egg-rr86.2%
expm1-def86.2%
expm1-log1p86.2%
associate-*r*86.2%
*-commutative86.2%
metadata-eval86.2%
associate-/r/86.2%
*-commutative86.2%
associate-/r*86.2%
associate-/l*86.2%
*-lft-identity86.2%
Simplified86.2%
Final simplification98.9%
(FPCore (f) :precision binary64 (* (/ (log (* (* PI 0.25) f)) PI) (- 4.0)))
double code(double f) {
return (log(((((double) M_PI) * 0.25) * f)) / ((double) M_PI)) * -4.0;
}
public static double code(double f) {
return (Math.log(((Math.PI * 0.25) * f)) / Math.PI) * -4.0;
}
def code(f): return (math.log(((math.pi * 0.25) * f)) / math.pi) * -4.0
function code(f) return Float64(Float64(log(Float64(Float64(pi * 0.25) * f)) / pi) * Float64(-4.0)) end
function tmp = code(f) tmp = (log(((pi * 0.25) * f)) / pi) * -4.0; end
code[f_] := N[(N[(N[Log[N[(N[(Pi * 0.25), $MachinePrecision] * f), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] * (-4.0)), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\left(\pi \cdot 0.25\right) \cdot f\right)}{\pi} \cdot \left(-4\right)
\end{array}
Initial program 5.4%
Taylor expanded in f around inf 5.4%
expm1-log1p-u5.5%
expm1-udef5.4%
Applied egg-rr98.0%
expm1-def97.9%
expm1-log1p99.2%
associate-*r*99.2%
*-commutative99.2%
Simplified99.2%
expm1-log1p-u97.9%
expm1-udef98.0%
Applied egg-rr2.4%
expm1-def2.4%
expm1-log1p3.9%
associate-*r*3.9%
*-commutative3.9%
metadata-eval3.9%
associate-/r/3.9%
*-commutative3.9%
associate-/r*3.9%
associate-/l*3.9%
*-lft-identity3.9%
Simplified3.9%
Taylor expanded in f around 0 1.6%
*-commutative1.6%
log-prod1.6%
*-commutative1.6%
Simplified1.6%
Final simplification1.6%
(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 5.4%
Taylor expanded in f around 0 96.7%
associate-*r/96.7%
mul-1-neg96.7%
unsub-neg96.7%
distribute-rgt-out--96.7%
metadata-eval96.7%
Simplified96.7%
Taylor expanded in f around 0 96.7%
Simplified96.4%
Final simplification96.4%
(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(Float64(log(Float64(Float64(4.0 / f) / pi)) * Float64(-4.0)) / pi) end
function tmp = code(f) tmp = (log(((4.0 / f) / pi)) * -4.0) / pi; end
code[f_] := N[(N[(N[Log[N[(N[(4.0 / f), $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision] * (-4.0)), $MachinePrecision] / Pi), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\frac{\frac{4}{f}}{\pi}\right) \cdot \left(-4\right)}{\pi}
\end{array}
Initial program 5.4%
Taylor expanded in f around 0 96.7%
associate-*r/96.7%
mul-1-neg96.7%
unsub-neg96.7%
distribute-rgt-out--96.7%
metadata-eval96.7%
Simplified96.7%
Taylor expanded in f around 0 96.7%
log-div96.6%
associate-/r*96.6%
*-commutative96.6%
associate-/r*96.6%
Simplified96.6%
Final simplification96.6%
herbie shell --seed 2024031
(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)))))))))