
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x eps) :precision binary64 (/ (- (* (+ 1.0 (/ 1.0 eps)) (exp (- (* (- 1.0 eps) x)))) (* (- (/ 1.0 eps) 1.0) (exp (- (* (+ 1.0 eps) x))))) 2.0))
double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = (((1.0d0 + (1.0d0 / eps)) * exp(-((1.0d0 - eps) * x))) - (((1.0d0 / eps) - 1.0d0) * exp(-((1.0d0 + eps) * x)))) / 2.0d0
end function
public static double code(double x, double eps) {
return (((1.0 + (1.0 / eps)) * Math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * Math.exp(-((1.0 + eps) * x)))) / 2.0;
}
def code(x, eps): return (((1.0 + (1.0 / eps)) * math.exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * math.exp(-((1.0 + eps) * x)))) / 2.0
function code(x, eps) return Float64(Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(-Float64(Float64(1.0 - eps) * x)))) - Float64(Float64(Float64(1.0 / eps) - 1.0) * exp(Float64(-Float64(Float64(1.0 + eps) * x))))) / 2.0) end
function tmp = code(x, eps) tmp = (((1.0 + (1.0 / eps)) * exp(-((1.0 - eps) * x))) - (((1.0 / eps) - 1.0) * exp(-((1.0 + eps) * x)))) / 2.0; end
code[x_, eps_] := N[(N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[(-N[(N[(1.0 - eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision] - N[(N[(N[(1.0 / eps), $MachinePrecision] - 1.0), $MachinePrecision] * N[Exp[(-N[(N[(1.0 + eps), $MachinePrecision] * x), $MachinePrecision])], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(1 + \frac{1}{\varepsilon}\right) \cdot e^{-\left(1 - \varepsilon\right) \cdot x} - \left(\frac{1}{\varepsilon} - 1\right) \cdot e^{-\left(1 + \varepsilon\right) \cdot x}}{2}
\end{array}
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (if (<= eps 0.000235) (/ (* 2.0 (/ (+ x 1.0) (exp x))) 2.0) (/ (+ (exp (* eps x)) (exp (* eps (- x)))) 2.0)))
eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (eps <= 0.000235) {
tmp = (2.0 * ((x + 1.0) / exp(x))) / 2.0;
} else {
tmp = (exp((eps * x)) + 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) :: tmp
if (eps <= 0.000235d0) then
tmp = (2.0d0 * ((x + 1.0d0) / exp(x))) / 2.0d0
else
tmp = (exp((eps * x)) + exp((eps * -x))) / 2.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double tmp;
if (eps <= 0.000235) {
tmp = (2.0 * ((x + 1.0) / Math.exp(x))) / 2.0;
} else {
tmp = (Math.exp((eps * x)) + Math.exp((eps * -x))) / 2.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if eps <= 0.000235: tmp = (2.0 * ((x + 1.0) / math.exp(x))) / 2.0 else: tmp = (math.exp((eps * x)) + math.exp((eps * -x))) / 2.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (eps <= 0.000235) tmp = Float64(Float64(2.0 * Float64(Float64(x + 1.0) / exp(x))) / 2.0); else tmp = Float64(Float64(exp(Float64(eps * x)) + exp(Float64(eps * Float64(-x)))) / 2.0); end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) tmp = 0.0; if (eps <= 0.000235) tmp = (2.0 * ((x + 1.0) / exp(x))) / 2.0; else tmp = (exp((eps * x)) + exp((eps * -x))) / 2.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function code[x_, eps_] := If[LessEqual[eps, 0.000235], N[(N[(2.0 * N[(N[(x + 1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[Exp[N[(eps * x), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;\varepsilon \leq 0.000235:\\
\;\;\;\;\frac{2 \cdot \frac{x + 1}{e^{x}}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{\varepsilon \cdot x} + e^{\varepsilon \cdot \left(-x\right)}}{2}\\
\end{array}
\end{array}
if eps < 2.34999999999999993e-4Initial program 57.1%
sub-neg57.1%
neg-sub057.1%
associate-+r-57.1%
Simplified57.1%
Taylor expanded in eps around 0 77.0%
associate--r+76.9%
associate-*r*76.9%
neg-mul-176.9%
cancel-sign-sub76.9%
distribute-rgt1-in76.9%
distribute-rgt-out--76.9%
neg-mul-176.9%
neg-mul-176.9%
Simplified76.9%
Taylor expanded in x around inf 77.0%
distribute-lft-out77.0%
distribute-rgt1-in76.9%
+-commutative76.9%
rec-exp77.0%
associate-*r/77.0%
*-commutative77.0%
*-lft-identity77.0%
Simplified77.0%
if 2.34999999999999993e-4 < eps Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
associate-+r-100.0%
Simplified100.0%
Taylor expanded in eps around inf 100.0%
associate-*r*100.0%
neg-mul-1100.0%
*-commutative100.0%
mul-1-neg100.0%
mul-1-neg100.0%
distribute-lft-neg-out100.0%
exp-prod82.6%
remove-double-neg82.6%
mul-1-neg82.6%
sub-neg82.6%
exp-prod100.0%
neg-mul-1100.0%
associate-*r*100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
sub-neg100.0%
mul-1-neg100.0%
remove-double-neg100.0%
distribute-rgt-neg-in100.0%
distribute-lft-in100.0%
Simplified100.0%
Taylor expanded in eps around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in eps around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification83.3%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (/ (+ (exp (- (* eps x) x)) (/ 1.0 (exp (fma eps x x)))) 2.0))
eps = abs(eps);
double code(double x, double eps) {
return (exp(((eps * x) - x)) + (1.0 / exp(fma(eps, x, x)))) / 2.0;
}
eps = abs(eps) function code(x, eps) return Float64(Float64(exp(Float64(Float64(eps * x) - x)) + Float64(1.0 / exp(fma(eps, x, x)))) / 2.0) end
NOTE: eps should be positive before calling this function code[x_, eps_] := N[(N[(N[Exp[N[(N[(eps * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision] + N[(1.0 / N[Exp[N[(eps * x + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
eps = |eps|\\
\\
\frac{e^{\varepsilon \cdot x - x} + \frac{1}{e^{\mathsf{fma}\left(\varepsilon, x, x\right)}}}{2}
\end{array}
Initial program 69.0%
Simplified68.9%
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 (+ eps -1.0))) (exp (- (- x) (* eps x)))) 2.0))
eps = abs(eps);
double code(double x, double eps) {
return (exp((x * (eps + -1.0))) + exp((-x - (eps * 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 * (eps + (-1.0d0)))) + exp((-x - (eps * x)))) / 2.0d0
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
return (Math.exp((x * (eps + -1.0))) + Math.exp((-x - (eps * x)))) / 2.0;
}
eps = abs(eps) def code(x, eps): return (math.exp((x * (eps + -1.0))) + math.exp((-x - (eps * x)))) / 2.0
eps = abs(eps) function code(x, eps) return Float64(Float64(exp(Float64(x * Float64(eps + -1.0))) + exp(Float64(Float64(-x) - Float64(eps * x)))) / 2.0) end
eps = abs(eps) function tmp = code(x, eps) tmp = (exp((x * (eps + -1.0))) + exp((-x - (eps * x)))) / 2.0; end
NOTE: eps should be positive before calling this function code[x_, eps_] := N[(N[(N[Exp[N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[N[((-x) - N[(eps * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
eps = |eps|\\
\\
\frac{e^{x \cdot \left(\varepsilon + -1\right)} + e^{\left(-x\right) - \varepsilon \cdot x}}{2}
\end{array}
Initial program 69.0%
sub-neg69.0%
neg-sub069.0%
associate-+r-69.0%
Simplified69.0%
Taylor expanded in eps around inf 98.6%
associate-*r*98.6%
neg-mul-198.6%
*-commutative98.6%
mul-1-neg98.6%
mul-1-neg98.6%
distribute-lft-neg-out98.6%
exp-prod91.6%
remove-double-neg91.6%
mul-1-neg91.6%
sub-neg91.6%
exp-prod98.6%
neg-mul-198.6%
associate-*r*98.6%
mul-1-neg98.6%
distribute-rgt-neg-in98.6%
sub-neg98.6%
mul-1-neg98.6%
remove-double-neg98.6%
distribute-rgt-neg-in98.6%
distribute-lft-in98.6%
Simplified98.6%
Final simplification98.6%
NOTE: eps should be positive before calling this function
(FPCore (x eps)
:precision binary64
(if (<= x -5e-275)
(/ (+ (exp (* eps (- x))) 1.0) 2.0)
(if (<= x 3.55e+49)
(/ (+ (exp (- (* eps x) x)) (+ (* x (- -1.0 eps)) 1.0)) 2.0)
(/ (* 2.0 (/ (+ x 1.0) (exp x))) 2.0))))eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (x <= -5e-275) {
tmp = (exp((eps * -x)) + 1.0) / 2.0;
} else if (x <= 3.55e+49) {
tmp = (exp(((eps * x) - x)) + ((x * (-1.0 - eps)) + 1.0)) / 2.0;
} else {
tmp = (2.0 * ((x + 1.0) / exp(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) :: tmp
if (x <= (-5d-275)) then
tmp = (exp((eps * -x)) + 1.0d0) / 2.0d0
else if (x <= 3.55d+49) then
tmp = (exp(((eps * x) - x)) + ((x * ((-1.0d0) - eps)) + 1.0d0)) / 2.0d0
else
tmp = (2.0d0 * ((x + 1.0d0) / exp(x))) / 2.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double tmp;
if (x <= -5e-275) {
tmp = (Math.exp((eps * -x)) + 1.0) / 2.0;
} else if (x <= 3.55e+49) {
tmp = (Math.exp(((eps * x) - x)) + ((x * (-1.0 - eps)) + 1.0)) / 2.0;
} else {
tmp = (2.0 * ((x + 1.0) / Math.exp(x))) / 2.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if x <= -5e-275: tmp = (math.exp((eps * -x)) + 1.0) / 2.0 elif x <= 3.55e+49: tmp = (math.exp(((eps * x) - x)) + ((x * (-1.0 - eps)) + 1.0)) / 2.0 else: tmp = (2.0 * ((x + 1.0) / math.exp(x))) / 2.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (x <= -5e-275) tmp = Float64(Float64(exp(Float64(eps * Float64(-x))) + 1.0) / 2.0); elseif (x <= 3.55e+49) tmp = Float64(Float64(exp(Float64(Float64(eps * x) - x)) + Float64(Float64(x * Float64(-1.0 - eps)) + 1.0)) / 2.0); else tmp = Float64(Float64(2.0 * Float64(Float64(x + 1.0) / exp(x))) / 2.0); end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -5e-275) tmp = (exp((eps * -x)) + 1.0) / 2.0; elseif (x <= 3.55e+49) tmp = (exp(((eps * x) - x)) + ((x * (-1.0 - eps)) + 1.0)) / 2.0; else tmp = (2.0 * ((x + 1.0) / exp(x))) / 2.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function code[x_, eps_] := If[LessEqual[x, -5e-275], N[(N[(N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 3.55e+49], N[(N[(N[Exp[N[(N[(eps * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision] + N[(N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(2.0 * N[(N[(x + 1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-275}:\\
\;\;\;\;\frac{e^{\varepsilon \cdot \left(-x\right)} + 1}{2}\\
\mathbf{elif}\;x \leq 3.55 \cdot 10^{+49}:\\
\;\;\;\;\frac{e^{\varepsilon \cdot x - x} + \left(x \cdot \left(-1 - \varepsilon\right) + 1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \frac{x + 1}{e^{x}}}{2}\\
\end{array}
\end{array}
if x < -4.99999999999999983e-275Initial program 65.0%
sub-neg65.0%
neg-sub065.0%
associate-+r-65.0%
Simplified65.0%
Taylor expanded in x around 0 40.3%
metadata-eval40.3%
distribute-neg-frac40.3%
sub-neg40.3%
Simplified40.3%
Taylor expanded in eps around inf 73.9%
mul-1-neg73.9%
associate-*r*73.9%
neg-mul-173.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in eps around inf 74.2%
associate-*r*74.2%
mul-1-neg74.2%
Simplified74.2%
if -4.99999999999999983e-275 < x < 3.54999999999999986e49Initial program 57.1%
Simplified57.0%
Taylor expanded in eps around inf 97.9%
Taylor expanded in x around 0 84.6%
associate-*r*84.6%
neg-mul-184.6%
*-commutative84.6%
Simplified84.6%
if 3.54999999999999986e49 < x Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
associate-+r-100.0%
Simplified100.0%
Taylor expanded in eps around 0 63.3%
associate--r+63.3%
associate-*r*63.3%
neg-mul-163.3%
cancel-sign-sub63.3%
distribute-rgt1-in63.3%
distribute-rgt-out--63.3%
neg-mul-163.3%
neg-mul-163.3%
Simplified63.3%
Taylor expanded in x around inf 63.3%
distribute-lft-out63.3%
distribute-rgt1-in63.3%
+-commutative63.3%
rec-exp63.3%
associate-*r/63.3%
*-commutative63.3%
*-lft-identity63.3%
Simplified63.3%
Final simplification76.0%
NOTE: eps should be positive before calling this function
(FPCore (x eps)
:precision binary64
(if (<= x 2e-252)
(/ (/ 2.0 (exp x)) 2.0)
(if (<= x 5.2e+81)
(/ (+ (exp (- (* eps x) x)) 1.0) 2.0)
(/ (* 2.0 (/ (+ x 1.0) (exp x))) 2.0))))eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (x <= 2e-252) {
tmp = (2.0 / exp(x)) / 2.0;
} else if (x <= 5.2e+81) {
tmp = (exp(((eps * x) - x)) + 1.0) / 2.0;
} else {
tmp = (2.0 * ((x + 1.0) / exp(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) :: tmp
if (x <= 2d-252) then
tmp = (2.0d0 / exp(x)) / 2.0d0
else if (x <= 5.2d+81) then
tmp = (exp(((eps * x) - x)) + 1.0d0) / 2.0d0
else
tmp = (2.0d0 * ((x + 1.0d0) / exp(x))) / 2.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double tmp;
if (x <= 2e-252) {
tmp = (2.0 / Math.exp(x)) / 2.0;
} else if (x <= 5.2e+81) {
tmp = (Math.exp(((eps * x) - x)) + 1.0) / 2.0;
} else {
tmp = (2.0 * ((x + 1.0) / Math.exp(x))) / 2.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if x <= 2e-252: tmp = (2.0 / math.exp(x)) / 2.0 elif x <= 5.2e+81: tmp = (math.exp(((eps * x) - x)) + 1.0) / 2.0 else: tmp = (2.0 * ((x + 1.0) / math.exp(x))) / 2.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (x <= 2e-252) tmp = Float64(Float64(2.0 / exp(x)) / 2.0); elseif (x <= 5.2e+81) tmp = Float64(Float64(exp(Float64(Float64(eps * x) - x)) + 1.0) / 2.0); else tmp = Float64(Float64(2.0 * Float64(Float64(x + 1.0) / exp(x))) / 2.0); end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 2e-252) tmp = (2.0 / exp(x)) / 2.0; elseif (x <= 5.2e+81) tmp = (exp(((eps * x) - x)) + 1.0) / 2.0; else tmp = (2.0 * ((x + 1.0) / exp(x))) / 2.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function code[x_, eps_] := If[LessEqual[x, 2e-252], N[(N[(2.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 5.2e+81], N[(N[(N[Exp[N[(N[(eps * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(2.0 * N[(N[(x + 1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{-252}:\\
\;\;\;\;\frac{\frac{2}{e^{x}}}{2}\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{+81}:\\
\;\;\;\;\frac{e^{\varepsilon \cdot x - x} + 1}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \frac{x + 1}{e^{x}}}{2}\\
\end{array}
\end{array}
if x < 1.99999999999999989e-252Initial program 62.6%
Simplified62.5%
Taylor expanded in eps around inf 98.8%
Taylor expanded in eps around 0 80.9%
rec-exp80.9%
count-280.9%
rec-exp80.9%
associate-*r/80.9%
metadata-eval80.9%
Simplified80.9%
if 1.99999999999999989e-252 < x < 5.19999999999999984e81Initial program 62.0%
Simplified61.9%
Taylor expanded in eps around inf 97.4%
Taylor expanded in x around 0 76.2%
if 5.19999999999999984e81 < x Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
associate-+r-100.0%
Simplified100.0%
Taylor expanded in eps around 0 65.0%
associate--r+65.0%
associate-*r*65.0%
neg-mul-165.0%
cancel-sign-sub65.0%
distribute-rgt1-in65.0%
distribute-rgt-out--65.0%
neg-mul-165.0%
neg-mul-165.0%
Simplified65.0%
Taylor expanded in x around inf 65.0%
distribute-lft-out65.0%
distribute-rgt1-in65.0%
+-commutative65.0%
rec-exp65.0%
associate-*r/65.0%
*-commutative65.0%
*-lft-identity65.0%
Simplified65.0%
Final simplification76.6%
NOTE: eps should be positive before calling this function
(FPCore (x eps)
:precision binary64
(if (<= x -1e-278)
(/ (+ (exp (* eps (- x))) 1.0) 2.0)
(if (<= x 1.1e+82)
(/ (+ (exp (- (* eps x) x)) 1.0) 2.0)
(/ (* 2.0 (/ (+ x 1.0) (exp x))) 2.0))))eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (x <= -1e-278) {
tmp = (exp((eps * -x)) + 1.0) / 2.0;
} else if (x <= 1.1e+82) {
tmp = (exp(((eps * x) - x)) + 1.0) / 2.0;
} else {
tmp = (2.0 * ((x + 1.0) / exp(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) :: tmp
if (x <= (-1d-278)) then
tmp = (exp((eps * -x)) + 1.0d0) / 2.0d0
else if (x <= 1.1d+82) then
tmp = (exp(((eps * x) - x)) + 1.0d0) / 2.0d0
else
tmp = (2.0d0 * ((x + 1.0d0) / exp(x))) / 2.0d0
end if
code = tmp
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
double tmp;
if (x <= -1e-278) {
tmp = (Math.exp((eps * -x)) + 1.0) / 2.0;
} else if (x <= 1.1e+82) {
tmp = (Math.exp(((eps * x) - x)) + 1.0) / 2.0;
} else {
tmp = (2.0 * ((x + 1.0) / Math.exp(x))) / 2.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if x <= -1e-278: tmp = (math.exp((eps * -x)) + 1.0) / 2.0 elif x <= 1.1e+82: tmp = (math.exp(((eps * x) - x)) + 1.0) / 2.0 else: tmp = (2.0 * ((x + 1.0) / math.exp(x))) / 2.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (x <= -1e-278) tmp = Float64(Float64(exp(Float64(eps * Float64(-x))) + 1.0) / 2.0); elseif (x <= 1.1e+82) tmp = Float64(Float64(exp(Float64(Float64(eps * x) - x)) + 1.0) / 2.0); else tmp = Float64(Float64(2.0 * Float64(Float64(x + 1.0) / exp(x))) / 2.0); end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -1e-278) tmp = (exp((eps * -x)) + 1.0) / 2.0; elseif (x <= 1.1e+82) tmp = (exp(((eps * x) - x)) + 1.0) / 2.0; else tmp = (2.0 * ((x + 1.0) / exp(x))) / 2.0; end tmp_2 = tmp; end
NOTE: eps should be positive before calling this function code[x_, eps_] := If[LessEqual[x, -1e-278], N[(N[(N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.1e+82], N[(N[(N[Exp[N[(N[(eps * x), $MachinePrecision] - x), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(2.0 * N[(N[(x + 1.0), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{-278}:\\
\;\;\;\;\frac{e^{\varepsilon \cdot \left(-x\right)} + 1}{2}\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{+82}:\\
\;\;\;\;\frac{e^{\varepsilon \cdot x - x} + 1}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \frac{x + 1}{e^{x}}}{2}\\
\end{array}
\end{array}
if x < -9.99999999999999938e-279Initial program 65.0%
sub-neg65.0%
neg-sub065.0%
associate-+r-65.0%
Simplified65.0%
Taylor expanded in x around 0 40.3%
metadata-eval40.3%
distribute-neg-frac40.3%
sub-neg40.3%
Simplified40.3%
Taylor expanded in eps around inf 73.9%
mul-1-neg73.9%
associate-*r*73.9%
neg-mul-173.9%
*-commutative73.9%
Simplified73.9%
Taylor expanded in eps around inf 74.2%
associate-*r*74.2%
mul-1-neg74.2%
Simplified74.2%
if -9.99999999999999938e-279 < x < 1.1000000000000001e82Initial program 59.6%
Simplified59.5%
Taylor expanded in eps around inf 98.0%
Taylor expanded in x around 0 81.2%
if 1.1000000000000001e82 < x Initial program 100.0%
sub-neg100.0%
neg-sub0100.0%
associate-+r-100.0%
Simplified100.0%
Taylor expanded in eps around 0 65.0%
associate--r+65.0%
associate-*r*65.0%
neg-mul-165.0%
cancel-sign-sub65.0%
distribute-rgt1-in65.0%
distribute-rgt-out--65.0%
neg-mul-165.0%
neg-mul-165.0%
Simplified65.0%
Taylor expanded in x around inf 65.0%
distribute-lft-out65.0%
distribute-rgt1-in65.0%
+-commutative65.0%
rec-exp65.0%
associate-*r/65.0%
*-commutative65.0%
*-lft-identity65.0%
Simplified65.0%
Final simplification75.4%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (/ (/ 2.0 (exp x)) 2.0))
eps = abs(eps);
double code(double x, double eps) {
return (2.0 / 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 = (2.0d0 / exp(x)) / 2.0d0
end function
eps = Math.abs(eps);
public static double code(double x, double eps) {
return (2.0 / Math.exp(x)) / 2.0;
}
eps = abs(eps) def code(x, eps): return (2.0 / math.exp(x)) / 2.0
eps = abs(eps) function code(x, eps) return Float64(Float64(2.0 / exp(x)) / 2.0) end
eps = abs(eps) function tmp = code(x, eps) tmp = (2.0 / exp(x)) / 2.0; end
NOTE: eps should be positive before calling this function code[x_, eps_] := N[(N[(2.0 / N[Exp[x], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]
\begin{array}{l}
eps = |eps|\\
\\
\frac{\frac{2}{e^{x}}}{2}
\end{array}
Initial program 69.0%
Simplified68.9%
Taylor expanded in eps around inf 98.6%
Taylor expanded in eps around 0 73.6%
rec-exp73.6%
count-273.6%
rec-exp73.6%
associate-*r/73.6%
metadata-eval73.6%
Simplified73.6%
Final simplification73.6%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (if (<= x 0.004) (/ (- 2.0 (* eps x)) 2.0) 0.0))
eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (x <= 0.004) {
tmp = (2.0 - (eps * x)) / 2.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 <= 0.004d0) then
tmp = (2.0d0 - (eps * x)) / 2.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 <= 0.004) {
tmp = (2.0 - (eps * x)) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if x <= 0.004: tmp = (2.0 - (eps * x)) / 2.0 else: tmp = 0.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (x <= 0.004) tmp = Float64(Float64(2.0 - Float64(eps * x)) / 2.0); else tmp = 0.0; end return tmp end
eps = abs(eps) function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 0.004) tmp = (2.0 - (eps * x)) / 2.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, 0.004], N[(N[(2.0 - N[(eps * x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.004:\\
\;\;\;\;\frac{2 - \varepsilon \cdot x}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 0.0040000000000000001Initial program 58.7%
sub-neg58.7%
neg-sub058.7%
associate-+r-58.7%
Simplified58.7%
Taylor expanded in x around 0 40.8%
metadata-eval40.8%
distribute-neg-frac40.8%
sub-neg40.8%
Simplified40.8%
Taylor expanded in x around 0 47.6%
associate-*r*47.6%
sub-neg47.6%
metadata-eval47.6%
+-commutative47.6%
Simplified47.6%
Taylor expanded in eps around inf 68.0%
mul-1-neg68.0%
*-commutative68.0%
unsub-neg68.0%
Simplified68.0%
if 0.0040000000000000001 < x Initial program 98.6%
Simplified98.6%
Taylor expanded in eps around 0 55.3%
neg-mul-155.3%
rec-exp55.3%
neg-mul-155.3%
div-sub55.3%
+-inverses55.3%
Simplified55.3%
Final simplification64.7%
NOTE: eps should be positive before calling this function (FPCore (x eps) :precision binary64 (if (<= x 7800000.0) 1.0 0.0))
eps = abs(eps);
double code(double x, double eps) {
double tmp;
if (x <= 7800000.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 <= 7800000.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 <= 7800000.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps = abs(eps) def code(x, eps): tmp = 0 if x <= 7800000.0: tmp = 1.0 else: tmp = 0.0 return tmp
eps = abs(eps) function code(x, eps) tmp = 0.0 if (x <= 7800000.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 <= 7800000.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, 7800000.0], 1.0, 0.0]
\begin{array}{l}
eps = |eps|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7800000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 7.8e6Initial program 59.3%
sub-neg59.3%
neg-sub059.3%
associate-+r-59.3%
Simplified59.3%
Taylor expanded in x around 0 63.1%
if 7.8e6 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 59.7%
neg-mul-159.7%
rec-exp59.7%
neg-mul-159.7%
div-sub59.7%
+-inverses59.7%
Simplified59.7%
Final simplification62.3%
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 69.0%
Simplified68.9%
Taylor expanded in eps around 0 16.0%
neg-mul-116.0%
rec-exp16.0%
neg-mul-116.0%
div-sub16.0%
+-inverses16.2%
Simplified16.2%
Final simplification16.2%
herbie shell --seed 2023279
(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))