Average Error: 0.5 → 0.4
Time: 18.3s
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 r6236025 = 1.0;
        double r6236026 = x;
        double r6236027 = exp(r6236026);
        double r6236028 = r6236025 + r6236027;
        double r6236029 = log(r6236028);
        double r6236030 = y;
        double r6236031 = r6236026 * r6236030;
        double r6236032 = r6236029 - r6236031;
        return r6236032;
}

double f(double x, double y) {
        double r6236033 = x;
        double r6236034 = exp(r6236033);
        double r6236035 = log1p(r6236034);
        double r6236036 = y;
        double r6236037 = r6236036 * r6236033;
        double r6236038 = r6236035 - r6236037;
        return r6236038;
}

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.5
Target0.1
Herbie0.4
\[\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.5

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

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

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

Reproduce

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