?

Average Accuracy: 90.3% → 99.8%
Time: 13.0s
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 -1.35 \cdot 10^{+154} \lor \neg \left(z \leq 3.7 \cdot 10^{+126}\right):\\ \;\;\;\;x \cdot x + z \cdot \left(\left(z \cdot y\right) \cdot -4\right)\\ \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 -1.35e+154) (not (<= z 3.7e+126)))
   (+ (* 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 <= -1.35e+154) || !(z <= 3.7e+126)) {
		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 <= -1.35e+154) || !(z <= 3.7e+126))
		tmp = Float64(Float64(x * x) + Float64(z * Float64(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, -1.35e+154], N[Not[LessEqual[z, 3.7e+126]], $MachinePrecision]], N[(N[(x * x), $MachinePrecision] + N[(z * N[(N[(z * y), $MachinePrecision] * -4.0), $MachinePrecision]), $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 -1.35 \cdot 10^{+154} \lor \neg \left(z \leq 3.7 \cdot 10^{+126}\right):\\
\;\;\;\;x \cdot x + z \cdot \left(\left(z \cdot y\right) \cdot -4\right)\\

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


\end{array}

Error?

Target

Original90.3%
Target90.3%
Herbie99.8%
\[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.35000000000000003e154 or 3.6999999999999998e126 < z

    1. Initial program 15.3%

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

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

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

      [Start]15.1

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

      associate-*r* [=>]15.1

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

      *-commutative [<=]15.1

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

      unpow2 [=>]15.1

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

      associate-*r* [=>]99.4

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

      *-commutative [=>]99.4

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

      *-commutative [=>]99.4

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

      associate-*l* [=>]99.4

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

    if -1.35000000000000003e154 < z < 3.6999999999999998e126

    1. Initial program 99.9%

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

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

      [Start]99.9

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

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

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

      +-commutative [=>]99.9

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

      *-commutative [=>]99.9

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

      fma-def [=>]99.9

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

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

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

      metadata-eval [=>]99.9

      \[ \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 simplification99.8%

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

Alternatives

Alternative 1
Accuracy99.8%
Cost7369
\[\begin{array}{l} \mathbf{if}\;z \leq -5.4 \cdot 10^{+147} \lor \neg \left(z \leq 1.45 \cdot 10^{+128}\right):\\ \;\;\;\;x \cdot x + z \cdot \left(\left(z \cdot y\right) \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 2
Accuracy56.3%
Cost1372
\[\begin{array}{l} t_1 := t \cdot \left(4 \cdot y\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -9.6 \cdot 10^{+40}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.85 \cdot 10^{-34}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 1.36 \cdot 10^{-253}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.16 \cdot 10^{-211}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-176}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-96}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 1.05 \cdot 10^{-29}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Accuracy87.2%
Cost1104
\[\begin{array}{l} t_1 := \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -8.8 \cdot 10^{+142}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.45 \cdot 10^{+40}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2 \cdot 10^{-18}:\\ \;\;\;\;x \cdot x + t \cdot \left(4 \cdot y\right)\\ \mathbf{elif}\;z \leq 1.45 \cdot 10^{+128}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Accuracy89.5%
Cost1100
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(\left(z \cdot y\right) \cdot -4\right)\\ \mathbf{if}\;z \leq -2.6 \cdot 10^{+106}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6.2 \cdot 10^{+40}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-29}:\\ \;\;\;\;x \cdot x + t \cdot \left(4 \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Accuracy99.8%
Cost1097
\[\begin{array}{l} \mathbf{if}\;z \leq -6.3 \cdot 10^{+147} \lor \neg \left(z \leq 1.3 \cdot 10^{+128}\right):\\ \;\;\;\;x \cdot x + z \cdot \left(\left(z \cdot y\right) \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - \left(z \cdot z - t\right) \cdot \left(4 \cdot y\right)\\ \end{array} \]
Alternative 6
Accuracy74.1%
Cost844
\[\begin{array}{l} \mathbf{if}\;x \leq -2.6 \cdot 10^{+17}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 1.05 \cdot 10^{-86}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;x \leq 1.7 \cdot 10^{-29}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 7
Accuracy58.8%
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{+17} \lor \neg \left(x \leq 1.2 \cdot 10^{-70}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(4 \cdot y\right)\\ \end{array} \]
Alternative 8
Accuracy34.9%
Cost192
\[x \cdot x \]

Error

Reproduce?

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