Average Error: 5.4 → 3.2
Time: 22.2s
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 r28333562 = x;
        double r28333563 = r28333562 * r28333562;
        double r28333564 = y;
        double r28333565 = 4.0;
        double r28333566 = r28333564 * r28333565;
        double r28333567 = z;
        double r28333568 = r28333567 * r28333567;
        double r28333569 = t;
        double r28333570 = r28333568 - r28333569;
        double r28333571 = r28333566 * r28333570;
        double r28333572 = r28333563 - r28333571;
        return r28333572;
}

double f(double x, double y, double z, double t) {
        double r28333573 = z;
        double r28333574 = r28333573 * r28333573;
        double r28333575 = 4.446553561229177e+281;
        bool r28333576 = r28333574 <= r28333575;
        double r28333577 = 4.0;
        double r28333578 = y;
        double r28333579 = t;
        double r28333580 = r28333579 - r28333574;
        double r28333581 = r28333578 * r28333580;
        double r28333582 = x;
        double r28333583 = r28333582 * r28333582;
        double r28333584 = fma(r28333577, r28333581, r28333583);
        double r28333585 = sqrt(r28333579);
        double r28333586 = r28333585 + r28333573;
        double r28333587 = r28333585 - r28333573;
        double r28333588 = r28333587 * r28333578;
        double r28333589 = r28333586 * r28333588;
        double r28333590 = fma(r28333577, r28333589, r28333583);
        double r28333591 = r28333576 ? r28333584 : r28333590;
        return r28333591;
}

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