Average Error: 0.5 → 0.6
Time: 18.5s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[e^{\mathsf{fma}\left(\frac{x \cdot x}{\log 2}, 0.125 - \frac{0.125}{\log 2}, \mathsf{fma}\left(\frac{x}{\log 2}, 0.5, \log \left(\log 2\right)\right)\right)} - x \cdot y\]
\log \left(1 + e^{x}\right) - x \cdot y
e^{\mathsf{fma}\left(\frac{x \cdot x}{\log 2}, 0.125 - \frac{0.125}{\log 2}, \mathsf{fma}\left(\frac{x}{\log 2}, 0.5, \log \left(\log 2\right)\right)\right)} - x \cdot y
double f(double x, double y) {
        double r6600316 = 1.0;
        double r6600317 = x;
        double r6600318 = exp(r6600317);
        double r6600319 = r6600316 + r6600318;
        double r6600320 = log(r6600319);
        double r6600321 = y;
        double r6600322 = r6600317 * r6600321;
        double r6600323 = r6600320 - r6600322;
        return r6600323;
}

double f(double x, double y) {
        double r6600324 = x;
        double r6600325 = r6600324 * r6600324;
        double r6600326 = 2.0;
        double r6600327 = log(r6600326);
        double r6600328 = r6600325 / r6600327;
        double r6600329 = 0.125;
        double r6600330 = r6600329 / r6600327;
        double r6600331 = r6600329 - r6600330;
        double r6600332 = r6600324 / r6600327;
        double r6600333 = 0.5;
        double r6600334 = log(r6600327);
        double r6600335 = fma(r6600332, r6600333, r6600334);
        double r6600336 = fma(r6600328, r6600331, r6600335);
        double r6600337 = exp(r6600336);
        double r6600338 = y;
        double r6600339 = r6600324 * r6600338;
        double r6600340 = r6600337 - r6600339;
        return r6600340;
}

Error

Bits error versus x

Bits error versus y

Target

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

    \[\log \left(1 + e^{x}\right) - x \cdot y\]
  2. Taylor expanded around 0 14.7

    \[\leadsto \color{blue}{\left(\left(0.5 \cdot x + \left(0.25 \cdot {x}^{2} + \log 2\right)\right) - \frac{1}{2} \cdot \frac{{x}^{2}}{{2}^{2}}\right)} - x \cdot y\]
  3. Simplified14.7

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, \mathsf{fma}\left(0.25, x, 0.5\right), \mathsf{fma}\left(\frac{-1}{2}, \frac{x}{2} \cdot \frac{x}{2}, \log 2\right)\right)} - x \cdot y\]
  4. Using strategy rm
  5. Applied add-exp-log14.7

    \[\leadsto \color{blue}{e^{\log \left(\mathsf{fma}\left(x, \mathsf{fma}\left(0.25, x, 0.5\right), \mathsf{fma}\left(\frac{-1}{2}, \frac{x}{2} \cdot \frac{x}{2}, \log 2\right)\right)\right)}} - x \cdot y\]
  6. Taylor expanded around 0 7.8

    \[\leadsto e^{\color{blue}{\left(0.125 \cdot \frac{{x}^{2}}{\log 2} + \left(\log \left(\log 2\right) + 0.5 \cdot \frac{x}{\log 2}\right)\right) - 0.125 \cdot \frac{{x}^{2}}{{\left(\log 2\right)}^{2}}}} - x \cdot y\]
  7. Simplified0.6

    \[\leadsto e^{\color{blue}{\mathsf{fma}\left(\frac{x \cdot x}{\log 2}, 0.125 - \frac{0.125}{\log 2}, \mathsf{fma}\left(\frac{x}{\log 2}, 0.5, \log \left(\log 2\right)\right)\right)}} - x \cdot y\]
  8. Final simplification0.6

    \[\leadsto e^{\mathsf{fma}\left(\frac{x \cdot x}{\log 2}, 0.125 - \frac{0.125}{\log 2}, \mathsf{fma}\left(\frac{x}{\log 2}, 0.5, \log \left(\log 2\right)\right)\right)} - x \cdot y\]

Reproduce

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