Average Error: 6.1 → 1.0
Time: 11.1s
Precision: binary64
Cost: 7368
\[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}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{+62}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - \frac{z}{\frac{\frac{1}{z \cdot y} \cdot -0.25}{-1}}\\ \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 -1.35e+154)
   (* z (* z (* y -4.0)))
   (if (<= z 2.05e+62)
     (fma x x (* (* y -4.0) (- (* z z) t)))
     (- (* x x) (/ z (/ (* (/ 1.0 (* z y)) -0.25) -1.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 <= -1.35e+154) {
		tmp = z * (z * (y * -4.0));
	} else if (z <= 2.05e+62) {
		tmp = fma(x, x, ((y * -4.0) * ((z * z) - t)));
	} else {
		tmp = (x * x) - (z / (((1.0 / (z * y)) * -0.25) / -1.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 (z <= -1.35e+154)
		tmp = Float64(z * Float64(z * Float64(y * -4.0)));
	elseif (z <= 2.05e+62)
		tmp = fma(x, x, Float64(Float64(y * -4.0) * Float64(Float64(z * z) - t)));
	else
		tmp = Float64(Float64(x * x) - Float64(z / Float64(Float64(Float64(1.0 / Float64(z * y)) * -0.25) / -1.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[z, -1.35e+154], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.05e+62], N[(x * x + N[(N[(y * -4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(z / N[(N[(N[(1.0 / N[(z * y), $MachinePrecision]), $MachinePrecision] * -0.25), $MachinePrecision] / -1.0), $MachinePrecision]), $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}:\\
\;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\

\mathbf{elif}\;z \leq 2.05 \cdot 10^{+62}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\right)\\

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


\end{array}

Error

Target

Original6.1
Target6.1
Herbie1.0
\[x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right) \]

Derivation

  1. Split input into 3 regimes
  2. if z < -1.35000000000000003e154

    1. Initial program 64.0

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

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

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

      [Start]64.0

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

      associate-*r* [=>]64.0

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

      *-commutative [<=]64.0

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

      unpow2 [=>]64.0

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

      *-commutative [<=]64.0

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

      associate-*l* [=>]6.9

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

    if -1.35000000000000003e154 < z < 2.04999999999999992e62

    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}{\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)} \]
      Proof

      [Start]0.1

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

      fma-neg [=>]0.1

      \[ \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.1

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

      *-commutative [=>]0.1

      \[ \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.1

      \[ \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.1

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

    if 2.04999999999999992e62 < z

    1. Initial program 27.4

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Applied egg-rr27.4

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

      \[\leadsto x \cdot x - \frac{y \cdot 4}{\color{blue}{\frac{1}{{z}^{2}}}} \]
    4. Simplified31.0

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

      [Start]32.7

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

      unpow2 [=>]32.7

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

      associate-/r* [=>]31.0

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

      \[\leadsto x \cdot x - \color{blue}{\frac{y \cdot -4}{\frac{1}{z}} \cdot \left(-z\right)} \]
    6. Applied egg-rr5.6

      \[\leadsto x \cdot x - \color{blue}{\frac{z}{\frac{\frac{1}{y \cdot z} \cdot -0.25}{-1}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{+62}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - \frac{z}{\frac{\frac{1}{z \cdot y} \cdot -0.25}{-1}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost2120
\[\begin{array}{l} t_1 := z \cdot z - t\\ t_2 := t_1 \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+305}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot t_1 + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \frac{y \cdot -4}{\frac{1}{z}}\\ \end{array} \]
Alternative 2
Error6.7
Cost1484
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-44}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+54}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{elif}\;z \cdot z \leq 4 \cdot 10^{+300}:\\ \;\;\;\;x \cdot x + \left(y \cdot -4\right) \cdot \left(z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 3
Error1.0
Cost1224
\[\begin{array}{l} \mathbf{if}\;z \leq -1.3 \cdot 10^{+154}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{+62}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right) + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - \frac{z}{\frac{\frac{1}{z \cdot y} \cdot -0.25}{-1}}\\ \end{array} \]
Alternative 4
Error7.8
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-44}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \cdot z \leq 4 \cdot 10^{+300}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 5
Error0.8
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+300}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right) + x \cdot x\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 6
Error27.9
Cost976
\[\begin{array}{l} t_1 := t \cdot \left(y \cdot 4\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -2.5 \cdot 10^{-63}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.15 \cdot 10^{-173}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -6.5 \cdot 10^{-234}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 6.2 \cdot 10^{+27}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error15.6
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -55000000000 \lor \neg \left(x \leq 2.4 \cdot 10^{-54}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \end{array} \]
Alternative 8
Error25.3
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -1.05 \cdot 10^{-5} \lor \neg \left(x \leq 1.6 \cdot 10^{-66}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \end{array} \]
Alternative 9
Error41.1
Cost192
\[x \cdot x \]

Error

Reproduce

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