
(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 9 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}
eps_m = (fabs.f64 eps)
(FPCore (x eps_m)
:precision binary64
(if (<= eps_m 1.0)
(* (exp (- x)) (+ 1.0 x))
(/
(+
(exp (* 2.0 (+ (fma 0.5 (fma x eps_m x) 1.0) -1.0)))
(exp (* x (- -1.0 eps_m))))
2.0)))eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 1.0) {
tmp = exp(-x) * (1.0 + x);
} else {
tmp = (exp((2.0 * (fma(0.5, fma(x, eps_m, x), 1.0) + -1.0))) + exp((x * (-1.0 - eps_m)))) / 2.0;
}
return tmp;
}
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 1.0) tmp = Float64(exp(Float64(-x)) * Float64(1.0 + x)); else tmp = Float64(Float64(exp(Float64(2.0 * Float64(fma(0.5, fma(x, eps_m, x), 1.0) + -1.0))) + exp(Float64(x * Float64(-1.0 - eps_m)))) / 2.0); end return tmp end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 1.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(1.0 + x), $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[N[(2.0 * N[(N[(0.5 * N[(x * eps$95$m + x), $MachinePrecision] + 1.0), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(x * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 1:\\
\;\;\;\;e^{-x} \cdot \left(1 + x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{2 \cdot \left(\mathsf{fma}\left(0.5, \mathsf{fma}\left(x, eps\_m, x\right), 1\right) + -1\right)} + e^{x \cdot \left(-1 - eps\_m\right)}}{2}\\
\end{array}
\end{array}
if eps < 1Initial program 58.3%
Simplified47.3%
Taylor expanded in eps around 0 34.6%
associate-+r+75.7%
mul-1-neg75.7%
sub-neg75.7%
+-inverses75.7%
distribute-lft-out75.7%
distribute-rgt1-in76.2%
mul-1-neg76.2%
Simplified76.2%
Taylor expanded in eps around 0 76.2%
+-commutative76.2%
Simplified76.2%
if 1 < eps Initial program 100.0%
Simplified89.5%
Taylor expanded in eps around inf 100.0%
Taylor expanded in x around -inf 100.0%
rec-exp100.0%
*-commutative100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
neg-mul-1100.0%
exp-prod100.0%
fma-define100.0%
+-commutative100.0%
*-rgt-identity100.0%
distribute-lft-in100.0%
exp-prod100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
distribute-neg-in100.0%
metadata-eval100.0%
unsub-neg100.0%
Simplified100.0%
Applied egg-rr100.0%
count-2100.0%
Simplified100.0%
expm1-log1p-u70.6%
expm1-undefine70.6%
pow1/270.6%
log-pow70.6%
add-log-exp70.6%
Applied egg-rr70.6%
sub-neg70.6%
log1p-undefine70.6%
rem-exp-log100.0%
*-rgt-identity100.0%
distribute-rgt1-in100.0%
distribute-lft1-in100.0%
*-rgt-identity100.0%
fma-define100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification82.5%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= eps_m 1.0) (* (exp (- x)) (+ 1.0 x)) (/ (+ (exp (* x (- -1.0 eps_m))) (exp (* eps_m x))) 2.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 1.0) {
tmp = exp(-x) * (1.0 + x);
} else {
tmp = (exp((x * (-1.0 - eps_m))) + exp((eps_m * x))) / 2.0;
}
return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (eps_m <= 1.0d0) then
tmp = exp(-x) * (1.0d0 + x)
else
tmp = (exp((x * ((-1.0d0) - eps_m))) + exp((eps_m * x))) / 2.0d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (eps_m <= 1.0) {
tmp = Math.exp(-x) * (1.0 + x);
} else {
tmp = (Math.exp((x * (-1.0 - eps_m))) + Math.exp((eps_m * x))) / 2.0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if eps_m <= 1.0: tmp = math.exp(-x) * (1.0 + x) else: tmp = (math.exp((x * (-1.0 - eps_m))) + math.exp((eps_m * x))) / 2.0 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 1.0) tmp = Float64(exp(Float64(-x)) * Float64(1.0 + x)); else tmp = Float64(Float64(exp(Float64(x * Float64(-1.0 - eps_m))) + exp(Float64(eps_m * x))) / 2.0); end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (eps_m <= 1.0) tmp = exp(-x) * (1.0 + x); else tmp = (exp((x * (-1.0 - eps_m))) + exp((eps_m * x))) / 2.0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 1.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(1.0 + x), $MachinePrecision]), $MachinePrecision], N[(N[(N[Exp[N[(x * N[(-1.0 - eps$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + N[Exp[N[(eps$95$m * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 1:\\
\;\;\;\;e^{-x} \cdot \left(1 + x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{e^{x \cdot \left(-1 - eps\_m\right)} + e^{eps\_m \cdot x}}{2}\\
\end{array}
\end{array}
if eps < 1Initial program 58.3%
Simplified47.3%
Taylor expanded in eps around 0 34.6%
associate-+r+75.7%
mul-1-neg75.7%
sub-neg75.7%
+-inverses75.7%
distribute-lft-out75.7%
distribute-rgt1-in76.2%
mul-1-neg76.2%
Simplified76.2%
Taylor expanded in eps around 0 76.2%
+-commutative76.2%
Simplified76.2%
if 1 < eps Initial program 100.0%
Simplified89.5%
Taylor expanded in eps around inf 100.0%
Taylor expanded in x around -inf 100.0%
rec-exp100.0%
*-commutative100.0%
fma-neg100.0%
neg-mul-1100.0%
remove-double-neg100.0%
neg-mul-1100.0%
exp-prod100.0%
fma-define100.0%
+-commutative100.0%
*-rgt-identity100.0%
distribute-lft-in100.0%
exp-prod100.0%
mul-1-neg100.0%
distribute-rgt-neg-in100.0%
distribute-neg-in100.0%
metadata-eval100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in eps around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification82.5%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x -6.5e-257) (/ (+ 1.0 (exp (* eps_m (- x)))) 2.0) (if (<= x 75000000000000.0) (/ (+ 1.0 (exp (* eps_m x))) 2.0) 0.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= -6.5e-257) {
tmp = (1.0 + exp((eps_m * -x))) / 2.0;
} else if (x <= 75000000000000.0) {
tmp = (1.0 + exp((eps_m * x))) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (x <= (-6.5d-257)) then
tmp = (1.0d0 + exp((eps_m * -x))) / 2.0d0
else if (x <= 75000000000000.0d0) then
tmp = (1.0d0 + exp((eps_m * x))) / 2.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (x <= -6.5e-257) {
tmp = (1.0 + Math.exp((eps_m * -x))) / 2.0;
} else if (x <= 75000000000000.0) {
tmp = (1.0 + Math.exp((eps_m * x))) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if x <= -6.5e-257: tmp = (1.0 + math.exp((eps_m * -x))) / 2.0 elif x <= 75000000000000.0: tmp = (1.0 + math.exp((eps_m * x))) / 2.0 else: tmp = 0.0 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= -6.5e-257) tmp = Float64(Float64(1.0 + exp(Float64(eps_m * Float64(-x)))) / 2.0); elseif (x <= 75000000000000.0) tmp = Float64(Float64(1.0 + exp(Float64(eps_m * x))) / 2.0); else tmp = 0.0; end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (x <= -6.5e-257) tmp = (1.0 + exp((eps_m * -x))) / 2.0; elseif (x <= 75000000000000.0) tmp = (1.0 + exp((eps_m * x))) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, -6.5e-257], N[(N[(1.0 + N[Exp[N[(eps$95$m * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 75000000000000.0], N[(N[(1.0 + N[Exp[N[(eps$95$m * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.5 \cdot 10^{-257}:\\
\;\;\;\;\frac{1 + e^{eps\_m \cdot \left(-x\right)}}{2}\\
\mathbf{elif}\;x \leq 75000000000000:\\
\;\;\;\;\frac{1 + e^{eps\_m \cdot x}}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -6.5000000000000002e-257Initial program 61.7%
Simplified61.7%
Taylor expanded in x around 0 35.1%
Taylor expanded in eps around inf 68.6%
sub-neg68.6%
mul-1-neg68.6%
remove-double-neg68.6%
mul-1-neg68.6%
distribute-rgt-neg-in68.6%
distribute-neg-in68.6%
metadata-eval68.6%
unsub-neg68.6%
Simplified68.6%
Taylor expanded in eps around inf 69.3%
associate-*r*69.3%
neg-mul-169.3%
Simplified69.3%
if -6.5000000000000002e-257 < x < 7.5e13Initial program 52.8%
Simplified44.1%
Taylor expanded in eps around inf 99.1%
Taylor expanded in x around 0 91.8%
Taylor expanded in eps around inf 92.1%
*-commutative99.2%
Simplified92.1%
if 7.5e13 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 57.8%
div-sub57.8%
mul-1-neg57.8%
rec-exp57.8%
+-inverses57.8%
metadata-eval57.8%
Simplified57.8%
Final simplification73.5%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= eps_m 1.0) (* (exp (- x)) (+ 1.0 x)) (/ (/ (* eps_m (* (+ 1.0 x) (+ 2.0 (* x 2.0)))) eps_m) 2.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 1.0) {
tmp = exp(-x) * (1.0 + x);
} else {
tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0;
}
return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (eps_m <= 1.0d0) then
tmp = exp(-x) * (1.0d0 + x)
else
tmp = ((eps_m * ((1.0d0 + x) * (2.0d0 + (x * 2.0d0)))) / eps_m) / 2.0d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (eps_m <= 1.0) {
tmp = Math.exp(-x) * (1.0 + x);
} else {
tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if eps_m <= 1.0: tmp = math.exp(-x) * (1.0 + x) else: tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 1.0) tmp = Float64(exp(Float64(-x)) * Float64(1.0 + x)); else tmp = Float64(Float64(Float64(eps_m * Float64(Float64(1.0 + x) * Float64(2.0 + Float64(x * 2.0)))) / eps_m) / 2.0); end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (eps_m <= 1.0) tmp = exp(-x) * (1.0 + x); else tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 1.0], N[(N[Exp[(-x)], $MachinePrecision] * N[(1.0 + x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(eps$95$m * N[(N[(1.0 + x), $MachinePrecision] * N[(2.0 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / eps$95$m), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 1:\\
\;\;\;\;e^{-x} \cdot \left(1 + x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{eps\_m \cdot \left(\left(1 + x\right) \cdot \left(2 + x \cdot 2\right)\right)}{eps\_m}}{2}\\
\end{array}
\end{array}
if eps < 1Initial program 58.3%
Simplified47.3%
Taylor expanded in eps around 0 34.6%
associate-+r+75.7%
mul-1-neg75.7%
sub-neg75.7%
+-inverses75.7%
distribute-lft-out75.7%
distribute-rgt1-in76.2%
mul-1-neg76.2%
Simplified76.2%
Taylor expanded in eps around 0 76.2%
+-commutative76.2%
Simplified76.2%
if 1 < eps Initial program 100.0%
Simplified76.9%
Taylor expanded in eps around 0 27.7%
associate-+r+27.7%
mul-1-neg27.7%
sub-neg27.7%
+-inverses27.7%
distribute-lft-out27.7%
distribute-rgt1-in27.7%
mul-1-neg27.7%
Simplified27.7%
Taylor expanded in x around 0 27.3%
neg-mul-127.3%
sub-neg27.3%
Simplified27.3%
associate-*r*27.3%
sub-neg27.3%
distribute-rgt-in27.3%
*-un-lft-identity27.3%
+-commutative27.3%
distribute-rgt-in27.3%
metadata-eval27.3%
add-sqr-sqrt10.7%
sqrt-unprod45.5%
sqr-neg45.5%
sqrt-unprod34.9%
add-sqr-sqrt58.9%
+-commutative58.9%
distribute-rgt-in58.9%
metadata-eval58.9%
Applied egg-rr58.9%
distribute-rgt1-in58.9%
+-commutative58.9%
Simplified58.9%
Final simplification71.6%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= eps_m 1.6e+56) (exp (- x)) (/ (/ (* eps_m (* (+ 1.0 x) (+ 2.0 (* x 2.0)))) eps_m) 2.0)))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (eps_m <= 1.6e+56) {
tmp = exp(-x);
} else {
tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0;
}
return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (eps_m <= 1.6d+56) then
tmp = exp(-x)
else
tmp = ((eps_m * ((1.0d0 + x) * (2.0d0 + (x * 2.0d0)))) / eps_m) / 2.0d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (eps_m <= 1.6e+56) {
tmp = Math.exp(-x);
} else {
tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if eps_m <= 1.6e+56: tmp = math.exp(-x) else: tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (eps_m <= 1.6e+56) tmp = exp(Float64(-x)); else tmp = Float64(Float64(Float64(eps_m * Float64(Float64(1.0 + x) * Float64(2.0 + Float64(x * 2.0)))) / eps_m) / 2.0); end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (eps_m <= 1.6e+56) tmp = exp(-x); else tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[eps$95$m, 1.6e+56], N[Exp[(-x)], $MachinePrecision], N[(N[(N[(eps$95$m * N[(N[(1.0 + x), $MachinePrecision] * N[(2.0 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / eps$95$m), $MachinePrecision] / 2.0), $MachinePrecision]]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;eps\_m \leq 1.6 \cdot 10^{+56}:\\
\;\;\;\;e^{-x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{eps\_m \cdot \left(\left(1 + x\right) \cdot \left(2 + x \cdot 2\right)\right)}{eps\_m}}{2}\\
\end{array}
\end{array}
if eps < 1.60000000000000002e56Initial program 60.0%
Simplified57.2%
Taylor expanded in eps around inf 97.6%
Taylor expanded in x around -inf 97.6%
rec-exp97.6%
*-commutative97.6%
fma-neg97.6%
neg-mul-197.6%
remove-double-neg97.6%
neg-mul-197.6%
exp-prod97.6%
fma-define97.6%
+-commutative97.6%
*-rgt-identity97.6%
distribute-lft-in97.6%
exp-prod97.6%
mul-1-neg97.6%
distribute-rgt-neg-in97.6%
distribute-neg-in97.6%
metadata-eval97.6%
unsub-neg97.6%
Simplified97.6%
Taylor expanded in eps around 0 84.6%
neg-mul-184.6%
Simplified84.6%
if 1.60000000000000002e56 < eps Initial program 100.0%
Simplified77.0%
Taylor expanded in eps around 0 27.9%
associate-+r+27.9%
mul-1-neg27.9%
sub-neg27.9%
+-inverses27.9%
distribute-lft-out27.9%
distribute-rgt1-in27.9%
mul-1-neg27.9%
Simplified27.9%
Taylor expanded in x around 0 27.5%
neg-mul-127.5%
sub-neg27.5%
Simplified27.5%
associate-*r*27.5%
sub-neg27.5%
distribute-rgt-in27.5%
*-un-lft-identity27.5%
+-commutative27.5%
distribute-rgt-in27.5%
metadata-eval27.5%
add-sqr-sqrt8.8%
sqrt-unprod44.7%
sqr-neg44.7%
sqrt-unprod35.9%
add-sqr-sqrt58.2%
+-commutative58.2%
distribute-rgt-in58.2%
metadata-eval58.2%
Applied egg-rr58.2%
distribute-rgt1-in58.2%
+-commutative58.2%
Simplified58.2%
Final simplification78.4%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x 6400000.0) (/ (/ (* eps_m (* (+ 1.0 x) (+ 2.0 (* x 2.0)))) eps_m) 2.0) 0.0))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 6400000.0) {
tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (x <= 6400000.0d0) then
tmp = ((eps_m * ((1.0d0 + x) * (2.0d0 + (x * 2.0d0)))) / eps_m) / 2.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (x <= 6400000.0) {
tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if x <= 6400000.0: tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0 else: tmp = 0.0 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 6400000.0) tmp = Float64(Float64(Float64(eps_m * Float64(Float64(1.0 + x) * Float64(2.0 + Float64(x * 2.0)))) / eps_m) / 2.0); else tmp = 0.0; end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (x <= 6400000.0) tmp = ((eps_m * ((1.0 + x) * (2.0 + (x * 2.0)))) / eps_m) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 6400000.0], N[(N[(N[(eps$95$m * N[(N[(1.0 + x), $MachinePrecision] * N[(2.0 + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / eps$95$m), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6400000:\\
\;\;\;\;\frac{\frac{eps\_m \cdot \left(\left(1 + x\right) \cdot \left(2 + x \cdot 2\right)\right)}{eps\_m}}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 6.4e6Initial program 57.8%
Simplified38.3%
Taylor expanded in eps around 0 23.3%
associate-+r+64.8%
mul-1-neg64.8%
sub-neg64.8%
+-inverses64.8%
distribute-lft-out64.8%
distribute-rgt1-in65.4%
mul-1-neg65.4%
Simplified65.4%
Taylor expanded in x around 0 63.5%
neg-mul-163.5%
sub-neg63.5%
Simplified63.5%
associate-*r*63.5%
sub-neg63.5%
distribute-rgt-in63.5%
*-un-lft-identity63.5%
+-commutative63.5%
distribute-rgt-in63.5%
metadata-eval63.5%
add-sqr-sqrt32.9%
sqrt-unprod63.4%
sqr-neg63.4%
sqrt-unprod30.6%
add-sqr-sqrt76.6%
+-commutative76.6%
distribute-rgt-in76.6%
metadata-eval76.6%
Applied egg-rr76.6%
distribute-rgt1-in76.6%
+-commutative76.6%
Simplified76.6%
if 6.4e6 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 57.8%
div-sub57.8%
mul-1-neg57.8%
rec-exp57.8%
+-inverses57.8%
metadata-eval57.8%
Simplified57.8%
Final simplification71.4%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x 2.0) (+ 1.0 (* (* x -0.5) (+ eps_m 1.0))) 0.0))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 2.0) {
tmp = 1.0 + ((x * -0.5) * (eps_m + 1.0));
} else {
tmp = 0.0;
}
return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (x <= 2.0d0) then
tmp = 1.0d0 + ((x * (-0.5d0)) * (eps_m + 1.0d0))
else
tmp = 0.0d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (x <= 2.0) {
tmp = 1.0 + ((x * -0.5) * (eps_m + 1.0));
} else {
tmp = 0.0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if x <= 2.0: tmp = 1.0 + ((x * -0.5) * (eps_m + 1.0)) else: tmp = 0.0 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 2.0) tmp = Float64(1.0 + Float64(Float64(x * -0.5) * Float64(eps_m + 1.0))); else tmp = 0.0; end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (x <= 2.0) tmp = 1.0 + ((x * -0.5) * (eps_m + 1.0)); else tmp = 0.0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 2.0], N[(1.0 + N[(N[(x * -0.5), $MachinePrecision] * N[(eps$95$m + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2:\\
\;\;\;\;1 + \left(x \cdot -0.5\right) \cdot \left(eps\_m + 1\right)\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 2Initial program 57.1%
Simplified57.1%
Taylor expanded in x around 0 38.1%
Taylor expanded in eps around inf 77.9%
sub-neg77.9%
mul-1-neg77.9%
remove-double-neg77.9%
mul-1-neg77.9%
distribute-rgt-neg-in77.9%
distribute-neg-in77.9%
metadata-eval77.9%
unsub-neg77.9%
Simplified77.9%
Taylor expanded in x around 0 67.5%
associate-*r*67.5%
Simplified67.5%
if 2 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 55.5%
div-sub55.5%
mul-1-neg55.5%
rec-exp55.5%
+-inverses55.5%
metadata-eval55.5%
Simplified55.5%
Final simplification64.1%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 (if (<= x 6400000.0) 1.0 0.0))
eps_m = fabs(eps);
double code(double x, double eps_m) {
double tmp;
if (x <= 6400000.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
real(8) :: tmp
if (x <= 6400000.0d0) then
tmp = 1.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
double tmp;
if (x <= 6400000.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
eps_m = math.fabs(eps) def code(x, eps_m): tmp = 0 if x <= 6400000.0: tmp = 1.0 else: tmp = 0.0 return tmp
eps_m = abs(eps) function code(x, eps_m) tmp = 0.0 if (x <= 6400000.0) tmp = 1.0; else tmp = 0.0; end return tmp end
eps_m = abs(eps); function tmp_2 = code(x, eps_m) tmp = 0.0; if (x <= 6400000.0) tmp = 1.0; else tmp = 0.0; end tmp_2 = tmp; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := If[LessEqual[x, 6400000.0], 1.0, 0.0]
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6400000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 6.4e6Initial program 57.8%
Simplified51.1%
Taylor expanded in eps around inf 97.4%
Taylor expanded in x around -inf 97.4%
rec-exp97.4%
*-commutative97.4%
fma-neg97.4%
neg-mul-197.4%
remove-double-neg97.4%
neg-mul-197.4%
exp-prod97.4%
fma-define97.4%
+-commutative97.4%
*-rgt-identity97.4%
distribute-lft-in97.4%
exp-prod97.4%
mul-1-neg97.4%
distribute-rgt-neg-in97.4%
distribute-neg-in97.4%
metadata-eval97.4%
unsub-neg97.4%
Simplified97.4%
Taylor expanded in x around 0 64.1%
if 6.4e6 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 57.8%
div-sub57.8%
mul-1-neg57.8%
rec-exp57.8%
+-inverses57.8%
metadata-eval57.8%
Simplified57.8%
eps_m = (fabs.f64 eps) (FPCore (x eps_m) :precision binary64 0.0)
eps_m = fabs(eps);
double code(double x, double eps_m) {
return 0.0;
}
eps_m = abs(eps)
real(8) function code(x, eps_m)
real(8), intent (in) :: x
real(8), intent (in) :: eps_m
code = 0.0d0
end function
eps_m = Math.abs(eps);
public static double code(double x, double eps_m) {
return 0.0;
}
eps_m = math.fabs(eps) def code(x, eps_m): return 0.0
eps_m = abs(eps) function code(x, eps_m) return 0.0 end
eps_m = abs(eps); function tmp = code(x, eps_m) tmp = 0.0; end
eps_m = N[Abs[eps], $MachinePrecision] code[x_, eps$95$m_] := 0.0
\begin{array}{l}
eps_m = \left|\varepsilon\right|
\\
0
\end{array}
Initial program 69.3%
Simplified64.4%
Taylor expanded in eps around 0 17.4%
div-sub17.4%
mul-1-neg17.4%
rec-exp17.4%
+-inverses17.7%
metadata-eval17.7%
Simplified17.7%
herbie shell --seed 2024146
(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))