Average Error: 5.9 → 3.6
Time: 6.0s
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 8.4058266113122735 \cdot 10^{287}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right) + \left(y \cdot 4\right) \cdot \mathsf{fma}\left(-z, z, z \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(\left(y \cdot 4\right) \cdot \left(\sqrt{t} + z\right)\right) \cdot \left(\sqrt{t} - z\right)\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 8.4058266113122735 \cdot 10^{287}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right) + \left(y \cdot 4\right) \cdot \mathsf{fma}\left(-z, z, z \cdot z\right)\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r683570 = x;
        double r683571 = r683570 * r683570;
        double r683572 = y;
        double r683573 = 4.0;
        double r683574 = r683572 * r683573;
        double r683575 = z;
        double r683576 = r683575 * r683575;
        double r683577 = t;
        double r683578 = r683576 - r683577;
        double r683579 = r683574 * r683578;
        double r683580 = r683571 - r683579;
        return r683580;
}

double f(double x, double y, double z, double t) {
        double r683581 = z;
        double r683582 = r683581 * r683581;
        double r683583 = 8.405826611312274e+287;
        bool r683584 = r683582 <= r683583;
        double r683585 = x;
        double r683586 = y;
        double r683587 = 4.0;
        double r683588 = r683586 * r683587;
        double r683589 = t;
        double r683590 = r683589 - r683582;
        double r683591 = r683588 * r683590;
        double r683592 = -r683581;
        double r683593 = fma(r683592, r683581, r683582);
        double r683594 = r683588 * r683593;
        double r683595 = r683591 + r683594;
        double r683596 = fma(r683585, r683585, r683595);
        double r683597 = sqrt(r683589);
        double r683598 = r683597 + r683581;
        double r683599 = r683588 * r683598;
        double r683600 = r683597 - r683581;
        double r683601 = r683599 * r683600;
        double r683602 = fma(r683585, r683585, r683601);
        double r683603 = r683584 ? r683596 : r683602;
        return r683603;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.9
Target5.8
Herbie3.6
\[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) < 8.405826611312274e+287

    1. Initial program 0.1

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\]
    2. Simplified0.1

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

      \[\leadsto \mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot \left(\color{blue}{\sqrt{t} \cdot \sqrt{t}} - z \cdot z\right)\right)\]
    5. Applied prod-diff32.3

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

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

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

    if 8.405826611312274e+287 < (* z z)

    1. Initial program 56.5

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\]
    2. Simplified56.5

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

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

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

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

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

Reproduce

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