?

Average Error: 9.27% → 0.19%
Time: 12.5s
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 2 \cdot 10^{+304}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\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) 2e+304)
   (fma x x (* (- (* z z) t) (* y -4.0)))
   (- (* 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) <= 2e+304) {
		tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
	} else {
		tmp = (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) <= 2e+304)
		tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0)));
	else
		tmp = Float64(Float64(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], 2e+304], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - 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 2 \cdot 10^{+304}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\

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


\end{array}

Error?

Target

Original9.27%
Target9.21%
Herbie0.19%
\[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) < 1.9999999999999999e304

    1. Initial program 0.17

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

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

      [Start]0.17

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

      fma-neg [=>]0.16

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

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

      *-commutative [=>]0.16

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

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

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

    if 1.9999999999999999e304 < (*.f64 z z)

    1. Initial program 97.34

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

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

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

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

      [Start]97.35

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

      unpow2 [=>]97.35

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

      associate-/r* [=>]90.88

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

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

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

Alternatives

Alternative 1
Error31.09%
Cost1878
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 9.5 \cdot 10^{-265} \lor \neg \left(x \cdot x \leq 1.7 \cdot 10^{-191}\right) \land \left(x \cdot x \leq 8.5 \cdot 10^{-119} \lor \neg \left(x \cdot x \leq 8 \cdot 10^{-88}\right) \land x \cdot x \leq 1.05 \cdot 10^{+97}\right):\\ \;\;\;\;y \cdot \left(\left(z \cdot z - t\right) \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 2
Error11.92%
Cost1744
\[\begin{array}{l} t_1 := x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-112}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 4 \cdot 10^{+94}:\\ \;\;\;\;y \cdot \left(\left(z \cdot z - t\right) \cdot -4\right)\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+305}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 3
Error43.45%
Cost1622
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 1.02 \cdot 10^{-268} \lor \neg \left(x \cdot x \leq 1.7 \cdot 10^{-191}\right) \land \left(x \cdot x \leq 10^{-118} \lor \neg \left(x \cdot x \leq 8 \cdot 10^{-87}\right) \land x \cdot x \leq 0.0055\right):\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 4
Error10.78%
Cost1485
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-112}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+66} \lor \neg \left(z \cdot z \leq 4 \cdot 10^{+94}\right):\\ \;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(\left(z \cdot z - t\right) \cdot -4\right)\\ \end{array} \]
Alternative 5
Error0.23%
Cost1348
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+304}:\\ \;\;\;\;\left(x \cdot x + y \cdot \left(t \cdot 4\right)\right) - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\ \end{array} \]
Alternative 6
Error14.06%
Cost1236
\[\begin{array}{l} t_1 := y \cdot \left(\left(z \cdot z - t\right) \cdot -4\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 -5 \cdot 10^{+156}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2100000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{-54}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 1.72 \cdot 10^{+28}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3 \cdot 10^{+52}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error0.19%
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+304}:\\ \;\;\;\;x \cdot x - \left(z \cdot z - t\right) \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\ \end{array} \]
Alternative 8
Error41.65%
Cost976
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -1450000000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.6 \cdot 10^{-43}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 1.4 \cdot 10^{-89}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \leq 6 \cdot 10^{-54}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error64.55%
Cost192
\[x \cdot x \]

Error

Reproduce?

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