
(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 12 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 (* 0.5 (fma (exp (* x (* 0.5 (- -1.0 eps_m)))) (exp (* x (* eps_m -0.5))) (exp (- (* eps_m x) x)))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
return 0.5 * fma(exp((x * (0.5 * (-1.0 - eps_m)))), exp((x * (eps_m * -0.5))), exp(((eps_m * x) - x)));
}
eps_m = abs(eps) function code(x, eps_m) return Float64(0.5 * fma(exp(Float64(x * Float64(0.5 * Float64(-1.0 - eps_m)))), exp(Float64(x * Float64(eps_m * -0.5))), exp(Float64(Float64(eps_m * x) - x)))) end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := N[(0.5 * N[(N[Exp[N[(x * N[(0.5 * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(x * N[(eps$95$m * -0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(N[(eps$95$m * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
0.5 \cdot \mathsf{fma}\left(e^{x \cdot \left(0.5 \cdot \left(-1 - eps\_m\right)\right)}, e^{x \cdot \left(eps\_m \cdot -0.5\right)}, e^{eps\_m \cdot x - x}\right)
\end{array}
Initial program 79.5%
Taylor expanded in eps around inf
lower-*.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f64N/A
Applied rewrites99.0%
Applied rewrites99.0%
Applied rewrites99.0%
Taylor expanded in eps around inf
Applied rewrites94.3%
Final simplification94.3%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<=
(+
(* (+ 1.0 (/ 1.0 eps_m)) (exp (* x (+ eps_m -1.0))))
(* (exp (* x (- -1.0 eps_m))) (+ 1.0 (/ -1.0 eps_m))))
2.0000004)
(* 0.5 (* 2.0 (* (exp (- x)) (+ 1.0 x))))
(fma
x
(fma
x
(*
0.25
(fma
(+ 1.0 eps_m)
(+ 1.0 eps_m)
(/ (* (fma eps_m eps_m -1.0) (+ eps_m -1.0)) (+ 1.0 eps_m))))
(fma (+ eps_m (- -1.0 eps_m)) 0.5 -0.5))
1.0)))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if ((((1.0 + (1.0 / eps_m)) * exp((x * (eps_m + -1.0)))) + (exp((x * (-1.0 - eps_m))) * (1.0 + (-1.0 / eps_m)))) <= 2.0000004) {
tmp = 0.5 * (2.0 * (exp(-x) * (1.0 + x)));
} else {
tmp = fma(x, fma(x, (0.25 * fma((1.0 + eps_m), (1.0 + eps_m), ((fma(eps_m, eps_m, -1.0) * (eps_m + -1.0)) / (1.0 + eps_m)))), fma((eps_m + (-1.0 - eps_m)), 0.5, -0.5)), 1.0);
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps_m)) * exp(Float64(x * Float64(eps_m + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps_m))) * Float64(1.0 + Float64(-1.0 / eps_m)))) <= 2.0000004) tmp = Float64(0.5 * Float64(2.0 * Float64(exp(Float64(-x)) * Float64(1.0 + x)))); else tmp = fma(x, fma(x, Float64(0.25 * fma(Float64(1.0 + eps_m), Float64(1.0 + eps_m), Float64(Float64(fma(eps_m, eps_m, -1.0) * Float64(eps_m + -1.0)) / Float64(1.0 + eps_m)))), fma(Float64(eps_m + Float64(-1.0 - eps_m)), 0.5, -0.5)), 1.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps$95$m + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0000004], N[(0.5 * N[(2.0 * N[(N[Exp[(-x)], $MachinePrecision] * N[(1.0 + x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(x * N[(0.25 * N[(N[(1.0 + eps$95$m), $MachinePrecision] * N[(1.0 + eps$95$m), $MachinePrecision] + N[(N[(N[(eps$95$m * eps$95$m + -1.0), $MachinePrecision] * N[(eps$95$m + -1.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 + eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps$95$m + N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision] * 0.5 + -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + \frac{1}{eps\_m}\right) \cdot e^{x \cdot \left(eps\_m + -1\right)} + e^{x \cdot \left(-1 - eps\_m\right)} \cdot \left(1 + \frac{-1}{eps\_m}\right) \leq 2.0000004:\\
\;\;\;\;0.5 \cdot \left(2 \cdot \left(e^{-x} \cdot \left(1 + x\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.25 \cdot \mathsf{fma}\left(1 + eps\_m, 1 + eps\_m, \frac{\mathsf{fma}\left(eps\_m, eps\_m, -1\right) \cdot \left(eps\_m + -1\right)}{1 + eps\_m}\right), \mathsf{fma}\left(eps\_m + \left(-1 - eps\_m\right), 0.5, -0.5\right)\right), 1\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 2.00000039999999979Initial program 63.6%
Taylor expanded in eps around 0
lower-*.f64N/A
distribute-lft-outN/A
cancel-sign-sub-invN/A
metadata-evalN/A
distribute-rgt1-inN/A
metadata-evalN/A
lower-*.f64N/A
distribute-rgt1-inN/A
*-commutativeN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
lower-+.f6499.6
Applied rewrites99.6%
if 2.00000039999999979 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) Initial program 99.1%
Taylor expanded in eps around inf
lower-*.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f64N/A
Applied rewrites99.1%
Applied rewrites99.1%
Taylor expanded in x around 0
Applied rewrites86.6%
Applied rewrites92.4%
Final simplification96.4%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<=
(+
(* (+ 1.0 (/ 1.0 eps_m)) (exp (* x (+ eps_m -1.0))))
(* (exp (* x (- -1.0 eps_m))) (+ 1.0 (/ -1.0 eps_m))))
2.0000004)
(exp (- x))
(fma
x
(fma
x
(*
0.25
(fma
(+ 1.0 eps_m)
(+ 1.0 eps_m)
(/ (* (fma eps_m eps_m -1.0) (+ eps_m -1.0)) (+ 1.0 eps_m))))
(fma (+ eps_m (- -1.0 eps_m)) 0.5 -0.5))
1.0)))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if ((((1.0 + (1.0 / eps_m)) * exp((x * (eps_m + -1.0)))) + (exp((x * (-1.0 - eps_m))) * (1.0 + (-1.0 / eps_m)))) <= 2.0000004) {
tmp = exp(-x);
} else {
tmp = fma(x, fma(x, (0.25 * fma((1.0 + eps_m), (1.0 + eps_m), ((fma(eps_m, eps_m, -1.0) * (eps_m + -1.0)) / (1.0 + eps_m)))), fma((eps_m + (-1.0 - eps_m)), 0.5, -0.5)), 1.0);
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps_m)) * exp(Float64(x * Float64(eps_m + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps_m))) * Float64(1.0 + Float64(-1.0 / eps_m)))) <= 2.0000004) tmp = exp(Float64(-x)); else tmp = fma(x, fma(x, Float64(0.25 * fma(Float64(1.0 + eps_m), Float64(1.0 + eps_m), Float64(Float64(fma(eps_m, eps_m, -1.0) * Float64(eps_m + -1.0)) / Float64(1.0 + eps_m)))), fma(Float64(eps_m + Float64(-1.0 - eps_m)), 0.5, -0.5)), 1.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps$95$m + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0000004], N[Exp[(-x)], $MachinePrecision], N[(x * N[(x * N[(0.25 * N[(N[(1.0 + eps$95$m), $MachinePrecision] * N[(1.0 + eps$95$m), $MachinePrecision] + N[(N[(N[(eps$95$m * eps$95$m + -1.0), $MachinePrecision] * N[(eps$95$m + -1.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 + eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps$95$m + N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision] * 0.5 + -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + \frac{1}{eps\_m}\right) \cdot e^{x \cdot \left(eps\_m + -1\right)} + e^{x \cdot \left(-1 - eps\_m\right)} \cdot \left(1 + \frac{-1}{eps\_m}\right) \leq 2.0000004:\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.25 \cdot \mathsf{fma}\left(1 + eps\_m, 1 + eps\_m, \frac{\mathsf{fma}\left(eps\_m, eps\_m, -1\right) \cdot \left(eps\_m + -1\right)}{1 + eps\_m}\right), \mathsf{fma}\left(eps\_m + \left(-1 - eps\_m\right), 0.5, -0.5\right)\right), 1\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 2.00000039999999979Initial program 63.6%
Taylor expanded in eps around inf
lower-*.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f64N/A
Applied rewrites98.9%
Taylor expanded in eps around 0
Applied rewrites98.6%
if 2.00000039999999979 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) Initial program 99.1%
Taylor expanded in eps around inf
lower-*.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f64N/A
Applied rewrites99.1%
Applied rewrites99.1%
Taylor expanded in x around 0
Applied rewrites86.6%
Applied rewrites92.4%
Final simplification95.8%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<=
(+
(* (+ 1.0 (/ 1.0 eps_m)) (exp (* x (+ eps_m -1.0))))
(* (exp (* x (- -1.0 eps_m))) (+ 1.0 (/ -1.0 eps_m))))
2.0000004)
1.0
(fma 0.5 (/ (* eps_m (* (fma eps_m eps_m -1.0) (* x x))) eps_m) 1.0)))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if ((((1.0 + (1.0 / eps_m)) * exp((x * (eps_m + -1.0)))) + (exp((x * (-1.0 - eps_m))) * (1.0 + (-1.0 / eps_m)))) <= 2.0000004) {
tmp = 1.0;
} else {
tmp = fma(0.5, ((eps_m * (fma(eps_m, eps_m, -1.0) * (x * x))) / eps_m), 1.0);
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps_m)) * exp(Float64(x * Float64(eps_m + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps_m))) * Float64(1.0 + Float64(-1.0 / eps_m)))) <= 2.0000004) tmp = 1.0; else tmp = fma(0.5, Float64(Float64(eps_m * Float64(fma(eps_m, eps_m, -1.0) * Float64(x * x))) / eps_m), 1.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps$95$m + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0000004], 1.0, N[(0.5 * N[(N[(eps$95$m * N[(N[(eps$95$m * eps$95$m + -1.0), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / eps$95$m), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + \frac{1}{eps\_m}\right) \cdot e^{x \cdot \left(eps\_m + -1\right)} + e^{x \cdot \left(-1 - eps\_m\right)} \cdot \left(1 + \frac{-1}{eps\_m}\right) \leq 2.0000004:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{eps\_m \cdot \left(\mathsf{fma}\left(eps\_m, eps\_m, -1\right) \cdot \left(x \cdot x\right)\right)}{eps\_m}, 1\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 2.00000039999999979Initial program 63.6%
Taylor expanded in x around 0
Applied rewrites65.8%
if 2.00000039999999979 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) Initial program 99.1%
Taylor expanded in x around 0
Applied rewrites79.4%
Taylor expanded in eps around 0
Applied rewrites84.9%
Taylor expanded in eps around 0
Applied rewrites87.1%
Final simplification75.4%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<=
(+
(* (+ 1.0 (/ 1.0 eps_m)) (exp (* x (+ eps_m -1.0))))
(* (exp (* x (- -1.0 eps_m))) (+ 1.0 (/ -1.0 eps_m))))
2.0000004)
1.0
(fma 0.5 (* x (* x (* eps_m eps_m))) 1.0)))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if ((((1.0 + (1.0 / eps_m)) * exp((x * (eps_m + -1.0)))) + (exp((x * (-1.0 - eps_m))) * (1.0 + (-1.0 / eps_m)))) <= 2.0000004) {
tmp = 1.0;
} else {
tmp = fma(0.5, (x * (x * (eps_m * eps_m))), 1.0);
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps_m)) * exp(Float64(x * Float64(eps_m + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps_m))) * Float64(1.0 + Float64(-1.0 / eps_m)))) <= 2.0000004) tmp = 1.0; else tmp = fma(0.5, Float64(x * Float64(x * Float64(eps_m * eps_m))), 1.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps$95$m + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0000004], 1.0, N[(0.5 * N[(x * N[(x * N[(eps$95$m * eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + \frac{1}{eps\_m}\right) \cdot e^{x \cdot \left(eps\_m + -1\right)} + e^{x \cdot \left(-1 - eps\_m\right)} \cdot \left(1 + \frac{-1}{eps\_m}\right) \leq 2.0000004:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x \cdot \left(x \cdot \left(eps\_m \cdot eps\_m\right)\right), 1\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) < 2.00000039999999979Initial program 63.6%
Taylor expanded in x around 0
Applied rewrites65.8%
if 2.00000039999999979 < (-.f64 (*.f64 (+.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 #s(literal 1 binary64) eps) x)))) (*.f64 (-.f64 (/.f64 #s(literal 1 binary64) eps) #s(literal 1 binary64)) (exp.f64 (neg.f64 (*.f64 (+.f64 #s(literal 1 binary64) eps) x))))) Initial program 99.1%
Taylor expanded in x around 0
Applied rewrites79.4%
Taylor expanded in eps around inf
Applied rewrites86.6%
Final simplification75.2%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (* 0.5 (+ (exp (fma x eps_m (- x))) (exp (* x (- -1.0 eps_m))))))
eps_m = fabs(eps);
double code(double x, double eps_m) {
return 0.5 * (exp(fma(x, eps_m, -x)) + exp((x * (-1.0 - eps_m))));
}
eps_m = abs(eps) function code(x, eps_m) return Float64(0.5 * Float64(exp(fma(x, eps_m, Float64(-x))) + exp(Float64(x * Float64(-1.0 - eps_m))))) end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := N[(0.5 * N[(N[Exp[N[(x * eps$95$m + (-x)), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(x * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
0.5 \cdot \left(e^{\mathsf{fma}\left(x, eps\_m, -x\right)} + e^{x \cdot \left(-1 - eps\_m\right)}\right)
\end{array}
Initial program 79.5%
Taylor expanded in eps around inf
lower-*.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f64N/A
Applied rewrites99.0%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= x 1.85e-147)
(fma
0.5
(/
(fma
eps_m
(fma x (* -0.5 (+ x x)) (* eps_m (fma (* eps_m x) x (* x (- x x)))))
(- x (* x (+ 1.0 (- x x)))))
eps_m)
1.0)
(if (<= x 4200.0)
(fma
x
(fma
x
(*
0.25
(fma
(+ 1.0 eps_m)
(+ 1.0 eps_m)
(/ (* (fma eps_m eps_m -1.0) (+ eps_m -1.0)) (+ 1.0 eps_m))))
(fma (+ eps_m (- -1.0 eps_m)) 0.5 -0.5))
1.0)
(/ (- (+ 1.0 (/ 1.0 eps_m)) (+ -1.0 (/ 1.0 eps_m))) 2.0))))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 1.85e-147) {
tmp = fma(0.5, (fma(eps_m, fma(x, (-0.5 * (x + x)), (eps_m * fma((eps_m * x), x, (x * (x - x))))), (x - (x * (1.0 + (x - x))))) / eps_m), 1.0);
} else if (x <= 4200.0) {
tmp = fma(x, fma(x, (0.25 * fma((1.0 + eps_m), (1.0 + eps_m), ((fma(eps_m, eps_m, -1.0) * (eps_m + -1.0)) / (1.0 + eps_m)))), fma((eps_m + (-1.0 - eps_m)), 0.5, -0.5)), 1.0);
} else {
tmp = ((1.0 + (1.0 / eps_m)) - (-1.0 + (1.0 / eps_m))) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 1.85e-147) tmp = fma(0.5, Float64(fma(eps_m, fma(x, Float64(-0.5 * Float64(x + x)), Float64(eps_m * fma(Float64(eps_m * x), x, Float64(x * Float64(x - x))))), Float64(x - Float64(x * Float64(1.0 + Float64(x - x))))) / eps_m), 1.0); elseif (x <= 4200.0) tmp = fma(x, fma(x, Float64(0.25 * fma(Float64(1.0 + eps_m), Float64(1.0 + eps_m), Float64(Float64(fma(eps_m, eps_m, -1.0) * Float64(eps_m + -1.0)) / Float64(1.0 + eps_m)))), fma(Float64(eps_m + Float64(-1.0 - eps_m)), 0.5, -0.5)), 1.0); else tmp = Float64(Float64(Float64(1.0 + Float64(1.0 / eps_m)) - Float64(-1.0 + Float64(1.0 / eps_m))) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 1.85e-147], N[(0.5 * N[(N[(eps$95$m * N[(x * N[(-0.5 * N[(x + x), $MachinePrecision]), $MachinePrecision] + N[(eps$95$m * N[(N[(eps$95$m * x), $MachinePrecision] * x + N[(x * N[(x - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(x - N[(x * N[(1.0 + N[(x - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / eps$95$m), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 4200.0], N[(x * N[(x * N[(0.25 * N[(N[(1.0 + eps$95$m), $MachinePrecision] * N[(1.0 + eps$95$m), $MachinePrecision] + N[(N[(N[(eps$95$m * eps$95$m + -1.0), $MachinePrecision] * N[(eps$95$m + -1.0), $MachinePrecision]), $MachinePrecision] / N[(1.0 + eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(eps$95$m + N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision] * 0.5 + -0.5), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] - N[(-1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.85 \cdot 10^{-147}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \frac{\mathsf{fma}\left(eps\_m, \mathsf{fma}\left(x, -0.5 \cdot \left(x + x\right), eps\_m \cdot \mathsf{fma}\left(eps\_m \cdot x, x, x \cdot \left(x - x\right)\right)\right), x - x \cdot \left(1 + \left(x - x\right)\right)\right)}{eps\_m}, 1\right)\\
\mathbf{elif}\;x \leq 4200:\\
\;\;\;\;\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.25 \cdot \mathsf{fma}\left(1 + eps\_m, 1 + eps\_m, \frac{\mathsf{fma}\left(eps\_m, eps\_m, -1\right) \cdot \left(eps\_m + -1\right)}{1 + eps\_m}\right), \mathsf{fma}\left(eps\_m + \left(-1 - eps\_m\right), 0.5, -0.5\right)\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{eps\_m}\right) - \left(-1 + \frac{1}{eps\_m}\right)}{2}\\
\end{array}
\end{array}
if x < 1.8500000000000001e-147Initial program 70.6%
Taylor expanded in x around 0
Applied rewrites89.7%
Taylor expanded in eps around 0
Applied rewrites91.3%
Applied rewrites92.9%
if 1.8500000000000001e-147 < x < 4200Initial program 67.7%
Taylor expanded in eps around inf
lower-*.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f64N/A
Applied rewrites97.6%
Applied rewrites97.7%
Taylor expanded in x around 0
Applied rewrites81.4%
Applied rewrites94.2%
if 4200 < x Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6424.1
Applied rewrites24.1%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
lower-/.f6458.1
Applied rewrites58.1%
Final simplification82.1%
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= x 9.5e+14)
(fma
0.5
(*
x
(/ (+ 1.0 (fma eps_m (fma eps_m (fma x eps_m 0.0) (- x)) -1.0)) eps_m))
1.0)
(/ (- (+ 1.0 (/ 1.0 eps_m)) (+ -1.0 (/ 1.0 eps_m))) 2.0)))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 9.5e+14) {
tmp = fma(0.5, (x * ((1.0 + fma(eps_m, fma(eps_m, fma(x, eps_m, 0.0), -x), -1.0)) / eps_m)), 1.0);
} else {
tmp = ((1.0 + (1.0 / eps_m)) - (-1.0 + (1.0 / eps_m))) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 9.5e+14) tmp = fma(0.5, Float64(x * Float64(Float64(1.0 + fma(eps_m, fma(eps_m, fma(x, eps_m, 0.0), Float64(-x)), -1.0)) / eps_m)), 1.0); else tmp = Float64(Float64(Float64(1.0 + Float64(1.0 / eps_m)) - Float64(-1.0 + Float64(1.0 / eps_m))) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 9.5e+14], N[(0.5 * N[(x * N[(N[(1.0 + N[(eps$95$m * N[(eps$95$m * N[(x * eps$95$m + 0.0), $MachinePrecision] + (-x)), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision] / eps$95$m), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] - N[(-1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 9.5 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x \cdot \frac{1 + \mathsf{fma}\left(eps\_m, \mathsf{fma}\left(eps\_m, \mathsf{fma}\left(x, eps\_m, 0\right), -x\right), -1\right)}{eps\_m}, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{eps\_m}\right) - \left(-1 + \frac{1}{eps\_m}\right)}{2}\\
\end{array}
\end{array}
if x < 9.5e14Initial program 70.4%
Taylor expanded in x around 0
Applied rewrites85.8%
Taylor expanded in eps around inf
Applied rewrites72.3%
Taylor expanded in eps around 0
Applied rewrites89.4%
if 9.5e14 < x Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6424.7
Applied rewrites24.7%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
lower-/.f6458.3
Applied rewrites58.3%
Final simplification79.8%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x 5.3e+14) (fma 0.5 (* x (* x (* eps_m eps_m))) 1.0) (/ (- (+ 1.0 (/ 1.0 eps_m)) (+ -1.0 (/ 1.0 eps_m))) 2.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 5.3e+14) {
tmp = fma(0.5, (x * (x * (eps_m * eps_m))), 1.0);
} else {
tmp = ((1.0 + (1.0 / eps_m)) - (-1.0 + (1.0 / eps_m))) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 5.3e+14) tmp = fma(0.5, Float64(x * Float64(x * Float64(eps_m * eps_m))), 1.0); else tmp = Float64(Float64(Float64(1.0 + Float64(1.0 / eps_m)) - Float64(-1.0 + Float64(1.0 / eps_m))) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 5.3e+14], N[(0.5 * N[(x * N[(x * N[(eps$95$m * eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(N[(1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision] - N[(-1.0 + N[(1.0 / eps$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.3 \cdot 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(0.5, x \cdot \left(x \cdot \left(eps\_m \cdot eps\_m\right)\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(1 + \frac{1}{eps\_m}\right) - \left(-1 + \frac{1}{eps\_m}\right)}{2}\\
\end{array}
\end{array}
if x < 5.3e14Initial program 70.4%
Taylor expanded in x around 0
Applied rewrites85.8%
Taylor expanded in eps around inf
Applied rewrites86.2%
if 5.3e14 < x Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f6424.7
Applied rewrites24.7%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
lower-+.f64N/A
lower-/.f6458.3
Applied rewrites58.3%
Final simplification77.6%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (fma 0.5 (* eps_m (* eps_m (* x x))) 1.0))
eps_m = fabs(eps);
double code(double x, double eps_m) {
return fma(0.5, (eps_m * (eps_m * (x * x))), 1.0);
}
eps_m = abs(eps) function code(x, eps_m) return fma(0.5, Float64(eps_m * Float64(eps_m * Float64(x * x))), 1.0) end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := N[(0.5 * N[(eps$95$m * N[(eps$95$m * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\mathsf{fma}\left(0.5, eps\_m \cdot \left(eps\_m \cdot \left(x \cdot x\right)\right), 1\right)
\end{array}
Initial program 79.5%
Taylor expanded in x around 0
Applied rewrites71.8%
Taylor expanded in eps around 0
Applied rewrites37.0%
Taylor expanded in eps around inf
Applied rewrites69.2%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (fma x (fma x 0.5 -1.0) 1.0))
eps_m = fabs(eps);
double code(double x, double eps_m) {
return fma(x, fma(x, 0.5, -1.0), 1.0);
}
eps_m = abs(eps) function code(x, eps_m) return fma(x, fma(x, 0.5, -1.0), 1.0) end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := N[(x * N[(x * 0.5 + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.5, -1\right), 1\right)
\end{array}
Initial program 79.5%
Taylor expanded in eps around inf
lower-*.f64N/A
cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower-+.f64N/A
Applied rewrites99.0%
Applied rewrites99.0%
Taylor expanded in x around 0
Applied rewrites72.0%
Taylor expanded in eps around 0
Applied rewrites55.2%
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 79.5%
Taylor expanded in x around 0
Applied rewrites38.1%
herbie shell --seed 2024219
(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))