
(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 (/ (* 2.0 (log (sqrt (tanh (* 0.25 (* f PI)))))) (- PI))))
double code(double f) {
return -4.0 * ((2.0 * log(sqrt(tanh((0.25 * (f * ((double) M_PI))))))) / -((double) M_PI));
}
public static double code(double f) {
return -4.0 * ((2.0 * Math.log(Math.sqrt(Math.tanh((0.25 * (f * Math.PI)))))) / -Math.PI);
}
def code(f): return -4.0 * ((2.0 * math.log(math.sqrt(math.tanh((0.25 * (f * math.pi)))))) / -math.pi)
function code(f) return Float64(-4.0 * Float64(Float64(2.0 * log(sqrt(tanh(Float64(0.25 * Float64(f * pi)))))) / Float64(-pi))) end
function tmp = code(f) tmp = -4.0 * ((2.0 * log(sqrt(tanh((0.25 * (f * pi)))))) / -pi); end
code[f_] := N[(-4.0 * N[(N[(2.0 * N[Log[N[Sqrt[N[Tanh[N[(0.25 * N[(f * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / (-Pi)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \frac{2 \cdot \log \left(\sqrt{\tanh \left(0.25 \cdot \left(f \cdot \pi\right)\right)}\right)}{-\pi}
\end{array}
Initial program 6.5%
associate-*l/6.5%
Applied egg-rr99.4%
neg-mul-199.4%
*-commutative99.4%
times-frac99.4%
metadata-eval99.4%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
Applied egg-rr99.4%
count-299.4%
Simplified99.4%
Final simplification99.4%
(FPCore (f) :precision binary64 (if (<= f 1.25) (/ (* -4.0 (- (log (/ 4.0 PI)) (log f))) PI) (* -4.0 (/ 0.0 PI))))
double code(double f) {
double tmp;
if (f <= 1.25) {
tmp = (-4.0 * (log((4.0 / ((double) M_PI))) - log(f))) / ((double) M_PI);
} else {
tmp = -4.0 * (0.0 / ((double) M_PI));
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.25) {
tmp = (-4.0 * (Math.log((4.0 / Math.PI)) - Math.log(f))) / Math.PI;
} else {
tmp = -4.0 * (0.0 / Math.PI);
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.25: tmp = (-4.0 * (math.log((4.0 / math.pi)) - math.log(f))) / math.pi else: tmp = -4.0 * (0.0 / math.pi) return tmp
function code(f) tmp = 0.0 if (f <= 1.25) tmp = Float64(Float64(-4.0 * Float64(log(Float64(4.0 / pi)) - log(f))) / pi); else tmp = Float64(-4.0 * Float64(0.0 / pi)); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.25) tmp = (-4.0 * (log((4.0 / pi)) - log(f))) / pi; else tmp = -4.0 * (0.0 / pi); end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.25], N[(N[(-4.0 * N[(N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision] - N[Log[f], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision], N[(-4.0 * N[(0.0 / Pi), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.25:\\
\;\;\;\;\frac{-4 \cdot \left(\log \left(\frac{4}{\pi}\right) - \log f\right)}{\pi}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{0}{\pi}\\
\end{array}
\end{array}
if f < 1.25Initial program 6.2%
Simplified99.4%
Taylor expanded in f around 0 98.4%
associate-*r/98.4%
mul-1-neg98.4%
unsub-neg98.4%
Simplified98.4%
if 1.25 < f Initial program 16.7%
associate-*l/16.7%
Applied egg-rr95.0%
neg-mul-195.0%
*-commutative95.0%
times-frac95.0%
metadata-eval95.0%
*-commutative95.0%
*-commutative95.0%
Simplified95.0%
Applied egg-rr78.5%
*-inverses78.5%
Simplified78.5%
Final simplification97.7%
(FPCore (f) :precision binary64 (* -4.0 (/ (log (tanh (* f (* 0.25 PI)))) (- PI))))
double code(double f) {
return -4.0 * (log(tanh((f * (0.25 * ((double) M_PI))))) / -((double) M_PI));
}
public static double code(double f) {
return -4.0 * (Math.log(Math.tanh((f * (0.25 * Math.PI)))) / -Math.PI);
}
def code(f): return -4.0 * (math.log(math.tanh((f * (0.25 * math.pi)))) / -math.pi)
function code(f) return Float64(-4.0 * Float64(log(tanh(Float64(f * Float64(0.25 * pi)))) / Float64(-pi))) end
function tmp = code(f) tmp = -4.0 * (log(tanh((f * (0.25 * pi)))) / -pi); end
code[f_] := N[(-4.0 * N[(N[Log[N[Tanh[N[(f * N[(0.25 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / (-Pi)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \frac{\log \tanh \left(f \cdot \left(0.25 \cdot \pi\right)\right)}{-\pi}
\end{array}
Initial program 6.5%
associate-*l/6.5%
Applied egg-rr99.4%
neg-mul-199.4%
*-commutative99.4%
times-frac99.4%
metadata-eval99.4%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (f) :precision binary64 (if (<= f 1.25) (* (log (/ 4.0 (* f PI))) (/ -4.0 PI)) (* -4.0 (/ 0.0 PI))))
double code(double f) {
double tmp;
if (f <= 1.25) {
tmp = log((4.0 / (f * ((double) M_PI)))) * (-4.0 / ((double) M_PI));
} else {
tmp = -4.0 * (0.0 / ((double) M_PI));
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.25) {
tmp = Math.log((4.0 / (f * Math.PI))) * (-4.0 / Math.PI);
} else {
tmp = -4.0 * (0.0 / Math.PI);
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.25: tmp = math.log((4.0 / (f * math.pi))) * (-4.0 / math.pi) else: tmp = -4.0 * (0.0 / math.pi) return tmp
function code(f) tmp = 0.0 if (f <= 1.25) tmp = Float64(log(Float64(4.0 / Float64(f * pi))) * Float64(-4.0 / pi)); else tmp = Float64(-4.0 * Float64(0.0 / pi)); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.25) tmp = log((4.0 / (f * pi))) * (-4.0 / pi); else tmp = -4.0 * (0.0 / pi); end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.25], N[(N[Log[N[(4.0 / N[(f * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-4.0 / Pi), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(0.0 / Pi), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.25:\\
\;\;\;\;\log \left(\frac{4}{f \cdot \pi}\right) \cdot \frac{-4}{\pi}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{0}{\pi}\\
\end{array}
\end{array}
if f < 1.25Initial program 6.2%
Simplified99.4%
Taylor expanded in f around 0 98.4%
associate-*r/98.4%
mul-1-neg98.4%
unsub-neg98.4%
Simplified98.4%
associate-/l*98.4%
diff-log98.3%
Applied egg-rr98.3%
associate-*r/98.3%
metadata-eval98.3%
distribute-lft-neg-in98.3%
*-commutative98.3%
distribute-rgt-neg-in98.3%
metadata-eval98.3%
associate-*r/98.2%
associate-/l/98.2%
Simplified98.2%
if 1.25 < f Initial program 16.7%
associate-*l/16.7%
Applied egg-rr95.0%
neg-mul-195.0%
*-commutative95.0%
times-frac95.0%
metadata-eval95.0%
*-commutative95.0%
*-commutative95.0%
Simplified95.0%
Applied egg-rr78.5%
*-inverses78.5%
Simplified78.5%
Final simplification97.5%
(FPCore (f) :precision binary64 (if (<= f 1.25) (/ (* -4.0 (log (/ (/ 4.0 PI) f))) PI) (* -4.0 (/ 0.0 PI))))
double code(double f) {
double tmp;
if (f <= 1.25) {
tmp = (-4.0 * log(((4.0 / ((double) M_PI)) / f))) / ((double) M_PI);
} else {
tmp = -4.0 * (0.0 / ((double) M_PI));
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.25) {
tmp = (-4.0 * Math.log(((4.0 / Math.PI) / f))) / Math.PI;
} else {
tmp = -4.0 * (0.0 / Math.PI);
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.25: tmp = (-4.0 * math.log(((4.0 / math.pi) / f))) / math.pi else: tmp = -4.0 * (0.0 / math.pi) return tmp
function code(f) tmp = 0.0 if (f <= 1.25) tmp = Float64(Float64(-4.0 * log(Float64(Float64(4.0 / pi) / f))) / pi); else tmp = Float64(-4.0 * Float64(0.0 / pi)); end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.25) tmp = (-4.0 * log(((4.0 / pi) / f))) / pi; else tmp = -4.0 * (0.0 / pi); end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.25], N[(N[(-4.0 * N[Log[N[(N[(4.0 / Pi), $MachinePrecision] / f), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision], N[(-4.0 * N[(0.0 / Pi), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.25:\\
\;\;\;\;\frac{-4 \cdot \log \left(\frac{\frac{4}{\pi}}{f}\right)}{\pi}\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \frac{0}{\pi}\\
\end{array}
\end{array}
if f < 1.25Initial program 6.2%
Simplified99.4%
Taylor expanded in f around 0 98.4%
associate-*r/98.4%
mul-1-neg98.4%
unsub-neg98.4%
Simplified98.4%
diff-log98.3%
Applied egg-rr98.3%
if 1.25 < f Initial program 16.7%
associate-*l/16.7%
Applied egg-rr95.0%
neg-mul-195.0%
*-commutative95.0%
times-frac95.0%
metadata-eval95.0%
*-commutative95.0%
*-commutative95.0%
Simplified95.0%
Applied egg-rr78.5%
*-inverses78.5%
Simplified78.5%
Final simplification97.6%
(FPCore (f) :precision binary64 (* -4.0 (/ 0.0 PI)))
double code(double f) {
return -4.0 * (0.0 / ((double) M_PI));
}
public static double code(double f) {
return -4.0 * (0.0 / Math.PI);
}
def code(f): return -4.0 * (0.0 / math.pi)
function code(f) return Float64(-4.0 * Float64(0.0 / pi)) end
function tmp = code(f) tmp = -4.0 * (0.0 / pi); end
code[f_] := N[(-4.0 * N[(0.0 / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-4 \cdot \frac{0}{\pi}
\end{array}
Initial program 6.5%
associate-*l/6.5%
Applied egg-rr99.4%
neg-mul-199.4%
*-commutative99.4%
times-frac99.4%
metadata-eval99.4%
*-commutative99.4%
*-commutative99.4%
Simplified99.4%
Applied egg-rr5.8%
*-inverses5.8%
Simplified5.8%
Final simplification5.8%
herbie shell --seed 2024067
(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)))))))))