\log \left(1 + e^{x}\right) - x \cdot y\begin{array}{l}
\mathbf{if}\;x \leq -797629278.9357958:\\
\;\;\;\;-x \cdot y\\
\mathbf{else}:\\
\;\;\;\;\log 2 + x \cdot \left(\left(0.5 + x \cdot 0.125\right) - y\right)\\
\end{array}(FPCore (x y) :precision binary64 (- (log (+ 1.0 (exp x))) (* x y)))
(FPCore (x y) :precision binary64 (if (<= x -797629278.9357958) (- (* x y)) (+ (log 2.0) (* x (- (+ 0.5 (* x 0.125)) y)))))
double code(double x, double y) {
return log(1.0 + exp(x)) - (x * y);
}
double code(double x, double y) {
double tmp;
if (x <= -797629278.9357958) {
tmp = -(x * y);
} else {
tmp = log(2.0) + (x * ((0.5 + (x * 0.125)) - y));
}
return tmp;
}











Bits error versus x











Bits error versus y
Results
| Original | 0.5 |
|---|---|
| Target | 0.1 |
| Herbie | 0.7 |
| Alternative 1 | |
|---|---|
| Error | 0.5 |
| Cost | 26112 |
| Alternative 2 | |
|---|---|
| Error | 0.5 |
| Cost | 13248 |
| Alternative 3 | |
|---|---|
| Error | 0.8 |
| Cost | 7169 |
| Alternative 4 | |
|---|---|
| Error | 1.1 |
| Cost | 7041 |
| Alternative 5 | |
|---|---|
| Error | 12.7 |
| Cost | 6785 |
| Alternative 6 | |
|---|---|
| Error | 32.9 |
| Cost | 584 |
| Alternative 7 | |
|---|---|
| Error | 56.0 |
| Cost | 64 |

if x < -797629278.93579578Initial program 0
Taylor expanded around inf 0
Simplified0
Simplified0
if -797629278.93579578 < x Initial program 0.6
Taylor expanded around 0 1.0
Simplified1.0
Simplified1.0
Final simplification0.7
herbie shell --seed 2021044
(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)))