Average Error: 0.6 → 0.7
Time: 7.3s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \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
\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \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 r58629 = 1.0;
        double r58630 = x;
        double r58631 = exp(r58630);
        double r58632 = r58629 + r58631;
        double r58633 = log(r58632);
        double r58634 = y;
        double r58635 = r58630 * r58634;
        double r58636 = r58633 - r58635;
        return r58636;
}

double f(double x, double y) {
        double r58637 = 1.0;
        double r58638 = 3.0;
        double r58639 = pow(r58637, r58638);
        double r58640 = x;
        double r58641 = exp(r58640);
        double r58642 = pow(r58641, r58638);
        double r58643 = r58639 + r58642;
        double r58644 = log(r58643);
        double r58645 = y;
        double r58646 = r58641 - r58637;
        double r58647 = r58641 * r58646;
        double r58648 = fma(r58637, r58637, r58647);
        double r58649 = log(r58648);
        double r58650 = fma(r58640, r58645, r58649);
        double r58651 = r58644 - r58650;
        return r58651;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.6
Target0.1
Herbie0.7
\[\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.6

    \[\log \left(1 + e^{x}\right) - x \cdot y\]
  2. Using strategy rm
  3. Applied flip3-+0.7

    \[\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.7

    \[\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. Applied associate--l-0.7

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

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

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

Reproduce

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