
(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 8 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
(if (<=
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
(/ (+ 1.0 x) (exp x))
(/
(- (* (exp (* x eps)) (/ (+ 1.0 eps) eps)) (- (exp (- (fma x eps x)))))
2.0)))
double code(double x, double eps) {
double tmp;
if ((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) <= 2.0) {
tmp = (1.0 + x) / exp(x);
} else {
tmp = ((exp((x * eps)) * ((1.0 + eps) / eps)) - -exp(-fma(x, eps, x))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) <= 2.0) tmp = Float64(Float64(1.0 + x) / exp(x)); else tmp = Float64(Float64(Float64(exp(Float64(x * eps)) * Float64(Float64(1.0 + eps) / eps)) - Float64(-exp(Float64(-fma(x, eps, x))))) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision] - (-N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x} \leq 2:\\
\;\;\;\;\frac{1 + x}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x \cdot \varepsilon} \cdot \frac{1 + \varepsilon}{\varepsilon} - \left(-e^{-\mathsf{fma}\left(x, \varepsilon, x\right)}\right)}{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))))) < 2Initial program 55.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
Taylor expanded in x around inf
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 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 inf
lower-*.f64N/A
lower-exp.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
Taylor expanded in eps around inf
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x eps)
:precision binary64
(if (<=
(-
(* (+ 1.0 (pow eps -1.0)) (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
4.0)
(/ (+ 1.0 x) (exp x))
(/ (- (/ (+ 1.0 eps) eps) (- (exp (- (fma x eps x))))) 2.0)))
double code(double x, double eps) {
double tmp;
if ((((1.0 + pow(eps, -1.0)) * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) <= 4.0) {
tmp = (1.0 + x) / exp(x);
} else {
tmp = (((1.0 + eps) / eps) - -exp(-fma(x, eps, x))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(Float64(1.0 + (eps ^ -1.0)) * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) <= 4.0) tmp = Float64(Float64(1.0 + x) / exp(x)); else tmp = Float64(Float64(Float64(Float64(1.0 + eps) / eps) - Float64(-exp(Float64(-fma(x, eps, x))))) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0], N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] - (-N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left(1 + {\varepsilon}^{-1}\right) \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x} \leq 4:\\
\;\;\;\;\frac{1 + x}{e^{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 + \varepsilon}{\varepsilon} - \left(-e^{-\mathsf{fma}\left(x, \varepsilon, x\right)}\right)}{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))))) < 4Initial program 55.7%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.9%
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites99.9%
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 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
lower-+.f6456.7
Applied rewrites56.7%
Final simplification82.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (/ (+ 1.0 eps) eps)))
(if (<= x -2500000000.0)
(/ (- t_0 (- (fma x eps x) 1.0)) 2.0)
(if (<= x 1.8)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(* (* 0.5 x) (fma (- eps 1.0) t_0 (pow eps -1.0)))))))
double code(double x, double eps) {
double t_0 = (1.0 + eps) / eps;
double tmp;
if (x <= -2500000000.0) {
tmp = (t_0 - (fma(x, eps, x) - 1.0)) / 2.0;
} else if (x <= 1.8) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else {
tmp = (0.5 * x) * fma((eps - 1.0), t_0, pow(eps, -1.0));
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 + eps) / eps) tmp = 0.0 if (x <= -2500000000.0) tmp = Float64(Float64(t_0 - Float64(fma(x, eps, x) - 1.0)) / 2.0); elseif (x <= 1.8) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(Float64(0.5 * x) * fma(Float64(eps - 1.0), t_0, (eps ^ -1.0))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision]}, If[LessEqual[x, -2500000000.0], N[(N[(t$95$0 - N[(N[(x * eps + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.8], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * t$95$0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1 + \varepsilon}{\varepsilon}\\
\mathbf{if}\;x \leq -2500000000:\\
\;\;\;\;\frac{t\_0 - \left(\mathsf{fma}\left(x, \varepsilon, x\right) - 1\right)}{2}\\
\mathbf{elif}\;x \leq 1.8:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot x\right) \cdot \mathsf{fma}\left(\varepsilon - 1, t\_0, {\varepsilon}^{-1}\right)\\
\end{array}
\end{array}
if x < -2.5e9Initial 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 rewrites49.4%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f6436.3
Applied rewrites36.3%
if -2.5e9 < x < 1.80000000000000004Initial program 48.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites80.6%
Taylor expanded in x around 0
Applied rewrites79.4%
Taylor expanded in x around 0
Applied rewrites79.5%
if 1.80000000000000004 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites53.7%
Taylor expanded in eps around 0
Applied rewrites63.0%
Final simplification67.5%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (+ (+ 2.0 x) x) (fma (- (* 0.25 x) 0.5) x 0.5))))
(if (<= eps -110000000.0)
t_0
(if (<= eps 1.0)
(/ (+ 1.0 x) (exp x))
(if (<= eps 4.6e+157)
t_0
(*
(* 0.5 x)
(fma
(- eps 1.0)
(/ (+ 1.0 eps) eps)
(/ (- 1.0 (* eps eps)) eps))))))))
double code(double x, double eps) {
double t_0 = ((2.0 + x) + x) * fma(((0.25 * x) - 0.5), x, 0.5);
double tmp;
if (eps <= -110000000.0) {
tmp = t_0;
} else if (eps <= 1.0) {
tmp = (1.0 + x) / exp(x);
} else if (eps <= 4.6e+157) {
tmp = t_0;
} else {
tmp = (0.5 * x) * fma((eps - 1.0), ((1.0 + eps) / eps), ((1.0 - (eps * eps)) / eps));
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(Float64(2.0 + x) + x) * fma(Float64(Float64(0.25 * x) - 0.5), x, 0.5)) tmp = 0.0 if (eps <= -110000000.0) tmp = t_0; elseif (eps <= 1.0) tmp = Float64(Float64(1.0 + x) / exp(x)); elseif (eps <= 4.6e+157) tmp = t_0; else tmp = Float64(Float64(0.5 * x) * fma(Float64(eps - 1.0), Float64(Float64(1.0 + eps) / eps), Float64(Float64(1.0 - Float64(eps * eps)) / eps))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(N[(2.0 + x), $MachinePrecision] + x), $MachinePrecision] * N[(N[(N[(0.25 * x), $MachinePrecision] - 0.5), $MachinePrecision] * x + 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -110000000.0], t$95$0, If[LessEqual[eps, 1.0], N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 4.6e+157], t$95$0, N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] + N[(N[(1.0 - N[(eps * eps), $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(2 + x\right) + x\right) \cdot \mathsf{fma}\left(0.25 \cdot x - 0.5, x, 0.5\right)\\
\mathbf{if}\;\varepsilon \leq -110000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\varepsilon \leq 1:\\
\;\;\;\;\frac{1 + x}{e^{x}}\\
\mathbf{elif}\;\varepsilon \leq 4.6 \cdot 10^{+157}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot x\right) \cdot \mathsf{fma}\left(\varepsilon - 1, \frac{1 + \varepsilon}{\varepsilon}, \frac{1 - \varepsilon \cdot \varepsilon}{\varepsilon}\right)\\
\end{array}
\end{array}
if eps < -1.1e8 or 1 < eps < 4.60000000000000008e157Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.6%
Applied rewrites31.6%
Applied rewrites31.6%
Taylor expanded in x around 0
Applied rewrites52.9%
if -1.1e8 < eps < 1Initial program 44.4%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.1%
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites99.2%
if 4.60000000000000008e157 < eps Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites1.6%
Taylor expanded in eps around 0
Applied rewrites66.7%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (+ (+ 2.0 x) x) (fma (- (* 0.25 x) 0.5) x 0.5))))
(if (<= eps -110000000.0)
t_0
(if (<= eps 520000.0)
(*
(/
(+ (+ x 2.0) x)
(fma (fma (fma 0.16666666666666666 x 0.5) x 1.0) x 1.0))
0.5)
(if (<= eps 4.6e+157)
t_0
(*
(* 0.5 x)
(fma
(- eps 1.0)
(/ (+ 1.0 eps) eps)
(/ (- 1.0 (* eps eps)) eps))))))))
double code(double x, double eps) {
double t_0 = ((2.0 + x) + x) * fma(((0.25 * x) - 0.5), x, 0.5);
double tmp;
if (eps <= -110000000.0) {
tmp = t_0;
} else if (eps <= 520000.0) {
tmp = (((x + 2.0) + x) / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0)) * 0.5;
} else if (eps <= 4.6e+157) {
tmp = t_0;
} else {
tmp = (0.5 * x) * fma((eps - 1.0), ((1.0 + eps) / eps), ((1.0 - (eps * eps)) / eps));
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(Float64(2.0 + x) + x) * fma(Float64(Float64(0.25 * x) - 0.5), x, 0.5)) tmp = 0.0 if (eps <= -110000000.0) tmp = t_0; elseif (eps <= 520000.0) tmp = Float64(Float64(Float64(Float64(x + 2.0) + x) / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0)) * 0.5); elseif (eps <= 4.6e+157) tmp = t_0; else tmp = Float64(Float64(0.5 * x) * fma(Float64(eps - 1.0), Float64(Float64(1.0 + eps) / eps), Float64(Float64(1.0 - Float64(eps * eps)) / eps))); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(N[(2.0 + x), $MachinePrecision] + x), $MachinePrecision] * N[(N[(N[(0.25 * x), $MachinePrecision] - 0.5), $MachinePrecision] * x + 0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, -110000000.0], t$95$0, If[LessEqual[eps, 520000.0], N[(N[(N[(N[(x + 2.0), $MachinePrecision] + x), $MachinePrecision] / N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[eps, 4.6e+157], t$95$0, N[(N[(0.5 * x), $MachinePrecision] * N[(N[(eps - 1.0), $MachinePrecision] * N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] + N[(N[(1.0 - N[(eps * eps), $MachinePrecision]), $MachinePrecision] / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left(2 + x\right) + x\right) \cdot \mathsf{fma}\left(0.25 \cdot x - 0.5, x, 0.5\right)\\
\mathbf{if}\;\varepsilon \leq -110000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;\varepsilon \leq 520000:\\
\;\;\;\;\frac{\left(x + 2\right) + x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right), x, 1\right)} \cdot 0.5\\
\mathbf{elif}\;\varepsilon \leq 4.6 \cdot 10^{+157}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot x\right) \cdot \mathsf{fma}\left(\varepsilon - 1, \frac{1 + \varepsilon}{\varepsilon}, \frac{1 - \varepsilon \cdot \varepsilon}{\varepsilon}\right)\\
\end{array}
\end{array}
if eps < -1.1e8 or 5.2e5 < eps < 4.60000000000000008e157Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites29.9%
Applied rewrites29.9%
Applied rewrites29.9%
Taylor expanded in x around 0
Applied rewrites52.0%
if -1.1e8 < eps < 5.2e5Initial program 46.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.4%
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites87.2%
if 4.60000000000000008e157 < eps Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites1.6%
Taylor expanded in eps around 0
Applied rewrites66.7%
Final simplification71.0%
(FPCore (x eps)
:precision binary64
(if (<= x -2500000000.0)
(/ (- (/ (+ 1.0 eps) eps) (- (fma x eps x) 1.0)) 2.0)
(if (<= x 1.8)
(fma (- (* (fma -0.125 x 0.3333333333333333) x) 0.5) (* x x) 1.0)
(* (* 0.5 x) 0.0))))
double code(double x, double eps) {
double tmp;
if (x <= -2500000000.0) {
tmp = (((1.0 + eps) / eps) - (fma(x, eps, x) - 1.0)) / 2.0;
} else if (x <= 1.8) {
tmp = fma(((fma(-0.125, x, 0.3333333333333333) * x) - 0.5), (x * x), 1.0);
} else {
tmp = (0.5 * x) * 0.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -2500000000.0) tmp = Float64(Float64(Float64(Float64(1.0 + eps) / eps) - Float64(fma(x, eps, x) - 1.0)) / 2.0); elseif (x <= 1.8) tmp = fma(Float64(Float64(fma(-0.125, x, 0.3333333333333333) * x) - 0.5), Float64(x * x), 1.0); else tmp = Float64(Float64(0.5 * x) * 0.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -2500000000.0], N[(N[(N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] - N[(N[(x * eps + x), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.8], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], N[(N[(0.5 * x), $MachinePrecision] * 0.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2500000000:\\
\;\;\;\;\frac{\frac{1 + \varepsilon}{\varepsilon} - \left(\mathsf{fma}\left(x, \varepsilon, x\right) - 1\right)}{2}\\
\mathbf{elif}\;x \leq 1.8:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right) \cdot x - 0.5, x \cdot x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot x\right) \cdot 0\\
\end{array}
\end{array}
if x < -2.5e9Initial 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 rewrites49.4%
Taylor expanded in x around 0
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f6436.3
Applied rewrites36.3%
if -2.5e9 < x < 1.80000000000000004Initial program 48.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites80.6%
Taylor expanded in x around 0
Applied rewrites79.4%
Taylor expanded in x around 0
Applied rewrites79.5%
if 1.80000000000000004 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites53.7%
Taylor expanded in eps around 0
Applied rewrites55.9%
(FPCore (x eps) :precision binary64 (if (<= x 440.0) 1.0 (* (* 0.5 x) 0.0)))
double code(double x, double eps) {
double tmp;
if (x <= 440.0) {
tmp = 1.0;
} else {
tmp = (0.5 * x) * 0.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 440.0d0) then
tmp = 1.0d0
else
tmp = (0.5d0 * x) * 0.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 440.0) {
tmp = 1.0;
} else {
tmp = (0.5 * x) * 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 440.0: tmp = 1.0 else: tmp = (0.5 * x) * 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 440.0) tmp = 1.0; else tmp = Float64(Float64(0.5 * x) * 0.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 440.0) tmp = 1.0; else tmp = (0.5 * x) * 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 440.0], 1.0, N[(N[(0.5 * x), $MachinePrecision] * 0.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 440:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot x\right) \cdot 0\\
\end{array}
\end{array}
if x < 440Initial program 59.9%
Taylor expanded in x around 0
Applied rewrites62.2%
if 440 < x Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites3.1%
Taylor expanded in x around inf
Applied rewrites53.7%
Taylor expanded in eps around 0
Applied rewrites55.9%
(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 73.5%
Taylor expanded in x around 0
Applied rewrites42.1%
herbie shell --seed 2024326
(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))