Average Error: 5.4 → 0.1
Time: 20.2s
Precision: 64
\[x \cdot x - \left(y \cdot 4.0\right) \cdot \left(z \cdot z - t\right)\]
\[\mathsf{fma}\left(t, y \cdot 4.0, x \cdot x - \left(\left(y \cdot 4.0\right) \cdot z\right) \cdot z\right)\]
x \cdot x - \left(y \cdot 4.0\right) \cdot \left(z \cdot z - t\right)
\mathsf{fma}\left(t, y \cdot 4.0, x \cdot x - \left(\left(y \cdot 4.0\right) \cdot z\right) \cdot z\right)
double f(double x, double y, double z, double t) {
        double r30059005 = x;
        double r30059006 = r30059005 * r30059005;
        double r30059007 = y;
        double r30059008 = 4.0;
        double r30059009 = r30059007 * r30059008;
        double r30059010 = z;
        double r30059011 = r30059010 * r30059010;
        double r30059012 = t;
        double r30059013 = r30059011 - r30059012;
        double r30059014 = r30059009 * r30059013;
        double r30059015 = r30059006 - r30059014;
        return r30059015;
}

double f(double x, double y, double z, double t) {
        double r30059016 = t;
        double r30059017 = y;
        double r30059018 = 4.0;
        double r30059019 = r30059017 * r30059018;
        double r30059020 = x;
        double r30059021 = r30059020 * r30059020;
        double r30059022 = z;
        double r30059023 = r30059019 * r30059022;
        double r30059024 = r30059023 * r30059022;
        double r30059025 = r30059021 - r30059024;
        double r30059026 = fma(r30059016, r30059019, r30059025);
        return r30059026;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

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

Derivation

  1. Initial program 5.4

    \[x \cdot x - \left(y \cdot 4.0\right) \cdot \left(z \cdot z - t\right)\]
  2. Taylor expanded around inf 5.4

    \[\leadsto \color{blue}{\left(4.0 \cdot \left(t \cdot y\right) + {x}^{2}\right) - 4.0 \cdot \left({z}^{2} \cdot y\right)}\]
  3. Simplified0.1

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

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

Reproduce

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