
(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}
(FPCore (x eps)
:precision binary64
(let* ((t_0
(+
(* (+ 1.0 (/ 1.0 eps)) (exp (* x (+ eps -1.0))))
(* (exp (* x (- -1.0 eps))) (+ 1.0 (/ -1.0 eps))))))
(if (<= t_0 2.000000005)
(* 0.5 (* (exp (- x)) (+ x (+ x 2.0))))
(/ t_0 2.0))))
double code(double x, double eps) {
double t_0 = ((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)));
double tmp;
if (t_0 <= 2.000000005) {
tmp = 0.5 * (exp(-x) * (x + (x + 2.0)));
} else {
tmp = t_0 / 2.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: tmp
t_0 = ((1.0d0 + (1.0d0 / eps)) * exp((x * (eps + (-1.0d0))))) + (exp((x * ((-1.0d0) - eps))) * (1.0d0 + ((-1.0d0) / eps)))
if (t_0 <= 2.000000005d0) then
tmp = 0.5d0 * (exp(-x) * (x + (x + 2.0d0)))
else
tmp = t_0 / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = ((1.0 + (1.0 / eps)) * Math.exp((x * (eps + -1.0)))) + (Math.exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)));
double tmp;
if (t_0 <= 2.000000005) {
tmp = 0.5 * (Math.exp(-x) * (x + (x + 2.0)));
} else {
tmp = t_0 / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = ((1.0 + (1.0 / eps)) * math.exp((x * (eps + -1.0)))) + (math.exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps))) tmp = 0 if t_0 <= 2.000000005: tmp = 0.5 * (math.exp(-x) * (x + (x + 2.0))) else: tmp = t_0 / 2.0 return tmp
function code(x, eps) t_0 = Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(x * Float64(eps + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps))) * Float64(1.0 + Float64(-1.0 / eps)))) tmp = 0.0 if (t_0 <= 2.000000005) tmp = Float64(0.5 * Float64(exp(Float64(-x)) * Float64(x + Float64(x + 2.0)))); else tmp = Float64(t_0 / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = ((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps))); tmp = 0.0; if (t_0 <= 2.000000005) tmp = 0.5 * (exp(-x) * (x + (x + 2.0))); else tmp = t_0 / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2.000000005], N[(0.5 * N[(N[Exp[(-x)], $MachinePrecision] * N[(x + N[(x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right)\\
\mathbf{if}\;t\_0 \leq 2.000000005:\\
\;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{2}\\
\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.00000000499999997Initial program 56.3%
Taylor expanded in eps around 0
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-rgt1-inN/A
distribute-rgt-out--N/A
*-commutativeN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
Applied rewrites100.0%
if 2.00000000499999997 < (-.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 100.0%
Final simplification100.0%
(FPCore (x eps)
:precision binary64
(if (<=
(+
(* (+ 1.0 (/ 1.0 eps)) (exp (* x (+ eps -1.0))))
(* (exp (* x (- -1.0 eps))) (+ 1.0 (/ -1.0 eps))))
2.0)
(* 0.5 (* (exp (- x)) (+ x (+ x 2.0))))
(fma
x
(*
0.5
(fma
(+ 1.0 eps)
(+ (/ 1.0 eps) -1.0)
(/ (fma eps (- (fma eps (+ (- 1.0 x) (fma x eps x)) 0.0) x) -1.0) eps)))
1.0)))
double code(double x, double eps) {
double tmp;
if ((((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)))) <= 2.0) {
tmp = 0.5 * (exp(-x) * (x + (x + 2.0)));
} else {
tmp = fma(x, (0.5 * fma((1.0 + eps), ((1.0 / eps) + -1.0), (fma(eps, (fma(eps, ((1.0 - x) + fma(x, eps, x)), 0.0) - x), -1.0) / eps))), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(x * Float64(eps + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps))) * Float64(1.0 + Float64(-1.0 / eps)))) <= 2.0) tmp = Float64(0.5 * Float64(exp(Float64(-x)) * Float64(x + Float64(x + 2.0)))); else tmp = fma(x, Float64(0.5 * fma(Float64(1.0 + eps), Float64(Float64(1.0 / eps) + -1.0), Float64(fma(eps, Float64(fma(eps, Float64(Float64(1.0 - x) + fma(x, eps, x)), 0.0) - x), -1.0) / eps))), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(0.5 * N[(N[Exp[(-x)], $MachinePrecision] * N[(x + N[(x + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(0.5 * N[(N[(1.0 + eps), $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + -1.0), $MachinePrecision] + N[(N[(eps * N[(N[(eps * N[(N[(1.0 - x), $MachinePrecision] + N[(x * eps + x), $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision] - x), $MachinePrecision] + -1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 2:\\
\;\;\;\;0.5 \cdot \left(e^{-x} \cdot \left(x + \left(x + 2\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5 \cdot \mathsf{fma}\left(1 + \varepsilon, \frac{1}{\varepsilon} + -1, \frac{\mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \left(1 - x\right) + \mathsf{fma}\left(x, \varepsilon, x\right), 0\right) - x, -1\right)}{\varepsilon}\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))))) < 2Initial program 56.1%
Taylor expanded in eps around 0
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-rgt1-inN/A
distribute-rgt-out--N/A
*-commutativeN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
Applied rewrites100.0%
if 2 < (-.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.9%
Taylor expanded in x around 0
Applied rewrites87.3%
Taylor expanded in eps around 0
Applied rewrites89.2%
Final simplification95.9%
(FPCore (x eps)
:precision binary64
(if (<=
(+
(* (+ 1.0 (/ 1.0 eps)) (exp (* x (+ eps -1.0))))
(* (exp (* x (- -1.0 eps))) (+ 1.0 (/ -1.0 eps))))
2.0)
(* 0.5 (* (exp (- x)) 2.0))
(fma
x
(*
0.5
(fma
(+ 1.0 eps)
(+ (/ 1.0 eps) -1.0)
(/ (fma eps (- (fma eps (+ (- 1.0 x) (fma x eps x)) 0.0) x) -1.0) eps)))
1.0)))
double code(double x, double eps) {
double tmp;
if ((((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)))) <= 2.0) {
tmp = 0.5 * (exp(-x) * 2.0);
} else {
tmp = fma(x, (0.5 * fma((1.0 + eps), ((1.0 / eps) + -1.0), (fma(eps, (fma(eps, ((1.0 - x) + fma(x, eps, x)), 0.0) - x), -1.0) / eps))), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(x * Float64(eps + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps))) * Float64(1.0 + Float64(-1.0 / eps)))) <= 2.0) tmp = Float64(0.5 * Float64(exp(Float64(-x)) * 2.0)); else tmp = fma(x, Float64(0.5 * fma(Float64(1.0 + eps), Float64(Float64(1.0 / eps) + -1.0), Float64(fma(eps, Float64(fma(eps, Float64(Float64(1.0 - x) + fma(x, eps, x)), 0.0) - x), -1.0) / eps))), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(0.5 * N[(N[Exp[(-x)], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(0.5 * N[(N[(1.0 + eps), $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + -1.0), $MachinePrecision] + N[(N[(eps * N[(N[(eps * N[(N[(1.0 - x), $MachinePrecision] + N[(x * eps + x), $MachinePrecision]), $MachinePrecision] + 0.0), $MachinePrecision] - x), $MachinePrecision] + -1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 2:\\
\;\;\;\;0.5 \cdot \left(e^{-x} \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5 \cdot \mathsf{fma}\left(1 + \varepsilon, \frac{1}{\varepsilon} + -1, \frac{\mathsf{fma}\left(\varepsilon, \mathsf{fma}\left(\varepsilon, \left(1 - x\right) + \mathsf{fma}\left(x, \varepsilon, x\right), 0\right) - x, -1\right)}{\varepsilon}\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))))) < 2Initial program 56.1%
Taylor expanded in eps around 0
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-rgt1-inN/A
distribute-rgt-out--N/A
*-commutativeN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites98.0%
if 2 < (-.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.9%
Taylor expanded in x around 0
Applied rewrites87.3%
Taylor expanded in eps around 0
Applied rewrites89.2%
Final simplification94.7%
(FPCore (x eps)
:precision binary64
(if (<=
(+
(* (+ 1.0 (/ 1.0 eps)) (exp (* x (+ eps -1.0))))
(* (exp (* x (- -1.0 eps))) (+ 1.0 (/ -1.0 eps))))
4.0)
(fma (* x x) (fma x 0.3333333333333333 -0.5) 1.0)
(* 0.5 (* x (* x (* eps eps))))))
double code(double x, double eps) {
double tmp;
if ((((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)))) <= 4.0) {
tmp = fma((x * x), fma(x, 0.3333333333333333, -0.5), 1.0);
} else {
tmp = 0.5 * (x * (x * (eps * eps)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(x * Float64(eps + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps))) * Float64(1.0 + Float64(-1.0 / eps)))) <= 4.0) tmp = fma(Float64(x * x), fma(x, 0.3333333333333333, -0.5), 1.0); else tmp = Float64(0.5 * Float64(x * Float64(x * Float64(eps * eps)))); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0], N[(N[(x * x), $MachinePrecision] * N[(x * 0.3333333333333333 + -0.5), $MachinePrecision] + 1.0), $MachinePrecision], N[(0.5 * N[(x * N[(x * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right) \leq 4:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), 1\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x \cdot \left(x \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\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))))) < 4Initial program 56.6%
Taylor expanded in eps around 0
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-rgt1-inN/A
distribute-rgt-out--N/A
*-commutativeN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
Applied rewrites99.7%
Taylor expanded in x around 0
Applied rewrites70.8%
if 4 < (-.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 100.0%
Taylor expanded in x around 0
Applied rewrites87.1%
Taylor expanded in eps around inf
Applied rewrites87.1%
Taylor expanded in eps around inf
Applied rewrites87.1%
Final simplification76.8%
(FPCore (x eps)
:precision binary64
(if (<= x 1.32e+60)
(fma
x
(*
0.5
(fma (+ 1.0 eps) (/ 1.0 eps) (/ (fma eps (* eps (* eps x)) -1.0) eps)))
1.0)
(if (<= x 1.45e+128)
(/ (- (/ 1.0 eps) (/ 1.0 eps)) 2.0)
(* 0.5 (* x (* x (* eps eps)))))))
double code(double x, double eps) {
double tmp;
if (x <= 1.32e+60) {
tmp = fma(x, (0.5 * fma((1.0 + eps), (1.0 / eps), (fma(eps, (eps * (eps * x)), -1.0) / eps))), 1.0);
} else if (x <= 1.45e+128) {
tmp = ((1.0 / eps) - (1.0 / eps)) / 2.0;
} else {
tmp = 0.5 * (x * (x * (eps * eps)));
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 1.32e+60) tmp = fma(x, Float64(0.5 * fma(Float64(1.0 + eps), Float64(1.0 / eps), Float64(fma(eps, Float64(eps * Float64(eps * x)), -1.0) / eps))), 1.0); elseif (x <= 1.45e+128) tmp = Float64(Float64(Float64(1.0 / eps) - Float64(1.0 / eps)) / 2.0); else tmp = Float64(0.5 * Float64(x * Float64(x * Float64(eps * eps)))); end return tmp end
code[x_, eps_] := If[LessEqual[x, 1.32e+60], N[(x * N[(0.5 * N[(N[(1.0 + eps), $MachinePrecision] * N[(1.0 / eps), $MachinePrecision] + N[(N[(eps * N[(eps * N[(eps * x), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 1.45e+128], N[(N[(N[(1.0 / eps), $MachinePrecision] - N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(0.5 * N[(x * N[(x * N[(eps * eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.32 \cdot 10^{+60}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5 \cdot \mathsf{fma}\left(1 + \varepsilon, \frac{1}{\varepsilon}, \frac{\mathsf{fma}\left(\varepsilon, \varepsilon \cdot \left(\varepsilon \cdot x\right), -1\right)}{\varepsilon}\right), 1\right)\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+128}:\\
\;\;\;\;\frac{\frac{1}{\varepsilon} - \frac{1}{\varepsilon}}{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x \cdot \left(x \cdot \left(\varepsilon \cdot \varepsilon\right)\right)\right)\\
\end{array}
\end{array}
if x < 1.32e60Initial program 63.2%
Taylor expanded in x around 0
Applied rewrites87.6%
Taylor expanded in eps around 0
Applied rewrites89.4%
Taylor expanded in eps around 0
Applied rewrites89.0%
Taylor expanded in eps around inf
Applied rewrites89.9%
if 1.32e60 < x < 1.45e128Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f648.7
Applied rewrites8.7%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f6463.7
Applied rewrites63.7%
Taylor expanded in eps around 0
Applied rewrites63.7%
Taylor expanded in eps around 0
Applied rewrites81.5%
if 1.45e128 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites42.9%
Taylor expanded in eps around inf
Applied rewrites43.5%
Taylor expanded in eps around inf
Applied rewrites70.6%
Final simplification85.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* x (* eps eps))))
(if (<= x 21000.0)
(fma x (* 0.5 t_0) 1.0)
(if (<= x 1.45e+128)
(/ (- (/ 1.0 eps) (/ 1.0 eps)) 2.0)
(* 0.5 (* x t_0))))))
double code(double x, double eps) {
double t_0 = x * (eps * eps);
double tmp;
if (x <= 21000.0) {
tmp = fma(x, (0.5 * t_0), 1.0);
} else if (x <= 1.45e+128) {
tmp = ((1.0 / eps) - (1.0 / eps)) / 2.0;
} else {
tmp = 0.5 * (x * t_0);
}
return tmp;
}
function code(x, eps) t_0 = Float64(x * Float64(eps * eps)) tmp = 0.0 if (x <= 21000.0) tmp = fma(x, Float64(0.5 * t_0), 1.0); elseif (x <= 1.45e+128) tmp = Float64(Float64(Float64(1.0 / eps) - Float64(1.0 / eps)) / 2.0); else tmp = Float64(0.5 * Float64(x * t_0)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(x * N[(eps * eps), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 21000.0], N[(x * N[(0.5 * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 1.45e+128], N[(N[(N[(1.0 / eps), $MachinePrecision] - N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(0.5 * N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{if}\;x \leq 21000:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5 \cdot t\_0, 1\right)\\
\mathbf{elif}\;x \leq 1.45 \cdot 10^{+128}:\\
\;\;\;\;\frac{\frac{1}{\varepsilon} - \frac{1}{\varepsilon}}{2}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x \cdot t\_0\right)\\
\end{array}
\end{array}
if x < 21000Initial program 61.0%
Taylor expanded in x around 0
Applied rewrites90.6%
Taylor expanded in eps around inf
Applied rewrites91.5%
if 21000 < x < 1.45e128Initial program 100.0%
Taylor expanded in x around 0
lower-+.f64N/A
lower-/.f649.8
Applied rewrites9.8%
Taylor expanded in x around 0
sub-negN/A
metadata-evalN/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f6456.9
Applied rewrites56.9%
Taylor expanded in eps around 0
Applied rewrites56.9%
Taylor expanded in eps around 0
Applied rewrites67.2%
if 1.45e128 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites42.9%
Taylor expanded in eps around inf
Applied rewrites43.5%
Taylor expanded in eps around inf
Applied rewrites70.6%
(FPCore (x eps) :precision binary64 (let* ((t_0 (* x (* eps eps)))) (if (<= x 0.034) (fma x (* 0.5 t_0) 1.0) (* 0.5 (* x t_0)))))
double code(double x, double eps) {
double t_0 = x * (eps * eps);
double tmp;
if (x <= 0.034) {
tmp = fma(x, (0.5 * t_0), 1.0);
} else {
tmp = 0.5 * (x * t_0);
}
return tmp;
}
function code(x, eps) t_0 = Float64(x * Float64(eps * eps)) tmp = 0.0 if (x <= 0.034) tmp = fma(x, Float64(0.5 * t_0), 1.0); else tmp = Float64(0.5 * Float64(x * t_0)); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(x * N[(eps * eps), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, 0.034], N[(x * N[(0.5 * t$95$0), $MachinePrecision] + 1.0), $MachinePrecision], N[(0.5 * N[(x * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(\varepsilon \cdot \varepsilon\right)\\
\mathbf{if}\;x \leq 0.034:\\
\;\;\;\;\mathsf{fma}\left(x, 0.5 \cdot t\_0, 1\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(x \cdot t\_0\right)\\
\end{array}
\end{array}
if x < 0.034000000000000002Initial program 60.5%
Taylor expanded in x around 0
Applied rewrites91.6%
Taylor expanded in eps around inf
Applied rewrites92.5%
if 0.034000000000000002 < x Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites35.6%
Taylor expanded in eps around inf
Applied rewrites36.2%
Taylor expanded in eps around inf
Applied rewrites59.6%
(FPCore (x eps) :precision binary64 (if (<= x 8.5e+99) 1.0 (* x (fma x (fma x 0.5 -1.0) 1.0))))
double code(double x, double eps) {
double tmp;
if (x <= 8.5e+99) {
tmp = 1.0;
} else {
tmp = x * fma(x, fma(x, 0.5, -1.0), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 8.5e+99) tmp = 1.0; else tmp = Float64(x * fma(x, fma(x, 0.5, -1.0), 1.0)); end return tmp end
code[x_, eps_] := If[LessEqual[x, 8.5e+99], 1.0, N[(x * N[(x * N[(x * 0.5 + -1.0), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 8.5 \cdot 10^{+99}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.5, -1\right), 1\right)\\
\end{array}
\end{array}
if x < 8.49999999999999984e99Initial program 64.5%
Taylor expanded in x around 0
Applied rewrites58.1%
if 8.49999999999999984e99 < x Initial program 100.0%
Taylor expanded in eps around 0
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-rgt1-inN/A
distribute-rgt-out--N/A
*-commutativeN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
Applied rewrites61.6%
Taylor expanded in x around inf
Applied rewrites61.6%
Taylor expanded in x around 0
Applied rewrites39.9%
(FPCore (x eps) :precision binary64 (fma (* x x) (fma x 0.3333333333333333 -0.5) 1.0))
double code(double x, double eps) {
return fma((x * x), fma(x, 0.3333333333333333, -0.5), 1.0);
}
function code(x, eps) return fma(Float64(x * x), fma(x, 0.3333333333333333, -0.5), 1.0) end
code[x_, eps_] := N[(N[(x * x), $MachinePrecision] * N[(x * 0.3333333333333333 + -0.5), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, 0.3333333333333333, -0.5\right), 1\right)
\end{array}
Initial program 72.7%
Taylor expanded in eps around 0
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
associate-+l-N/A
distribute-rgt1-inN/A
distribute-rgt-out--N/A
*-commutativeN/A
distribute-lft-outN/A
lower-*.f64N/A
lower-exp.f64N/A
lower-neg.f64N/A
Applied rewrites63.3%
Taylor expanded in x around 0
Applied rewrites54.1%
(FPCore (x eps) :precision binary64 1.0)
double code(double x, double eps) {
return 1.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 1.0d0
end function
public static double code(double x, double eps) {
return 1.0;
}
def code(x, eps): return 1.0
function code(x, eps) return 1.0 end
function tmp = code(x, eps) tmp = 1.0; end
code[x_, eps_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 72.7%
Taylor expanded in x around 0
Applied rewrites45.4%
herbie shell --seed 2024221
(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))