Average Error: 0.1 → 0.0
Time: 8.9s
Precision: 64
\[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3\]
\[\mathsf{fma}\left(3, d1, 1 \cdot \left(d1 \cdot \left(d3 + d2\right)\right)\right)\]
\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3
\mathsf{fma}\left(3, d1, 1 \cdot \left(d1 \cdot \left(d3 + d2\right)\right)\right)
double f(double d1, double d2, double d3) {
        double r228128 = d1;
        double r228129 = 3.0;
        double r228130 = r228128 * r228129;
        double r228131 = d2;
        double r228132 = r228128 * r228131;
        double r228133 = r228130 + r228132;
        double r228134 = d3;
        double r228135 = r228128 * r228134;
        double r228136 = r228133 + r228135;
        return r228136;
}

double f(double d1, double d2, double d3) {
        double r228137 = 3.0;
        double r228138 = d1;
        double r228139 = 1.0;
        double r228140 = d3;
        double r228141 = d2;
        double r228142 = r228140 + r228141;
        double r228143 = r228138 * r228142;
        double r228144 = r228139 * r228143;
        double r228145 = fma(r228137, r228138, r228144);
        return r228145;
}

Error

Bits error versus d1

Bits error versus d2

Bits error versus d3

Target

Original0.1
Target0.1
Herbie0.0
\[d1 \cdot \left(\left(3 + d2\right) + d3\right)\]

Derivation

  1. Initial program 0.1

    \[\left(d1 \cdot 3 + d1 \cdot d2\right) + d1 \cdot d3\]
  2. Simplified0.1

    \[\leadsto \color{blue}{d1 \cdot \left(d3 + \left(3 + d2\right)\right)}\]
  3. Using strategy rm
  4. Applied flip-+22.3

    \[\leadsto d1 \cdot \color{blue}{\frac{d3 \cdot d3 - \left(3 + d2\right) \cdot \left(3 + d2\right)}{d3 - \left(3 + d2\right)}}\]
  5. Applied associate-*r/25.7

    \[\leadsto \color{blue}{\frac{d1 \cdot \left(d3 \cdot d3 - \left(3 + d2\right) \cdot \left(3 + d2\right)\right)}{d3 - \left(3 + d2\right)}}\]
  6. Taylor expanded around 0 0.1

    \[\leadsto \color{blue}{3 \cdot d1 + \left(1 \cdot \left(d1 \cdot d3\right) + 1 \cdot \left(d1 \cdot d2\right)\right)}\]
  7. Simplified0.0

    \[\leadsto \color{blue}{\mathsf{fma}\left(3, d1, 1 \cdot \left(d1 \cdot \left(d3 + d2\right)\right)\right)}\]
  8. Final simplification0.0

    \[\leadsto \mathsf{fma}\left(3, d1, 1 \cdot \left(d1 \cdot \left(d3 + d2\right)\right)\right)\]

Reproduce

herbie shell --seed 2019351 +o rules:numerics
(FPCore (d1 d2 d3)
  :name "FastMath test3"
  :precision binary64

  :herbie-target
  (* d1 (+ (+ 3 d2) d3))

  (+ (+ (* d1 3) (* d1 d2)) (* d1 d3)))