?

Average Error: 8.93% → 0.51%
Time: 10.8s
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 5 \cdot 10^{+233}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, z \cdot \left(y \cdot -4\right), 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) 5e+233)
   (fma x x (* (- (* z z) t) (* y -4.0)))
   (fma z (* z (* 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 * z) <= 5e+233) {
		tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
	} else {
		tmp = fma(z, (z * (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 (Float64(z * z) <= 5e+233)
		tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0)));
	else
		tmp = fma(z, Float64(z * 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[LessEqual[N[(z * z), $MachinePrecision], 5e+233], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $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 \cdot z \leq 5 \cdot 10^{+233}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\

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


\end{array}

Error?

Target

Original8.93%
Target8.91%
Herbie0.51%
\[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) < 5.00000000000000009e233

    1. Initial program 0.12

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

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

      [Start]0.12

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

      fma-neg [=>]0.12

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

      distribute-lft-neg-in [=>]0.12

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

      *-commutative [=>]0.12

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

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

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

      metadata-eval [=>]0.12

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

    if 5.00000000000000009e233 < (*.f64 z z)

    1. Initial program 66.74

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

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

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

      [Start]69.37

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

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

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

      metadata-eval [=>]69.37

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

      unpow2 [=>]69.37

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

      associate-*r* [=>]69.37

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

      *-commutative [<=]69.37

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

      unpow2 [=>]69.36

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

      +-commutative [=>]69.36

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

      associate-*r* [=>]3.07

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

      *-commutative [<=]3.07

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

      fma-def [=>]3.06

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

      *-commutative [=>]3.06

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

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

Alternatives

Alternative 1
Error0.51%
Cost7236
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+233}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right) + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, z \cdot \left(y \cdot -4\right), x \cdot x\right)\\ \end{array} \]
Alternative 2
Error28.84%
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 -4 \cdot 10^{-158}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-165}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+306}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 3
Error42.54%
Cost1240
\[\begin{array}{l} t_1 := 4 \cdot \left(t \cdot y\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -3.55 \cdot 10^{+34}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.7 \cdot 10^{-212}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 1.16 \cdot 10^{-306}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-297}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 10^{-40}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error10.91%
Cost1232
\[\begin{array}{l} t_1 := \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ t_2 := x \cdot x + -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;z \leq -9.4 \cdot 10^{+92}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-61}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-61}:\\ \;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;z \leq 2.3 \cdot 10^{+69}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error13.33%
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 1.5 \cdot 10^{-121}:\\ \;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+233}:\\ \;\;\;\;\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 6
Error0.51%
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+233}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right) + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 7
Error41.24%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -5.8 \cdot 10^{+14}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 2.2 \cdot 10^{+58}:\\ \;\;\;\;4 \cdot \left(t \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 8
Error64.78%
Cost192
\[x \cdot x \]

Error

Reproduce?

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