Average Error: 0.5 → 0.5
Time: 4.7s
Precision: 64
\[\log \left(1 + e^{x}\right) - x \cdot y\]
\[\log \left(\frac{{1}^{3} + {\left(e^{x}\right)}^{3}}{\mathsf{fma}\left(e^{x}, e^{x} - 1, 1 \cdot 1\right)}\right) - x \cdot y\]
\log \left(1 + e^{x}\right) - x \cdot y
\log \left(\frac{{1}^{3} + {\left(e^{x}\right)}^{3}}{\mathsf{fma}\left(e^{x}, e^{x} - 1, 1 \cdot 1\right)}\right) - x \cdot y
double f(double x, double y) {
        double r159792 = 1.0;
        double r159793 = x;
        double r159794 = exp(r159793);
        double r159795 = r159792 + r159794;
        double r159796 = log(r159795);
        double r159797 = y;
        double r159798 = r159793 * r159797;
        double r159799 = r159796 - r159798;
        return r159799;
}

double f(double x, double y) {
        double r159800 = 1.0;
        double r159801 = 3.0;
        double r159802 = pow(r159800, r159801);
        double r159803 = x;
        double r159804 = exp(r159803);
        double r159805 = pow(r159804, r159801);
        double r159806 = r159802 + r159805;
        double r159807 = r159804 - r159800;
        double r159808 = r159800 * r159800;
        double r159809 = fma(r159804, r159807, r159808);
        double r159810 = r159806 / r159809;
        double r159811 = log(r159810);
        double r159812 = y;
        double r159813 = r159803 * r159812;
        double r159814 = r159811 - r159813;
        return r159814;
}

Error

Bits error versus x

Bits error versus y

Target

Original0.5
Target0.0
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. 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. Simplified0.5

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

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

Reproduce

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