
(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 (/ (/ (+ 1.0 (+ (log (tanh (* f (* PI 0.25)))) -1.0)) PI) 0.25))
double code(double f) {
return ((1.0 + (log(tanh((f * (((double) M_PI) * 0.25)))) + -1.0)) / ((double) M_PI)) / 0.25;
}
public static double code(double f) {
return ((1.0 + (Math.log(Math.tanh((f * (Math.PI * 0.25)))) + -1.0)) / Math.PI) / 0.25;
}
def code(f): return ((1.0 + (math.log(math.tanh((f * (math.pi * 0.25)))) + -1.0)) / math.pi) / 0.25
function code(f) return Float64(Float64(Float64(1.0 + Float64(log(tanh(Float64(f * Float64(pi * 0.25)))) + -1.0)) / pi) / 0.25) end
function tmp = code(f) tmp = ((1.0 + (log(tanh((f * (pi * 0.25)))) + -1.0)) / pi) / 0.25; end
code[f_] := N[(N[(N[(1.0 + N[(N[Log[N[Tanh[N[(f * N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / Pi), $MachinePrecision] / 0.25), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1 + \left(\log \tanh \left(f \cdot \left(\pi \cdot 0.25\right)\right) + -1\right)}{\pi}}{0.25}
\end{array}
Initial program 7.4%
associate-*l/7.4%
Applied egg-rr98.8%
neg-mul-198.8%
*-commutative98.8%
times-frac98.8%
metadata-eval98.8%
*-commutative98.8%
Simplified98.8%
metadata-eval98.8%
times-frac98.8%
*-commutative98.8%
neg-mul-198.8%
*-commutative98.8%
associate-/r*98.8%
distribute-neg-frac98.8%
distribute-frac-neg298.8%
*-commutative98.8%
frac-2neg98.8%
Applied egg-rr98.8%
add-sqr-sqrt1.2%
sqrt-unprod2.7%
sqr-neg2.7%
*-commutative2.7%
*-commutative2.7%
sqrt-unprod2.7%
add-sqr-sqrt2.7%
neg-sub02.7%
metadata-eval2.7%
*-commutative2.7%
Applied egg-rr98.8%
(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(Float64(log(tanh(Float64(f * Float64(pi * 0.25)))) / pi) / 0.25) end
function tmp = code(f) tmp = (log(tanh((f * (pi * 0.25)))) / pi) / 0.25; end
code[f_] := N[(N[(N[Log[N[Tanh[N[(f * N[(Pi * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / Pi), $MachinePrecision] / 0.25), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\log \tanh \left(f \cdot \left(\pi \cdot 0.25\right)\right)}{\pi}}{0.25}
\end{array}
Initial program 7.4%
associate-*l/7.4%
Applied egg-rr98.8%
neg-mul-198.8%
*-commutative98.8%
times-frac98.8%
metadata-eval98.8%
*-commutative98.8%
Simplified98.8%
metadata-eval98.8%
times-frac98.8%
*-commutative98.8%
neg-mul-198.8%
*-commutative98.8%
associate-/r*98.8%
distribute-neg-frac98.8%
distribute-frac-neg298.8%
*-commutative98.8%
frac-2neg98.8%
Applied egg-rr98.8%
(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.4%
associate-*l/7.4%
Applied egg-rr98.8%
neg-mul-198.8%
*-commutative98.8%
times-frac98.8%
metadata-eval98.8%
*-commutative98.8%
Simplified98.8%
metadata-eval98.8%
times-frac98.8%
*-commutative98.8%
neg-mul-198.8%
*-commutative98.8%
associate-/r*98.8%
distribute-neg-frac98.8%
distribute-frac-neg298.8%
*-commutative98.8%
frac-2neg98.8%
Applied egg-rr98.8%
Taylor expanded in f around 0 96.2%
*-commutative96.2%
associate-*r*96.2%
*-commutative96.2%
Simplified96.2%
Final simplification96.2%
(FPCore (f) :precision binary64 (* (log (/ 4.0 (* f PI))) (/ -4.0 PI)))
double code(double f) {
return log((4.0 / (f * ((double) M_PI)))) * (-4.0 / ((double) M_PI));
}
public static double code(double f) {
return Math.log((4.0 / (f * Math.PI))) * (-4.0 / Math.PI);
}
def code(f): return math.log((4.0 / (f * math.pi))) * (-4.0 / math.pi)
function code(f) return Float64(log(Float64(4.0 / Float64(f * pi))) * Float64(-4.0 / pi)) end
function tmp = code(f) tmp = log((4.0 / (f * pi))) * (-4.0 / pi); end
code[f_] := N[(N[Log[N[(4.0 / N[(f * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-4.0 / Pi), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\log \left(\frac{4}{f \cdot \pi}\right) \cdot \frac{-4}{\pi}
\end{array}
Initial program 7.4%
Simplified98.4%
Taylor expanded in f around 0 95.7%
(FPCore (f) :precision binary64 (log 0.0))
double code(double f) {
return log(0.0);
}
real(8) function code(f)
real(8), intent (in) :: f
code = log(0.0d0)
end function
public static double code(double f) {
return Math.log(0.0);
}
def code(f): return math.log(0.0)
function code(f) return log(0.0) end
function tmp = code(f) tmp = log(0.0); end
code[f_] := N[Log[0.0], $MachinePrecision]
\begin{array}{l}
\\
\log 0
\end{array}
Initial program 7.4%
associate-*l/7.4%
Applied egg-rr98.8%
neg-mul-198.8%
*-commutative98.8%
times-frac98.8%
metadata-eval98.8%
*-commutative98.8%
Simplified98.8%
metadata-eval98.8%
times-frac98.8%
*-commutative98.8%
neg-mul-198.8%
*-commutative98.8%
associate-/r*98.8%
distribute-neg-frac98.8%
distribute-frac-neg298.8%
*-commutative98.8%
frac-2neg98.8%
Applied egg-rr98.8%
Applied egg-rr3.1%
+-inverses3.1%
Simplified3.1%
*-un-lft-identity3.1%
div-inv3.1%
metadata-eval3.1%
Applied egg-rr3.1%
*-lft-identity3.1%
log1p-expm13.1%
log1p-define3.1%
rem-exp-log3.1%
log1p-define3.1%
log1p-expm13.1%
exp-prod3.1%
*-rgt-identity3.1%
associate-*r/3.1%
exp-to-pow3.1%
pow-base-03.1%
metadata-eval3.1%
Simplified3.1%
(FPCore (f) :precision binary64 (/ (/ 0.0 PI) 0.25))
double code(double f) {
return (0.0 / ((double) M_PI)) / 0.25;
}
public static double code(double f) {
return (0.0 / Math.PI) / 0.25;
}
def code(f): return (0.0 / math.pi) / 0.25
function code(f) return Float64(Float64(0.0 / pi) / 0.25) end
function tmp = code(f) tmp = (0.0 / pi) / 0.25; end
code[f_] := N[(N[(0.0 / Pi), $MachinePrecision] / 0.25), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{0}{\pi}}{0.25}
\end{array}
Initial program 7.4%
associate-*l/7.4%
Applied egg-rr98.8%
neg-mul-198.8%
*-commutative98.8%
times-frac98.8%
metadata-eval98.8%
*-commutative98.8%
Simplified98.8%
metadata-eval98.8%
times-frac98.8%
*-commutative98.8%
neg-mul-198.8%
*-commutative98.8%
associate-/r*98.8%
distribute-neg-frac98.8%
distribute-frac-neg298.8%
*-commutative98.8%
frac-2neg98.8%
Applied egg-rr98.8%
add-exp-log98.8%
add-sqr-sqrt1.2%
sqrt-unprod2.7%
sqr-neg2.7%
log-rec2.7%
log-rec2.7%
sqrt-unprod2.7%
add-sqr-sqrt2.7%
add-exp-log2.7%
add-sqr-sqrt2.7%
Applied egg-rr4.2%
*-inverses4.2%
Simplified4.2%
Final simplification4.2%
herbie shell --seed 2024177
(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)))))))))