Average Error: 0.6 → 0.6
Time: 15.7s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(y, -x, \sqrt[3]{{\left(\log \left(e^{x} + 1\right)\right)}^{3}}\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(y, -x, \sqrt[3]{{\left(\log \left(e^{x} + 1\right)\right)}^{3}}\right)
double f(double x, double y) {
        double r111781 = 1.0;
        double r111782 = x;
        double r111783 = exp(r111782);
        double r111784 = r111781 + r111783;
        double r111785 = log(r111784);
        double r111786 = y;
        double r111787 = r111782 * r111786;
        double r111788 = r111785 - r111787;
        return r111788;
}

double f(double x, double y) {
        double r111789 = y;
        double r111790 = x;
        double r111791 = -r111790;
        double r111792 = exp(r111790);
        double r111793 = 1.0;
        double r111794 = r111792 + r111793;
        double r111795 = log(r111794);
        double r111796 = 3.0;
        double r111797 = pow(r111795, r111796);
        double r111798 = cbrt(r111797);
        double r111799 = fma(r111789, r111791, r111798);
        return r111799;
}

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. Using strategy rm
  9. Applied add-cbrt-cube0.6

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

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

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

Reproduce

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