Average Error: 5.7 → 0.5
Time: 23.4s
Precision: binary64
Cost: 8264
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} t_1 := \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;\mathsf{fma}\left(x, x, \begin{array}{l} \mathbf{if}\;y \cdot z \ne 0:\\ \;\;\;\;\frac{z \cdot -4}{\frac{1}{y \cdot z}}\\ \mathbf{else}:\\ \;\;\;\;\left(-4 \cdot y\right) \cdot \left(z \cdot z\right)\\ \end{array}\right)\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+293}:\\ \;\;\;\;x \cdot x - t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(\left(-4 \cdot y\right) \cdot z\right) \cdot z\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 (* (* y 4.0) (- (* z z) t))))
   (if (<= t_1 (- INFINITY))
     (fma
      x
      x
      (if (!= (* y z) 0.0)
        (/ (* z -4.0) (/ 1.0 (* y z)))
        (* (* -4.0 y) (* z z))))
     (if (<= t_1 2e+293) (- (* x x) t_1) (fma x x (* (* (* -4.0 y) z) z))))))
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 = (y * 4.0) * ((z * z) - t);
	double tmp_1;
	if (t_1 <= -((double) INFINITY)) {
		double tmp_2;
		if ((y * z) != 0.0) {
			tmp_2 = (z * -4.0) / (1.0 / (y * z));
		} else {
			tmp_2 = (-4.0 * y) * (z * z);
		}
		tmp_1 = fma(x, x, tmp_2);
	} else if (t_1 <= 2e+293) {
		tmp_1 = (x * x) - t_1;
	} else {
		tmp_1 = fma(x, x, (((-4.0 * y) * z) * z));
	}
	return tmp_1;
}
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(y * 4.0) * Float64(Float64(z * z) - t))
	tmp_1 = 0.0
	if (t_1 <= Float64(-Inf))
		tmp_2 = 0.0
		if (Float64(y * z) != 0.0)
			tmp_2 = Float64(Float64(z * -4.0) / Float64(1.0 / Float64(y * z)));
		else
			tmp_2 = Float64(Float64(-4.0 * y) * Float64(z * z));
		end
		tmp_1 = fma(x, x, tmp_2);
	elseif (t_1 <= 2e+293)
		tmp_1 = Float64(Float64(x * x) - t_1);
	else
		tmp_1 = fma(x, x, Float64(Float64(Float64(-4.0 * y) * z) * z));
	end
	return tmp_1
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[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(x * x + If[Unequal[N[(y * z), $MachinePrecision], 0.0], N[(N[(z * -4.0), $MachinePrecision] / N[(1.0 / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-4.0 * y), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision], If[LessEqual[t$95$1, 2e+293], N[(N[(x * x), $MachinePrecision] - t$95$1), $MachinePrecision], N[(x * x + N[(N[(N[(-4.0 * y), $MachinePrecision] * z), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
t_1 := \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\mathsf{fma}\left(x, x, \begin{array}{l}
\mathbf{if}\;y \cdot z \ne 0:\\
\;\;\;\;\frac{z \cdot -4}{\frac{1}{y \cdot z}}\\

\mathbf{else}:\\
\;\;\;\;\left(-4 \cdot y\right) \cdot \left(z \cdot z\right)\\


\end{array}\right)\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+293}:\\
\;\;\;\;x \cdot x - t_1\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(\left(-4 \cdot y\right) \cdot z\right) \cdot z\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 3 regimes
  2. if (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)) < -inf.0

    1. Initial program 64.0

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Taylor expanded in t around 0 64.0

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;y \cdot z \ne 0:\\ \;\;\;\;\frac{z \cdot -4}{\frac{1}{y \cdot z}}\\ \mathbf{else}:\\ \;\;\;\;\left(-4 \cdot y\right) \cdot \left(z \cdot z\right)\\ } \end{array}}\right) \]

    if -inf.0 < (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)) < 1.9999999999999998e293

    1. Initial program 0.1

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

    if 1.9999999999999998e293 < (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))

    1. Initial program 53.0

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Taylor expanded in t around 0 59.9

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

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

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

Alternatives

Alternative 1
Error0.2
Cost7236
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+269}:\\ \;\;\;\;x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(\left(-4 \cdot y\right) \cdot z\right) \cdot z\right)\\ \end{array} \]
Alternative 2
Error13.1
Cost1104
\[\begin{array}{l} t_1 := x \cdot x - \left(-4 \cdot y\right) \cdot t\\ t_2 := \left(\left(-4 \cdot y\right) \cdot z\right) \cdot z\\ \mathbf{if}\;z \leq -1.85 \cdot 10^{+140}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 250000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.5 \cdot 10^{+65}:\\ \;\;\;\;\left(-4 \cdot y\right) \cdot \left(z \cdot z\right)\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+144}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error0.2
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+269}:\\ \;\;\;\;x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\left(-4 \cdot y\right) \cdot z\right) \cdot z + x \cdot x\\ \end{array} \]
Alternative 4
Error6.5
Cost968
\[\begin{array}{l} t_1 := \left(\left(-4 \cdot y\right) \cdot z\right) \cdot z + x \cdot x\\ \mathbf{if}\;z \leq -22000000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 12500000:\\ \;\;\;\;x \cdot x - \left(-4 \cdot y\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error26.1
Cost848
\[\begin{array}{l} t_1 := \left(t \cdot 4\right) \cdot y\\ \mathbf{if}\;x \leq -4.55 \cdot 10^{-10}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 6.1 \cdot 10^{-24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{+34}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 4.4 \cdot 10^{+59}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 6
Error41.9
Cost192
\[x \cdot x \]

Error

Reproduce

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