?

Average Error: 54.4% → 98.5%
Time: 23.0s
Precision: binary64
Cost: 19648.00

?

\[ \begin{array}{c}[a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\log \left(e^{a} + e^{b}\right) \]
\[\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 (+ (log1p (exp a)) (/ b (+ (exp a) 1.0))))
double code(double a, double b) {
	return log((exp(a) + exp(b)));
}
double code(double a, double b) {
	return log1p(exp(a)) + (b / (exp(a) + 1.0));
}
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)) + (b / (Math.exp(a) + 1.0));
}
def code(a, b):
	return math.log((math.exp(a) + math.exp(b)))
def code(a, b):
	return math.log1p(math.exp(a)) + (b / (math.exp(a) + 1.0))
function code(a, b)
	return log(Float64(exp(a) + exp(b)))
end
function code(a, b)
	return Float64(log1p(exp(a)) + Float64(b / Float64(exp(a) + 1.0)))
end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := N[(N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision] + N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\log \left(e^{a} + e^{b}\right)
\mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 54.4

    \[\log \left(e^{a} + e^{b}\right) \]
  2. Taylor expanded in b around 0 98.2

    \[\leadsto \color{blue}{\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}} \]
  3. Simplified98.5

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

    [Start]98.2

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

    log1p-def [=>]98.5

    \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)} + \frac{b}{1 + e^{a}} \]
  4. Final simplification98.5

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

Alternatives

Alternative 1
Error98.3%
Cost20036.00
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 10^{-24}:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + \left(e^{a} + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\right)\right)\\ \end{array} \]
Alternative 2
Error98.1%
Cost19652.00
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 10^{-24}:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{a} + \left(b + 1\right)\right)\\ \end{array} \]
Alternative 3
Error98.2%
Cost19392.00
\[\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right) \]
Alternative 4
Error97.7%
Cost13764.00
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 10^{-24}:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \left(0.5 + b \cdot -0.25\right) + \left(b \cdot 0.5 + \log 2\right)\\ \end{array} \]
Alternative 5
Error97.7%
Cost7236.00
\[\begin{array}{l} \mathbf{if}\;a \leq -1:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(2 + \left(0.5 \cdot \left(b \cdot b\right) + \left(a + b\right)\right)\right)\\ \end{array} \]
Alternative 6
Error57.4%
Cost6852.00
\[\begin{array}{l} \mathbf{if}\;a \leq -112:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;b \cdot 0.5 + \log 2\\ \end{array} \]
Alternative 7
Error97.2%
Cost6852.00
\[\begin{array}{l} \mathbf{if}\;a \leq -85:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;b \cdot 0.5 + \log 2\\ \end{array} \]
Alternative 8
Error57.3%
Cost6724.00
\[\begin{array}{l} \mathbf{if}\;a \leq -1:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log \left(a + 2\right)\\ \end{array} \]
Alternative 9
Error57.3%
Cost6724.00
\[\begin{array}{l} \mathbf{if}\;a \leq -118:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log \left(b + 2\right)\\ \end{array} \]
Alternative 10
Error56.8%
Cost6596.00
\[\begin{array}{l} \mathbf{if}\;a \leq -130:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log 2\\ \end{array} \]
Alternative 11
Error11.9%
Cost192.00
\[b \cdot 0.5 \]

Error

Reproduce?

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