Average Error: 6.1 → 3.3
Time: 14.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 r720134 = x;
        double r720135 = r720134 * r720134;
        double r720136 = y;
        double r720137 = 4.0;
        double r720138 = r720136 * r720137;
        double r720139 = z;
        double r720140 = r720139 * r720139;
        double r720141 = t;
        double r720142 = r720140 - r720141;
        double r720143 = r720138 * r720142;
        double r720144 = r720135 - r720143;
        return r720144;
}

double f(double x, double y, double z, double t) {
        double r720145 = z;
        double r720146 = r720145 * r720145;
        double r720147 = 6.123223926836545e+304;
        bool r720148 = r720146 <= r720147;
        double r720149 = 4.0;
        double r720150 = y;
        double r720151 = t;
        double r720152 = r720151 - r720146;
        double r720153 = r720150 * r720152;
        double r720154 = x;
        double r720155 = r720154 * r720154;
        double r720156 = fma(r720149, r720153, r720155);
        double r720157 = sqrt(r720151);
        double r720158 = r720157 + r720145;
        double r720159 = r720150 * r720158;
        double r720160 = r720157 - r720145;
        double r720161 = r720159 * r720160;
        double r720162 = fma(r720149, r720161, r720155);
        double r720163 = r720148 ? r720156 : r720162;
        return r720163;
}

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