Average Error: 5.8 → 0.4
Time: 10.9s
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 -7.8 \cdot 10^{+130}:\\ \;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+93}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\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 -7.8e+130)
   (+ (* x x) (* z (/ (* y 4.0) (/ -1.0 z))))
   (if (<= z 2.7e+93)
     (fma x x (* (* y -4.0) (- (* z z) t)))
     (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 <= -7.8e+130) {
		tmp = (x * x) + (z * ((y * 4.0) / (-1.0 / z)));
	} else if (z <= 2.7e+93) {
		tmp = fma(x, x, ((y * -4.0) * ((z * z) - t)));
	} 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 (z <= -7.8e+130)
		tmp = Float64(Float64(x * x) + Float64(z * Float64(Float64(y * 4.0) / Float64(-1.0 / z))));
	elseif (z <= 2.7e+93)
		tmp = fma(x, x, Float64(Float64(y * -4.0) * Float64(Float64(z * z) - t)));
	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[z, -7.8e+130], N[(N[(x * x), $MachinePrecision] + N[(z * N[(N[(y * 4.0), $MachinePrecision] / N[(-1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2.7e+93], N[(x * x + N[(N[(y * -4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $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 \leq -7.8 \cdot 10^{+130}:\\
\;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\

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

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


\end{array}

Error

Target

Original5.8
Target5.8
Herbie0.4
\[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 < -7.8000000000000004e130

    1. Initial program 49.3

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

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

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

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

      [Start]49.7

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

      unpow2 [=>]49.7

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

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

    if -7.8000000000000004e130 < z < 2.6999999999999999e93

    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.6999999999999999e93 < z

    1. Initial program 33.8

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

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

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

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

      [Start]37.0

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

      *-commutative [=>]37.0

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

      *-commutative [=>]37.0

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

      unpow2 [=>]37.0

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

      associate-*r* [<=]37.0

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

      associate-*l* [=>]3.4

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

      *-commutative [=>]3.4

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

      associate-*l* [=>]3.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{+130}:\\ \;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+93}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\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
Error0.4
Cost7240
\[\begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{+130}:\\ \;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+93}:\\ \;\;\;\;x \cdot x + \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\right)\\ \end{array} \]
Alternative 2
Error8.5
Cost1616
\[\begin{array}{l} t_1 := \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ t_2 := x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;z \cdot z \leq 10^{-55}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 7 \cdot 10^{+135}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 10^{+170}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+260}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 3
Error27.7
Cost1376
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_2 := t \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;x \leq -1.25 \cdot 10^{-65}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -1.8 \cdot 10^{-126}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-212}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-273}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-302}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 8.5 \cdot 10^{-262}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.65 \cdot 10^{-176}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.2 \cdot 10^{-23}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 4
Error6.5
Cost1224
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{-55}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+111}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 5
Error0.4
Cost1097
\[\begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{+130} \lor \neg \left(z \leq 2.7 \cdot 10^{+93}\right):\\ \;\;\;\;x \cdot x + -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \end{array} \]
Alternative 6
Error0.4
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \leq -7.8 \cdot 10^{+130}:\\ \;\;\;\;x \cdot x + z \cdot \frac{y \cdot 4}{\frac{-1}{z}}\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+93}:\\ \;\;\;\;x \cdot x + \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 7
Error14.3
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -115000 \lor \neg \left(x \leq 0.13\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \end{array} \]
Alternative 8
Error24.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{-64}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 3.8 \cdot 10^{-23}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 9
Error41.3
Cost192
\[x \cdot x \]

Error

Reproduce

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