Average Error: 5.8 → 0.2
Time: 7.4s
Precision: binary64
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} t_1 := \mathsf{fma}\left(z, y \cdot \left(z \cdot -4\right), x \cdot x\right)\\ \mathbf{if}\;z \leq -6.038238978544222 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9.433316727882347 \cdot 10^{+117}:\\ \;\;\;\;\mathsf{fma}\left(y, 4 \cdot \mathsf{fma}\left(z, -z, t\right), x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
t_1 := \mathsf{fma}\left(z, y \cdot \left(z \cdot -4\right), x \cdot x\right)\\
\mathbf{if}\;z \leq -6.038238978544222 \cdot 10^{+153}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 9.433316727882347 \cdot 10^{+117}:\\
\;\;\;\;\mathsf{fma}\left(y, 4 \cdot \mathsf{fma}\left(z, -z, t\right), x \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (fma z (* y (* z -4.0)) (* x x))))
   (if (<= z -6.038238978544222e+153)
     t_1
     (if (<= z 9.433316727882347e+117)
       (fma y (* 4.0 (fma z (- z) t)) (* x x))
       t_1))))
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 t_1 = fma(z, (y * (z * -4.0)), (x * x));
	double tmp;
	if (z <= -6.038238978544222e+153) {
		tmp = t_1;
	} else if (z <= 9.433316727882347e+117) {
		tmp = fma(y, (4.0 * fma(z, -z, t)), (x * x));
	} else {
		tmp = t_1;
	}
	return tmp;
}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.8
Target5.8
Herbie0.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 < -6.0382389785442217e153 or 9.43331672788234659e117 < z

    1. Initial program 50.5

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, 4 \cdot \left(t - z \cdot z\right), x \cdot x\right)} \]
    3. Applied egg-rr50.6

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

      \[\leadsto \color{blue}{{x}^{2} - 4 \cdot \left(y \cdot {z}^{2}\right)} \]
    5. Simplified1.3

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

    if -6.0382389785442217e153 < z < 9.43331672788234659e117

    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, 4 \cdot \left(t - z \cdot z\right), x \cdot x\right)} \]
    3. Applied egg-rr0.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -6.038238978544222 \cdot 10^{+153}:\\ \;\;\;\;\mathsf{fma}\left(z, y \cdot \left(z \cdot -4\right), x \cdot x\right)\\ \mathbf{elif}\;z \leq 9.433316727882347 \cdot 10^{+117}:\\ \;\;\;\;\mathsf{fma}\left(y, 4 \cdot \mathsf{fma}\left(z, -z, t\right), x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, y \cdot \left(z \cdot -4\right), x \cdot x\right)\\ \end{array} \]

Reproduce

herbie shell --seed 2022130 
(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))))