Average Error: 5.8 → 3.2
Time: 12.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 1.19532991694202995 \cdot 10^{299}:\\ \;\;\;\;\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 1.19532991694202995 \cdot 10^{299}:\\
\;\;\;\;\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 r724452 = x;
        double r724453 = r724452 * r724452;
        double r724454 = y;
        double r724455 = 4.0;
        double r724456 = r724454 * r724455;
        double r724457 = z;
        double r724458 = r724457 * r724457;
        double r724459 = t;
        double r724460 = r724458 - r724459;
        double r724461 = r724456 * r724460;
        double r724462 = r724453 - r724461;
        return r724462;
}

double f(double x, double y, double z, double t) {
        double r724463 = z;
        double r724464 = r724463 * r724463;
        double r724465 = 1.19532991694203e+299;
        bool r724466 = r724464 <= r724465;
        double r724467 = 4.0;
        double r724468 = y;
        double r724469 = t;
        double r724470 = r724469 - r724464;
        double r724471 = r724468 * r724470;
        double r724472 = x;
        double r724473 = r724472 * r724472;
        double r724474 = fma(r724467, r724471, r724473);
        double r724475 = sqrt(r724469);
        double r724476 = r724475 + r724463;
        double r724477 = r724468 * r724476;
        double r724478 = r724475 - r724463;
        double r724479 = r724477 * r724478;
        double r724480 = fma(r724467, r724479, r724473);
        double r724481 = r724466 ? r724474 : r724480;
        return r724481;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.8
Target5.8
Herbie3.2
\[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.19532991694203e+299

    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 1.19532991694203e+299 < (* z z)

    1. Initial program 60.2

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

      \[\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-sqrt62.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-squares62.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*32.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.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \le 1.19532991694202995 \cdot 10^{299}:\\ \;\;\;\;\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 2020043 +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))))