Average Error: 0.5 → 0.5
Time: 9.4s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \left(\sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right)} \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) - x \cdot y\]
\log \left(1 + e^{x}\right) - x \cdot y
\left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \left(\sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right)} \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) - x \cdot y
double f(double x, double y) {
        double r131618 = 1.0;
        double r131619 = x;
        double r131620 = exp(r131619);
        double r131621 = r131618 + r131620;
        double r131622 = log(r131621);
        double r131623 = y;
        double r131624 = r131619 * r131623;
        double r131625 = r131622 - r131624;
        return r131625;
}

double f(double x, double y) {
        double r131626 = 1.0;
        double r131627 = 3.0;
        double r131628 = pow(r131626, r131627);
        double r131629 = x;
        double r131630 = exp(r131629);
        double r131631 = pow(r131630, r131627);
        double r131632 = r131628 + r131631;
        double r131633 = log(r131632);
        double r131634 = r131630 - r131626;
        double r131635 = r131630 * r131634;
        double r131636 = fma(r131626, r131626, r131635);
        double r131637 = sqrt(r131636);
        double r131638 = log(r131637);
        double r131639 = r131638 + r131638;
        double r131640 = cbrt(r131639);
        double r131641 = log(r131636);
        double r131642 = cbrt(r131641);
        double r131643 = r131640 * r131642;
        double r131644 = r131643 * r131642;
        double r131645 = r131633 - r131644;
        double r131646 = y;
        double r131647 = r131629 * r131646;
        double r131648 = r131645 - r131647;
        return r131648;
}

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 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. Applied log-div0.5

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

    \[\leadsto \left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \color{blue}{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) - x \cdot y\]
  6. Using strategy rm
  7. Applied add-cube-cbrt0.5

    \[\leadsto \left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \color{blue}{\left(\sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)} \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}}\right) - x \cdot y\]
  8. Using strategy rm
  9. Applied add-sqr-sqrt0.5

    \[\leadsto \left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \left(\sqrt[3]{\log \color{blue}{\left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)} \cdot \sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right)}} \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) - x \cdot y\]
  10. Applied log-prod0.5

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

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

Reproduce

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