Average Error: 0.6 → 0.6
Time: 4.5s
Precision: binary64
\[\log \left(1 + e^{x}\right) - x \cdot y \]
\[\begin{array}{l} t_0 := \frac{y}{2} \cdot x\\ \left(\mathsf{log1p}\left(e^{x}\right) - t_0\right) - t_0 \end{array} \]
\log \left(1 + e^{x}\right) - x \cdot y
\begin{array}{l}
t_0 := \frac{y}{2} \cdot x\\
\left(\mathsf{log1p}\left(e^{x}\right) - t_0\right) - t_0
\end{array}
(FPCore (x y) :precision binary64 (- (log (+ 1.0 (exp x))) (* x y)))
(FPCore (x y)
 :precision binary64
 (let* ((t_0 (* (/ y 2.0) x))) (- (- (log1p (exp x)) t_0) t_0)))
double code(double x, double y) {
	return log(1.0 + exp(x)) - (x * y);
}
double code(double x, double y) {
	double t_0 = (y / 2.0) * x;
	return (log1p(exp(x)) - t_0) - t_0;
}

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.0
Herbie0.6
\[\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. Initial program 0.6

    \[\log \left(1 + e^{x}\right) - x \cdot y \]
  2. Simplified0.6

    \[\leadsto \color{blue}{\mathsf{log1p}\left(e^{x}\right) - x \cdot y} \]
  3. Applied add-log-exp_binary6428.7

    \[\leadsto \mathsf{log1p}\left(e^{x}\right) - \color{blue}{\log \left(e^{x \cdot y}\right)} \]
  4. Applied log1p-udef_binary6428.7

    \[\leadsto \color{blue}{\log \left(1 + e^{x}\right)} - \log \left(e^{x \cdot y}\right) \]
  5. Applied diff-log_binary6428.7

    \[\leadsto \color{blue}{\log \left(\frac{1 + e^{x}}{e^{x \cdot y}}\right)} \]
  6. Applied add-sqr-sqrt_binary6428.7

    \[\leadsto \log \left(\frac{1 + e^{x}}{\color{blue}{\sqrt{e^{x \cdot y}} \cdot \sqrt{e^{x \cdot y}}}}\right) \]
  7. Applied *-un-lft-identity_binary6428.7

    \[\leadsto \log \left(\frac{\color{blue}{1 \cdot \left(1 + e^{x}\right)}}{\sqrt{e^{x \cdot y}} \cdot \sqrt{e^{x \cdot y}}}\right) \]
  8. Applied times-frac_binary6428.7

    \[\leadsto \log \color{blue}{\left(\frac{1}{\sqrt{e^{x \cdot y}}} \cdot \frac{1 + e^{x}}{\sqrt{e^{x \cdot y}}}\right)} \]
  9. Applied log-prod_binary6428.7

    \[\leadsto \color{blue}{\log \left(\frac{1}{\sqrt{e^{x \cdot y}}}\right) + \log \left(\frac{1 + e^{x}}{\sqrt{e^{x \cdot y}}}\right)} \]
  10. Simplified28.0

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

    \[\leadsto \left(-\frac{y}{2} \cdot x\right) + \color{blue}{\left(\mathsf{log1p}\left(e^{x}\right) - \frac{y}{2} \cdot x\right)} \]
  12. Final simplification0.6

    \[\leadsto \left(\mathsf{log1p}\left(e^{x}\right) - \frac{y}{2} \cdot x\right) - \frac{y}{2} \cdot x \]

Reproduce

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