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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, 0.25 \cdot x + 0.5, \log 2 - \frac{1}{2} \cdot \frac{{x}^{2}}{{2}^{2}}\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 <= -915233.3327664499)) {
		VAR = ((double) (((double) log(((double) (((double) cbrt(((double) (1.0 + ((double) exp(x)))))) * ((double) cbrt(((double) (1.0 + ((double) exp(x)))))))))) + ((double) (((double) log(((double) cbrt(((double) (1.0 + ((double) exp(x)))))))) - ((double) (x * y))))));
	} else {
		VAR = ((double) (((double) fma(x, ((double) (((double) (0.25 * x)) + 0.5)), ((double) (((double) log(2.0)) - ((double) (0.5 * ((double) (((double) pow(x, 2.0)) / ((double) pow(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.0
Herbie0.6
\[\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 < -915233.3327664499

    1. Initial program 0

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

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

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

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

    if -915233.3327664499 < x

    1. Initial program 0.8

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

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

      \[\leadsto \log \color{blue}{\left(\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, x + 2\right)\right)} - x \cdot y\]
    4. Taylor expanded around 0 0.8

      \[\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\]
    5. Simplified0.8

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

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

Reproduce

herbie shell --seed 2020121 +o rules:numerics
(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)))