Average Error: 0.5 → 0.5
Time: 14.7s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(-y, x, \log \left({\left(e^{x}\right)}^{3} + {1}^{3}\right) - \log \left(\mathsf{fma}\left(e^{x} - 1, e^{x}, 1 \cdot 1\right)\right)\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(-y, x, \log \left({\left(e^{x}\right)}^{3} + {1}^{3}\right) - \log \left(\mathsf{fma}\left(e^{x} - 1, e^{x}, 1 \cdot 1\right)\right)\right)
double f(double x, double y) {
        double r109408 = 1.0;
        double r109409 = x;
        double r109410 = exp(r109409);
        double r109411 = r109408 + r109410;
        double r109412 = log(r109411);
        double r109413 = y;
        double r109414 = r109409 * r109413;
        double r109415 = r109412 - r109414;
        return r109415;
}

double f(double x, double y) {
        double r109416 = y;
        double r109417 = -r109416;
        double r109418 = x;
        double r109419 = exp(r109418);
        double r109420 = 3.0;
        double r109421 = pow(r109419, r109420);
        double r109422 = 1.0;
        double r109423 = pow(r109422, r109420);
        double r109424 = r109421 + r109423;
        double r109425 = log(r109424);
        double r109426 = r109419 - r109422;
        double r109427 = r109422 * r109422;
        double r109428 = fma(r109426, r109419, r109427);
        double r109429 = log(r109428);
        double r109430 = r109425 - r109429;
        double r109431 = fma(r109417, r109418, r109430);
        return r109431;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.5
Target0.0
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. Simplified0.4

    \[\leadsto \color{blue}{\mathsf{fma}\left(-y, x, \log \left(1 + e^{x}\right)\right)}\]
  3. Using strategy rm
  4. Applied flip3-+0.5

    \[\leadsto \mathsf{fma}\left(-y, x, \log \color{blue}{\left(\frac{{1}^{3} + {\left(e^{x}\right)}^{3}}{1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)}\right)}\right)\]
  5. Applied log-div0.5

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

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

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

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

Reproduce

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

  :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)))