Average Error: 6.1 → 3.3
Time: 13.0s
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 r590392 = x;
        double r590393 = r590392 * r590392;
        double r590394 = y;
        double r590395 = 4.0;
        double r590396 = r590394 * r590395;
        double r590397 = z;
        double r590398 = r590397 * r590397;
        double r590399 = t;
        double r590400 = r590398 - r590399;
        double r590401 = r590396 * r590400;
        double r590402 = r590393 - r590401;
        return r590402;
}

double f(double x, double y, double z, double t) {
        double r590403 = z;
        double r590404 = r590403 * r590403;
        double r590405 = 6.123223926836545e+304;
        bool r590406 = r590404 <= r590405;
        double r590407 = 4.0;
        double r590408 = y;
        double r590409 = t;
        double r590410 = r590409 - r590404;
        double r590411 = r590408 * r590410;
        double r590412 = x;
        double r590413 = r590412 * r590412;
        double r590414 = fma(r590407, r590411, r590413);
        double r590415 = sqrt(r590409);
        double r590416 = r590415 + r590403;
        double r590417 = r590408 * r590416;
        double r590418 = r590415 - r590403;
        double r590419 = r590417 * r590418;
        double r590420 = fma(r590407, r590419, r590413);
        double r590421 = r590406 ? r590414 : r590420;
        return r590421;
}

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))))