?

Average Error: 8.64% → 0.55%
Time: 10.7s
Precision: binary64
Cost: 7369

?

\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+150} \lor \neg \left(z \leq 6.6 \cdot 10^{+90}\right):\\ \;\;\;\;x \cdot x + \left(z \cdot \left(z \cdot y\right)\right) \cdot -4\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot z - t, y \cdot -4, 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 (or (<= z -2e+150) (not (<= z 6.6e+90)))
   (+ (* x x) (* (* z (* z y)) -4.0))
   (fma (- (* z z) t) (* y -4.0) (* 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 <= -2e+150) || !(z <= 6.6e+90)) {
		tmp = (x * x) + ((z * (z * y)) * -4.0);
	} else {
		tmp = fma(((z * z) - t), (y * -4.0), (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 ((z <= -2e+150) || !(z <= 6.6e+90))
		tmp = Float64(Float64(x * x) + Float64(Float64(z * Float64(z * y)) * -4.0));
	else
		tmp = fma(Float64(Float64(z * z) - t), Float64(y * -4.0), 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[Or[LessEqual[z, -2e+150], N[Not[LessEqual[z, 6.6e+90]], $MachinePrecision]], N[(N[(x * x), $MachinePrecision] + N[(N[(z * N[(z * y), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision] + 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 \leq -2 \cdot 10^{+150} \lor \neg \left(z \leq 6.6 \cdot 10^{+90}\right):\\
\;\;\;\;x \cdot x + \left(z \cdot \left(z \cdot y\right)\right) \cdot -4\\

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


\end{array}

Error?

Target

Original8.64%
Target8.6%
Herbie0.55%
\[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 < -1.99999999999999996e150 or 6.60000000000000016e90 < z

    1. Initial program 65.43

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

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

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

      [Start]68.32

      \[ x \cdot x - 4 \cdot \left(y \cdot {z}^{2}\right) \]

      unpow2 [=>]68.32

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

      associate-*r* [=>]3.27

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

    if -1.99999999999999996e150 < z < 6.60000000000000016e90

    1. Initial program 0.15

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

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

      [Start]0.15

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

      cancel-sign-sub-inv [=>]0.15

      \[ \color{blue}{x \cdot x + \left(-y \cdot 4\right) \cdot \left(z \cdot z - t\right)} \]

      +-commutative [=>]0.15

      \[ \color{blue}{\left(-y \cdot 4\right) \cdot \left(z \cdot z - t\right) + x \cdot x} \]

      *-commutative [=>]0.15

      \[ \color{blue}{\left(z \cdot z - t\right) \cdot \left(-y \cdot 4\right)} + x \cdot x \]

      fma-def [=>]0.14

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

      distribute-rgt-neg-in [=>]0.14

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

      metadata-eval [=>]0.14

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

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

Alternatives

Alternative 1
Error44.56%
Cost1768
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_2 := t \cdot \left(4 \cdot y\right)\\ \mathbf{if}\;x \leq -2.1 \cdot 10^{+17}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -4.5 \cdot 10^{-10}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{-31}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -4.1 \cdot 10^{-72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.85 \cdot 10^{-300}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-268}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.2 \cdot 10^{-223}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 5.8 \cdot 10^{-205}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-178}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 2
Error14.75%
Cost1236
\[\begin{array}{l} t_1 := \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ t_2 := x \cdot x - t \cdot \left(y \cdot -4\right)\\ t_3 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -2.1 \cdot 10^{+125}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.8 \cdot 10^{-18}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 4.8 \cdot 10^{+73}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9 \cdot 10^{+90}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error11.36%
Cost1100
\[\begin{array}{l} t_1 := x \cdot x + \left(z \cdot \left(z \cdot y\right)\right) \cdot -4\\ \mathbf{if}\;z \leq -5.5 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.6 \cdot 10^{-96}:\\ \;\;\;\;4 \cdot \left(y \cdot t - y \cdot \left(z \cdot z\right)\right)\\ \mathbf{elif}\;z \leq 8.3 \cdot 10^{+40}:\\ \;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error0.55%
Cost1097
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+150} \lor \neg \left(z \leq 6.6 \cdot 10^{+90}\right):\\ \;\;\;\;x \cdot x + \left(z \cdot \left(z \cdot y\right)\right) \cdot -4\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \end{array} \]
Alternative 5
Error40.07%
Cost849
\[\begin{array}{l} \mathbf{if}\;x \leq -38000000000000:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -2.3 \cdot 10^{-9} \lor \neg \left(x \leq -4.8 \cdot 10^{-56}\right) \land x \leq 3.4:\\ \;\;\;\;t \cdot \left(4 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 6
Error23.51%
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -6.2 \cdot 10^{+17}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{+48}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 7
Error64.7%
Cost192
\[x \cdot x \]

Error

Reproduce?

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