?

Average Error: 29.8 → 1.2
Time: 21.4s
Precision: binary64
Cost: 46528

?

\[ \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}\\ \frac{b}{t_0} + \left(\log t_0 + 0.5 \cdot \left(\left(\frac{1}{t_0} - \frac{1}{{t_0}^{2}}\right) \cdot {b}^{2}\right)\right) \end{array} \]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (+ 1.0 (exp a))))
   (+
    (/ b t_0)
    (+
     (log t_0)
     (* 0.5 (* (- (/ 1.0 t_0) (/ 1.0 (pow t_0 2.0))) (pow b 2.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 (b / t_0) + (log(t_0) + (0.5 * (((1.0 / t_0) - (1.0 / pow(t_0, 2.0))) * pow(b, 2.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 = (b / t_0) + (log(t_0) + (0.5d0 * (((1.0d0 / t_0) - (1.0d0 / (t_0 ** 2.0d0))) * (b ** 2.0d0))))
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 (b / t_0) + (Math.log(t_0) + (0.5 * (((1.0 / t_0) - (1.0 / Math.pow(t_0, 2.0))) * Math.pow(b, 2.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 (b / t_0) + (math.log(t_0) + (0.5 * (((1.0 / t_0) - (1.0 / math.pow(t_0, 2.0))) * math.pow(b, 2.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(Float64(b / t_0) + Float64(log(t_0) + Float64(0.5 * Float64(Float64(Float64(1.0 / t_0) - Float64(1.0 / (t_0 ^ 2.0))) * (b ^ 2.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 = (b / t_0) + (log(t_0) + (0.5 * (((1.0 / t_0) - (1.0 / (t_0 ^ 2.0))) * (b ^ 2.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[(b / t$95$0), $MachinePrecision] + N[(N[Log[t$95$0], $MachinePrecision] + N[(0.5 * N[(N[(N[(1.0 / t$95$0), $MachinePrecision] - N[(1.0 / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
t_0 := 1 + e^{a}\\
\frac{b}{t_0} + \left(\log t_0 + 0.5 \cdot \left(\left(\frac{1}{t_0} - \frac{1}{{t_0}^{2}}\right) \cdot {b}^{2}\right)\right)
\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 29.8

    \[\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) + \left(0.5 \cdot \left(\left(\frac{1}{1 + e^{a}} - \frac{1}{{\left(1 + e^{a}\right)}^{2}}\right) \cdot {b}^{2}\right) + \frac{b}{1 + e^{a}}\right)} \]
  3. Simplified1.2

    \[\leadsto \color{blue}{\frac{b}{1 + e^{a}} + \left(\log \left(1 + e^{a}\right) + 0.5 \cdot \left(\left(\frac{1}{1 + e^{a}} - \frac{1}{{\left(1 + e^{a}\right)}^{2}}\right) \cdot {b}^{2}\right)\right)} \]
    Proof

    [Start]1.2

    \[ \log \left(1 + e^{a}\right) + \left(0.5 \cdot \left(\left(\frac{1}{1 + e^{a}} - \frac{1}{{\left(1 + e^{a}\right)}^{2}}\right) \cdot {b}^{2}\right) + \frac{b}{1 + e^{a}}\right) \]

    rational.json-simplify-41 [<=]1.2

    \[ \color{blue}{\frac{b}{1 + e^{a}} + \left(\log \left(1 + e^{a}\right) + 0.5 \cdot \left(\left(\frac{1}{1 + e^{a}} - \frac{1}{{\left(1 + e^{a}\right)}^{2}}\right) \cdot {b}^{2}\right)\right)} \]
  4. Final simplification1.2

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

Alternatives

Alternative 1
Error26.3
Cost32452
\[\begin{array}{l} t_0 := e^{a} + e^{b}\\ \mathbf{if}\;t_0 \leq 1:\\ \;\;\;\;0.5 \cdot b\\ \mathbf{else}:\\ \;\;\;\;\log t_0\\ \end{array} \]
Alternative 2
Error1.3
Cost19776
\[\begin{array}{l} t_0 := 1 + e^{a}\\ \log t_0 + \frac{b}{t_0} \end{array} \]
Alternative 3
Error27.5
Cost19524
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;0.5 \cdot b + 0.125 \cdot {b}^{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + e^{a}\right)\\ \end{array} \]
Alternative 4
Error27.6
Cost19524
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;0.5 \cdot b + 0.125 \cdot {b}^{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{b} - -1\right)\\ \end{array} \]
Alternative 5
Error28.0
Cost7044
\[\begin{array}{l} \mathbf{if}\;a \leq -125:\\ \;\;\;\;0.5 \cdot b + 0.125 \cdot {b}^{2}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot b + \log 2\\ \end{array} \]
Alternative 6
Error27.9
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -78:\\ \;\;\;\;0.5 \cdot b\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot b + \log 2\\ \end{array} \]
Alternative 7
Error28.0
Cost6724
\[\begin{array}{l} \mathbf{if}\;a \leq -90:\\ \;\;\;\;0.5 \cdot b\\ \mathbf{else}:\\ \;\;\;\;\log \left(2 + b\right)\\ \end{array} \]
Alternative 8
Error28.3
Cost6596
\[\begin{array}{l} \mathbf{if}\;a \leq -108:\\ \;\;\;\;0.5 \cdot b\\ \mathbf{else}:\\ \;\;\;\;\log 2\\ \end{array} \]
Alternative 9
Error56.3
Cost192
\[0.5 \cdot b \]

Error

Reproduce?

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