
(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
(if (<= (* (/ PI 4.0) f) 2e-32)
(* 4.0 (/ (- (log f) (log (/ 4.0 PI))) PI))
(*
(log (sqrt (pow (/ 1.0 (tanh (* f (* PI -0.25)))) 2.0)))
(/ -1.0 (/ PI 4.0)))))
double code(double f) {
double tmp;
if (((((double) M_PI) / 4.0) * f) <= 2e-32) {
tmp = 4.0 * ((log(f) - log((4.0 / ((double) M_PI)))) / ((double) M_PI));
} else {
tmp = log(sqrt(pow((1.0 / tanh((f * (((double) M_PI) * -0.25)))), 2.0))) * (-1.0 / (((double) M_PI) / 4.0));
}
return tmp;
}
public static double code(double f) {
double tmp;
if (((Math.PI / 4.0) * f) <= 2e-32) {
tmp = 4.0 * ((Math.log(f) - Math.log((4.0 / Math.PI))) / Math.PI);
} else {
tmp = Math.log(Math.sqrt(Math.pow((1.0 / Math.tanh((f * (Math.PI * -0.25)))), 2.0))) * (-1.0 / (Math.PI / 4.0));
}
return tmp;
}
def code(f): tmp = 0 if ((math.pi / 4.0) * f) <= 2e-32: tmp = 4.0 * ((math.log(f) - math.log((4.0 / math.pi))) / math.pi) else: tmp = math.log(math.sqrt(math.pow((1.0 / math.tanh((f * (math.pi * -0.25)))), 2.0))) * (-1.0 / (math.pi / 4.0)) return tmp
function code(f) tmp = 0.0 if (Float64(Float64(pi / 4.0) * f) <= 2e-32) tmp = Float64(4.0 * Float64(Float64(log(f) - log(Float64(4.0 / pi))) / pi)); else tmp = Float64(log(sqrt((Float64(1.0 / tanh(Float64(f * Float64(pi * -0.25)))) ^ 2.0))) * Float64(-1.0 / Float64(pi / 4.0))); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (((pi / 4.0) * f) <= 2e-32) tmp = 4.0 * ((log(f) - log((4.0 / pi))) / pi); else tmp = log(sqrt(((1.0 / tanh((f * (pi * -0.25)))) ^ 2.0))) * (-1.0 / (pi / 4.0)); end tmp_2 = tmp; end
code[f_] := If[LessEqual[N[(N[(Pi / 4.0), $MachinePrecision] * f), $MachinePrecision], 2e-32], N[(4.0 * N[(N[(N[Log[f], $MachinePrecision] - N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[Sqrt[N[Power[N[(1.0 / N[Tanh[N[(f * N[(Pi * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * N[(-1.0 / N[(Pi / 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\pi}{4} \cdot f \leq 2 \cdot 10^{-32}:\\
\;\;\;\;4 \cdot \frac{\log f - \log \left(\frac{4}{\pi}\right)}{\pi}\\
\mathbf{else}:\\
\;\;\;\;\log \left(\sqrt{{\left(\frac{1}{\tanh \left(f \cdot \left(\pi \cdot -0.25\right)\right)}\right)}^{2}}\right) \cdot \frac{-1}{\frac{\pi}{4}}\\
\end{array}
\end{array}
if (*.f64 (/.f64 (PI.f64) 4) f) < 2.00000000000000011e-32Initial program 3.1%
Taylor expanded in f around 0 99.3%
associate-/r*99.3%
distribute-rgt-out--99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in f around 0 99.6%
associate-*r/99.6%
neg-mul-199.6%
sub-neg99.6%
associate-*r/99.6%
Simplified99.6%
if 2.00000000000000011e-32 < (*.f64 (/.f64 (PI.f64) 4) f) Initial program 33.0%
Applied egg-rr93.0%
Final simplification98.6%
(FPCore (f) :precision binary64 (/ (- (log (fma f (* PI 0.08333333333333333) (/ 4.0 (* PI f))))) (* PI 0.25)))
double code(double f) {
return -log(fma(f, (((double) M_PI) * 0.08333333333333333), (4.0 / (((double) M_PI) * f)))) / (((double) M_PI) * 0.25);
}
function code(f) return Float64(Float64(-log(fma(f, Float64(pi * 0.08333333333333333), Float64(4.0 / Float64(pi * f))))) / Float64(pi * 0.25)) end
code[f_] := N[((-N[Log[N[(f * N[(Pi * 0.08333333333333333), $MachinePrecision] + N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-\log \left(\mathsf{fma}\left(f, \pi \cdot 0.08333333333333333, \frac{4}{\pi \cdot f}\right)\right)}{\pi \cdot 0.25}
\end{array}
Initial program 7.3%
Taylor expanded in f around 0 96.1%
Simplified96.1%
*-un-lft-identity96.1%
fma-udef96.1%
div-inv96.1%
metadata-eval96.1%
associate-/r/96.1%
unpow-prod-down96.1%
metadata-eval96.1%
Applied egg-rr96.1%
+-commutative96.1%
*-commutative96.1%
fma-def96.1%
associate-*l/96.1%
times-frac96.1%
cube-unmult96.1%
unpow296.1%
associate-/l*96.1%
*-inverses96.1%
/-rgt-identity96.1%
metadata-eval96.1%
*-commutative96.1%
associate-*l*96.1%
metadata-eval96.1%
Simplified96.1%
associate-*l/96.2%
*-un-lft-identity96.2%
div-inv96.2%
metadata-eval96.2%
Applied egg-rr96.2%
Simplified96.2%
Final simplification96.2%
(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 7.3%
Taylor expanded in f around 0 95.2%
associate-/r*95.2%
distribute-rgt-out--95.2%
metadata-eval95.2%
Simplified95.2%
Taylor expanded in f around 0 95.4%
associate-*r/95.4%
neg-mul-195.4%
sub-neg95.4%
associate-*r/95.4%
Simplified95.4%
Final simplification95.4%
(FPCore (f) :precision binary64 (* (/ (log (* PI (* f 0.08333333333333333))) PI) (- 4.0)))
double code(double f) {
return (log((((double) M_PI) * (f * 0.08333333333333333))) / ((double) M_PI)) * -4.0;
}
public static double code(double f) {
return (Math.log((Math.PI * (f * 0.08333333333333333))) / Math.PI) * -4.0;
}
def code(f): return (math.log((math.pi * (f * 0.08333333333333333))) / math.pi) * -4.0
function code(f) return Float64(Float64(log(Float64(pi * Float64(f * 0.08333333333333333))) / pi) * Float64(-4.0)) end
function tmp = code(f) tmp = (log((pi * (f * 0.08333333333333333))) / pi) * -4.0; end
code[f_] := N[(N[(N[Log[N[(Pi * N[(f * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] * (-4.0)), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\pi \cdot \left(f \cdot 0.08333333333333333\right)\right)}{\pi} \cdot \left(-4\right)
\end{array}
Initial program 7.3%
Taylor expanded in f around 0 96.1%
Simplified96.1%
*-un-lft-identity96.1%
fma-udef96.1%
div-inv96.1%
metadata-eval96.1%
associate-/r/96.1%
unpow-prod-down96.1%
metadata-eval96.1%
Applied egg-rr96.1%
+-commutative96.1%
*-commutative96.1%
fma-def96.1%
associate-*l/96.1%
times-frac96.1%
cube-unmult96.1%
unpow296.1%
associate-/l*96.1%
*-inverses96.1%
/-rgt-identity96.1%
metadata-eval96.1%
*-commutative96.1%
associate-*l*96.1%
metadata-eval96.1%
Simplified96.1%
associate-*l/96.2%
*-un-lft-identity96.2%
div-inv96.2%
metadata-eval96.2%
Applied egg-rr96.2%
Simplified96.2%
Taylor expanded in f around inf 1.6%
log-prod1.6%
+-commutative1.6%
mul-1-neg1.6%
log-rec1.6%
remove-double-neg1.6%
log-prod1.6%
log-prod1.6%
associate-*l*1.6%
*-commutative1.6%
Simplified1.6%
Final simplification1.6%
(FPCore (f) :precision binary64 (* (log (/ 4.0 (* PI f))) (/ (- 4.0) PI)))
double code(double f) {
return log((4.0 / (((double) M_PI) * f))) * (-4.0 / ((double) M_PI));
}
public static double code(double f) {
return Math.log((4.0 / (Math.PI * f))) * (-4.0 / Math.PI);
}
def code(f): return math.log((4.0 / (math.pi * f))) * (-4.0 / math.pi)
function code(f) return Float64(log(Float64(4.0 / Float64(pi * f))) * Float64(Float64(-4.0) / pi)) end
function tmp = code(f) tmp = log((4.0 / (pi * f))) * (-4.0 / pi); end
code[f_] := N[(N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[((-4.0) / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log \left(\frac{4}{\pi \cdot f}\right) \cdot \frac{-4}{\pi}
\end{array}
Initial program 7.3%
Taylor expanded in f around 0 95.2%
associate-/r*95.2%
distribute-rgt-out--95.2%
metadata-eval95.2%
Simplified95.2%
Taylor expanded in f around 0 95.4%
associate-*r/95.4%
neg-mul-195.4%
sub-neg95.4%
associate-/l*95.3%
remove-double-neg95.3%
log-rec95.3%
mul-1-neg95.3%
mul-1-neg95.3%
log-rec95.3%
remove-double-neg95.3%
Simplified95.3%
associate-/r/95.2%
div-inv95.2%
frac-times95.2%
metadata-eval95.2%
Applied egg-rr95.2%
Final simplification95.2%
(FPCore (f) :precision binary64 (/ (- 4.0) (/ PI (log (/ (/ 4.0 PI) f)))))
double code(double f) {
return -4.0 / (((double) M_PI) / log(((4.0 / ((double) M_PI)) / f)));
}
public static double code(double f) {
return -4.0 / (Math.PI / Math.log(((4.0 / Math.PI) / f)));
}
def code(f): return -4.0 / (math.pi / math.log(((4.0 / math.pi) / f)))
function code(f) return Float64(Float64(-4.0) / Float64(pi / log(Float64(Float64(4.0 / pi) / f)))) end
function tmp = code(f) tmp = -4.0 / (pi / log(((4.0 / pi) / f))); end
code[f_] := N[((-4.0) / N[(Pi / N[Log[N[(N[(4.0 / Pi), $MachinePrecision] / f), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-4}{\frac{\pi}{\log \left(\frac{\frac{4}{\pi}}{f}\right)}}
\end{array}
Initial program 7.3%
Taylor expanded in f around 0 95.2%
associate-/r*95.2%
distribute-rgt-out--95.2%
metadata-eval95.2%
Simplified95.2%
Taylor expanded in f around 0 95.4%
associate-*r/95.4%
neg-mul-195.4%
sub-neg95.4%
associate-/l*95.3%
remove-double-neg95.3%
log-rec95.3%
mul-1-neg95.3%
mul-1-neg95.3%
log-rec95.3%
remove-double-neg95.3%
Simplified95.3%
Final simplification95.3%
(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.3%
Taylor expanded in f around 0 95.2%
associate-/r*95.2%
distribute-rgt-out--95.2%
metadata-eval95.2%
Simplified95.2%
Taylor expanded in f around 0 95.4%
associate-*r/95.4%
neg-mul-195.4%
sub-neg95.4%
associate-/l*95.3%
remove-double-neg95.3%
log-rec95.3%
mul-1-neg95.3%
mul-1-neg95.3%
log-rec95.3%
remove-double-neg95.3%
Simplified95.3%
Taylor expanded in f around 0 95.4%
*-commutative95.4%
mul-1-neg95.4%
log-rec95.4%
log-prod95.4%
metadata-eval95.4%
associate-/r*95.4%
*-commutative95.4%
associate-*l/95.4%
associate-*r/95.4%
metadata-eval95.4%
associate-/r*95.4%
metadata-eval95.4%
times-frac95.4%
Simplified95.4%
Final simplification95.4%
herbie shell --seed 2023292
(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)))))))))