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

Percentage Accurate: 90.1% → 94.8%
Time: 12.1s
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.1% 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: 94.8% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+289}:\\ \;\;\;\;x \cdot x - \left(y \cdot 4\right) \cdot \mathsf{fma}\left(z, z, -t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x \cdot x\right) \cdot \left(\left(y \cdot -4\right) \cdot {\left(\frac{z}{x}\right)}^{2} + 1\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= (* x x) 2e+289)
   (- (* x x) (* (* y 4.0) (fma z z (- t))))
   (* (* x x) (+ (* (* y -4.0) (pow (/ z x) 2.0)) 1.0))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((x * x) <= 2e+289) {
		tmp = (x * x) - ((y * 4.0) * fma(z, z, -t));
	} else {
		tmp = (x * x) * (((y * -4.0) * pow((z / x), 2.0)) + 1.0);
	}
	return tmp;
}
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(x * x) <= 2e+289)
		tmp = Float64(Float64(x * x) - Float64(Float64(y * 4.0) * fma(z, z, Float64(-t))));
	else
		tmp = Float64(Float64(x * x) * Float64(Float64(Float64(y * -4.0) * (Float64(z / x) ^ 2.0)) + 1.0));
	end
	return tmp
end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+289], N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(z * z + (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * N[(N[(N[(y * -4.0), $MachinePrecision] * N[Power[N[(z / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 93.0%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. fma-neg93.1%

        \[\leadsto x \cdot x - \left(y \cdot 4\right) \cdot \color{blue}{\mathsf{fma}\left(z, z, -t\right)} \]
    4. Applied egg-rr93.1%

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

    if 2.0000000000000001e289 < (*.f64 x x)

    1. Initial program 87.5%

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

        \[\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-in92.2%

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

        \[\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-in92.2%

        \[\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-eval92.2%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in x around inf 62.5%

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(1 + -4 \cdot \frac{y \cdot \left({z}^{2} - t\right)}{{x}^{2}}\right)} \]
    6. Step-by-step derivation
      1. associate-/l*73.4%

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

      \[\leadsto \color{blue}{{x}^{2} \cdot \left(1 + -4 \cdot \left(y \cdot \frac{{z}^{2} - t}{{x}^{2}}\right)\right)} \]
    8. Applied egg-rr62.5%

      \[\leadsto {x}^{2} \cdot \left(1 + \color{blue}{\frac{y \cdot \left(4 \cdot \mathsf{fma}\left(z, z, t\right)\right)}{-{x}^{2}}}\right) \]
    9. Step-by-step derivation
      1. associate-/l*73.4%

        \[\leadsto {x}^{2} \cdot \left(1 + \color{blue}{y \cdot \frac{4 \cdot \mathsf{fma}\left(z, z, t\right)}{-{x}^{2}}}\right) \]
      2. neg-mul-173.4%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \frac{4 \cdot \mathsf{fma}\left(z, z, t\right)}{\color{blue}{-1 \cdot {x}^{2}}}\right) \]
      3. times-frac73.4%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \color{blue}{\left(\frac{4}{-1} \cdot \frac{\mathsf{fma}\left(z, z, t\right)}{{x}^{2}}\right)}\right) \]
      4. metadata-eval73.4%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(\color{blue}{-4} \cdot \frac{\mathsf{fma}\left(z, z, t\right)}{{x}^{2}}\right)\right) \]
      5. rem-square-sqrt48.4%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \frac{\color{blue}{\sqrt{\mathsf{fma}\left(z, z, t\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, t\right)}}}{{x}^{2}}\right)\right) \]
      6. fma-undefine48.4%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \frac{\sqrt{\color{blue}{z \cdot z + t}} \cdot \sqrt{\mathsf{fma}\left(z, z, t\right)}}{{x}^{2}}\right)\right) \]
      7. rem-square-sqrt35.9%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \frac{\sqrt{z \cdot z + \color{blue}{\sqrt{t} \cdot \sqrt{t}}} \cdot \sqrt{\mathsf{fma}\left(z, z, t\right)}}{{x}^{2}}\right)\right) \]
      8. hypot-undefine35.9%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \frac{\color{blue}{\mathsf{hypot}\left(z, \sqrt{t}\right)} \cdot \sqrt{\mathsf{fma}\left(z, z, t\right)}}{{x}^{2}}\right)\right) \]
      9. fma-undefine35.9%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \frac{\mathsf{hypot}\left(z, \sqrt{t}\right) \cdot \sqrt{\color{blue}{z \cdot z + t}}}{{x}^{2}}\right)\right) \]
      10. rem-square-sqrt35.9%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \frac{\mathsf{hypot}\left(z, \sqrt{t}\right) \cdot \sqrt{z \cdot z + \color{blue}{\sqrt{t} \cdot \sqrt{t}}}}{{x}^{2}}\right)\right) \]
      11. hypot-undefine35.9%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \frac{\mathsf{hypot}\left(z, \sqrt{t}\right) \cdot \color{blue}{\mathsf{hypot}\left(z, \sqrt{t}\right)}}{{x}^{2}}\right)\right) \]
      12. unpow235.9%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \frac{\mathsf{hypot}\left(z, \sqrt{t}\right) \cdot \mathsf{hypot}\left(z, \sqrt{t}\right)}{\color{blue}{x \cdot x}}\right)\right) \]
      13. times-frac45.3%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \color{blue}{\left(\frac{\mathsf{hypot}\left(z, \sqrt{t}\right)}{x} \cdot \frac{\mathsf{hypot}\left(z, \sqrt{t}\right)}{x}\right)}\right)\right) \]
      14. unpow245.3%

        \[\leadsto {x}^{2} \cdot \left(1 + y \cdot \left(-4 \cdot \color{blue}{{\left(\frac{\mathsf{hypot}\left(z, \sqrt{t}\right)}{x}\right)}^{2}}\right)\right) \]
      15. associate-*r*45.3%

        \[\leadsto {x}^{2} \cdot \left(1 + \color{blue}{\left(y \cdot -4\right) \cdot {\left(\frac{\mathsf{hypot}\left(z, \sqrt{t}\right)}{x}\right)}^{2}}\right) \]
    10. Simplified45.3%

      \[\leadsto {x}^{2} \cdot \left(1 + \color{blue}{\left(y \cdot -4\right) \cdot {\left(\frac{\mathsf{hypot}\left(z, \sqrt{t}\right)}{x}\right)}^{2}}\right) \]
    11. Taylor expanded in z around inf 98.4%

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

        \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(y \cdot -4\right) \cdot {\left(\frac{z}{x}\right)}^{2}\right) \]
    13. Applied egg-rr98.4%

      \[\leadsto \color{blue}{\left(x \cdot x\right)} \cdot \left(1 + \left(y \cdot -4\right) \cdot {\left(\frac{z}{x}\right)}^{2}\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification94.4%

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

Alternative 2: 92.5% accurate, 0.1× speedup?

\[\begin{array}{l} \\ \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 (fma x x (* (* y -4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
	return fma(x, x, ((y * -4.0) * ((z * z) - t)));
}
function code(x, y, z, t)
	return fma(x, x, Float64(Float64(y * -4.0) * Float64(Float64(z * z) - t)))
end
code[x_, y_, z_, t_] := N[(x * x + N[(N[(y * -4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\right)
\end{array}
Derivation
  1. Initial program 91.7%

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

      \[\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-in92.8%

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

      \[\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-in92.8%

      \[\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-eval92.8%

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

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

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

Alternative 3: 91.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \cdot x \leq 8.5 \cdot 10^{+291}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= (* x x) 8.5e+291)
   (+ (* x x) (* (* y 4.0) (- t (* z z))))
   (- (* x x) (* y (* t -4.0)))))
double code(double x, double y, double z, double t) {
	double tmp;
	if ((x * x) <= 8.5e+291) {
		tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
	} else {
		tmp = (x * x) - (y * (t * -4.0));
	}
	return tmp;
}
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
    real(8) :: tmp
    if ((x * x) <= 8.5d+291) then
        tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
    else
        tmp = (x * x) - (y * (t * (-4.0d0)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((x * x) <= 8.5e+291) {
		tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
	} else {
		tmp = (x * x) - (y * (t * -4.0));
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if (x * x) <= 8.5e+291:
		tmp = (x * x) + ((y * 4.0) * (t - (z * z)))
	else:
		tmp = (x * x) - (y * (t * -4.0))
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(x * x) <= 8.5e+291)
		tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z))));
	else
		tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0)));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((x * x) <= 8.5e+291)
		tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
	else
		tmp = (x * x) - (y * (t * -4.0));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 8.5e+291], 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[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


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

    1. Initial program 93.1%

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

    if 8.5000000000000003e291 < (*.f64 x x)

    1. Initial program 87.3%

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

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

        \[\leadsto x \cdot x - \color{blue}{\left(t \cdot y\right) \cdot -4} \]
      2. *-commutative93.9%

        \[\leadsto x \cdot x - \color{blue}{\left(y \cdot t\right)} \cdot -4 \]
      3. associate-*l*93.9%

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

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

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

Alternative 4: 74.1% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 3.7 \cdot 10^{+65}:\\ \;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= z 3.7e+65) (- (* x x) (* y (* t -4.0))) (* (* y -4.0) (* z z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= 3.7e+65) {
		tmp = (x * x) - (y * (t * -4.0));
	} else {
		tmp = (y * -4.0) * (z * z);
	}
	return tmp;
}
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
    real(8) :: tmp
    if (z <= 3.7d+65) then
        tmp = (x * x) - (y * (t * (-4.0d0)))
    else
        tmp = (y * (-4.0d0)) * (z * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= 3.7e+65) {
		tmp = (x * x) - (y * (t * -4.0));
	} else {
		tmp = (y * -4.0) * (z * z);
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if z <= 3.7e+65:
		tmp = (x * x) - (y * (t * -4.0))
	else:
		tmp = (y * -4.0) * (z * z)
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (z <= 3.7e+65)
		tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0)));
	else
		tmp = Float64(Float64(y * -4.0) * Float64(z * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (z <= 3.7e+65)
		tmp = (x * x) - (y * (t * -4.0));
	else
		tmp = (y * -4.0) * (z * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[z, 3.7e+65], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * -4.0), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 3.69999999999999995e65

    1. Initial program 94.0%

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

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

        \[\leadsto x \cdot x - \color{blue}{\left(t \cdot y\right) \cdot -4} \]
      2. *-commutative72.8%

        \[\leadsto x \cdot x - \color{blue}{\left(y \cdot t\right)} \cdot -4 \]
      3. associate-*l*72.8%

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

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

    if 3.69999999999999995e65 < z

    1. Initial program 81.0%

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

        \[\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-in83.2%

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

        \[\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-in83.2%

        \[\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-eval83.2%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in z around inf 72.3%

      \[\leadsto \color{blue}{-4 \cdot \left(y \cdot {z}^{2}\right)} \]
    6. Step-by-step derivation
      1. associate-*r*72.3%

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

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

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

      \[\leadsto \color{blue}{{z}^{2} \cdot \left(y \cdot -4\right)} \]
    8. Step-by-step derivation
      1. pow272.3%

        \[\leadsto \color{blue}{\left(z \cdot z\right)} \cdot \left(y \cdot -4\right) \]
    9. Applied egg-rr72.3%

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

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

Alternative 5: 44.3% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;z \leq 2100000:\\ \;\;\;\;4 \cdot \left(y \cdot t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z\right)\\ \end{array} \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (if (<= z 2100000.0) (* 4.0 (* y t)) (* (* y -4.0) (* z z))))
double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= 2100000.0) {
		tmp = 4.0 * (y * t);
	} else {
		tmp = (y * -4.0) * (z * z);
	}
	return tmp;
}
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
    real(8) :: tmp
    if (z <= 2100000.0d0) then
        tmp = 4.0d0 * (y * t)
    else
        tmp = (y * (-4.0d0)) * (z * z)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= 2100000.0) {
		tmp = 4.0 * (y * t);
	} else {
		tmp = (y * -4.0) * (z * z);
	}
	return tmp;
}
def code(x, y, z, t):
	tmp = 0
	if z <= 2100000.0:
		tmp = 4.0 * (y * t)
	else:
		tmp = (y * -4.0) * (z * z)
	return tmp
function code(x, y, z, t)
	tmp = 0.0
	if (z <= 2100000.0)
		tmp = Float64(4.0 * Float64(y * t));
	else
		tmp = Float64(Float64(y * -4.0) * Float64(z * z));
	end
	return tmp
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (z <= 2100000.0)
		tmp = 4.0 * (y * t);
	else
		tmp = (y * -4.0) * (z * z);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := If[LessEqual[z, 2100000.0], N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(N[(y * -4.0), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;z \leq 2100000:\\
\;\;\;\;4 \cdot \left(y \cdot t\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 2.1e6

    1. Initial program 93.7%

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

        \[\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-in94.7%

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

        \[\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-in94.7%

        \[\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-eval94.7%

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)} \]
    4. Add Preprocessing
    5. Taylor expanded in t around inf 35.2%

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

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

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

    if 2.1e6 < z

    1. Initial program 84.6%

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

        \[\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-in86.4%

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

        \[\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-in86.4%

        \[\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-eval86.4%

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

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

      \[\leadsto \color{blue}{-4 \cdot \left(y \cdot {z}^{2}\right)} \]
    6. Step-by-step derivation
      1. associate-*r*63.8%

        \[\leadsto \color{blue}{\left(-4 \cdot y\right) \cdot {z}^{2}} \]
      2. *-commutative63.8%

        \[\leadsto \color{blue}{{z}^{2} \cdot \left(-4 \cdot y\right)} \]
      3. *-commutative63.8%

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

      \[\leadsto \color{blue}{{z}^{2} \cdot \left(y \cdot -4\right)} \]
    8. Step-by-step derivation
      1. pow263.8%

        \[\leadsto \color{blue}{\left(z \cdot z\right)} \cdot \left(y \cdot -4\right) \]
    9. Applied egg-rr63.8%

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

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

Alternative 6: 31.5% accurate, 2.6× speedup?

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

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

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

      \[\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-in92.8%

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

      \[\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-in92.8%

      \[\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-eval92.8%

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in t around inf 31.7%

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

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

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

Developer Target 1: 90.2% 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 2024146 
(FPCore (x y z t)
  :name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
  :precision binary64

  :alt
  (! :herbie-platform default (- (* x x) (* 4 (* y (- (* z z) t)))))

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