
(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 eps) 1.0)))
(if (<=
(-
(* (exp (* (+ -1.0 eps) x)) t_0)
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
2.0)
(* (exp (- x)) (+ x 1.0))
(/ (- (* (exp (* x eps)) t_0) (/ -1.0 (exp (fma x eps x)))) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (((exp(((-1.0 + eps) * x)) * t_0) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 2.0) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = ((exp((x * eps)) * t_0) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) + 1.0) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(-1.0 + eps) * x)) * t_0) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 2.0) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(Float64(exp(Float64(x * eps)) * t_0) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] * t$95$0), $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 := \frac{1}{\varepsilon} + 1\\
\mathbf{if}\;e^{\left(-1 + \varepsilon\right) \cdot x} \cdot t\_0 - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 2:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x \cdot \varepsilon} \cdot t\_0 - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\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.1%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
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%
Taylor expanded in eps around inf
*-commutativeN/A
lower-*.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (/ 1.0 eps) 1.0)))
(if (<=
(-
(* (exp (* (+ -1.0 eps) x)) t_0)
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
2.0)
(* (exp (- x)) (+ x 1.0))
(/ (- (* (exp (* x eps)) t_0) (- (exp (- (fma x eps x))))) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (((exp(((-1.0 + eps) * x)) * t_0) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 2.0) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = ((exp((x * eps)) * t_0) - -exp(-fma(x, eps, x))) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) + 1.0) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(-1.0 + eps) * x)) * t_0) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 2.0) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(Float64(exp(Float64(x * eps)) * t_0) - Float64(-exp(Float64(-fma(x, eps, x))))) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Exp[N[(x * eps), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] - (-N[Exp[(-N[(x * eps + x), $MachinePrecision])], $MachinePrecision])), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} + 1\\
\mathbf{if}\;e^{\left(-1 + \varepsilon\right) \cdot x} \cdot t\_0 - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 2:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x \cdot \varepsilon} \cdot t\_0 - \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.1%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
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 eps around inf
lower-*.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (- (/ 1.0 eps) 1.0))
(t_1 (* (exp (* (+ -1.0 eps) x)) (+ (/ 1.0 eps) 1.0))))
(if (<= (- t_1 (* (exp (* (- -1.0 eps) x)) t_0)) 0.0)
(* (exp (- x)) (+ x 1.0))
(/ (- t_1 (* (fma (- -1.0 eps) x 1.0) t_0)) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) - 1.0;
double t_1 = exp(((-1.0 + eps) * x)) * ((1.0 / eps) + 1.0);
double tmp;
if ((t_1 - (exp(((-1.0 - eps) * x)) * t_0)) <= 0.0) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = (t_1 - (fma((-1.0 - eps), x, 1.0) * t_0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) - 1.0) t_1 = Float64(exp(Float64(Float64(-1.0 + eps) * x)) * Float64(Float64(1.0 / eps) + 1.0)) tmp = 0.0 if (Float64(t_1 - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * t_0)) <= 0.0) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(t_1 - Float64(fma(Float64(-1.0 - eps), x, 1.0) * t_0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$1 - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision], 0.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - N[(N[(N[(-1.0 - eps), $MachinePrecision] * x + 1.0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} - 1\\
t_1 := e^{\left(-1 + \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} + 1\right)\\
\mathbf{if}\;t\_1 - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot t\_0 \leq 0:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 - \mathsf{fma}\left(-1 - \varepsilon, x, 1\right) \cdot 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))))) < 0.0Initial program 41.9%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
Applied rewrites100.0%
if 0.0 < (-.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
associate--l+N/A
mul-1-negN/A
associate-*r*N/A
distribute-lft-neg-inN/A
distribute-lft1-inN/A
lower-*.f64N/A
distribute-rgt-neg-inN/A
*-commutativeN/A
lower-fma.f64N/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
lower--.f64N/A
lower--.f64N/A
lower-/.f6461.3
Applied rewrites61.3%
Final simplification78.6%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (exp (* (+ -1.0 eps) x)) (+ (/ 1.0 eps) 1.0))))
(if (<= (- t_0 (* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0))) 2.0)
(* (exp (- x)) (+ x 1.0))
(/ (- t_0 (fma (- eps -1.0) x -1.0)) 2.0))))
double code(double x, double eps) {
double t_0 = exp(((-1.0 + eps) * x)) * ((1.0 / eps) + 1.0);
double tmp;
if ((t_0 - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 2.0) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = (t_0 - fma((eps - -1.0), x, -1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(exp(Float64(Float64(-1.0 + eps) * x)) * Float64(Float64(1.0 / eps) + 1.0)) tmp = 0.0 if (Float64(t_0 - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 2.0) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(t_0 - fma(Float64(eps - -1.0), x, -1.0)) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(t$95$0 - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - N[(N[(eps - -1.0), $MachinePrecision] * x + -1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\left(-1 + \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} + 1\right)\\
\mathbf{if}\;t\_0 - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 2:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - \mathsf{fma}\left(\varepsilon - -1, x, -1\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.1%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites100.0%
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%
Taylor expanded in x around 0
Applied rewrites48.9%
Final simplification78.6%
(FPCore (x eps)
:precision binary64
(if (<=
(-
(* (exp (* (+ -1.0 eps) x)) (+ (/ 1.0 eps) 1.0))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
40.0)
(* (exp (- x)) (+ x 1.0))
(/ (- (/ 1.0 eps) (/ -1.0 (exp (fma x eps x)))) 2.0)))
double code(double x, double eps) {
double tmp;
if (((exp(((-1.0 + eps) * x)) * ((1.0 / eps) + 1.0)) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 40.0) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = ((1.0 / eps) - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(-1.0 + eps) * x)) * Float64(Float64(1.0 / eps) + 1.0)) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 40.0) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(Float64(1.0 / eps) - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[N[(N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 40.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / 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}\;e^{\left(-1 + \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} + 1\right) - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 40:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\varepsilon} - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\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))))) < 40Initial program 56.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.8%
Applied rewrites98.8%
if 40 < (-.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%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6460.5
Applied rewrites60.5%
Taylor expanded in eps around 0
Applied rewrites59.8%
Final simplification83.1%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (/ 1.0 eps) 1.0)))
(if (<=
(-
(* (exp (* (+ -1.0 eps) x)) t_0)
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
4.0)
(* (exp (- x)) (+ x 1.0))
(/ (- t_0 (/ -1.0 (exp x))) 2.0))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (((exp(((-1.0 + eps) * x)) * t_0) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 4.0) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = (t_0 - (-1.0 / exp(x))) / 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 / eps) + 1.0d0
if (((exp((((-1.0d0) + eps) * x)) * t_0) - (exp((((-1.0d0) - eps) * x)) * ((1.0d0 / eps) - 1.0d0))) <= 4.0d0) then
tmp = exp(-x) * (x + 1.0d0)
else
tmp = (t_0 - ((-1.0d0) / exp(x))) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (((Math.exp(((-1.0 + eps) * x)) * t_0) - (Math.exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 4.0) {
tmp = Math.exp(-x) * (x + 1.0);
} else {
tmp = (t_0 - (-1.0 / Math.exp(x))) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = (1.0 / eps) + 1.0 tmp = 0 if ((math.exp(((-1.0 + eps) * x)) * t_0) - (math.exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 4.0: tmp = math.exp(-x) * (x + 1.0) else: tmp = (t_0 - (-1.0 / math.exp(x))) / 2.0 return tmp
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) + 1.0) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(-1.0 + eps) * x)) * t_0) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 4.0) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(t_0 - Float64(-1.0 / exp(x))) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = (1.0 / eps) + 1.0; tmp = 0.0; if (((exp(((-1.0 + eps) * x)) * t_0) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 4.0) tmp = exp(-x) * (x + 1.0); else tmp = (t_0 - (-1.0 / exp(x))) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[N[(N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - N[(-1.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} + 1\\
\mathbf{if}\;e^{\left(-1 + \varepsilon\right) \cdot x} \cdot t\_0 - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 4:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - \frac{-1}{e^{x}}}{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 56.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.4%
Applied rewrites99.4%
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%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6460.1
Applied rewrites60.1%
Taylor expanded in eps around 0
Applied rewrites43.3%
Final simplification76.6%
(FPCore (x eps)
:precision binary64
(if (<=
(-
(* (exp (* (+ -1.0 eps) x)) (+ (/ 1.0 eps) 1.0))
(* (exp (* (- -1.0 eps) x)) (- (/ 1.0 eps) 1.0)))
40.0)
(* (exp (- x)) (+ x 1.0))
(/ (- (/ 1.0 eps) (/ -1.0 (exp x))) 2.0)))
double code(double x, double eps) {
double tmp;
if (((exp(((-1.0 + eps) * x)) * ((1.0 / eps) + 1.0)) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 40.0) {
tmp = exp(-x) * (x + 1.0);
} else {
tmp = ((1.0 / eps) - (-1.0 / exp(x))) / 2.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (((exp((((-1.0d0) + eps) * x)) * ((1.0d0 / eps) + 1.0d0)) - (exp((((-1.0d0) - eps) * x)) * ((1.0d0 / eps) - 1.0d0))) <= 40.0d0) then
tmp = exp(-x) * (x + 1.0d0)
else
tmp = ((1.0d0 / eps) - ((-1.0d0) / exp(x))) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (((Math.exp(((-1.0 + eps) * x)) * ((1.0 / eps) + 1.0)) - (Math.exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 40.0) {
tmp = Math.exp(-x) * (x + 1.0);
} else {
tmp = ((1.0 / eps) - (-1.0 / Math.exp(x))) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if ((math.exp(((-1.0 + eps) * x)) * ((1.0 / eps) + 1.0)) - (math.exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 40.0: tmp = math.exp(-x) * (x + 1.0) else: tmp = ((1.0 / eps) - (-1.0 / math.exp(x))) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (Float64(Float64(exp(Float64(Float64(-1.0 + eps) * x)) * Float64(Float64(1.0 / eps) + 1.0)) - Float64(exp(Float64(Float64(-1.0 - eps) * x)) * Float64(Float64(1.0 / eps) - 1.0))) <= 40.0) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); else tmp = Float64(Float64(Float64(1.0 / eps) - Float64(-1.0 / exp(x))) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (((exp(((-1.0 + eps) * x)) * ((1.0 / eps) + 1.0)) - (exp(((-1.0 - eps) * x)) * ((1.0 / eps) - 1.0))) <= 40.0) tmp = exp(-x) * (x + 1.0); else tmp = ((1.0 / eps) - (-1.0 / exp(x))) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[N[(N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] - N[(N[Exp[N[(N[(-1.0 - eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 40.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(1.0 / eps), $MachinePrecision] - N[(-1.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{\left(-1 + \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} + 1\right) - e^{\left(-1 - \varepsilon\right) \cdot x} \cdot \left(\frac{1}{\varepsilon} - 1\right) \leq 40:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\varepsilon} - \frac{-1}{e^{x}}}{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))))) < 40Initial program 56.3%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites98.8%
Applied rewrites98.8%
if 40 < (-.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%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6460.5
Applied rewrites60.5%
Taylor expanded in eps around 0
Applied rewrites43.6%
Taylor expanded in eps around 0
Applied rewrites43.1%
Final simplification76.4%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (/ 1.0 eps) 1.0)))
(if (<= eps 7.4e+19)
(* (exp (- x)) (+ x 1.0))
(if (<= eps 1.55e+249)
(/ (- t_0 (/ -1.0 (exp (fma x eps x)))) 2.0)
(/ (- (* (exp (* (+ -1.0 eps) x)) t_0) -1.0) 2.0)))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (eps <= 7.4e+19) {
tmp = exp(-x) * (x + 1.0);
} else if (eps <= 1.55e+249) {
tmp = (t_0 - (-1.0 / exp(fma(x, eps, x)))) / 2.0;
} else {
tmp = ((exp(((-1.0 + eps) * x)) * t_0) - -1.0) / 2.0;
}
return tmp;
}
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) + 1.0) tmp = 0.0 if (eps <= 7.4e+19) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); elseif (eps <= 1.55e+249) tmp = Float64(Float64(t_0 - Float64(-1.0 / exp(fma(x, eps, x)))) / 2.0); else tmp = Float64(Float64(Float64(exp(Float64(Float64(-1.0 + eps) * x)) * t_0) - -1.0) / 2.0); end return tmp end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[eps, 7.4e+19], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 1.55e+249], N[(N[(t$95$0 - N[(-1.0 / N[Exp[N[(x * eps + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] - -1.0), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} + 1\\
\mathbf{if}\;\varepsilon \leq 7.4 \cdot 10^{+19}:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{elif}\;\varepsilon \leq 1.55 \cdot 10^{+249}:\\
\;\;\;\;\frac{t\_0 - \frac{-1}{e^{\mathsf{fma}\left(x, \varepsilon, x\right)}}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\left(-1 + \varepsilon\right) \cdot x} \cdot t\_0 - -1}{2}\\
\end{array}
\end{array}
if eps < 7.4e19Initial program 65.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.4%
Applied rewrites69.4%
if 7.4e19 < eps < 1.55000000000000008e249Initial program 99.9%
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.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6476.5
Applied rewrites76.5%
if 1.55000000000000008e249 < eps Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites56.8%
Final simplification69.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ (/ 1.0 eps) 1.0)))
(if (<= eps 55000000000000.0)
(* (exp (- x)) (+ x 1.0))
(if (<= eps 8e+243)
(/ (- t_0 (/ -1.0 (exp x))) 2.0)
(/ (- (* (exp (* (+ -1.0 eps) x)) t_0) -1.0) 2.0)))))
double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (eps <= 55000000000000.0) {
tmp = exp(-x) * (x + 1.0);
} else if (eps <= 8e+243) {
tmp = (t_0 - (-1.0 / exp(x))) / 2.0;
} else {
tmp = ((exp(((-1.0 + eps) * x)) * t_0) - -1.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 / eps) + 1.0d0
if (eps <= 55000000000000.0d0) then
tmp = exp(-x) * (x + 1.0d0)
else if (eps <= 8d+243) then
tmp = (t_0 - ((-1.0d0) / exp(x))) / 2.0d0
else
tmp = ((exp((((-1.0d0) + eps) * x)) * t_0) - (-1.0d0)) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = (1.0 / eps) + 1.0;
double tmp;
if (eps <= 55000000000000.0) {
tmp = Math.exp(-x) * (x + 1.0);
} else if (eps <= 8e+243) {
tmp = (t_0 - (-1.0 / Math.exp(x))) / 2.0;
} else {
tmp = ((Math.exp(((-1.0 + eps) * x)) * t_0) - -1.0) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = (1.0 / eps) + 1.0 tmp = 0 if eps <= 55000000000000.0: tmp = math.exp(-x) * (x + 1.0) elif eps <= 8e+243: tmp = (t_0 - (-1.0 / math.exp(x))) / 2.0 else: tmp = ((math.exp(((-1.0 + eps) * x)) * t_0) - -1.0) / 2.0 return tmp
function code(x, eps) t_0 = Float64(Float64(1.0 / eps) + 1.0) tmp = 0.0 if (eps <= 55000000000000.0) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); elseif (eps <= 8e+243) tmp = Float64(Float64(t_0 - Float64(-1.0 / exp(x))) / 2.0); else tmp = Float64(Float64(Float64(exp(Float64(Float64(-1.0 + eps) * x)) * t_0) - -1.0) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = (1.0 / eps) + 1.0; tmp = 0.0; if (eps <= 55000000000000.0) tmp = exp(-x) * (x + 1.0); elseif (eps <= 8e+243) tmp = (t_0 - (-1.0 / exp(x))) / 2.0; else tmp = ((exp(((-1.0 + eps) * x)) * t_0) - -1.0) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[eps, 55000000000000.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 8e+243], N[(N[(t$95$0 - N[(-1.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[Exp[N[(N[(-1.0 + eps), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision] - -1.0), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\varepsilon} + 1\\
\mathbf{if}\;\varepsilon \leq 55000000000000:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{elif}\;\varepsilon \leq 8 \cdot 10^{+243}:\\
\;\;\;\;\frac{t\_0 - \frac{-1}{e^{x}}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\left(-1 + \varepsilon\right) \cdot x} \cdot t\_0 - -1}{2}\\
\end{array}
\end{array}
if eps < 5.5e13Initial program 65.2%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.6%
Applied rewrites69.6%
if 5.5e13 < eps < 8.0000000000000006e243Initial program 99.9%
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.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6474.3
Applied rewrites74.3%
Taylor expanded in eps around 0
Applied rewrites73.8%
if 8.0000000000000006e243 < eps Initial program 100.0%
Taylor expanded in eps around inf
exp-negN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f64N/A
lower-exp.f64N/A
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f64100.0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites53.6%
Final simplification69.3%
(FPCore (x eps)
:precision binary64
(if (<= eps 3.05e-6)
(* (exp (- x)) (+ x 1.0))
(if (<= eps 7.3e+106)
(* (fma (fma 0.5 x -1.0) x 1.0) (+ x 1.0))
(/ (- (+ (/ 1.0 eps) 1.0) (fma (- eps -1.0) x -1.0)) 2.0))))
double code(double x, double eps) {
double tmp;
if (eps <= 3.05e-6) {
tmp = exp(-x) * (x + 1.0);
} else if (eps <= 7.3e+106) {
tmp = fma(fma(0.5, x, -1.0), x, 1.0) * (x + 1.0);
} else {
tmp = (((1.0 / eps) + 1.0) - fma((eps - -1.0), x, -1.0)) / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (eps <= 3.05e-6) tmp = Float64(exp(Float64(-x)) * Float64(x + 1.0)); elseif (eps <= 7.3e+106) tmp = Float64(fma(fma(0.5, x, -1.0), x, 1.0) * Float64(x + 1.0)); else tmp = Float64(Float64(Float64(Float64(1.0 / eps) + 1.0) - fma(Float64(eps - -1.0), x, -1.0)) / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[eps, 3.05e-6], N[(N[Exp[(-x)], $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[eps, 7.3e+106], N[(N[(N[(0.5 * x + -1.0), $MachinePrecision] * x + 1.0), $MachinePrecision] * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[(eps - -1.0), $MachinePrecision] * x + -1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 3.05 \cdot 10^{-6}:\\
\;\;\;\;e^{-x} \cdot \left(x + 1\right)\\
\mathbf{elif}\;\varepsilon \leq 7.3 \cdot 10^{+106}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.5, x, -1\right), x, 1\right) \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} + 1\right) - \mathsf{fma}\left(\varepsilon - -1, x, -1\right)}{2}\\
\end{array}
\end{array}
if eps < 3.05000000000000002e-6Initial program 65.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites69.5%
Applied rewrites69.5%
if 3.05000000000000002e-6 < eps < 7.30000000000000003e106Initial program 100.0%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites56.4%
Applied rewrites56.4%
Taylor expanded in x around 0
Applied rewrites75.3%
if 7.30000000000000003e106 < eps Initial program 99.9%
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.f6499.9
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
lower-+.f64N/A
lower-/.f6471.9
Applied rewrites71.9%
Taylor expanded in eps around 0
Applied rewrites59.4%
Taylor expanded in x around 0
Applied rewrites45.1%
Final simplification65.8%
(FPCore (x eps)
:precision binary64
(if (<= x -195.0)
(/ (- (+ (/ 1.0 eps) 1.0) (fma (- eps -1.0) x -1.0)) 2.0)
(if (<= x 1.85)
(fma (* (fma (fma -0.125 x 0.3333333333333333) x -0.5) x) x 1.0)
(/ 0.0 2.0))))
double code(double x, double eps) {
double tmp;
if (x <= -195.0) {
tmp = (((1.0 / eps) + 1.0) - fma((eps - -1.0), x, -1.0)) / 2.0;
} else if (x <= 1.85) {
tmp = fma((fma(fma(-0.125, x, 0.3333333333333333), x, -0.5) * x), x, 1.0);
} else {
tmp = 0.0 / 2.0;
}
return tmp;
}
function code(x, eps) tmp = 0.0 if (x <= -195.0) tmp = Float64(Float64(Float64(Float64(1.0 / eps) + 1.0) - fma(Float64(eps - -1.0), x, -1.0)) / 2.0); elseif (x <= 1.85) tmp = fma(Float64(fma(fma(-0.125, x, 0.3333333333333333), x, -0.5) * x), x, 1.0); else tmp = Float64(0.0 / 2.0); end return tmp end
code[x_, eps_] := If[LessEqual[x, -195.0], N[(N[(N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision] - N[(N[(eps - -1.0), $MachinePrecision] * x + -1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.85], N[(N[(N[(N[(-0.125 * x + 0.3333333333333333), $MachinePrecision] * x + -0.5), $MachinePrecision] * x), $MachinePrecision] * x + 1.0), $MachinePrecision], N[(0.0 / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -195:\\
\;\;\;\;\frac{\left(\frac{1}{\varepsilon} + 1\right) - \mathsf{fma}\left(\varepsilon - -1, x, -1\right)}{2}\\
\mathbf{elif}\;x \leq 1.85:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.125, x, 0.3333333333333333\right), x, -0.5\right) \cdot x, x, 1\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{2}\\
\end{array}
\end{array}
if x < -195Initial 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
+-commutativeN/A
lower-+.f64N/A
lower-/.f6450.4
Applied rewrites50.4%
Taylor expanded in eps around 0
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites31.6%
if -195 < x < 1.8500000000000001Initial program 50.5%
Taylor expanded in eps around 0
*-commutativeN/A
lower-*.f64N/A
Applied rewrites78.6%
Taylor expanded in x around 0
Applied rewrites77.5%
Applied rewrites77.5%
if 1.8500000000000001 < x Initial program 100.0%
+-lft-identityN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites79.5%
Taylor expanded in eps around 0
div-subN/A
neg-mul-1N/A
+-inverses59.6
Applied rewrites59.6%
(FPCore (x eps) :precision binary64 (if (<= x 1650000000000.0) 1.0 (/ 0.0 2.0)))
double code(double x, double eps) {
double tmp;
if (x <= 1650000000000.0) {
tmp = 1.0;
} else {
tmp = 0.0 / 2.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 1650000000000.0d0) then
tmp = 1.0d0
else
tmp = 0.0d0 / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 1650000000000.0) {
tmp = 1.0;
} else {
tmp = 0.0 / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 1650000000000.0: tmp = 1.0 else: tmp = 0.0 / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 1650000000000.0) tmp = 1.0; else tmp = Float64(0.0 / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 1650000000000.0) tmp = 1.0; else tmp = 0.0 / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 1650000000000.0], 1.0, N[(0.0 / 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1650000000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{2}\\
\end{array}
\end{array}
if x < 1.65e12Initial program 63.5%
Taylor expanded in x around 0
Applied rewrites57.5%
if 1.65e12 < x Initial program 100.0%
+-lft-identityN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites78.1%
Taylor expanded in eps around 0
div-subN/A
neg-mul-1N/A
+-inverses63.6
Applied rewrites63.6%
(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.9%
Taylor expanded in x around 0
Applied rewrites42.0%
herbie shell --seed 2024332
(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))