?

Average Error: 9.06% → 1.76%
Time: 10.7s
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 -1.35 \cdot 10^{+154} \lor \neg \left(z \leq 7.4 \cdot 10^{+112}\right):\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\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 -1.35e+154) (not (<= z 7.4e+112)))
   (* z (* z (* y -4.0)))
   (fma x x (* (* y -4.0) (- (* z z) t)))))
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 <= -1.35e+154) || !(z <= 7.4e+112)) {
		tmp = z * (z * (y * -4.0));
	} else {
		tmp = fma(x, x, ((y * -4.0) * ((z * z) - t)));
	}
	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 <= -1.35e+154) || !(z <= 7.4e+112))
		tmp = Float64(z * Float64(z * Float64(y * -4.0)));
	else
		tmp = fma(x, x, Float64(Float64(y * -4.0) * Float64(Float64(z * z) - t)));
	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, -1.35e+154], N[Not[LessEqual[z, 7.4e+112]], $MachinePrecision]], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(N[(y * -4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $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 -1.35 \cdot 10^{+154} \lor \neg \left(z \leq 7.4 \cdot 10^{+112}\right):\\
\;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\

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


\end{array}

Error?

Target

Original9.06%
Target9.05%
Herbie1.76%
\[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 < -1.35000000000000003e154 or 7.40000000000000008e112 < z

    1. Initial program 77.4

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

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

      \[\leadsto \color{blue}{z \cdot \left(z \cdot \left(y \cdot -4\right)\right)} \]
      Proof

      [Start]82.5

      \[ -4 \cdot \left(y \cdot {z}^{2}\right) \]

      associate-*r* [=>]82.5

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

      *-commutative [<=]82.5

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

      unpow2 [=>]82.5

      \[ \left(y \cdot -4\right) \cdot \color{blue}{\left(z \cdot z\right)} \]

      *-commutative [=>]82.5

      \[ \color{blue}{\left(z \cdot z\right) \cdot \left(y \cdot -4\right)} \]

      associate-*l* [=>]14.41

      \[ \color{blue}{z \cdot \left(z \cdot \left(y \cdot -4\right)\right)} \]

    if -1.35000000000000003e154 < z < 7.40000000000000008e112

    1. Initial program 0.11

      \[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

      [Start]0.11

      \[ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]

      fma-neg [=>]0.1

      \[ \color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\right)} \]

      distribute-lft-neg-in [=>]0.1

      \[ \mathsf{fma}\left(x, x, \color{blue}{\left(-y \cdot 4\right) \cdot \left(z \cdot z - t\right)}\right) \]

      *-commutative [=>]0.1

      \[ \mathsf{fma}\left(x, x, \color{blue}{\left(z \cdot z - t\right) \cdot \left(-y \cdot 4\right)}\right) \]

      distribute-rgt-neg-in [=>]0.1

      \[ \mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \color{blue}{\left(y \cdot \left(-4\right)\right)}\right) \]

      metadata-eval [=>]0.1

      \[ \mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot \color{blue}{-4}\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.76

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

Alternatives

Alternative 1
Error43.93%
Cost1504
\[\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 -3 \cdot 10^{+52}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -8.2 \cdot 10^{-123}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.3 \cdot 10^{-159}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq -3.2 \cdot 10^{-228}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -1.7 \cdot 10^{-271}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 2.15 \cdot 10^{-43}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \leq 1.6 \cdot 10^{-7}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 1.85 \cdot 10^{+43}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 2
Error24.77%
Cost1357
\[\begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-71} \lor \neg \left(x \cdot x \leq 1.65 \cdot 10^{+15}\right) \land x \cdot x \leq 1.05 \cdot 10^{+76}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 3
Error12.04%
Cost1104
\[\begin{array}{l} t_1 := \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ t_2 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -2.4 \cdot 10^{+153}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -6.4 \cdot 10^{-43}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.5 \cdot 10^{-13}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \leq 7.4 \cdot 10^{+112}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error12.2%
Cost1104
\[\begin{array}{l} t_1 := z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -1.35 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -7.5 \cdot 10^{+48}:\\ \;\;\;\;x \cdot x + -4 \cdot \left(y \cdot \left(z \cdot z\right)\right)\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{-12}:\\ \;\;\;\;x \cdot x + t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;z \leq 4 \cdot 10^{+110}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error1.76%
Cost1097
\[\begin{array}{l} \mathbf{if}\;z \leq -1.35 \cdot 10^{+154} \lor \neg \left(z \leq 7.4 \cdot 10^{+112}\right):\\ \;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z - t\right) + x \cdot x\\ \end{array} \]
Alternative 6
Error40.93%
Cost850
\[\begin{array}{l} \mathbf{if}\;x \leq -114000000000 \lor \neg \left(x \leq 6 \cdot 10^{-61}\right) \land \left(x \leq 2300000000 \lor \neg \left(x \leq 1.48 \cdot 10^{+54}\right)\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 7
Error40.94%
Cost849
\[\begin{array}{l} \mathbf{if}\;x \leq -260000000000:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 1.65 \cdot 10^{-60}:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{elif}\;x \leq 1650000000 \lor \neg \left(x \leq 1.6 \cdot 10^{+54}\right):\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;4 \cdot \left(y \cdot t\right)\\ \end{array} \]
Alternative 8
Error64.42%
Cost192
\[x \cdot x \]

Error

Reproduce?

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