Average Error: 0.5 → 0.4
Time: 10.1s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\begin{array}{l} \mathbf{if}\;x \le -0.00155976793741554524:\\ \;\;\;\;\left(\log \left(1 \cdot 1 - e^{x + x}\right) - \log \left(1 - e^{x}\right)\right) - x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\log 2 + 0.5 \cdot x\right) + {x}^{2} \cdot \left(0.25 - \frac{\frac{1}{2}}{{2}^{2}}\right)\right) - x \cdot y\\ \end{array}\]
\log \left(1 + e^{x}\right) - x \cdot y
\begin{array}{l}
\mathbf{if}\;x \le -0.00155976793741554524:\\
\;\;\;\;\left(\log \left(1 \cdot 1 - e^{x + x}\right) - \log \left(1 - e^{x}\right)\right) - x \cdot y\\

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

\end{array}
double f(double x, double y) {
        double r147245 = 1.0;
        double r147246 = x;
        double r147247 = exp(r147246);
        double r147248 = r147245 + r147247;
        double r147249 = log(r147248);
        double r147250 = y;
        double r147251 = r147246 * r147250;
        double r147252 = r147249 - r147251;
        return r147252;
}

double f(double x, double y) {
        double r147253 = x;
        double r147254 = -0.0015597679374155452;
        bool r147255 = r147253 <= r147254;
        double r147256 = 1.0;
        double r147257 = r147256 * r147256;
        double r147258 = r147253 + r147253;
        double r147259 = exp(r147258);
        double r147260 = r147257 - r147259;
        double r147261 = log(r147260);
        double r147262 = exp(r147253);
        double r147263 = r147256 - r147262;
        double r147264 = log(r147263);
        double r147265 = r147261 - r147264;
        double r147266 = y;
        double r147267 = r147253 * r147266;
        double r147268 = r147265 - r147267;
        double r147269 = 2.0;
        double r147270 = log(r147269);
        double r147271 = 0.5;
        double r147272 = r147271 * r147253;
        double r147273 = r147270 + r147272;
        double r147274 = 2.0;
        double r147275 = pow(r147253, r147274);
        double r147276 = 0.25;
        double r147277 = 0.5;
        double r147278 = pow(r147269, r147274);
        double r147279 = r147277 / r147278;
        double r147280 = r147276 - r147279;
        double r147281 = r147275 * r147280;
        double r147282 = r147273 + r147281;
        double r147283 = r147282 - r147267;
        double r147284 = r147255 ? r147268 : r147283;
        return r147284;
}

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.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.0015597679374155452

    1. Initial program 0.2

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

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

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

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

    if -0.0015597679374155452 < x

    1. Initial program 0.7

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

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

      \[\leadsto \color{blue}{\left(\left(\log 2 + 0.5 \cdot x\right) + {x}^{2} \cdot \left(0.25 - \frac{\frac{1}{2}}{{2}^{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 -0.00155976793741554524:\\ \;\;\;\;\left(\log \left(1 \cdot 1 - e^{x + x}\right) - \log \left(1 - e^{x}\right)\right) - x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\left(\left(\log 2 + 0.5 \cdot x\right) + {x}^{2} \cdot \left(0.25 - \frac{\frac{1}{2}}{{2}^{2}}\right)\right) - x \cdot y\\ \end{array}\]

Reproduce

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