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

Percentage Accurate: 90.6% → 95.9%
Time: 6.9s
Alternatives: 8
Speedup: 0.8×

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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    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}

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 8 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.6% 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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x, y, z, t)
use fmin_fmax_functions
    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: 95.9% accurate, 0.7× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;x\_m \cdot x\_m - \mathsf{fma}\left(z, z \cdot \left(4 \cdot y\right), -4 \cdot \left(t \cdot y\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.35e+154)
   (- (* x_m x_m) (fma z (* z (* 4.0 y)) (* -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 <= 1.35e+154) {
		tmp = (x_m * x_m) - fma(z, (z * (4.0 * y)), (-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 (x_m <= 1.35e+154)
		tmp = Float64(Float64(x_m * x_m) - fma(z, Float64(z * Float64(4.0 * y)), Float64(-4.0 * Float64(t * y))));
	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.35e+154], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(z * N[(z * N[(4.0 * y), $MachinePrecision]), $MachinePrecision] + N[(-4.0 * N[(t * y), $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 1.35 \cdot 10^{+154}:\\
\;\;\;\;x\_m \cdot x\_m - \mathsf{fma}\left(z, z \cdot \left(4 \cdot y\right), -4 \cdot \left(t \cdot y\right)\right)\\

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


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

    1. Initial program 94.1%

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

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

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

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

    if 1.35000000000000003e154 < x

    1. Initial program 79.9%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    3. Applied rewrites91.4%

      \[\leadsto \color{blue}{x \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 94.0% accurate, 0.8× speedup?

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

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

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


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

    1. Initial program 93.6%

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

    if 9.9999999999999998e146 < z

    1. Initial program 71.1%

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x, x, -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 78.6% accurate, 1.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if z < 2.29999999999999986e-28

    1. Initial program 93.2%

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

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

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

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

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

    if 2.29999999999999986e-28 < z

    1. Initial program 83.8%

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

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

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

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

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

      \[\leadsto \mathsf{fma}\left(x, x, -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 76.0% accurate, 0.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;z \leq 1260000000:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, 4 \cdot \left(t \cdot y\right)\right)\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < 1.26e9

    1. Initial program 93.4%

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

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

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

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

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

    if 1.26e9 < z < 1.7499999999999999e190

    1. Initial program 88.2%

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

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

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

    if 1.7499999999999999e190 < z

    1. Initial program 73.4%

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

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

      \[\leadsto \color{blue}{\left(\left(z \cdot z\right) \cdot y\right) \cdot -4} \]
    4. Applied rewrites89.6%

      \[\leadsto \left(z \cdot \left(z \cdot y\right)\right) \cdot -4 \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 75.6% accurate, 1.2× speedup?

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

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

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


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

    1. Initial program 93.6%

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

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

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

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

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

    if 4.6999999999999998e61 < z

    1. Initial program 78.8%

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

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

      \[\leadsto \color{blue}{\left(\left(z \cdot z\right) \cdot y\right) \cdot -4} \]
    4. Applied rewrites79.2%

      \[\leadsto \left(z \cdot \left(z \cdot y\right)\right) \cdot -4 \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 58.6% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;z \leq 1.96 \cdot 10^{-140}:\\ \;\;\;\;\left(4 \cdot t\right) \cdot y\\ \mathbf{elif}\;z \leq 1260000000:\\ \;\;\;\;x\_m \cdot x\_m\\ \mathbf{else}:\\ \;\;\;\;\left(z \cdot \left(z \cdot y\right)\right) \cdot -4\\ \end{array} \end{array} \]
x_m = (fabs.f64 x)
(FPCore (x_m y z t)
 :precision binary64
 (if (<= z 1.96e-140)
   (* (* 4.0 t) y)
   (if (<= z 1260000000.0) (* x_m x_m) (* (* z (* z y)) -4.0))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
	double tmp;
	if (z <= 1.96e-140) {
		tmp = (4.0 * t) * y;
	} else if (z <= 1260000000.0) {
		tmp = x_m * x_m;
	} else {
		tmp = (z * (z * y)) * -4.0;
	}
	return tmp;
}
x_m =     private
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x_m, y, z, t)
use fmin_fmax_functions
    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 (z <= 1.96d-140) then
        tmp = (4.0d0 * t) * y
    else if (z <= 1260000000.0d0) then
        tmp = x_m * x_m
    else
        tmp = (z * (z * y)) * (-4.0d0)
    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 (z <= 1.96e-140) {
		tmp = (4.0 * t) * y;
	} else if (z <= 1260000000.0) {
		tmp = x_m * x_m;
	} else {
		tmp = (z * (z * y)) * -4.0;
	}
	return tmp;
}
x_m = math.fabs(x)
def code(x_m, y, z, t):
	tmp = 0
	if z <= 1.96e-140:
		tmp = (4.0 * t) * y
	elif z <= 1260000000.0:
		tmp = x_m * x_m
	else:
		tmp = (z * (z * y)) * -4.0
	return tmp
x_m = abs(x)
function code(x_m, y, z, t)
	tmp = 0.0
	if (z <= 1.96e-140)
		tmp = Float64(Float64(4.0 * t) * y);
	elseif (z <= 1260000000.0)
		tmp = Float64(x_m * x_m);
	else
		tmp = Float64(Float64(z * Float64(z * y)) * -4.0);
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, y, z, t)
	tmp = 0.0;
	if (z <= 1.96e-140)
		tmp = (4.0 * t) * y;
	elseif (z <= 1260000000.0)
		tmp = x_m * x_m;
	else
		tmp = (z * (z * y)) * -4.0;
	end
	tmp_2 = tmp;
end
x_m = N[Abs[x], $MachinePrecision]
code[x$95$m_, y_, z_, t_] := If[LessEqual[z, 1.96e-140], N[(N[(4.0 * t), $MachinePrecision] * y), $MachinePrecision], If[LessEqual[z, 1260000000.0], N[(x$95$m * x$95$m), $MachinePrecision], N[(N[(z * N[(z * y), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]]]
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.96 \cdot 10^{-140}:\\
\;\;\;\;\left(4 \cdot t\right) \cdot y\\

\mathbf{elif}\;z \leq 1260000000:\\
\;\;\;\;x\_m \cdot x\_m\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if z < 1.96000000000000002e-140

    1. Initial program 92.6%

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

      \[\leadsto \color{blue}{4 \cdot \left(t \cdot y\right)} \]
    3. Applied rewrites36.1%

      \[\leadsto \color{blue}{\left(t \cdot y\right) \cdot 4} \]
    4. Applied rewrites36.1%

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

    if 1.96000000000000002e-140 < z < 1.26e9

    1. Initial program 98.0%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    3. Applied rewrites52.0%

      \[\leadsto \color{blue}{x \cdot x} \]

    if 1.26e9 < z

    1. Initial program 82.1%

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

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

      \[\leadsto \color{blue}{\left(\left(z \cdot z\right) \cdot y\right) \cdot -4} \]
    4. Applied rewrites71.2%

      \[\leadsto \left(z \cdot \left(z \cdot y\right)\right) \cdot -4 \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 46.7% accurate, 1.7× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;x\_m \leq 0.195:\\ \;\;\;\;\left(4 \cdot t\right) \cdot y\\ \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 0.195) (* (* 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 <= 0.195) {
		tmp = (4.0 * t) * y;
	} else {
		tmp = x_m * x_m;
	}
	return tmp;
}
x_m =     private
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x_m, y, z, t)
use fmin_fmax_functions
    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 <= 0.195d0) 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 <= 0.195) {
		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 <= 0.195:
		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 (x_m <= 0.195)
		tmp = Float64(Float64(4.0 * 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 <= 0.195)
		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[LessEqual[x$95$m, 0.195], N[(N[(4.0 * t), $MachinePrecision] * y), $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 0.195:\\
\;\;\;\;\left(4 \cdot t\right) \cdot y\\

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


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

    1. Initial program 93.8%

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

      \[\leadsto \color{blue}{4 \cdot \left(t \cdot y\right)} \]
    3. Applied rewrites47.8%

      \[\leadsto \color{blue}{\left(t \cdot y\right) \cdot 4} \]
    4. Applied rewrites47.8%

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

    if 0.19500000000000001 < x

    1. Initial program 87.3%

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

      \[\leadsto \color{blue}{{x}^{2}} \]
    3. Applied rewrites69.3%

      \[\leadsto \color{blue}{x \cdot x} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 40.8% accurate, 4.6× 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 =     private
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(x_m, y, z, t)
use fmin_fmax_functions
    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 90.6%

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

    \[\leadsto \color{blue}{{x}^{2}} \]
  3. Applied rewrites40.8%

    \[\leadsto \color{blue}{x \cdot x} \]
  4. Add Preprocessing

Reproduce

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