| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13120 |
\[\mathsf{log1p}\left(e^{x}\right) - y \cdot x
\]
(FPCore (x y) :precision binary64 (- (log (+ 1.0 (exp x))) (* x y)))
(FPCore (x y) :precision binary64 (fma (- y) x (log1p (exp x))))
double code(double x, double y) {
return log((1.0 + exp(x))) - (x * y);
}
double code(double x, double y) {
return fma(-y, x, log1p(exp(x)));
}
function code(x, y) return Float64(log(Float64(1.0 + exp(x))) - Float64(x * y)) end
function code(x, y) return fma(Float64(-y), x, log1p(exp(x))) end
code[x_, y_] := N[(N[Log[N[(1.0 + N[Exp[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := N[((-y) * x + N[Log[1 + N[Exp[x], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(-y, x, \mathsf{log1p}\left(e^{x}\right)\right)
| Original | 0.6 |
|---|---|
| Target | 0.1 |
| Herbie | 0.5 |
Initial program 0.6
Simplified0.5
[Start]0.6 | \[ \log \left(1 + e^{x}\right) - x \cdot y
\] |
|---|---|
log1p-def [=>]0.5 | \[ \color{blue}{\mathsf{log1p}\left(e^{x}\right)} - x \cdot y
\] |
Applied egg-rr13.3
Applied egg-rr0.5
Taylor expanded in x around inf 0.6
Simplified0.5
[Start]0.6 | \[ \left(-2 \cdot y + y\right) \cdot x + \log \left(1 + e^{x}\right)
\] |
|---|---|
distribute-lft1-in [=>]0.6 | \[ \color{blue}{\left(\left(-2 + 1\right) \cdot y\right)} \cdot x + \log \left(1 + e^{x}\right)
\] |
metadata-eval [=>]0.6 | \[ \left(\color{blue}{-1} \cdot y\right) \cdot x + \log \left(1 + e^{x}\right)
\] |
log1p-def [=>]0.5 | \[ \left(-1 \cdot y\right) \cdot x + \color{blue}{\mathsf{log1p}\left(e^{x}\right)}
\] |
fma-def [=>]0.5 | \[ \color{blue}{\mathsf{fma}\left(-1 \cdot y, x, \mathsf{log1p}\left(e^{x}\right)\right)}
\] |
mul-1-neg [=>]0.5 | \[ \mathsf{fma}\left(\color{blue}{-y}, x, \mathsf{log1p}\left(e^{x}\right)\right)
\] |
Final simplification0.5
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 13120 |
| Alternative 2 | |
|---|---|
| Error | 12.2 |
| Cost | 6984 |
| Alternative 3 | |
|---|---|
| Error | 0.8 |
| Cost | 6980 |
| Alternative 4 | |
|---|---|
| Error | 1.0 |
| Cost | 6852 |
| Alternative 5 | |
|---|---|
| Error | 12.1 |
| Cost | 6728 |
| Alternative 6 | |
|---|---|
| Error | 33.8 |
| Cost | 256 |
| Alternative 7 | |
|---|---|
| Error | 61.7 |
| Cost | 192 |
herbie shell --seed 2023039
(FPCore (x y)
:name "Logistic regression 2"
:precision binary64
:herbie-target
(if (<= x 0.0) (- (log (+ 1.0 (exp x))) (* x y)) (- (log (+ 1.0 (exp (- x)))) (* (- x) (- 1.0 y))))
(- (log (+ 1.0 (exp x))) (* x y)))