Average Error: 5.9 → 0.1
Time: 20.7s
Precision: 64
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\]
\[\mathsf{fma}\left(x, x, z \cdot \left(\left(4 \cdot y\right) \cdot \left(-z\right)\right) + \left(4 \cdot y\right) \cdot t\right)\]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\mathsf{fma}\left(x, x, z \cdot \left(\left(4 \cdot y\right) \cdot \left(-z\right)\right) + \left(4 \cdot y\right) \cdot t\right)
double f(double x, double y, double z, double t) {
        double r31959505 = x;
        double r31959506 = r31959505 * r31959505;
        double r31959507 = y;
        double r31959508 = 4.0;
        double r31959509 = r31959507 * r31959508;
        double r31959510 = z;
        double r31959511 = r31959510 * r31959510;
        double r31959512 = t;
        double r31959513 = r31959511 - r31959512;
        double r31959514 = r31959509 * r31959513;
        double r31959515 = r31959506 - r31959514;
        return r31959515;
}

double f(double x, double y, double z, double t) {
        double r31959516 = x;
        double r31959517 = z;
        double r31959518 = 4.0;
        double r31959519 = y;
        double r31959520 = r31959518 * r31959519;
        double r31959521 = -r31959517;
        double r31959522 = r31959520 * r31959521;
        double r31959523 = r31959517 * r31959522;
        double r31959524 = t;
        double r31959525 = r31959520 * r31959524;
        double r31959526 = r31959523 + r31959525;
        double r31959527 = fma(r31959516, r31959516, r31959526);
        return r31959527;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.9
Target5.9
Herbie0.1
\[x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)\]

Derivation

  1. Initial program 5.9

    \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\]
  2. Using strategy rm
  3. Applied fma-neg5.9

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\right)}\]
  4. Using strategy rm
  5. Applied sub-neg5.9

    \[\leadsto \mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot \color{blue}{\left(z \cdot z + \left(-t\right)\right)}\right)\]
  6. Applied distribute-lft-in5.9

    \[\leadsto \mathsf{fma}\left(x, x, -\color{blue}{\left(\left(y \cdot 4\right) \cdot \left(z \cdot z\right) + \left(y \cdot 4\right) \cdot \left(-t\right)\right)}\right)\]
  7. Using strategy rm
  8. Applied associate-*r*0.1

    \[\leadsto \mathsf{fma}\left(x, x, -\left(\color{blue}{\left(\left(y \cdot 4\right) \cdot z\right) \cdot z} + \left(y \cdot 4\right) \cdot \left(-t\right)\right)\right)\]
  9. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(x, x, z \cdot \left(\left(4 \cdot y\right) \cdot \left(-z\right)\right) + \left(4 \cdot y\right) \cdot t\right)\]

Reproduce

herbie shell --seed 2019169 +o rules:numerics
(FPCore (x y z t)
  :name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"

  :herbie-target
  (- (* x x) (* 4.0 (* y (- (* z z) t))))

  (- (* x x) (* (* y 4.0) (- (* z z) t))))