Average Error: 0.5 → 0.7
Time: 4.7s
Precision: binary64
Cost: 7425
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\begin{array}{l} \mathbf{if}\;x \leq -797629278.9357958:\\ \;\;\;\;-x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\log 2 + x \cdot \left(\left(0.5 + x \cdot 0.125\right) - y\right)\\ \end{array}\]
\log \left(1 + e^{x}\right) - x \cdot y
\begin{array}{l}
\mathbf{if}\;x \leq -797629278.9357958:\\
\;\;\;\;-x \cdot y\\

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

\end{array}
(FPCore (x y) :precision binary64 (- (log (+ 1.0 (exp x))) (* x y)))
(FPCore (x y)
 :precision binary64
 (if (<= x -797629278.9357958)
   (- (* x y))
   (+ (log 2.0) (* x (- (+ 0.5 (* x 0.125)) y)))))
double code(double x, double y) {
	return log(1.0 + exp(x)) - (x * y);
}
double code(double x, double y) {
	double tmp;
	if (x <= -797629278.9357958) {
		tmp = -(x * y);
	} else {
		tmp = log(2.0) + (x * ((0.5 + (x * 0.125)) - y));
	}
	return tmp;
}

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.7
\[\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}\]

Alternatives

Alternative 1
Error0.5
Cost26112
\[\sqrt[3]{{\log \left(1 + e^{x}\right)}^{3}} - x \cdot y\]
Alternative 2
Error0.5
Cost13248
\[\log \left(1 + e^{x}\right) - x \cdot y\]
Alternative 3
Error0.8
Cost7169
\[\begin{array}{l} \mathbf{if}\;x \leq -797629278.9357958:\\ \;\;\;\;-x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\log 2 + x \cdot \left(0.5 - y\right)\\ \end{array}\]
Alternative 4
Error1.1
Cost7041
\[\begin{array}{l} \mathbf{if}\;x \leq -797629278.9357958:\\ \;\;\;\;-x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\log 2 - x \cdot y\\ \end{array}\]
Alternative 5
Error12.7
Cost6785
\[\begin{array}{l} \mathbf{if}\;x \leq -7.993413570552596 \cdot 10^{-35}:\\ \;\;\;\;-x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\log 2\\ \end{array}\]
Alternative 6
Error32.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.502084621141915 \cdot 10^{-224} \lor \neg \left(x \leq 8.737947054107844 \cdot 10^{-207}\right):\\ \;\;\;\;-x \cdot y\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array}\]
Alternative 7
Error56.0
Cost64
\[1\]

Error

Derivation

  1. Split input into 2 regimes
  2. if x < -797629278.93579578

    1. Initial program 0

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

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

      \[\leadsto \color{blue}{-x \cdot y}\]
    4. Simplified0

      \[\leadsto \color{blue}{-x \cdot y}\]

    if -797629278.93579578 < x

    1. Initial program 0.6

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

      \[\leadsto \color{blue}{\left(0.5 \cdot x + \left(0.125 \cdot {x}^{2} + \log 2\right)\right) - x \cdot y}\]
    3. Simplified1.0

      \[\leadsto \color{blue}{\log 2 + x \cdot \left(\left(0.5 + x \cdot 0.125\right) - y\right)}\]
    4. Simplified1.0

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -797629278.9357958:\\ \;\;\;\;-x \cdot y\\ \mathbf{else}:\\ \;\;\;\;\log 2 + x \cdot \left(\left(0.5 + x \cdot 0.125\right) - y\right)\\ \end{array}\]

Reproduce

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