Average Error: 29.8 → 1.1
Time: 5.9s
Precision: binary64
\[[a, b]=\mathsf{sort}([a, b])\]
\[\log \left(e^{a} + e^{b}\right) \]
\[\mathsf{log1p}\left(e^{a}\right) + \frac{b}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{a} + 1\right)\right)} \]
\log \left(e^{a} + e^{b}\right)
\mathsf{log1p}\left(e^{a}\right) + \frac{b}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{a} + 1\right)\right)}
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (+ (log1p (exp a)) (/ b (expm1 (log1p (+ (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 / expm1(log1p(exp(a) + 1.0)));
}

Error

Bits error versus a

Bits error versus b

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 29.8

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

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

    \[\leadsto \color{blue}{\mathsf{log1p}\left(e^{a}\right) + \frac{b}{1 + e^{a}}} \]
  4. Applied expm1-log1p-u_binary641.1

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

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

Reproduce

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