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

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

\end{array}
double f(double x, double y, double z, double t) {
        double r38412644 = x;
        double r38412645 = r38412644 * r38412644;
        double r38412646 = y;
        double r38412647 = 4.0;
        double r38412648 = r38412646 * r38412647;
        double r38412649 = z;
        double r38412650 = r38412649 * r38412649;
        double r38412651 = t;
        double r38412652 = r38412650 - r38412651;
        double r38412653 = r38412648 * r38412652;
        double r38412654 = r38412645 - r38412653;
        return r38412654;
}

double f(double x, double y, double z, double t) {
        double r38412655 = z;
        double r38412656 = r38412655 * r38412655;
        double r38412657 = 1.1822871610112986e+287;
        bool r38412658 = r38412656 <= r38412657;
        double r38412659 = x;
        double r38412660 = 4.0;
        double r38412661 = t;
        double r38412662 = r38412661 - r38412656;
        double r38412663 = y;
        double r38412664 = r38412662 * r38412663;
        double r38412665 = r38412660 * r38412664;
        double r38412666 = fma(r38412659, r38412659, r38412665);
        double r38412667 = sqrt(r38412661);
        double r38412668 = r38412667 + r38412655;
        double r38412669 = r38412667 - r38412655;
        double r38412670 = r38412669 * r38412663;
        double r38412671 = r38412668 * r38412670;
        double r38412672 = r38412660 * r38412671;
        double r38412673 = fma(r38412659, r38412659, r38412672);
        double r38412674 = r38412658 ? r38412666 : r38412673;
        return r38412674;
}

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, 4 \cdot \left(\left(t - z \cdot z\right) \cdot y\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, 4 \cdot \left(\left(t - z \cdot z\right) \cdot y\right)\right)}\]
    5. Using strategy rm
    6. Applied add-sqr-sqrt59.3

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

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

      \[\leadsto \mathsf{fma}\left(x, x, 4 \cdot \color{blue}{\left(\left(\sqrt{t} + z\right) \cdot \left(\left(\sqrt{t} - z\right) \cdot y\right)\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, 4 \cdot \left(\left(t - z \cdot z\right) \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, 4 \cdot \left(\left(\sqrt{t} + z\right) \cdot \left(\left(\sqrt{t} - z\right) \cdot y\right)\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))))