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

\mathbf{elif}\;t_2 \leq 10^{+299}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot x + z \cdot t_1\\


\end{array}

Error

Target

Original6.6
Target6.5
Herbie0.3
\[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 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. Applied egg-rr64.0

      \[\leadsto x \cdot x - \color{blue}{\frac{\left({z}^{4} - t \cdot t\right) \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(z, z, t\right)}} \]
    3. Taylor expanded in z around inf 63.8

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

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

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

    if -inf.0 < (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t)) < 1.0000000000000001e299

    1. Initial program 0.1

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

    if 1.0000000000000001e299 < (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))

    1. Initial program 57.9

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Applied egg-rr64.0

      \[\leadsto x \cdot x - \color{blue}{\frac{\left({z}^{4} - t \cdot t\right) \cdot \left(y \cdot 4\right)}{\mathsf{fma}\left(z, z, t\right)}} \]
    3. Taylor expanded in z around inf 61.2

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

      \[\leadsto x \cdot x - \color{blue}{z \cdot \left(4 \cdot \left(y \cdot z\right)\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

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

Alternatives

Alternative 1
Error0.3
Cost2120
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(-4 \cdot \left(y \cdot z\right)\right)\\ t_2 := \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\\ \mathbf{if}\;t_2 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 10^{+299}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error28.3
Cost1636
\[\begin{array}{l} t_1 := \left(y \cdot z\right) \cdot \left(z \cdot -4\right)\\ t_2 := \left(y \cdot 4\right) \cdot t\\ \mathbf{if}\;x \leq -1.2323444711302884 \cdot 10^{-14}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq -5.852853906865885 \cdot 10^{-161}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -2.9988574797288687 \cdot 10^{-229}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -1.2647199548819823 \cdot 10^{-294}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.212765141254506 \cdot 10^{-270}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 9.534519967280354 \cdot 10^{-199}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 3.828080932709091 \cdot 10^{-96}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2467757849298437:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq 4.1956750723996366 \cdot 10^{+23}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 3
Error8.6
Cost1616
\[\begin{array}{l} t_1 := \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ t_2 := x \cdot x + \left(y \cdot 4\right) \cdot t\\ \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-65}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{-25}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+69}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+290}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot z\right) \cdot \left(z \cdot -4\right)\\ \end{array} \]
Alternative 4
Error11.2
Cost1356
\[\begin{array}{l} t_1 := \left(y \cdot z\right) \cdot \left(z \cdot -4\right)\\ t_2 := x \cdot x + \left(y \cdot 4\right) \cdot t\\ \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{-65}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{-36}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+118}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error6.4
Cost968
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(-4 \cdot \left(y \cdot z\right)\right)\\ \mathbf{if}\;z \leq -1.1486979428564014 \cdot 10^{-62}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.764795347216732 \cdot 10^{-15}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error26.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.2323444711302884 \cdot 10^{-14}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 31366007443453564:\\ \;\;\;\;\left(y \cdot 4\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 7
Error42.2
Cost192
\[x \cdot x \]

Error

Reproduce

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