Average Error: 0.4 → 0.5
Time: 13.3s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \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) - \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 r119192 = 1.0;
        double r119193 = x;
        double r119194 = exp(r119193);
        double r119195 = r119192 + r119194;
        double r119196 = log(r119195);
        double r119197 = y;
        double r119198 = r119193 * r119197;
        double r119199 = r119196 - r119198;
        return r119199;
}

double f(double x, double y) {
        double r119200 = 1.0;
        double r119201 = 3.0;
        double r119202 = pow(r119200, r119201);
        double r119203 = x;
        double r119204 = exp(r119203);
        double r119205 = pow(r119204, r119201);
        double r119206 = r119202 + r119205;
        double r119207 = log(r119206);
        double r119208 = r119204 - r119200;
        double r119209 = r119204 * r119208;
        double r119210 = fma(r119200, r119200, r119209);
        double r119211 = log(r119210);
        double r119212 = r119207 - r119211;
        double r119213 = y;
        double r119214 = r119203 * r119213;
        double r119215 = r119212 - r119214;
        return r119215;
}

Error

Bits error versus x

Bits error versus y

Target

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

    \[\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. Final simplification0.5

    \[\leadsto \left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \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 2019208 +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)))