| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 19520 |
\[\frac{e^{a}}{e^{a} + e^{b}}
\]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
:precision binary64
(let* ((t_0 (/ 1.0 (+ (exp b) 1.0))))
(if (<= b -218191.03391589562)
t_0
(if (<= b 6.330604416213415e-22) (/ (exp a) (+ (exp a) 1.0)) t_0))))double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
double t_0 = 1.0 / (exp(b) + 1.0);
double tmp;
if (b <= -218191.03391589562) {
tmp = t_0;
} else if (b <= 6.330604416213415e-22) {
tmp = exp(a) / (exp(a) + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
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
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 / (exp(b) + 1.0d0)
if (b <= (-218191.03391589562d0)) then
tmp = t_0
else if (b <= 6.330604416213415d-22) then
tmp = exp(a) / (exp(a) + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b) {
return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
public static double code(double a, double b) {
double t_0 = 1.0 / (Math.exp(b) + 1.0);
double tmp;
if (b <= -218191.03391589562) {
tmp = t_0;
} else if (b <= 6.330604416213415e-22) {
tmp = Math.exp(a) / (Math.exp(a) + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b): t_0 = 1.0 / (math.exp(b) + 1.0) tmp = 0 if b <= -218191.03391589562: tmp = t_0 elif b <= 6.330604416213415e-22: tmp = math.exp(a) / (math.exp(a) + 1.0) else: tmp = t_0 return tmp
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function code(a, b) t_0 = Float64(1.0 / Float64(exp(b) + 1.0)) tmp = 0.0 if (b <= -218191.03391589562) tmp = t_0; elseif (b <= 6.330604416213415e-22) tmp = Float64(exp(a) / Float64(exp(a) + 1.0)); else tmp = t_0; end return tmp end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
function tmp_2 = code(a, b) t_0 = 1.0 / (exp(b) + 1.0); tmp = 0.0; if (b <= -218191.03391589562) tmp = t_0; elseif (b <= 6.330604416213415e-22) tmp = exp(a) / (exp(a) + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_] := Block[{t$95$0 = N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -218191.03391589562], t$95$0, If[LessEqual[b, 6.330604416213415e-22], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
t_0 := \frac{1}{e^{b} + 1}\\
\mathbf{if}\;b \leq -218191.03391589562:\\
\;\;\;\;t_0\\
\mathbf{elif}\;b \leq 6.330604416213415 \cdot 10^{-22}:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
| Original | 0.7 |
|---|---|
| Target | 0.0 |
| Herbie | 1.1 |
if b < -218191.03391589562 or 6.330604416213415e-22 < b Initial program 0.9
Taylor expanded in a around 0 1.0
if -218191.03391589562 < b < 6.330604416213415e-22Initial program 0.6
Taylor expanded in b around 0 1.3
Final simplification1.1
| Alternative 1 | |
|---|---|
| Error | 0.7 |
| Cost | 19520 |
| Alternative 2 | |
|---|---|
| Error | 1.1 |
| Cost | 6852 |
| Alternative 3 | |
|---|---|
| Error | 22.6 |
| Cost | 6592 |
| Alternative 4 | |
|---|---|
| Error | 38.9 |
| Cost | 320 |
| Alternative 5 | |
|---|---|
| Error | 39.0 |
| Cost | 64 |

herbie shell --seed 2022300
(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))))