
(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))))))
(if (<= t_0 0.0)
(/ (+ (/ (+ 1.0 x) (exp x)) (* (+ 1.0 x) (exp (- x)))) 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 tmp;
if (t_0 <= 0.0) {
tmp = (((1.0 + x) / exp(x)) + ((1.0 + x) * exp(-x))) / 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) :: tmp
t_0 = ((1.0d0 + (1.0d0 / eps)) * exp((x * (eps + (-1.0d0))))) + (exp((x * ((-1.0d0) - eps))) * (1.0d0 - (1.0d0 / eps)))
if (t_0 <= 0.0d0) then
tmp = (((1.0d0 + x) / exp(x)) + ((1.0d0 + x) * exp(-x))) / 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 tmp;
if (t_0 <= 0.0) {
tmp = (((1.0 + x) / Math.exp(x)) + ((1.0 + x) * Math.exp(-x))) / 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))) tmp = 0 if t_0 <= 0.0: tmp = (((1.0 + x) / math.exp(x)) + ((1.0 + x) * math.exp(-x))) / 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)))) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(Float64(Float64(Float64(1.0 + x) / exp(x)) + Float64(Float64(1.0 + x) * exp(Float64(-x)))) / 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))); tmp = 0.0; if (t_0 <= 0.0) tmp = (((1.0 + x) / exp(x)) + ((1.0 + x) * exp(-x))) / 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]}, If[LessEqual[t$95$0, 0.0], N[(N[(N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] * N[Exp[(-x)], $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)\\
\mathbf{if}\;t_0 \leq 0:\\
\;\;\;\;\frac{\frac{1 + x}{e^{x}} + \left(1 + x\right) \cdot e^{-x}}{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 39.9%
div-sub39.9%
+-rgt-identity39.9%
div-sub39.9%
Simplified39.9%
Taylor expanded in eps around 0 100.0%
*-commutative100.0%
distribute-lft1-in100.0%
mul-1-neg100.0%
distribute-lft-out100.0%
mul-1-neg100.0%
*-commutative100.0%
distribute-lft1-in100.0%
mul-1-neg100.0%
Simplified100.0%
exp-neg100.0%
un-div-inv100.0%
Applied egg-rr100.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
(let* ((t_0 (exp (- x))) (t_1 (* (+ 1.0 x) t_0)))
(if (<= x -720.0)
(/ (+ 1.0 t_0) 2.0)
(if (<= x 1.3e-10)
(/ (+ 1.0 (exp (* eps (- x)))) 2.0)
(/ (+ t_1 t_1) 2.0)))))
double code(double x, double eps) {
double t_0 = exp(-x);
double t_1 = (1.0 + x) * t_0;
double tmp;
if (x <= -720.0) {
tmp = (1.0 + t_0) / 2.0;
} else if (x <= 1.3e-10) {
tmp = (1.0 + exp((eps * -x))) / 2.0;
} else {
tmp = (t_1 + t_1) / 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 = exp(-x)
t_1 = (1.0d0 + x) * t_0
if (x <= (-720.0d0)) then
tmp = (1.0d0 + t_0) / 2.0d0
else if (x <= 1.3d-10) then
tmp = (1.0d0 + exp((eps * -x))) / 2.0d0
else
tmp = (t_1 + t_1) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.exp(-x);
double t_1 = (1.0 + x) * t_0;
double tmp;
if (x <= -720.0) {
tmp = (1.0 + t_0) / 2.0;
} else if (x <= 1.3e-10) {
tmp = (1.0 + Math.exp((eps * -x))) / 2.0;
} else {
tmp = (t_1 + t_1) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = math.exp(-x) t_1 = (1.0 + x) * t_0 tmp = 0 if x <= -720.0: tmp = (1.0 + t_0) / 2.0 elif x <= 1.3e-10: tmp = (1.0 + math.exp((eps * -x))) / 2.0 else: tmp = (t_1 + t_1) / 2.0 return tmp
function code(x, eps) t_0 = exp(Float64(-x)) t_1 = Float64(Float64(1.0 + x) * t_0) tmp = 0.0 if (x <= -720.0) tmp = Float64(Float64(1.0 + t_0) / 2.0); elseif (x <= 1.3e-10) tmp = Float64(Float64(1.0 + exp(Float64(eps * Float64(-x)))) / 2.0); else tmp = Float64(Float64(t_1 + t_1) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = exp(-x); t_1 = (1.0 + x) * t_0; tmp = 0.0; if (x <= -720.0) tmp = (1.0 + t_0) / 2.0; elseif (x <= 1.3e-10) tmp = (1.0 + exp((eps * -x))) / 2.0; else tmp = (t_1 + t_1) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, Block[{t$95$1 = N[(N[(1.0 + x), $MachinePrecision] * t$95$0), $MachinePrecision]}, If[LessEqual[x, -720.0], N[(N[(1.0 + t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.3e-10], N[(N[(1.0 + N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(t$95$1 + t$95$1), $MachinePrecision] / 2.0), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
t_1 := \left(1 + x\right) \cdot t_0\\
\mathbf{if}\;x \leq -720:\\
\;\;\;\;\frac{1 + t_0}{2}\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-10}:\\
\;\;\;\;\frac{1 + e^{\varepsilon \cdot \left(-x\right)}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 + t_1}{2}\\
\end{array}
\end{array}
if x < -720Initial program 100.0%
div-sub100.0%
+-rgt-identity100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 42.3%
Taylor expanded in eps around inf 42.3%
cancel-sign-sub-inv42.3%
metadata-eval42.3%
*-lft-identity42.3%
exp-prod42.3%
+-commutative42.3%
*-lft-identity42.3%
metadata-eval42.3%
cancel-sign-sub-inv42.3%
exp-prod42.3%
*-commutative42.3%
*-commutative42.3%
sub-neg42.3%
mul-1-neg42.3%
remove-double-neg42.3%
associate-*l*42.3%
*-commutative42.3%
distribute-lft-in42.3%
metadata-eval42.3%
mul-1-neg42.3%
Simplified42.3%
Taylor expanded in eps around 0 100.0%
neg-mul-1100.0%
Simplified100.0%
if -720 < x < 1.29999999999999991e-10Initial program 57.3%
div-sub57.3%
+-rgt-identity57.3%
div-sub57.3%
Simplified57.3%
Taylor expanded in x around 0 47.7%
Taylor expanded in eps around inf 90.3%
cancel-sign-sub-inv90.3%
metadata-eval90.3%
*-lft-identity90.3%
exp-prod90.3%
+-commutative90.3%
*-lft-identity90.3%
metadata-eval90.3%
cancel-sign-sub-inv90.3%
exp-prod90.3%
*-commutative90.3%
*-commutative90.3%
sub-neg90.3%
mul-1-neg90.3%
remove-double-neg90.3%
associate-*l*90.3%
*-commutative90.3%
distribute-lft-in90.3%
metadata-eval90.3%
mul-1-neg90.3%
Simplified90.3%
Taylor expanded in eps around inf 90.3%
mul-1-neg90.3%
distribute-lft-neg-out90.3%
*-commutative90.3%
Simplified90.3%
if 1.29999999999999991e-10 < x Initial program 96.4%
div-sub96.4%
+-rgt-identity96.4%
div-sub96.4%
Simplified96.4%
Taylor expanded in eps around 0 52.1%
*-commutative52.1%
distribute-lft1-in52.1%
mul-1-neg52.1%
distribute-lft-out52.1%
mul-1-neg52.1%
*-commutative52.1%
distribute-lft1-in52.1%
mul-1-neg52.1%
Simplified52.1%
Final simplification79.9%
(FPCore (x eps)
:precision binary64
(let* ((t_0 (exp (- x))))
(if (<= x -720.0)
(/ (+ 1.0 t_0) 2.0)
(if (<= x 1.3e-10)
(/ (+ 1.0 (exp (* eps (- x)))) 2.0)
(/ (+ (/ (+ 1.0 x) (exp x)) (* (+ 1.0 x) t_0)) 2.0)))))
double code(double x, double eps) {
double t_0 = exp(-x);
double tmp;
if (x <= -720.0) {
tmp = (1.0 + t_0) / 2.0;
} else if (x <= 1.3e-10) {
tmp = (1.0 + exp((eps * -x))) / 2.0;
} else {
tmp = (((1.0 + x) / exp(x)) + ((1.0 + x) * 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) :: tmp
t_0 = exp(-x)
if (x <= (-720.0d0)) then
tmp = (1.0d0 + t_0) / 2.0d0
else if (x <= 1.3d-10) then
tmp = (1.0d0 + exp((eps * -x))) / 2.0d0
else
tmp = (((1.0d0 + x) / exp(x)) + ((1.0d0 + x) * t_0)) / 2.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double t_0 = Math.exp(-x);
double tmp;
if (x <= -720.0) {
tmp = (1.0 + t_0) / 2.0;
} else if (x <= 1.3e-10) {
tmp = (1.0 + Math.exp((eps * -x))) / 2.0;
} else {
tmp = (((1.0 + x) / Math.exp(x)) + ((1.0 + x) * t_0)) / 2.0;
}
return tmp;
}
def code(x, eps): t_0 = math.exp(-x) tmp = 0 if x <= -720.0: tmp = (1.0 + t_0) / 2.0 elif x <= 1.3e-10: tmp = (1.0 + math.exp((eps * -x))) / 2.0 else: tmp = (((1.0 + x) / math.exp(x)) + ((1.0 + x) * t_0)) / 2.0 return tmp
function code(x, eps) t_0 = exp(Float64(-x)) tmp = 0.0 if (x <= -720.0) tmp = Float64(Float64(1.0 + t_0) / 2.0); elseif (x <= 1.3e-10) tmp = Float64(Float64(1.0 + exp(Float64(eps * Float64(-x)))) / 2.0); else tmp = Float64(Float64(Float64(Float64(1.0 + x) / exp(x)) + Float64(Float64(1.0 + x) * t_0)) / 2.0); end return tmp end
function tmp_2 = code(x, eps) t_0 = exp(-x); tmp = 0.0; if (x <= -720.0) tmp = (1.0 + t_0) / 2.0; elseif (x <= 1.3e-10) tmp = (1.0 + exp((eps * -x))) / 2.0; else tmp = (((1.0 + x) / exp(x)) + ((1.0 + x) * t_0)) / 2.0; end tmp_2 = tmp; end
code[x_, eps_] := Block[{t$95$0 = N[Exp[(-x)], $MachinePrecision]}, If[LessEqual[x, -720.0], N[(N[(1.0 + t$95$0), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1.3e-10], N[(N[(1.0 + N[Exp[N[(eps * (-x)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], N[(N[(N[(N[(1.0 + x), $MachinePrecision] / N[Exp[x], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 + x), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-x}\\
\mathbf{if}\;x \leq -720:\\
\;\;\;\;\frac{1 + t_0}{2}\\
\mathbf{elif}\;x \leq 1.3 \cdot 10^{-10}:\\
\;\;\;\;\frac{1 + e^{\varepsilon \cdot \left(-x\right)}}{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1 + x}{e^{x}} + \left(1 + x\right) \cdot t_0}{2}\\
\end{array}
\end{array}
if x < -720Initial program 100.0%
div-sub100.0%
+-rgt-identity100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 42.3%
Taylor expanded in eps around inf 42.3%
cancel-sign-sub-inv42.3%
metadata-eval42.3%
*-lft-identity42.3%
exp-prod42.3%
+-commutative42.3%
*-lft-identity42.3%
metadata-eval42.3%
cancel-sign-sub-inv42.3%
exp-prod42.3%
*-commutative42.3%
*-commutative42.3%
sub-neg42.3%
mul-1-neg42.3%
remove-double-neg42.3%
associate-*l*42.3%
*-commutative42.3%
distribute-lft-in42.3%
metadata-eval42.3%
mul-1-neg42.3%
Simplified42.3%
Taylor expanded in eps around 0 100.0%
neg-mul-1100.0%
Simplified100.0%
if -720 < x < 1.29999999999999991e-10Initial program 57.3%
div-sub57.3%
+-rgt-identity57.3%
div-sub57.3%
Simplified57.3%
Taylor expanded in x around 0 47.7%
Taylor expanded in eps around inf 90.3%
cancel-sign-sub-inv90.3%
metadata-eval90.3%
*-lft-identity90.3%
exp-prod90.3%
+-commutative90.3%
*-lft-identity90.3%
metadata-eval90.3%
cancel-sign-sub-inv90.3%
exp-prod90.3%
*-commutative90.3%
*-commutative90.3%
sub-neg90.3%
mul-1-neg90.3%
remove-double-neg90.3%
associate-*l*90.3%
*-commutative90.3%
distribute-lft-in90.3%
metadata-eval90.3%
mul-1-neg90.3%
Simplified90.3%
Taylor expanded in eps around inf 90.3%
mul-1-neg90.3%
distribute-lft-neg-out90.3%
*-commutative90.3%
Simplified90.3%
if 1.29999999999999991e-10 < x Initial program 96.4%
div-sub96.4%
+-rgt-identity96.4%
div-sub96.4%
Simplified96.4%
Taylor expanded in eps around 0 52.1%
*-commutative52.1%
distribute-lft1-in52.1%
mul-1-neg52.1%
distribute-lft-out52.1%
mul-1-neg52.1%
*-commutative52.1%
distribute-lft1-in52.1%
mul-1-neg52.1%
Simplified52.1%
exp-neg52.0%
un-div-inv52.0%
Applied egg-rr52.0%
Final simplification79.9%
(FPCore (x eps) :precision binary64 (if (<= x -720.0) (/ (+ 1.0 (exp (- x))) 2.0) (if (<= x 1880.0) (/ (+ 1.0 (exp (* eps (- x)))) 2.0) 0.0)))
double code(double x, double eps) {
double tmp;
if (x <= -720.0) {
tmp = (1.0 + exp(-x)) / 2.0;
} else if (x <= 1880.0) {
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 <= (-720.0d0)) then
tmp = (1.0d0 + exp(-x)) / 2.0d0
else if (x <= 1880.0d0) 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 <= -720.0) {
tmp = (1.0 + Math.exp(-x)) / 2.0;
} else if (x <= 1880.0) {
tmp = (1.0 + Math.exp((eps * -x))) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= -720.0: tmp = (1.0 + math.exp(-x)) / 2.0 elif x <= 1880.0: tmp = (1.0 + math.exp((eps * -x))) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= -720.0) tmp = Float64(Float64(1.0 + exp(Float64(-x))) / 2.0); elseif (x <= 1880.0) tmp = Float64(Float64(1.0 + exp(Float64(eps * Float64(-x)))) / 2.0); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= -720.0) tmp = (1.0 + exp(-x)) / 2.0; elseif (x <= 1880.0) tmp = (1.0 + exp((eps * -x))) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, -720.0], N[(N[(1.0 + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], If[LessEqual[x, 1880.0], 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 -720:\\
\;\;\;\;\frac{1 + e^{-x}}{2}\\
\mathbf{elif}\;x \leq 1880:\\
\;\;\;\;\frac{1 + e^{\varepsilon \cdot \left(-x\right)}}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < -720Initial program 100.0%
div-sub100.0%
+-rgt-identity100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around 0 42.3%
Taylor expanded in eps around inf 42.3%
cancel-sign-sub-inv42.3%
metadata-eval42.3%
*-lft-identity42.3%
exp-prod42.3%
+-commutative42.3%
*-lft-identity42.3%
metadata-eval42.3%
cancel-sign-sub-inv42.3%
exp-prod42.3%
*-commutative42.3%
*-commutative42.3%
sub-neg42.3%
mul-1-neg42.3%
remove-double-neg42.3%
associate-*l*42.3%
*-commutative42.3%
distribute-lft-in42.3%
metadata-eval42.3%
mul-1-neg42.3%
Simplified42.3%
Taylor expanded in eps around 0 100.0%
neg-mul-1100.0%
Simplified100.0%
if -720 < x < 1880Initial program 56.8%
div-sub56.8%
+-rgt-identity56.8%
div-sub56.8%
Simplified56.8%
Taylor expanded in x around 0 46.0%
Taylor expanded in eps around inf 88.0%
cancel-sign-sub-inv88.0%
metadata-eval88.0%
*-lft-identity88.0%
exp-prod88.0%
+-commutative88.0%
*-lft-identity88.0%
metadata-eval88.0%
cancel-sign-sub-inv88.0%
exp-prod88.0%
*-commutative88.0%
*-commutative88.0%
sub-neg88.0%
mul-1-neg88.0%
remove-double-neg88.0%
associate-*l*88.0%
*-commutative88.0%
distribute-lft-in88.0%
metadata-eval88.0%
mul-1-neg88.0%
Simplified88.0%
Taylor expanded in eps around inf 88.6%
mul-1-neg88.6%
distribute-lft-neg-out88.6%
*-commutative88.6%
Simplified88.6%
if 1880 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 51.4%
div-sub51.4%
rec-exp51.4%
mul-1-neg51.4%
+-inverses51.4%
Simplified51.4%
Final simplification79.6%
(FPCore (x eps) :precision binary64 (if (<= x 500.0) (/ (+ 1.0 (exp (- x))) 2.0) 0.0))
double code(double x, double eps) {
double tmp;
if (x <= 500.0) {
tmp = (1.0 + exp(-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 <= 500.0d0) then
tmp = (1.0d0 + exp(-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 <= 500.0) {
tmp = (1.0 + Math.exp(-x)) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 500.0: tmp = (1.0 + math.exp(-x)) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 500.0) tmp = Float64(Float64(1.0 + exp(Float64(-x))) / 2.0); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 500.0) tmp = (1.0 + exp(-x)) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 500.0], N[(N[(1.0 + N[Exp[(-x)], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 500:\\
\;\;\;\;\frac{1 + e^{-x}}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 500Initial program 66.8%
div-sub66.8%
+-rgt-identity66.8%
div-sub66.8%
Simplified66.8%
Taylor expanded in x around 0 45.2%
Taylor expanded in eps around inf 77.4%
cancel-sign-sub-inv77.4%
metadata-eval77.4%
*-lft-identity77.4%
exp-prod77.4%
+-commutative77.4%
*-lft-identity77.4%
metadata-eval77.4%
cancel-sign-sub-inv77.4%
exp-prod77.4%
*-commutative77.4%
*-commutative77.4%
sub-neg77.4%
mul-1-neg77.4%
remove-double-neg77.4%
associate-*l*77.4%
*-commutative77.4%
distribute-lft-in77.4%
metadata-eval77.4%
mul-1-neg77.4%
Simplified77.4%
Taylor expanded in eps around 0 78.7%
neg-mul-178.7%
Simplified78.7%
if 500 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 51.4%
div-sub51.4%
rec-exp51.4%
mul-1-neg51.4%
+-inverses51.4%
Simplified51.4%
Final simplification70.7%
(FPCore (x eps) :precision binary64 (if (<= x 25.0) (/ (+ (* x (+ eps -1.0)) 2.0) 2.0) 0.0))
double code(double x, double eps) {
double tmp;
if (x <= 25.0) {
tmp = ((x * (eps + -1.0)) + 2.0) / 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 <= 25.0d0) then
tmp = ((x * (eps + (-1.0d0))) + 2.0d0) / 2.0d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x, double eps) {
double tmp;
if (x <= 25.0) {
tmp = ((x * (eps + -1.0)) + 2.0) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 25.0: tmp = ((x * (eps + -1.0)) + 2.0) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 25.0) tmp = Float64(Float64(Float64(x * Float64(eps + -1.0)) + 2.0) / 2.0); else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 25.0) tmp = ((x * (eps + -1.0)) + 2.0) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 25.0], N[(N[(N[(x * N[(eps + -1.0), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 25:\\
\;\;\;\;\frac{x \cdot \left(\varepsilon + -1\right) + 2}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 25Initial program 66.8%
div-sub66.8%
+-rgt-identity66.8%
div-sub66.8%
Simplified66.8%
Taylor expanded in x around 0 45.2%
Taylor expanded in eps around inf 77.4%
*-commutative77.4%
sub-neg77.4%
mul-1-neg77.4%
*-commutative77.4%
+-commutative77.4%
mul-1-neg77.4%
*-commutative77.4%
mul-1-neg77.4%
sub-neg77.4%
Simplified77.4%
Taylor expanded in x around 0 63.1%
if 25 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 51.4%
div-sub51.4%
rec-exp51.4%
mul-1-neg51.4%
+-inverses51.4%
Simplified51.4%
Final simplification59.7%
(FPCore (x eps) :precision binary64 (if (<= x 0.0055) (/ (- 2.0 (* eps x)) 2.0) 0.0))
double code(double x, double eps) {
double tmp;
if (x <= 0.0055) {
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 <= 0.0055d0) 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 <= 0.0055) {
tmp = (2.0 - (eps * x)) / 2.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 0.0055: tmp = (2.0 - (eps * x)) / 2.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 0.0055) 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 <= 0.0055) tmp = (2.0 - (eps * x)) / 2.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 0.0055], N[(N[(2.0 - N[(eps * x), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0055:\\
\;\;\;\;\frac{2 - \varepsilon \cdot x}{2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 0.0054999999999999997Initial program 66.6%
div-sub66.6%
+-rgt-identity66.6%
div-sub66.6%
Simplified66.6%
Taylor expanded in x around 0 45.4%
Taylor expanded in eps around inf 77.8%
cancel-sign-sub-inv77.8%
metadata-eval77.8%
*-lft-identity77.8%
exp-prod77.8%
+-commutative77.8%
*-lft-identity77.8%
metadata-eval77.8%
cancel-sign-sub-inv77.8%
exp-prod77.8%
*-commutative77.8%
*-commutative77.8%
sub-neg77.8%
mul-1-neg77.8%
remove-double-neg77.8%
associate-*l*77.8%
*-commutative77.8%
distribute-lft-in77.8%
metadata-eval77.8%
mul-1-neg77.8%
Simplified77.8%
Taylor expanded in eps around inf 78.3%
mul-1-neg78.3%
distribute-lft-neg-out78.3%
*-commutative78.3%
Simplified78.3%
Taylor expanded in x around 0 61.3%
+-commutative61.3%
associate-*r*61.3%
mul-1-neg61.3%
cancel-sign-sub-inv61.3%
Simplified61.3%
if 0.0054999999999999997 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 50.8%
div-sub50.8%
rec-exp50.8%
mul-1-neg50.8%
+-inverses50.8%
Simplified50.8%
Final simplification58.2%
(FPCore (x eps) :precision binary64 (if (<= x 495.0) 1.0 0.0))
double code(double x, double eps) {
double tmp;
if (x <= 495.0) {
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 <= 495.0d0) 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 <= 495.0) {
tmp = 1.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x, eps): tmp = 0 if x <= 495.0: tmp = 1.0 else: tmp = 0.0 return tmp
function code(x, eps) tmp = 0.0 if (x <= 495.0) tmp = 1.0; else tmp = 0.0; end return tmp end
function tmp_2 = code(x, eps) tmp = 0.0; if (x <= 495.0) tmp = 1.0; else tmp = 0.0; end tmp_2 = tmp; end
code[x_, eps_] := If[LessEqual[x, 495.0], 1.0, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 495:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 495Initial program 66.8%
div-sub66.8%
+-rgt-identity66.8%
div-sub66.8%
Simplified66.8%
Taylor expanded in x around 0 56.7%
if 495 < x Initial program 100.0%
Simplified100.0%
Taylor expanded in eps around 0 51.4%
div-sub51.4%
rec-exp51.4%
mul-1-neg51.4%
+-inverses51.4%
Simplified51.4%
Final simplification55.1%
(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 76.5%
Simplified72.2%
Taylor expanded in eps around 0 16.5%
div-sub16.5%
rec-exp16.5%
mul-1-neg16.5%
+-inverses16.8%
Simplified16.8%
Final simplification16.8%
herbie shell --seed 2023182
(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))