Average Error: 6.1 → 3.3
Time: 20.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 6.12322392683654523 \cdot 10^{304}:\\ \;\;\;\;\mathsf{fma}\left(4, y \cdot \left(t - z \cdot z\right), x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(4, \left(y \cdot \left(\sqrt{t} + z\right)\right) \cdot \left(\sqrt{t} - z\right), x \cdot x\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 6.12322392683654523 \cdot 10^{304}:\\
\;\;\;\;\mathsf{fma}\left(4, y \cdot \left(t - z \cdot z\right), x \cdot x\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r566353 = x;
        double r566354 = r566353 * r566353;
        double r566355 = y;
        double r566356 = 4.0;
        double r566357 = r566355 * r566356;
        double r566358 = z;
        double r566359 = r566358 * r566358;
        double r566360 = t;
        double r566361 = r566359 - r566360;
        double r566362 = r566357 * r566361;
        double r566363 = r566354 - r566362;
        return r566363;
}

double f(double x, double y, double z, double t) {
        double r566364 = z;
        double r566365 = r566364 * r566364;
        double r566366 = 6.123223926836545e+304;
        bool r566367 = r566365 <= r566366;
        double r566368 = 4.0;
        double r566369 = y;
        double r566370 = t;
        double r566371 = r566370 - r566365;
        double r566372 = r566369 * r566371;
        double r566373 = x;
        double r566374 = r566373 * r566373;
        double r566375 = fma(r566368, r566372, r566374);
        double r566376 = sqrt(r566370);
        double r566377 = r566376 + r566364;
        double r566378 = r566369 * r566377;
        double r566379 = r566376 - r566364;
        double r566380 = r566378 * r566379;
        double r566381 = fma(r566368, r566380, r566374);
        double r566382 = r566367 ? r566375 : r566381;
        return r566382;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original6.1
Target6.1
Herbie3.3
\[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) < 6.123223926836545e+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(4, y \cdot \left(t - z \cdot z\right), x \cdot x\right)}\]

    if 6.123223926836545e+304 < (* z z)

    1. Initial program 62.7

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

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

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

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

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

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

Reproduce

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