Average Error: 29.3 → 1.0
Time: 26.5s
Precision: binary64
\[[a, b] = \mathsf{sort}([a, b]) \\]
\[\log \left(e^{a} + e^{b}\right) \]
\[\frac{b}{1 + e^{a}} + \mathsf{log1p}\left(e^{a}\right) \]
\log \left(e^{a} + e^{b}\right)
\frac{b}{1 + e^{a}} + \mathsf{log1p}\left(e^{a}\right)
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (+ (/ b (+ 1.0 (exp a))) (log1p (exp a))))
double code(double a, double b) {
	return log(exp(a) + exp(b));
}
double code(double a, double b) {
	return (b / (1.0 + exp(a))) + log1p(exp(a));
}

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.3

    \[\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.0

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

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

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

Reproduce

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