| Alternative 1 | |
|---|---|
| Error | 3.21% |
| Cost | 25924 |
\[\begin{array}{l}
\mathbf{if}\;e^{b} \leq 1.00000002:\\
\;\;\;\;\mathsf{log1p}\left(e^{a} + b\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\
\end{array}
\]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (log1p (+ (exp a) (expm1 b))))
double code(double a, double b) {
return log((exp(a) + exp(b)));
}
double code(double a, double b) {
return log1p((exp(a) + expm1(b)));
}
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) {
return Math.log1p((Math.exp(a) + Math.expm1(b)));
}
def code(a, b): return math.log((math.exp(a) + math.exp(b)))
def code(a, b): return math.log1p((math.exp(a) + math.expm1(b)))
function code(a, b) return log(Float64(exp(a) + exp(b))) end
function code(a, b) return log1p(Float64(exp(a) + expm1(b))) end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := N[Log[1 + N[(N[Exp[a], $MachinePrecision] + N[(Exp[b] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\log \left(e^{a} + e^{b}\right)
\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)
Results
Initial program 46.38
Applied egg-rr47.12
Simplified2.2
[Start]47.12 | \[ \log \left(\sqrt{e^{a} + e^{b}}\right) + \log \left(\sqrt{e^{a} + e^{b}}\right)
\] |
|---|---|
log-prod [<=]47.53 | \[ \color{blue}{\log \left(\sqrt{e^{a} + e^{b}} \cdot \sqrt{e^{a} + e^{b}}\right)}
\] |
rem-square-sqrt [=>]46.38 | \[ \log \color{blue}{\left(e^{a} + e^{b}\right)}
\] |
log1p-expm1 [<=]46.56 | \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{a} + e^{b}\right)\right)\right)}
\] |
expm1-def [<=]46.56 | \[ \mathsf{log1p}\left(\color{blue}{e^{\log \left(e^{a} + e^{b}\right)} - 1}\right)
\] |
rem-exp-log [=>]46.56 | \[ \mathsf{log1p}\left(\color{blue}{\left(e^{a} + e^{b}\right)} - 1\right)
\] |
associate--l+ [=>]46.29 | \[ \mathsf{log1p}\left(\color{blue}{e^{a} + \left(e^{b} - 1\right)}\right)
\] |
expm1-def [=>]2.2 | \[ \mathsf{log1p}\left(e^{a} + \color{blue}{\mathsf{expm1}\left(b\right)}\right)
\] |
Final simplification2.2
| Alternative 1 | |
|---|---|
| Error | 3.21% |
| Cost | 25924 |
| Alternative 2 | |
|---|---|
| Error | 47.84% |
| Cost | 13128 |
| Alternative 3 | |
|---|---|
| Error | 4.28% |
| Cost | 12992 |
| Alternative 4 | |
|---|---|
| Error | 49.52% |
| Cost | 12864 |
| Alternative 5 | |
|---|---|
| Error | 50.88% |
| Cost | 6976 |
| Alternative 6 | |
|---|---|
| Error | 50.78% |
| Cost | 6720 |
| Alternative 7 | |
|---|---|
| Error | 51.06% |
| Cost | 6592 |
| Alternative 8 | |
|---|---|
| Error | 51.05% |
| Cost | 6592 |
| Alternative 9 | |
|---|---|
| Error | 51.56% |
| Cost | 6464 |
| Alternative 10 | |
|---|---|
| Error | 97.37% |
| Cost | 192 |
herbie shell --seed 2023103
(FPCore (a b)
:name "symmetry log of sum of exp"
:precision binary64
(log (+ (exp a) (exp b))))