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

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


\end{array}

Error

Target

Original6.0
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) < 4.99999999999999991e295

    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
      (fma.f64 x x (*.f64 (-.f64 (*.f64 z z) t) (*.f64 y -4))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (*.f64 (-.f64 (*.f64 z z) t) (*.f64 y (Rewrite<= metadata-eval (neg.f64 4))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (*.f64 (-.f64 (*.f64 z z) t) (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 y 4))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (-.f64 (*.f64 z z) t) (*.f64 y 4))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-neg_binary64 (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)))): 2 points increase in error, 0 points decrease in error

    if 4.99999999999999991e295 < (*.f64 z z)

    1. Initial program 59.0

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\left(-z\right) \cdot {\left(\sqrt[3]{4 \cdot \left(z \cdot y\right)}\right)}^{2}, \sqrt[3]{4 \cdot \left(z \cdot y\right)}, x \cdot x\right)} \]
    5. Taylor expanded in x around 0 59.1

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(y \cdot z\right) \cdot \left(-4 \cdot z\right)\right)} \]
      Proof
      (fma.f64 x x (*.f64 (*.f64 y z) (*.f64 -4 z))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 z y)) (*.f64 -4 z))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (*.f64 (*.f64 z y) (*.f64 (Rewrite<= metadata-eval (neg.f64 4)) z))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (*.f64 (*.f64 z y) (Rewrite<= distribute-lft-neg-in_binary64 (neg.f64 (*.f64 4 z))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (Rewrite<= distribute-rgt-neg-in_binary64 (neg.f64 (*.f64 (*.f64 z y) (*.f64 4 z))))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (neg.f64 (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 (*.f64 z y) 4) z)))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (neg.f64 (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 4 (*.f64 z y))) z))): 0 points increase in error, 0 points decrease in error
      (fma.f64 x x (neg.f64 (Rewrite<= *-commutative_binary64 (*.f64 z (*.f64 4 (*.f64 z y)))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 x x) (neg.f64 (*.f64 z (*.f64 4 (*.f64 z y)))))): 3 points increase in error, 0 points decrease in error
      (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 (*.f64 z (*.f64 4 (*.f64 z y)))) (*.f64 x x))): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (Rewrite=> *-commutative_binary64 (*.f64 (*.f64 4 (*.f64 z y)) z))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (Rewrite=> associate-*l*_binary64 (*.f64 4 (*.f64 (*.f64 z y) z)))) (*.f64 x x)): 1 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (*.f64 4 (*.f64 (Rewrite=> *-commutative_binary64 (*.f64 y z)) z))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (*.f64 4 (Rewrite<= associate-*r*_binary64 (*.f64 y (*.f64 z z))))) (*.f64 x x)): 50 points increase in error, 23 points decrease in error
      (+.f64 (neg.f64 (*.f64 4 (*.f64 y (Rewrite<= unpow2_binary64 (pow.f64 z 2))))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (*.f64 4 (Rewrite<= *-rgt-identity_binary64 (*.f64 (*.f64 y (pow.f64 z 2)) 1)))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (*.f64 4 (Rewrite<= *-commutative_binary64 (*.f64 1 (*.f64 y (pow.f64 z 2)))))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (neg.f64 (*.f64 4 (*.f64 (Rewrite<= pow-base-1_binary64 (pow.f64 1 1/3)) (*.f64 y (pow.f64 z 2))))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite=> distribute-lft-neg-in_binary64 (*.f64 (neg.f64 4) (*.f64 (pow.f64 1 1/3) (*.f64 y (pow.f64 z 2))))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 (Rewrite=> metadata-eval -4) (*.f64 (pow.f64 1 1/3) (*.f64 y (pow.f64 z 2)))) (*.f64 x x)): 0 points increase in error, 0 points decrease in error
      (+.f64 (*.f64 -4 (*.f64 (pow.f64 1 1/3) (*.f64 y (pow.f64 z 2)))) (Rewrite<= unpow2_binary64 (pow.f64 x 2))): 0 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

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

Alternatives

Alternative 1
Error0.3
Cost7240
\[\begin{array}{l} t_1 := \mathsf{fma}\left(x, x, \left(z \cdot y\right) \cdot \left(z \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.2 \cdot 10^{+96}:\\ \;\;\;\;x \cdot x + \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error8.7
Cost1236
\[\begin{array}{l} t_1 := y \cdot \left(4 \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 + t \cdot \left(y \cdot 4\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{+154}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -7.6 \cdot 10^{-57}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.5 \cdot 10^{-10}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 2.65 \cdot 10^{+39}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.35 \cdot 10^{+63}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error6.5
Cost1100
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(y \cdot \left(z \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -1.25 \cdot 10^{+47}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -3.1 \cdot 10^{-57}:\\ \;\;\;\;y \cdot \left(4 \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{elif}\;z \leq 2.05 \cdot 10^{-14}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error0.1
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+295}:\\ \;\;\;\;x \cdot x + \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(y \cdot \left(z \cdot -4\right)\right)\\ \end{array} \]
Alternative 5
Error16.4
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1.5 \cdot 10^{+70}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 5 \cdot 10^{+24}:\\ \;\;\;\;y \cdot \left(4 \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 6
Error25.4
Cost712
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -5.2 \cdot 10^{-5}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.5 \cdot 10^{-8}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error27.5
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1 \cdot 10^{+70}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 62:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 8
Error42.5
Cost192
\[x \cdot x \]

Error

Reproduce

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