Average Error: 29.3 → 0.9
Time: 16.3s
Precision: binary64
\[[a, b] = \mathsf{sort}([a, b]) \\]
\[\log \left(e^{a} + e^{b}\right) \]
\[e^{\log \left(\mathsf{log1p}\left(e^{a}\right)\right)} + \frac{b}{e^{a} + 1} \]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (+ (exp (log (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 exp(log(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.exp(Math.log(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.exp(math.log(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(exp(log(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[Exp[N[Log[N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] + N[(b / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\log \left(e^{a} + e^{b}\right)
e^{\log \left(\mathsf{log1p}\left(e^{a}\right)\right)} + \frac{b}{e^{a} + 1}

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

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

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

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

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

Reproduce

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