?

Average Error: 0.0 → 0.0
Time: 9.1s
Precision: binary64
Cost: 19392

?

$\left(1 \leq x \land x \leq 500\right) \land \left(1 \leq y \land y \leq 500\right)$
$\begin{array}{c}[x, y] = \mathsf{sort}([x, y])\\ \end{array}$
$\log \left(e^{x} + e^{y}\right)$
$\mathsf{log1p}\left(e^{y} + \mathsf{expm1}\left(x\right)\right)$
(FPCore (x y) :precision binary64 (log (+ (exp x) (exp y))))
(FPCore (x y) :precision binary64 (log1p (+ (exp y) (expm1 x))))
double code(double x, double y) {
return log((exp(x) + exp(y)));
}

double code(double x, double y) {
return log1p((exp(y) + expm1(x)));
}

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(y) + Math.expm1(x)));
}

def code(x, y):
return math.log((math.exp(x) + math.exp(y)))

def code(x, y):
return math.log1p((math.exp(y) + math.expm1(x)))

function code(x, y)
return log(Float64(exp(x) + exp(y)))
end

function code(x, y)
return log1p(Float64(exp(y) + expm1(x)))
end

code[x_, y_] := N[Log[N[(N[Exp[x], $MachinePrecision] + N[Exp[y],$MachinePrecision]), $MachinePrecision]],$MachinePrecision]

code[x_, y_] := N[Log[1 + N[(N[Exp[y], $MachinePrecision] + N[(Exp[x] - 1),$MachinePrecision]), $MachinePrecision]],$MachinePrecision]

\log \left(e^{x} + e^{y}\right)

\mathsf{log1p}\left(e^{y} + \mathsf{expm1}\left(x\right)\right)


Try it out?

Results

 In Out
Enter valid numbers for all inputs

Derivation?

1. Initial program 0.0

$\log \left(e^{x} + e^{y}\right)$
2. Taylor expanded in x around inf 0.0

$\leadsto \color{blue}{\log \left(e^{y} + e^{x}\right)}$
3. Simplified0.0

$\leadsto \color{blue}{\mathsf{log1p}\left(e^{y} + \mathsf{expm1}\left(x\right)\right)}$
Proof
[Start]0.0 $\log \left(e^{y} + e^{x}\right)$ $\log \color{blue}{\left(e^{x} + e^{y}\right)}$ $\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log \left(e^{x} + e^{y}\right)\right)\right)}$ $\mathsf{log1p}\left(\color{blue}{e^{\log \left(e^{x} + e^{y}\right)} - 1}\right)$ $\mathsf{log1p}\left(\color{blue}{\left(e^{x} + e^{y}\right)} - 1\right)$ $\mathsf{log1p}\left(\color{blue}{\left(e^{y} + e^{x}\right)} - 1\right)$ $\mathsf{log1p}\left(\color{blue}{e^{y} + \left(e^{x} - 1\right)}\right)$ $\mathsf{log1p}\left(e^{y} + \color{blue}{\mathsf{expm1}\left(x\right)}\right)$
4. Final simplification0.0

$\leadsto \mathsf{log1p}\left(e^{y} + \mathsf{expm1}\left(x\right)\right)$

Alternatives

Alternative 1
Error0.0
Cost19392
$\log \left(e^{y} + e^{x}\right)$
Alternative 2
Error12.5
Cost13760
$\log \left(\frac{1}{1 - x} + \left(e^{y} - \frac{x}{\frac{1 - x}{x}}\right)\right)$
Alternative 3
Error12.5
Cost12992
$\mathsf{log1p}\left(e^{y} + x\right)$
Alternative 4
Error12.6
Cost12864
$\mathsf{log1p}\left(e^{y}\right)$
Alternative 5
Error53.8
Cost6720
$\log \left(x + \left(y + 2\right)\right)$
Alternative 6
Error51.9
Cost6720
$\log 2 + y \cdot 0.5$
Alternative 7
Error53.9
Cost6592
$\log \left(y + 2\right)$
Alternative 8
Error54.6
Cost6464
$\log 2$
Alternative 9
Error54.4
Cost6464
$\log x$

Reproduce?

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