?

Average Error: 29.3 → 1.2
Time: 17.2s
Precision: binary64
Cost: 45513

?

\[ \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}\\ \mathbf{if}\;t_0 \leq 1.5 \lor \neg \left(t_0 \leq 2.1\right):\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\log t_0\\ \end{array} \]
(FPCore (a b) :precision binary64 (log (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (+ (exp a) (exp b))))
   (if (or (<= t_0 1.5) (not (<= t_0 2.1)))
     (/ b (+ 2.0 (expm1 a)))
     (log t_0))))
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 tmp;
	if ((t_0 <= 1.5) || !(t_0 <= 2.1)) {
		tmp = b / (2.0 + expm1(a));
	} else {
		tmp = log(t_0);
	}
	return tmp;
}
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 tmp;
	if ((t_0 <= 1.5) || !(t_0 <= 2.1)) {
		tmp = b / (2.0 + Math.expm1(a));
	} else {
		tmp = Math.log(t_0);
	}
	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)
	tmp = 0
	if (t_0 <= 1.5) or not (t_0 <= 2.1):
		tmp = b / (2.0 + math.expm1(a))
	else:
		tmp = math.log(t_0)
	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))
	tmp = 0.0
	if ((t_0 <= 1.5) || !(t_0 <= 2.1))
		tmp = Float64(b / Float64(2.0 + expm1(a)));
	else
		tmp = log(t_0);
	end
	return 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]}, If[Or[LessEqual[t$95$0, 1.5], N[Not[LessEqual[t$95$0, 2.1]], $MachinePrecision]], N[(b / N[(2.0 + N[(Exp[a] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[t$95$0], $MachinePrecision]]]
\log \left(e^{a} + e^{b}\right)
\begin{array}{l}
t_0 := e^{a} + e^{b}\\
\mathbf{if}\;t_0 \leq 1.5 \lor \neg \left(t_0 \leq 2.1\right):\\
\;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\

\mathbf{else}:\\
\;\;\;\;\log t_0\\


\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 2.10000000000000009 < (+.f64 (exp.f64 a) (exp.f64 b))

    1. Initial program 57.6

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

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

      \[\leadsto \color{blue}{\mathsf{log1p}\left(e^{a}\right) + \frac{b}{1 + e^{a}}} \]
      Proof

      [Start]1.9

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

      log1p-def [=>]1.7

      \[ \color{blue}{\mathsf{log1p}\left(e^{a}\right)} + \frac{b}{1 + e^{a}} \]
    4. Taylor expanded in b around inf 2.3

      \[\leadsto \color{blue}{\frac{b}{1 + e^{a}}} \]
    5. Simplified2.3

      \[\leadsto \color{blue}{\frac{b}{2 + \mathsf{expm1}\left(a\right)}} \]
      Proof

      [Start]2.3

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

      +-commutative [=>]2.3

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

      metadata-eval [<=]2.3

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

      associate--l+ [<=]2.3

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

      +-commutative [<=]2.3

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

      associate--l+ [=>]2.3

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

      expm1-def [=>]2.3

      \[ \frac{b}{2 + \color{blue}{\mathsf{expm1}\left(a\right)}} \]

    if 1.5 < (+.f64 (exp.f64 a) (exp.f64 b)) < 2.10000000000000009

    1. Initial program 0.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{a} + e^{b} \leq 1.5 \lor \neg \left(e^{a} + e^{b} \leq 2.1\right):\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(e^{a} + e^{b}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.7
Cost25924
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)\\ \end{array} \]
Alternative 2
Error1.1
Cost19648
\[\mathsf{log1p}\left(e^{a}\right) + \frac{b}{e^{a} + 1} \]
Alternative 3
Error1.7
Cost19396
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 10^{-301}:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(e^{b}\right)\\ \end{array} \]
Alternative 4
Error1.1
Cost13636
\[\begin{array}{l} \mathbf{if}\;a \leq -36:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + \left(e^{a} + \left(b + 0.5 \cdot \left(b \cdot b\right)\right)\right)\right)\\ \end{array} \]
Alternative 5
Error1.8
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 10^{-301}:\\ \;\;\;\;\frac{b}{2 + \mathsf{expm1}\left(a\right)}\\ \mathbf{else}:\\ \;\;\;\;\log \left(b + \left(a + 2\right)\right)\\ \end{array} \]
Alternative 6
Error27.1
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -1:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log \left(b + \left(a + 2\right)\right)\\ \end{array} \]
Alternative 7
Error27.4
Cost6724
\[\begin{array}{l} \mathbf{if}\;a \leq -700:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log \left(b + 2\right)\\ \end{array} \]
Alternative 8
Error27.4
Cost6724
\[\begin{array}{l} \mathbf{if}\;a \leq -700:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(b + 1\right)\\ \end{array} \]
Alternative 9
Error27.7
Cost6596
\[\begin{array}{l} \mathbf{if}\;a \leq -700:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\log 2\\ \end{array} \]
Alternative 10
Error56.4
Cost192
\[b \cdot 0.5 \]

Error

Reproduce?

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