
(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 13 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 (pow eps -1.0))))
(if (<=
(/
(-
(* t_0 (exp (* (+ -1.0 eps) x)))
(* (- (pow eps -1.0) 1.0) (exp (* (- -1.0 eps) x))))
2.0)
1.0)
(* (* (+ (+ x 2.0) x) (exp (- x))) 0.5)
(/
(- (* t_0 (exp (- (* (- x) eps)))) (/ -1.0 (exp (fma x eps x))))
2.0))))
double code(double x, double eps) {
double t_0 = 1.0 + pow(eps, -1.0);
double tmp;
if ((((t_0 * exp(((-1.0 + eps) * x))) - ((pow(eps, -1.0) - 1.0) * exp(((-1.0 - eps) * x)))) / 2.0) <= 1.0) {
tmp = (((x + 2.0) + x) * exp(-x)) * 0.5;
} else {
tmp = ((t_0 * exp(-(-x * eps))) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(1.0 + (eps ^ -1.0)) tmp = 0.0 if (Float64(Float64(Float64(t_0 * exp(Float64(Float64(-1.0 + eps) * x))) - Float64(Float64((eps ^ -1.0) - 1.0) * exp(Float64(Float64(-1.0 - eps) * x)))) / 2.0) <= 1.0) tmp = Float64(Float64(Float64(Float64(x + 2.0) + x) * exp(Float64(-x))) * 0.5); else tmp = Float64(Float64(Float64(t_0 * exp(Float64(-Float64(Float64(-x) * eps)))) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(1.0 + N[Power[eps, -1.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(t$95$0 * 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), $MachinePrecision], 1.0], N[(N[(N[(N[(x + 2.0), $MachinePrecision] + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(t$95$0 * N[Exp[(-N[((-x) * eps), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + {\varepsilon}^{-1}\\
\mathbf{if}\;\frac{t\_0 \cdot e^{\left(-1 + \varepsilon\right) \cdot x} - \left({\varepsilon}^{-1} - 1\right) \cdot e^{\left(-1 - \varepsilon\right) \cdot x}}{2} \leq 1:\\
\;\;\;\;\left(\left(\left(x + 2\right) + x\right) \cdot e^{-x}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot e^{-\left(-x\right) \cdot \varepsilon} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.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))))) #s(literal 2 binary64)) < 1Initial program 63.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
if 1 < (/.f64 (-.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))))) #s(literal 2 binary64)) 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 eps around inf
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64100.0
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))))
2.0)
2.0)
(* (* (+ (+ x 2.0) x) (exp (- x))) 0.5)
(/ (- (/ (+ 1.0 eps) eps) (/ -1.0 (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) <= 2.0) {
tmp = (((x + 2.0) + x) * exp(-x)) * 0.5;
} else {
tmp = (((1.0 + eps) / eps) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(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) <= 2.0) tmp = Float64(Float64(Float64(Float64(x + 2.0) + x) * exp(Float64(-x))) * 0.5); else tmp = Float64(Float64(Float64(Float64(1.0 + eps) / eps) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(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), $MachinePrecision], 2.0], N[(N[(N[(N[(x + 2.0), $MachinePrecision] + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[(N[(1.0 + eps), $MachinePrecision] / eps), $MachinePrecision] - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\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}}{2} \leq 2:\\
\;\;\;\;\left(\left(\left(x + 2\right) + x\right) \cdot e^{-x}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 + \varepsilon}{\varepsilon} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\end{array}
\end{array}
if (/.f64 (-.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))))) #s(literal 2 binary64)) < 2Initial program 64.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.9%
Applied rewrites99.9%
if 2 < (/.f64 (-.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))))) #s(literal 2 binary64)) 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
*-inversesN/A
div-addN/A
+-commutativeN/A
lower-/.f64N/A
lower-+.f6458.6
Applied rewrites58.6%
Final simplification82.2%
(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)
0.0)
(* (* (+ (+ x 2.0) x) (exp (- x))) 0.5)
(fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.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) <= 0.0) {
tmp = (((x + 2.0) + x) * exp(-x)) * 0.5;
} else {
tmp = fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(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) <= 0.0) tmp = Float64(Float64(Float64(Float64(x + 2.0) + x) * exp(Float64(-x))) * 0.5); else tmp = fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(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), $MachinePrecision], 0.0], N[(N[(N[(N[(x + 2.0), $MachinePrecision] + x), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{\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}}{2} \leq 0:\\
\;\;\;\;\left(\left(\left(x + 2\right) + x\right) \cdot e^{-x}\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)\\
\end{array}
\end{array}
if (/.f64 (-.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))))) #s(literal 2 binary64)) < 0.0Initial program 46.1%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
if 0.0 < (/.f64 (-.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))))) #s(literal 2 binary64)) Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites31.7%
Taylor expanded in x around 0
Applied rewrites46.9%
Taylor expanded in x around 0
Applied rewrites46.9%
Applied rewrites64.9%
Final simplification78.2%
(FPCore (x eps)
:precision binary64
(if (<= x -1.0)
(/ (- x) (exp x))
(if (<= x 240.0)
1.0
(if (<= x 2.5e+49)
(* (exp x) x)
(if (<= x 1.62e+180)
(/ (- (+ (pow eps -1.0) 1.0) (- (pow eps -1.0) 1.0)) 2.0)
(* (fma (- (* 0.5 x) 1.0) x 1.0) x))))))
double code(double x, double eps) {
double tmp;
if (x <= -1.0) {
tmp = -x / exp(x);
} else if (x <= 240.0) {
tmp = 1.0;
} else if (x <= 2.5e+49) {
tmp = exp(x) * x;
} else if (x <= 1.62e+180) {
tmp = ((pow(eps, -1.0) + 1.0) - (pow(eps, -1.0) - 1.0)) / 2.0;
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(-x) / exp(x)); elseif (x <= 240.0) tmp = 1.0; elseif (x <= 2.5e+49) tmp = Float64(exp(x) * x); elseif (x <= 1.62e+180) tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64((eps ^ -1.0) - 1.0)) / 2.0); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, -1.0], N[((-x) / N[Exp[x], $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 240.0], 1.0, If[LessEqual[x, 2.5e+49], N[(N[Exp[x], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.62e+180], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;\frac{-x}{e^{x}}\\
\mathbf{elif}\;x \leq 240:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+49}:\\
\;\;\;\;e^{x} \cdot x\\
\mathbf{elif}\;x \leq 1.62 \cdot 10^{+180}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites0.0%
Taylor expanded in x around 0
Applied rewrites0.1%
Taylor expanded in x around inf
Applied rewrites0.0%
Applied rewrites100.0%
if -1 < x < 240Initial program 60.7%
Taylor expanded in x around 0
Applied rewrites77.3%
if 240 < x < 2.5000000000000002e49Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.9%
Taylor expanded in x around 0
Applied rewrites3.5%
Taylor expanded in x around inf
Applied rewrites28.9%
Applied rewrites72.7%
if 2.5000000000000002e49 < x < 1.62e180Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6410.6
Applied rewrites10.6%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6475.8
Applied rewrites75.8%
if 1.62e180 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
Taylor expanded in x around inf
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
Final simplification78.7%
(FPCore (x eps)
:precision binary64
(if (<= x 240.0)
(fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.0)
(if (<= x 2.5e+49)
(* (exp x) x)
(if (<= x 1.62e+180)
(/ (- (+ (pow eps -1.0) 1.0) (- (pow eps -1.0) 1.0)) 2.0)
(* (fma (- (* 0.5 x) 1.0) x 1.0) x)))))
double code(double x, double eps) {
double tmp;
if (x <= 240.0) {
tmp = fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
} else if (x <= 2.5e+49) {
tmp = exp(x) * x;
} else if (x <= 1.62e+180) {
tmp = ((pow(eps, -1.0) + 1.0) - (pow(eps, -1.0) - 1.0)) / 2.0;
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 240.0) tmp = fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0); elseif (x <= 2.5e+49) tmp = Float64(exp(x) * x); elseif (x <= 1.62e+180) tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64((eps ^ -1.0) - 1.0)) / 2.0); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 240.0], N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 2.5e+49], N[(N[Exp[x], $MachinePrecision] * x), $MachinePrecision], If[LessEqual[x, 1.62e+180], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 240:\\
\;\;\;\;\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{+49}:\\
\;\;\;\;e^{x} \cdot x\\
\mathbf{elif}\;x \leq 1.62 \cdot 10^{+180}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 240Initial program 69.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites60.3%
Taylor expanded in x around 0
Applied rewrites59.8%
Taylor expanded in x around 0
Applied rewrites59.8%
Applied rewrites76.4%
if 240 < x < 2.5000000000000002e49Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites28.9%
Taylor expanded in x around 0
Applied rewrites3.5%
Taylor expanded in x around inf
Applied rewrites28.9%
Applied rewrites72.7%
if 2.5000000000000002e49 < x < 1.62e180Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6410.6
Applied rewrites10.6%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6475.8
Applied rewrites75.8%
if 1.62e180 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
Taylor expanded in x around inf
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
Final simplification74.6%
(FPCore (x eps)
:precision binary64
(if (<= x 410000000.0)
(fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.0)
(if (<= x 1.62e+180)
(/ (- (+ (pow eps -1.0) 1.0) (- (pow eps -1.0) 1.0)) 2.0)
(* (fma (- (* 0.5 x) 1.0) x 1.0) x))))
double code(double x, double eps) {
double tmp;
if (x <= 410000000.0) {
tmp = fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
} else if (x <= 1.62e+180) {
tmp = ((pow(eps, -1.0) + 1.0) - (pow(eps, -1.0) - 1.0)) / 2.0;
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 410000000.0) tmp = fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0); elseif (x <= 1.62e+180) tmp = Float64(Float64(Float64((eps ^ -1.0) + 1.0) - Float64((eps ^ -1.0) - 1.0)) / 2.0); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 410000000.0], N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 1.62e+180], N[(N[(N[(N[Power[eps, -1.0], $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[Power[eps, -1.0], $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 410000000:\\
\;\;\;\;\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 1.62 \cdot 10^{+180}:\\
\;\;\;\;\frac{\left({\varepsilon}^{-1} + 1\right) - \left({\varepsilon}^{-1} - 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 4.1e8Initial program 69.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites59.7%
Taylor expanded in x around 0
Applied rewrites59.2%
Taylor expanded in x around 0
Applied rewrites59.2%
Applied rewrites75.6%
if 4.1e8 < x < 1.62e180Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6419.4
Applied rewrites19.4%
Taylor expanded in x around 0
lower--.f64N/A
lower-/.f6462.7
Applied rewrites62.7%
if 1.62e180 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
Taylor expanded in x around inf
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
Final simplification71.6%
(FPCore (x eps)
:precision binary64
(if (<= x 5e+102)
(fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.0)
(if (<= x 1.62e+180)
(/ x (fma (fma (fma 0.16666666666666666 x 0.5) x 1.0) x 1.0))
(* (fma (- (* 0.5 x) 1.0) x 1.0) x))))
double code(double x, double eps) {
double tmp;
if (x <= 5e+102) {
tmp = fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
} else if (x <= 1.62e+180) {
tmp = x / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 5e+102) tmp = fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0); elseif (x <= 1.62e+180) tmp = Float64(x / fma(fma(fma(0.16666666666666666, x, 0.5), x, 1.0), x, 1.0)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 5e+102], N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 1.62e+180], N[(x / N[(N[(N[(0.16666666666666666 * x + 0.5), $MachinePrecision] * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{+102}:\\
\;\;\;\;\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 1.62 \cdot 10^{+180}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, x, 0.5\right), x, 1\right), x, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 5e102Initial program 73.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.5%
Taylor expanded in x around 0
Applied rewrites52.0%
Taylor expanded in x around 0
Applied rewrites52.0%
Applied rewrites66.2%
if 5e102 < x < 1.62e180Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites81.1%
Taylor expanded in x around 0
Applied rewrites20.5%
Taylor expanded in x around inf
Applied rewrites81.1%
Taylor expanded in x around 0
Applied rewrites81.1%
if 1.62e180 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
Taylor expanded in x around inf
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
(FPCore (x eps)
:precision binary64
(if (<= x 1.75e+154)
(fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.0)
(if (<= x 1.62e+180)
(/ x (fma (fma 0.5 x 1.0) x 1.0))
(* (fma (- (* 0.5 x) 1.0) x 1.0) x))))
double code(double x, double eps) {
double tmp;
if (x <= 1.75e+154) {
tmp = fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
} else if (x <= 1.62e+180) {
tmp = x / fma(fma(0.5, x, 1.0), x, 1.0);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 1.75e+154) tmp = fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0); elseif (x <= 1.62e+180) tmp = Float64(x / fma(fma(0.5, x, 1.0), x, 1.0)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 1.75e+154], N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[x, 1.62e+180], N[(x / N[(N[(0.5 * x + 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.75 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)\\
\mathbf{elif}\;x \leq 1.62 \cdot 10^{+180}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, 1\right), x, 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 1.7500000000000001e154Initial program 75.8%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites58.4%
Taylor expanded in x around 0
Applied rewrites50.5%
Taylor expanded in x around 0
Applied rewrites50.5%
Applied rewrites63.7%
if 1.7500000000000001e154 < x < 1.62e180Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites1.6%
Taylor expanded in x around inf
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites90.5%
if 1.62e180 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
Taylor expanded in x around inf
Applied rewrites37.7%
Taylor expanded in x around 0
Applied rewrites63.9%
(FPCore (x eps) :precision binary64 (if (<= x 2.2) (- 1.0 (* (* (- (* 0.3333333333333333 x) 0.5) x) x)) (* (fma (- (* 0.5 x) 1.0) x 1.0) x)))
double code(double x, double eps) {
double tmp;
if (x <= 2.2) {
tmp = 1.0 - ((((0.3333333333333333 * x) - 0.5) * x) * x);
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 2.2) tmp = Float64(1.0 - Float64(Float64(Float64(Float64(0.3333333333333333 * x) - 0.5) * x) * x)); else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 2.2], N[(1.0 - N[(N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.2:\\
\;\;\;\;1 - \left(\left(0.3333333333333333 \cdot x - 0.5\right) \cdot x\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 2.2000000000000002Initial program 70.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites60.1%
Taylor expanded in x around 0
Applied rewrites60.1%
Taylor expanded in x around 0
Applied rewrites60.1%
Applied rewrites76.8%
if 2.2000000000000002 < x Initial program 98.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites52.5%
Taylor expanded in x around 0
Applied rewrites30.1%
Taylor expanded in x around inf
Applied rewrites51.7%
Taylor expanded in x around 0
Applied rewrites30.1%
(FPCore (x eps) :precision binary64 (if (<= x 600.0) 1.0 (* (fma (- (* 0.5 x) 1.0) x 1.0) x)))
double code(double x, double eps) {
double tmp;
if (x <= 600.0) {
tmp = 1.0;
} else {
tmp = fma(((0.5 * x) - 1.0), x, 1.0) * x;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= 600.0) tmp = 1.0; else tmp = Float64(fma(Float64(Float64(0.5 * x) - 1.0), x, 1.0) * x); end return tmp end
code[x_, eps_] := If[LessEqual[x, 600.0], 1.0, N[(N[(N[(N[(0.5 * x), $MachinePrecision] - 1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 600:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5 \cdot x - 1, x, 1\right) \cdot x\\
\end{array}
\end{array}
if x < 600Initial program 69.6%
Taylor expanded in x around 0
Applied rewrites60.5%
if 600 < x Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites52.0%
Taylor expanded in x around 0
Applied rewrites30.4%
Taylor expanded in x around inf
Applied rewrites52.0%
Taylor expanded in x around 0
Applied rewrites30.4%
(FPCore (x eps) :precision binary64 (fma (- (fabs (* 0.3333333333333333 x)) 0.5) (* x x) 1.0))
double code(double x, double eps) {
return fma((fabs((0.3333333333333333 * x)) - 0.5), (x * x), 1.0);
}
function code(x, eps) return fma(Float64(abs(Float64(0.3333333333333333 * x)) - 0.5), Float64(x * x), 1.0) end
code[x_, eps_] := N[(N[(N[Abs[N[(0.3333333333333333 * x), $MachinePrecision]], $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\left|0.3333333333333333 \cdot x\right| - 0.5, x \cdot x, 1\right)
\end{array}
Initial program 79.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.6%
Taylor expanded in x around 0
Applied rewrites50.2%
Taylor expanded in x around 0
Applied rewrites50.2%
Applied rewrites61.3%
(FPCore (x eps) :precision binary64 (fma (- (* 0.3333333333333333 x) 0.5) (* x x) 1.0))
double code(double x, double eps) {
return fma(((0.3333333333333333 * x) - 0.5), (x * x), 1.0);
}
function code(x, eps) return fma(Float64(Float64(0.3333333333333333 * x) - 0.5), Float64(x * x), 1.0) end
code[x_, eps_] := N[(N[(N[(0.3333333333333333 * x), $MachinePrecision] - 0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0.3333333333333333 \cdot x - 0.5, x \cdot x, 1\right)
\end{array}
Initial program 79.6%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites57.6%
Taylor expanded in x around 0
Applied rewrites50.2%
Taylor expanded in x around 0
Applied rewrites50.2%
(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 79.6%
Taylor expanded in x around 0
Applied rewrites41.7%
herbie shell --seed 2024343
(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))