Average Error: 0.5 → 0.5
Time: 15.6s
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 r117726 = 1.0;
        double r117727 = x;
        double r117728 = exp(r117727);
        double r117729 = r117726 + r117728;
        double r117730 = log(r117729);
        double r117731 = y;
        double r117732 = r117727 * r117731;
        double r117733 = r117730 - r117732;
        return r117733;
}

double f(double x, double y) {
        double r117734 = y;
        double r117735 = x;
        double r117736 = -r117735;
        double r117737 = 1.0;
        double r117738 = exp(r117735);
        double r117739 = r117737 + r117738;
        double r117740 = log(r117739);
        double r117741 = fma(r117734, r117736, r117740);
        return r117741;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.5
Target0.1
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. Using strategy rm
  3. Applied *-un-lft-identity0.5

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

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

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

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

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

Reproduce

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