Average Error: 0.5 → 0.5
Time: 8.3s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \left(\sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)} \cdot \sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right)}\right) \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) - x \cdot y\]
\log \left(1 + e^{x}\right) - x \cdot y
\left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \left(\sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)} \cdot \sqrt[3]{\log \left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right) + \log \left(\sqrt{\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)}\right)}\right) \cdot \sqrt[3]{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right) - x \cdot y
double f(double x, double y) {
        double r153182 = 1.0;
        double r153183 = x;
        double r153184 = exp(r153183);
        double r153185 = r153182 + r153184;
        double r153186 = log(r153185);
        double r153187 = y;
        double r153188 = r153183 * r153187;
        double r153189 = r153186 - r153188;
        return r153189;
}

double f(double x, double y) {
        double r153190 = 1.0;
        double r153191 = 3.0;
        double r153192 = pow(r153190, r153191);
        double r153193 = x;
        double r153194 = exp(r153193);
        double r153195 = pow(r153194, r153191);
        double r153196 = r153192 + r153195;
        double r153197 = log(r153196);
        double r153198 = r153194 - r153190;
        double r153199 = r153194 * r153198;
        double r153200 = fma(r153190, r153190, r153199);
        double r153201 = log(r153200);
        double r153202 = cbrt(r153201);
        double r153203 = sqrt(r153200);
        double r153204 = log(r153203);
        double r153205 = r153204 + r153204;
        double r153206 = cbrt(r153205);
        double r153207 = r153202 * r153206;
        double r153208 = r153207 * r153202;
        double r153209 = r153197 - r153208;
        double r153210 = y;
        double r153211 = r153193 * r153210;
        double r153212 = r153209 - r153211;
        return r153212;
}

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 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. Simplified0.5

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

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

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

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

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

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