Average Error: 0.5 → 0.5
Time: 15.6s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(y, -x, \log \left(1 + e^{x}\right)\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(y, -x, \log \left(1 + e^{x}\right)\right)
double f(double x, double y) {
        double r88365 = 1.0;
        double r88366 = x;
        double r88367 = exp(r88366);
        double r88368 = r88365 + r88367;
        double r88369 = log(r88368);
        double r88370 = y;
        double r88371 = r88366 * r88370;
        double r88372 = r88369 - r88371;
        return r88372;
}

double f(double x, double y) {
        double r88373 = y;
        double r88374 = x;
        double r88375 = -r88374;
        double r88376 = 1.0;
        double r88377 = exp(r88374);
        double r88378 = r88376 + r88377;
        double r88379 = log(r88378);
        double r88380 = fma(r88373, r88375, r88379);
        return r88380;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.5
Target0.1
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;x \le 0.0:\\ \;\;\;\;\log \left(1 + e^{x}\right) - x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\log \left(1 + e^{-x}\right) - \left(-x\right) \cdot \left(1 - y\right)\\ \end{array}\]

Derivation

  1. Initial program 0.5

    \[\log \left(1 + e^{x}\right) - x \cdot y\]
  2. Using strategy rm
  3. Applied *-un-lft-identity0.5

    \[\leadsto \log \color{blue}{\left(1 \cdot \left(1 + e^{x}\right)\right)} - x \cdot y\]
  4. Applied log-prod0.5

    \[\leadsto \color{blue}{\left(\log 1 + \log \left(1 + e^{x}\right)\right)} - x \cdot y\]
  5. Applied associate--l+0.5

    \[\leadsto \color{blue}{\log 1 + \left(\log \left(1 + e^{x}\right) - x \cdot y\right)}\]
  6. Simplified0.5

    \[\leadsto \log 1 + \color{blue}{\mathsf{fma}\left(y, -x, \log \left(1 + e^{x}\right)\right)}\]
  7. Final simplification0.5

    \[\leadsto \mathsf{fma}\left(y, -x, \log \left(1 + e^{x}\right)\right)\]

Reproduce

herbie shell --seed 2019323 +o rules:numerics
(FPCore (x y)
  :name "Logistic regression 2"
  :precision binary64

  :herbie-target
  (if (<= x 0.0) (- (log (+ 1 (exp x))) (* x y)) (- (log (+ 1 (exp (- x)))) (* (- x) (- 1 y))))

  (- (log (+ 1 (exp x))) (* x y)))