
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = exp(a) / (exp(a) + exp(b))
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (/ (exp b) (exp a)))))
double code(double a, double b) {
return 1.0 / (1.0 + (exp(b) / exp(a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + (exp(b) / exp(a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + (Math.exp(b) / Math.exp(a)));
}
def code(a, b): return 1.0 / (1.0 + (math.exp(b) / math.exp(a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + Float64(exp(b) / exp(a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + (exp(b) / exp(a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[(N[Exp[b], $MachinePrecision] / N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + \frac{e^{b}}{e^{a}}}
\end{array}
Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div99.9%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in72.2%
exp-neg72.2%
rgt-mult-inverse100.0%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
exp-diff100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -70.0) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -70.0) {
tmp = 1.0 / (1.0 + exp(-a));
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-70.0d0)) then
tmp = 1.0d0 / (1.0d0 + exp(-a))
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -70.0) {
tmp = 1.0 / (1.0 + Math.exp(-a));
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -70.0: tmp = 1.0 / (1.0 + math.exp(-a)) else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -70.0) tmp = Float64(1.0 / Float64(1.0 + exp(Float64(-a)))); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -70.0) tmp = 1.0 / (1.0 + exp(-a)); else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -70.0], N[(1.0 / N[(1.0 + N[Exp[(-a)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -70:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -70Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in2.7%
exp-neg2.7%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
+-commutative100.0%
Simplified100.0%
if -70 < a Initial program 99.9%
*-lft-identity99.9%
associate-/l*100.0%
remove-double-div99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
*-commutative99.9%
distribute-rgt-in99.9%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 99.0%
+-commutative99.0%
Simplified99.0%
Final simplification99.3%
(FPCore (a b) :precision binary64 (if (<= a -70.0) (/ (- (exp a)) a) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -70.0) {
tmp = -exp(a) / a;
} else {
tmp = 1.0 / (1.0 + exp(b));
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-70.0d0)) then
tmp = -exp(a) / a
else
tmp = 1.0d0 / (1.0d0 + exp(b))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -70.0) {
tmp = -Math.exp(a) / a;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -70.0: tmp = -math.exp(a) / a else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -70.0) tmp = Float64(Float64(-exp(a)) / a); else tmp = Float64(1.0 / Float64(1.0 + exp(b))); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -70.0) tmp = -exp(a) / a; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -70.0], N[((-N[Exp[a], $MachinePrecision]) / a), $MachinePrecision], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -70:\\
\;\;\;\;\frac{-e^{a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -70Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 97.3%
+-commutative97.3%
Simplified97.3%
Taylor expanded in a around inf 97.3%
frac-2neg97.3%
div-inv97.3%
add-sqr-sqrt97.3%
sqrt-unprod97.3%
sqr-neg97.3%
sqrt-unprod0.0%
add-sqr-sqrt97.7%
Applied egg-rr97.7%
associate-*r/97.7%
*-rgt-identity97.7%
Simplified97.7%
if -70 < a Initial program 99.9%
*-lft-identity99.9%
associate-/l*100.0%
remove-double-div99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
*-commutative99.9%
distribute-rgt-in99.9%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 99.0%
+-commutative99.0%
Simplified99.0%
Final simplification98.6%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div99.9%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in72.2%
exp-neg72.2%
rgt-mult-inverse100.0%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (a b) :precision binary64 (if (<= a -66.0) (/ (- (exp a)) a) (if (<= a -5.3e-20) 1.0 (+ 0.5 (* a 0.25)))))
double code(double a, double b) {
double tmp;
if (a <= -66.0) {
tmp = -exp(a) / a;
} else if (a <= -5.3e-20) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-66.0d0)) then
tmp = -exp(a) / a
else if (a <= (-5.3d-20)) then
tmp = 1.0d0
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -66.0) {
tmp = -Math.exp(a) / a;
} else if (a <= -5.3e-20) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -66.0: tmp = -math.exp(a) / a elif a <= -5.3e-20: tmp = 1.0 else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -66.0) tmp = Float64(Float64(-exp(a)) / a); elseif (a <= -5.3e-20) tmp = 1.0; else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -66.0) tmp = -exp(a) / a; elseif (a <= -5.3e-20) tmp = 1.0; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -66.0], N[((-N[Exp[a], $MachinePrecision]) / a), $MachinePrecision], If[LessEqual[a, -5.3e-20], 1.0, N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -66:\\
\;\;\;\;\frac{-e^{a}}{a}\\
\mathbf{elif}\;a \leq -5.3 \cdot 10^{-20}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -66Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 97.3%
+-commutative97.3%
Simplified97.3%
Taylor expanded in a around inf 97.3%
frac-2neg97.3%
div-inv97.3%
add-sqr-sqrt97.3%
sqrt-unprod97.3%
sqr-neg97.3%
sqrt-unprod0.0%
add-sqr-sqrt97.7%
Applied egg-rr97.7%
associate-*r/97.7%
*-rgt-identity97.7%
Simplified97.7%
if -66 < a < -5.3000000000000002e-20Initial program 99.8%
*-lft-identity99.8%
associate-/l*99.8%
remove-double-div99.3%
exp-neg99.5%
associate-/r/99.5%
/-rgt-identity99.5%
*-commutative99.5%
distribute-rgt-in99.5%
exp-neg99.8%
rgt-mult-inverse99.8%
prod-exp99.8%
unsub-neg99.8%
Simplified99.8%
exp-diff99.8%
clear-num99.8%
Applied egg-rr99.8%
Applied egg-rr68.6%
*-inverses69.3%
Simplified69.3%
if -5.3000000000000002e-20 < a Initial program 99.9%
Taylor expanded in b around 0 56.5%
Taylor expanded in a around 0 56.5%
*-commutative56.5%
Simplified56.5%
Final simplification68.7%
(FPCore (a b) :precision binary64 (if (<= a -750.0) (/ (exp a) a) (if (<= a -3.1e-20) 1.0 (+ 0.5 (* a 0.25)))))
double code(double a, double b) {
double tmp;
if (a <= -750.0) {
tmp = exp(a) / a;
} else if (a <= -3.1e-20) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (a <= (-750.0d0)) then
tmp = exp(a) / a
else if (a <= (-3.1d-20)) then
tmp = 1.0d0
else
tmp = 0.5d0 + (a * 0.25d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (a <= -750.0) {
tmp = Math.exp(a) / a;
} else if (a <= -3.1e-20) {
tmp = 1.0;
} else {
tmp = 0.5 + (a * 0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -750.0: tmp = math.exp(a) / a elif a <= -3.1e-20: tmp = 1.0 else: tmp = 0.5 + (a * 0.25) return tmp
function code(a, b) tmp = 0.0 if (a <= -750.0) tmp = Float64(exp(a) / a); elseif (a <= -3.1e-20) tmp = 1.0; else tmp = Float64(0.5 + Float64(a * 0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -750.0) tmp = exp(a) / a; elseif (a <= -3.1e-20) tmp = 1.0; else tmp = 0.5 + (a * 0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -750.0], N[(N[Exp[a], $MachinePrecision] / a), $MachinePrecision], If[LessEqual[a, -3.1e-20], 1.0, N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -750:\\
\;\;\;\;\frac{e^{a}}{a}\\
\mathbf{elif}\;a \leq -3.1 \cdot 10^{-20}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\end{array}
\end{array}
if a < -750Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in a around inf 100.0%
if -750 < a < -3.1e-20Initial program 99.9%
*-lft-identity99.9%
associate-/l*99.7%
remove-double-div99.3%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in99.4%
exp-neg99.7%
rgt-mult-inverse99.7%
prod-exp99.7%
unsub-neg99.7%
Simplified99.7%
exp-diff99.7%
clear-num99.7%
Applied egg-rr99.7%
Applied egg-rr57.3%
*-inverses57.8%
Simplified57.8%
if -3.1e-20 < a Initial program 99.9%
Taylor expanded in b around 0 56.5%
Taylor expanded in a around 0 56.5%
*-commutative56.5%
Simplified56.5%
Final simplification68.7%
(FPCore (a b) :precision binary64 (if (<= b -2.0) 1.0 (+ 0.5 (* b -0.25))))
double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 1.0;
} else {
tmp = 0.5 + (b * -0.25);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-2.0d0)) then
tmp = 1.0d0
else
tmp = 0.5d0 + (b * (-0.25d0))
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -2.0) {
tmp = 1.0;
} else {
tmp = 0.5 + (b * -0.25);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -2.0: tmp = 1.0 else: tmp = 0.5 + (b * -0.25) return tmp
function code(a, b) tmp = 0.0 if (b <= -2.0) tmp = 1.0; else tmp = Float64(0.5 + Float64(b * -0.25)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -2.0) tmp = 1.0; else tmp = 0.5 + (b * -0.25); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -2.0], 1.0, N[(0.5 + N[(b * -0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5 + b \cdot -0.25\\
\end{array}
\end{array}
if b < -2Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
*-commutative99.9%
distribute-rgt-in99.9%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
exp-diff100.0%
clear-num100.0%
Applied egg-rr100.0%
Applied egg-rr100.0%
*-inverses100.0%
Simplified100.0%
if -2 < b Initial program 99.9%
*-lft-identity99.9%
associate-/l*99.9%
remove-double-div99.9%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in65.2%
exp-neg65.2%
rgt-mult-inverse100.0%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 76.3%
+-commutative76.3%
Simplified76.3%
Taylor expanded in b around 0 46.0%
*-commutative46.0%
Simplified46.0%
Final simplification56.9%
(FPCore (a b) :precision binary64 (if (<= b -1.0) 1.0 (/ 1.0 (+ b 2.0))))
double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-1.0d0)) then
tmp = 1.0d0
else
tmp = 1.0d0 / (b + 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.0) {
tmp = 1.0;
} else {
tmp = 1.0 / (b + 2.0);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.0: tmp = 1.0 else: tmp = 1.0 / (b + 2.0) return tmp
function code(a, b) tmp = 0.0 if (b <= -1.0) tmp = 1.0; else tmp = Float64(1.0 / Float64(b + 2.0)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.0) tmp = 1.0; else tmp = 1.0 / (b + 2.0); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.0], 1.0, N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{b + 2}\\
\end{array}
\end{array}
if b < -1Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
*-commutative99.9%
distribute-rgt-in99.9%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
exp-diff100.0%
clear-num100.0%
Applied egg-rr100.0%
Applied egg-rr100.0%
*-inverses100.0%
Simplified100.0%
if -1 < b Initial program 99.9%
*-lft-identity99.9%
associate-/l*99.9%
remove-double-div99.9%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in65.2%
exp-neg65.2%
rgt-mult-inverse100.0%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 76.3%
+-commutative76.3%
Simplified76.3%
Taylor expanded in b around 0 46.6%
+-commutative46.6%
Simplified46.6%
Final simplification57.4%
(FPCore (a b) :precision binary64 (if (<= b -1.1) 1.0 0.5))
double code(double a, double b) {
double tmp;
if (b <= -1.1) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-1.1d0)) then
tmp = 1.0d0
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.1) {
tmp = 1.0;
} else {
tmp = 0.5;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.1: tmp = 1.0 else: tmp = 0.5 return tmp
function code(a, b) tmp = 0.0 if (b <= -1.1) tmp = 1.0; else tmp = 0.5; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.1) tmp = 1.0; else tmp = 0.5; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.1], 1.0, 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if b < -1.1000000000000001Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
*-commutative99.9%
distribute-rgt-in99.9%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
exp-diff100.0%
clear-num100.0%
Applied egg-rr100.0%
Applied egg-rr100.0%
*-inverses100.0%
Simplified100.0%
if -1.1000000000000001 < b Initial program 99.9%
*-lft-identity99.9%
associate-/l*99.9%
remove-double-div99.9%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in65.2%
exp-neg65.2%
rgt-mult-inverse100.0%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 76.3%
+-commutative76.3%
Simplified76.3%
Taylor expanded in b around 0 45.0%
Final simplification56.2%
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
return 0.5;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.5d0
end function
public static double code(double a, double b) {
return 0.5;
}
def code(a, b): return 0.5
function code(a, b) return 0.5 end
function tmp = code(a, b) tmp = 0.5; end
code[a_, b_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 100.0%
*-lft-identity100.0%
associate-/l*100.0%
remove-double-div99.9%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
*-commutative100.0%
distribute-rgt-in72.2%
exp-neg72.2%
rgt-mult-inverse100.0%
prod-exp99.9%
unsub-neg99.9%
Simplified99.9%
Taylor expanded in a around 0 81.1%
+-commutative81.1%
Simplified81.1%
Taylor expanded in b around 0 39.7%
Final simplification39.7%
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b): return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b) return Float64(1.0 / Float64(1.0 + exp(Float64(b - a)))) end
function tmp = code(a, b) tmp = 1.0 / (1.0 + exp((b - a))); end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{1 + e^{b - a}}
\end{array}
herbie shell --seed 2023306
(FPCore (a b)
:name "Quotient of sum of exps"
:precision binary64
:herbie-target
(/ 1.0 (+ 1.0 (exp (- b a))))
(/ (exp a) (+ (exp a) (exp b))))