
(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}
NOTE: eps should be positive before calling this function
(FPCore (x eps)
:precision binary64
(let* ((t_0 (* (+ x 1.0) (exp (- x)))))
(if (<= eps 5e-56)
(/ (+ t_0 t_0) 2.0)
(/ (+ (exp (* x (+ -1.0 eps))) (exp (* eps (- x)))) 2.0))))eps = abs(eps);
double code(double x, double eps) {
double t_0 = (x + 1.0) * exp(-x);
double tmp;
if (eps <= 5e-56) {
tmp = (t_0 + t_0) / 2.0;
} else {
tmp = (exp((x * (-1.0 + eps))) + exp((eps * -x))) / 2.0;
}
return tmp;
}
NOTE: eps should be positive before calling this function
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 = (x + 1.0d0) * exp(-x)
if (eps <= 5d-56) then
tmp = (t_0 + t_0) / 2.0d0
else
tmp = (exp((x * ((-1.0d0) + eps))) + exp((eps * -x))) / 2.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double t_0 = (x + 1.0) * Math.exp(-x);
double tmp;
if (eps <= 5e-56) {
tmp = (t_0 + t_0) / 2.0;
} else {
tmp = (Math.exp((x * (-1.0 + eps))) + Math.exp((eps * -x))) / 2.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): t_0 = (x + 1.0) * math.exp(-x) tmp = 0 if eps <= 5e-56: tmp = (t_0 + t_0) / 2.0 else: tmp = (math.exp((x * (-1.0 + eps))) + math.exp((eps * -x))) / 2.0 return tmp
eps = abs(eps) function code(x, eps) t_0 = Float64(Float64(x + 1.0) * exp(Float64(-x))) tmp = 0.0 if (eps <= 5e-56) tmp = Float64(Float64(t_0 + t_0) / 2.0); else tmp = Float64(Float64(exp(Float64(x * Float64(-1.0 + eps))) + exp(Float64(eps * Float64(-x)))) / 2.0); end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) t_0 = (x + 1.0) * exp(-x); tmp = 0.0; if (eps <= 5e-56) tmp = (t_0 + t_0) / 2.0; else tmp = (exp((x * (-1.0 + eps))) + exp((eps * -x))) / 2.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function
code[x_, eps_] := Block[{t$95$0 = N[(N[(x + 1.0), $MachinePrecision] * N[Exp[(-x)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[eps, 5e-56], N[(N[(t$95$0 + t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[Exp[N[(x * N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
t_0 := \left(x + 1\right) \cdot e^{-x}\\
\mathbf{if}\;\varepsilon \leq 5 \cdot 10^{-56}:\\
\;\;\;\;\frac{t_0 + t_0}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x \cdot \left(-1 + \varepsilon\right)} + e^{\varepsilon \cdot \left(-x\right)}}{2}\\
\end{array}
\end{array}
if eps < 4.99999999999999997e-56Initial program 57.4%
div-sub57.4%
+-rgt-identity57.4%
div-sub57.4%
Simplified57.4%
Taylor expanded in eps around 0 71.4%
*-commutative71.4%
distribute-lft1-in71.4%
neg-mul-171.4%
distribute-lft-out71.4%
mul-1-neg71.4%
*-commutative71.4%
distribute-lft1-in71.4%
neg-mul-171.4%
Simplified71.4%
if 4.99999999999999997e-56 < eps Initial program 92.1%
div-sub92.1%
+-rgt-identity92.1%
div-sub92.1%
Simplified92.1%
Taylor expanded in eps around inf 100.0%
Taylor expanded in eps around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification79.7%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (/ (+ (exp (* x (+ -1.0 eps))) (exp (* x (- -1.0 eps)))) 2.0))
eps = abs(eps);
double code(double x, double eps) {
return (exp((x * (-1.0 + eps))) + exp((x * (-1.0 - eps)))) / 2.0;
}
NOTE: eps should be positive before calling this function
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (exp((x * ((-1.0d0) + eps))) + exp((x * ((-1.0d0) - eps)))) / 2.0d0
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
return (Math.exp((x * (-1.0 + eps))) + Math.exp((x * (-1.0 - eps)))) / 2.0;
}
eps = abs(eps) def code(x, eps): return (math.exp((x * (-1.0 + eps))) + math.exp((x * (-1.0 - eps)))) / 2.0
eps = abs(eps) function code(x, eps) return Float64(Float64(exp(Float64(x * Float64(-1.0 + eps))) + exp(Float64(x * Float64(-1.0 - eps)))) / 2.0) end
eps = abs(eps) function tmp = code(x, eps) tmp = (exp((x * (-1.0 + eps))) + exp((x * (-1.0 - eps)))) / 2.0; end
NOTE: eps should be positive before calling this function code[x_, eps_] := N[(N[(N[Exp[N[(x * N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
eps = |eps|\\
\\
\frac{e^{x \cdot \left(-1 + \varepsilon\right)} + e^{x \cdot \left(-1 - \varepsilon\right)}}{2}
\end{array}
Initial program 67.4%
div-sub67.4%
+-rgt-identity67.4%
div-sub67.4%
Simplified67.4%
Taylor expanded in eps around inf 98.6%
Final simplification98.6%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (/ (+ (exp (* x (+ -1.0 eps))) (exp (- x))) 2.0))
eps = abs(eps);
double code(double x, double eps) {
return (exp((x * (-1.0 + eps))) + exp(-x)) / 2.0;
}
NOTE: eps should be positive before calling this function
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (exp((x * ((-1.0d0) + eps))) + exp(-x)) / 2.0d0
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
return (Math.exp((x * (-1.0 + eps))) + Math.exp(-x)) / 2.0;
}
eps = abs(eps) def code(x, eps): return (math.exp((x * (-1.0 + eps))) + math.exp(-x)) / 2.0
eps = abs(eps) function code(x, eps) return Float64(Float64(exp(Float64(x * Float64(-1.0 + eps))) + exp(Float64(-x))) / 2.0) end
eps = abs(eps) function tmp = code(x, eps) tmp = (exp((x * (-1.0 + eps))) + exp(-x)) / 2.0; end
NOTE: eps should be positive before calling this function code[x_, eps_] := N[(N[(N[Exp[N[(x * N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
eps = |eps|\\
\\
\frac{e^{x \cdot \left(-1 + \varepsilon\right)} + e^{-x}}{2}
\end{array}
Initial program 67.4%
div-sub67.4%
+-rgt-identity67.4%
div-sub67.4%
Simplified67.4%
Taylor expanded in eps around inf 98.6%
Taylor expanded in eps around 0 85.9%
Final simplification85.9%
NOTE: eps should be positive before calling this function
(FPCore (x eps)
:precision binary64
(let* ((t_0 (+ 1.0 (/ -1.0 eps)))
(t_1 (+ (/ 1.0 eps) 1.0))
(t_2 (/ (+ t_1 (* (exp (* x (- -1.0 eps))) t_0)) 2.0)))
(if (<= x -1.6e-19)
t_2
(if (<= x -1.45e-66)
1.0
(if (<= x -2.65e-111)
t_2
(if (<= x 950000000.0)
1.0
(if (<= x 2.2e+166)
0.0
(/ (+ (* (exp (* x (+ -1.0 eps))) t_1) t_0) 2.0))))))))eps = abs(eps);
double code(double x, double eps) {
double t_0 = 1.0 + (-1.0 / eps);
double t_1 = (1.0 / eps) + 1.0;
double t_2 = (t_1 + (exp((x * (-1.0 - eps))) * t_0)) / 2.0;
double tmp;
if (x <= -1.6e-19) {
tmp = t_2;
} else if (x <= -1.45e-66) {
tmp = 1.0;
} else if (x <= -2.65e-111) {
tmp = t_2;
} else if (x <= 950000000.0) {
tmp = 1.0;
} else if (x <= 2.2e+166) {
tmp = 0.0;
} else {
tmp = ((exp((x * (-1.0 + eps))) * t_1) + t_0) / 2.0;
}
return tmp;
}
NOTE: eps should be positive before calling this function
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: t_0
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = 1.0d0 + ((-1.0d0) / eps)
t_1 = (1.0d0 / eps) + 1.0d0
t_2 = (t_1 + (exp((x * ((-1.0d0) - eps))) * t_0)) / 2.0d0
if (x <= (-1.6d-19)) then
tmp = t_2
else if (x <= (-1.45d-66)) then
tmp = 1.0d0
else if (x <= (-2.65d-111)) then
tmp = t_2
else if (x <= 950000000.0d0) then
tmp = 1.0d0
else if (x <= 2.2d+166) then
tmp = 0.0d0
else
tmp = ((exp((x * ((-1.0d0) + eps))) * t_1) + t_0) / 2.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double t_0 = 1.0 + (-1.0 / eps);
double t_1 = (1.0 / eps) + 1.0;
double t_2 = (t_1 + (Math.exp((x * (-1.0 - eps))) * t_0)) / 2.0;
double tmp;
if (x <= -1.6e-19) {
tmp = t_2;
} else if (x <= -1.45e-66) {
tmp = 1.0;
} else if (x <= -2.65e-111) {
tmp = t_2;
} else if (x <= 950000000.0) {
tmp = 1.0;
} else if (x <= 2.2e+166) {
tmp = 0.0;
} else {
tmp = ((Math.exp((x * (-1.0 + eps))) * t_1) + t_0) / 2.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): t_0 = 1.0 + (-1.0 / eps) t_1 = (1.0 / eps) + 1.0 t_2 = (t_1 + (math.exp((x * (-1.0 - eps))) * t_0)) / 2.0 tmp = 0 if x <= -1.6e-19: tmp = t_2 elif x <= -1.45e-66: tmp = 1.0 elif x <= -2.65e-111: tmp = t_2 elif x <= 950000000.0: tmp = 1.0 elif x <= 2.2e+166: tmp = 0.0 else: tmp = ((math.exp((x * (-1.0 + eps))) * t_1) + t_0) / 2.0 return tmp
eps = abs(eps) function code(x, eps) t_0 = Float64(1.0 + Float64(-1.0 / eps)) t_1 = Float64(Float64(1.0 / eps) + 1.0) t_2 = Float64(Float64(t_1 + Float64(exp(Float64(x * Float64(-1.0 - eps))) * t_0)) / 2.0) tmp = 0.0 if (x <= -1.6e-19) tmp = t_2; elseif (x <= -1.45e-66) tmp = 1.0; elseif (x <= -2.65e-111) tmp = t_2; elseif (x <= 950000000.0) tmp = 1.0; elseif (x <= 2.2e+166) tmp = 0.0; else tmp = Float64(Float64(Float64(exp(Float64(x * Float64(-1.0 + eps))) * t_1) + t_0) / 2.0); end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) t_0 = 1.0 + (-1.0 / eps); t_1 = (1.0 / eps) + 1.0; t_2 = (t_1 + (exp((x * (-1.0 - eps))) * t_0)) / 2.0; tmp = 0.0; if (x <= -1.6e-19) tmp = t_2; elseif (x <= -1.45e-66) tmp = 1.0; elseif (x <= -2.65e-111) tmp = t_2; elseif (x <= 950000000.0) tmp = 1.0; elseif (x <= 2.2e+166) tmp = 0.0; else tmp = ((exp((x * (-1.0 + eps))) * t_1) + t_0) / 2.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function
code[x_, eps_] := Block[{t$95$0 = N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 + N[(N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]}, If[LessEqual[x, -1.6e-19], t$95$2, If[LessEqual[x, -1.45e-66], 1.0, If[LessEqual[x, -2.65e-111], t$95$2, If[LessEqual[x, 950000000.0], 1.0, If[LessEqual[x, 2.2e+166], 0.0, N[(N[(N[(N[Exp[N[(x * N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * t$95$1), $MachinePrecision] + t$95$0), $MachinePrecision] / 2.0), $MachinePrecision]]]]]]]]]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
t_0 := 1 + \frac{-1}{\varepsilon}\\
t_1 := \frac{1}{\varepsilon} + 1\\
t_2 := \frac{t_1 + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot t_0}{2}\\
\mathbf{if}\;x \leq -1.6 \cdot 10^{-19}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq -1.45 \cdot 10^{-66}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq -2.65 \cdot 10^{-111}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;x \leq 950000000:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+166}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x \cdot \left(-1 + \varepsilon\right)} \cdot t_1 + t_0}{2}\\
\end{array}
\end{array}
if x < -1.59999999999999991e-19 or -1.45000000000000006e-66 < x < -2.6499999999999999e-111Initial program 93.5%
div-sub93.5%
+-rgt-identity93.5%
div-sub93.5%
Simplified93.5%
Taylor expanded in x around 0 46.3%
if -1.59999999999999991e-19 < x < -1.45000000000000006e-66 or -2.6499999999999999e-111 < x < 9.5e8Initial program 44.9%
div-sub44.9%
+-rgt-identity44.9%
div-sub44.9%
Simplified44.9%
Taylor expanded in x around 0 79.0%
if 9.5e8 < x < 2.1999999999999999e166Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 66.3%
div-sub66.3%
rec-exp66.3%
neg-mul-166.3%
+-inverses66.3%
Simplified66.3%
if 2.1999999999999999e166 < x Initial program 100.0%
div-sub100.0%
+-rgt-identity100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 31.6%
Final simplification66.4%
NOTE: eps should be positive before calling this function
(FPCore (x eps)
:precision binary64
(if (<= x -580.0)
(/ (/ (exp (- x)) eps) 2.0)
(if (<= x 950000000.0)
1.0
(if (<= x 1.7e+166)
0.0
(/
(+
(* (exp (* x (+ -1.0 eps))) (+ (/ 1.0 eps) 1.0))
(+ 1.0 (/ -1.0 eps)))
2.0)))))eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (x <= -580.0) {
tmp = (exp(-x) / eps) / 2.0;
} else if (x <= 950000000.0) {
tmp = 1.0;
} else if (x <= 1.7e+166) {
tmp = 0.0;
} else {
tmp = ((exp((x * (-1.0 + eps))) * ((1.0 / eps) + 1.0)) + (1.0 + (-1.0 / eps))) / 2.0;
}
return tmp;
}
NOTE: eps should be positive before calling this function
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= (-580.0d0)) then
tmp = (exp(-x) / eps) / 2.0d0
else if (x <= 950000000.0d0) then
tmp = 1.0d0
else if (x <= 1.7d+166) then
tmp = 0.0d0
else
tmp = ((exp((x * ((-1.0d0) + eps))) * ((1.0d0 / eps) + 1.0d0)) + (1.0d0 + ((-1.0d0) / eps))) / 2.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double tmp;
if (x <= -580.0) {
tmp = (Math.exp(-x) / eps) / 2.0;
} else if (x <= 950000000.0) {
tmp = 1.0;
} else if (x <= 1.7e+166) {
tmp = 0.0;
} else {
tmp = ((Math.exp((x * (-1.0 + eps))) * ((1.0 / eps) + 1.0)) + (1.0 + (-1.0 / eps))) / 2.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if x <= -580.0: tmp = (math.exp(-x) / eps) / 2.0 elif x <= 950000000.0: tmp = 1.0 elif x <= 1.7e+166: tmp = 0.0 else: tmp = ((math.exp((x * (-1.0 + eps))) * ((1.0 / eps) + 1.0)) + (1.0 + (-1.0 / eps))) / 2.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (x <= -580.0) tmp = Float64(Float64(exp(Float64(-x)) / eps) / 2.0); elseif (x <= 950000000.0) tmp = 1.0; elseif (x <= 1.7e+166) tmp = 0.0; else tmp = Float64(Float64(Float64(exp(Float64(x * Float64(-1.0 + eps))) * Float64(Float64(1.0 / eps) + 1.0)) + Float64(1.0 + Float64(-1.0 / eps))) / 2.0); end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -580.0) tmp = (exp(-x) / eps) / 2.0; elseif (x <= 950000000.0) tmp = 1.0; elseif (x <= 1.7e+166) tmp = 0.0; else tmp = ((exp((x * (-1.0 + eps))) * ((1.0 / eps) + 1.0)) + (1.0 + (-1.0 / eps))) / 2.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function code[x_, eps_] := If[LessEqual[x, -580.0], N[(N[(N[Exp[(-x)], $MachinePrecision] / eps), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 950000000.0], 1.0, If[LessEqual[x, 1.7e+166], 0.0, N[(N[(N[(N[Exp[N[(x * N[(-1.0 + eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(N[(1.0 / eps), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -580:\\
\;\;\;\;\frac{\frac{e^{-x}}{\varepsilon}}{2}\\
\mathbf{elif}\;x \leq 950000000:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{+166}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x \cdot \left(-1 + \varepsilon\right)} \cdot \left(\frac{1}{\varepsilon} + 1\right) + \left(1 + \frac{-1}{\varepsilon}\right)}{2}\\
\end{array}
\end{array}
if x < -580Initial program 100.0%
Simplified100.0%
add-cube-cbrt100.0%
pow2100.0%
add-exp-log100.0%
log1p-udef100.0%
div-exp100.0%
add-exp-log100.0%
log1p-udef100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in eps around inf 100.0%
Taylor expanded in eps around 0 48.4%
mul-1-neg48.4%
Simplified48.4%
if -580 < x < 9.5e8Initial program 47.9%
div-sub47.9%
+-rgt-identity47.9%
div-sub47.9%
Simplified47.9%
Taylor expanded in x around 0 74.8%
if 9.5e8 < x < 1.7e166Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 66.3%
div-sub66.3%
rec-exp66.3%
neg-mul-166.3%
+-inverses66.3%
Simplified66.3%
if 1.7e166 < x Initial program 100.0%
div-sub100.0%
+-rgt-identity100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 31.6%
Final simplification65.8%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (if (<= x -580.0) (/ (/ (exp (- x)) eps) 2.0) (if (<= x 950000000.0) 1.0 0.0)))
eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (x <= -580.0) {
tmp = (exp(-x) / eps) / 2.0;
} else if (x <= 950000000.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
NOTE: eps should be positive before calling this function
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= (-580.0d0)) then
tmp = (exp(-x) / eps) / 2.0d0
else if (x <= 950000000.0d0) then
tmp = 1.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double tmp;
if (x <= -580.0) {
tmp = (Math.exp(-x) / eps) / 2.0;
} else if (x <= 950000000.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if x <= -580.0: tmp = (math.exp(-x) / eps) / 2.0 elif x <= 950000000.0: tmp = 1.0 else: tmp = 0.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (x <= -580.0) tmp = Float64(Float64(exp(Float64(-x)) / eps) / 2.0); elseif (x <= 950000000.0) tmp = 1.0; else tmp = 0.0; end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -580.0) tmp = (exp(-x) / eps) / 2.0; elseif (x <= 950000000.0) tmp = 1.0; else tmp = 0.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function code[x_, eps_] := If[LessEqual[x, -580.0], N[(N[(N[Exp[(-x)], $MachinePrecision] / eps), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 950000000.0], 1.0, 0.0]]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -580:\\
\;\;\;\;\frac{\frac{e^{-x}}{\varepsilon}}{2}\\
\mathbf{elif}\;x \leq 950000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -580Initial program 100.0%
Simplified100.0%
add-cube-cbrt100.0%
pow2100.0%
add-exp-log100.0%
log1p-udef100.0%
div-exp100.0%
add-exp-log100.0%
log1p-udef100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in eps around inf 100.0%
Taylor expanded in eps around 0 48.4%
mul-1-neg48.4%
Simplified48.4%
if -580 < x < 9.5e8Initial program 47.9%
div-sub47.9%
+-rgt-identity47.9%
div-sub47.9%
Simplified47.9%
Taylor expanded in x around 0 74.8%
if 9.5e8 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 54.6%
div-sub54.6%
rec-exp54.6%
neg-mul-154.6%
+-inverses54.6%
Simplified54.6%
Final simplification66.5%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (if (<= x 950000000.0) 1.0 0.0))
eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (x <= 950000000.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
NOTE: eps should be positive before calling this function
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 950000000.0d0) then
tmp = 1.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double tmp;
if (x <= 950000000.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if x <= 950000000.0: tmp = 1.0 else: tmp = 0.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (x <= 950000000.0) tmp = 1.0; else tmp = 0.0; end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 950000000.0) tmp = 1.0; else tmp = 0.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function code[x_, eps_] := If[LessEqual[x, 950000000.0], 1.0, 0.0]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 950000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 9.5e8Initial program 56.3%
div-sub56.3%
+-rgt-identity56.3%
div-sub56.3%
Simplified56.3%
Taylor expanded in x around 0 63.2%
if 9.5e8 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 54.6%
div-sub54.6%
rec-exp54.6%
neg-mul-154.6%
+-inverses54.6%
Simplified54.6%
Final simplification61.0%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 0.0)
eps = abs(eps);
double code(double x, double eps) {
return 0.0;
}
NOTE: eps should be positive before calling this function
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
return 0.0;
}
eps = abs(eps) def code(x, eps): return 0.0
eps = abs(eps) function code(x, eps) return 0.0 end
eps = abs(eps) function tmp = code(x, eps) tmp = 0.0; end
NOTE: eps should be positive before calling this function code[x_, eps_] := 0.0
\begin{array}{l}
eps = |eps|\\
\\
0
\end{array}
Initial program 67.4%
Simplified60.7%
Taylor expanded in eps around 0 15.6%
div-sub15.6%
rec-exp15.6%
neg-mul-115.6%
+-inverses15.8%
Simplified15.8%
Final simplification15.8%
herbie shell --seed 2023207
(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))