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

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


\end{array}

Error

Target

Original5.6
Target5.6
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.9999999999999996e274

    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.9999999999999996e274 < (*.f64 z z)

    1. Initial program 51.6

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

      \[\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 t around 0 51.9

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

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

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

      \[\leadsto \color{blue}{\left(z \cdot -4\right) \cdot \left(z \cdot y\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^{+275}:\\ \;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + \left(z \cdot -4\right) \cdot \left(z \cdot y\right)\\ \end{array} \]

Alternatives

Alternative 1
Error29.9
Cost2032
\[\begin{array}{l} t_1 := \left(y \cdot 4\right) \cdot t\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;x \leq -3.0273931135738003 \cdot 10^{+29}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -2.929263524129633:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7.288788096472708 \cdot 10^{-45}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -9.689301414779853 \cdot 10^{-175}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -5.156705001414148 \cdot 10^{-219}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.934006364236762 \cdot 10^{-285}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -7.3754539059838635 \cdot 10^{-301}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5818191885384684 \cdot 10^{-276}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 9.389232660634333 \cdot 10^{-147}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.5294842321168915 \cdot 10^{-105}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 2.998943068913706 \cdot 10^{-21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 7.59105345878354 \cdot 10^{+24}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 2
Error27.9
Cost1748
\[\begin{array}{l} t_1 := y \cdot \left(\left(z \cdot z\right) \cdot -4\right)\\ t_2 := \left(y \cdot 4\right) \cdot t\\ \mathbf{if}\;x \cdot x \leq 1.9003578267628206 \cdot 10^{-233}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 2.1 \cdot 10^{-148}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 8.993659530585558 \cdot 10^{-42}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 0.039669042070278854:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \cdot x \leq 8.060691857099481 \cdot 10^{+70}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 3
Error0.1
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+275}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + \left(z \cdot -4\right) \cdot \left(z \cdot y\right)\\ \end{array} \]
Alternative 4
Error6.3
Cost968
\[\begin{array}{l} t_1 := x \cdot x + \left(z \cdot -4\right) \cdot \left(z \cdot y\right)\\ \mathbf{if}\;z \leq -215451.4053317422:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.888393880916253 \cdot 10^{-35}:\\ \;\;\;\;x \cdot x + y \cdot \left(4 \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error11.4
Cost840
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -215451.4053317422:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.36307045331819 \cdot 10^{-16}:\\ \;\;\;\;x \cdot x + y \cdot \left(4 \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error25.9
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3.455342515686513 \cdot 10^{-60}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 7.640403314294012 \cdot 10^{+36}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 7
Error41.1
Cost192
\[x \cdot x \]

Error

Reproduce

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