Average Error: 0.5 → 0.7
Time: 5.7s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \left(\sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)} \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)}\right) \cdot \sqrt[3]{\log \left(1 \cdot 1 + \log \left({\left(e^{e^{x}}\right)}^{\left(e^{x} - 1\right)}\right)\right)}\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \left(\sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)} \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)}\right) \cdot \sqrt[3]{\log \left(1 \cdot 1 + \log \left({\left(e^{e^{x}}\right)}^{\left(e^{x} - 1\right)}\right)\right)}\right)
double f(double x, double y) {
        double r128056 = 1.0;
        double r128057 = x;
        double r128058 = exp(r128057);
        double r128059 = r128056 + r128058;
        double r128060 = log(r128059);
        double r128061 = y;
        double r128062 = r128057 * r128061;
        double r128063 = r128060 - r128062;
        return r128063;
}

double f(double x, double y) {
        double r128064 = 1.0;
        double r128065 = 3.0;
        double r128066 = pow(r128064, r128065);
        double r128067 = x;
        double r128068 = exp(r128067);
        double r128069 = pow(r128068, r128065);
        double r128070 = r128066 + r128069;
        double r128071 = log(r128070);
        double r128072 = y;
        double r128073 = r128064 * r128064;
        double r128074 = r128068 * r128068;
        double r128075 = r128064 * r128068;
        double r128076 = r128074 - r128075;
        double r128077 = r128073 + r128076;
        double r128078 = log(r128077);
        double r128079 = cbrt(r128078);
        double r128080 = r128079 * r128079;
        double r128081 = exp(r128068);
        double r128082 = r128068 - r128064;
        double r128083 = pow(r128081, r128082);
        double r128084 = log(r128083);
        double r128085 = r128073 + r128084;
        double r128086 = log(r128085);
        double r128087 = cbrt(r128086);
        double r128088 = r128080 * r128087;
        double r128089 = fma(r128067, r128072, r128088);
        double r128090 = r128071 - r128089;
        return r128090;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.5
Target0.1
Herbie0.7
\[\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. Initial program 0.5

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

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

    \[\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. Applied associate--l-0.5

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

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

    \[\leadsto \log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \color{blue}{\left(\sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)} \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)}\right) \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)}}\right)\]
  9. Using strategy rm
  10. Applied add-log-exp0.6

    \[\leadsto \log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \left(\sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)} \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)}\right) \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - \color{blue}{\log \left(e^{1 \cdot e^{x}}\right)}\right)\right)}\right)\]
  11. Applied add-log-exp0.7

    \[\leadsto \log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \left(\sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)} \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)}\right) \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(\color{blue}{\log \left(e^{e^{x} \cdot e^{x}}\right)} - \log \left(e^{1 \cdot e^{x}}\right)\right)\right)}\right)\]
  12. Applied diff-log0.7

    \[\leadsto \log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \left(\sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)} \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)}\right) \cdot \sqrt[3]{\log \left(1 \cdot 1 + \color{blue}{\log \left(\frac{e^{e^{x} \cdot e^{x}}}{e^{1 \cdot e^{x}}}\right)}\right)}\right)\]
  13. Simplified0.7

    \[\leadsto \log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \mathsf{fma}\left(x, y, \left(\sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)} \cdot \sqrt[3]{\log \left(1 \cdot 1 + \left(e^{x} \cdot e^{x} - 1 \cdot e^{x}\right)\right)}\right) \cdot \sqrt[3]{\log \left(1 \cdot 1 + \log \color{blue}{\left({\left(e^{e^{x}}\right)}^{\left(e^{x} - 1\right)}\right)}\right)}\right)\]
  14. Final simplification0.7

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

Reproduce

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