Average Error: 0.5 → 0.3
Time: 2.5s
Precision: binary64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\begin{array}{l} \mathbf{if}\;x \leq 236.15022108429926:\\ \;\;\;\;\left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \log \left(1 \cdot 1 + e^{x} \cdot \left(e^{x} - 1\right)\right)\right) - x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\left(\log 2 + \left(x \cdot 0.5 + \left(x \cdot x\right) \cdot \left(0.25 - \frac{0.5}{2 \cdot 2}\right)\right)\right) - x \cdot y\\ \end{array}\]
\log \left(1 + e^{x}\right) - x \cdot y
\begin{array}{l}
\mathbf{if}\;x \leq 236.15022108429926:\\
\;\;\;\;\left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \log \left(1 \cdot 1 + e^{x} \cdot \left(e^{x} - 1\right)\right)\right) - x \cdot y\\

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

\end{array}
double code(double x, double y) {
	return ((double) (((double) log(((double) (1.0 + ((double) exp(x)))))) - ((double) (x * y))));
}
double code(double x, double y) {
	double VAR;
	if ((x <= 236.15022108429926)) {
		VAR = ((double) (((double) (((double) log(((double) (((double) pow(1.0, 3.0)) + ((double) pow(((double) exp(x)), 3.0)))))) - ((double) log(((double) (((double) (1.0 * 1.0)) + ((double) (((double) exp(x)) * ((double) (((double) exp(x)) - 1.0)))))))))) - ((double) (x * y))));
	} else {
		VAR = ((double) (((double) (((double) log(2.0)) + ((double) (((double) (x * 0.5)) + ((double) (((double) (x * x)) * ((double) (0.25 - (0.5 / ((double) (2.0 * 2.0))))))))))) - ((double) (x * y))));
	}
	return VAR;
}

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.3
\[\begin{array}{l} \mathbf{if}\;x \leq 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 < 236.150221084299261

    1. Initial program 0.1

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

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

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

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

    if 236.150221084299261 < x

    1. Initial program 60.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 236.15022108429926:\\ \;\;\;\;\left(\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \log \left(1 \cdot 1 + e^{x} \cdot \left(e^{x} - 1\right)\right)\right) - x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\left(\log 2 + \left(x \cdot 0.5 + \left(x \cdot x\right) \cdot \left(0.25 - \frac{0.5}{2 \cdot 2}\right)\right)\right) - x \cdot y\\ \end{array}\]

Reproduce

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

  :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)))