?

Average Error: 5.9 → 0.2
Time: 13.1s
Precision: binary64
Cost: 7428

?

\[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^{+276}:\\ \;\;\;\;x \cdot x + y \cdot \left(\mathsf{fma}\left(z, z, -t\right) \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\ \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+276)
   (+ (* x x) (* y (* (fma z z (- t)) -4.0)))
   (+ (* x x) (* z (/ (* y 4.0) (/ -1.0 z))))))
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+276) {
		tmp = (x * x) + (y * (fma(z, z, -t) * -4.0));
	} else {
		tmp = (x * x) + (z * ((y * 4.0) / (-1.0 / z)));
	}
	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+276)
		tmp = Float64(Float64(x * x) + Float64(y * Float64(fma(z, z, Float64(-t)) * -4.0)));
	else
		tmp = Float64(Float64(x * x) + Float64(z * Float64(Float64(y * 4.0) / Float64(-1.0 / z))));
	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+276], N[(N[(x * x), $MachinePrecision] + N[(y * N[(N[(z * z + (-t)), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(z * N[(N[(y * 4.0), $MachinePrecision] / N[(-1.0 / z), $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 2 \cdot 10^{+276}:\\
\;\;\;\;x \cdot x + y \cdot \left(\mathsf{fma}\left(z, z, -t\right) \cdot -4\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\


\end{array}

Error?

Target

Original5.9
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.0000000000000001e276

    1. Initial program 0.1

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

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

      [Start]0.1

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

      associate-*l* [=>]0.1

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

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

    if 2.0000000000000001e276 < (*.f64 z z)

    1. Initial program 54.2

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

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

      [Start]54.2

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

      associate-*l* [=>]54.3

      \[ x \cdot x - \color{blue}{y \cdot \left(4 \cdot \left(z \cdot z - t\right)\right)} \]
    3. Applied egg-rr54.3

      \[\leadsto x \cdot x - \color{blue}{\frac{y \cdot 4}{\frac{1}{z \cdot z - t}}} \]
    4. Taylor expanded in z around inf 54.6

      \[\leadsto x \cdot x - \frac{y \cdot 4}{\color{blue}{\frac{1}{{z}^{2}}}} \]
    5. Simplified51.7

      \[\leadsto x \cdot x - \frac{y \cdot 4}{\color{blue}{\frac{\frac{1}{z}}{z}}} \]
      Proof

      [Start]54.6

      \[ x \cdot x - \frac{y \cdot 4}{\frac{1}{{z}^{2}}} \]

      unpow2 [=>]54.6

      \[ x \cdot x - \frac{y \cdot 4}{\frac{1}{\color{blue}{z \cdot z}}} \]

      associate-/r* [=>]51.7

      \[ x \cdot x - \frac{y \cdot 4}{\color{blue}{\frac{\frac{1}{z}}{z}}} \]
    6. Applied egg-rr0.7

      \[\leadsto x \cdot x - \color{blue}{\frac{y \cdot 4}{\frac{-1}{z}} \cdot \left(-z\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^{+276}:\\ \;\;\;\;x \cdot x + y \cdot \left(\mathsf{fma}\left(z, z, -t\right) \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\ \end{array} \]

Alternatives

Alternative 1
Error7.3
Cost1744
\[\begin{array}{l} t_1 := x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{-22}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{elif}\;z \cdot z \leq 2000000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+304}:\\ \;\;\;\;x \cdot x - y \cdot \left(\left(z \cdot z\right) \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;-4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 2
Error6.5
Cost1484
\[\begin{array}{l} t_1 := x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{-22}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{elif}\;z \cdot z \leq 2000000000000:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\ \end{array} \]
Alternative 3
Error26.8
Cost1372
\[\begin{array}{l} t_1 := -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ t_2 := 4 \cdot \left(y \cdot t\right)\\ \mathbf{if}\;x \leq -4.5 \cdot 10^{-15}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -1.02 \cdot 10^{-112}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -8.4 \cdot 10^{-157}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4 \cdot 10^{-173}:\\ \;\;\;\;y \cdot \left(4 \cdot t\right)\\ \mathbf{elif}\;x \leq 3 \cdot 10^{-156}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{-101}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.35 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 4
Error26.7
Cost1372
\[\begin{array}{l} t_1 := -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ t_2 := 4 \cdot \left(y \cdot t\right)\\ \mathbf{if}\;x \leq -5.2 \cdot 10^{-13}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -7 \cdot 10^{-113}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7.8 \cdot 10^{-152}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 4.6 \cdot 10^{-173}:\\ \;\;\;\;y \cdot \left(4 \cdot t\right)\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-157}:\\ \;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;x \leq 1.45 \cdot 10^{-100}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-30}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 5
Error8.7
Cost1104
\[\begin{array}{l} t_1 := \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ t_2 := -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;z \leq -3.5 \cdot 10^{+91}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.9 \cdot 10^{-50}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 780000:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \leq 5 \cdot 10^{+137}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error0.3
Cost1097
\[\begin{array}{l} \mathbf{if}\;z \leq -3.5 \cdot 10^{+91} \lor \neg \left(z \leq 1.5 \cdot 10^{+139}\right):\\ \;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + y \cdot \left(4 \cdot \left(t - z \cdot z\right)\right)\\ \end{array} \]
Alternative 7
Error0.2
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+276}:\\ \;\;\;\;x \cdot x + y \cdot \left(4 \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\ \end{array} \]
Alternative 8
Error15.8
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{+41}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 21000:\\ \;\;\;\;\left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 9
Error25.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -7 \cdot 10^{-21}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-65}:\\ \;\;\;\;4 \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 10
Error25.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.4 \cdot 10^{-14}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-65}:\\ \;\;\;\;y \cdot \left(4 \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 11
Error41.0
Cost192
\[x \cdot x \]

Error

Reproduce?

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