Average Error: 0.5 → 0.4
Time: 16.5s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\sqrt{\mathsf{log1p}\left(\left(e^{x}\right)\right)} \cdot \sqrt{\mathsf{log1p}\left(\left(e^{x}\right)\right)}\right)\right)\right)\right) - y \cdot x\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\sqrt{\mathsf{log1p}\left(\left(e^{x}\right)\right)} \cdot \sqrt{\mathsf{log1p}\left(\left(e^{x}\right)\right)}\right)\right)\right)\right) - y \cdot x
double f(double x, double y) {
        double r20525446 = 1.0;
        double r20525447 = x;
        double r20525448 = exp(r20525447);
        double r20525449 = r20525446 + r20525448;
        double r20525450 = log(r20525449);
        double r20525451 = y;
        double r20525452 = r20525447 * r20525451;
        double r20525453 = r20525450 - r20525452;
        return r20525453;
}

double f(double x, double y) {
        double r20525454 = x;
        double r20525455 = exp(r20525454);
        double r20525456 = log1p(r20525455);
        double r20525457 = sqrt(r20525456);
        double r20525458 = r20525457 * r20525457;
        double r20525459 = log1p(r20525458);
        double r20525460 = expm1(r20525459);
        double r20525461 = y;
        double r20525462 = r20525461 * r20525454;
        double r20525463 = r20525460 - r20525462;
        return r20525463;
}

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(\left(e^{x}\right)\right) - y \cdot x}\]
  3. Using strategy rm
  4. Applied expm1-log1p-u0.4

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\left(\mathsf{log1p}\left(\left(\mathsf{log1p}\left(\left(e^{x}\right)\right)\right)\right)\right)\right)} - y \cdot x\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt0.4

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

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

Reproduce

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