?

Average Error: 5.9 → 0.2
Time: 11.5s
Precision: binary64
Cost: 8392

?

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

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

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


\end{array}

Error?

Target

Original5.9
Target5.9
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 (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)) < -2.0000000000000002e302

    1. Initial program 60.2

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

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

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

      [Start]62.2

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

      unpow2 [=>]62.2

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

      associate-*r* [=>]2.5

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

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

    if -2.0000000000000002e302 < (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)) < 1.99999999999999997e307

    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.99999999999999997e307 < (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))

    1. Initial program 63.1

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

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

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

      [Start]63.8

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

      unpow2 [=>]63.8

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

      associate-*r* [=>]1.1

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

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

Alternatives

Alternative 1
Error0.2
Cost7620
\[\begin{array}{l} t_1 := z \cdot z - t\\ t_2 := t_1 \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+302}:\\ \;\;\;\;\mathsf{fma}\left(x, x, z \cdot \left(\left(y \cdot z\right) \cdot -4\right)\right)\\ \mathbf{elif}\;t_2 \leq 2 \cdot 10^{+307}:\\ \;\;\;\;x \cdot x + t_1 \cdot \left(y \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + -4 \cdot \left(z \cdot \left(y \cdot z\right)\right)\\ \end{array} \]
Alternative 2
Error12.3
Cost3292
\[\begin{array}{l} t_1 := z \cdot z - t\\ t_2 := t_1 \cdot \left(y \cdot -4\right)\\ t_3 := x \cdot x - t \cdot \left(y \cdot -4\right)\\ \mathbf{if}\;t_1 \leq 10^{-74}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{-36}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 8 \cdot 10^{+65}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+119}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+243}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+294}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+307}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 3
Error0.2
Cost2121
\[\begin{array}{l} t_1 := z \cdot z - t\\ t_2 := t_1 \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;t_2 \leq -2 \cdot 10^{+302} \lor \neg \left(t_2 \leq 2 \cdot 10^{+307}\right):\\ \;\;\;\;x \cdot x + -4 \cdot \left(z \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + t_1 \cdot \left(y \cdot -4\right)\\ \end{array} \]
Alternative 4
Error27.4
Cost1488
\[\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 \cdot x \leq 1.4 \cdot 10^{-249}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 4.2 \cdot 10^{-194}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 3.1 \cdot 10^{-151}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 1.5 \cdot 10^{-29}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 5
Error7.0
Cost1232
\[\begin{array}{l} t_1 := x \cdot x + -4 \cdot \left(y \cdot \left(z \cdot z\right)\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2600:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 120000000000:\\ \;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{+138}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error6.1
Cost969
\[\begin{array}{l} \mathbf{if}\;z \leq -430 \lor \neg \left(z \leq 225000000000\right):\\ \;\;\;\;x \cdot x + -4 \cdot \left(z \cdot \left(y \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - t \cdot \left(y \cdot -4\right)\\ \end{array} \]
Alternative 7
Error15.1
Cost836
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 1.2 \cdot 10^{-35}:\\ \;\;\;\;\left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 8
Error26.5
Cost585
\[\begin{array}{l} \mathbf{if}\;x \leq -2.45 \cdot 10^{-76} \lor \neg \left(x \leq 2.05 \cdot 10^{-9}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \end{array} \]
Alternative 9
Error41.9
Cost192
\[x \cdot x \]

Error

Reproduce?

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