
(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 8 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 (* 0.25 (* PI f))))
(*
(log (exp (/ (log (/ (* 2.0 (cosh t_0)) (* 2.0 (sinh t_0)))) PI)))
(- 4.0))))
double code(double f) {
double t_0 = 0.25 * (((double) M_PI) * f);
return log(exp((log(((2.0 * cosh(t_0)) / (2.0 * sinh(t_0)))) / ((double) M_PI)))) * -4.0;
}
public static double code(double f) {
double t_0 = 0.25 * (Math.PI * f);
return Math.log(Math.exp((Math.log(((2.0 * Math.cosh(t_0)) / (2.0 * Math.sinh(t_0)))) / Math.PI))) * -4.0;
}
def code(f): t_0 = 0.25 * (math.pi * f) return math.log(math.exp((math.log(((2.0 * math.cosh(t_0)) / (2.0 * math.sinh(t_0)))) / math.pi))) * -4.0
function code(f) t_0 = Float64(0.25 * Float64(pi * f)) return Float64(log(exp(Float64(log(Float64(Float64(2.0 * cosh(t_0)) / Float64(2.0 * sinh(t_0)))) / pi))) * Float64(-4.0)) end
function tmp = code(f) t_0 = 0.25 * (pi * f); tmp = log(exp((log(((2.0 * cosh(t_0)) / (2.0 * sinh(t_0)))) / pi))) * -4.0; end
code[f_] := Block[{t$95$0 = N[(0.25 * N[(Pi * f), $MachinePrecision]), $MachinePrecision]}, N[(N[Log[N[Exp[N[(N[Log[N[(N[(2.0 * N[Cosh[t$95$0], $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sinh[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] * (-4.0)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.25 \cdot \left(\pi \cdot f\right)\\
\log \left(e^{\frac{\log \left(\frac{2 \cdot \cosh t_0}{2 \cdot \sinh t_0}\right)}{\pi}}\right) \cdot \left(-4\right)
\end{array}
\end{array}
Initial program 6.4%
Taylor expanded in f around inf 6.4%
add-log-exp6.4%
Applied egg-rr97.7%
Final simplification97.7%
(FPCore (f) :precision binary64 (let* ((t_0 (* f (* 0.25 PI)))) (* 4.0 (/ (- (log (/ (cosh t_0) (sinh t_0)))) PI))))
double code(double f) {
double t_0 = f * (0.25 * ((double) M_PI));
return 4.0 * (-log((cosh(t_0) / sinh(t_0))) / ((double) M_PI));
}
public static double code(double f) {
double t_0 = f * (0.25 * Math.PI);
return 4.0 * (-Math.log((Math.cosh(t_0) / Math.sinh(t_0))) / Math.PI);
}
def code(f): t_0 = f * (0.25 * math.pi) return 4.0 * (-math.log((math.cosh(t_0) / math.sinh(t_0))) / math.pi)
function code(f) t_0 = Float64(f * Float64(0.25 * pi)) return Float64(4.0 * Float64(Float64(-log(Float64(cosh(t_0) / sinh(t_0)))) / pi)) end
function tmp = code(f) t_0 = f * (0.25 * pi); tmp = 4.0 * (-log((cosh(t_0) / sinh(t_0))) / pi); end
code[f_] := Block[{t$95$0 = N[(f * N[(0.25 * Pi), $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 \left(0.25 \cdot \pi\right)\\
4 \cdot \frac{-\log \left(\frac{\cosh t_0}{\sinh t_0}\right)}{\pi}
\end{array}
\end{array}
Initial program 6.4%
Taylor expanded in f around inf 6.4%
*-un-lft-identity6.4%
cosh-undef6.4%
*-commutative6.4%
sinh-undef97.7%
*-commutative97.7%
Applied egg-rr97.7%
*-lft-identity97.7%
times-frac97.7%
metadata-eval97.7%
*-lft-identity97.7%
associate-*r*97.7%
*-commutative97.7%
*-commutative97.7%
associate-*r*97.7%
*-commutative97.7%
*-commutative97.7%
Simplified97.7%
Final simplification97.7%
(FPCore (f) :precision binary64 (* (fabs (/ (log (/ 4.0 (* PI f))) PI)) (- 4.0)))
double code(double f) {
return fabs((log((4.0 / (((double) M_PI) * f))) / ((double) M_PI))) * -4.0;
}
public static double code(double f) {
return Math.abs((Math.log((4.0 / (Math.PI * f))) / Math.PI)) * -4.0;
}
def code(f): return math.fabs((math.log((4.0 / (math.pi * f))) / math.pi)) * -4.0
function code(f) return Float64(abs(Float64(log(Float64(4.0 / Float64(pi * f))) / pi)) * Float64(-4.0)) end
function tmp = code(f) tmp = abs((log((4.0 / (pi * f))) / pi)) * -4.0; end
code[f_] := N[(N[Abs[N[(N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision] * (-4.0)), $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{\log \left(\frac{4}{\pi \cdot f}\right)}{\pi}\right| \cdot \left(-4\right)
\end{array}
Initial program 6.4%
Taylor expanded in f around 0 96.7%
mul-1-neg96.7%
unsub-neg96.7%
distribute-rgt-out--96.7%
associate-/r*96.7%
metadata-eval96.7%
Simplified96.7%
expm1-log1p-u95.5%
diff-log95.5%
div-inv95.5%
metadata-eval95.5%
Applied egg-rr95.5%
expm1-log1p-u96.7%
add-sqr-sqrt96.2%
sqrt-unprod96.7%
pow296.7%
associate-*l/96.7%
metadata-eval96.7%
associate-/r*96.7%
Applied egg-rr96.7%
unpow296.7%
rem-sqrt-square96.7%
*-commutative96.7%
Simplified96.7%
Final simplification96.7%
(FPCore (f) :precision binary64 (* (/ 4.0 PI) (- (log f) (log (/ 4.0 PI)))))
double code(double f) {
return (4.0 / ((double) M_PI)) * (log(f) - log((4.0 / ((double) M_PI))));
}
public static double code(double f) {
return (4.0 / Math.PI) * (Math.log(f) - Math.log((4.0 / Math.PI)));
}
def code(f): return (4.0 / math.pi) * (math.log(f) - math.log((4.0 / math.pi)))
function code(f) return Float64(Float64(4.0 / pi) * Float64(log(f) - log(Float64(4.0 / pi)))) end
function tmp = code(f) tmp = (4.0 / pi) * (log(f) - log((4.0 / pi))); end
code[f_] := N[(N[(4.0 / Pi), $MachinePrecision] * N[(N[Log[f], $MachinePrecision] - N[Log[N[(4.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{\pi} \cdot \left(\log f - \log \left(\frac{4}{\pi}\right)\right)
\end{array}
Initial program 6.4%
Taylor expanded in f around 0 96.7%
associate-*r/96.7%
associate-/l*96.7%
associate-/r/96.7%
mul-1-neg96.7%
unsub-neg96.7%
distribute-rgt-out--96.7%
*-commutative96.7%
associate-/r*96.7%
metadata-eval96.7%
metadata-eval96.7%
Simplified96.7%
Final simplification96.7%
(FPCore (f) :precision binary64 (* 4.0 (/ (- (log (* 0.25 (* PI f)))) (- PI))))
double code(double f) {
return 4.0 * (-log((0.25 * (((double) M_PI) * f))) / -((double) M_PI));
}
public static double code(double f) {
return 4.0 * (-Math.log((0.25 * (Math.PI * f))) / -Math.PI);
}
def code(f): return 4.0 * (-math.log((0.25 * (math.pi * f))) / -math.pi)
function code(f) return Float64(4.0 * Float64(Float64(-log(Float64(0.25 * Float64(pi * f)))) / Float64(-pi))) end
function tmp = code(f) tmp = 4.0 * (-log((0.25 * (pi * f))) / -pi); end
code[f_] := N[(4.0 * N[((-N[Log[N[(0.25 * N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / (-Pi)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \frac{-\log \left(0.25 \cdot \left(\pi \cdot f\right)\right)}{-\pi}
\end{array}
Initial program 6.4%
Taylor expanded in f around 0 96.7%
mul-1-neg96.7%
unsub-neg96.7%
distribute-rgt-out--96.7%
associate-/r*96.7%
metadata-eval96.7%
Simplified96.7%
expm1-log1p-u95.5%
diff-log95.5%
div-inv95.5%
metadata-eval95.5%
Applied egg-rr95.5%
expm1-log1p-u96.7%
frac-2neg96.7%
associate-*l/96.7%
metadata-eval96.7%
associate-/r*96.7%
neg-log96.7%
*-commutative96.7%
clear-num96.7%
div-inv96.7%
metadata-eval96.7%
associate-*r*96.7%
*-commutative96.7%
*-commutative96.7%
associate-*r*96.7%
Applied egg-rr96.7%
Final simplification96.7%
(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 / pi) * Float64(-log(Float64(4.0 / Float64(pi * f))))) end
function tmp = code(f) tmp = (4.0 / pi) * -log((4.0 / (pi * f))); end
code[f_] := N[(N[(4.0 / Pi), $MachinePrecision] * (-N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{\pi} \cdot \left(-\log \left(\frac{4}{\pi \cdot f}\right)\right)
\end{array}
Initial program 6.4%
Taylor expanded in f around 0 96.6%
associate-/r*96.6%
distribute-rgt-out--96.6%
*-commutative96.6%
associate-/r*96.6%
metadata-eval96.6%
metadata-eval96.6%
Simplified96.6%
Taylor expanded in f around 0 96.7%
associate-*r/96.7%
neg-mul-196.7%
log-rec96.7%
+-commutative96.7%
log-rec96.7%
metadata-eval96.7%
associate-*l/96.7%
unsub-neg96.7%
log-div96.7%
associate-*l/96.6%
associate-*l/96.6%
metadata-eval96.6%
associate-/l/96.6%
Simplified96.6%
Final simplification96.6%
(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(4.0 / Float64(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[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-4}{\frac{\pi}{\log \left(\frac{4}{\pi \cdot f}\right)}}
\end{array}
Initial program 6.4%
Taylor expanded in f around 0 96.7%
associate-*r/96.7%
associate-/l*96.7%
associate-/r/96.7%
mul-1-neg96.7%
unsub-neg96.7%
distribute-rgt-out--96.7%
*-commutative96.7%
associate-/r*96.7%
metadata-eval96.7%
metadata-eval96.7%
Simplified96.7%
associate-*l/96.7%
diff-log96.7%
associate-/r*96.7%
associate-/l*96.6%
*-commutative96.6%
Applied egg-rr96.6%
Final simplification96.6%
(FPCore (f) :precision binary64 (/ (- (log (/ 4.0 (* PI f)))) (* 0.25 PI)))
double code(double f) {
return -log((4.0 / (((double) M_PI) * f))) / (0.25 * ((double) M_PI));
}
public static double code(double f) {
return -Math.log((4.0 / (Math.PI * f))) / (0.25 * Math.PI);
}
def code(f): return -math.log((4.0 / (math.pi * f))) / (0.25 * math.pi)
function code(f) return Float64(Float64(-log(Float64(4.0 / Float64(pi * f)))) / Float64(0.25 * pi)) end
function tmp = code(f) tmp = -log((4.0 / (pi * f))) / (0.25 * pi); end
code[f_] := N[((-N[Log[N[(4.0 / N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]) / N[(0.25 * Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{-\log \left(\frac{4}{\pi \cdot f}\right)}{0.25 \cdot \pi}
\end{array}
Initial program 6.4%
Taylor expanded in f around 0 96.6%
associate-/r*96.6%
distribute-rgt-out--96.6%
*-commutative96.6%
associate-/r*96.6%
metadata-eval96.6%
metadata-eval96.6%
Simplified96.6%
associate-*l/96.7%
*-un-lft-identity96.7%
associate-/l/96.7%
*-commutative96.7%
div-inv96.7%
metadata-eval96.7%
Applied egg-rr96.7%
Final simplification96.7%
herbie shell --seed 2023207
(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)))))))))