| Alternative 1 | |
|---|---|
| Error | 1.1% |
| Cost | 32448 |
\[\frac{e^{a}}{{\left({\left(e^{a} + e^{b}\right)}^{3}\right)}^{0.3333333333333333}}
\]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (if (<= a -13000.0) 0.0 (/ 1.0 (+ -1.0 (+ (exp b) 2.0)))))
double code(double a, double b) {
return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
double tmp;
if (a <= -13000.0) {
tmp = 0.0;
} else {
tmp = 1.0 / (-1.0 + (exp(b) + 2.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) :: tmp
if (a <= (-13000.0d0)) then
tmp = 0.0d0
else
tmp = 1.0d0 / ((-1.0d0) + (exp(b) + 2.0d0))
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 tmp;
if (a <= -13000.0) {
tmp = 0.0;
} else {
tmp = 1.0 / (-1.0 + (Math.exp(b) + 2.0));
}
return tmp;
}
def code(a, b): return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b): tmp = 0 if a <= -13000.0: tmp = 0.0 else: tmp = 1.0 / (-1.0 + (math.exp(b) + 2.0)) return tmp
function code(a, b) return Float64(exp(a) / Float64(exp(a) + exp(b))) end
function code(a, b) tmp = 0.0 if (a <= -13000.0) tmp = 0.0; else tmp = Float64(1.0 / Float64(-1.0 + Float64(exp(b) + 2.0))); end return tmp end
function tmp = code(a, b) tmp = exp(a) / (exp(a) + exp(b)); end
function tmp_2 = code(a, b) tmp = 0.0; if (a <= -13000.0) tmp = 0.0; else tmp = 1.0 / (-1.0 + (exp(b) + 2.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_] := If[LessEqual[a, -13000.0], 0.0, N[(1.0 / N[(-1.0 + N[(N[Exp[b], $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;a \leq -13000:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{-1 + \left(e^{b} + 2\right)}\\
\end{array}
Results
| Original | 1.02% |
|---|---|
| Target | 0.02% |
| Herbie | 1.4% |
if a < -13000Initial program 1.14
Taylor expanded in a around 0 64.79
Taylor expanded in b around 0 96.07
Simplified96.07
[Start]96.07 | \[ \frac{1}{2 + b}
\] |
|---|---|
+-commutative [=>]96.07 | \[ \frac{1}{\color{blue}{b + 2}}
\] |
Applied egg-rr66.58
Simplified66.58
[Start]66.58 | \[ \left(1 + \frac{1}{b + 2}\right) - 1
\] |
|---|---|
associate--l+ [=>]66.58 | \[ \color{blue}{1 + \left(\frac{1}{b + 2} - 1\right)}
\] |
Taylor expanded in b around inf 0.55
if -13000 < a Initial program 0.98
Taylor expanded in a around 0 1.7
Applied egg-rr1.7
Simplified1.7
[Start]1.7 | \[ \frac{1}{\left(1 + \left(1 + e^{b}\right)\right) - 1}
\] |
|---|---|
sub-neg [=>]1.7 | \[ \frac{1}{\color{blue}{\left(1 + \left(1 + e^{b}\right)\right) + \left(-1\right)}}
\] |
associate-+r+ [=>]1.7 | \[ \frac{1}{\color{blue}{\left(\left(1 + 1\right) + e^{b}\right)} + \left(-1\right)}
\] |
metadata-eval [=>]1.7 | \[ \frac{1}{\left(\color{blue}{2} + e^{b}\right) + \left(-1\right)}
\] |
metadata-eval [=>]1.7 | \[ \frac{1}{\left(2 + e^{b}\right) + \color{blue}{-1}}
\] |
Final simplification1.4
| Alternative 1 | |
|---|---|
| Error | 1.1% |
| Cost | 32448 |
| Alternative 2 | |
|---|---|
| Error | 1.02% |
| Cost | 19520 |
| Alternative 3 | |
|---|---|
| Error | 1.39% |
| Cost | 6852 |
| Alternative 4 | |
|---|---|
| Error | 17.22% |
| Cost | 6724 |
| Alternative 5 | |
|---|---|
| Error | 36.75% |
| Cost | 717 |
| Alternative 6 | |
|---|---|
| Error | 20.38% |
| Cost | 708 |
| Alternative 7 | |
|---|---|
| Error | 37.11% |
| Cost | 460 |
| Alternative 8 | |
|---|---|
| Error | 60.57% |
| Cost | 64 |
herbie shell --seed 2023102
(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))))