?

Average Error: 30.0 → 0.6
Time: 1.3min
Precision: binary64
Cost: 58824

?

\[ \begin{array}{c}[a, b] = \mathsf{sort}([a, b])\\ \end{array} \]
\[\log \left(e^{a} + e^{b}\right) \]
\[\begin{array}{l} t_0 := e^{a} + e^{b}\\ t_1 := 1 + e^{a}\\ t_2 := \log t_1 + \frac{b}{t_1}\\ \mathbf{if}\;t_0 \leq 1.5:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+102}:\\ \;\;\;\;\log \left(e^{b} \cdot 1.5 - \left(\left(e^{b} - e^{a}\right) + \frac{e^{b}}{-2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (+ (exp a) (exp b)))
        (t_1 (+ 1.0 (exp a)))
        (t_2 (+ (log t_1) (/ b t_1))))
   (if (<= t_0 1.5)
     t_2
     (if (<= t_0 5e+102)
       (log (- (* (exp b) 1.5) (+ (- (exp b) (exp a)) (/ (exp b) -2.0))))
       t_2))))
double code(double a, double b) {
	return log((exp(a) + exp(b)));
}
double code(double a, double b) {
	double t_0 = exp(a) + exp(b);
	double t_1 = 1.0 + exp(a);
	double t_2 = log(t_1) + (b / t_1);
	double tmp;
	if (t_0 <= 1.5) {
		tmp = t_2;
	} else if (t_0 <= 5e+102) {
		tmp = log(((exp(b) * 1.5) - ((exp(b) - exp(a)) + (exp(b) / -2.0))));
	} else {
		tmp = t_2;
	}
	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) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = exp(a) + exp(b)
    t_1 = 1.0d0 + exp(a)
    t_2 = log(t_1) + (b / t_1)
    if (t_0 <= 1.5d0) then
        tmp = t_2
    else if (t_0 <= 5d+102) then
        tmp = log(((exp(b) * 1.5d0) - ((exp(b) - exp(a)) + (exp(b) / (-2.0d0)))))
    else
        tmp = t_2
    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 t_0 = Math.exp(a) + Math.exp(b);
	double t_1 = 1.0 + Math.exp(a);
	double t_2 = Math.log(t_1) + (b / t_1);
	double tmp;
	if (t_0 <= 1.5) {
		tmp = t_2;
	} else if (t_0 <= 5e+102) {
		tmp = Math.log(((Math.exp(b) * 1.5) - ((Math.exp(b) - Math.exp(a)) + (Math.exp(b) / -2.0))));
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(a, b):
	return math.log((math.exp(a) + math.exp(b)))
def code(a, b):
	t_0 = math.exp(a) + math.exp(b)
	t_1 = 1.0 + math.exp(a)
	t_2 = math.log(t_1) + (b / t_1)
	tmp = 0
	if t_0 <= 1.5:
		tmp = t_2
	elif t_0 <= 5e+102:
		tmp = math.log(((math.exp(b) * 1.5) - ((math.exp(b) - math.exp(a)) + (math.exp(b) / -2.0))))
	else:
		tmp = t_2
	return tmp
function code(a, b)
	return log(Float64(exp(a) + exp(b)))
end
function code(a, b)
	t_0 = Float64(exp(a) + exp(b))
	t_1 = Float64(1.0 + exp(a))
	t_2 = Float64(log(t_1) + Float64(b / t_1))
	tmp = 0.0
	if (t_0 <= 1.5)
		tmp = t_2;
	elseif (t_0 <= 5e+102)
		tmp = log(Float64(Float64(exp(b) * 1.5) - Float64(Float64(exp(b) - exp(a)) + Float64(exp(b) / -2.0))));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp = code(a, b)
	tmp = log((exp(a) + exp(b)));
end
function tmp_2 = code(a, b)
	t_0 = exp(a) + exp(b);
	t_1 = 1.0 + exp(a);
	t_2 = log(t_1) + (b / t_1);
	tmp = 0.0;
	if (t_0 <= 1.5)
		tmp = t_2;
	elseif (t_0 <= 5e+102)
		tmp = log(((exp(b) * 1.5) - ((exp(b) - exp(a)) + (exp(b) / -2.0))));
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
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[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[Exp[a], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Log[t$95$1], $MachinePrecision] + N[(b / t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1.5], t$95$2, If[LessEqual[t$95$0, 5e+102], N[Log[N[(N[(N[Exp[b], $MachinePrecision] * 1.5), $MachinePrecision] - N[(N[(N[Exp[b], $MachinePrecision] - N[Exp[a], $MachinePrecision]), $MachinePrecision] + N[(N[Exp[b], $MachinePrecision] / -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], t$95$2]]]]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
t_0 := e^{a} + e^{b}\\
t_1 := 1 + e^{a}\\
t_2 := \log t_1 + \frac{b}{t_1}\\
\mathbf{if}\;t_0 \leq 1.5:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+102}:\\
\;\;\;\;\log \left(e^{b} \cdot 1.5 - \left(\left(e^{b} - e^{a}\right) + \frac{e^{b}}{-2}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\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 (+.f64 (exp.f64 a) (exp.f64 b)) < 1.5 or 5e102 < (+.f64 (exp.f64 a) (exp.f64 b))

    1. Initial program 58.2

      \[\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}}} \]

    if 1.5 < (+.f64 (exp.f64 a) (exp.f64 b)) < 5e102

    1. Initial program 0.0

      \[\log \left(e^{a} + e^{b}\right) \]
    2. Applied egg-rr0.0

      \[\leadsto \log \color{blue}{\left(3 \cdot \frac{e^{b}}{2} - \left(\left(e^{b} - e^{a}\right) + \frac{e^{b}}{-2}\right)\right)} \]
    3. Simplified0.0

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

      [Start]0.0

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

      rational_best-simplify-55 [=>]0.0

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

      metadata-eval [=>]0.0

      \[ \log \left(e^{b} \cdot \color{blue}{1.5} - \left(\left(e^{b} - e^{a}\right) + \frac{e^{b}}{-2}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{a} + e^{b} \leq 1.5:\\ \;\;\;\;\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}\\ \mathbf{elif}\;e^{a} + e^{b} \leq 5 \cdot 10^{+102}:\\ \;\;\;\;\log \left(e^{b} \cdot 1.5 - \left(\left(e^{b} - e^{a}\right) + \frac{e^{b}}{-2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + e^{a}\right) + \frac{b}{1 + e^{a}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.9
Cost46528
\[\begin{array}{l} t_0 := 1 + e^{a}\\ \left(\log t_0 + \frac{b}{t_0}\right) + 0.5 \cdot \left(\left(\frac{1}{t_0} - \frac{1}{{t_0}^{2}}\right) \cdot {b}^{2}\right) \end{array} \]
Alternative 2
Error0.7
Cost45896
\[\begin{array}{l} t_0 := e^{a} + e^{b}\\ t_1 := 1 + e^{a}\\ t_2 := \log t_1 + \frac{b}{t_1}\\ \mathbf{if}\;t_0 \leq 2:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+102}:\\ \;\;\;\;\log \left(e^{b} \cdot 1.5 - \left(-1 + 0.5 \cdot e^{b}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error1.9
Cost32452
\[\begin{array}{l} t_0 := e^{a} + e^{b}\\ \mathbf{if}\;t_0 \leq 1.0000002:\\ \;\;\;\;\frac{b}{1 + e^{a}} + 0.125 \cdot {b}^{2}\\ \mathbf{else}:\\ \;\;\;\;\log t_0\\ \end{array} \]
Alternative 4
Error3.0
Cost19972
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{b}{1 + e^{a}} + 0.125 \cdot {b}^{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + e^{b}\right)\\ \end{array} \]
Alternative 5
Error26.9
Cost19780
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 1.00004:\\ \;\;\;\;\log \left(1 + e^{a}\right) + \frac{b}{2}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + e^{b}\right)\\ \end{array} \]
Alternative 6
Error30.6
Cost13252
\[\begin{array}{l} \mathbf{if}\;b \leq 4.2 \cdot 10^{-5}:\\ \;\;\;\;\log \left(e^{a} + \left(1 + b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + e^{b}\right)\\ \end{array} \]
Alternative 7
Error31.1
Cost13124
\[\begin{array}{l} \mathbf{if}\;b \leq 4.8 \cdot 10^{-25}:\\ \;\;\;\;\log \left(1 + e^{a}\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + e^{b}\right)\\ \end{array} \]
Alternative 8
Error32.1
Cost12992
\[\log \left(1 + e^{a}\right) \]
Alternative 9
Error31.9
Cost7496
\[\begin{array}{l} \mathbf{if}\;a \leq -1.4:\\ \;\;\;\;0.125 \cdot {b}^{2}\\ \mathbf{elif}\;a \leq -8.4 \cdot 10^{-16}:\\ \;\;\;\;\left(\frac{a}{8} - \left(a \cdot -0.25 - \log 2\right)\right) + \frac{a}{8}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot b + \log 2\\ \end{array} \]
Alternative 10
Error31.9
Cost6984
\[\begin{array}{l} \mathbf{if}\;a \leq -1.4:\\ \;\;\;\;0.125 \cdot {b}^{2}\\ \mathbf{elif}\;a \leq -8.4 \cdot 10^{-16}:\\ \;\;\;\;0.5 \cdot a + \log 2\\ \mathbf{else}:\\ \;\;\;\;\log \left(2 + b\right)\\ \end{array} \]
Alternative 11
Error31.9
Cost6984
\[\begin{array}{l} \mathbf{if}\;a \leq -1.4:\\ \;\;\;\;0.125 \cdot {b}^{2}\\ \mathbf{elif}\;a \leq -2 \cdot 10^{-16}:\\ \;\;\;\;0.5 \cdot a + \log 2\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot b + \log 2\\ \end{array} \]
Alternative 12
Error31.9
Cost6856
\[\begin{array}{l} \mathbf{if}\;a \leq -1:\\ \;\;\;\;0.125 \cdot {b}^{2}\\ \mathbf{elif}\;a \leq -3.8 \cdot 10^{-16}:\\ \;\;\;\;\log \left(2 + a\right)\\ \mathbf{else}:\\ \;\;\;\;\log \left(2 + b\right)\\ \end{array} \]
Alternative 13
Error32.9
Cost6592
\[\log \left(2 + b\right) \]
Alternative 14
Error33.2
Cost6464
\[\log 2 \]
Alternative 15
Error62.3
Cost192
\[0.5 \cdot a \]

Error

Reproduce?

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