Average Error: 0.5 → 0.5
Time: 9.6s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(-x, y, \sqrt[3]{{\left(\log \left(e^{x} + 1\right)\right)}^{3}}\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(-x, y, \sqrt[3]{{\left(\log \left(e^{x} + 1\right)\right)}^{3}}\right)
double f(double x, double y) {
        double r204209 = 1.0;
        double r204210 = x;
        double r204211 = exp(r204210);
        double r204212 = r204209 + r204211;
        double r204213 = log(r204212);
        double r204214 = y;
        double r204215 = r204210 * r204214;
        double r204216 = r204213 - r204215;
        return r204216;
}

double f(double x, double y) {
        double r204217 = x;
        double r204218 = -r204217;
        double r204219 = y;
        double r204220 = exp(r204217);
        double r204221 = 1.0;
        double r204222 = r204220 + r204221;
        double r204223 = log(r204222);
        double r204224 = 3.0;
        double r204225 = pow(r204223, r204224);
        double r204226 = cbrt(r204225);
        double r204227 = fma(r204218, r204219, r204226);
        return r204227;
}

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. Taylor expanded around inf 0.5

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(-x, y, \log \left(e^{x} + 1\right)\right)}\]
  4. Using strategy rm
  5. Applied add-cbrt-cube0.5

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

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

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

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)))