Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B

Percentage Accurate: 90.4% → 93.7%
Time: 10.3s
Alternatives: 6
Speedup: 0.6×

Specification

?
\[\begin{array}{l} \\ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (- (* 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));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t):
	return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t)
	return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t)))
end
function tmp = code(x, y, z, t)
	tmp = (x * x) - ((y * 4.0) * ((z * z) - t));
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]
\begin{array}{l}

\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 6 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 90.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (- (* 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));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end function
public static double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t):
	return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t)
	return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t)))
end
function tmp = code(x, y, z, t)
	tmp = (x * x) - ((y * 4.0) * ((z * z) - t));
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]
\begin{array}{l}

\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}

Alternative 1: 93.7% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 1.5 \cdot 10^{+239}:\\ \;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z t)
 :precision binary64
 (if (<= x_m 1.5e+239) (fma x_m x_m (* (- (* z z) t) (* y -4.0))) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
	double tmp;
	if (x_m <= 1.5e+239) {
		tmp = fma(x_m, x_m, (((z * z) - t) * (y * -4.0)));
	} else {
		tmp = x_m * x_m;
	}
	return tmp;
}
x_m = abs(x)
function code(x_m, y, z, t)
	tmp = 0.0
	if (x_m <= 1.5e+239)
		tmp = fma(x_m, x_m, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0)));
	else
		tmp = Float64(x_m * x_m);
	end
	return tmp
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := If[LessEqual[x$95$m, 1.5e+239], N[(x$95$m * x$95$m + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m * x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1.5 \cdot 10^{+239}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\

\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 1.4999999999999999e239

    1. Initial program 93.9%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Step-by-step derivation
      1. fma-neg96.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, -\left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)\right)} \]
      2. distribute-lft-neg-in96.0%

        \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(-y \cdot 4\right) \cdot \left(z \cdot z - t\right)}\right) \]
      3. *-commutative96.0%

        \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(z \cdot z - t\right) \cdot \left(-y \cdot 4\right)}\right) \]
      4. distribute-rgt-neg-in96.0%

        \[\leadsto \mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \color{blue}{\left(y \cdot \left(-4\right)\right)}\right) \]
      5. metadata-eval96.0%

        \[\leadsto \mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot \color{blue}{-4}\right)\right) \]
    3. Simplified96.0%

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

    if 1.4999999999999999e239 < x

    1. Initial program 66.7%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 66.7%

      \[\leadsto x \cdot x - \color{blue}{4 \cdot \left(y \cdot \left({z}^{2} - t\right)\right)} \]
    4. Simplified100.0%

      \[\leadsto x \cdot x - \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.2%

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

Alternative 2: 94.1% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;t \leq 9.2 \cdot 10^{+188}:\\ \;\;\;\;x\_m \cdot x\_m - \left(-4 \cdot \left(t \cdot y\right) + z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot x\_m + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z t)
 :precision binary64
 (if (<= t 9.2e+188)
   (- (* x_m x_m) (+ (* -4.0 (* t y)) (* z (* z (* y 4.0)))))
   (+ (* x_m x_m) (* (* y 4.0) (- t (* z z))))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
	double tmp;
	if (t <= 9.2e+188) {
		tmp = (x_m * x_m) - ((-4.0 * (t * y)) + (z * (z * (y * 4.0))));
	} else {
		tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if (t <= 9.2d+188) then
        tmp = (x_m * x_m) - (((-4.0d0) * (t * y)) + (z * (z * (y * 4.0d0))))
    else
        tmp = (x_m * x_m) + ((y * 4.0d0) * (t - (z * z)))
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
	double tmp;
	if (t <= 9.2e+188) {
		tmp = (x_m * x_m) - ((-4.0 * (t * y)) + (z * (z * (y * 4.0))));
	} else {
		tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m, y, z, t):
	tmp = 0
	if t <= 9.2e+188:
		tmp = (x_m * x_m) - ((-4.0 * (t * y)) + (z * (z * (y * 4.0))))
	else:
		tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)))
	return tmp
