Average Error: 5.9 → 5.3
Time: 12.9s
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.778274390329388464489784682083722821395 \cdot 10^{308}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(4 \cdot t, y, 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 1.778274390329388464489784682083722821395 \cdot 10^{308}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\

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

\end{array}
double f(double x, double y, double z, double t) {
        double r502164 = x;
        double r502165 = r502164 * r502164;
        double r502166 = y;
        double r502167 = 4.0;
        double r502168 = r502166 * r502167;
        double r502169 = z;
        double r502170 = r502169 * r502169;
        double r502171 = t;
        double r502172 = r502170 - r502171;
        double r502173 = r502168 * r502172;
        double r502174 = r502165 - r502173;
        return r502174;
}

double f(double x, double y, double z, double t) {
        double r502175 = z;
        double r502176 = r502175 * r502175;
        double r502177 = 1.7782743903293885e+308;
        bool r502178 = r502176 <= r502177;
        double r502179 = y;
        double r502180 = 4.0;
        double r502181 = r502179 * r502180;
        double r502182 = t;
        double r502183 = r502182 - r502176;
        double r502184 = x;
        double r502185 = r502184 * r502184;
        double r502186 = fma(r502181, r502183, r502185);
        double r502187 = r502180 * r502182;
        double r502188 = fma(r502187, r502179, r502185);
        double r502189 = r502178 ? r502186 : r502188;
        return r502189;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.9
Target5.9
Herbie5.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) < 1.7782743903293885e+308

    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(y \cdot 4, t - z \cdot z, x \cdot x\right)}\]

    if 1.7782743903293885e+308 < (* z z)

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)}\]
    3. Taylor expanded around 0 56.7

      \[\leadsto \color{blue}{{x}^{2} + 4 \cdot \left(t \cdot y\right)}\]
    4. Simplified56.7

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

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

Reproduce

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