Average Error: 0.5 → 0.5
Time: 14.7s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(y, -x, \log \left(1 + e^{x}\right)\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(y, -x, \log \left(1 + e^{x}\right)\right)
double f(double x, double y) {
        double r120050 = 1.0;
        double r120051 = x;
        double r120052 = exp(r120051);
        double r120053 = r120050 + r120052;
        double r120054 = log(r120053);
        double r120055 = y;
        double r120056 = r120051 * r120055;
        double r120057 = r120054 - r120056;
        return r120057;
}

double f(double x, double y) {
        double r120058 = y;
        double r120059 = x;
        double r120060 = -r120059;
        double r120061 = 1.0;
        double r120062 = exp(r120059);
        double r120063 = r120061 + r120062;
        double r120064 = log(r120063);
        double r120065 = fma(r120058, r120060, r120064);
        return r120065;
}

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 *-un-lft-identity0.5

    \[\leadsto \log \color{blue}{\left(1 \cdot \left(1 + e^{x}\right)\right)} - x \cdot y\]
  4. Applied log-prod0.5

    \[\leadsto \color{blue}{\left(\log 1 + \log \left(1 + e^{x}\right)\right)} - x \cdot y\]
  5. Applied associate--l+0.5

    \[\leadsto \color{blue}{\log 1 + \left(\log \left(1 + e^{x}\right) - x \cdot y\right)}\]
  6. Simplified0.5

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

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

Reproduce

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