?

Average Error: 6.2 → 0.2
Time: 15.4s
Precision: binary64
Cost: 7368

?

\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} t_1 := z \cdot \left(y \cdot -4\right)\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+112}:\\ \;\;\;\;x \cdot x + z \cdot t_1\\ \mathbf{elif}\;z \leq 2 \cdot 10^{+136}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(4 \cdot y\right) \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t_1, x \cdot x\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
 (let* ((t_1 (* z (* y -4.0))))
   (if (<= z -2.4e+112)
     (+ (* x x) (* z t_1))
     (if (<= z 2e+136)
       (fma x x (* (* 4.0 y) (- t (* z z))))
       (fma z t_1 (* x x))))))
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 t_1 = z * (y * -4.0);
	double tmp;
	if (z <= -2.4e+112) {
		tmp = (x * x) + (z * t_1);
	} else if (z <= 2e+136) {
		tmp = fma(x, x, ((4.0 * y) * (t - (z * z))));
	} else {
		tmp = fma(z, t_1, (x * x));
	}
	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)
	t_1 = Float64(z * Float64(y * -4.0))
	tmp = 0.0
	if (z <= -2.4e+112)
		tmp = Float64(Float64(x * x) + Float64(z * t_1));
	elseif (z <= 2e+136)
		tmp = fma(x, x, Float64(Float64(4.0 * y) * Float64(t - Float64(z * z))));
	else
		tmp = fma(z, t_1, Float64(x * x));
	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_] := Block[{t$95$1 = N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -2.4e+112], N[(N[(x * x), $MachinePrecision] + N[(z * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 2e+136], N[(x * x + N[(N[(4.0 * y), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * t$95$1 + N[(x * x), $MachinePrecision]), $MachinePrecision]]]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
t_1 := z \cdot \left(y \cdot -4\right)\\
\mathbf{if}\;z \leq -2.4 \cdot 10^{+112}:\\
\;\;\;\;x \cdot x + z \cdot t_1\\

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

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, t_1, x \cdot x\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 3 regimes
  2. if z < -2.4e112

    1. Initial program 41.1

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

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

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

      [Start]42.0

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

      *-commutative [=>]42.0

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

      *-commutative [=>]42.0

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

      unpow2 [=>]42.0

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

      associate-*r* [<=]42.0

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

      associate-*l* [=>]1.1

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

      *-commutative [=>]1.1

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

    if -2.4e112 < z < 2.00000000000000012e136

    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.00000000000000012e136 < z

    1. Initial program 52.6

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

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

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

      [Start]53.2

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

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

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

      metadata-eval [=>]53.2

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

      unpow2 [=>]53.2

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

      associate-*r* [=>]53.2

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

      *-commutative [<=]53.2

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

      unpow2 [=>]53.2

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

      *-commutative [<=]53.2

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

      +-commutative [=>]53.2

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

      associate-*l* [=>]0.9

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

      fma-def [=>]0.9

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

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

Alternatives

Alternative 1
Error0.2
Cost7240
\[\begin{array}{l} t_1 := z \cdot \left(y \cdot -4\right)\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+112}:\\ \;\;\;\;x \cdot x + z \cdot t_1\\ \mathbf{elif}\;z \leq 8.2 \cdot 10^{+142}:\\ \;\;\;\;x \cdot x + \left(4 \cdot y\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(z, t_1, x \cdot x\right)\\ \end{array} \]
Alternative 2
Error8.3
Cost1764
\[\begin{array}{l} t_1 := x \cdot x + -4 \cdot \left(y \cdot \left(z \cdot z\right)\right)\\ t_2 := 4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ t_3 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_4 := x \cdot x + \left(4 \cdot y\right) \cdot t\\ \mathbf{if}\;z \leq -1.32 \cdot 10^{+154}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq -1.28 \cdot 10^{-24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-105}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq 1.7 \cdot 10^{-33}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 3700:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.1 \cdot 10^{+54}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+69}:\\ \;\;\;\;t_4\\ \mathbf{elif}\;z \leq 9.5 \cdot 10^{+123}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+142}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 3
Error7.5
Cost1496
\[\begin{array}{l} t_1 := x \cdot x + \left(4 \cdot y\right) \cdot t\\ t_2 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_3 := 4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{if}\;z \leq -7.3 \cdot 10^{-25}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-105}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 6.8 \cdot 10^{-34}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2900:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq 5.1 \cdot 10^{+54}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.1 \cdot 10^{+69}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error26.9
Cost1376
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_2 := \left(4 \cdot y\right) \cdot t\\ \mathbf{if}\;x \leq -6.8 \cdot 10^{-42}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -1.65 \cdot 10^{-184}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -6.4 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.35 \cdot 10^{-264}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-239}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 3.3 \cdot 10^{-208}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 1.2 \cdot 10^{-193}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-21}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 5
Error8.9
Cost1368
\[\begin{array}{l} t_1 := 4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_3 := x \cdot x + \left(4 \cdot y\right) \cdot t\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+112}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.8 \cdot 10^{-69}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{-105}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 9.8 \cdot 10^{-45}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 31000:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 9.2 \cdot 10^{+142}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error0.2
Cost1097
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+112} \lor \neg \left(z \leq 5.2 \cdot 10^{+139}\right):\\ \;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + \left(4 \cdot y\right) \cdot \left(t - z \cdot z\right)\\ \end{array} \]
Alternative 7
Error16.1
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -4.5 \cdot 10^{-43} \lor \neg \left(x \leq 7 \cdot 10^{-17}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ \end{array} \]
Alternative 8
Error25.8
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -3.2 \cdot 10^{-42} \lor \neg \left(x \leq 7.8 \cdot 10^{-22}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;\left(4 \cdot y\right) \cdot t\\ \end{array} \]
Alternative 9
Error41.9
Cost192
\[x \cdot x \]

Error

Reproduce?

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