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

\mathbf{else}:\\
\;\;\;\;e^{\left(\sqrt[3]{\log \left(\log \left(\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, x + 2\right)\right)\right)} \cdot \sqrt[3]{\log \left(\log \left(\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, x + 2\right)\right)\right)}\right) \cdot \sqrt[3]{\log \left(\log \left(\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, x + 2\right)\right)\right)}} - x \cdot y\\

\end{array}
double f(double x, double y) {
        double r147256 = 1.0;
        double r147257 = x;
        double r147258 = exp(r147257);
        double r147259 = r147256 + r147258;
        double r147260 = log(r147259);
        double r147261 = y;
        double r147262 = r147257 * r147261;
        double r147263 = r147260 - r147262;
        return r147263;
}

double f(double x, double y) {
        double r147264 = x;
        double r147265 = -8.057362563360427e-05;
        bool r147266 = r147264 <= r147265;
        double r147267 = 1.0;
        double r147268 = exp(r147264);
        double r147269 = r147267 + r147268;
        double r147270 = cbrt(r147269);
        double r147271 = r147270 * r147270;
        double r147272 = log(r147271);
        double r147273 = r147267 * r147267;
        double r147274 = r147268 * r147268;
        double r147275 = r147273 - r147274;
        double r147276 = cbrt(r147275);
        double r147277 = log(r147276);
        double r147278 = r147267 - r147268;
        double r147279 = cbrt(r147278);
        double r147280 = log(r147279);
        double r147281 = r147277 - r147280;
        double r147282 = y;
        double r147283 = r147264 * r147282;
        double r147284 = r147281 - r147283;
        double r147285 = r147272 + r147284;
        double r147286 = 0.5;
        double r147287 = 2.0;
        double r147288 = pow(r147264, r147287);
        double r147289 = 2.0;
        double r147290 = r147264 + r147289;
        double r147291 = fma(r147286, r147288, r147290);
        double r147292 = log(r147291);
        double r147293 = log(r147292);
        double r147294 = cbrt(r147293);
        double r147295 = r147294 * r147294;
        double r147296 = r147295 * r147294;
        double r147297 = exp(r147296);
        double r147298 = r147297 - r147283;
        double r147299 = r147266 ? r147285 : r147298;
        return r147299;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.5
Target0.1
Herbie0.5
\[\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 < -8.057362563360427e-05

    1. Initial program 0.2

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

      \[\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.2

      \[\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.2

      \[\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)}\]
    6. Using strategy rm
    7. Applied flip-+0.2

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

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

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

    if -8.057362563360427e-05 < x

    1. Initial program 0.7

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

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

      \[\leadsto \log \color{blue}{\left(\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, x + 2\right)\right)} - x \cdot y\]
    4. Using strategy rm
    5. Applied add-exp-log0.6

      \[\leadsto \color{blue}{e^{\log \left(\log \left(\mathsf{fma}\left(\frac{1}{2}, {x}^{2}, x + 2\right)\right)\right)}} - x \cdot y\]
    6. Using strategy rm
    7. Applied add-cube-cbrt0.6

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

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

Reproduce

herbie shell --seed 2020062 +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)))