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

Percentage Accurate: 91.1% → 94.4%
Time: 6.3s
Alternatives: 5
Speedup: 0.9×

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 5 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: 91.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.4% accurate, 0.1× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 3.6 \cdot 10^{+217}:\\ \;\;\;\;\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 3.6e+217) (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 <= 3.6e+217) {
		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 <= 3.6e+217)
		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, 3.6e+217], 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 3.6 \cdot 10^{+217}:\\
\;\;\;\;\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 < 3.6000000000000002e217

    1. Initial program 85.6%

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Step-by-step derivation
      1. fma-neg88.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-in88.2%

        \[\leadsto \mathsf{fma}\left(x, x, \color{blue}{\left(-y \cdot 4\right) \cdot \left(z \cdot z - t\right)}\right) \]
      3. *-commutative88.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-in88.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-eval88.2%

        \[\leadsto \mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot \color{blue}{-4}\right)\right) \]
    3. Simplified88.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

    if 3.6000000000000002e217 < x

    1. Initial program 80.0%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    4. Step-by-step derivation
      1. pow296.0%

        \[\leadsto \color{blue}{x \cdot x} \]
    5. Applied egg-rr96.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.6 \cdot 10^{+217}:\\ \;\;\;\;\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: 57.1% accurate, 0.8× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \cdot x_m \leq 8.8 \cdot 10^{-238} \lor \neg \left(x_m \cdot x_m \leq 2.8 \cdot 10^{-193}\right) \land x_m \cdot x_m \leq 4.2 \cdot 10^{+90}:\\ \;\;\;\;4 \cdot \left(t \cdot y\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 (or (<= (* x_m x_m) 8.8e-238)
         (and (not (<= (* x_m x_m) 2.8e-193)) (<= (* x_m x_m) 4.2e+90)))
   (* 4.0 (* t y))
   (* 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) <= 8.8e-238) || (!((x_m * x_m) <= 2.8e-193) && ((x_m * x_m) <= 4.2e+90))) {
		tmp = 4.0 * (t * y);
	} 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) <= 8.8d-238) .or. (.not. ((x_m * x_m) <= 2.8d-193)) .and. ((x_m * x_m) <= 4.2d+90)) then
        tmp = 4.0d0 * (t * y)
    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) <= 8.8e-238) || (!((x_m * x_m) <= 2.8e-193) && ((x_m * x_m) <= 4.2e+90))) {
		tmp = 4.0 * (t * y);
	} 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) <= 8.8e-238) or (not ((x_m * x_m) <= 2.8e-193) and ((x_m * x_m) <= 4.2e+90)):
		tmp = 4.0 * (t * y)
	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) <= 8.8e-238) || (!(Float64(x_m * x_m) <= 2.8e-193) && (Float64(x_m * x_m) <= 4.2e+90)))
		tmp = Float64(4.0 * Float64(t * y));
	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) <= 8.8e-238) || (~(((x_m * x_m) <= 2.8e-193)) && ((x_m * x_m) <= 4.2e+90)))
		tmp = 4.0 * (t * y);
	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[Or[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 8.8e-238], And[N[Not[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 2.8e-193]], $MachinePrecision], LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 4.2e+90]]], N[(4.0 * N[(t * y), $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 8.8 \cdot 10^{-238} \lor \neg \left(x_m \cdot x_m \leq 2.8 \cdot 10^{-193}\right) \land x_m \cdot x_m \leq 4.2 \cdot 10^{+90}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\

\mathbf{else}:\\
\;\;\;\;x_m \cdot x_m\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x x) < 8.79999999999999965e-238 or 2.8000000000000002e-193 < (*.f64 x x) < 4.19999999999999961e90

    1. Initial program 90.8%

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

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

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

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

    if 8.79999999999999965e-238 < (*.f64 x x) < 2.8000000000000002e-193 or 4.19999999999999961e90 < (*.f64 x x)

    1. Initial program 78.7%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    4. Step-by-step derivation
      1. pow275.1%

        \[\leadsto \color{blue}{x \cdot x} \]
    5. Applied egg-rr75.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \cdot x \leq 8.8 \cdot 10^{-238} \lor \neg \left(x \cdot x \leq 2.8 \cdot 10^{-193}\right) \land x \cdot x \leq 4.2 \cdot 10^{+90}:\\ \;\;\;\;4 \cdot \left(t \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 92.8% accurate, 0.9× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \leq 2.3 \cdot 10^{+140}:\\ \;\;\;\;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 2.3e+140)
   (+ (* 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 <= 2.3e+140) {
		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 <= 2.3d+140) 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 <= 2.3e+140) {
		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 <= 2.3e+140:
		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 (x_m <= 2.3e+140)
		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 <= 2.3e+140)
		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[x$95$m, 2.3e+140], 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 \leq 2.3 \cdot 10^{+140}:\\
\;\;\;\;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 x < 2.2999999999999999e140

    1. Initial program 87.9%

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

    if 2.2999999999999999e140 < x

    1. Initial program 69.2%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    4. Step-by-step derivation
      1. pow289.7%

        \[\leadsto \color{blue}{x \cdot x} \]
    5. Applied egg-rr89.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 2.3 \cdot 10^{+140}:\\ \;\;\;\;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: 66.3% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x_m \cdot x_m \leq \infty:\\ \;\;\;\;x_m \cdot x_m - 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) INFINITY) (- (* x_m x_m) (* 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) <= ((double) INFINITY)) {
		tmp = (x_m * x_m) - (y * (t * -4.0));
	} else {
		tmp = x_m * x_m;
	}
	return tmp;
}
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) <= Double.POSITIVE_INFINITY) {
		tmp = (x_m * x_m) - (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) <= math.inf:
		tmp = (x_m * x_m) - (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) <= Inf)
		tmp = Float64(Float64(x_m * x_m) - 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) <= Inf)
		tmp = (x_m * x_m) - (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], Infinity], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(y * N[(t * -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 \cdot x_m \leq \infty:\\
\;\;\;\;x_m \cdot x_m - 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) < +inf.0

    1. Initial program 85.1%

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

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

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

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

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

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

    if +inf.0 < (*.f64 x x)

    1. Initial program 85.1%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    4. Step-by-step derivation
      1. pow241.9%

        \[\leadsto \color{blue}{x \cdot x} \]
    5. Applied egg-rr41.9%

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

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

Alternative 5: 41.0% accurate, 4.3× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ x_m \cdot x_m \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z t) :precision binary64 (* x_m x_m))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
	return x_m * x_m;
}
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
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;
}
x_m = math.fabs(x)
def code(x_m, y, z, t):
	return x_m * x_m
x_m = abs(x)
function code(x_m, y, z, t)
	return Float64(x_m * x_m)
end
x_m = abs(x);
function tmp = code(x_m, y, z, t)
	tmp = x_m * x_m;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := N[(x$95$m * x$95$m), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|

\\
x_m \cdot x_m
\end{array}
Derivation
  1. Initial program 85.1%

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

    \[\leadsto \color{blue}{{x}^{2}} \]
  4. Step-by-step derivation
    1. pow241.9%

      \[\leadsto \color{blue}{x \cdot x} \]
  5. Applied egg-rr41.9%

    \[\leadsto \color{blue}{x \cdot x} \]
  6. Final simplification41.9%

    \[\leadsto x \cdot x \]
  7. Add Preprocessing

Developer target: 91.1% 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 2024010 
(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))))