Average Error: 0.5 → 0.5
Time: 18.9s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\log \left(\frac{\mathsf{fma}\left(1, 1 \cdot 1, e^{\mathsf{fma}\left(2, x, x\right)}\right)}{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right) - x \cdot y\]
\log \left(1 + e^{x}\right) - x \cdot y
\log \left(\frac{\mathsf{fma}\left(1, 1 \cdot 1, e^{\mathsf{fma}\left(2, x, x\right)}\right)}{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right) - x \cdot y
double f(double x, double y) {
        double r5987693 = 1.0;
        double r5987694 = x;
        double r5987695 = exp(r5987694);
        double r5987696 = r5987693 + r5987695;
        double r5987697 = log(r5987696);
        double r5987698 = y;
        double r5987699 = r5987694 * r5987698;
        double r5987700 = r5987697 - r5987699;
        return r5987700;
}

double f(double x, double y) {
        double r5987701 = 1.0;
        double r5987702 = r5987701 * r5987701;
        double r5987703 = 2.0;
        double r5987704 = x;
        double r5987705 = fma(r5987703, r5987704, r5987704);
        double r5987706 = exp(r5987705);
        double r5987707 = fma(r5987701, r5987702, r5987706);
        double r5987708 = exp(r5987704);
        double r5987709 = r5987708 - r5987701;
        double r5987710 = r5987708 * r5987709;
        double r5987711 = fma(r5987701, r5987701, r5987710);
        double r5987712 = r5987707 / r5987711;
        double r5987713 = log(r5987712);
        double r5987714 = y;
        double r5987715 = r5987704 * r5987714;
        double r5987716 = r5987713 - r5987715;
        return r5987716;
}

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. Using strategy rm
  3. Applied flip3-+0.5

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

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

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

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

Reproduce

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