Average Error: 5.4 → 3.2
Time: 20.8s
Precision: 64
\[x \cdot x - \left(y \cdot 4.0\right) \cdot \left(z \cdot z - t\right)\]
\[\begin{array}{l} \mathbf{if}\;z \cdot z \le 4.446553561229177 \cdot 10^{+281}:\\ \;\;\;\;\mathsf{fma}\left(4.0, y \cdot \left(t - z \cdot z\right), x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(4.0, \left(\sqrt{t} + z\right) \cdot \left(\left(\sqrt{t} - z\right) \cdot y\right), x \cdot x\right)\\ \end{array}\]
x \cdot x - \left(y \cdot 4.0\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
\mathbf{if}\;z \cdot z \le 4.446553561229177 \cdot 10^{+281}:\\
\;\;\;\;\mathsf{fma}\left(4.0, y \cdot \left(t - z \cdot z\right), x \cdot x\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r16633427 = x;
        double r16633428 = r16633427 * r16633427;
        double r16633429 = y;
        double r16633430 = 4.0;
        double r16633431 = r16633429 * r16633430;
        double r16633432 = z;
        double r16633433 = r16633432 * r16633432;
        double r16633434 = t;
        double r16633435 = r16633433 - r16633434;
        double r16633436 = r16633431 * r16633435;
        double r16633437 = r16633428 - r16633436;
        return r16633437;
}

double f(double x, double y, double z, double t) {
        double r16633438 = z;
        double r16633439 = r16633438 * r16633438;
        double r16633440 = 4.446553561229177e+281;
        bool r16633441 = r16633439 <= r16633440;
        double r16633442 = 4.0;
        double r16633443 = y;
        double r16633444 = t;
        double r16633445 = r16633444 - r16633439;
        double r16633446 = r16633443 * r16633445;
        double r16633447 = x;
        double r16633448 = r16633447 * r16633447;
        double r16633449 = fma(r16633442, r16633446, r16633448);
        double r16633450 = sqrt(r16633444);
        double r16633451 = r16633450 + r16633438;
        double r16633452 = r16633450 - r16633438;
        double r16633453 = r16633452 * r16633443;
        double r16633454 = r16633451 * r16633453;
        double r16633455 = fma(r16633442, r16633454, r16633448);
        double r16633456 = r16633441 ? r16633449 : r16633455;
        return r16633456;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (* z z) < 4.446553561229177e+281

    1. Initial program 0.1

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

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

    if 4.446553561229177e+281 < (* z z)

    1. Initial program 51.2

      \[x \cdot x - \left(y \cdot 4.0\right) \cdot \left(z \cdot z - t\right)\]
    2. Simplified51.2

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

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

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

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

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

Reproduce

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