| Alternative 1 | |
|---|---|
| Error | 0.9 |
| Cost | 19648 |
\[\mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}
\]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (if (<= (exp a) 2e-123) (/ b (+ (exp a) 1.0)) (log (+ (exp a) (exp b)))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
double code(double a, double b) {
double tmp;
if (exp(a) <= 2e-123) {
tmp = b / (exp(a) + 1.0);
} else {
tmp = log((exp(a) + exp(b)));
}
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) <= 2d-123) then
tmp = b / (exp(a) + 1.0d0)
else
tmp = log((exp(a) + exp(b)))
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) <= 2e-123) {
tmp = b / (Math.exp(a) + 1.0);
} else {
tmp = Math.log((Math.exp(a) + Math.exp(b)));
}
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) <= 2e-123: tmp = b / (math.exp(a) + 1.0) else: tmp = math.log((math.exp(a) + math.exp(b))) return tmp
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function code(a, b) tmp = 0.0 if (exp(a) <= 2e-123) tmp = Float64(b / Float64(exp(a) + 1.0)); else tmp = log(Float64(exp(a) + exp(b))); 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) <= 2e-123) tmp = b / (exp(a) + 1.0); else tmp = log((exp(a) + exp(b))); 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], 2e-123], N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 2 \cdot 10^{-123}:\\
\;\;\;\;\frac{b}{e^{a} + 1}\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
Results
if (exp.f64 a) < 2.0000000000000001e-123Initial program 58.2
Taylor expanded in b around 0 0.0
Simplified0
Taylor expanded in b around inf 0.0
if 2.0000000000000001e-123 < (exp.f64 a) Initial program 1.1
Final simplification0.6
| Alternative 1 | |
|---|---|
| Error | 0.9 |
| Cost | 19648 |
| Alternative 2 | |
|---|---|
| Error | 1.1 |
| Cost | 19396 |
| Alternative 3 | |
|---|---|
| Error | 27.9 |
| Cost | 6852 |
| Alternative 4 | |
|---|---|
| Error | 1.6 |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Error | 28.0 |
| Cost | 6724 |
| Alternative 6 | |
|---|---|
| Error | 28.4 |
| Cost | 6596 |
| Alternative 7 | |
|---|---|
| Error | 56.2 |
| Cost | 192 |

herbie shell --seed 2022313
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))