Average Error: 5.7 → 0.5
Time: 4.6s
Precision: binary64
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} t_1 := z \cdot z - t\\ \mathbf{if}\;t_1 \leq 2 \cdot 10^{+287}:\\ \;\;\;\;\mathsf{fma}\left(y, t_1 \cdot -4, 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} \]
(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 (- (* z z) t)))
   (if (<= t_1 2e+287)
     (fma y (* t_1 -4.0) (* x x))
     (fma x x (* z (* z (* y -4.0)))))))
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 = (z * z) - t;
	double tmp;
	if (t_1 <= 2e+287) {
		tmp = fma(y, (t_1 * -4.0), (x * x));
	} else {
		tmp = fma(x, x, (z * (z * (y * -4.0))));
	}
	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 = Float64(Float64(z * z) - t)
	tmp = 0.0
	if (t_1 <= 2e+287)
		tmp = fma(y, Float64(t_1 * -4.0), Float64(x * x));
	else
		tmp = fma(x, x, Float64(z * Float64(z * Float64(y * -4.0))));
	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[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]}, If[LessEqual[t$95$1, 2e+287], N[(y * N[(t$95$1 * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
t_1 := z \cdot z - t\\
\mathbf{if}\;t_1 \leq 2 \cdot 10^{+287}:\\
\;\;\;\;\mathsf{fma}\left(y, t_1 \cdot -4, 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}

Error

Target

Original5.7
Target5.7
Herbie0.5
\[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 z z) t) < 2.0000000000000002e287

    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, \left(z \cdot z - t\right) \cdot -4, x \cdot x\right)} \]

    if 2.0000000000000002e287 < (-.f64 (*.f64 z z) t)

    1. Initial program 51.7

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z - t \leq 2 \cdot 10^{+287}:\\ \;\;\;\;\mathsf{fma}\left(y, \left(z \cdot z - t\right) \cdot -4, 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 2022210 
(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))))