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

\mathbf{else}:\\
\;\;\;\;\log \left(\frac{1}{2} \cdot {x}^{2} + \left(x + 2\right)\right) - x \cdot y\\

\end{array}
double f(double x, double y) {
        double r180098 = 1.0;
        double r180099 = x;
        double r180100 = exp(r180099);
        double r180101 = r180098 + r180100;
        double r180102 = log(r180101);
        double r180103 = y;
        double r180104 = r180099 * r180103;
        double r180105 = r180102 - r180104;
        return r180105;
}

double f(double x, double y) {
        double r180106 = x;
        double r180107 = 0.00010259817767565942;
        bool r180108 = r180106 <= r180107;
        double r180109 = 1.0;
        double r180110 = exp(r180106);
        double r180111 = r180109 + r180110;
        double r180112 = 3.0;
        double r180113 = pow(r180111, r180112);
        double r180114 = cbrt(r180113);
        double r180115 = log(r180114);
        double r180116 = y;
        double r180117 = r180106 * r180116;
        double r180118 = r180115 - r180117;
        double r180119 = 0.5;
        double r180120 = 2.0;
        double r180121 = pow(r180106, r180120);
        double r180122 = r180119 * r180121;
        double r180123 = 2.0;
        double r180124 = r180106 + r180123;
        double r180125 = r180122 + r180124;
        double r180126 = log(r180125);
        double r180127 = r180126 - r180117;
        double r180128 = r180108 ? r180118 : r180127;
        return r180128;
}

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.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. Split input into 2 regimes
  2. if x < 0.00010259817767565942

    1. Initial program 0.1

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

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

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

    if 0.00010259817767565942 < x

    1. Initial program 31.4

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

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

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

Reproduce

herbie shell --seed 2020064 
(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)))