Average Error: 0.6 → 0.4
Time: 15.8s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\begin{array}{l} \mathbf{if}\;x \le -9.413547838898711118287877808175068139462 \cdot 10^{-6}:\\ \;\;\;\;\log \left(\sqrt{1 + e^{x}}\right) + \left(\log \left(\sqrt{1 + e^{x}}\right) - x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\frac{{\left(\log 2\right)}^{2} \cdot {x}^{2}}{{2}^{2}} \cdot \frac{-3}{2} + \left({\left(\log 2\right)}^{2} \cdot \left(x \cdot 1.5 + \log 2\right) + \left(0.75 \cdot {x}^{2}\right) \cdot \left(\log 2 + {\left(\log 2\right)}^{2}\right)\right)} - x \cdot y\\ \end{array}\]
\log \left(1 + e^{x}\right) - x \cdot y
\begin{array}{l}
\mathbf{if}\;x \le -9.413547838898711118287877808175068139462 \cdot 10^{-6}:\\
\;\;\;\;\log \left(\sqrt{1 + e^{x}}\right) + \left(\log \left(\sqrt{1 + e^{x}}\right) - x \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{\frac{{\left(\log 2\right)}^{2} \cdot {x}^{2}}{{2}^{2}} \cdot \frac{-3}{2} + \left({\left(\log 2\right)}^{2} \cdot \left(x \cdot 1.5 + \log 2\right) + \left(0.75 \cdot {x}^{2}\right) \cdot \left(\log 2 + {\left(\log 2\right)}^{2}\right)\right)} - x \cdot y\\

\end{array}
double f(double x, double y) {
        double r137547 = 1.0;
        double r137548 = x;
        double r137549 = exp(r137548);
        double r137550 = r137547 + r137549;
        double r137551 = log(r137550);
        double r137552 = y;
        double r137553 = r137548 * r137552;
        double r137554 = r137551 - r137553;
        return r137554;
}

double f(double x, double y) {
        double r137555 = x;
        double r137556 = -9.413547838898711e-06;
        bool r137557 = r137555 <= r137556;
        double r137558 = 1.0;
        double r137559 = exp(r137555);
        double r137560 = r137558 + r137559;
        double r137561 = sqrt(r137560);
        double r137562 = log(r137561);
        double r137563 = y;
        double r137564 = r137555 * r137563;
        double r137565 = r137562 - r137564;
        double r137566 = r137562 + r137565;
        double r137567 = 2.0;
        double r137568 = log(r137567);
        double r137569 = 2.0;
        double r137570 = pow(r137568, r137569);
        double r137571 = pow(r137555, r137569);
        double r137572 = r137570 * r137571;
        double r137573 = pow(r137567, r137569);
        double r137574 = r137572 / r137573;
        double r137575 = -1.5;
        double r137576 = r137574 * r137575;
        double r137577 = 1.5;
        double r137578 = r137555 * r137577;
        double r137579 = r137578 + r137568;
        double r137580 = r137570 * r137579;
        double r137581 = 0.75;
        double r137582 = r137581 * r137571;
        double r137583 = r137568 + r137570;
        double r137584 = r137582 * r137583;
        double r137585 = r137580 + r137584;
        double r137586 = r137576 + r137585;
        double r137587 = cbrt(r137586);
        double r137588 = r137587 - r137564;
        double r137589 = r137557 ? r137566 : r137588;
        return r137589;
}

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.4
\[\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. Split input into 2 regimes
  2. if x < -9.413547838898711e-06

    1. Initial program 0.2

      \[\log \left(1 + e^{x}\right) - x \cdot y\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt0.2

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

      \[\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+0.2

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

    if -9.413547838898711e-06 < x

    1. Initial program 0.7

      \[\log \left(1 + e^{x}\right) - x \cdot y\]
    2. Taylor expanded around 0 0.4

      \[\leadsto \log \color{blue}{\left(\frac{1}{2} \cdot {x}^{2} + \left(x + 2\right)\right)} - x \cdot y\]
    3. Using strategy rm
    4. Applied add-cbrt-cube0.4

      \[\leadsto \color{blue}{\sqrt[3]{\left(\log \left(\frac{1}{2} \cdot {x}^{2} + \left(x + 2\right)\right) \cdot \log \left(\frac{1}{2} \cdot {x}^{2} + \left(x + 2\right)\right)\right) \cdot \log \left(\frac{1}{2} \cdot {x}^{2} + \left(x + 2\right)\right)}} - x \cdot y\]
    5. Simplified0.4

      \[\leadsto \sqrt[3]{\color{blue}{{\left(\log \left(\frac{1}{2} \cdot {x}^{2} + \left(x + 2\right)\right)\right)}^{3}}} - x \cdot y\]
    6. Taylor expanded around 0 0.4

      \[\leadsto \sqrt[3]{\color{blue}{\left(0.75 \cdot \left({\left(\log 2\right)}^{2} \cdot {x}^{2}\right) + \left({\left(\log 2\right)}^{3} + \left(1.5 \cdot \left({\left(\log 2\right)}^{2} \cdot x\right) + 0.75 \cdot \left(\log 2 \cdot {x}^{2}\right)\right)\right)\right) - \frac{3}{2} \cdot \frac{{\left(\log 2\right)}^{2} \cdot {x}^{2}}{{2}^{2}}}} - x \cdot y\]
    7. Simplified0.4

      \[\leadsto \sqrt[3]{\color{blue}{\frac{{\left(\log 2\right)}^{2} \cdot {x}^{2}}{{2}^{2}} \cdot \frac{-3}{2} + \left({\left(\log 2\right)}^{2} \cdot \left(x \cdot 1.5 + \log 2\right) + \left(0.75 \cdot {x}^{2}\right) \cdot \left(\log 2 + {\left(\log 2\right)}^{2}\right)\right)}} - x \cdot y\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \le -9.413547838898711118287877808175068139462 \cdot 10^{-6}:\\ \;\;\;\;\log \left(\sqrt{1 + e^{x}}\right) + \left(\log \left(\sqrt{1 + e^{x}}\right) - x \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\frac{{\left(\log 2\right)}^{2} \cdot {x}^{2}}{{2}^{2}} \cdot \frac{-3}{2} + \left({\left(\log 2\right)}^{2} \cdot \left(x \cdot 1.5 + \log 2\right) + \left(0.75 \cdot {x}^{2}\right) \cdot \left(\log 2 + {\left(\log 2\right)}^{2}\right)\right)} - x \cdot y\\ \end{array}\]

Reproduce

herbie shell --seed 2019325 
(FPCore (x y)
  :name "Logistic regression 2"
  :precision binary64

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

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