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(\frac{{\left(e^{x}\right)}^{3} + {1}^{3}}{\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(\frac{{\left(e^{x}\right)}^{3} + {1}^{3}}{\mathsf{fma}\left(e^{x} - 1, e^{x}, 1 \cdot 1\right)}\right)\right)
double f(double x, double y) {
        double r109141 = 1.0;
        double r109142 = x;
        double r109143 = exp(r109142);
        double r109144 = r109141 + r109143;
        double r109145 = log(r109144);
        double r109146 = y;
        double r109147 = r109142 * r109146;
        double r109148 = r109145 - r109147;
        return r109148;
}

double f(double x, double y) {
        double r109149 = y;
        double r109150 = -r109149;
        double r109151 = x;
        double r109152 = exp(r109151);
        double r109153 = 3.0;
        double r109154 = pow(r109152, r109153);
        double r109155 = 1.0;
        double r109156 = pow(r109155, r109153);
        double r109157 = r109154 + r109156;
        double r109158 = r109152 - r109155;
        double r109159 = r109155 * r109155;
        double r109160 = fma(r109158, r109152, r109159);
        double r109161 = r109157 / r109160;
        double r109162 = log(r109161);
        double r109163 = fma(r109150, r109151, r109162);
        return r109163;
}

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. Simplified0.5

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

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