
(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 8 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 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 99.6%
*-lft-identity99.6%
associate-/l*99.6%
remove-double-div99.6%
exp-neg99.6%
associate-/r/99.6%
/-rgt-identity99.6%
*-commutative99.6%
distribute-rgt-in72.6%
exp-neg72.7%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= a -6.4e-6) (/ 1.0 (+ 1.0 (exp (- a)))) (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -6.4e-6) {
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 <= (-6.4d-6)) 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 <= -6.4e-6) {
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 <= -6.4e-6: 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 <= -6.4e-6) 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 <= -6.4e-6) 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, -6.4e-6], 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 -6.4 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{1 + e^{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -6.3999999999999997e-6Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.6%
/-rgt-identity98.6%
*-commutative98.6%
distribute-rgt-in1.4%
exp-neg1.4%
rgt-mult-inverse98.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
if -6.3999999999999997e-6 < a Initial 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-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 99.7%
Final simplification99.8%
(FPCore (a b) :precision binary64 (if (<= a -720.0) 0.0 (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (a <= -720.0) {
tmp = 0.0;
} 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 <= (-720.0d0)) then
tmp = 0.0d0
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 <= -720.0) {
tmp = 0.0;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if a <= -720.0: tmp = 0.0 else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (a <= -720.0) tmp = 0.0; 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 <= -720.0) tmp = 0.0; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[a, -720.0], 0.0, N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -720:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if a < -720Initial program 98.6%
*-lft-identity98.6%
associate-/l*98.6%
remove-double-div98.6%
exp-neg98.6%
associate-/r/98.6%
/-rgt-identity98.6%
*-commutative98.6%
distribute-rgt-in0.0%
exp-neg0.0%
rgt-mult-inverse98.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 5.6%
neg-mul-15.6%
unsub-neg5.6%
Simplified5.6%
expm1-log1p-u5.6%
expm1-udef95.9%
log1p-udef95.9%
rem-exp-log95.9%
Applied egg-rr95.9%
Taylor expanded in a around inf 100.0%
if -720 < a Initial 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-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 99.4%
Final simplification99.5%
(FPCore (a b) :precision binary64 (if (<= b -7800000.0) 0.5 (if (<= b -1.7e-43) 0.0 (if (<= b 1.2e-67) (+ 0.5 (* a 0.25)) 0.0))))
double code(double a, double b) {
double tmp;
if (b <= -7800000.0) {
tmp = 0.5;
} else if (b <= -1.7e-43) {
tmp = 0.0;
} else if (b <= 1.2e-67) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-7800000.0d0)) then
tmp = 0.5d0
else if (b <= (-1.7d-43)) then
tmp = 0.0d0
else if (b <= 1.2d-67) then
tmp = 0.5d0 + (a * 0.25d0)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -7800000.0) {
tmp = 0.5;
} else if (b <= -1.7e-43) {
tmp = 0.0;
} else if (b <= 1.2e-67) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -7800000.0: tmp = 0.5 elif b <= -1.7e-43: tmp = 0.0 elif b <= 1.2e-67: tmp = 0.5 + (a * 0.25) else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -7800000.0) tmp = 0.5; elseif (b <= -1.7e-43) tmp = 0.0; elseif (b <= 1.2e-67) tmp = Float64(0.5 + Float64(a * 0.25)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -7800000.0) tmp = 0.5; elseif (b <= -1.7e-43) tmp = 0.0; elseif (b <= 1.2e-67) tmp = 0.5 + (a * 0.25); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -7800000.0], 0.5, If[LessEqual[b, -1.7e-43], 0.0, If[LessEqual[b, 1.2e-67], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], 0.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7800000:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq -1.7 \cdot 10^{-43}:\\
\;\;\;\;0\\
\mathbf{elif}\;b \leq 1.2 \cdot 10^{-67}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -7.8e6Initial 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-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 18.8%
if -7.8e6 < b < -1.7e-43 or 1.2e-67 < b Initial program 99.0%
*-lft-identity99.0%
associate-/l*99.0%
remove-double-div99.0%
exp-neg99.0%
associate-/r/99.0%
/-rgt-identity99.0%
*-commutative99.0%
distribute-rgt-in55.7%
exp-neg55.7%
rgt-mult-inverse99.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 53.1%
Taylor expanded in a around 0 11.3%
neg-mul-111.3%
unsub-neg11.3%
Simplified11.3%
expm1-log1p-u11.3%
expm1-udef53.1%
log1p-udef53.1%
rem-exp-log53.1%
Applied egg-rr53.1%
Taylor expanded in a around inf 91.0%
if -1.7e-43 < b < 1.2e-67Initial 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-in75.7%
exp-neg75.7%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 76.5%
neg-mul-176.5%
unsub-neg76.5%
Simplified76.5%
Taylor expanded in a around 0 76.2%
Final simplification71.1%
(FPCore (a b) :precision binary64 (if (<= b -13800000.0) 0.5 (if (<= b -1.15e-42) 0.0 (if (<= b 1.6e-66) (/ 1.0 (- 2.0 a)) 0.0))))
double code(double a, double b) {
double tmp;
if (b <= -13800000.0) {
tmp = 0.5;
} else if (b <= -1.15e-42) {
tmp = 0.0;
} else if (b <= 1.6e-66) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-13800000.0d0)) then
tmp = 0.5d0
else if (b <= (-1.15d-42)) then
tmp = 0.0d0
else if (b <= 1.6d-66) then
tmp = 1.0d0 / (2.0d0 - a)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -13800000.0) {
tmp = 0.5;
} else if (b <= -1.15e-42) {
tmp = 0.0;
} else if (b <= 1.6e-66) {
tmp = 1.0 / (2.0 - a);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -13800000.0: tmp = 0.5 elif b <= -1.15e-42: tmp = 0.0 elif b <= 1.6e-66: tmp = 1.0 / (2.0 - a) else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -13800000.0) tmp = 0.5; elseif (b <= -1.15e-42) tmp = 0.0; elseif (b <= 1.6e-66) tmp = Float64(1.0 / Float64(2.0 - a)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -13800000.0) tmp = 0.5; elseif (b <= -1.15e-42) tmp = 0.0; elseif (b <= 1.6e-66) tmp = 1.0 / (2.0 - a); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -13800000.0], 0.5, If[LessEqual[b, -1.15e-42], 0.0, If[LessEqual[b, 1.6e-66], N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision], 0.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -13800000:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq -1.15 \cdot 10^{-42}:\\
\;\;\;\;0\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{-66}:\\
\;\;\;\;\frac{1}{2 - a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -1.38e7Initial 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-in100.0%
exp-neg100.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 100.0%
Taylor expanded in b around 0 18.8%
if -1.38e7 < b < -1.15000000000000002e-42 or 1.59999999999999991e-66 < b Initial program 99.0%
*-lft-identity99.0%
associate-/l*99.0%
remove-double-div99.0%
exp-neg99.0%
associate-/r/99.0%
/-rgt-identity99.0%
*-commutative99.0%
distribute-rgt-in55.7%
exp-neg55.7%
rgt-mult-inverse99.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 53.1%
Taylor expanded in a around 0 11.3%
neg-mul-111.3%
unsub-neg11.3%
Simplified11.3%
expm1-log1p-u11.3%
expm1-udef53.1%
log1p-udef53.1%
rem-exp-log53.1%
Applied egg-rr53.1%
Taylor expanded in a around inf 91.0%
if -1.15000000000000002e-42 < b < 1.59999999999999991e-66Initial 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-in75.7%
exp-neg75.7%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 76.5%
neg-mul-176.5%
unsub-neg76.5%
Simplified76.5%
Final simplification71.2%
(FPCore (a b) :precision binary64 (if (<= b 245.0) (+ (+ 1.0 (/ 1.0 (- 2.0 a))) -1.0) 0.0))
double code(double a, double b) {
double tmp;
if (b <= 245.0) {
tmp = (1.0 + (1.0 / (2.0 - a))) + -1.0;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 245.0d0) then
tmp = (1.0d0 + (1.0d0 / (2.0d0 - a))) + (-1.0d0)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 245.0) {
tmp = (1.0 + (1.0 / (2.0 - a))) + -1.0;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 245.0: tmp = (1.0 + (1.0 / (2.0 - a))) + -1.0 else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= 245.0) tmp = Float64(Float64(1.0 + Float64(1.0 / Float64(2.0 - a))) + -1.0); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 245.0) tmp = (1.0 + (1.0 / (2.0 - a))) + -1.0; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 245.0], N[(N[(1.0 + N[(1.0 / N[(2.0 - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 245:\\
\;\;\;\;\left(1 + \frac{1}{2 - a}\right) + -1\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < 245Initial program 99.4%
*-lft-identity99.4%
associate-/l*99.4%
remove-double-div99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
*-commutative99.4%
distribute-rgt-in76.6%
exp-neg76.6%
rgt-mult-inverse99.4%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 77.8%
Taylor expanded in a around 0 55.4%
neg-mul-155.4%
unsub-neg55.4%
Simplified55.4%
expm1-log1p-u55.4%
expm1-udef75.9%
log1p-udef75.9%
rem-exp-log75.9%
Applied egg-rr75.9%
if 245 < b Initial 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-in62.5%
exp-neg62.5%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 39.5%
Taylor expanded in a around 0 4.2%
neg-mul-14.2%
unsub-neg4.2%
Simplified4.2%
expm1-log1p-u4.2%
expm1-udef39.5%
log1p-udef39.5%
rem-exp-log39.5%
Applied egg-rr39.5%
Taylor expanded in a around inf 100.0%
Final simplification82.7%
(FPCore (a b) :precision binary64 (if (<= b -5500000.0) 0.5 (if (<= b -1.15e-42) 0.0 (if (<= b 1.5e-66) 0.5 0.0))))
double code(double a, double b) {
double tmp;
if (b <= -5500000.0) {
tmp = 0.5;
} else if (b <= -1.15e-42) {
tmp = 0.0;
} else if (b <= 1.5e-66) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= (-5500000.0d0)) then
tmp = 0.5d0
else if (b <= (-1.15d-42)) then
tmp = 0.0d0
else if (b <= 1.5d-66) then
tmp = 0.5d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -5500000.0) {
tmp = 0.5;
} else if (b <= -1.15e-42) {
tmp = 0.0;
} else if (b <= 1.5e-66) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -5500000.0: tmp = 0.5 elif b <= -1.15e-42: tmp = 0.0 elif b <= 1.5e-66: tmp = 0.5 else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -5500000.0) tmp = 0.5; elseif (b <= -1.15e-42) tmp = 0.0; elseif (b <= 1.5e-66) tmp = 0.5; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -5500000.0) tmp = 0.5; elseif (b <= -1.15e-42) tmp = 0.0; elseif (b <= 1.5e-66) tmp = 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -5500000.0], 0.5, If[LessEqual[b, -1.15e-42], 0.0, If[LessEqual[b, 1.5e-66], 0.5, 0.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5500000:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq -1.15 \cdot 10^{-42}:\\
\;\;\;\;0\\
\mathbf{elif}\;b \leq 1.5 \cdot 10^{-66}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -5.5e6 or -1.15000000000000002e-42 < b < 1.5000000000000001e-66Initial 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-in83.0%
exp-neg83.0%
rgt-mult-inverse100.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 82.8%
Taylor expanded in b around 0 58.3%
if -5.5e6 < b < -1.15000000000000002e-42 or 1.5000000000000001e-66 < b Initial program 99.0%
*-lft-identity99.0%
associate-/l*99.0%
remove-double-div99.0%
exp-neg99.0%
associate-/r/99.0%
/-rgt-identity99.0%
*-commutative99.0%
distribute-rgt-in55.7%
exp-neg55.7%
rgt-mult-inverse99.0%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in b around 0 53.1%
Taylor expanded in a around 0 11.3%
neg-mul-111.3%
unsub-neg11.3%
Simplified11.3%
expm1-log1p-u11.3%
expm1-udef53.1%
log1p-udef53.1%
rem-exp-log53.1%
Applied egg-rr53.1%
Taylor expanded in a around inf 91.0%
Final simplification70.7%
(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 99.6%
*-lft-identity99.6%
associate-/l*99.6%
remove-double-div99.6%
exp-neg99.6%
associate-/r/99.6%
/-rgt-identity99.6%
*-commutative99.6%
distribute-rgt-in72.6%
exp-neg72.7%
rgt-mult-inverse99.6%
prod-exp100.0%
unsub-neg100.0%
Simplified100.0%
Taylor expanded in a around 0 83.3%
Taylor expanded in b around 0 40.1%
Final simplification40.1%
(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 2023299
(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))))