?

Average Error: 29.7 → 0.7
Time: 21.0s
Precision: binary64
Cost: 25924

?

\[ \begin{array}{c}[a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\log \left(e^{a} + e^{b}\right) \]
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{b}{e^{a} - -1}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{a} + e^{b}\right)\\ \end{array} \]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (<= (exp a) 0.0) (/ b (- (exp a) -1.0)) (log (+ (exp a) (exp b)))))
double code(double a, double b) {
	return log((exp(a) + exp(b)));
}
double code(double a, double b) {
	double tmp;
	if (exp(a) <= 0.0) {
		tmp = b / (exp(a) - -1.0);
	} else {
		tmp = log((exp(a) + exp(b)));
	}
	return tmp;
}
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) :: tmp
    if (exp(a) <= 0.0d0) then
        tmp = b / (exp(a) - (-1.0d0))
    else
        tmp = log((exp(a) + exp(b)))
    end if
    code = tmp
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 tmp;
	if (Math.exp(a) <= 0.0) {
		tmp = b / (Math.exp(a) - -1.0);
	} else {
		tmp = Math.log((Math.exp(a) + Math.exp(b)));
	}
	return tmp;
}
def code(a, b):
	return math.log((math.exp(a) + math.exp(b)))
def code(a, b):
	tmp = 0
	if math.exp(a) <= 0.0:
		tmp = b / (math.exp(a) - -1.0)
	else:
		tmp = math.log((math.exp(a) + math.exp(b)))
	return tmp
function code(a, b)
	return log(Float64(exp(a) + exp(b)))
end
function code(a, b)
	tmp = 0.0
	if (exp(a) <= 0.0)
		tmp = Float64(b / Float64(exp(a) - -1.0));
	else
		tmp = log(Float64(exp(a) + exp(b)));
	end
	return tmp
end
function tmp = code(a, b)
	tmp = log((exp(a) + exp(b)));
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (exp(a) <= 0.0)
		tmp = b / (exp(a) - -1.0);
	else
		tmp = log((exp(a) + exp(b)));
	end
	tmp_2 = tmp;
end
code[a_, b_] := N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 0.0], N[(b / N[(N[Exp[a], $MachinePrecision] - -1.0), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;\frac{b}{e^{a} - -1}\\

\mathbf{else}:\\
\;\;\;\;\log \left(e^{a} + e^{b}\right)\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (exp.f64 a) < 0.0

    1. Initial program 58.1

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

      \[\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. Simplified0

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

      [Start]0

      \[ \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-1 [=>]0

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

      rational.json-simplify-41 [=>]0

      \[ \color{blue}{\frac{b}{1 + e^{a}} + \left(0.5 \cdot \left(\left(\frac{1}{1 + e^{a}} - \frac{1}{{\left(1 + e^{a}\right)}^{2}}\right) \cdot {b}^{2}\right) + \log \left(1 + e^{a}\right)\right)} \]
    4. Taylor expanded in b around 0 0

      \[\leadsto \frac{b}{1 + e^{a}} + \color{blue}{\log \left(1 + e^{a}\right)} \]
    5. Taylor expanded in b around inf 0

      \[\leadsto \color{blue}{\frac{b}{1 + e^{a}}} \]
    6. Simplified0

      \[\leadsto \color{blue}{\frac{b}{e^{a} - -1}} \]
      Proof

      [Start]0

      \[ \frac{b}{1 + e^{a}} \]

      rational.json-simplify-17 [=>]0

      \[ \frac{b}{\color{blue}{e^{a} - -1}} \]

    if 0.0 < (exp.f64 a)

    1. Initial program 1.5

      \[\log \left(e^{a} + e^{b}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{b}{e^{a} - -1}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{a} + e^{b}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.9
Cost46528
\[\begin{array}{l} t_0 := 1 + e^{a}\\ \frac{b}{t_0} + \left(0.5 \cdot \left(\left(\frac{1}{t_0} - \frac{1}{{t_0}^{2}}\right) \cdot {b}^{2}\right) + \log t_0\right) \end{array} \]
Alternative 2
Error1.1
Cost19776
\[\begin{array}{l} t_0 := 1 + e^{a}\\ \log t_0 + \frac{b}{t_0} \end{array} \]
Alternative 3
Error1.4
Cost19524
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{b}{e^{a} - -1}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{b} - -1\right)\\ \end{array} \]
Alternative 4
Error1.5
Cost7364
\[\begin{array}{l} \mathbf{if}\;a \leq -1.35:\\ \;\;\;\;\frac{b}{e^{a} - -1}\\ \mathbf{else}:\\ \;\;\;\;b \cdot \left(0.5 - a \cdot 0.25\right) + \left(\log 2 + 0.5 \cdot a\right)\\ \end{array} \]
Alternative 5
Error27.7
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -130:\\ \;\;\;\;\frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;b \cdot 0.5 + \log 2\\ \end{array} \]
Alternative 6
Error1.8
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -25:\\ \;\;\;\;\frac{b}{e^{a} - -1}\\ \mathbf{else}:\\ \;\;\;\;b \cdot 0.5 + \log 2\\ \end{array} \]
Alternative 7
Error27.9
Cost6724
\[\begin{array}{l} \mathbf{if}\;a \leq -1:\\ \;\;\;\;\frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(2 + a\right)\\ \end{array} \]
Alternative 8
Error27.8
Cost6724
\[\begin{array}{l} \mathbf{if}\;a \leq -92:\\ \;\;\;\;\frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(2 + b\right)\\ \end{array} \]
Alternative 9
Error28.1
Cost6596
\[\begin{array}{l} \mathbf{if}\;a \leq -75:\\ \;\;\;\;\frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;\log 2\\ \end{array} \]
Alternative 10
Error56.3
Cost192
\[\frac{b}{2} \]

Error

Reproduce?

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