?

Average Error: 6.2 → 0.2
Time: 13.2s
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^{+258}:\\ \;\;\;\;\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) 1e+258)
   (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) <= 1e+258) {
		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) <= 1e+258)
		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], 1e+258], 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 10^{+258}:\\
\;\;\;\;\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

Original6.2
Target6.2
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) < 1.00000000000000006e258

    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 1.00000000000000006e258 < (*.f64 z z)

    1. Initial program 48.7

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

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

      [Start]48.7

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

      associate-*l* [=>]48.7

      \[ x \cdot x - \color{blue}{y \cdot \left(4 \cdot \left(z \cdot z - t\right)\right)} \]
    3. Taylor expanded in z around inf 49.3

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

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

      [Start]49.3

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

      *-commutative [=>]49.3

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

      *-commutative [=>]49.3

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

      unpow2 [=>]49.3

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

      associate-*r* [<=]49.3

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

      associate-*l* [=>]0.9

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

      *-commutative [=>]0.9

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+258}:\\ \;\;\;\;\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
Error19.0
Cost1740
\[\begin{array}{l} t_1 := z \cdot z - t\\ t_2 := t_1 \cdot \left(y \cdot -4\right)\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-185}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-35}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+307}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 2
Error8.5
Cost1108
\[\begin{array}{l} t_1 := \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -1.32 \cdot 10^{+154}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -4.4 \cdot 10^{-69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-18}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \leq 3.1 \cdot 10^{+80}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.3 \cdot 10^{+87}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error6.5
Cost1100
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -9.2 \cdot 10^{+92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-69}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;z \leq 3.9 \cdot 10^{-23}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error0.2
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+258}:\\ \;\;\;\;x \cdot x + y \cdot \left(\left(z \cdot z - t\right) \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 5
Error25.7
Cost713
\[\begin{array}{l} \mathbf{if}\;z \leq -1.75 \cdot 10^{+40} \lor \neg \left(z \leq 2.85 \cdot 10^{-22}\right):\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \left(t \cdot y\right)\\ \end{array} \]
Alternative 6
Error25.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -2.1 \cdot 10^{+19}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 205000000000:\\ \;\;\;\;4 \cdot \left(t \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 7
Error42.0
Cost192
\[x \cdot x \]

Error

Reproduce?

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