Average Error: 5.7 → 2.9
Time: 7.7s
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.34650475463234078 \cdot 10^{304}:\\ \;\;\;\;\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 1.34650475463234078 \cdot 10^{304}:\\
\;\;\;\;\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 r759522 = x;
        double r759523 = r759522 * r759522;
        double r759524 = y;
        double r759525 = 4.0;
        double r759526 = r759524 * r759525;
        double r759527 = z;
        double r759528 = r759527 * r759527;
        double r759529 = t;
        double r759530 = r759528 - r759529;
        double r759531 = r759526 * r759530;
        double r759532 = r759523 - r759531;
        return r759532;
}

double f(double x, double y, double z, double t) {
        double r759533 = z;
        double r759534 = r759533 * r759533;
        double r759535 = 1.3465047546323408e+304;
        bool r759536 = r759534 <= r759535;
        double r759537 = x;
        double r759538 = y;
        double r759539 = 4.0;
        double r759540 = r759538 * r759539;
        double r759541 = t;
        double r759542 = r759541 - r759534;
        double r759543 = r759540 * r759542;
        double r759544 = -r759533;
        double r759545 = fma(r759544, r759533, r759534);
        double r759546 = r759540 * r759545;
        double r759547 = r759543 + r759546;
        double r759548 = fma(r759537, r759537, r759547);
        double r759549 = sqrt(r759541);
        double r759550 = r759549 + r759533;
        double r759551 = r759540 * r759550;
        double r759552 = r759549 - r759533;
        double r759553 = r759551 * r759552;
        double r759554 = fma(r759537, r759537, r759553);
        double r759555 = r759536 ? r759548 : r759554;
        return r759555;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.7
Target5.7
Herbie2.9
\[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.3465047546323408e+304

    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.2

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

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

      \[\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 1.3465047546323408e+304 < (* z z)

    1. Initial program 62.1

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\]
    2. Simplified62.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-sqrt63.0

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

      \[\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*30.5

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \le 1.34650475463234078 \cdot 10^{304}:\\ \;\;\;\;\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 2020056 +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))))