
(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 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 98.8%
add-exp-log98.8%
div-exp98.8%
Applied egg-rr98.8%
Taylor expanded in a around -inf 98.8%
exp-neg98.8%
neg-mul-198.8%
prod-exp98.8%
rem-exp-log98.8%
*-commutative98.8%
distribute-rgt-in74.2%
rec-exp74.2%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) 0.0 (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.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 (exp(a) <= 0.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 (Math.exp(a) <= 0.0) {
tmp = 0.0;
} else {
tmp = 1.0 / (1.0 + Math.exp(b));
}
return tmp;
}
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = 0.0 else: tmp = 1.0 / (1.0 + math.exp(b)) return tmp
function code(a, b) tmp = 0.0 if (exp(a) <= 0.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 (exp(a) <= 0.0) tmp = 0.0; else tmp = 1.0 / (1.0 + exp(b)); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], 0.0, N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{1 + e^{b}}\\
\end{array}
\end{array}
if (exp.f64 a) < 0.0Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around -inf 100.0%
exp-neg100.0%
neg-mul-1100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
distribute-rgt-in0.0%
rec-exp0.0%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
Applied egg-rr100.0%
if 0.0 < (exp.f64 a) Initial program 98.4%
Taylor expanded in a around 0 98.2%
Final simplification98.6%
(FPCore (a b)
:precision binary64
(if (<= b -1.9)
1.0
(if (<= b -5.4e-188)
(+ 0.5 (* b -0.25))
(if (<= b -1.25e-208)
(exp a)
(if (<= b 1.08e-157)
(+ 0.5 (* a 0.25))
(if (<= b 5e-146) (exp a) (if (<= b 38.0) (/ 1.0 (+ b 2.0)) 0.0)))))))
double code(double a, double b) {
double tmp;
if (b <= -1.9) {
tmp = 1.0;
} else if (b <= -5.4e-188) {
tmp = 0.5 + (b * -0.25);
} else if (b <= -1.25e-208) {
tmp = exp(a);
} else if (b <= 1.08e-157) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 5e-146) {
tmp = exp(a);
} else if (b <= 38.0) {
tmp = 1.0 / (b + 2.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 <= (-1.9d0)) then
tmp = 1.0d0
else if (b <= (-5.4d-188)) then
tmp = 0.5d0 + (b * (-0.25d0))
else if (b <= (-1.25d-208)) then
tmp = exp(a)
else if (b <= 1.08d-157) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 5d-146) then
tmp = exp(a)
else if (b <= 38.0d0) then
tmp = 1.0d0 / (b + 2.0d0)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -1.9) {
tmp = 1.0;
} else if (b <= -5.4e-188) {
tmp = 0.5 + (b * -0.25);
} else if (b <= -1.25e-208) {
tmp = Math.exp(a);
} else if (b <= 1.08e-157) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 5e-146) {
tmp = Math.exp(a);
} else if (b <= 38.0) {
tmp = 1.0 / (b + 2.0);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -1.9: tmp = 1.0 elif b <= -5.4e-188: tmp = 0.5 + (b * -0.25) elif b <= -1.25e-208: tmp = math.exp(a) elif b <= 1.08e-157: tmp = 0.5 + (a * 0.25) elif b <= 5e-146: tmp = math.exp(a) elif b <= 38.0: tmp = 1.0 / (b + 2.0) else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -1.9) tmp = 1.0; elseif (b <= -5.4e-188) tmp = Float64(0.5 + Float64(b * -0.25)); elseif (b <= -1.25e-208) tmp = exp(a); elseif (b <= 1.08e-157) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 5e-146) tmp = exp(a); elseif (b <= 38.0) tmp = Float64(1.0 / Float64(b + 2.0)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -1.9) tmp = 1.0; elseif (b <= -5.4e-188) tmp = 0.5 + (b * -0.25); elseif (b <= -1.25e-208) tmp = exp(a); elseif (b <= 1.08e-157) tmp = 0.5 + (a * 0.25); elseif (b <= 5e-146) tmp = exp(a); elseif (b <= 38.0) tmp = 1.0 / (b + 2.0); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -1.9], 1.0, If[LessEqual[b, -5.4e-188], N[(0.5 + N[(b * -0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, -1.25e-208], N[Exp[a], $MachinePrecision], If[LessEqual[b, 1.08e-157], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5e-146], N[Exp[a], $MachinePrecision], If[LessEqual[b, 38.0], N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision], 0.0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.9:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq -5.4 \cdot 10^{-188}:\\
\;\;\;\;0.5 + b \cdot -0.25\\
\mathbf{elif}\;b \leq -1.25 \cdot 10^{-208}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{-157}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-146}:\\
\;\;\;\;e^{a}\\
\mathbf{elif}\;b \leq 38:\\
\;\;\;\;\frac{1}{b + 2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -1.8999999999999999Initial program 98.1%
add-exp-log98.1%
div-exp98.1%
Applied egg-rr98.1%
Taylor expanded in a around -inf 98.1%
exp-neg98.1%
neg-mul-198.1%
prod-exp98.0%
rem-exp-log98.0%
*-commutative98.0%
distribute-rgt-in98.0%
rec-exp98.0%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 20.3%
Applied egg-rr100.0%
if -1.8999999999999999 < b < -5.4000000000000002e-188Initial program 93.5%
Taylor expanded in a around 0 72.9%
Taylor expanded in b around 0 72.9%
*-commutative72.9%
Simplified72.9%
if -5.4000000000000002e-188 < b < -1.24999999999999991e-208 or 1.0799999999999999e-157 < b < 4.99999999999999957e-146Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around inf 87.5%
if -1.24999999999999991e-208 < b < 1.0799999999999999e-157Initial program 100.0%
Taylor expanded in b around 0 100.0%
Taylor expanded in a around 0 69.4%
*-commutative69.4%
Simplified69.4%
if 4.99999999999999957e-146 < b < 38Initial program 99.8%
Taylor expanded in a around 0 86.2%
Taylor expanded in b around 0 83.7%
+-commutative83.7%
Simplified83.7%
if 38 < b Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around -inf 100.0%
exp-neg100.0%
neg-mul-1100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
distribute-rgt-in64.8%
rec-exp64.8%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 37.2%
Applied egg-rr100.0%
Final simplification87.5%
(FPCore (a b)
:precision binary64
(if (<= b -8.2e-13)
1.0
(if (or (<= b 9.8e-158) (and (not (<= b 5e-146)) (<= b 38.0)))
(+ 0.5 (* a 0.25))
0.0)))
double code(double a, double b) {
double tmp;
if (b <= -8.2e-13) {
tmp = 1.0;
} else if ((b <= 9.8e-158) || (!(b <= 5e-146) && (b <= 38.0))) {
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 <= (-8.2d-13)) then
tmp = 1.0d0
else if ((b <= 9.8d-158) .or. (.not. (b <= 5d-146)) .and. (b <= 38.0d0)) 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 <= -8.2e-13) {
tmp = 1.0;
} else if ((b <= 9.8e-158) || (!(b <= 5e-146) && (b <= 38.0))) {
tmp = 0.5 + (a * 0.25);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -8.2e-13: tmp = 1.0 elif (b <= 9.8e-158) or (not (b <= 5e-146) and (b <= 38.0)): tmp = 0.5 + (a * 0.25) else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -8.2e-13) tmp = 1.0; elseif ((b <= 9.8e-158) || (!(b <= 5e-146) && (b <= 38.0))) 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 <= -8.2e-13) tmp = 1.0; elseif ((b <= 9.8e-158) || (~((b <= 5e-146)) && (b <= 38.0))) tmp = 0.5 + (a * 0.25); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -8.2e-13], 1.0, If[Or[LessEqual[b, 9.8e-158], And[N[Not[LessEqual[b, 5e-146]], $MachinePrecision], LessEqual[b, 38.0]]], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], 0.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-13}:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 9.8 \cdot 10^{-158} \lor \neg \left(b \leq 5 \cdot 10^{-146}\right) \land b \leq 38:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -8.2000000000000004e-13Initial program 96.4%
add-exp-log96.4%
div-exp96.4%
Applied egg-rr96.4%
Taylor expanded in a around -inf 96.4%
exp-neg96.5%
neg-mul-196.5%
prod-exp96.3%
rem-exp-log96.3%
*-commutative96.3%
distribute-rgt-in94.5%
rec-exp94.5%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 24.2%
Applied egg-rr96.8%
if -8.2000000000000004e-13 < b < 9.79999999999999986e-158 or 4.99999999999999957e-146 < b < 38Initial program 99.1%
Taylor expanded in b around 0 97.7%
Taylor expanded in a around 0 72.4%
*-commutative72.4%
Simplified72.4%
if 9.79999999999999986e-158 < b < 4.99999999999999957e-146 or 38 < b Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around -inf 100.0%
exp-neg100.0%
neg-mul-1100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
distribute-rgt-in60.3%
rec-exp60.3%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 42.9%
Applied egg-rr98.8%
Final simplification85.7%
(FPCore (a b)
:precision binary64
(if (<= b -8.2e-13)
1.0
(if (<= b 1.08e-157)
(+ 0.5 (* a 0.25))
(if (<= b 6.8e-149) 0.0 (if (<= b 0.047) (+ 0.5 (* b -0.25)) 0.0)))))
double code(double a, double b) {
double tmp;
if (b <= -8.2e-13) {
tmp = 1.0;
} else if (b <= 1.08e-157) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 6.8e-149) {
tmp = 0.0;
} else if (b <= 0.047) {
tmp = 0.5 + (b * -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 <= (-8.2d-13)) then
tmp = 1.0d0
else if (b <= 1.08d-157) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 6.8d-149) then
tmp = 0.0d0
else if (b <= 0.047d0) then
tmp = 0.5d0 + (b * (-0.25d0))
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -8.2e-13) {
tmp = 1.0;
} else if (b <= 1.08e-157) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 6.8e-149) {
tmp = 0.0;
} else if (b <= 0.047) {
tmp = 0.5 + (b * -0.25);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -8.2e-13: tmp = 1.0 elif b <= 1.08e-157: tmp = 0.5 + (a * 0.25) elif b <= 6.8e-149: tmp = 0.0 elif b <= 0.047: tmp = 0.5 + (b * -0.25) else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -8.2e-13) tmp = 1.0; elseif (b <= 1.08e-157) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 6.8e-149) tmp = 0.0; elseif (b <= 0.047) tmp = Float64(0.5 + Float64(b * -0.25)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -8.2e-13) tmp = 1.0; elseif (b <= 1.08e-157) tmp = 0.5 + (a * 0.25); elseif (b <= 6.8e-149) tmp = 0.0; elseif (b <= 0.047) tmp = 0.5 + (b * -0.25); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -8.2e-13], 1.0, If[LessEqual[b, 1.08e-157], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6.8e-149], 0.0, If[LessEqual[b, 0.047], N[(0.5 + N[(b * -0.25), $MachinePrecision]), $MachinePrecision], 0.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-13}:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{-157}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 6.8 \cdot 10^{-149}:\\
\;\;\;\;0\\
\mathbf{elif}\;b \leq 0.047:\\
\;\;\;\;0.5 + b \cdot -0.25\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -8.2000000000000004e-13Initial program 96.4%
add-exp-log96.4%
div-exp96.4%
Applied egg-rr96.4%
Taylor expanded in a around -inf 96.4%
exp-neg96.5%
neg-mul-196.5%
prod-exp96.3%
rem-exp-log96.3%
*-commutative96.3%
distribute-rgt-in94.5%
rec-exp94.5%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 24.2%
Applied egg-rr96.8%
if -8.2000000000000004e-13 < b < 1.0799999999999999e-157Initial program 98.8%
Taylor expanded in b around 0 98.8%
Taylor expanded in a around 0 67.9%
*-commutative67.9%
Simplified67.9%
if 1.0799999999999999e-157 < b < 6.7999999999999998e-149 or 0.047 < b Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around -inf 100.0%
exp-neg100.0%
neg-mul-1100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
distribute-rgt-in61.0%
rec-exp61.0%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 41.0%
Applied egg-rr98.7%
if 6.7999999999999998e-149 < b < 0.047Initial program 99.8%
Taylor expanded in a around 0 84.0%
Taylor expanded in b around 0 84.1%
*-commutative84.1%
Simplified84.1%
Final simplification85.8%
(FPCore (a b)
:precision binary64
(if (<= b -8.2e-13)
1.0
(if (<= b 8.8e-158)
(+ 0.5 (* a 0.25))
(if (<= b 7.5e-149) 0.0 (if (<= b 38.0) (/ 1.0 (+ b 2.0)) 0.0)))))
double code(double a, double b) {
double tmp;
if (b <= -8.2e-13) {
tmp = 1.0;
} else if (b <= 8.8e-158) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 7.5e-149) {
tmp = 0.0;
} else if (b <= 38.0) {
tmp = 1.0 / (b + 2.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 <= (-8.2d-13)) then
tmp = 1.0d0
else if (b <= 8.8d-158) then
tmp = 0.5d0 + (a * 0.25d0)
else if (b <= 7.5d-149) then
tmp = 0.0d0
else if (b <= 38.0d0) then
tmp = 1.0d0 / (b + 2.0d0)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -8.2e-13) {
tmp = 1.0;
} else if (b <= 8.8e-158) {
tmp = 0.5 + (a * 0.25);
} else if (b <= 7.5e-149) {
tmp = 0.0;
} else if (b <= 38.0) {
tmp = 1.0 / (b + 2.0);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -8.2e-13: tmp = 1.0 elif b <= 8.8e-158: tmp = 0.5 + (a * 0.25) elif b <= 7.5e-149: tmp = 0.0 elif b <= 38.0: tmp = 1.0 / (b + 2.0) else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -8.2e-13) tmp = 1.0; elseif (b <= 8.8e-158) tmp = Float64(0.5 + Float64(a * 0.25)); elseif (b <= 7.5e-149) tmp = 0.0; elseif (b <= 38.0) tmp = Float64(1.0 / Float64(b + 2.0)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -8.2e-13) tmp = 1.0; elseif (b <= 8.8e-158) tmp = 0.5 + (a * 0.25); elseif (b <= 7.5e-149) tmp = 0.0; elseif (b <= 38.0) tmp = 1.0 / (b + 2.0); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -8.2e-13], 1.0, If[LessEqual[b, 8.8e-158], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.5e-149], 0.0, If[LessEqual[b, 38.0], N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision], 0.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-13}:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 8.8 \cdot 10^{-158}:\\
\;\;\;\;0.5 + a \cdot 0.25\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{-149}:\\
\;\;\;\;0\\
\mathbf{elif}\;b \leq 38:\\
\;\;\;\;\frac{1}{b + 2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -8.2000000000000004e-13Initial program 96.4%
add-exp-log96.4%
div-exp96.4%
Applied egg-rr96.4%
Taylor expanded in a around -inf 96.4%
exp-neg96.5%
neg-mul-196.5%
prod-exp96.3%
rem-exp-log96.3%
*-commutative96.3%
distribute-rgt-in94.5%
rec-exp94.5%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 24.2%
Applied egg-rr96.8%
if -8.2000000000000004e-13 < b < 8.8000000000000004e-158Initial program 98.8%
Taylor expanded in b around 0 98.8%
Taylor expanded in a around 0 67.9%
*-commutative67.9%
Simplified67.9%
if 8.8000000000000004e-158 < b < 7.49999999999999995e-149 or 38 < b Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around -inf 100.0%
exp-neg100.0%
neg-mul-1100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
distribute-rgt-in60.5%
rec-exp60.5%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 41.4%
Applied egg-rr100.0%
if 7.49999999999999995e-149 < b < 38Initial program 99.8%
Taylor expanded in a around 0 84.4%
Taylor expanded in b around 0 82.1%
+-commutative82.1%
Simplified82.1%
Final simplification85.8%
(FPCore (a b)
:precision binary64
(if (<= b -8.2e-13)
1.0
(if (<= b 1.08e-157)
0.5
(if (<= b 6.8e-149) 0.0 (if (<= b 38.0) 0.5 0.0)))))
double code(double a, double b) {
double tmp;
if (b <= -8.2e-13) {
tmp = 1.0;
} else if (b <= 1.08e-157) {
tmp = 0.5;
} else if (b <= 6.8e-149) {
tmp = 0.0;
} else if (b <= 38.0) {
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 <= (-8.2d-13)) then
tmp = 1.0d0
else if (b <= 1.08d-157) then
tmp = 0.5d0
else if (b <= 6.8d-149) then
tmp = 0.0d0
else if (b <= 38.0d0) 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 <= -8.2e-13) {
tmp = 1.0;
} else if (b <= 1.08e-157) {
tmp = 0.5;
} else if (b <= 6.8e-149) {
tmp = 0.0;
} else if (b <= 38.0) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -8.2e-13: tmp = 1.0 elif b <= 1.08e-157: tmp = 0.5 elif b <= 6.8e-149: tmp = 0.0 elif b <= 38.0: tmp = 0.5 else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -8.2e-13) tmp = 1.0; elseif (b <= 1.08e-157) tmp = 0.5; elseif (b <= 6.8e-149) tmp = 0.0; elseif (b <= 38.0) tmp = 0.5; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -8.2e-13) tmp = 1.0; elseif (b <= 1.08e-157) tmp = 0.5; elseif (b <= 6.8e-149) tmp = 0.0; elseif (b <= 38.0) tmp = 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -8.2e-13], 1.0, If[LessEqual[b, 1.08e-157], 0.5, If[LessEqual[b, 6.8e-149], 0.0, If[LessEqual[b, 38.0], 0.5, 0.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.2 \cdot 10^{-13}:\\
\;\;\;\;1\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{-157}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq 6.8 \cdot 10^{-149}:\\
\;\;\;\;0\\
\mathbf{elif}\;b \leq 38:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -8.2000000000000004e-13Initial program 96.4%
add-exp-log96.4%
div-exp96.4%
Applied egg-rr96.4%
Taylor expanded in a around -inf 96.4%
exp-neg96.5%
neg-mul-196.5%
prod-exp96.3%
rem-exp-log96.3%
*-commutative96.3%
distribute-rgt-in94.5%
rec-exp94.5%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 24.2%
Applied egg-rr96.8%
if -8.2000000000000004e-13 < b < 1.0799999999999999e-157 or 6.7999999999999998e-149 < b < 38Initial program 99.1%
Taylor expanded in a around 0 73.0%
Taylor expanded in b around 0 71.6%
if 1.0799999999999999e-157 < b < 6.7999999999999998e-149 or 38 < b Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around -inf 100.0%
exp-neg100.0%
neg-mul-1100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
distribute-rgt-in60.5%
rec-exp60.5%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 41.4%
Applied egg-rr100.0%
Final simplification85.5%
(FPCore (a b) :precision binary64 (if (<= b 1.08e-157) 0.5 (if (<= b 6.8e-149) 0.0 (if (<= b 38.0) 0.5 0.0))))
double code(double a, double b) {
double tmp;
if (b <= 1.08e-157) {
tmp = 0.5;
} else if (b <= 6.8e-149) {
tmp = 0.0;
} else if (b <= 38.0) {
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 <= 1.08d-157) then
tmp = 0.5d0
else if (b <= 6.8d-149) then
tmp = 0.0d0
else if (b <= 38.0d0) 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 <= 1.08e-157) {
tmp = 0.5;
} else if (b <= 6.8e-149) {
tmp = 0.0;
} else if (b <= 38.0) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.08e-157: tmp = 0.5 elif b <= 6.8e-149: tmp = 0.0 elif b <= 38.0: tmp = 0.5 else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= 1.08e-157) tmp = 0.5; elseif (b <= 6.8e-149) tmp = 0.0; elseif (b <= 38.0) tmp = 0.5; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.08e-157) tmp = 0.5; elseif (b <= 6.8e-149) tmp = 0.0; elseif (b <= 38.0) tmp = 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.08e-157], 0.5, If[LessEqual[b, 6.8e-149], 0.0, If[LessEqual[b, 38.0], 0.5, 0.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.08 \cdot 10^{-157}:\\
\;\;\;\;0.5\\
\mathbf{elif}\;b \leq 6.8 \cdot 10^{-149}:\\
\;\;\;\;0\\
\mathbf{elif}\;b \leq 38:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < 1.0799999999999999e-157 or 6.7999999999999998e-149 < b < 38Initial program 98.3%
Taylor expanded in a around 0 80.3%
Taylor expanded in b around 0 55.7%
if 1.0799999999999999e-157 < b < 6.7999999999999998e-149 or 38 < b Initial program 100.0%
add-exp-log100.0%
div-exp100.0%
Applied egg-rr100.0%
Taylor expanded in a around -inf 100.0%
exp-neg100.0%
neg-mul-1100.0%
prod-exp100.0%
rem-exp-log100.0%
*-commutative100.0%
distribute-rgt-in60.5%
rec-exp60.5%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 41.4%
Applied egg-rr100.0%
Final simplification68.8%
(FPCore (a b) :precision binary64 (if (<= b -900000.0) 0.1111111111111111 0.0))
double code(double a, double b) {
double tmp;
if (b <= -900000.0) {
tmp = 0.1111111111111111;
} 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 <= (-900000.0d0)) then
tmp = 0.1111111111111111d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= -900000.0) {
tmp = 0.1111111111111111;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= -900000.0: tmp = 0.1111111111111111 else: tmp = 0.0 return tmp
function code(a, b) tmp = 0.0 if (b <= -900000.0) tmp = 0.1111111111111111; else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= -900000.0) tmp = 0.1111111111111111; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, -900000.0], 0.1111111111111111, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -900000:\\
\;\;\;\;0.1111111111111111\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -9e5Initial program 98.1%
add-exp-log98.1%
div-exp98.1%
Applied egg-rr98.1%
Taylor expanded in a around -inf 98.1%
exp-neg98.1%
neg-mul-198.1%
prod-exp98.0%
rem-exp-log98.0%
*-commutative98.0%
distribute-rgt-in98.0%
rec-exp98.0%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 20.3%
Applied egg-rr16.1%
if -9e5 < b Initial program 99.0%
add-exp-log99.0%
div-exp99.0%
Applied egg-rr99.0%
Taylor expanded in a around -inf 99.0%
exp-neg99.0%
neg-mul-199.0%
prod-exp99.0%
rem-exp-log99.0%
*-commutative99.0%
distribute-rgt-in68.1%
rec-exp68.1%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 77.1%
Applied egg-rr54.9%
Final simplification47.0%
(FPCore (a b) :precision binary64 0.0)
double code(double a, double b) {
return 0.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.0d0
end function
public static double code(double a, double b) {
return 0.0;
}
def code(a, b): return 0.0
function code(a, b) return 0.0 end
function tmp = code(a, b) tmp = 0.0; end
code[a_, b_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 98.8%
add-exp-log98.8%
div-exp98.8%
Applied egg-rr98.8%
Taylor expanded in a around -inf 98.8%
exp-neg98.8%
neg-mul-198.8%
prod-exp98.8%
rem-exp-log98.8%
*-commutative98.8%
distribute-rgt-in74.2%
rec-exp74.2%
rgt-mult-inverse100.0%
prod-exp100.0%
Simplified100.0%
Taylor expanded in b around 0 65.6%
Applied egg-rr44.4%
Final simplification44.4%
(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 2023321
(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))))