Average Error: 5.8 → 0.7
Time: 10.7s
Precision: binary64
Cost: 14340
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} t_1 := t - z \cdot z\\ t_2 := x \cdot x + \left(y \cdot 4\right) \cdot t_1\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;x \cdot x - {\left(z \cdot \left(\sqrt{y} \cdot 2\right)\right)}^{2}\\ \mathbf{elif}\;t_2 \leq 10^{+306}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot 4, t_1, x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;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
 (let* ((t_1 (- t (* z z))) (t_2 (+ (* x x) (* (* y 4.0) t_1))))
   (if (<= t_2 (- INFINITY))
     (- (* x x) (pow (* z (* (sqrt y) 2.0)) 2.0))
     (if (<= t_2 1e+306) (fma (* y 4.0) t_1 (* 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 t_1 = t - (z * z);
	double t_2 = (x * x) + ((y * 4.0) * t_1);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = (x * x) - pow((z * (sqrt(y) * 2.0)), 2.0);
	} else if (t_2 <= 1e+306) {
		tmp = fma((y * 4.0), t_1, (x * x));
	} else {
		tmp = 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)
	t_1 = Float64(t - Float64(z * z))
	t_2 = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * t_1))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = Float64(Float64(x * x) - (Float64(z * Float64(sqrt(y) * 2.0)) ^ 2.0));
	elseif (t_2 <= 1e+306)
		tmp = fma(Float64(y * 4.0), t_1, Float64(x * x));
	else
		tmp = 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_] := Block[{t$95$1 = N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, (-Infinity)], N[(N[(x * x), $MachinePrecision] - N[Power[N[(z * N[(N[Sqrt[y], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e+306], N[(N[(y * 4.0), $MachinePrecision] * t$95$1 + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
t_1 := t - z \cdot z\\
t_2 := x \cdot x + \left(y \cdot 4\right) \cdot t_1\\
\mathbf{if}\;t_2 \leq -\infty:\\
\;\;\;\;x \cdot x - {\left(z \cdot \left(\sqrt{y} \cdot 2\right)\right)}^{2}\\

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

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


\end{array}

Error

Target

Original5.8
Target5.8
Herbie0.7
\[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 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < -inf.0

    1. Initial program 64.0

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

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

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

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

    if -inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < 1.00000000000000002e306

    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 1.00000000000000002e306 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)))

    1. Initial program 58.9

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

      \[\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
    3. Taylor expanded in z around inf 63.1

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

      \[\leadsto \color{blue}{z \cdot \left(z \cdot \left(y \cdot -4\right)\right)} \]
      Proof
      (*.f64 z (*.f64 z (*.f64 y -4))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (*.f64 z (Rewrite<= *-commutative_binary64 (*.f64 -4 y)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (*.f64 -4 y))): 57 points increase in error, 26 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)))): 0 points increase in error, 2 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification0.7

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

Alternatives

Alternative 1
Error0.8
Cost7364
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+307}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 2
Error15.0
Cost1356
\[\begin{array}{l} t_1 := 4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{if}\;x \cdot x \leq 1.90102007349918 \cdot 10^{+38}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 1.818014596613012 \cdot 10^{+94}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \cdot x \leq 2.2116214828124666 \cdot 10^{+108}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 3
Error7.3
Cost1224
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+31}:\\ \;\;\;\;x \cdot x + 4 \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+294}:\\ \;\;\;\;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 4
Error7.9
Cost1096
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 500000000:\\ \;\;\;\;x \cdot x + 4 \cdot \left(y \cdot t\right)\\ \mathbf{elif}\;z \cdot z \leq 10^{+307}:\\ \;\;\;\;4 \cdot \left(y \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 5
Error0.8
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+307}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \end{array} \]
Alternative 6
Error26.0
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -200.75505071961211:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -7.259321918316625 \cdot 10^{-234}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot t\\ \mathbf{elif}\;x \leq -1.324057617090057 \cdot 10^{-284}:\\ \;\;\;\;y \cdot \left(\left(z \cdot z\right) \cdot -4\right)\\ \mathbf{elif}\;x \leq 0.26204522071887015:\\ \;\;\;\;4 \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 7
Error26.2
Cost712
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -7.420801833234761 \cdot 10^{+30}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 115347712.83426407:\\ \;\;\;\;\left(y \cdot 4\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error25.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -200.75505071961211:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 0.26204522071887015:\\ \;\;\;\;4 \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 9
Error25.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -200.75505071961211:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 0.26204522071887015:\\ \;\;\;\;\left(y \cdot 4\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 10
Error41.5
Cost192
\[x \cdot x \]

Error

Reproduce

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