Alternative 1 | |
---|---|
Error | 1.0 |
Cost | 19524 |
\[\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}
\]
(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}
Results
Initial program 30.0
Taylor expanded in y around 0 1.1
Simplified1.0
[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}}
\] |
Final simplification1.0
Alternative 1 | |
---|---|
Error | 1.0 |
Cost | 19524 |
Alternative 2 | |
---|---|
Error | 1.4 |
Cost | 19396 |
Alternative 3 | |
---|---|
Error | 1.5 |
Cost | 13764 |
Alternative 4 | |
---|---|
Error | 1.9 |
Cost | 13252 |
Alternative 5 | |
---|---|
Error | 32.6 |
Cost | 6720 |
Alternative 6 | |
---|---|
Error | 32.8 |
Cost | 6592 |
Alternative 7 | |
---|---|
Error | 33.1 |
Cost | 6464 |
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))))