| Alternative 1 | |
|---|---|
| Accuracy | 73.8% |
| Cost | 13252 |
\[\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
\]

(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (if (<= (exp a) 0.0) (/ b (+ (exp a) 1.0)) (+ (* b 0.5) (log 2.0))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
double code(double a, double b) {
double tmp;
if (exp(a) <= 0.0) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = (b * 0.5) + log(2.0);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = log((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 (exp(a) <= 0.0d0) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = (b * 0.5d0) + log(2.0d0)
end if
code = tmp
end function
public static double code(double a, double b) {
return Math.log((Math.exp(a) + Math.exp(b)));
}
public static double code(double a, double b) {
double tmp;
if (Math.exp(a) <= 0.0) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = (b * 0.5) + Math.log(2.0);
}
return tmp;
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
def code(a, b): tmp = 0 if math.exp(a) <= 0.0: tmp = b / (math.exp(a) + 1.0) else: tmp = (b * 0.5) + math.log(2.0) return tmp
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function code(a, b) tmp = 0.0 if (exp(a) <= 0.0) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = Float64(Float64(b * 0.5) + log(2.0)); end return tmp end
function tmp = code(a, b) tmp = log((exp(a) + exp(b))); end
function tmp_2 = code(a, b) tmp = 0.0; if (exp(a) <= 0.0) tmp = b / (exp(a) + 1.0); else tmp = (b * 0.5) + log(2.0); end tmp_2 = tmp; end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(b * 0.5), $MachinePrecision] + N[Log[2.0], $MachinePrecision]), $MachinePrecision]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;b \cdot 0.5 + \log 2\\
\end{array}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if (exp.f64 a) < 0.0Initial program 5.5%
Taylor expanded in b around 0 89.6%
Simplified89.6%
[Start]89.6% | \[ \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}
\] |
|---|---|
log1p-def [=>]89.6% | \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)} + \frac{b}{1 + e^{a}}
\] |
Taylor expanded in b around inf 89.6%
if 0.0 < (exp.f64 a) Initial program 35.6%
Taylor expanded in b around 0 35.5%
Simplified35.5%
[Start]35.5% | \[ \log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}
\] |
|---|---|
log1p-def [=>]35.5% | \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)} + \frac{b}{1 + e^{a}}
\] |
Taylor expanded in a around 0 34.2%
Final simplification47.9%
| Alternative 1 | |
|---|---|
| Accuracy | 73.8% |
| Cost | 13252 |
| Alternative 2 | |
|---|---|
| Accuracy | 73.8% |
| Cost | 19648 |
| Alternative 3 | |
|---|---|
| Accuracy | 34.4% |
| Cost | 6852 |
| Alternative 4 | |
|---|---|
| Accuracy | 38.4% |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Accuracy | 34.2% |
| Cost | 6724 |
| Alternative 6 | |
|---|---|
| Accuracy | 34.0% |
| Cost | 6596 |
| Alternative 7 | |
|---|---|
| Accuracy | 15.3% |
| Cost | 192 |
herbie shell --seed 2023256
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))