Average Error: 5.7 → 4.2
Time: 4.6s
Precision: binary64
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} \mathbf{if}\;x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \leq \infty:\\ \;\;\;\;\mathsf{fma}\left(y, 4 \cdot \left(t - z \cdot z\right), x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, 4 \cdot \left(y \cdot t\right)\right)\\ \end{array} \]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
\mathbf{if}\;x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \leq \infty:\\
\;\;\;\;\mathsf{fma}\left(y, 4 \cdot \left(t - z \cdot z\right), x \cdot x\right)\\

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


\end{array}
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (- (* x x) (* (* y 4.0) (- (* z z) t))) INFINITY)
   (fma y (* 4.0 (- t (* z z))) (* x x))
   (fma x x (* 4.0 (* y t)))))
double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (((x * x) - ((y * 4.0) * ((z * z) - t))) <= ((double) INFINITY)) {
		tmp = fma(y, (4.0 * (t - (z * z))), (x * x));
	} else {
		tmp = fma(x, x, (4.0 * (y * t)));
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.7
Target5.7
Herbie4.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 (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < +inf.0

    1. Initial program 2.8

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, 4 \cdot \left(t - z \cdot z\right), x \cdot x\right)} \]

    if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)))

    1. Initial program 64.0

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

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

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

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

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

Reproduce

herbie shell --seed 2022088 
(FPCore (x y z t)
  :name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
  :precision binary64

  :herbie-target
  (- (* x x) (* 4.0 (* y (- (* z z) t))))

  (- (* x x) (* (* y 4.0) (- (* z z) t))))