Average Error: 0.6 → 0.6
Time: 16.8s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(-y, x, \log \left(1 + e^{x}\right)\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(-y, x, \log \left(1 + e^{x}\right)\right)
double f(double x, double y) {
        double r81524 = 1.0;
        double r81525 = x;
        double r81526 = exp(r81525);
        double r81527 = r81524 + r81526;
        double r81528 = log(r81527);
        double r81529 = y;
        double r81530 = r81525 * r81529;
        double r81531 = r81528 - r81530;
        return r81531;
}

double f(double x, double y) {
        double r81532 = y;
        double r81533 = -r81532;
        double r81534 = x;
        double r81535 = 1.0;
        double r81536 = exp(r81534);
        double r81537 = r81535 + r81536;
        double r81538 = log(r81537);
        double r81539 = fma(r81533, r81534, r81538);
        return r81539;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.6
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.6

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

    \[\leadsto \log \color{blue}{\left({\left(1 + e^{x}\right)}^{1}\right)} - x \cdot y\]
  4. Applied log-pow0.6

    \[\leadsto \color{blue}{1 \cdot \log \left(1 + e^{x}\right)} - x \cdot y\]
  5. Applied prod-diff0.6

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

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

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

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

Reproduce

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