Average Error: 5.9 → 3.3
Time: 16.3s
Precision: 64
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\]
\[\begin{array}{l} \mathbf{if}\;z \cdot z \le 4.012940309661976867141675654509420293463 \cdot 10^{304}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(-\left(z \cdot z - t\right)\right) \cdot \left(y \cdot 4\right)\right) - \left(y \cdot 4\right) \cdot \mathsf{fma}\left(-t, 1, t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(-\left(z + \sqrt{t}\right)\right) \cdot \left(\left(z - \sqrt{t}\right) \cdot \left(y \cdot 4\right)\right)\right) - \left(y \cdot 4\right) \cdot \mathsf{fma}\left(-t, 1, t\right)\\ \end{array}\]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
\mathbf{if}\;z \cdot z \le 4.012940309661976867141675654509420293463 \cdot 10^{304}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(-\left(z \cdot z - t\right)\right) \cdot \left(y \cdot 4\right)\right) - \left(y \cdot 4\right) \cdot \mathsf{fma}\left(-t, 1, t\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(-\left(z + \sqrt{t}\right)\right) \cdot \left(\left(z - \sqrt{t}\right) \cdot \left(y \cdot 4\right)\right)\right) - \left(y \cdot 4\right) \cdot \mathsf{fma}\left(-t, 1, t\right)\\

\end{array}
double f(double x, double y, double z, double t) {
        double r338917 = x;
        double r338918 = r338917 * r338917;
        double r338919 = y;
        double r338920 = 4.0;
        double r338921 = r338919 * r338920;
        double r338922 = z;
        double r338923 = r338922 * r338922;
        double r338924 = t;
        double r338925 = r338923 - r338924;
        double r338926 = r338921 * r338925;
        double r338927 = r338918 - r338926;
        return r338927;
}

double f(double x, double y, double z, double t) {
        double r338928 = z;
        double r338929 = r338928 * r338928;
        double r338930 = 4.012940309661977e+304;
        bool r338931 = r338929 <= r338930;
        double r338932 = x;
        double r338933 = t;
        double r338934 = r338929 - r338933;
        double r338935 = -r338934;
        double r338936 = y;
        double r338937 = 4.0;
        double r338938 = r338936 * r338937;
        double r338939 = r338935 * r338938;
        double r338940 = fma(r338932, r338932, r338939);
        double r338941 = -r338933;
        double r338942 = 1.0;
        double r338943 = fma(r338941, r338942, r338933);
        double r338944 = r338938 * r338943;
        double r338945 = r338940 - r338944;
        double r338946 = sqrt(r338933);
        double r338947 = r338928 + r338946;
        double r338948 = -r338947;
        double r338949 = r338928 - r338946;
        double r338950 = r338949 * r338938;
        double r338951 = r338948 * r338950;
        double r338952 = fma(r338932, r338932, r338951);
        double r338953 = r338952 - r338944;
        double r338954 = r338931 ? r338945 : r338953;
        return r338954;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (* z z) < 4.012940309661977e+304

    1. Initial program 0.1

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\]
    2. Using strategy rm
    3. Applied *-un-lft-identity0.1

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - \color{blue}{1 \cdot t}\right)\]
    4. Applied prod-diff0.1

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(\mathsf{fma}\left(z, z, -t \cdot 1\right) + \mathsf{fma}\left(-t, 1, t \cdot 1\right)\right)}\]
    5. Applied distribute-rgt-in0.1

      \[\leadsto x \cdot x - \color{blue}{\left(\mathsf{fma}\left(z, z, -t \cdot 1\right) \cdot \left(y \cdot 4\right) + \mathsf{fma}\left(-t, 1, t \cdot 1\right) \cdot \left(y \cdot 4\right)\right)}\]
    6. Applied associate--r+0.1

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

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

    if 4.012940309661977e+304 < (* z z)

    1. Initial program 62.5

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\]
    2. Using strategy rm
    3. Applied *-un-lft-identity62.5

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - \color{blue}{1 \cdot t}\right)\]
    4. Applied prod-diff62.5

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(\mathsf{fma}\left(z, z, -t \cdot 1\right) + \mathsf{fma}\left(-t, 1, t \cdot 1\right)\right)}\]
    5. Applied distribute-rgt-in62.5

      \[\leadsto x \cdot x - \color{blue}{\left(\mathsf{fma}\left(z, z, -t \cdot 1\right) \cdot \left(y \cdot 4\right) + \mathsf{fma}\left(-t, 1, t \cdot 1\right) \cdot \left(y \cdot 4\right)\right)}\]
    6. Applied associate--r+62.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(-\left(z \cdot z - t\right)\right) \cdot \left(y \cdot 4\right)\right)} - \mathsf{fma}\left(-t, 1, t \cdot 1\right) \cdot \left(y \cdot 4\right)\]
    8. Using strategy rm
    9. Applied add-sqr-sqrt63.4

      \[\leadsto \mathsf{fma}\left(x, x, \left(-\left(z \cdot z - \color{blue}{\sqrt{t} \cdot \sqrt{t}}\right)\right) \cdot \left(y \cdot 4\right)\right) - \mathsf{fma}\left(-t, 1, t \cdot 1\right) \cdot \left(y \cdot 4\right)\]
    10. Applied difference-of-squares63.4

      \[\leadsto \mathsf{fma}\left(x, x, \left(-\color{blue}{\left(z + \sqrt{t}\right) \cdot \left(z - \sqrt{t}\right)}\right) \cdot \left(y \cdot 4\right)\right) - \mathsf{fma}\left(-t, 1, t \cdot 1\right) \cdot \left(y \cdot 4\right)\]
    11. Applied distribute-lft-neg-in63.4

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(\left(-\left(z + \sqrt{t}\right)\right) \cdot \left(z - \sqrt{t}\right)\right)} \cdot \left(y \cdot 4\right)\right) - \mathsf{fma}\left(-t, 1, t \cdot 1\right) \cdot \left(y \cdot 4\right)\]
    12. Applied associate-*l*34.3

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(-\left(z + \sqrt{t}\right)\right) \cdot \left(\left(z - \sqrt{t}\right) \cdot \left(y \cdot 4\right)\right)}\right) - \mathsf{fma}\left(-t, 1, t \cdot 1\right) \cdot \left(y \cdot 4\right)\]
  3. Recombined 2 regimes into one program.
  4. Final simplification3.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \le 4.012940309661976867141675654509420293463 \cdot 10^{304}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(-\left(z \cdot z - t\right)\right) \cdot \left(y \cdot 4\right)\right) - \left(y \cdot 4\right) \cdot \mathsf{fma}\left(-t, 1, t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(-\left(z + \sqrt{t}\right)\right) \cdot \left(\left(z - \sqrt{t}\right) \cdot \left(y \cdot 4\right)\right)\right) - \left(y \cdot 4\right) \cdot \mathsf{fma}\left(-t, 1, t\right)\\ \end{array}\]

Reproduce

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

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

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