Average Error: 0.5 → 0.6
Time: 5.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(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\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(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)\right)
double f(double x, double y) {
        double r174495 = 1.0;
        double r174496 = x;
        double r174497 = exp(r174496);
        double r174498 = r174495 + r174497;
        double r174499 = log(r174498);
        double r174500 = y;
        double r174501 = r174496 * r174500;
        double r174502 = r174499 - r174501;
        return r174502;
}

double f(double x, double y) {
        double r174503 = 1.0;
        double r174504 = 3.0;
        double r174505 = pow(r174503, r174504);
        double r174506 = x;
        double r174507 = exp(r174506);
        double r174508 = pow(r174507, r174504);
        double r174509 = r174505 + r174508;
        double r174510 = log(r174509);
        double r174511 = y;
        double r174512 = r174503 * r174503;
        double r174513 = r174507 * r174507;
        double r174514 = r174503 * r174507;
        double r174515 = r174513 - r174514;
        double r174516 = r174512 + r174515;
        double r174517 = log(r174516);
        double r174518 = fma(r174506, r174511, r174517);
        double r174519 = r174510 - r174518;
        return r174519;
}

Error

Bits error versus x

Bits error versus y

Target

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

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

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

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

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

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

Reproduce

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