
(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 (let* ((t_0 (/ PI (/ 4.0 f)))) (- (/ (log (/ (cosh t_0) (sinh t_0))) (* PI 0.25)))))
double code(double f) {
double t_0 = ((double) M_PI) / (4.0 / f);
return -(log((cosh(t_0) / sinh(t_0))) / (((double) M_PI) * 0.25));
}
public static double code(double f) {
double t_0 = Math.PI / (4.0 / f);
return -(Math.log((Math.cosh(t_0) / Math.sinh(t_0))) / (Math.PI * 0.25));
}
def code(f): t_0 = math.pi / (4.0 / f) return -(math.log((math.cosh(t_0) / math.sinh(t_0))) / (math.pi * 0.25))
function code(f) t_0 = Float64(pi / Float64(4.0 / f)) return Float64(-Float64(log(Float64(cosh(t_0) / sinh(t_0))) / Float64(pi * 0.25))) end
function tmp = code(f) t_0 = pi / (4.0 / f); tmp = -(log((cosh(t_0) / sinh(t_0))) / (pi * 0.25)); end
code[f_] := Block[{t$95$0 = N[(Pi / N[(4.0 / f), $MachinePrecision]), $MachinePrecision]}, (-N[(N[Log[N[(N[Cosh[t$95$0], $MachinePrecision] / N[Sinh[t$95$0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision])]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\pi}{\frac{4}{f}}\\
-\frac{\log \left(\frac{\cosh t_0}{\sinh t_0}\right)}{\pi \cdot 0.25}
\end{array}
\end{array}
Initial program 8.3%
expm1-log1p-u8.3%
expm1-udef8.3%
Applied egg-rr97.5%
expm1-def97.5%
expm1-log1p98.7%
*-commutative98.7%
times-frac98.7%
metadata-eval98.7%
*-lft-identity98.7%
associate-/l*98.7%
associate-/l*98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (f) :precision binary64 (- 1.0 (+ 1.0 (/ (log (/ 2.0 (* f (* PI 0.5)))) (* PI 0.25)))))
double code(double f) {
return 1.0 - (1.0 + (log((2.0 / (f * (((double) M_PI) * 0.5)))) / (((double) M_PI) * 0.25)));
}
public static double code(double f) {
return 1.0 - (1.0 + (Math.log((2.0 / (f * (Math.PI * 0.5)))) / (Math.PI * 0.25)));
}
def code(f): return 1.0 - (1.0 + (math.log((2.0 / (f * (math.pi * 0.5)))) / (math.pi * 0.25)))
function code(f) return Float64(1.0 - Float64(1.0 + Float64(log(Float64(2.0 / Float64(f * Float64(pi * 0.5)))) / Float64(pi * 0.25)))) end
function tmp = code(f) tmp = 1.0 - (1.0 + (log((2.0 / (f * (pi * 0.5)))) / (pi * 0.25))); end
code[f_] := N[(1.0 - N[(1.0 + N[(N[Log[N[(2.0 / N[(f * N[(Pi * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \left(1 + \frac{\log \left(\frac{2}{f \cdot \left(\pi \cdot 0.5\right)}\right)}{\pi \cdot 0.25}\right)
\end{array}
Initial program 8.3%
Taylor expanded in f around 0 96.9%
distribute-rgt-out--96.9%
metadata-eval96.9%
Simplified96.9%
expm1-log1p-u95.9%
associate-*l/95.9%
*-un-lft-identity95.9%
associate-/r*95.9%
associate-/r*95.9%
div-inv95.9%
metadata-eval95.9%
Applied egg-rr95.9%
expm1-udef95.9%
log1p-udef95.9%
add-exp-log97.1%
div-inv97.1%
associate-/l/97.1%
frac-times97.1%
metadata-eval97.1%
Applied egg-rr97.1%
Final simplification97.1%
(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 8.3%
expm1-log1p-u8.3%
expm1-udef8.3%
Applied egg-rr97.5%
expm1-def97.5%
expm1-log1p98.7%
*-commutative98.7%
times-frac98.7%
metadata-eval98.7%
*-lft-identity98.7%
associate-/l*98.7%
associate-/l*98.7%
Simplified98.7%
Taylor expanded in f around 0 97.1%
*-commutative97.1%
expm1-log1p-u95.9%
expm1-udef95.9%
sub-neg95.9%
Applied egg-rr76.7%
+-commutative76.7%
associate-+r+76.7%
metadata-eval76.7%
metadata-eval76.7%
log-pow96.9%
metadata-eval96.9%
associate-/r*96.9%
*-commutative96.9%
associate-/r/97.0%
metadata-eval97.0%
associate-/r*97.0%
neg-mul-197.0%
*-commutative97.0%
associate-/l*97.0%
distribute-neg-frac97.0%
metadata-eval97.0%
Simplified96.9%
Final simplification96.9%
(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 8.3%
Taylor expanded in f around 0 97.0%
associate-*r/97.0%
associate-/l*96.9%
mul-1-neg96.9%
unsub-neg96.9%
distribute-rgt-out--96.9%
metadata-eval96.9%
Simplified96.9%
Taylor expanded in f around 0 96.9%
metadata-eval96.9%
associate-/r*96.9%
associate-/l/96.9%
log-div97.0%
associate-/l/97.0%
associate-/r*97.0%
metadata-eval97.0%
associate-/r*97.0%
*-commutative97.0%
Simplified97.0%
Final simplification97.0%
(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 8.3%
expm1-log1p-u8.3%
expm1-udef8.3%
Applied egg-rr97.5%
expm1-def97.5%
expm1-log1p98.7%
*-commutative98.7%
times-frac98.7%
metadata-eval98.7%
*-lft-identity98.7%
associate-/l*98.7%
associate-/l*98.7%
Simplified98.7%
Taylor expanded in f around 0 97.1%
Final simplification97.1%
herbie shell --seed 2023249
(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)))))))))