Average Error: 0.5 → 0.5
Time: 6.0s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \log \left(\sqrt{1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)}\right) + \log \left(\sqrt{1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)}\right)\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \log \left(\sqrt{1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)}\right) + \log \left(\sqrt{1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)}\right)\right)
double f(double x, double y) {
        double r171633 = 1.0;
        double r171634 = x;
        double r171635 = exp(r171634);
        double r171636 = r171633 + r171635;
        double r171637 = log(r171636);
        double r171638 = y;
        double r171639 = r171634 * r171638;
        double r171640 = r171637 - r171639;
        return r171640;
}

double f(double x, double y) {
        double r171641 = 1.0;
        double r171642 = 3.0;
        double r171643 = pow(r171641, r171642);
        double r171644 = x;
        double r171645 = exp(r171644);
        double r171646 = pow(r171645, r171642);
        double r171647 = r171643 + r171646;
        double r171648 = log(r171647);
        double r171649 = y;
        double r171650 = r171641 * r171641;
        double r171651 = r171645 * r171645;
        double r171652 = r171641 * r171645;
        double r171653 = r171651 - r171652;
        double r171654 = r171650 + r171653;
        double r171655 = sqrt(r171654);
        double r171656 = log(r171655);
        double r171657 = r171656 + r171656;
        double r171658 = fma(r171644, r171649, r171657);
        double r171659 = r171648 - r171658;
        return r171659;
}

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. 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. Applied associate--l-0.5

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

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

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

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

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

Reproduce

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