?

Average Accuracy: 90.9% → 99.5%
Time: 14.9s
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 10^{+222}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot z - t, y \cdot -4, x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\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) 1e+222)
   (fma (- (* z z) t) (* y -4.0) (* x x))
   (fma x x (* z (* z (* y -4.0))))))
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) <= 1e+222) {
		tmp = fma(((z * z) - t), (y * -4.0), (x * x));
	} else {
		tmp = fma(x, x, (z * (z * (y * -4.0))));
	}
	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) <= 1e+222)
		tmp = fma(Float64(Float64(z * z) - t), Float64(y * -4.0), Float64(x * x));
	else
		tmp = fma(x, x, Float64(z * Float64(z * Float64(y * -4.0))));
	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], 1e+222], N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $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 10^{+222}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot z - t, y \cdot -4, x \cdot x\right)\\

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


\end{array}

Error?

Target

Original90.9%
Target90.9%
Herbie99.5%
\[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) < 1e222

    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) \]

    if 1e222 < (*.f64 z z)

    1. Initial program 40.8%

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

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

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

      [Start]38.2

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

      associate-*r* [=>]38.2

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

      *-commutative [<=]38.2

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

      unpow2 [=>]38.2

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

      associate-*r* [=>]97.1

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

      *-commutative [=>]97.1

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

      *-commutative [=>]97.1

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

      associate-*l* [=>]97.1

      \[ x \cdot x - z \cdot \color{blue}{\left(4 \cdot \left(y \cdot z\right)\right)} \]
    4. Applied egg-rr97.1%

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

      [Start]97.1

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

      fma-neg [=>]97.1

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

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

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

      associate-*r* [=>]97.1

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

      *-commutative [=>]97.1

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

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

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

      *-commutative [=>]97.1

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

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

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

      metadata-eval [=>]97.1

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

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

Alternatives

Alternative 1
Accuracy99.5%
Cost7236
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+222}:\\ \;\;\;\;x \cdot x - \left(\left(z \cdot z\right) \cdot \left(y \cdot 4\right) + t \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\right)\\ \end{array} \]
Alternative 2
Accuracy85.7%
Cost1368
\[\begin{array}{l} t_1 := \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_3 := x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;z \leq -6 \cdot 10^{+135}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -7 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{-69}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.02 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+96}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.4 \cdot 10^{+117}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Accuracy85.7%
Cost1368
\[\begin{array}{l} t_1 := \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_3 := x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;z \leq -1.45 \cdot 10^{+135}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -3.5 \cdot 10^{-8}:\\ \;\;\;\;-4 \cdot \left(\left(z \cdot z\right) \cdot y - t \cdot y\right)\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{-69}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 3.4 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{+96}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.9 \cdot 10^{+117}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Accuracy99.5%
Cost1348
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+222}:\\ \;\;\;\;x \cdot x - \left(\left(z \cdot z\right) \cdot \left(y \cdot 4\right) + t \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 5
Accuracy55.9%
Cost1241
\[\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.6 \cdot 10^{-9}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.4 \cdot 10^{-294}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.65 \cdot 10^{-180}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 6.5 \cdot 10^{-29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+65} \lor \neg \left(z \leq 1.4 \cdot 10^{+98}\right):\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 6
Accuracy55.9%
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 -8.8 \cdot 10^{-9}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.4 \cdot 10^{-294}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.82 \cdot 10^{-182}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{-29}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{+64}:\\ \;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{+98}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Accuracy89.6%
Cost1100
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;z \leq -3.6 \cdot 10^{-9}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.6 \cdot 10^{-69}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{+64}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy99.5%
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+222}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 9
Accuracy76.9%
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -4.7 \cdot 10^{-33} \lor \neg \left(x \leq 3.7 \cdot 10^{+27}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \end{array} \]
Alternative 10
Accuracy60.1%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3.4 \cdot 10^{-33}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-67}:\\ \;\;\;\;4 \cdot \left(t \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 11
Accuracy35.5%
Cost192
\[x \cdot x \]

Error

Reproduce?

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