Average Error: 6.1 → 0.1
Time: 15.1s
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^{+300}:\\ \;\;\;\;\mathsf{fma}\left(z \cdot z - t, y \cdot -4, x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, -4 \cdot \left(z \cdot \left(z \cdot y\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 z) 1e+300)
   (fma (- (* z z) t) (* y -4.0) (* x x))
   (fma x x (* -4.0 (* z (* z y))))))
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+300) {
		tmp = fma(((z * z) - t), (y * -4.0), (x * x));
	} else {
		tmp = fma(x, x, (-4.0 * (z * (z * y))));
	}
	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+300)
		tmp = fma(Float64(Float64(z * z) - t), Float64(y * -4.0), Float64(x * x));
	else
		tmp = fma(x, x, Float64(-4.0 * Float64(z * Float64(z * y))));
	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+300], N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(-4.0 * N[(z * N[(z * y), $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^{+300}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot z - t, y \cdot -4, x \cdot x\right)\\

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


\end{array}

Error

Target

Original6.1
Target6.0
Herbie0.1
\[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.0000000000000001e300

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

      [Start]0.1

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

      cancel-sign-sub-inv [=>]0.1

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

      +-commutative [=>]0.1

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

      *-commutative [=>]0.1

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

      fma-def [=>]0.1

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

      distribute-rgt-neg-in [=>]0.1

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

      metadata-eval [=>]0.1

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

    if 1.0000000000000001e300 < (*.f64 z z)

    1. Initial program 60.4

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

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

      [Start]60.4

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

      fma-neg [=>]60.4

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

      distribute-lft-neg-in [=>]60.4

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

      *-commutative [=>]60.4

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

      distribute-rgt-neg-in [=>]60.4

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

      metadata-eval [=>]60.4

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

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

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

      [Start]60.4

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

      unpow2 [=>]60.4

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

      associate-*r* [=>]0.3

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

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

Alternatives

Alternative 1
Error0.1
Cost7364
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+300}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\right)\\ \end{array} \]
Alternative 2
Error0.1
Cost7236
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+300}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\right)\\ \end{array} \]
Alternative 3
Error20.9
Cost1632
\[\begin{array}{l} t_1 := \left(y \cdot 4\right) \cdot \left(t - z \cdot z\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 -2.55 \cdot 10^{-49}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -2.9 \cdot 10^{-106}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq -7 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.4 \cdot 10^{-176}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 7 \cdot 10^{-297}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-275}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+152}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error27.5
Cost1372
\[\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 -1 \cdot 10^{+19}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5.8 \cdot 10^{-109}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq -3.55 \cdot 10^{-155}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.55 \cdot 10^{-179}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-295}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-275}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 3.35 \cdot 10^{-52}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error6.8
Cost1224
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 4 \cdot 10^{+18}:\\ \;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+223}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 6
Error7.8
Cost1104
\[\begin{array}{l} t_1 := \left(y \cdot 4\right) \cdot \left(t - z \cdot z\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 -0.82:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1600000000:\\ \;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;z \leq 4.05 \cdot 10^{+152}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error0.1
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+300}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(-4 \cdot \left(z \cdot y\right)\right)\\ \end{array} \]
Alternative 8
Error25.8
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -5.4 \cdot 10^{-84} \lor \neg \left(x \leq 6.2 \cdot 10^{-61}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \end{array} \]
Alternative 9
Error41.6
Cost192
\[x \cdot x \]

Error

Reproduce

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