
(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 (/ (log (/ 1.0 (/ 1.0 (tanh (* PI (* 0.25 f)))))) (* PI 0.25)))
double code(double f) {
return log((1.0 / (1.0 / tanh((((double) M_PI) * (0.25 * f)))))) / (((double) M_PI) * 0.25);
}
public static double code(double f) {
return Math.log((1.0 / (1.0 / Math.tanh((Math.PI * (0.25 * f)))))) / (Math.PI * 0.25);
}
def code(f): return math.log((1.0 / (1.0 / math.tanh((math.pi * (0.25 * f)))))) / (math.pi * 0.25)
function code(f) return Float64(log(Float64(1.0 / Float64(1.0 / tanh(Float64(pi * Float64(0.25 * f)))))) / Float64(pi * 0.25)) end
function tmp = code(f) tmp = log((1.0 / (1.0 / tanh((pi * (0.25 * f)))))) / (pi * 0.25); end
code[f_] := N[(N[Log[N[(1.0 / N[(1.0 / N[Tanh[N[(Pi * N[(0.25 * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\frac{1}{\frac{1}{\tanh \left(\pi \cdot \left(0.25 \cdot f\right)\right)}}\right)}{\pi \cdot 0.25}
\end{array}
Initial program 8.0%
*-commutativeN/A
un-div-invN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
Applied egg-rr99.5%
tanh-def-bN/A
clear-numN/A
/-lowering-/.f64N/A
clear-numN/A
tanh-def-bN/A
/-lowering-/.f64N/A
tanh-lowering-tanh.f64N/A
associate-*l*N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
*-lowering-*.f6499.5
Applied egg-rr99.5%
(FPCore (f) :precision binary64 (/ (log (tanh (* f (* PI 0.25)))) (* PI 0.25)))
double code(double f) {
return log(tanh((f * (((double) M_PI) * 0.25)))) / (((double) M_PI) * 0.25);
}
public static double code(double f) {
return Math.log(Math.tanh((f * (Math.PI * 0.25)))) / (Math.PI * 0.25);
}
def code(f): return math.log(math.tanh((f * (math.pi * 0.25)))) / (math.pi * 0.25)
function code(f) return Float64(log(tanh(Float64(f * Float64(pi * 0.25)))) / Float64(pi * 0.25)) end
function tmp = code(f) tmp = log(tanh((f * (pi * 0.25)))) / (pi * 0.25); end
code[f_] := N[(N[Log[N[Tanh[N[(f * N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \tanh \left(f \cdot \left(\pi \cdot 0.25\right)\right)}{\pi \cdot 0.25}
\end{array}
Initial program 8.0%
*-commutativeN/A
un-div-invN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (f) :precision binary64 (/ (log (/ (fma f (fma f (fma PI 0.08333333333333333 0.0) 0.0) (/ 4.0 PI)) f)) (fma PI -0.25 0.0)))
double code(double f) {
return log((fma(f, fma(f, fma(((double) M_PI), 0.08333333333333333, 0.0), 0.0), (4.0 / ((double) M_PI))) / f)) / fma(((double) M_PI), -0.25, 0.0);
}
function code(f) return Float64(log(Float64(fma(f, fma(f, fma(pi, 0.08333333333333333, 0.0), 0.0), Float64(4.0 / pi)) / f)) / fma(pi, -0.25, 0.0)) end
code[f_] := N[(N[Log[N[(N[(f * N[(f * N[(Pi * 0.08333333333333333 + 0.0), $MachinePrecision] + 0.0), $MachinePrecision] + N[(4.0 / Pi), $MachinePrecision]), $MachinePrecision] / f), $MachinePrecision]], $MachinePrecision] / N[(Pi * -0.25 + 0.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(\frac{\mathsf{fma}\left(f, \mathsf{fma}\left(f, \mathsf{fma}\left(\pi, 0.08333333333333333, 0\right), 0\right), \frac{4}{\pi}\right)}{f}\right)}{\mathsf{fma}\left(\pi, -0.25, 0\right)}
\end{array}
Initial program 8.0%
Taylor expanded in f around 0
Simplified96.5%
clear-numN/A
*-commutativeN/A
clear-numN/A
div-invN/A
metadata-evalN/A
Applied egg-rr96.7%
(FPCore (f) :precision binary64 (/ (* 4.0 (log (/ f (fma f (fma f (fma PI 0.08333333333333333 0.0) 0.0) (/ 4.0 PI))))) PI))
double code(double f) {
return (4.0 * log((f / fma(f, fma(f, fma(((double) M_PI), 0.08333333333333333, 0.0), 0.0), (4.0 / ((double) M_PI)))))) / ((double) M_PI);
}
function code(f) return Float64(Float64(4.0 * log(Float64(f / fma(f, fma(f, fma(pi, 0.08333333333333333, 0.0), 0.0), Float64(4.0 / pi))))) / pi) end
code[f_] := N[(N[(4.0 * N[Log[N[(f / N[(f * N[(f * N[(Pi * 0.08333333333333333 + 0.0), $MachinePrecision] + 0.0), $MachinePrecision] + N[(4.0 / Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision]
\begin{array}{l}
\\
\frac{4 \cdot \log \left(\frac{f}{\mathsf{fma}\left(f, \mathsf{fma}\left(f, \mathsf{fma}\left(\pi, 0.08333333333333333, 0\right), 0\right), \frac{4}{\pi}\right)}\right)}{\pi}
\end{array}
Initial program 8.0%
Taylor expanded in f around 0
Simplified96.5%
clear-numN/A
distribute-rgt-neg-inN/A
associate-*l/N/A
/-lowering-/.f64N/A
Applied egg-rr96.7%
(FPCore (f) :precision binary64 (/ (log (* f (* PI (fma (* -0.005208333333333333 (* f f)) (* PI PI) 0.25)))) (* PI 0.25)))
double code(double f) {
return log((f * (((double) M_PI) * fma((-0.005208333333333333 * (f * f)), (((double) M_PI) * ((double) M_PI)), 0.25)))) / (((double) M_PI) * 0.25);
}
function code(f) return Float64(log(Float64(f * Float64(pi * fma(Float64(-0.005208333333333333 * Float64(f * f)), Float64(pi * pi), 0.25)))) / Float64(pi * 0.25)) end
code[f_] := N[(N[Log[N[(f * N[(Pi * N[(N[(-0.005208333333333333 * N[(f * f), $MachinePrecision]), $MachinePrecision] * N[(Pi * Pi), $MachinePrecision] + 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(f \cdot \left(\pi \cdot \mathsf{fma}\left(-0.005208333333333333 \cdot \left(f \cdot f\right), \pi \cdot \pi, 0.25\right)\right)\right)}{\pi \cdot 0.25}
\end{array}
Initial program 8.0%
*-commutativeN/A
un-div-invN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
Applied egg-rr99.5%
Taylor expanded in f around 0
Simplified96.6%
Taylor expanded in f around inf
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
associate-+r+N/A
distribute-rgt-outN/A
metadata-evalN/A
metadata-evalN/A
cube-multN/A
unpow2N/A
associate-*l*N/A
associate-*r/N/A
*-commutativeN/A
associate-/l*N/A
distribute-lft-outN/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
accelerator-lowering-fma.f64N/A
Simplified42.6%
Taylor expanded in f around 0
associate-*r*N/A
unpow3N/A
unpow2N/A
associate-*r*N/A
distribute-rgt-outN/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
accelerator-lowering-fma.f64N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
unpow2N/A
*-lowering-*.f64N/A
PI-lowering-PI.f64N/A
PI-lowering-PI.f6496.6
Simplified96.6%
(FPCore (f) :precision binary64 (/ (log (* 0.25 (* PI f))) (* PI 0.25)))
double code(double f) {
return log((0.25 * (((double) M_PI) * f))) / (((double) M_PI) * 0.25);
}
public static double code(double f) {
return Math.log((0.25 * (Math.PI * f))) / (Math.PI * 0.25);
}
def code(f): return math.log((0.25 * (math.pi * f))) / (math.pi * 0.25)
function code(f) return Float64(log(Float64(0.25 * Float64(pi * f))) / Float64(pi * 0.25)) end
function tmp = code(f) tmp = log((0.25 * (pi * f))) / (pi * 0.25); end
code[f_] := N[(N[Log[N[(0.25 * N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\log \left(0.25 \cdot \left(\pi \cdot f\right)\right)}{\pi \cdot 0.25}
\end{array}
Initial program 8.0%
*-commutativeN/A
un-div-invN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
Applied egg-rr99.5%
Taylor expanded in f around 0
*-lowering-*.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f6496.0
Simplified96.0%
Final simplification96.0%
(FPCore (f) :precision binary64 (* (/ 4.0 PI) (log (* 0.25 (* PI f)))))
double code(double f) {
return (4.0 / ((double) M_PI)) * log((0.25 * (((double) M_PI) * f)));
}
public static double code(double f) {
return (4.0 / Math.PI) * Math.log((0.25 * (Math.PI * f)));
}
def code(f): return (4.0 / math.pi) * math.log((0.25 * (math.pi * f)))
function code(f) return Float64(Float64(4.0 / pi) * log(Float64(0.25 * Float64(pi * f)))) end
function tmp = code(f) tmp = (4.0 / pi) * log((0.25 * (pi * f))); end
code[f_] := N[(N[(4.0 / Pi), $MachinePrecision] * N[Log[N[(0.25 * N[(Pi * f), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{4}{\pi} \cdot \log \left(0.25 \cdot \left(\pi \cdot f\right)\right)
\end{array}
Initial program 8.0%
*-commutativeN/A
un-div-invN/A
distribute-neg-fracN/A
/-lowering-/.f64N/A
Applied egg-rr99.5%
Taylor expanded in f around 0
*-lowering-*.f64N/A
*-lowering-*.f64N/A
PI-lowering-PI.f6496.0
Simplified96.0%
clear-numN/A
*-commutativeN/A
associate-/r/N/A
associate-/r*N/A
metadata-evalN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
sum-logN/A
*-commutativeN/A
metadata-evalN/A
associate-*l*N/A
+-rgt-identityN/A
log-prodN/A
*-lowering-*.f64N/A
Applied egg-rr95.9%
+-rgt-identityN/A
associate-*r*N/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
PI-lowering-PI.f6495.9
Applied egg-rr95.9%
Final simplification95.9%
herbie shell --seed 2024199
(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)))))))))