Average Error: 29.9 → 1.1
Time: 18.2s
Precision: binary64
\[[a, b] = \mathsf{sort}([a, b]) \\]
\[\log \left(e^{a} + e^{b}\right) \]
\[\begin{array}{l} t_0 := \mathsf{expm1}\left(a + a\right)\\ \mathsf{log1p}\left(e^{a}\right) - \frac{b \cdot t_0}{t_0 \cdot \left(-1 - e^{a}\right)} \end{array} \]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (expm1 (+ a a))))
   (- (log1p (exp a)) (/ (* b t_0) (* t_0 (- -1.0 (exp a)))))))
double code(double a, double b) {
	return log((exp(a) + exp(b)));
}
double code(double a, double b) {
	double t_0 = expm1((a + a));
	return log1p(exp(a)) - ((b * t_0) / (t_0 * (-1.0 - 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) {
	double t_0 = Math.expm1((a + a));
	return Math.log1p(Math.exp(a)) - ((b * t_0) / (t_0 * (-1.0 - Math.exp(a))));
}
def code(a, b):
	return math.log((math.exp(a) + math.exp(b)))
def code(a, b):
	t_0 = math.expm1((a + a))
	return math.log1p(math.exp(a)) - ((b * t_0) / (t_0 * (-1.0 - math.exp(a))))
function code(a, b)
	return log(Float64(exp(a) + exp(b)))
end
function code(a, b)
	t_0 = expm1(Float64(a + a))
	return Float64(log1p(exp(a)) - Float64(Float64(b * t_0) / Float64(t_0 * Float64(-1.0 - exp(a)))))
end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := Block[{t$95$0 = N[(Exp[N[(a + a), $MachinePrecision]] - 1), $MachinePrecision]}, N[(N[Log[1 + N[Exp[a], $MachinePrecision]], $MachinePrecision] - N[(N[(b * t$95$0), $MachinePrecision] / N[(t$95$0 * N[(-1.0 - N[Exp[a], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
t_0 := \mathsf{expm1}\left(a + a\right)\\
\mathsf{log1p}\left(e^{a}\right) - \frac{b \cdot t_0}{t_0 \cdot \left(-1 - e^{a}\right)}
\end{array}

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

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

    \[\leadsto \mathsf{log1p}\left(e^{a}\right) + \frac{b}{\color{blue}{\frac{1 \cdot 1 - e^{a} \cdot e^{a}}{1 - e^{a}}}} \]
  5. Applied associate-/r/_binary6430.0

    \[\leadsto \mathsf{log1p}\left(e^{a}\right) + \color{blue}{\frac{b}{1 \cdot 1 - e^{a} \cdot e^{a}} \cdot \left(1 - e^{a}\right)} \]
  6. Simplified1.5

    \[\leadsto \mathsf{log1p}\left(e^{a}\right) + \color{blue}{\frac{b}{-\mathsf{expm1}\left(a + a\right)}} \cdot \left(1 - e^{a}\right) \]
  7. Applied flip--_binary641.5

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

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

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

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

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

Reproduce

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