Average Error: 0.5 → 0.5
Time: 16.1s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\log \left(\sqrt{1 + e^{x}}\right) + \left(\log \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + e^{x}\right)\right)}\right) - y \cdot x\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\log \left(\sqrt{1 + e^{x}}\right) + \left(\log \left(\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + e^{x}\right)\right)}\right) - y \cdot x\right)
double f(double x, double y) {
        double r5108702 = 1.0;
        double r5108703 = x;
        double r5108704 = exp(r5108703);
        double r5108705 = r5108702 + r5108704;
        double r5108706 = log(r5108705);
        double r5108707 = y;
        double r5108708 = r5108703 * r5108707;
        double r5108709 = r5108706 - r5108708;
        return r5108709;
}

double f(double x, double y) {
        double r5108710 = 1.0;
        double r5108711 = x;
        double r5108712 = exp(r5108711);
        double r5108713 = r5108710 + r5108712;
        double r5108714 = sqrt(r5108713);
        double r5108715 = log(r5108714);
        double r5108716 = log1p(r5108713);
        double r5108717 = expm1(r5108716);
        double r5108718 = sqrt(r5108717);
        double r5108719 = log(r5108718);
        double r5108720 = y;
        double r5108721 = r5108720 * r5108711;
        double r5108722 = r5108719 - r5108721;
        double r5108723 = r5108715 + r5108722;
        return r5108723;
}

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.5
\[\begin{array}{l} \mathbf{if}\;x \le 0.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. Using strategy rm
  3. Applied add-sqr-sqrt1.3

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

    \[\leadsto \color{blue}{\left(\log \left(\sqrt{1 + e^{x}}\right) + \log \left(\sqrt{1 + e^{x}}\right)\right)} - x \cdot y\]
  5. Applied associate--l+1.0

    \[\leadsto \color{blue}{\log \left(\sqrt{1 + e^{x}}\right) + \left(\log \left(\sqrt{1 + e^{x}}\right) - x \cdot y\right)}\]
  6. Using strategy rm
  7. Applied expm1-log1p-u0.5

    \[\leadsto \log \left(\sqrt{1 + e^{x}}\right) + \left(\log \left(\sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + e^{x}\right)\right)}}\right) - x \cdot y\right)\]
  8. Final simplification0.5

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

Reproduce

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

  :herbie-target
  (if (<= x 0.0) (- (log (+ 1.0 (exp x))) (* x y)) (- (log (+ 1.0 (exp (- x)))) (* (- x) (- 1.0 y))))

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