Average Error: 0.5 → 0.5
Time: 17.2s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(y, -x, \left(\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\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)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(y, -x, \left(\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\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)
double f(double x, double y) {
        double r96605 = 1.0;
        double r96606 = x;
        double r96607 = exp(r96606);
        double r96608 = r96605 + r96607;
        double r96609 = log(r96608);
        double r96610 = y;
        double r96611 = r96606 * r96610;
        double r96612 = r96609 - r96611;
        return r96612;
}

double f(double x, double y) {
        double r96613 = y;
        double r96614 = x;
        double r96615 = -r96614;
        double r96616 = 1.0;
        double r96617 = exp(r96614);
        double r96618 = r96617 - r96616;
        double r96619 = r96617 * r96618;
        double r96620 = fma(r96616, r96616, r96619);
        double r96621 = log(r96620);
        double r96622 = r96616 + r96617;
        double r96623 = log(r96622);
        double r96624 = r96621 + r96623;
        double r96625 = r96624 - r96621;
        double r96626 = fma(r96613, r96615, r96625);
        return r96626;
}

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

    \[\leadsto \log 1 + \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)\]
  9. Applied log-div0.5

    \[\leadsto \log 1 + \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)\]
  10. Simplified0.5

    \[\leadsto \log 1 + \mathsf{fma}\left(y, -x, \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)\]
  11. Using strategy rm
  12. Applied sum-cubes0.5

    \[\leadsto \log 1 + \mathsf{fma}\left(y, -x, \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)\]
  13. Applied log-prod0.5

    \[\leadsto \log 1 + \mathsf{fma}\left(y, -x, \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)\]
  14. Simplified0.5

    \[\leadsto \log 1 + \mathsf{fma}\left(y, -x, \left(\color{blue}{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\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)\]
  15. Final simplification0.5

    \[\leadsto \mathsf{fma}\left(y, -x, \left(\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\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)\]

Reproduce

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