Average Error: 0.5 → 0.5
Time: 17.0s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(\sqrt{\log \left(\sqrt{1 + e^{x}}\right)}, \sqrt{\log \left(\sqrt{1 + e^{x}}\right)} + \sqrt{\log \left(\sqrt{1 + e^{x}}\right)}, -x \cdot y\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(\sqrt{\log \left(\sqrt{1 + e^{x}}\right)}, \sqrt{\log \left(\sqrt{1 + e^{x}}\right)} + \sqrt{\log \left(\sqrt{1 + e^{x}}\right)}, -x \cdot y\right)
double f(double x, double y) {
        double r7109538 = 1.0;
        double r7109539 = x;
        double r7109540 = exp(r7109539);
        double r7109541 = r7109538 + r7109540;
        double r7109542 = log(r7109541);
        double r7109543 = y;
        double r7109544 = r7109539 * r7109543;
        double r7109545 = r7109542 - r7109544;
        return r7109545;
}

double f(double x, double y) {
        double r7109546 = 1.0;
        double r7109547 = x;
        double r7109548 = exp(r7109547);
        double r7109549 = r7109546 + r7109548;
        double r7109550 = sqrt(r7109549);
        double r7109551 = log(r7109550);
        double r7109552 = sqrt(r7109551);
        double r7109553 = r7109552 + r7109552;
        double r7109554 = y;
        double r7109555 = r7109547 * r7109554;
        double r7109556 = -r7109555;
        double r7109557 = fma(r7109552, r7109553, r7109556);
        return r7109557;
}

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 add-sqr-sqrt1.3

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

    \[\leadsto \color{blue}{\left(\log \left(\sqrt{1 + e^{x}}\right) + \log \left(\sqrt{1 + e^{x}}\right)\right)} - x \cdot y\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt1.0

    \[\leadsto \left(\log \left(\sqrt{1 + e^{x}}\right) + \color{blue}{\sqrt{\log \left(\sqrt{1 + e^{x}}\right)} \cdot \sqrt{\log \left(\sqrt{1 + e^{x}}\right)}}\right) - x \cdot y\]
  7. Applied add-sqr-sqrt0.5

    \[\leadsto \left(\color{blue}{\sqrt{\log \left(\sqrt{1 + e^{x}}\right)} \cdot \sqrt{\log \left(\sqrt{1 + e^{x}}\right)}} + \sqrt{\log \left(\sqrt{1 + e^{x}}\right)} \cdot \sqrt{\log \left(\sqrt{1 + e^{x}}\right)}\right) - x \cdot y\]
  8. Applied distribute-lft-out0.5

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

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

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

Reproduce

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