| Alternative 1 | |
|---|---|
| Error | 1.2 |
| Cost | 19392 |
\[\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)
\]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (if (<= a -1e-108) (log1p (+ (exp a) (+ b (* 0.5 (* b b))))) (log1p (exp b))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
double code(double a, double b) {
double tmp;
if (a <= -1e-108) {
tmp = log1p((exp(a) + (b + (0.5 * (b * b)))));
} else {
tmp = log1p(exp(b));
}
return tmp;
}
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 (a <= -1e-108) {
tmp = Math.log1p((Math.exp(a) + (b + (0.5 * (b * b)))));
} else {
tmp = Math.log1p(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 a <= -1e-108: tmp = math.log1p((math.exp(a) + (b + (0.5 * (b * b))))) else: tmp = math.log1p(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 (a <= -1e-108) tmp = log1p(Float64(exp(a) + Float64(b + Float64(0.5 * Float64(b * b))))); else tmp = log1p(exp(b)); end return tmp end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := If[LessEqual[a, -1e-108], N[Log[1 + N[(N[Exp[a], $MachinePrecision] + N[(b + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
\mathbf{if}\;a \leq -1 \cdot 10^{-108}:\\
\;\;\;\;\mathsf{log1p}\left(e^{a} + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\
\end{array}
Results
if a < -1.00000000000000004e-108Initial program 44.0
Applied egg-rr44.3
Simplified1.1
[Start]44.3 | \[ \log \left(\sqrt{e^{a} + e^{b}}\right) + \log \left(\sqrt{e^{a} + e^{b}}\right)
\] |
|---|---|
log-prod [<=]44.4 | \[ \color{blue}{\log \left(\sqrt{e^{a} + e^{b}} \cdot \sqrt{e^{a} + e^{b}}\right)}
\] |
rem-square-sqrt [=>]44.0 | \[ \log \color{blue}{\left(e^{a} + e^{b}\right)}
\] |
log1p-expm1 [<=]44.1 | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{a} + e^{b}\right)\right)\right)}
\] |
expm1-def [<=]44.1 | \[ \mathsf{log1p}\left(\color{blue}{e^{\log \left(e^{a} + e^{b}\right)} - 1}\right)
\] |
rem-exp-log [=>]44.1 | \[ \mathsf{log1p}\left(\color{blue}{\left(e^{a} + e^{b}\right)} - 1\right)
\] |
associate--l+ [=>]44.0 | \[ \mathsf{log1p}\left(\color{blue}{e^{a} + \left(e^{b} - 1\right)}\right)
\] |
expm1-def [=>]1.1 | \[ \mathsf{log1p}\left(e^{a} + \color{blue}{\mathsf{expm1}\left(b\right)}\right)
\] |
Taylor expanded in b around 0 1.8
Simplified1.8
[Start]1.8 | \[ \mathsf{log1p}\left(e^{a} + \left(b + 0.5 \cdot {b}^{2}\right)\right)
\] |
|---|---|
unpow2 [=>]1.8 | \[ \mathsf{log1p}\left(e^{a} + \left(b + 0.5 \cdot \color{blue}{\left(b \cdot b\right)}\right)\right)
\] |
if -1.00000000000000004e-108 < a Initial program 1.4
Taylor expanded in a around 0 1.4
Simplified1.3
[Start]1.4 | \[ \log \left(1 + e^{b}\right)
\] |
|---|---|
log1p-def [=>]1.3 | \[ \color{blue}{\mathsf{log1p}\left(e^{b}\right)}
\] |
Final simplification1.6
| Alternative 1 | |
|---|---|
| Error | 1.2 |
| Cost | 19392 |
| Alternative 2 | |
|---|---|
| Error | 2.0 |
| Cost | 13124 |
| Alternative 3 | |
|---|---|
| Error | 30.5 |
| Cost | 12996 |
| Alternative 4 | |
|---|---|
| Error | 31.2 |
| Cost | 12864 |
| Alternative 5 | |
|---|---|
| Error | 32.0 |
| Cost | 6720 |
| Alternative 6 | |
|---|---|
| Error | 32.2 |
| Cost | 6592 |
| Alternative 7 | |
|---|---|
| Error | 32.2 |
| Cost | 6592 |
| Alternative 8 | |
|---|---|
| Error | 32.5 |
| Cost | 6464 |
| Alternative 9 | |
|---|---|
| Error | 62.3 |
| Cost | 320 |
herbie shell --seed 2023025
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))