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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r26301614 = x;
        double r26301615 = r26301614 * r26301614;
        double r26301616 = y;
        double r26301617 = 4.0;
        double r26301618 = r26301616 * r26301617;
        double r26301619 = z;
        double r26301620 = r26301619 * r26301619;
        double r26301621 = t;
        double r26301622 = r26301620 - r26301621;
        double r26301623 = r26301618 * r26301622;
        double r26301624 = r26301615 - r26301623;
        return r26301624;
}

double f(double x, double y, double z, double t) {
        double r26301625 = z;
        double r26301626 = r26301625 * r26301625;
        double r26301627 = 1.1822871610112986e+287;
        bool r26301628 = r26301626 <= r26301627;
        double r26301629 = x;
        double r26301630 = y;
        double r26301631 = 4.0;
        double r26301632 = r26301630 * r26301631;
        double r26301633 = -r26301625;
        double r26301634 = fma(r26301633, r26301625, r26301626);
        double r26301635 = r26301632 * r26301634;
        double r26301636 = t;
        double r26301637 = r26301636 - r26301626;
        double r26301638 = r26301632 * r26301637;
        double r26301639 = r26301635 + r26301638;
        double r26301640 = fma(r26301629, r26301629, r26301639);
        double r26301641 = sqrt(r26301636);
        double r26301642 = r26301641 + r26301625;
        double r26301643 = r26301642 * r26301632;
        double r26301644 = r26301641 - r26301625;
        double r26301645 = r26301643 * r26301644;
        double r26301646 = fma(r26301629, r26301629, r26301645);
        double r26301647 = r26301628 ? r26301640 : r26301646;
        return r26301647;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.0
Target6.0
Herbie3.7
\[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) < 1.1822871610112986e+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(4, \left(t - z \cdot z\right) \cdot y, x \cdot x\right)}\]
    3. Taylor expanded around inf 0.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\right)}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt31.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)\]
    7. Applied prod-diff31.6

      \[\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)\]
    8. Applied distribute-rgt-in31.6

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

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

    if 1.1822871610112986e+287 < (* z z)

    1. Initial program 54.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(4, \left(t - z \cdot z\right) \cdot y, x \cdot x\right)}\]
    3. Taylor expanded around inf 54.8

      \[\leadsto \color{blue}{\left(4 \cdot \left(t \cdot y\right) + {x}^{2}\right) - 4 \cdot \left({z}^{2} \cdot y\right)}\]
    4. Simplified54.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\right)}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt59.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)\]
    7. Applied difference-of-squares59.3

      \[\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)\]
    8. Applied associate-*r*33.4

      \[\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.7

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

Reproduce

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