x_m = abs(x)
function code(x_m, y, z, t)
	tmp = 0.0
	if (t <= 9.2e+188)
		tmp = Float64(Float64(x_m * x_m) - Float64(Float64(-4.0 * Float64(t * y)) + Float64(z * Float64(z * Float64(y * 4.0)))));
	else
		tmp = Float64(Float64(x_m * x_m) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z))));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, y, z, t)
	tmp = 0.0;
	if (t <= 9.2e+188)
		tmp = (x_m * x_m) - ((-4.0 * (t * y)) + (z * (z * (y * 4.0))));
	else
		tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := If[LessEqual[t, 9.2e+188], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision] + N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;t \leq 9.2 \cdot 10^{+188}:\\
\;\;\;\;x\_m \cdot x\_m - \left(-4 \cdot \left(t \cdot y\right) + z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 9.20000000000000046e188

    1. Initial program 92.9%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Add Preprocessing
    3. Taylor expanded in z around 0 92.5%

      \[\leadsto x \cdot x - \color{blue}{\left(-4 \cdot \left(t \cdot y\right) + 4 \cdot \left(y \cdot {z}^{2}\right)\right)} \]
    4. Step-by-step derivation
      1. +-commutative92.5%

        \[\leadsto x \cdot x - \color{blue}{\left(4 \cdot \left(y \cdot {z}^{2}\right) + -4 \cdot \left(t \cdot y\right)\right)} \]
      2. add-sqr-sqrt59.3%

        \[\leadsto x \cdot x - \left(\color{blue}{\sqrt{4 \cdot \left(y \cdot {z}^{2}\right)} \cdot \sqrt{4 \cdot \left(y \cdot {z}^{2}\right)}} + -4 \cdot \left(t \cdot y\right)\right) \]
      3. *-commutative59.3%

        \[\leadsto x \cdot x - \left(\sqrt{4 \cdot \left(y \cdot {z}^{2}\right)} \cdot \sqrt{4 \cdot \left(y \cdot {z}^{2}\right)} + -4 \cdot \color{blue}{\left(y \cdot t\right)}\right) \]
      4. fma-define59.3%

        \[\leadsto x \cdot x - \color{blue}{\mathsf{fma}\left(\sqrt{4 \cdot \left(y \cdot {z}^{2}\right)}, \sqrt{4 \cdot \left(y \cdot {z}^{2}\right)}, -4 \cdot \left(y \cdot t\right)\right)} \]
    5. Applied egg-rr49.5%

      \[\leadsto x \cdot x - \color{blue}{\mathsf{fma}\left(\left(2 \cdot \sqrt{y}\right) \cdot z, \left(2 \cdot \sqrt{y}\right) \cdot z, \left(-4 \cdot y\right) \cdot t\right)} \]
    6. Step-by-step derivation
      1. fma-undefine49.5%

        \[\leadsto x \cdot x - \color{blue}{\left(\left(\left(2 \cdot \sqrt{y}\right) \cdot z\right) \cdot \left(\left(2 \cdot \sqrt{y}\right) \cdot z\right) + \left(-4 \cdot y\right) \cdot t\right)} \]
      2. unpow249.5%

        \[\leadsto x \cdot x - \left(\color{blue}{{\left(\left(2 \cdot \sqrt{y}\right) \cdot z\right)}^{2}} + \left(-4 \cdot y\right) \cdot t\right) \]
      3. *-commutative49.5%

        \[\leadsto x \cdot x - \left({\color{blue}{\left(z \cdot \left(2 \cdot \sqrt{y}\right)\right)}}^{2} + \left(-4 \cdot y\right) \cdot t\right) \]
      4. associate-*l*49.5%

        \[\leadsto x \cdot x - \left({\left(z \cdot \left(2 \cdot \sqrt{y}\right)\right)}^{2} + \color{blue}{-4 \cdot \left(y \cdot t\right)}\right) \]
      5. *-commutative49.5%

        \[\leadsto x \cdot x - \left({\left(z \cdot \left(2 \cdot \sqrt{y}\right)\right)}^{2} + -4 \cdot \color{blue}{\left(t \cdot y\right)}\right) \]
    7. Simplified49.5%

      \[\leadsto x \cdot x - \color{blue}{\left({\left(z \cdot \left(2 \cdot \sqrt{y}\right)\right)}^{2} + -4 \cdot \left(t \cdot y\right)\right)} \]
    8. Step-by-step derivation
      1. unpow-prod-down45.6%

        \[\leadsto x \cdot x - \left(\color{blue}{{z}^{2} \cdot {\left(2 \cdot \sqrt{y}\right)}^{2}} + -4 \cdot \left(t \cdot y\right)\right) \]
      2. unpow245.6%

        \[\leadsto x \cdot x - \left(\color{blue}{\left(z \cdot z\right)} \cdot {\left(2 \cdot \sqrt{y}\right)}^{2} + -4 \cdot \left(t \cdot y\right)\right) \]
      3. associate-*l*49.5%

        \[\leadsto x \cdot x - \left(\color{blue}{z \cdot \left(z \cdot {\left(2 \cdot \sqrt{y}\right)}^{2}\right)} + -4 \cdot \left(t \cdot y\right)\right) \]
      4. *-commutative49.5%

        \[\leadsto x \cdot x - \left(z \cdot \left(z \cdot {\color{blue}{\left(\sqrt{y} \cdot 2\right)}}^{2}\right) + -4 \cdot \left(t \cdot y\right)\right) \]
      5. unpow-prod-down49.5%

        \[\leadsto x \cdot x - \left(z \cdot \left(z \cdot \color{blue}{\left({\left(\sqrt{y}\right)}^{2} \cdot {2}^{2}\right)}\right) + -4 \cdot \left(t \cdot y\right)\right) \]
      6. pow249.5%

        \[\leadsto x \cdot x - \left(z \cdot \left(z \cdot \left(\color{blue}{\left(\sqrt{y} \cdot \sqrt{y}\right)} \cdot {2}^{2}\right)\right) + -4 \cdot \left(t \cdot y\right)\right) \]
      7. metadata-eval49.5%

        \[\leadsto x \cdot x - \left(z \cdot \left(z \cdot \left(\left(\sqrt{y} \cdot \sqrt{y}\right) \cdot \color{blue}{4}\right)\right) + -4 \cdot \left(t \cdot y\right)\right) \]
      8. add-sqr-sqrt96.4%

        \[\leadsto x \cdot x - \left(z \cdot \left(z \cdot \left(\color{blue}{y} \cdot 4\right)\right) + -4 \cdot \left(t \cdot y\right)\right) \]
    9. Applied egg-rr96.4%

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

    if 9.20000000000000046e188 < t

    1. Initial program 90.3%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification95.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq 9.2 \cdot 10^{+188}:\\ \;\;\;\;x \cdot x - \left(-4 \cdot \left(t \cdot y\right) + z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 93.1% accurate, 0.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \cdot x\_m \leq 3.9 \cdot 10^{+300}:\\ \;\;\;\;x\_m \cdot x\_m + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z t)
 :precision binary64
 (if (<= (* x_m x_m) 3.9e+300)
   (+ (* x_m x_m) (* (* y 4.0) (- t (* z z))))
   (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
	double tmp;
	if ((x_m * x_m) <= 3.9e+300) {
		tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
	} else {
		tmp = x_m * x_m;
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((x_m * x_m) <= 3.9d+300) then
        tmp = (x_m * x_m) + ((y * 4.0d0) * (t - (z * z)))
    else
        tmp = x_m * x_m
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
	double tmp;
	if ((x_m * x_m) <= 3.9e+300) {
		tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
	} else {
		tmp = x_m * x_m;
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m, y, z, t):
	tmp = 0
	if (x_m * x_m) <= 3.9e+300:
		tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)))
	else:
		tmp = x_m * x_m
	return tmp
x_m = abs(x)
function code(x_m, y, z, t)
	tmp = 0.0
	if (Float64(x_m * x_m) <= 3.9e+300)
		tmp = Float64(Float64(x_m * x_m) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z))));
	else
		tmp = Float64(x_m * x_m);
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, y, z, t)
	tmp = 0.0;
	if ((x_m * x_m) <= 3.9e+300)
		tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
	else
		tmp = x_m * x_m;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 3.9e+300], N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x$95$m * x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m \leq 3.9 \cdot 10^{+300}:\\
