
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= eps_m 7500000000000.0)
(/ (fma (+ 1.0 x) (exp (- x)) (/ (+ 1.0 x) (exp x))) 2.0)
(/
(-
(* (+ 1.0 (pow eps_m -1.0)) (exp (* x eps_m)))
(- (exp (- (fma x eps_m x)))))
2.0)))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 7500000000000.0) {
tmp = fma((1.0 + x), exp(-x), ((1.0 + x) / exp(x))) / 2.0;
} else {
tmp = (((1.0 + pow(eps_m, -1.0)) * exp((x * eps_m))) - -exp(-fma(x, eps_m, x))) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 7500000000000.0) tmp = Float64(fma(Float64(1.0 + x), exp(Float64(-x)), Float64(Float64(1.0 + x) / exp(x))) / 2.0); else tmp = Float64(Float64(Float64(Float64(1.0 + (eps_m ^ -1.0)) * exp(Float64(x * eps_m))) - Float64(-exp(Float64(-fma(x, eps_m, x))))) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 7500000000000.0], N[(N[(N[(1.0 + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(1.0 + N[Power[eps$95$m, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - (-N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 7500000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(1 + x, e^{-x}, \frac{1 + x}{e^{x}}\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + {eps\_m}^{-1}\right) \cdot e^{x \cdot eps\_m} - \left(-e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right)}{2}\\
\end{array}
\end{array}
if eps < 7.5e12Initial program 60.2%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6471.9
Applied rewrites71.9%
if 7.5e12 < eps Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification79.7%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= eps_m 82000000000000.0)
(/ (fma (+ 1.0 x) (exp (- x)) (/ (+ 1.0 x) (exp x))) 2.0)
(if (<= eps_m 5.6e+125)
(/ (- (/ (- eps_m -1.0) eps_m) (- (exp (- (fma x eps_m x))))) 2.0)
(/ (- (* (+ 1.0 (pow eps_m -1.0)) (exp (* x eps_m))) -1.0) 2.0))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 82000000000000.0) {
tmp = fma((1.0 + x), exp(-x), ((1.0 + x) / exp(x))) / 2.0;
} else if (eps_m <= 5.6e+125) {
tmp = (((eps_m - -1.0) / eps_m) - -exp(-fma(x, eps_m, x))) / 2.0;
} else {
tmp = (((1.0 + pow(eps_m, -1.0)) * exp((x * eps_m))) - -1.0) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 82000000000000.0) tmp = Float64(fma(Float64(1.0 + x), exp(Float64(-x)), Float64(Float64(1.0 + x) / exp(x))) / 2.0); elseif (eps_m <= 5.6e+125) tmp = Float64(Float64(Float64(Float64(eps_m - -1.0) / eps_m) - Float64(-exp(Float64(-fma(x, eps_m, x))))) / 2.0); else tmp = Float64(Float64(Float64(Float64(1.0 + (eps_m ^ -1.0)) * exp(Float64(x * eps_m))) - -1.0) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 82000000000000.0], N[(N[(N[(1.0 + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps$95$m, 5.6e+125], N[(N[(N[(N[(eps$95$m - -1.0), $MachinePrecision] / eps$95$m), $MachinePrecision] - (-N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(1.0 + N[Power[eps$95$m, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 82000000000000:\\
\;\;\;\;\frac{\mathsf{fma}\left(1 + x, e^{-x}, \frac{1 + x}{e^{x}}\right)}{2}\\
\mathbf{elif}\;eps\_m \leq 5.6 \cdot 10^{+125}:\\
\;\;\;\;\frac{\frac{eps\_m - -1}{eps\_m} - \left(-e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + {eps\_m}^{-1}\right) \cdot e^{x \cdot eps\_m} - -1}{2}\\
\end{array}
\end{array}
if eps < 8.2e13Initial program 60.2%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6471.9
Applied rewrites71.9%
if 8.2e13 < eps < 5.6000000000000002e125Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6474.2
Applied rewrites74.2%
if 5.6000000000000002e125 < eps Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites58.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6458.8
Applied rewrites58.8%
Final simplification70.1%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= eps_m 82000000000000.0)
(/ (* (exp (- x)) (+ (+ x 1.0) (+ x 1.0))) 2.0)
(if (<= eps_m 5.6e+125)
(/ (- (/ (- eps_m -1.0) eps_m) (- (exp (- (fma x eps_m x))))) 2.0)
(/ (- (* (+ 1.0 (pow eps_m -1.0)) (exp (* x eps_m))) -1.0) 2.0))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 82000000000000.0) {
tmp = (exp(-x) * ((x + 1.0) + (x + 1.0))) / 2.0;
} else if (eps_m <= 5.6e+125) {
tmp = (((eps_m - -1.0) / eps_m) - -exp(-fma(x, eps_m, x))) / 2.0;
} else {
tmp = (((1.0 + pow(eps_m, -1.0)) * exp((x * eps_m))) - -1.0) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 82000000000000.0) tmp = Float64(Float64(exp(Float64(-x)) * Float64(Float64(x + 1.0) + Float64(x + 1.0))) / 2.0); elseif (eps_m <= 5.6e+125) tmp = Float64(Float64(Float64(Float64(eps_m - -1.0) / eps_m) - Float64(-exp(Float64(-fma(x, eps_m, x))))) / 2.0); else tmp = Float64(Float64(Float64(Float64(1.0 + (eps_m ^ -1.0)) * exp(Float64(x * eps_m))) - -1.0) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 82000000000000.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(x + 1.0), $MachinePrecision] + N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[eps$95$m, 5.6e+125], N[(N[(N[(N[(eps$95$m - -1.0), $MachinePrecision] / eps$95$m), $MachinePrecision] - (-N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(1.0 + N[Power[eps$95$m, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * eps$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - -1.0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 82000000000000:\\
\;\;\;\;\frac{e^{-x} \cdot \left(\left(x + 1\right) + \left(x + 1\right)\right)}{2}\\
\mathbf{elif}\;eps\_m \leq 5.6 \cdot 10^{+125}:\\
\;\;\;\;\frac{\frac{eps\_m - -1}{eps\_m} - \left(-e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + {eps\_m}^{-1}\right) \cdot e^{x \cdot eps\_m} - -1}{2}\\
\end{array}
\end{array}
if eps < 8.2e13Initial program 60.2%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6471.9
Applied rewrites71.9%
Applied rewrites71.9%
if 8.2e13 < eps < 5.6000000000000002e125Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6474.2
Applied rewrites74.2%
if 5.6000000000000002e125 < eps Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites58.8%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f6458.8
Applied rewrites58.8%
Final simplification70.1%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= x 1.48e-5)
(/ (- 2.0 (* (fabs x) x)) 2.0)
(if (<= x 2.3e+153)
(/ (- (+ (pow eps_m -1.0) 1.0) (- (pow eps_m -1.0) 1.0)) 2.0)
(/ (fma (fma 0.6666666666666666 x -1.0) (* x x) 2.0) 2.0))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 1.48e-5) {
tmp = (2.0 - (fabs(x) * x)) / 2.0;
} else if (x <= 2.3e+153) {
tmp = ((pow(eps_m, -1.0) + 1.0) - (pow(eps_m, -1.0) - 1.0)) / 2.0;
} else {
tmp = fma(fma(0.6666666666666666, x, -1.0), (x * x), 2.0) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 1.48e-5) tmp = Float64(Float64(2.0 - Float64(abs(x) * x)) / 2.0); elseif (x <= 2.3e+153) tmp = Float64(Float64(Float64((eps_m ^ -1.0) + 1.0) - Float64((eps_m ^ -1.0) - 1.0)) / 2.0); else tmp = Float64(fma(fma(0.6666666666666666, x, -1.0), Float64(x * x), 2.0) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 1.48e-5], N[(N[(2.0 - N[(N[Abs[x], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 2.3e+153], N[(N[(N[(N[Power[eps$95$m, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[Power[eps$95$m, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.6666666666666666 * x + -1.0), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.48 \cdot 10^{-5}:\\
\;\;\;\;\frac{2 - \left|x\right| \cdot x}{2}\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+153}:\\
\;\;\;\;\frac{\left({eps\_m}^{-1} + 1\right) - \left({eps\_m}^{-1} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.6666666666666666, x, -1\right), x \cdot x, 2\right)}{2}\\
\end{array}
\end{array}
if x < 1.4800000000000001e-5Initial program 60.8%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6461.9
Applied rewrites61.9%
Taylor expanded in x around 0
Applied rewrites61.4%
Applied rewrites72.9%
if 1.4800000000000001e-5 < x < 2.3000000000000001e153Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6430.8
Applied rewrites30.8%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6451.6
Applied rewrites51.6%
if 2.3000000000000001e153 < x Initial program 100.0%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6440.9
Applied rewrites40.9%
Taylor expanded in x around 0
Applied rewrites60.6%
Final simplification68.3%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= x 1.4)
(/ (- 2.0 (* (fabs x) x)) 2.0)
(if (<= x 2.3e+153)
(/ (- (pow eps_m -1.0) (- (pow eps_m -1.0) 1.0)) 2.0)
(/ (fma (fma 0.6666666666666666 x -1.0) (* x x) 2.0) 2.0))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 1.4) {
tmp = (2.0 - (fabs(x) * x)) / 2.0;
} else if (x <= 2.3e+153) {
tmp = (pow(eps_m, -1.0) - (pow(eps_m, -1.0) - 1.0)) / 2.0;
} else {
tmp = fma(fma(0.6666666666666666, x, -1.0), (x * x), 2.0) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 1.4) tmp = Float64(Float64(2.0 - Float64(abs(x) * x)) / 2.0); elseif (x <= 2.3e+153) tmp = Float64(Float64((eps_m ^ -1.0) - Float64((eps_m ^ -1.0) - 1.0)) / 2.0); else tmp = Float64(fma(fma(0.6666666666666666, x, -1.0), Float64(x * x), 2.0) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 1.4], N[(N[(2.0 - N[(N[Abs[x], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 2.3e+153], N[(N[(N[Power[eps$95$m, -1.0], $MachinePrecision] - N[(N[Power[eps$95$m, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.6666666666666666 * x + -1.0), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;\frac{2 - \left|x\right| \cdot x}{2}\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+153}:\\
\;\;\;\;\frac{{eps\_m}^{-1} - \left({eps\_m}^{-1} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.6666666666666666, x, -1\right), x \cdot x, 2\right)}{2}\\
\end{array}
\end{array}
if x < 1.3999999999999999Initial program 61.0%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6461.6
Applied rewrites61.6%
Taylor expanded in x around 0
Applied rewrites61.1%
Applied rewrites72.5%
if 1.3999999999999999 < x < 2.3000000000000001e153Initial program 100.0%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6431.6
Applied rewrites31.6%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6452.9
Applied rewrites52.9%
Taylor expanded in eps around 0
Applied rewrites52.9%
if 2.3000000000000001e153 < x Initial program 100.0%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6440.9
Applied rewrites40.9%
Taylor expanded in x around 0
Applied rewrites60.6%
Final simplification68.3%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= eps_m 82000000000000.0) (/ (* (exp (- x)) (+ (+ x 1.0) (+ x 1.0))) 2.0) (/ (- (/ (- eps_m -1.0) eps_m) (- (exp (- (fma x eps_m x))))) 2.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 82000000000000.0) {
tmp = (exp(-x) * ((x + 1.0) + (x + 1.0))) / 2.0;
} else {
tmp = (((eps_m - -1.0) / eps_m) - -exp(-fma(x, eps_m, x))) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 82000000000000.0) tmp = Float64(Float64(exp(Float64(-x)) * Float64(Float64(x + 1.0) + Float64(x + 1.0))) / 2.0); else tmp = Float64(Float64(Float64(Float64(eps_m - -1.0) / eps_m) - Float64(-exp(Float64(-fma(x, eps_m, x))))) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 82000000000000.0], N[(N[(N[Exp[(-x)], $MachinePrecision] * N[(N[(x + 1.0), $MachinePrecision] + N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(eps$95$m - -1.0), $MachinePrecision] / eps$95$m), $MachinePrecision] - (-N[Exp[(-N[(x * eps$95$m + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 82000000000000:\\
\;\;\;\;\frac{e^{-x} \cdot \left(\left(x + 1\right) + \left(x + 1\right)\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{eps\_m - -1}{eps\_m} - \left(-e^{-\mathsf{fma}\left(x, eps\_m, x\right)}\right)}{2}\\
\end{array}
\end{array}
if eps < 8.2e13Initial program 60.2%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6471.9
Applied rewrites71.9%
Applied rewrites71.9%
if 8.2e13 < eps Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
+-commutativeN/A
metadata-evalN/A
sub-negN/A
lower--.f6461.3
Applied rewrites61.3%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x 4e+153) (/ (* (exp (- x)) 2.0) 2.0) (/ (fma (fma 0.6666666666666666 x -1.0) (* x x) 2.0) 2.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 4e+153) {
tmp = (exp(-x) * 2.0) / 2.0;
} else {
tmp = fma(fma(0.6666666666666666, x, -1.0), (x * x), 2.0) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 4e+153) tmp = Float64(Float64(exp(Float64(-x)) * 2.0) / 2.0); else tmp = Float64(fma(fma(0.6666666666666666, x, -1.0), Float64(x * x), 2.0) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 4e+153], N[(N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.6666666666666666 * x + -1.0), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4 \cdot 10^{+153}:\\
\;\;\;\;\frac{e^{-x} \cdot 2}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.6666666666666666, x, -1\right), x \cdot x, 2\right)}{2}\\
\end{array}
\end{array}
if x < 4e153Initial program 67.4%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6460.5
Applied rewrites60.5%
Applied rewrites60.5%
Taylor expanded in x around 0
Applied rewrites73.7%
if 4e153 < x Initial program 100.0%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6440.9
Applied rewrites40.9%
Taylor expanded in x around 0
Applied rewrites60.6%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x -3500.0) (/ (- 2.0 (* (fabs x) x)) 2.0) (/ (fma (fma 0.6666666666666666 x -1.0) (* x x) 2.0) 2.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -3500.0) {
tmp = (2.0 - (fabs(x) * x)) / 2.0;
} else {
tmp = fma(fma(0.6666666666666666, x, -1.0), (x * x), 2.0) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -3500.0) tmp = Float64(Float64(2.0 - Float64(abs(x) * x)) / 2.0); else tmp = Float64(fma(fma(0.6666666666666666, x, -1.0), Float64(x * x), 2.0) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -3500.0], N[(N[(2.0 - N[(N[Abs[x], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(0.6666666666666666 * x + -1.0), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3500:\\
\;\;\;\;\frac{2 - \left|x\right| \cdot x}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.6666666666666666, x, -1\right), x \cdot x, 2\right)}{2}\\
\end{array}
\end{array}
if x < -3500Initial program 100.0%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f640.0
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.1%
Applied rewrites67.5%
if -3500 < x Initial program 67.1%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6466.5
Applied rewrites66.5%
Taylor expanded in x around 0
Applied rewrites61.9%
Final simplification62.6%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (/ (- 2.0 (* (fabs x) x)) 2.0))
eps_m = fabs(eps);
double code(double x, double eps_m) {
return (2.0 - (fabs(x) * x)) / 2.0;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
code = (2.0d0 - (abs(x) * x)) / 2.0d0
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
return (2.0 - (Math.abs(x) * x)) / 2.0;
}
eps_m = math.fabs(eps) def code(x, eps_m): return (2.0 - (math.fabs(x) * x)) / 2.0
eps_m = abs(eps) function code(x, eps_m) return Float64(Float64(2.0 - Float64(abs(x) * x)) / 2.0) end
eps_m = abs(eps); function tmp = code(x, eps_m) tmp = (2.0 - (abs(x) * x)) / 2.0; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := N[(N[(2.0 - N[(N[Abs[x], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\frac{2 - \left|x\right| \cdot x}{2}
\end{array}
Initial program 71.2%
Taylor expanded in eps around 0
sub-negN/A
distribute-rgt1-inN/A
distribute-lft-outN/A
mul-1-negN/A
remove-double-negN/A
lower-fma.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
distribute-rgt1-inN/A
exp-negN/A
associate-*r/N/A
*-rgt-identityN/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-exp.f6458.2
Applied rewrites58.2%
Taylor expanded in x around 0
Applied rewrites45.4%
Applied rewrites53.8%
Final simplification53.8%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 1.0)
eps_m = fabs(eps);
double code(double x, double eps_m) {
return 1.0;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
code = 1.0d0
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
return 1.0;
}
eps_m = math.fabs(eps) def code(x, eps_m): return 1.0
eps_m = abs(eps) function code(x, eps_m) return 1.0 end
eps_m = abs(eps); function tmp = code(x, eps_m) tmp = 1.0; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := 1.0
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
1
\end{array}
Initial program 71.2%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f6469.3
Applied rewrites69.3%
Taylor expanded in x around 0
Applied rewrites46.3%
herbie shell --seed 2024305
(FPCore (x eps)
:name "NMSE Section 6.1 mentioned, A"
:precision binary64
(/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))