?

Average Error: 29.4 → 1.4
Time: 15.7s
Precision: binary64
Cost: 19392

?

\[ \begin{array}{c}[a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\log \left(e^{a} + e^{b}\right) \]
\[\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 (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)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 29.4

    \[\log \left(e^{a} + e^{b}\right) \]
  2. Applied egg-rr29.9

    \[\leadsto \color{blue}{\log \left(\sqrt{e^{a} + e^{b}}\right) + \log \left(\sqrt{e^{a} + e^{b}}\right)} \]
  3. Simplified1.4

    \[\leadsto \color{blue}{\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)} \]
    Proof

    [Start]29.9

    \[ \log \left(\sqrt{e^{a} + e^{b}}\right) + \log \left(\sqrt{e^{a} + e^{b}}\right) \]

    log-prod [<=]30.2

    \[ \color{blue}{\log \left(\sqrt{e^{a} + e^{b}} \cdot \sqrt{e^{a} + e^{b}}\right)} \]

    rem-square-sqrt [=>]29.4

    \[ \log \color{blue}{\left(e^{a} + e^{b}\right)} \]

    log1p-expm1 [<=]29.5

    \[ \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{a} + e^{b}\right)\right)\right)} \]

    expm1-def [<=]29.5

    \[ \mathsf{log1p}\left(\color{blue}{e^{\log \left(e^{a} + e^{b}\right)} - 1}\right) \]

    rem-exp-log [=>]29.5

    \[ \mathsf{log1p}\left(\color{blue}{\left(e^{a} + e^{b}\right)} - 1\right) \]

    associate--l+ [=>]29.3

    \[ \mathsf{log1p}\left(\color{blue}{e^{a} + \left(e^{b} - 1\right)}\right) \]

    expm1-def [=>]1.4

    \[ \mathsf{log1p}\left(e^{a} + \color{blue}{\mathsf{expm1}\left(b\right)}\right) \]
  4. Final simplification1.4

    \[\leadsto \mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right) \]

Alternatives

Alternative 1
Error2.1
Cost25928
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 1.001:\\ \;\;\;\;\mathsf{log1p}\left(e^{a} + b\right)\\ \mathbf{elif}\;e^{b} \leq 10^{+280}:\\ \;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\ \mathbf{else}:\\ \;\;\;\;b \cdot 0.5 + \log 2\\ \end{array} \]
Alternative 2
Error1.8
Cost25924
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 1.00000000001:\\ \;\;\;\;\mathsf{log1p}\left(e^{a} + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{a} + e^{b}\right)\\ \end{array} \]
Alternative 3
Error27.0
Cost19396
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(e^{a}\right)\\ \end{array} \]
Alternative 4
Error27.3
Cost19396
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\ \end{array} \]
Alternative 5
Error2.2
Cost13376
\[\mathsf{log1p}\left(e^{a} + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\right) \]
Alternative 6
Error27.6
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -1.38:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log 2 + a \cdot 0.5\\ \end{array} \]
Alternative 7
Error27.6
Cost6724
\[\begin{array}{l} \mathbf{if}\;a \leq -380:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log \left(b + 2\right)\\ \end{array} \]
Alternative 8
Error27.9
Cost6596
\[\begin{array}{l} \mathbf{if}\;a \leq -380:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log 2\\ \end{array} \]
Alternative 9
Error56.4
Cost192
\[b \cdot 0.5 \]

Error

Reproduce?

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