
(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}
(FPCore (x eps)
:precision binary64
(let* ((t_0
(+
(* (+ 1.0 (/ 1.0 eps)) (exp (* x (+ eps -1.0))))
(* (exp (* x (- -1.0 eps))) (+ 1.0 (/ -1.0 eps)))))
(t_1 (exp (- x))))
(if (<= t_0 0.0) (/ (* 2.0 (+ t_1 (* x t_1))) 2.0) (/ t_0 2.0))))
double code(double x, double eps) {
double t_0 = ((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)));
double t_1 = exp(-x);
double tmp;
if (t_0 <= 0.0) {
tmp = (2.0 * (t_1 + (x * t_1))) / 2.0;
} else {
tmp = t_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) :: t_1
real(8) :: tmp
t_0 = ((1.0d0 + (1.0d0 / eps)) * exp((x * (eps + (-1.0d0))))) + (exp((x * ((-1.0d0) - eps))) * (1.0d0 + ((-1.0d0) / eps)))
t_1 = exp(-x)
if (t_0 <= 0.0d0) then
tmp = (2.0d0 * (t_1 + (x * t_1))) / 2.0d0
else
tmp = t_0 / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = ((1.0 + (1.0 / eps)) * Math.exp((x * (eps + -1.0)))) + (Math.exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps)));
double t_1 = Math.exp(-x);
double tmp;
if (t_0 <= 0.0) {
tmp = (2.0 * (t_1 + (x * t_1))) / 2.0;
} else {
tmp = t_0 / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = ((1.0 + (1.0 / eps)) * math.exp((x * (eps + -1.0)))) + (math.exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps))) t_1 = math.exp(-x) tmp = 0 if t_0 <= 0.0: tmp = (2.0 * (t_1 + (x * t_1))) / 2.0 else: tmp = t_0 / 2.0 return tmp
function code(x, eps) t_0 = Float64(Float64(Float64(1.0 + Float64(1.0 / eps)) * exp(Float64(x * Float64(eps + -1.0)))) + Float64(exp(Float64(x * Float64(-1.0 - eps))) * Float64(1.0 + Float64(-1.0 / eps)))) t_1 = exp(Float64(-x)) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(2.0 * Float64(t_1 + Float64(x * t_1))) / 2.0); else tmp = Float64(t_0 / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = ((1.0 + (1.0 / eps)) * exp((x * (eps + -1.0)))) + (exp((x * (-1.0 - eps))) * (1.0 + (-1.0 / eps))); t_1 = exp(-x); tmp = 0.0; if (t_0 <= 0.0) tmp = (2.0 * (t_1 + (x * t_1))) / 2.0; else tmp = t_0 / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[(N[(N[(1.0 + N[(1.0 / eps), $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[N[(x * N[(-1.0 - eps), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[(1.0 + N[(-1.0 / eps), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(N[(2.0 * N[(t$95$1 + N[(x * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(t$95$0 / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 + \frac{1}{\varepsilon}\right) \cdot e^{x \cdot \left(\varepsilon + -1\right)} + e^{x \cdot \left(-1 - \varepsilon\right)} \cdot \left(1 + \frac{-1}{\varepsilon}\right)\\
t_1 := e^{-x}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;\frac{2 \cdot \left(t\_1 + x \cdot t\_1\right)}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{2}\\
\end{array}
\end{array}
if (-.f64 (*.f64 (+.f64 1 (/.f64 1 eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 1 eps) x)))) (*.f64 (-.f64 (/.f64 1 eps) 1) (exp.f64 (neg.f64 (*.f64 (+.f64 1 eps) x))))) < 0.0Initial program 32.5%
Simplified32.5%
Taylor expanded in eps around 0 100.0%
associate--r+100.0%
associate-*r*100.0%
mul-1-neg100.0%
cancel-sign-sub100.0%
distribute-rgt1-in100.0%
distribute-rgt-out--99.9%
mul-1-neg99.9%
mul-1-neg99.9%
Simplified99.9%
Taylor expanded in x around inf 100.0%
distribute-lft-out100.0%
Simplified100.0%
if 0.0 < (-.f64 (*.f64 (+.f64 1 (/.f64 1 eps)) (exp.f64 (neg.f64 (*.f64 (-.f64 1 eps) x)))) (*.f64 (-.f64 (/.f64 1 eps) 1) (exp.f64 (neg.f64 (*.f64 (+.f64 1 eps) x))))) Initial program 100.0%
Final simplification100.0%
(FPCore (x eps)
:precision binary64
(if (<= x -2e-244)
(/ (+ 1.0 (exp (* eps (- x)))) 2.0)
(if (<= x 6e+190)
(/ (+ 1.0 (exp (* eps x))) 2.0)
(/ (* 2.0 (/ (+ 1.0 x) (exp x))) 2.0))))
double code(double x, double eps) {
double tmp;
if (x <= -2e-244) {
tmp = (1.0 + exp((eps * -x))) / 2.0;
} else if (x <= 6e+190) {
tmp = (1.0 + exp((eps * x))) / 2.0;
} else {
tmp = (2.0 * ((1.0 + x) / 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 (x <= (-2d-244)) then
tmp = (1.0d0 + exp((eps * -x))) / 2.0d0
else if (x <= 6d+190) then
tmp = (1.0d0 + exp((eps * x))) / 2.0d0
else
tmp = (2.0d0 * ((1.0d0 + x) / exp(x))) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -2e-244) {
tmp = (1.0 + Math.exp((eps * -x))) / 2.0;
} else if (x <= 6e+190) {
tmp = (1.0 + Math.exp((eps * x))) / 2.0;
} else {
tmp = (2.0 * ((1.0 + x) / Math.exp(x))) / 2.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -2e-244: tmp = (1.0 + math.exp((eps * -x))) / 2.0 elif x <= 6e+190: tmp = (1.0 + math.exp((eps * x))) / 2.0 else: tmp = (2.0 * ((1.0 + x) / math.exp(x))) / 2.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= -2e-244) tmp = Float64(Float64(1.0 + exp(Float64(eps * Float64(-x)))) / 2.0); elseif (x <= 6e+190) tmp = Float64(Float64(1.0 + exp(Float64(eps * x))) / 2.0); else tmp = Float64(Float64(2.0 * Float64(Float64(1.0 + x) / exp(x))) / 2.0); end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -2e-244) tmp = (1.0 + exp((eps * -x))) / 2.0; elseif (x <= 6e+190) tmp = (1.0 + exp((eps * x))) / 2.0; else tmp = (2.0 * ((1.0 + x) / exp(x))) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -2e-244], N[(N[(1.0 + N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 6e+190], N[(N[(1.0 + N[Exp[N[(eps * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(2.0 * N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-244}:\\
\;\;\;\;\frac{1 + e^{\varepsilon \cdot \left(-x\right)}}{2}\\
\mathbf{elif}\;x \leq 6 \cdot 10^{+190}:\\
\;\;\;\;\frac{1 + e^{\varepsilon \cdot x}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \frac{1 + x}{e^{x}}}{2}\\
\end{array}
\end{array}
if x < -1.9999999999999999e-244Initial program 68.4%
Simplified68.4%
Taylor expanded in x around 0 43.9%
Taylor expanded in eps around inf 74.5%
neg-mul-174.5%
distribute-rgt-neg-in74.5%
Simplified74.5%
add-sqr-sqrt5.0%
sqrt-unprod42.8%
sqr-neg42.8%
sqrt-unprod37.8%
add-sqr-sqrt67.3%
sub-neg67.3%
distribute-lft-in67.3%
*-commutative67.3%
*-un-lft-identity67.3%
Applied egg-rr67.3%
*-rgt-identity67.3%
distribute-lft-in67.3%
sub-neg67.3%
Simplified67.3%
Taylor expanded in eps around inf 67.9%
associate-*r*67.9%
mul-1-neg67.9%
Simplified67.9%
if -1.9999999999999999e-244 < x < 5.99999999999999964e190Initial program 66.2%
Simplified66.2%
Taylor expanded in x around 0 43.0%
Taylor expanded in eps around inf 75.3%
neg-mul-175.3%
distribute-rgt-neg-in75.3%
Simplified75.3%
Taylor expanded in eps around inf 75.7%
*-commutative75.7%
Simplified75.7%
if 5.99999999999999964e190 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 63.1%
associate--r+63.1%
associate-*r*63.1%
mul-1-neg63.1%
cancel-sign-sub63.1%
distribute-rgt1-in63.1%
distribute-rgt-out--63.1%
mul-1-neg63.1%
mul-1-neg63.1%
Simplified63.1%
Taylor expanded in x around inf 63.1%
distribute-lft-out63.1%
neg-mul-163.1%
neg-mul-163.1%
distribute-rgt1-in63.1%
neg-mul-163.1%
exp-neg63.1%
associate-/l*63.1%
*-rgt-identity63.1%
+-commutative63.1%
Simplified63.1%
Final simplification71.3%
(FPCore (x eps) :precision binary64 (if (<= x -0.0215) (/ (+ 1.0 (exp (- x))) 2.0) (if (<= x 1.02e+189) (/ (+ 1.0 (exp (* eps x))) 2.0) 0.0)))
double code(double x, double eps) {
double tmp;
if (x <= -0.0215) {
tmp = (1.0 + exp(-x)) / 2.0;
} else if (x <= 1.02e+189) {
tmp = (1.0 + exp((eps * x))) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= (-0.0215d0)) then
tmp = (1.0d0 + exp(-x)) / 2.0d0
else if (x <= 1.02d+189) then
tmp = (1.0d0 + exp((eps * x))) / 2.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -0.0215) {
tmp = (1.0 + Math.exp(-x)) / 2.0;
} else if (x <= 1.02e+189) {
tmp = (1.0 + Math.exp((eps * x))) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -0.0215: tmp = (1.0 + math.exp(-x)) / 2.0 elif x <= 1.02e+189: tmp = (1.0 + math.exp((eps * x))) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= -0.0215) tmp = Float64(Float64(1.0 + exp(Float64(-x))) / 2.0); elseif (x <= 1.02e+189) tmp = Float64(Float64(1.0 + exp(Float64(eps * x))) / 2.0); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -0.0215) tmp = (1.0 + exp(-x)) / 2.0; elseif (x <= 1.02e+189) tmp = (1.0 + exp((eps * x))) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -0.0215], N[(N[(1.0 + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.02e+189], N[(N[(1.0 + N[Exp[N[(eps * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0215:\\
\;\;\;\;\frac{1 + e^{-x}}{2}\\
\mathbf{elif}\;x \leq 1.02 \cdot 10^{+189}:\\
\;\;\;\;\frac{1 + e^{\varepsilon \cdot x}}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -0.021499999999999998Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 53.0%
Taylor expanded in eps around inf 53.0%
neg-mul-153.0%
distribute-rgt-neg-in53.0%
Simplified53.0%
Taylor expanded in eps around 0 94.2%
neg-mul-194.2%
Simplified94.2%
if -0.021499999999999998 < x < 1.02e189Initial program 61.5%
Simplified61.5%
Taylor expanded in x around 0 41.7%
Taylor expanded in eps around inf 78.8%
neg-mul-178.8%
distribute-rgt-neg-in78.8%
Simplified78.8%
Taylor expanded in eps around inf 79.3%
*-commutative79.3%
Simplified79.3%
if 1.02e189 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 63.1%
mul-1-neg63.1%
mul-1-neg63.1%
rec-exp63.1%
sub-neg63.1%
div-sub63.1%
rec-exp63.1%
mul-1-neg63.1%
+-inverses63.1%
Simplified63.1%
Final simplification79.2%
(FPCore (x eps) :precision binary64 (if (<= x -1.3e-245) (/ (+ 1.0 (exp (* eps (- x)))) 2.0) (if (<= x 3.1e+190) (/ (+ 1.0 (exp (* eps x))) 2.0) 0.0)))
double code(double x, double eps) {
double tmp;
if (x <= -1.3e-245) {
tmp = (1.0 + exp((eps * -x))) / 2.0;
} else if (x <= 3.1e+190) {
tmp = (1.0 + exp((eps * x))) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= (-1.3d-245)) then
tmp = (1.0d0 + exp((eps * -x))) / 2.0d0
else if (x <= 3.1d+190) then
tmp = (1.0d0 + exp((eps * x))) / 2.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= -1.3e-245) {
tmp = (1.0 + Math.exp((eps * -x))) / 2.0;
} else if (x <= 3.1e+190) {
tmp = (1.0 + Math.exp((eps * x))) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -1.3e-245: tmp = (1.0 + math.exp((eps * -x))) / 2.0 elif x <= 3.1e+190: tmp = (1.0 + math.exp((eps * x))) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= -1.3e-245) tmp = Float64(Float64(1.0 + exp(Float64(eps * Float64(-x)))) / 2.0); elseif (x <= 3.1e+190) tmp = Float64(Float64(1.0 + exp(Float64(eps * x))) / 2.0); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -1.3e-245) tmp = (1.0 + exp((eps * -x))) / 2.0; elseif (x <= 3.1e+190) tmp = (1.0 + exp((eps * x))) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -1.3e-245], N[(N[(1.0 + N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 3.1e+190], N[(N[(1.0 + N[Exp[N[(eps * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-245}:\\
\;\;\;\;\frac{1 + e^{\varepsilon \cdot \left(-x\right)}}{2}\\
\mathbf{elif}\;x \leq 3.1 \cdot 10^{+190}:\\
\;\;\;\;\frac{1 + e^{\varepsilon \cdot x}}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -1.30000000000000003e-245Initial program 68.4%
Simplified68.4%
Taylor expanded in x around 0 43.9%
Taylor expanded in eps around inf 74.5%
neg-mul-174.5%
distribute-rgt-neg-in74.5%
Simplified74.5%
add-sqr-sqrt5.0%
sqrt-unprod42.8%
sqr-neg42.8%
sqrt-unprod37.8%
add-sqr-sqrt67.3%
sub-neg67.3%
distribute-lft-in67.3%
*-commutative67.3%
*-un-lft-identity67.3%
Applied egg-rr67.3%
*-rgt-identity67.3%
distribute-lft-in67.3%
sub-neg67.3%
Simplified67.3%
Taylor expanded in eps around inf 67.9%
associate-*r*67.9%
mul-1-neg67.9%
Simplified67.9%
if -1.30000000000000003e-245 < x < 3.1000000000000001e190Initial program 66.2%
Simplified66.2%
Taylor expanded in x around 0 43.0%
Taylor expanded in eps around inf 75.3%
neg-mul-175.3%
distribute-rgt-neg-in75.3%
Simplified75.3%
Taylor expanded in eps around inf 75.7%
*-commutative75.7%
Simplified75.7%
if 3.1000000000000001e190 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 63.1%
mul-1-neg63.1%
mul-1-neg63.1%
rec-exp63.1%
sub-neg63.1%
div-sub63.1%
rec-exp63.1%
mul-1-neg63.1%
+-inverses63.1%
Simplified63.1%
Final simplification71.3%
(FPCore (x eps) :precision binary64 (if (<= x 150.0) (/ (- 2.0 (* eps x)) 2.0) (if (<= x 7e+134) (/ (/ (expm1 x) eps) 2.0) 0.0)))
double code(double x, double eps) {
double tmp;
if (x <= 150.0) {
tmp = (2.0 - (eps * x)) / 2.0;
} else if (x <= 7e+134) {
tmp = (expm1(x) / eps) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if (x <= 150.0) {
tmp = (2.0 - (eps * x)) / 2.0;
} else if (x <= 7e+134) {
tmp = (Math.expm1(x) / eps) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 150.0: tmp = (2.0 - (eps * x)) / 2.0 elif x <= 7e+134: tmp = (math.expm1(x) / eps) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 150.0) tmp = Float64(Float64(2.0 - Float64(eps * x)) / 2.0); elseif (x <= 7e+134) tmp = Float64(Float64(expm1(x) / eps) / 2.0); else tmp = 0.0; end return tmp end
code[x_, eps_] := If[LessEqual[x, 150.0], N[(N[(2.0 - N[(eps * x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 7e+134], N[(N[(N[(Exp[x] - 1), $MachinePrecision] / eps), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 150:\\
\;\;\;\;\frac{2 - \varepsilon \cdot x}{2}\\
\mathbf{elif}\;x \leq 7 \cdot 10^{+134}:\\
\;\;\;\;\frac{\frac{\mathsf{expm1}\left(x\right)}{\varepsilon}}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 150Initial program 60.8%
Simplified50.7%
Taylor expanded in x around 0 62.9%
Taylor expanded in eps around 0 67.2%
Taylor expanded in x around 0 67.2%
mul-1-neg67.2%
*-commutative67.2%
unsub-neg67.2%
Simplified67.2%
if 150 < x < 7.00000000000000006e134Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 40.1%
Taylor expanded in eps around 0 1.8%
expm1-define1.8%
neg-mul-11.8%
Simplified1.8%
expm1-undefine1.8%
div-sub1.8%
add-sqr-sqrt0.0%
sqrt-unprod38.9%
sqr-neg38.9%
sqrt-unprod38.9%
add-sqr-sqrt38.9%
Applied egg-rr38.9%
div-sub38.9%
expm1-undefine38.9%
Simplified38.9%
if 7.00000000000000006e134 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 60.2%
mul-1-neg60.2%
mul-1-neg60.2%
rec-exp60.2%
sub-neg60.2%
div-sub60.2%
rec-exp60.2%
mul-1-neg60.2%
+-inverses60.2%
Simplified60.2%
Final simplification63.2%
(FPCore (x eps) :precision binary64 (if (<= x 470.0) (/ (+ 1.0 (exp (- x))) 2.0) (if (<= x 2e+135) (/ (/ (expm1 x) eps) 2.0) 0.0)))
double code(double x, double eps) {
double tmp;
if (x <= 470.0) {
tmp = (1.0 + exp(-x)) / 2.0;
} else if (x <= 2e+135) {
tmp = (expm1(x) / eps) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
public static double code(double x, double eps) {
double tmp;
if (x <= 470.0) {
tmp = (1.0 + Math.exp(-x)) / 2.0;
} else if (x <= 2e+135) {
tmp = (Math.expm1(x) / eps) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 470.0: tmp = (1.0 + math.exp(-x)) / 2.0 elif x <= 2e+135: tmp = (math.expm1(x) / eps) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 470.0) tmp = Float64(Float64(1.0 + exp(Float64(-x))) / 2.0); elseif (x <= 2e+135) tmp = Float64(Float64(expm1(x) / eps) / 2.0); else tmp = 0.0; end return tmp end
code[x_, eps_] := If[LessEqual[x, 470.0], N[(N[(1.0 + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 2e+135], N[(N[(N[(Exp[x] - 1), $MachinePrecision] / eps), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 470:\\
\;\;\;\;\frac{1 + e^{-x}}{2}\\
\mathbf{elif}\;x \leq 2 \cdot 10^{+135}:\\
\;\;\;\;\frac{\frac{\mathsf{expm1}\left(x\right)}{\varepsilon}}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 470Initial program 60.8%
Simplified60.8%
Taylor expanded in x around 0 44.5%
Taylor expanded in eps around inf 82.0%
neg-mul-182.0%
distribute-rgt-neg-in82.0%
Simplified82.0%
Taylor expanded in eps around 0 78.3%
neg-mul-178.3%
Simplified78.3%
if 470 < x < 1.99999999999999992e135Initial program 100.0%
Simplified100.0%
Taylor expanded in x around 0 40.1%
Taylor expanded in eps around 0 1.8%
expm1-define1.8%
neg-mul-11.8%
Simplified1.8%
expm1-undefine1.8%
div-sub1.8%
add-sqr-sqrt0.0%
sqrt-unprod38.9%
sqr-neg38.9%
sqrt-unprod38.9%
add-sqr-sqrt38.9%
Applied egg-rr38.9%
div-sub38.9%
expm1-undefine38.9%
Simplified38.9%
if 1.99999999999999992e135 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 60.2%
mul-1-neg60.2%
mul-1-neg60.2%
rec-exp60.2%
sub-neg60.2%
div-sub60.2%
rec-exp60.2%
mul-1-neg60.2%
+-inverses60.2%
Simplified60.2%
Final simplification71.3%
(FPCore (x eps) :precision binary64 (if (<= x 260.0) (/ (- 2.0 (* eps x)) 2.0) 0.0))
double code(double x, double eps) {
double tmp;
if (x <= 260.0) {
tmp = (2.0 - (eps * x)) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 260.0d0) then
tmp = (2.0d0 - (eps * x)) / 2.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 260.0) {
tmp = (2.0 - (eps * x)) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 260.0: tmp = (2.0 - (eps * x)) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 260.0) tmp = Float64(Float64(2.0 - Float64(eps * x)) / 2.0); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 260.0) tmp = (2.0 - (eps * x)) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 260.0], N[(N[(2.0 - N[(eps * x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 260:\\
\;\;\;\;\frac{2 - \varepsilon \cdot x}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 260Initial program 60.8%
Simplified50.7%
Taylor expanded in x around 0 62.9%
Taylor expanded in eps around 0 67.2%
Taylor expanded in x around 0 67.2%
mul-1-neg67.2%
*-commutative67.2%
unsub-neg67.2%
Simplified67.2%
if 260 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 49.3%
mul-1-neg49.3%
mul-1-neg49.3%
rec-exp49.3%
sub-neg49.3%
div-sub49.3%
rec-exp49.3%
mul-1-neg49.3%
+-inverses49.3%
Simplified49.3%
Final simplification62.5%
(FPCore (x eps) :precision binary64 (if (<= x 3.7e+35) 1.0 0.0))
double code(double x, double eps) {
double tmp;
if (x <= 3.7e+35) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
real(8) :: tmp
if (x <= 3.7d+35) then
tmp = 1.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 3.7e+35) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 3.7e+35: tmp = 1.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 3.7e+35) tmp = 1.0; else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 3.7e+35) tmp = 1.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 3.7e+35], 1.0, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.7 \cdot 10^{+35}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 3.7e35Initial program 61.9%
Simplified61.9%
Taylor expanded in x around 0 61.4%
if 3.7e35 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 53.1%
mul-1-neg53.1%
mul-1-neg53.1%
rec-exp53.1%
sub-neg53.1%
div-sub53.1%
rec-exp53.1%
mul-1-neg53.1%
+-inverses53.1%
Simplified53.1%
Final simplification59.3%
(FPCore (x eps) :precision binary64 0.0)
double code(double x, double eps) {
return 0.0;
}
real(8) function code(x, eps)
real(8), intent (in) :: x
real(8), intent (in) :: eps
code = 0.0d0
end function
public static double code(double x, double eps) {
return 0.0;
}
def code(x, eps): return 0.0
function code(x, eps) return 0.0 end
function tmp = code(x, eps) tmp = 0.0; end
code[x_, eps_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 71.2%
Simplified59.3%
Taylor expanded in eps around 0 14.8%
mul-1-neg14.8%
mul-1-neg14.8%
rec-exp14.8%
sub-neg14.8%
div-sub14.8%
rec-exp14.8%
mul-1-neg14.8%
+-inverses15.0%
Simplified15.0%
Final simplification15.0%
herbie shell --seed 2024039
(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))