Average Error: 0.5 → 0.5
Time: 21.5s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\left(\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right) + \left(\log \left(1 + e^{x}\right) - \log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)\right)\right) - x \cdot y\]
\log \left(1 + e^{x}\right) - x \cdot y
\left(\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right) + \left(\log \left(1 + e^{x}\right) - \log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)\right)\right) - x \cdot y
double f(double x, double y) {
        double r109416 = 1.0;
        double r109417 = x;
        double r109418 = exp(r109417);
        double r109419 = r109416 + r109418;
        double r109420 = log(r109419);
        double r109421 = y;
        double r109422 = r109417 * r109421;
        double r109423 = r109420 - r109422;
        return r109423;
}

double f(double x, double y) {
        double r109424 = 1.0;
        double r109425 = r109424 * r109424;
        double r109426 = x;
        double r109427 = exp(r109426);
        double r109428 = r109427 * r109427;
        double r109429 = r109424 * r109427;
        double r109430 = r109428 - r109429;
        double r109431 = r109425 + r109430;
        double r109432 = log(r109431);
        double r109433 = r109424 + r109427;
        double r109434 = log(r109433);
        double r109435 = r109427 - r109424;
        double r109436 = r109427 * r109435;
        double r109437 = fma(r109424, r109424, r109436);
        double r109438 = log(r109437);
        double r109439 = r109434 - r109438;
        double r109440 = r109432 + r109439;
        double r109441 = y;
        double r109442 = r109426 * r109441;
        double r109443 = r109440 - r109442;
        return r109443;
}

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. Using strategy rm
  3. Applied flip3-+0.5

    \[\leadsto \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)} - x \cdot y\]
  4. Applied log-div0.5

    \[\leadsto \color{blue}{\left(\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)} - x \cdot y\]
  5. Simplified0.5

    \[\leadsto \left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \color{blue}{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) - x \cdot y\]
  6. Using strategy rm
  7. Applied sum-cubes0.5

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

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

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

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

Reproduce

herbie shell --seed 2019326 +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)))