Average Error: 6.0 → 0.2
Time: 11.8s
Precision: binary64
Cost: 7369
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} \mathbf{if}\;z \leq -2 \cdot 10^{+155} \lor \neg \left(z \leq 2 \cdot 10^{+139}\right):\\ \;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(4 \cdot y\right) \cdot \left(t - z \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
 (if (or (<= z -2e+155) (not (<= z 2e+139)))
   (+ (* x x) (* z (* z (* y -4.0))))
   (fma x x (* (* 4.0 y) (- t (* z 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 tmp;
	if ((z <= -2e+155) || !(z <= 2e+139)) {
		tmp = (x * x) + (z * (z * (y * -4.0)));
	} else {
		tmp = fma(x, x, ((4.0 * y) * (t - (z * 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)
	tmp = 0.0
	if ((z <= -2e+155) || !(z <= 2e+139))
		tmp = Float64(Float64(x * x) + Float64(z * Float64(z * Float64(y * -4.0))));
	else
		tmp = fma(x, x, Float64(Float64(4.0 * y) * Float64(t - Float64(z * 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_] := If[Or[LessEqual[z, -2e+155], N[Not[LessEqual[z, 2e+139]], $MachinePrecision]], N[(N[(x * x), $MachinePrecision] + N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(N[(4.0 * y), $MachinePrecision] * N[(t - N[(z * z), $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 \leq -2 \cdot 10^{+155} \lor \neg \left(z \leq 2 \cdot 10^{+139}\right):\\
\;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\

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


\end{array}

Error

Target

Original6.0
Target6.0
Herbie0.2
\[x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right) \]

Derivation

  1. Split input into 2 regimes
  2. if z < -2.00000000000000001e155 or 2.00000000000000007e139 < z

    1. Initial program 58.1

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

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

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

    if -2.00000000000000001e155 < z < 2.00000000000000007e139

    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))))): 6 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))))): 6 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, 6 points decrease in error
      (Rewrite<= fma-neg_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. Recombined 2 regimes into one program.
  4. Final simplification0.2

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

Alternatives

Alternative 1
Error6.8
Cost1364
\[\begin{array}{l} t_1 := y \cdot \left(\left(z \cdot z - t\right) \cdot -4\right)\\ t_2 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ t_3 := x \cdot x + \left(4 \cdot y\right) \cdot t\\ \mathbf{if}\;z \leq -1.75 \cdot 10^{+123}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -7.8 \cdot 10^{-75}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{-24}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;z \leq 7 \cdot 10^{+32}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.5 \cdot 10^{+58}:\\ \;\;\;\;t_3\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error7.5
Cost1104
\[\begin{array}{l} t_1 := y \cdot \left(\left(z \cdot z - t\right) \cdot -4\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -6.6 \cdot 10^{+153}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -5 \cdot 10^{-66}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 5.8 \cdot 10^{-25}:\\ \;\;\;\;x \cdot x + \left(4 \cdot y\right) \cdot t\\ \mathbf{elif}\;z \leq 10^{+136}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error0.1
Cost1097
\[\begin{array}{l} \mathbf{if}\;z \leq -1.2 \cdot 10^{+154} \lor \neg \left(z \leq 1.85 \cdot 10^{+140}\right):\\ \;\;\;\;x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + \left(4 \cdot y\right) \cdot \left(t - z \cdot z\right)\\ \end{array} \]
Alternative 4
Error25.7
Cost848
\[\begin{array}{l} t_1 := \left(4 \cdot y\right) \cdot t\\ \mathbf{if}\;x \leq -3 \cdot 10^{-8}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -2 \cdot 10^{-161}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.22 \cdot 10^{-190}:\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{elif}\;x \leq 1.8 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 5
Error15.7
Cost841
\[\begin{array}{l} \mathbf{if}\;x \leq -2.3 \cdot 10^{-14} \lor \neg \left(x \leq 9.6 \cdot 10^{+63}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;y \cdot \left(\left(z \cdot z - t\right) \cdot -4\right)\\ \end{array} \]
Alternative 6
Error25.3
Cost580
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 9.8 \cdot 10^{-21}:\\ \;\;\;\;\left(4 \cdot y\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 7
Error42.0
Cost192
\[x \cdot x \]

Error

Reproduce

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