Average Error: 5.8 → 0.4
Time: 5.2s
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(x, x, z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{+125}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9.8 \cdot 10^{+89}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot -4, z \cdot z - t, 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 x x (* z (* z (* y -4.0))))))
   (if (<= z -1e+125)
     t_1
     (if (<= z 9.8e+89) (fma (* y -4.0) (- (* 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(x, x, (z * (z * (y * -4.0))));
	double tmp;
	if (z <= -1e+125) {
		tmp = t_1;
	} else if (z <= 9.8e+89) {
		tmp = fma((y * -4.0), ((z * z) - t), (x * x));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t)))
end
function code(x, y, z, t)
	t_1 = fma(x, x, Float64(z * Float64(z * Float64(y * -4.0))))
	tmp = 0.0
	if (z <= -1e+125)
		tmp = t_1;
	elseif (z <= 9.8e+89)
		tmp = fma(Float64(y * -4.0), Float64(Float64(z * z) - t), Float64(x * x));
	else
		tmp = t_1;
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x * x + N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1e+125], t$95$1, If[LessEqual[z, 9.8e+89], N[(N[(y * -4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
t_1 := \mathsf{fma}\left(x, x, z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\right)\\
\mathbf{if}\;z \leq -1 \cdot 10^{+125}:\\
\;\;\;\;t_1\\

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

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


\end{array}

Error

Bits error versus x

Bits error versus y

Bits error versus z

Bits error versus t

Target

Original5.8
Target5.8
Herbie0.4
\[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 < -9.9999999999999992e124 or 9.79999999999999992e89 < z

    1. Initial program 37.0

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

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

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

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

    if -9.9999999999999992e124 < z < 9.79999999999999992e89

    1. Initial program 0.1

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Applied egg-rr0.1

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

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

Reproduce

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