?

Average Error: 29.4 → 1.1
Time: 21.2s
Precision: binary64
Cost: 19776

?

\[ \begin{array}{c}[a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\log \left(e^{a} + e^{b}\right) \]
\[\begin{array}{l} t_0 := 1 + e^{a}\\ \log t_0 + \frac{b}{t_0} \end{array} \]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (+ 1.0 (exp a)))) (+ (log t_0) (/ b t_0))))
double code(double a, double b) {
	return log((exp(a) + exp(b)));
}
double code(double a, double b) {
	double t_0 = 1.0 + exp(a);
	return log(t_0) + (b / t_0);
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = log((exp(a) + exp(b)))
end function
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_0
    t_0 = 1.0d0 + exp(a)
    code = log(t_0) + (b / t_0)
end function
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 = 1.0 + Math.exp(a);
	return Math.log(t_0) + (b / t_0);
}
def code(a, b):
	return math.log((math.exp(a) + math.exp(b)))
def code(a, b):
	t_0 = 1.0 + math.exp(a)
	return math.log(t_0) + (b / t_0)
function code(a, b)
	return log(Float64(exp(a) + exp(b)))
end
function code(a, b)
	t_0 = Float64(1.0 + exp(a))
	return Float64(log(t_0) + Float64(b / t_0))
end
function tmp = code(a, b)
	tmp = log((exp(a) + exp(b)));
end
function tmp = code(a, b)
	t_0 = 1.0 + exp(a);
	tmp = log(t_0) + (b / t_0);
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[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]}, N[(N[Log[t$95$0], $MachinePrecision] + N[(b / t$95$0), $MachinePrecision]), $MachinePrecision]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
t_0 := 1 + e^{a}\\
\log t_0 + \frac{b}{t_0}
\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 29.4

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

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

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

Alternatives

Alternative 1
Error1.6
Cost19524
\[\begin{array}{l} t_0 := 1 + e^{a}\\ \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{b}{t_0}\\ \mathbf{else}:\\ \;\;\;\;\log t_0\\ \end{array} \]
Alternative 2
Error1.2
Cost13252
\[\begin{array}{l} \mathbf{if}\;a \leq -37:\\ \;\;\;\;\frac{b}{1 + e^{a}}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{a} + \left(b - -1\right)\right)\\ \end{array} \]
Alternative 3
Error27.4
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -118:\\ \;\;\;\;\frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot b + \log 2\\ \end{array} \]
Alternative 4
Error1.9
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -37:\\ \;\;\;\;\frac{b}{1 + e^{a}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot b + \log 2\\ \end{array} \]
Alternative 5
Error27.5
Cost6724
\[\begin{array}{l} \mathbf{if}\;a \leq -1:\\ \;\;\;\;\frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(2 + a\right)\\ \end{array} \]
Alternative 6
Error27.5
Cost6724
\[\begin{array}{l} \mathbf{if}\;a \leq -145:\\ \;\;\;\;\frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(2 + b\right)\\ \end{array} \]
Alternative 7
Error27.8
Cost6596
\[\begin{array}{l} \mathbf{if}\;a \leq -160:\\ \;\;\;\;\frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;\log 2\\ \end{array} \]
Alternative 8
Error56.4
Cost192
\[\frac{b}{2} \]

Error

Reproduce?

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