
(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 (* (* 0.25 f) PI))) 0.25) PI))
double code(double f) {
return (log(tanh(((0.25 * f) * ((double) M_PI)))) / 0.25) / ((double) M_PI);
}
public static double code(double f) {
return (Math.log(Math.tanh(((0.25 * f) * Math.PI))) / 0.25) / Math.PI;
}
def code(f): return (math.log(math.tanh(((0.25 * f) * math.pi))) / 0.25) / math.pi
function code(f) return Float64(Float64(log(tanh(Float64(Float64(0.25 * f) * pi))) / 0.25) / pi) end
function tmp = code(f) tmp = (log(tanh(((0.25 * f) * pi))) / 0.25) / pi; end
code[f_] := N[(N[(N[Log[N[Tanh[N[(N[(0.25 * f), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / 0.25), $MachinePrecision] / Pi), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{\log \tanh \left(\left(0.25 \cdot f\right) \cdot \pi\right)}{0.25}}{\pi}
\end{array}
Initial program 6.0%
distribute-lft-neg-in6.0%
distribute-neg-frac26.0%
associate-*l/6.0%
Simplified6.0%
add-cube-cbrt6.0%
log-prod6.0%
Applied egg-rr6.0%
Simplified99.1%
*-un-lft-identity99.1%
div-inv99.1%
times-frac99.0%
Applied egg-rr99.2%
associate-*l/99.3%
*-lft-identity99.3%
distribute-frac-neg99.3%
distribute-neg-frac299.3%
associate-*r*99.3%
*-commutative99.3%
associate-*r*99.3%
metadata-eval99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (f) :precision binary64 (if (<= f 1.3) (* (log (* 0.25 (* f PI))) (/ -4.0 (- PI))) 0.0))
double code(double f) {
double tmp;
if (f <= 1.3) {
tmp = log((0.25 * (f * ((double) M_PI)))) * (-4.0 / -((double) M_PI));
} else {
tmp = 0.0;
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.3) {
tmp = Math.log((0.25 * (f * Math.PI))) * (-4.0 / -Math.PI);
} else {
tmp = 0.0;
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.3: tmp = math.log((0.25 * (f * math.pi))) * (-4.0 / -math.pi) else: tmp = 0.0 return tmp
function code(f) tmp = 0.0 if (f <= 1.3) tmp = Float64(log(Float64(0.25 * Float64(f * pi))) * Float64(-4.0 / Float64(-pi))); else tmp = 0.0; end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.3) tmp = log((0.25 * (f * pi))) * (-4.0 / -pi); else tmp = 0.0; end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.3], N[(N[Log[N[(0.25 * N[(f * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(-4.0 / (-Pi)), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.3:\\
\;\;\;\;\log \left(0.25 \cdot \left(f \cdot \pi\right)\right) \cdot \frac{-4}{-\pi}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if f < 1.30000000000000004Initial program 6.1%
Taylor expanded in f around 0 98.5%
distribute-rgt-out--98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in f around 0 98.5%
div-inv98.5%
metadata-eval98.5%
associate-*l/98.7%
*-un-lft-identity98.7%
metadata-eval98.7%
div-inv98.7%
frac-2neg98.7%
metadata-eval98.7%
associate-/r/98.7%
clear-num98.7%
log-rec98.7%
div-inv98.7%
metadata-eval98.7%
associate-*r*98.7%
frac-2neg98.7%
Applied egg-rr98.5%
associate-/r/98.5%
associate-*r*98.5%
*-commutative98.5%
associate-*r*98.5%
associate-*l/98.5%
metadata-eval98.5%
Simplified98.5%
if 1.30000000000000004 < f Initial program 5.2%
distribute-lft-neg-in5.2%
distribute-neg-frac25.2%
associate-*l/5.2%
Simplified5.2%
Taylor expanded in f around inf 5.2%
Simplified93.3%
Applied egg-rr87.9%
Final simplification98.2%
(FPCore (f) :precision binary64 (if (<= f 1.3) (/ (* -4.0 (log (* f (* 0.25 PI)))) (- PI)) 0.0))
double code(double f) {
double tmp;
if (f <= 1.3) {
tmp = (-4.0 * log((f * (0.25 * ((double) M_PI))))) / -((double) M_PI);
} else {
tmp = 0.0;
}
return tmp;
}
public static double code(double f) {
double tmp;
if (f <= 1.3) {
tmp = (-4.0 * Math.log((f * (0.25 * Math.PI)))) / -Math.PI;
} else {
tmp = 0.0;
}
return tmp;
}
def code(f): tmp = 0 if f <= 1.3: tmp = (-4.0 * math.log((f * (0.25 * math.pi)))) / -math.pi else: tmp = 0.0 return tmp
function code(f) tmp = 0.0 if (f <= 1.3) tmp = Float64(Float64(-4.0 * log(Float64(f * Float64(0.25 * pi)))) / Float64(-pi)); else tmp = 0.0; end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 1.3) tmp = (-4.0 * log((f * (0.25 * pi)))) / -pi; else tmp = 0.0; end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 1.3], N[(N[(-4.0 * N[Log[N[(f * N[(0.25 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / (-Pi)), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 1.3:\\
\;\;\;\;\frac{-4 \cdot \log \left(f \cdot \left(0.25 \cdot \pi\right)\right)}{-\pi}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if f < 1.30000000000000004Initial program 6.1%
add-sqr-sqrt6.1%
pow26.1%
Applied egg-rr99.1%
Taylor expanded in f around 0 98.3%
unpow298.3%
add-sqr-sqrt98.7%
associate-*r/98.7%
sum-log98.7%
*-commutative98.7%
Applied egg-rr98.7%
if 1.30000000000000004 < f Initial program 5.2%
distribute-lft-neg-in5.2%
distribute-neg-frac25.2%
associate-*l/5.2%
Simplified5.2%
Taylor expanded in f around inf 5.2%
Simplified93.3%
Applied egg-rr87.9%
Final simplification98.4%
(FPCore (f) :precision binary64 (if (<= f 230.0) -16.0 0.0))
double code(double f) {
double tmp;
if (f <= 230.0) {
tmp = -16.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(f)
real(8), intent (in) :: f
real(8) :: tmp
if (f <= 230.0d0) then
tmp = -16.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double f) {
double tmp;
if (f <= 230.0) {
tmp = -16.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(f): tmp = 0 if f <= 230.0: tmp = -16.0 else: tmp = 0.0 return tmp
function code(f) tmp = 0.0 if (f <= 230.0) tmp = -16.0; else tmp = 0.0; end return tmp end
function tmp_2 = code(f) tmp = 0.0; if (f <= 230.0) tmp = -16.0; else tmp = 0.0; end tmp_2 = tmp; end
code[f_] := If[LessEqual[f, 230.0], -16.0, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;f \leq 230:\\
\;\;\;\;-16\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if f < 230Initial program 6.2%
distribute-lft-neg-in6.2%
distribute-neg-frac26.2%
associate-*l/6.2%
Simplified6.2%
Taylor expanded in f around inf 6.2%
Simplified99.3%
Applied egg-rr15.6%
if 230 < f Initial program 0.0%
distribute-lft-neg-in0.0%
distribute-neg-frac20.0%
associate-*l/0.0%
Simplified0.0%
Taylor expanded in f around inf 0.0%
Simplified100.0%
Applied egg-rr100.0%
Final simplification17.9%
(FPCore (f) :precision binary64 -16.0)
double code(double f) {
return -16.0;
}
real(8) function code(f)
real(8), intent (in) :: f
code = -16.0d0
end function
public static double code(double f) {
return -16.0;
}
def code(f): return -16.0
function code(f) return -16.0 end
function tmp = code(f) tmp = -16.0; end
code[f_] := -16.0
\begin{array}{l}
\\
-16
\end{array}
Initial program 6.0%
distribute-lft-neg-in6.0%
distribute-neg-frac26.0%
associate-*l/6.0%
Simplified6.0%
Taylor expanded in f around inf 6.0%
Simplified99.3%
Applied egg-rr15.2%
Final simplification15.2%
herbie shell --seed 2024080
(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)))))))))