?

Average Error: 30.0 → 1.0
Time: 39.2s
Precision: binary64
Cost: 19648

?

\[\left(-1.79 \cdot 10^{+308} \leq x \land x \leq 1.79 \cdot 10^{+308}\right) \land \left(-1.79 \cdot 10^{+308} \leq y \land y \leq 1.79 \cdot 10^{+308}\right)\]
\[ \begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array} \]
\[\log \left(e^{x} + e^{y}\right) \]
\[\mathsf{log1p}\left(e^{x}\right) + \frac{y}{e^{x} + 1} \]
(FPCore (x y) :precision binary64 (log (+ (exp x) (exp y))))
(FPCore (x y) :precision binary64 (+ (log1p (exp x)) (/ y (+ (exp x) 1.0))))
double code(double x, double y) {
	return log((exp(x) + exp(y)));
}
double code(double x, double y) {
	return log1p(exp(x)) + (y / (exp(x) + 1.0));
}
public static double code(double x, double y) {
	return Math.log((Math.exp(x) + Math.exp(y)));
}
public static double code(double x, double y) {
	return Math.log1p(Math.exp(x)) + (y / (Math.exp(x) + 1.0));
}
def code(x, y):
	return math.log((math.exp(x) + math.exp(y)))
def code(x, y):
	return math.log1p(math.exp(x)) + (y / (math.exp(x) + 1.0))
function code(x, y)
	return log(Float64(exp(x) + exp(y)))
end
function code(x, y)
	return Float64(log1p(exp(x)) + Float64(y / Float64(exp(x) + 1.0)))
end
code[x_, y_] := N[Log[N[(N[Exp[x], $MachinePrecision] + N[Exp[y], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_] := N[(N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision] + N[(y / N[(N[Exp[x], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\log \left(e^{x} + e^{y}\right)
\mathsf{log1p}\left(e^{x}\right) + \frac{y}{e^{x} + 1}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 30.0

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

    \[\leadsto \color{blue}{\frac{y}{1 + e^{x}} + \log \left(1 + e^{x}\right)} \]
  3. Simplified1.0

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

    [Start]1.1

    \[ \frac{y}{1 + e^{x}} + \log \left(1 + e^{x}\right) \]

    +-commutative [=>]1.1

    \[ \color{blue}{\log \left(1 + e^{x}\right) + \frac{y}{1 + e^{x}}} \]

    log1p-def [=>]1.0

    \[ \color{blue}{\mathsf{log1p}\left(e^{x}\right)} + \frac{y}{1 + e^{x}} \]
  4. Final simplification1.0

    \[\leadsto \mathsf{log1p}\left(e^{x}\right) + \frac{y}{e^{x} + 1} \]

Alternatives

Alternative 1
Error1.0
Cost19524
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 0:\\ \;\;\;\;\frac{y}{e^{x} + 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(e^{x} + y\right)\\ \end{array} \]
Alternative 2
Error1.4
Cost19396
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 0:\\ \;\;\;\;\frac{y}{e^{x} + 1}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(e^{x}\right)\\ \end{array} \]
Alternative 3
Error1.5
Cost13764
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 2 \cdot 10^{-6}:\\ \;\;\;\;\frac{y}{e^{x} + 1}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \left(0.5 + y \cdot -0.25\right) + \left(\log 2 + y \cdot 0.5\right)\\ \end{array} \]
Alternative 4
Error1.9
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{x} \leq 0:\\ \;\;\;\;\frac{y}{e^{x} + 1}\\ \mathbf{else}:\\ \;\;\;\;\log 2 + y \cdot 0.5\\ \end{array} \]
Alternative 5
Error32.6
Cost6720
\[\log 2 + y \cdot 0.5 \]
Alternative 6
Error32.8
Cost6592
\[\log \left(y + 2\right) \]
Alternative 7
Error33.1
Cost6464
\[\log 2 \]

Error

Reproduce?

herbie shell --seed 1 
(FPCore (x y)
  :name "log(exp(x)+exp(y))"
  :precision binary64
  :pre (and (and (<= -1.79e+308 x) (<= x 1.79e+308)) (and (<= -1.79e+308 y) (<= y 1.79e+308)))
  (log (+ (exp x) (exp y))))