Average Error: 6.0 → 0.2
Time: 13.7s
Precision: binary64
Cost: 7364
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+256}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot \left(y \cdot -4\right), z, x \cdot x\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 (<= (* z z) 2e+256)
   (fma x x (* (- (* z z) t) (* y -4.0)))
   (fma (* z (* y -4.0)) z (* x x))))
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 ((z * z) <= 2e+256) {
		tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
	} else {
		tmp = fma((z * (y * -4.0)), z, (x * x));
	}
	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)
	tmp = 0.0
	if (Float64(z * z) <= 2e+256)
		tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0)));
	else
		tmp = fma(Float64(z * Float64(y * -4.0)), z, Float64(x * x));
	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_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+256], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision] * z + N[(x * x), $MachinePrecision]), $MachinePrecision]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+256}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\

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


\end{array}

Error

Target

Original6.0
Target5.9
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 (*.f64 z z) < 2.0000000000000001e256

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

    if 2.0000000000000001e256 < (*.f64 z z)

    1. Initial program 47.5

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

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

      \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\left(z \cdot z\right)} \]
      Proof
      (*.f64 z z): 0 points increase in error, 0 points decrease in error
      (Rewrite<= unpow2_binary64 (pow.f64 z 2)): 0 points increase in error, 0 points decrease in error
    4. Applied egg-rr1.2

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

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

Alternatives

Alternative 1
Error0.2
Cost7236
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+256}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right) + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot \left(y \cdot -4\right), z, x \cdot x\right)\\ \end{array} \]
Alternative 2
Error27.9
Cost1748
\[\begin{array}{l} t_1 := 4 \cdot \left(t \cdot y\right)\\ \mathbf{if}\;z \cdot z \leq 10^{-307}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 10^{-233}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{-196}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{-137}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{-98}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 3
Error19.3
Cost1740
\[\begin{array}{l} t_1 := z \cdot z - t\\ t_2 := t_1 \cdot \left(y \cdot -4\right)\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-6}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{-129}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+304}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 4
Error7.8
Cost1232
\[\begin{array}{l} t_1 := x \cdot x + \left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{+160}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.0648518555048894 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.422403819666622 \cdot 10^{-55}:\\ \;\;\;\;x \cdot x + y \cdot \left(t \cdot 4\right)\\ \mathbf{elif}\;z \leq 10^{+115}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error26.3
Cost1100
\[\begin{array}{l} t_1 := 4 \cdot \left(t \cdot y\right)\\ \mathbf{if}\;x \cdot x \leq 5.903348252639539 \cdot 10^{-261}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 3.6616406915803755 \cdot 10^{-193}:\\ \;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;x \cdot x \leq 1.9426676544576173 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 6
Error8.0
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{-82}:\\ \;\;\;\;x \cdot x + y \cdot \left(t \cdot 4\right)\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+256}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 7
Error1.3
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+256}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right) + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 8
Error26.2
Cost848
\[\begin{array}{l} t_1 := 4 \cdot \left(t \cdot y\right)\\ \mathbf{if}\;x \leq -1.7599262833541525 \cdot 10^{-63}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 2.1585915846538582 \cdot 10^{-116}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.988158621646355 \cdot 10^{-76}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 1.570961412167542 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 9
Error41.1
Cost192
\[x \cdot x \]

Error

Reproduce

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