Average Error: 0.5 → 0.5
Time: 6.2s
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 r188511 = 1.0;
        double r188512 = x;
        double r188513 = exp(r188512);
        double r188514 = r188511 + r188513;
        double r188515 = log(r188514);
        double r188516 = y;
        double r188517 = r188512 * r188516;
        double r188518 = r188515 - r188517;
        return r188518;
}

double f(double x, double y) {
        double r188519 = 1.0;
        double r188520 = 3.0;
        double r188521 = pow(r188519, r188520);
        double r188522 = x;
        double r188523 = exp(r188522);
        double r188524 = pow(r188523, r188520);
        double r188525 = r188521 + r188524;
        double r188526 = r188523 - r188519;
        double r188527 = r188519 * r188519;
        double r188528 = fma(r188523, r188526, r188527);
        double r188529 = r188525 / r188528;
        double r188530 = log(r188529);
        double r188531 = y;
        double r188532 = r188522 * r188531;
        double r188533 = r188530 - r188532;
        return r188533;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.5
Target0.0
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. Simplified0.5

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

    \[\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 2020003 +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)))