
(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 (/ (/ (log (tanh (/ f (/ 4.0 PI)))) PI) 0.25))
double code(double f) {
return (log(tanh((f / (4.0 / ((double) M_PI))))) / ((double) M_PI)) / 0.25;
}
public static double code(double f) {
return (Math.log(Math.tanh((f / (4.0 / Math.PI)))) / Math.PI) / 0.25;
}
def code(f): return (math.log(math.tanh((f / (4.0 / math.pi)))) / math.pi) / 0.25
function code(f) return Float64(Float64(log(tanh(Float64(f / Float64(4.0 / pi)))) / pi) / 0.25) end
function tmp = code(f) tmp = (log(tanh((f / (4.0 / pi)))) / pi) / 0.25; end
code[f_] := N[(N[(N[Log[N[Tanh[N[(f / N[(4.0 / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] / 0.25), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\log \tanh \left(\frac{f}{\frac{4}{\pi}}\right)}{\pi}}{0.25}
\end{array}
Initial program 7.9%
*-commutativeN/A
un-div-invN/A
div-invN/A
associate-/r*N/A
Applied egg-rr98.9%
(FPCore (f)
:precision binary64
(let* ((t_0 (* f (* f PI))))
(/
(*
4.0
(log
(*
(/ f (- (/ 16.0 (* PI PI)) (* (* t_0 t_0) 0.006944444444444444)))
(- (/ 4.0 PI) (* f (* f (* PI 0.08333333333333333)))))))
PI)))
double code(double f) {
double t_0 = f * (f * ((double) M_PI));
return (4.0 * log(((f / ((16.0 / (((double) M_PI) * ((double) M_PI))) - ((t_0 * t_0) * 0.006944444444444444))) * ((4.0 / ((double) M_PI)) - (f * (f * (((double) M_PI) * 0.08333333333333333))))))) / ((double) M_PI);
}
public static double code(double f) {
double t_0 = f * (f * Math.PI);
return (4.0 * Math.log(((f / ((16.0 / (Math.PI * Math.PI)) - ((t_0 * t_0) * 0.006944444444444444))) * ((4.0 / Math.PI) - (f * (f * (Math.PI * 0.08333333333333333))))))) / Math.PI;
}
def code(f): t_0 = f * (f * math.pi) return (4.0 * math.log(((f / ((16.0 / (math.pi * math.pi)) - ((t_0 * t_0) * 0.006944444444444444))) * ((4.0 / math.pi) - (f * (f * (math.pi * 0.08333333333333333))))))) / math.pi
function code(f) t_0 = Float64(f * Float64(f * pi)) return Float64(Float64(4.0 * log(Float64(Float64(f / Float64(Float64(16.0 / Float64(pi * pi)) - Float64(Float64(t_0 * t_0) * 0.006944444444444444))) * Float64(Float64(4.0 / pi) - Float64(f * Float64(f * Float64(pi * 0.08333333333333333))))))) / pi) end
function tmp = code(f) t_0 = f * (f * pi); tmp = (4.0 * log(((f / ((16.0 / (pi * pi)) - ((t_0 * t_0) * 0.006944444444444444))) * ((4.0 / pi) - (f * (f * (pi * 0.08333333333333333))))))) / pi; end
code[f_] := Block[{t$95$0 = N[(f * N[(f * Pi), $MachinePrecision]), $MachinePrecision]}, N[(N[(4.0 * N[Log[N[(N[(f / N[(N[(16.0 / N[(Pi * Pi), $MachinePrecision]), $MachinePrecision] - N[(N[(t$95$0 * t$95$0), $MachinePrecision] * 0.006944444444444444), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(4.0 / Pi), $MachinePrecision] - N[(f * N[(f * N[(Pi * 0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := f \cdot \left(f \cdot \pi\right)\\
\frac{4 \cdot \log \left(\frac{f}{\frac{16}{\pi \cdot \pi} - \left(t\_0 \cdot t\_0\right) \cdot 0.006944444444444444} \cdot \left(\frac{4}{\pi} - f \cdot \left(f \cdot \left(\pi \cdot 0.08333333333333333\right)\right)\right)\right)}{\pi}
\end{array}
\end{array}
Initial program 7.9%
Applied egg-rr8.2%
Taylor expanded in f around 0
Simplified96.6%
clear-numN/A
distribute-rgt-neg-inN/A
associate-*l/N/A
/-lowering-/.f64N/A
Applied egg-rr96.7%
flip-+N/A
associate-/r/N/A
*-lowering-*.f64N/A
Applied egg-rr96.7%
(FPCore (f) :precision binary64 (/ (* 4.0 (log (/ f (+ (/ 4.0 PI) (* (* PI 0.08333333333333333) (* f f)))))) PI))
double code(double f) {
return (4.0 * log((f / ((4.0 / ((double) M_PI)) + ((((double) M_PI) * 0.08333333333333333) * (f * f)))))) / ((double) M_PI);
}
public static double code(double f) {
return (4.0 * Math.log((f / ((4.0 / Math.PI) + ((Math.PI * 0.08333333333333333) * (f * f)))))) / Math.PI;
}
def code(f): return (4.0 * math.log((f / ((4.0 / math.pi) + ((math.pi * 0.08333333333333333) * (f * f)))))) / math.pi
function code(f) return Float64(Float64(4.0 * log(Float64(f / Float64(Float64(4.0 / pi) + Float64(Float64(pi * 0.08333333333333333) * Float64(f * f)))))) / pi) end
function tmp = code(f) tmp = (4.0 * log((f / ((4.0 / pi) + ((pi * 0.08333333333333333) * (f * f)))))) / pi; end
code[f_] := N[(N[(4.0 * N[Log[N[(f / N[(N[(4.0 / Pi), $MachinePrecision] + N[(N[(Pi * 0.08333333333333333), $MachinePrecision] * N[(f * f), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \log \left(\frac{f}{\frac{4}{\pi} + \left(\pi \cdot 0.08333333333333333\right) \cdot \left(f \cdot f\right)}\right)}{\pi}
\end{array}
Initial program 7.9%
Applied egg-rr8.2%
Taylor expanded in f around 0
Simplified96.6%
clear-numN/A
distribute-rgt-neg-inN/A
associate-*l/N/A
/-lowering-/.f64N/A
Applied egg-rr96.7%
Final simplification96.7%
(FPCore (f) :precision binary64 (/ (/ (log (* f (* PI 0.25))) PI) 0.25))
double code(double f) {
return (log((f * (((double) M_PI) * 0.25))) / ((double) M_PI)) / 0.25;
}
public static double code(double f) {
return (Math.log((f * (Math.PI * 0.25))) / Math.PI) / 0.25;
}
def code(f): return (math.log((f * (math.pi * 0.25))) / math.pi) / 0.25
function code(f) return Float64(Float64(log(Float64(f * Float64(pi * 0.25))) / pi) / 0.25) end
function tmp = code(f) tmp = (log((f * (pi * 0.25))) / pi) / 0.25; end
code[f_] := N[(N[(N[Log[N[(f * N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] / 0.25), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\log \left(f \cdot \left(\pi \cdot 0.25\right)\right)}{\pi}}{0.25}
\end{array}
Initial program 7.9%
*-commutativeN/A
un-div-invN/A
div-invN/A
associate-/r*N/A
Applied egg-rr98.9%
Taylor expanded in f around 0
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f6496.0%
Simplified96.0%
Final simplification96.0%
(FPCore (f) :precision binary64 (* (/ 4.0 PI) (log (/ f (/ 4.0 PI)))))
double code(double f) {
return (4.0 / ((double) M_PI)) * log((f / (4.0 / ((double) M_PI))));
}
public static double code(double f) {
return (4.0 / Math.PI) * Math.log((f / (4.0 / Math.PI)));
}
def code(f): return (4.0 / math.pi) * math.log((f / (4.0 / math.pi)))
function code(f) return Float64(Float64(4.0 / pi) * log(Float64(f / Float64(4.0 / pi)))) end
function tmp = code(f) tmp = (4.0 / pi) * log((f / (4.0 / pi))); end
code[f_] := N[(N[(4.0 / Pi), $MachinePrecision] * N[Log[N[(f / N[(4.0 / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{\pi} \cdot \log \left(\frac{f}{\frac{4}{\pi}}\right)
\end{array}
Initial program 7.9%
Taylor expanded in f around 0
associate-/l/N/A
metadata-evalN/A
associate-*r/N/A
/-lowering-/.f64N/A
associate-*r/N/A
metadata-evalN/A
distribute-rgt-out--N/A
metadata-evalN/A
*-commutativeN/A
associate-/r*N/A
metadata-evalN/A
/-lowering-/.f64N/A
PI-lowering-PI.f6495.9%
Simplified95.9%
clear-numN/A
distribute-rgt-neg-inN/A
*-lowering-*.f64N/A
/-lowering-/.f64N/A
PI-lowering-PI.f64N/A
neg-logN/A
clear-numN/A
log-lowering-log.f64N/A
/-lowering-/.f64N/A
/-lowering-/.f64N/A
PI-lowering-PI.f6495.9%
Applied egg-rr95.9%
herbie shell --seed 2024191
(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)))))))))