Average Error: 0.6 → 0.5
Time: 20.5s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{log1p}\left(\left(e^{x}\right)\right) - y \cdot x\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{log1p}\left(\left(e^{x}\right)\right) - y \cdot x
double f(double x, double y) {
        double r4862451 = 1.0;
        double r4862452 = x;
        double r4862453 = exp(r4862452);
        double r4862454 = r4862451 + r4862453;
        double r4862455 = log(r4862454);
        double r4862456 = y;
        double r4862457 = r4862452 * r4862456;
        double r4862458 = r4862455 - r4862457;
        return r4862458;
}

double f(double x, double y) {
        double r4862459 = x;
        double r4862460 = exp(r4862459);
        double r4862461 = log1p(r4862460);
        double r4862462 = y;
        double r4862463 = r4862462 * r4862459;
        double r4862464 = r4862461 - r4862463;
        return r4862464;
}

Error

Bits error versus x

Bits error versus y

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.6
Target0.0
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;x \le 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.6

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

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\left(e^{x}\right)\right) - y \cdot x}\]
  3. Final simplification0.5

    \[\leadsto \mathsf{log1p}\left(\left(e^{x}\right)\right) - y \cdot x\]

Reproduce

herbie shell --seed 2019129 +o rules:numerics
(FPCore (x y)
  :name "Logistic regression 2"

  :herbie-target
  (if (<= x 0) (- (log (+ 1 (exp x))) (* x y)) (- (log (+ 1 (exp (- x)))) (* (- x) (- 1 y))))

  (- (log (+ 1 (exp x))) (* x y)))