Average Error: 0.5 → 0.6
Time: 4.5s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\log \left(\frac{{1}^{3} + {\left(e^{x}\right)}^{3}}{\mathsf{fma}\left(e^{x}, e^{x} - 1, 1 \cdot 1\right)}\right) - x \cdot y\]
\log \left(1 + e^{x}\right) - x \cdot y
\log \left(\frac{{1}^{3} + {\left(e^{x}\right)}^{3}}{\mathsf{fma}\left(e^{x}, e^{x} - 1, 1 \cdot 1\right)}\right) - x \cdot y
double f(double x, double y) {
        double r140698 = 1.0;
        double r140699 = x;
        double r140700 = exp(r140699);
        double r140701 = r140698 + r140700;
        double r140702 = log(r140701);
        double r140703 = y;
        double r140704 = r140699 * r140703;
        double r140705 = r140702 - r140704;
        return r140705;
}

double f(double x, double y) {
        double r140706 = 1.0;
        double r140707 = 3.0;
        double r140708 = pow(r140706, r140707);
        double r140709 = x;
        double r140710 = exp(r140709);
        double r140711 = pow(r140710, r140707);
        double r140712 = r140708 + r140711;
        double r140713 = r140710 - r140706;
        double r140714 = r140706 * r140706;
        double r140715 = fma(r140710, r140713, r140714);
        double r140716 = r140712 / r140715;
        double r140717 = log(r140716);
        double r140718 = y;
        double r140719 = r140709 * r140718;
        double r140720 = r140717 - r140719;
        return r140720;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.5
Target0.1
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. Simplified0.6

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

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

Reproduce

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