\;\;\;\;x\_m \cdot x\_m + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 3.8999999999999999e300

    1. Initial program 95.9%

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

    if 3.8999999999999999e300 < (*.f64 x x)

    1. Initial program 82.8%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 82.8%

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

      \[\leadsto x \cdot x - \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 3.9 \cdot 10^{+300}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 59.1% accurate, 1.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \cdot x\_m \leq 5 \cdot 10^{-10}:\\ \;\;\;\;y \cdot \left(t \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;x\_m \cdot x\_m\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z t)
 :precision binary64
 (if (<= (* x_m x_m) 5e-10) (* y (* t 4.0)) (* x_m x_m)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
	double tmp;
	if ((x_m * x_m) <= 5e-10) {
		tmp = y * (t * 4.0);
	} else {
		tmp = x_m * x_m;
	}
	return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((x_m * x_m) <= 5d-10) then
        tmp = y * (t * 4.0d0)
    else
        tmp = x_m * x_m
    end if
    code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
	double tmp;
	if ((x_m * x_m) <= 5e-10) {
		tmp = y * (t * 4.0);
	} else {
		tmp = x_m * x_m;
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m, y, z, t):
	tmp = 0
	if (x_m * x_m) <= 5e-10:
		tmp = y * (t * 4.0)
	else:
		tmp = x_m * x_m
	return tmp
x_m = abs(x)
function code(x_m, y, z, t)
	tmp = 0.0
	if (Float64(x_m * x_m) <= 5e-10)
		tmp = Float64(y * Float64(t * 4.0));
	else
		tmp = Float64(x_m * x_m);
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, y, z, t)
	tmp = 0.0;
	if ((x_m * x_m) <= 5e-10)
		tmp = y * (t * 4.0);
	else
		tmp = x_m * x_m;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 5e-10], N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision], N[(x$95$m * x$95$m), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m \leq 5 \cdot 10^{-10}:\\
\;\;\;\;y \cdot \left(t \cdot 4\right)\\

\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 5.00000000000000031e-10

    1. Initial program 96.4%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Add Preprocessing
    3. Taylor expanded in t around inf 47.4%

      \[\leadsto \color{blue}{4 \cdot \left(t \cdot y\right)} \]
    4. Step-by-step derivation
      1. associate-*r*47.4%

        \[\leadsto \color{blue}{\left(4 \cdot t\right) \cdot y} \]
    5. Simplified47.4%

      \[\leadsto \color{blue}{\left(4 \cdot t\right) \cdot y} \]

    if 5.00000000000000031e-10 < (*.f64 x x)

    1. Initial program 88.5%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Add Preprocessing
    3. Taylor expanded in y around 0 88.5%

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

      \[\leadsto x \cdot x - \color{blue}{0} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification60.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 5 \cdot 10^{-10}:\\ \;\;\;\;y \cdot \left(t \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 66.7% accurate, 1.4× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x\_m \cdot x\_m - -4 \cdot \left(t \cdot y\right) \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z t) :precision binary64 (- (* x_m x_m) (* -4.0 (* t y))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
	return (x_m * x_m) - (-4.0 * (t * y));
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x_m * x_m) - ((-4.0d0) * (t * y))
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
	return (x_m * x_m) - (-4.0 * (t * y));
}
x_m = math.fabs(x)
def code(x_m, y, z, t):
	return (x_m * x_m) - (-4.0 * (t * y))
x_m = abs(x)
function code(x_m, y, z, t)
	return Float64(Float64(x_m * x_m) - Float64(-4.0 * Float64(t * y)))
end
x_m = abs(x);
function tmp = code(x_m, y, z, t)
	tmp = (x_m * x_m) - (-4.0 * (t * y));
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(-4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
x\_m \cdot x\_m - -4 \cdot \left(t \cdot y\right)
\end{array}
Derivation
  1. Initial program 92.6%

    \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
  2. Add Preprocessing
  3. Taylor expanded in z around 0 66.6%

    \[\leadsto x \cdot x - \color{blue}{-4 \cdot \left(t \cdot y\right)} \]
  4. Step-by-step derivation
    1. *-commutative66.6%

      \[\leadsto x \cdot x - -4 \cdot \color{blue}{\left(y \cdot t\right)} \]
  5. Simplified66.6%

    \[\leadsto x \cdot x - \color{blue}{-4 \cdot \left(y \cdot t\right)} \]
  6. Final simplification66.6%

    \[\leadsto x \cdot x - -4 \cdot \left(t \cdot y\right) \]
  7. Add Preprocessing

Alternative 6: 31.2% accurate, 2.6× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ y \cdot \left(t \cdot 4\right) \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z t) :precision binary64 (* y (* t 4.0)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
	return y * (t * 4.0);
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
    real(8), intent (in) :: x_m
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = y * (t * 4.0d0)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
	return y * (t * 4.0);
}
x_m = math.fabs(x)
def code(x_m, y, z, t):
	return y * (t * 4.0)
x_m = abs(x)
function code(x_m, y, z, t)
	return Float64(y * Float64(t * 4.0))
end
x_m = abs(x);
function tmp = code(x_m, y, z, t)
	tmp = y * (t * 4.0);
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := N[(y * N[(t * 4.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
y \cdot \left(t \cdot 4\right)
\end{array}
Derivation
  1. Initial program 92.6%

    \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
  2. Add Preprocessing
  3. Taylor expanded in t around inf 32.7%

    \[\leadsto \color{blue}{4 \cdot \left(t \cdot y\right)} \]
  4. Step-by-step derivation
    1. associate-*r*32.7%

      \[\leadsto \color{blue}{\left(4 \cdot t\right) \cdot y} \]
  5. Simplified32.7%

    \[\leadsto \color{blue}{\left(4 \cdot t\right) \cdot y} \]
  6. Final simplification32.7%

    \[\leadsto y \cdot \left(t \cdot 4\right) \]
  7. Add Preprocessing

Developer target: 90.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right) \end{array} \]
(FPCore (x y z t) :precision binary64 (- (* x x) (* 4.0 (* y (- (* z z) t)))))
double code(double x, double y, double z, double t) {
	return (x * x) - (4.0 * (y * ((z * z) - t)));
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * x) - (4.0d0 * (y * ((z * z) - t)))
end function
public static double code(double x, double y, double z, double t) {
	return (x * x) - (4.0 * (y * ((z * z) - t)));
}
def code(x, y, z, t):
	return (x * x) - (4.0 * (y * ((z * z) - t)))
function code(x, y, z, t)
	return Float64(Float64(x * x) - Float64(4.0 * Float64(y * Float64(Float64(z * z) - t))))
end
function tmp = code(x, y, z, t)
	tmp = (x * x) - (4.0 * (y * ((z * z) - t)));
end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(4.0 * N[(y * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)
\end{array}

Reproduce

?
herbie shell --seed 2024079 
(FPCore (x y z t)
  :name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
  :precision binary64

  :alt
  (- (* x x) (* 4.0 (* y (- (* z z) t))))

  (- (* x x) (* (* y 4.0) (- (* z z) t))))