Average Error: 0.5 → 0.4
Time: 21.4s
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 r5139899 = 1.0;
        double r5139900 = x;
        double r5139901 = exp(r5139900);
        double r5139902 = r5139899 + r5139901;
        double r5139903 = log(r5139902);
        double r5139904 = y;
        double r5139905 = r5139900 * r5139904;
        double r5139906 = r5139903 - r5139905;
        return r5139906;
}

double f(double x, double y) {
        double r5139907 = x;
        double r5139908 = exp(r5139907);
        double r5139909 = log1p(r5139908);
        double r5139910 = y;
        double r5139911 = r5139910 * r5139907;
        double r5139912 = r5139909 - r5139911;
        return r5139912;
}

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.0
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. Taylor expanded around inf 0.5

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

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

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

Reproduce

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