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

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 egg-rr1.5

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

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

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

Reproduce

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