Average Error: 0.5 → 0.6
Time: 4.5s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\log \left(\frac{{1}^{3} + {\left(e^{x}\right)}^{3}}{\mathsf{fma}\left(e^{x}, e^{x} - 1, 1 \cdot 1\right)}\right) - x \cdot y\]
\log \left(1 + e^{x}\right) - x \cdot y
\log \left(\frac{{1}^{3} + {\left(e^{x}\right)}^{3}}{\mathsf{fma}\left(e^{x}, e^{x} - 1, 1 \cdot 1\right)}\right) - x \cdot y
double f(double x, double y) {
        double r123229 = 1.0;
        double r123230 = x;
        double r123231 = exp(r123230);
        double r123232 = r123229 + r123231;
        double r123233 = log(r123232);
        double r123234 = y;
        double r123235 = r123230 * r123234;
        double r123236 = r123233 - r123235;
        return r123236;
}

double f(double x, double y) {
        double r123237 = 1.0;
        double r123238 = 3.0;
        double r123239 = pow(r123237, r123238);
        double r123240 = x;
        double r123241 = exp(r123240);
        double r123242 = pow(r123241, r123238);
        double r123243 = r123239 + r123242;
        double r123244 = r123241 - r123237;
        double r123245 = r123237 * r123237;
        double r123246 = fma(r123241, r123244, r123245);
        double r123247 = r123243 / r123246;
        double r123248 = log(r123247);
        double r123249 = y;
        double r123250 = r123240 * r123249;
        double r123251 = r123248 - r123250;
        return r123251;
}

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. Using strategy rm
  3. Applied flip3-+0.6

    \[\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. Simplified0.6

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

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

Reproduce

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