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

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


\end{array}

Error

Target

Original5.8
Target5.8
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) < 9.99999999999999945e272

    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(y \cdot 4, t - z \cdot z, x \cdot x\right)} \]
      Proof
      (fma.f64 (*.f64 y 4) (-.f64 t (*.f64 z z)) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 y 4) (Rewrite=> sub-neg_binary64 (+.f64 t (neg.f64 (*.f64 z z)))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 y 4) (Rewrite<= +-commutative_binary64 (+.f64 (neg.f64 (*.f64 z z)) t)) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 y 4) (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 (*.f64 z z))) t) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 y 4) (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 (*.f64 z z) t))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (fma.f64 (*.f64 y 4) (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 (*.f64 z z) t))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (*.f64 y 4) (neg.f64 (-.f64 (*.f64 z z) t))) (*.f64 x x))): 2 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= distribute-lft-neg-out_binary64 (*.f64 (neg.f64 (*.f64 y 4)) (-.f64 (*.f64 z z) t))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 (*.f64 x x) (*.f64 (neg.f64 (*.f64 y 4)) (-.f64 (*.f64 z z) t)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= cancel-sign-sub-inv_binary64 (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)))): 0 points increase in error, 0 points decrease in error

    if 9.99999999999999945e272 < (*.f64 z z)

    1. Initial program 53.0

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

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

      \[\leadsto x \cdot x - \color{blue}{\left(z \cdot z\right) \cdot \left(4 \cdot y\right)} \]
      Proof
      (*.f64 (*.f64 z z) (*.f64 4 y)): 0 points increase in error, 0 points decrease in error
      (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) (*.f64 4 y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 4 y) (pow.f64 z 2))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 4 (*.f64 y (pow.f64 z 2)))): 1 points increase in error, 1 points decrease in error
    4. Applied egg-rr0.5

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

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

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

Alternatives

Alternative 1
Error8.4
Cost2004
\[\begin{array}{l} t_1 := 4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ t_2 := x \cdot x + y \cdot \left(4 \cdot t\right)\\ \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-162}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 4000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 4 \cdot 10^{+267}:\\ \;\;\;\;x \cdot x - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 2
Error7.4
Cost1744
\[\begin{array}{l} t_1 := 4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ t_2 := x \cdot x + y \cdot \left(4 \cdot t\right)\\ \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-162}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 4000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+100}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - z \cdot \left(y \cdot \left(z \cdot 4\right)\right)\\ \end{array} \]
Alternative 3
Error7.4
Cost1744
\[\begin{array}{l} t_1 := x \cdot x + y \cdot \left(4 \cdot t\right)\\ \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-162}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 4000000:\\ \;\;\;\;4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+24}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+100}:\\ \;\;\;\;4 \cdot \left(y \cdot t - \left(z \cdot z\right) \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - z \cdot \left(y \cdot \left(z \cdot 4\right)\right)\\ \end{array} \]
Alternative 4
Error9.3
Cost1616
\[\begin{array}{l} t_1 := 4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ t_2 := x \cdot x + y \cdot \left(4 \cdot t\right)\\ \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-162}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 4000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 10^{+273}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 5
Error0.1
Cost1348
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+273}:\\ \;\;\;\;x \cdot x + \left(\left(y \cdot 4\right) \cdot t - \left(z \cdot z\right) \cdot \left(y \cdot 4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - z \cdot \left(y \cdot \left(z \cdot 4\right)\right)\\ \end{array} \]
Alternative 6
Error27.0
Cost1240
\[\begin{array}{l} t_1 := 4 \cdot \left(y \cdot t\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -1.3697376400827172 \cdot 10^{+51}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -1.7729976387777524 \cdot 10^{-202}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -4.0316955099059275 \cdot 10^{-227}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 2.912703042506244 \cdot 10^{-232}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot t\\ \mathbf{elif}\;z \leq 2.679430492637666 \cdot 10^{-204}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 24.498733668643645:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 7
Error0.1
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+273}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - z \cdot \left(y \cdot \left(z \cdot 4\right)\right)\\ \end{array} \]
Alternative 8
Error10.8
Cost840
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -9.5 \cdot 10^{+72}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 24.498733668643645:\\ \;\;\;\;x \cdot x + y \cdot \left(4 \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error24.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.476371380373097 \cdot 10^{-21}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{-5}:\\ \;\;\;\;4 \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 10
Error24.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -4.476371380373097 \cdot 10^{-21}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 4.3 \cdot 10^{-5}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 11
Error41.3
Cost192
\[x \cdot x \]

Error

Reproduce

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