Average Error: 0.5 → 0.5
Time: 14.8s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\mathsf{fma}\left(y, -x, \left(\log \left({\left({1}^{3}\right)}^{3} + {\left({\left(e^{x}\right)}^{3}\right)}^{3}\right) - \log \left(\mathsf{fma}\left({\left(e^{x}\right)}^{3}, {\left(e^{x}\right)}^{3} - {1}^{3}, {1}^{6}\right)\right)\right) - \log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)\right)\]
\log \left(1 + e^{x}\right) - x \cdot y
\mathsf{fma}\left(y, -x, \left(\log \left({\left({1}^{3}\right)}^{3} + {\left({\left(e^{x}\right)}^{3}\right)}^{3}\right) - \log \left(\mathsf{fma}\left({\left(e^{x}\right)}^{3}, {\left(e^{x}\right)}^{3} - {1}^{3}, {1}^{6}\right)\right)\right) - \log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)\right)
double f(double x, double y) {
        double r102056 = 1.0;
        double r102057 = x;
        double r102058 = exp(r102057);
        double r102059 = r102056 + r102058;
        double r102060 = log(r102059);
        double r102061 = y;
        double r102062 = r102057 * r102061;
        double r102063 = r102060 - r102062;
        return r102063;
}

double f(double x, double y) {
        double r102064 = y;
        double r102065 = x;
        double r102066 = -r102065;
        double r102067 = 1.0;
        double r102068 = 3.0;
        double r102069 = pow(r102067, r102068);
        double r102070 = pow(r102069, r102068);
        double r102071 = exp(r102065);
        double r102072 = pow(r102071, r102068);
        double r102073 = pow(r102072, r102068);
        double r102074 = r102070 + r102073;
        double r102075 = log(r102074);
        double r102076 = r102072 - r102069;
        double r102077 = 6.0;
        double r102078 = pow(r102067, r102077);
        double r102079 = fma(r102072, r102076, r102078);
        double r102080 = log(r102079);
        double r102081 = r102075 - r102080;
        double r102082 = r102071 - r102067;
        double r102083 = r102071 * r102082;
        double r102084 = fma(r102067, r102067, r102083);
        double r102085 = log(r102084);
        double r102086 = r102081 - r102085;
        double r102087 = fma(r102064, r102066, r102086);
        return r102087;
}

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. Initial program 0.5

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(y, -x, \log \left(1 + e^{x}\right)\right)}\]
  4. Using strategy rm
  5. Applied flip3-+0.5

    \[\leadsto \mathsf{fma}\left(y, -x, \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)}\right)\]
  6. Applied log-div0.5

    \[\leadsto \mathsf{fma}\left(y, -x, \color{blue}{\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)\]
  7. Simplified0.5

    \[\leadsto \mathsf{fma}\left(y, -x, \log \left({1}^{3} + {\left(e^{x}\right)}^{3}\right) - \color{blue}{\log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)}\right)\]
  8. Using strategy rm
  9. Applied flip3-+0.5

    \[\leadsto \mathsf{fma}\left(y, -x, \log \color{blue}{\left(\frac{{\left({1}^{3}\right)}^{3} + {\left({\left(e^{x}\right)}^{3}\right)}^{3}}{{1}^{3} \cdot {1}^{3} + \left({\left(e^{x}\right)}^{3} \cdot {\left(e^{x}\right)}^{3} - {1}^{3} \cdot {\left(e^{x}\right)}^{3}\right)}\right)} - \log \left(\mathsf{fma}\left(1, 1, e^{x} \cdot \left(e^{x} - 1\right)\right)\right)\right)\]
  10. Applied log-div0.5

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

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

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

Reproduce

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