Average Error: 0.6 → 0.5
Time: 29.0s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{log1p}\left(e^{x}\right) - y \cdot x\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{log1p}\left(e^{x}\right) - y \cdot x
double f(double x, double y) {
        double r5719313 = 1.0;
        double r5719314 = x;
        double r5719315 = exp(r5719314);
        double r5719316 = r5719313 + r5719315;
        double r5719317 = log(r5719316);
        double r5719318 = y;
        double r5719319 = r5719314 * r5719318;
        double r5719320 = r5719317 - r5719319;
        return r5719320;
}

double f(double x, double y) {
        double r5719321 = x;
        double r5719322 = exp(r5719321);
        double r5719323 = log1p(r5719322);
        double r5719324 = y;
        double r5719325 = r5719324 * r5719321;
        double r5719326 = r5719323 - r5719325;
        return r5719326;
}

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.1
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(e^{x}\right) - y \cdot x}\]
  3. Final simplification0.5

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

Reproduce

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