Average Error: 0.6 → 0.6
Time: 14.8s
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 r83058 = 1.0;
        double r83059 = x;
        double r83060 = exp(r83059);
        double r83061 = r83058 + r83060;
        double r83062 = log(r83061);
        double r83063 = y;
        double r83064 = r83059 * r83063;
        double r83065 = r83062 - r83064;
        return r83065;
}

double f(double x, double y) {
        double r83066 = y;
        double r83067 = x;
        double r83068 = -r83067;
        double r83069 = exp(r83067);
        double r83070 = 1.0;
        double r83071 = r83069 + r83070;
        double r83072 = log(r83071);
        double r83073 = 3.0;
        double r83074 = pow(r83072, r83073);
        double r83075 = cbrt(r83074);
        double r83076 = fma(r83066, r83068, r83075);
        return r83076;
}

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, -x, \log \left(1 + e^{x}\right)\right)}\]
  4. Using strategy rm
  5. 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)\]
  6. Simplified0.6

    \[\leadsto \mathsf{fma}\left(y, -x, \sqrt[3]{\color{blue}{{\left(\log \left(e^{x} + 1\right)\right)}^{3}}}\right)\]
  7. 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)))