Diagrams.Solve.Polynomial:cubForm from diagrams-solve-0.1, I

Percentage Accurate: 91.0% → 96.1%
Time: 10.0s
Alternatives: 9
Speedup: 0.5×

Specification

?
\[\begin{array}{l} \\ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
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, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = ((x * y) - ((z * 9.0d0) * t)) / (a * 2.0d0)
end function
public static double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
def code(x, y, z, t, a):
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0)
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0))
end
function tmp = code(x, y, z, t, a)
	tmp = ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\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 9 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.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \end{array} \]
(FPCore (x y z t a)
 :precision binary64
 (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))
double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
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, a)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = ((x * y) - ((z * 9.0d0) * t)) / (a * 2.0d0)
end function
public static double code(double x, double y, double z, double t, double a) {
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
}
def code(x, y, z, t, a):
	return ((x * y) - ((z * 9.0) * t)) / (a * 2.0)
function code(x, y, z, t, a)
	return Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a * 2.0))
end
function tmp = code(x, y, z, t, a)
	tmp = ((x * y) - ((z * 9.0) * t)) / (a * 2.0);
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2}
\end{array}

Alternative 1: 96.1% accurate, 0.3× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a\_m \cdot 2}\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -\infty:\\ \;\;\;\;\frac{\mathsf{fma}\left(x \cdot 0.5, \frac{y}{t}, z \cdot -4.5\right)}{a\_m} \cdot t\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+285}:\\ \;\;\;\;\mathsf{fma}\left(-4.5, \frac{t \cdot z}{a\_m}, 0.5 \cdot \frac{x \cdot y}{a\_m}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\frac{x \cdot 0.5}{t}, y, z \cdot -4.5\right)}{a\_m} \cdot t\\ \end{array} \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (let* ((t_1 (/ (- (* x y) (* (* z 9.0) t)) (* a_m 2.0))))
   (*
    a_s
    (if (<= t_1 (- INFINITY))
      (* (/ (fma (* x 0.5) (/ y t) (* z -4.5)) a_m) t)
      (if (<= t_1 5e+285)
        (fma -4.5 (/ (* t z) a_m) (* 0.5 (/ (* x y) a_m)))
        (* (/ (fma (/ (* x 0.5) t) y (* z -4.5)) a_m) t))))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = ((x * y) - ((z * 9.0) * t)) / (a_m * 2.0);
	double tmp;
	if (t_1 <= -((double) INFINITY)) {
		tmp = (fma((x * 0.5), (y / t), (z * -4.5)) / a_m) * t;
	} else if (t_1 <= 5e+285) {
		tmp = fma(-4.5, ((t * z) / a_m), (0.5 * ((x * y) / a_m)));
	} else {
		tmp = (fma(((x * 0.5) / t), y, (z * -4.5)) / a_m) * t;
	}
	return a_s * tmp;
}
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t)) / Float64(a_m * 2.0))
	tmp = 0.0
	if (t_1 <= Float64(-Inf))
		tmp = Float64(Float64(fma(Float64(x * 0.5), Float64(y / t), Float64(z * -4.5)) / a_m) * t);
	elseif (t_1 <= 5e+285)
		tmp = fma(-4.5, Float64(Float64(t * z) / a_m), Float64(0.5 * Float64(Float64(x * y) / a_m)));
	else
		tmp = Float64(Float64(fma(Float64(Float64(x * 0.5) / t), y, Float64(z * -4.5)) / a_m) * t);
	end
	return Float64(a_s * tmp)
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision] / N[(a$95$m * 2.0), $MachinePrecision]), $MachinePrecision]}, N[(a$95$s * If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(N[(x * 0.5), $MachinePrecision] * N[(y / t), $MachinePrecision] + N[(z * -4.5), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision] * t), $MachinePrecision], If[LessEqual[t$95$1, 5e+285], N[(-4.5 * N[(N[(t * z), $MachinePrecision] / a$95$m), $MachinePrecision] + N[(0.5 * N[(N[(x * y), $MachinePrecision] / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(x * 0.5), $MachinePrecision] / t), $MachinePrecision] * y + N[(z * -4.5), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision] * t), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a\_m \cdot 2}\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -\infty:\\
\;\;\;\;\frac{\mathsf{fma}\left(x \cdot 0.5, \frac{y}{t}, z \cdot -4.5\right)}{a\_m} \cdot t\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{+285}:\\
\;\;\;\;\mathsf{fma}\left(-4.5, \frac{t \cdot z}{a\_m}, 0.5 \cdot \frac{x \cdot y}{a\_m}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(\frac{x \cdot 0.5}{t}, y, z \cdot -4.5\right)}{a\_m} \cdot t\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (-.f64 (*.f64 x y) (*.f64 (*.f64 z #s(literal 9 binary64)) t)) (*.f64 a #s(literal 2 binary64))) < -inf.0

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in t around inf

      \[\leadsto \color{blue}{t \cdot \left(\frac{-9}{2} \cdot \frac{z}{a} + \frac{1}{2} \cdot \frac{x \cdot y}{a \cdot t}\right)} \]
    3. Applied rewrites78.4%

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

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

    if -inf.0 < (/.f64 (-.f64 (*.f64 x y) (*.f64 (*.f64 z #s(literal 9 binary64)) t)) (*.f64 a #s(literal 2 binary64))) < 5.00000000000000016e285

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{-9}{2} \cdot \frac{t \cdot z}{a} + \frac{1}{2} \cdot \frac{x \cdot y}{a}} \]
    3. Applied rewrites89.0%

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

    if 5.00000000000000016e285 < (/.f64 (-.f64 (*.f64 x y) (*.f64 (*.f64 z #s(literal 9 binary64)) t)) (*.f64 a #s(literal 2 binary64)))

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in t around inf

      \[\leadsto \color{blue}{t \cdot \left(\frac{-9}{2} \cdot \frac{z}{a} + \frac{1}{2} \cdot \frac{x \cdot y}{a \cdot t}\right)} \]
    3. Applied rewrites78.4%

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

      \[\leadsto \frac{\mathsf{fma}\left(x \cdot 0.5, \frac{y}{t}, z \cdot -4.5\right)}{a} \cdot \color{blue}{t} \]
    5. Applied rewrites80.8%

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

Alternative 2: 95.6% accurate, 0.4× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := \frac{\mathsf{fma}\left(x \cdot 0.5, \frac{y}{t}, z \cdot -4.5\right)}{a\_m} \cdot t\\ t_2 := x \cdot y - \left(z \cdot 9\right) \cdot t\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;t\_2 \leq -\infty:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq 10^{+242}:\\ \;\;\;\;\frac{0.5}{a\_m} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (let* ((t_1 (* (/ (fma (* x 0.5) (/ y t) (* z -4.5)) a_m) t))
        (t_2 (- (* x y) (* (* z 9.0) t))))
   (*
    a_s
    (if (<= t_2 (- INFINITY))
      t_1
      (if (<= t_2 1e+242) (* (/ 0.5 a_m) (- (* x y) (* (* t 9.0) z))) t_1)))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = (fma((x * 0.5), (y / t), (z * -4.5)) / a_m) * t;
	double t_2 = (x * y) - ((z * 9.0) * t);
	double tmp;
	if (t_2 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_2 <= 1e+242) {
		tmp = (0.5 / a_m) * ((x * y) - ((t * 9.0) * z));
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(Float64(fma(Float64(x * 0.5), Float64(y / t), Float64(z * -4.5)) / a_m) * t)
	t_2 = Float64(Float64(x * y) - Float64(Float64(z * 9.0) * t))
	tmp = 0.0
	if (t_2 <= Float64(-Inf))
		tmp = t_1;
	elseif (t_2 <= 1e+242)
		tmp = Float64(Float64(0.5 / a_m) * Float64(Float64(x * y) - Float64(Float64(t * 9.0) * z)));
	else
		tmp = t_1;
	end
	return Float64(a_s * tmp)
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(N[(N[(N[(x * 0.5), $MachinePrecision] * N[(y / t), $MachinePrecision] + N[(z * -4.5), $MachinePrecision]), $MachinePrecision] / a$95$m), $MachinePrecision] * t), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * y), $MachinePrecision] - N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]}, N[(a$95$s * If[LessEqual[t$95$2, (-Infinity)], t$95$1, If[LessEqual[t$95$2, 1e+242], N[(N[(0.5 / a$95$m), $MachinePrecision] * N[(N[(x * y), $MachinePrecision] - N[(N[(t * 9.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]), $MachinePrecision]]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \frac{\mathsf{fma}\left(x \cdot 0.5, \frac{y}{t}, z \cdot -4.5\right)}{a\_m} \cdot t\\
t_2 := x \cdot y - \left(z \cdot 9\right) \cdot t\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_2 \leq -\infty:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_2 \leq 10^{+242}:\\
\;\;\;\;\frac{0.5}{a\_m} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (*.f64 x y) (*.f64 (*.f64 z #s(literal 9 binary64)) t)) < -inf.0 or 1.00000000000000005e242 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z #s(literal 9 binary64)) t))

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in t around inf

      \[\leadsto \color{blue}{t \cdot \left(\frac{-9}{2} \cdot \frac{z}{a} + \frac{1}{2} \cdot \frac{x \cdot y}{a \cdot t}\right)} \]
    3. Applied rewrites78.4%

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

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

    if -inf.0 < (-.f64 (*.f64 x y) (*.f64 (*.f64 z #s(literal 9 binary64)) t)) < 1.00000000000000005e242

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Applied rewrites91.0%

      \[\leadsto \frac{x \cdot y - \color{blue}{\left(t \cdot 9\right) \cdot z}}{a \cdot 2} \]
    3. Applied rewrites90.9%

      \[\leadsto \color{blue}{\frac{1}{a + a} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{a}} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right) \]
    5. Applied rewrites90.9%

      \[\leadsto \color{blue}{\frac{0.5}{a}} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right) \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 94.6% accurate, 0.5× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := \left(z \cdot 9\right) \cdot t\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+296}:\\ \;\;\;\;t \cdot \left(\frac{-4.5}{a\_m} \cdot z\right)\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+237}:\\ \;\;\;\;\frac{0.5}{a\_m} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-4.5 \cdot \frac{z}{a\_m}\right)\\ \end{array} \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (let* ((t_1 (* (* z 9.0) t)))
   (*
    a_s
    (if (<= t_1 -5e+296)
      (* t (* (/ -4.5 a_m) z))
      (if (<= t_1 2e+237)
        (* (/ 0.5 a_m) (- (* x y) (* (* t 9.0) z)))
        (* t (* -4.5 (/ z a_m))))))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = (z * 9.0) * t;
	double tmp;
	if (t_1 <= -5e+296) {
		tmp = t * ((-4.5 / a_m) * z);
	} else if (t_1 <= 2e+237) {
		tmp = (0.5 / a_m) * ((x * y) - ((t * 9.0) * z));
	} else {
		tmp = t * (-4.5 * (z / a_m));
	}
	return a_s * tmp;
}
a\_m =     private
a\_s =     private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (z * 9.0d0) * t
    if (t_1 <= (-5d+296)) then
        tmp = t * (((-4.5d0) / a_m) * z)
    else if (t_1 <= 2d+237) then
        tmp = (0.5d0 / a_m) * ((x * y) - ((t * 9.0d0) * z))
    else
        tmp = t * ((-4.5d0) * (z / a_m))
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = (z * 9.0) * t;
	double tmp;
	if (t_1 <= -5e+296) {
		tmp = t * ((-4.5 / a_m) * z);
	} else if (t_1 <= 2e+237) {
		tmp = (0.5 / a_m) * ((x * y) - ((t * 9.0) * z));
	} else {
		tmp = t * (-4.5 * (z / a_m));
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	t_1 = (z * 9.0) * t
	tmp = 0
	if t_1 <= -5e+296:
		tmp = t * ((-4.5 / a_m) * z)
	elif t_1 <= 2e+237:
		tmp = (0.5 / a_m) * ((x * y) - ((t * 9.0) * z))
	else:
		tmp = t * (-4.5 * (z / a_m))
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(Float64(z * 9.0) * t)
	tmp = 0.0
	if (t_1 <= -5e+296)
		tmp = Float64(t * Float64(Float64(-4.5 / a_m) * z));
	elseif (t_1 <= 2e+237)
		tmp = Float64(Float64(0.5 / a_m) * Float64(Float64(x * y) - Float64(Float64(t * 9.0) * z)));
	else
		tmp = Float64(t * Float64(-4.5 * Float64(z / a_m)));
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	t_1 = (z * 9.0) * t;
	tmp = 0.0;
	if (t_1 <= -5e+296)
		tmp = t * ((-4.5 / a_m) * z);
	elseif (t_1 <= 2e+237)
		tmp = (0.5 / a_m) * ((x * y) - ((t * 9.0) * z));
	else
		tmp = t * (-4.5 * (z / a_m));
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]}, N[(a$95$s * If[LessEqual[t$95$1, -5e+296], N[(t * N[(N[(-4.5 / a$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+237], N[(N[(0.5 / a$95$m), $MachinePrecision] * N[(N[(x * y), $MachinePrecision] - N[(N[(t * 9.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(-4.5 * N[(z / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \left(z \cdot 9\right) \cdot t\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+296}:\\
\;\;\;\;t \cdot \left(\frac{-4.5}{a\_m} \cdot z\right)\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+237}:\\
\;\;\;\;\frac{0.5}{a\_m} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;t \cdot \left(-4.5 \cdot \frac{z}{a\_m}\right)\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 z #s(literal 9 binary64)) t) < -5.0000000000000001e296

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in t around inf

      \[\leadsto \color{blue}{t \cdot \left(\frac{-9}{2} \cdot \frac{z}{a} + \frac{1}{2} \cdot \frac{x \cdot y}{a \cdot t}\right)} \]
    3. Applied rewrites78.4%

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

      \[\leadsto t \cdot \left(\frac{-9}{2} \cdot \color{blue}{\frac{z}{a}}\right) \]
    5. Applied rewrites50.1%

      \[\leadsto t \cdot \left(-4.5 \cdot \color{blue}{\frac{z}{a}}\right) \]
    6. Applied rewrites50.1%

      \[\leadsto t \cdot \left(\frac{-4.5}{a} \cdot z\right) \]

    if -5.0000000000000001e296 < (*.f64 (*.f64 z #s(literal 9 binary64)) t) < 1.99999999999999988e237

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Applied rewrites91.0%

      \[\leadsto \frac{x \cdot y - \color{blue}{\left(t \cdot 9\right) \cdot z}}{a \cdot 2} \]
    3. Applied rewrites90.9%

      \[\leadsto \color{blue}{\frac{1}{a + a} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right)} \]
    4. Taylor expanded in a around 0

      \[\leadsto \color{blue}{\frac{\frac{1}{2}}{a}} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right) \]
    5. Applied rewrites90.9%

      \[\leadsto \color{blue}{\frac{0.5}{a}} \cdot \left(x \cdot y - \left(t \cdot 9\right) \cdot z\right) \]

    if 1.99999999999999988e237 < (*.f64 (*.f64 z #s(literal 9 binary64)) t)

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in t around inf

      \[\leadsto \color{blue}{t \cdot \left(\frac{-9}{2} \cdot \frac{z}{a} + \frac{1}{2} \cdot \frac{x \cdot y}{a \cdot t}\right)} \]
    3. Applied rewrites78.4%

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

      \[\leadsto t \cdot \left(\frac{-9}{2} \cdot \color{blue}{\frac{z}{a}}\right) \]
    5. Applied rewrites50.1%

      \[\leadsto t \cdot \left(-4.5 \cdot \color{blue}{\frac{z}{a}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 94.6% accurate, 0.5× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := \left(z \cdot 9\right) \cdot t\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+296}:\\ \;\;\;\;t \cdot \left(\frac{-4.5}{a\_m} \cdot z\right)\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+227}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-9, t \cdot z, x \cdot y\right)}{a\_m + a\_m}\\ \mathbf{else}:\\ \;\;\;\;t \cdot \left(-4.5 \cdot \frac{z}{a\_m}\right)\\ \end{array} \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (let* ((t_1 (* (* z 9.0) t)))
   (*
    a_s
    (if (<= t_1 -5e+296)
      (* t (* (/ -4.5 a_m) z))
      (if (<= t_1 2e+227)
        (/ (fma -9.0 (* t z) (* x y)) (+ a_m a_m))
        (* t (* -4.5 (/ z a_m))))))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = (z * 9.0) * t;
	double tmp;
	if (t_1 <= -5e+296) {
		tmp = t * ((-4.5 / a_m) * z);
	} else if (t_1 <= 2e+227) {
		tmp = fma(-9.0, (t * z), (x * y)) / (a_m + a_m);
	} else {
		tmp = t * (-4.5 * (z / a_m));
	}
	return a_s * tmp;
}
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(Float64(z * 9.0) * t)
	tmp = 0.0
	if (t_1 <= -5e+296)
		tmp = Float64(t * Float64(Float64(-4.5 / a_m) * z));
	elseif (t_1 <= 2e+227)
		tmp = Float64(fma(-9.0, Float64(t * z), Float64(x * y)) / Float64(a_m + a_m));
	else
		tmp = Float64(t * Float64(-4.5 * Float64(z / a_m)));
	end
	return Float64(a_s * tmp)
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(N[(z * 9.0), $MachinePrecision] * t), $MachinePrecision]}, N[(a$95$s * If[LessEqual[t$95$1, -5e+296], N[(t * N[(N[(-4.5 / a$95$m), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+227], N[(N[(-9.0 * N[(t * z), $MachinePrecision] + N[(x * y), $MachinePrecision]), $MachinePrecision] / N[(a$95$m + a$95$m), $MachinePrecision]), $MachinePrecision], N[(t * N[(-4.5 * N[(z / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \left(z \cdot 9\right) \cdot t\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+296}:\\
\;\;\;\;t \cdot \left(\frac{-4.5}{a\_m} \cdot z\right)\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+227}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-9, t \cdot z, x \cdot y\right)}{a\_m + a\_m}\\

\mathbf{else}:\\
\;\;\;\;t \cdot \left(-4.5 \cdot \frac{z}{a\_m}\right)\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 (*.f64 z #s(literal 9 binary64)) t) < -5.0000000000000001e296

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in t around inf

      \[\leadsto \color{blue}{t \cdot \left(\frac{-9}{2} \cdot \frac{z}{a} + \frac{1}{2} \cdot \frac{x \cdot y}{a \cdot t}\right)} \]
    3. Applied rewrites78.4%

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

      \[\leadsto t \cdot \left(\frac{-9}{2} \cdot \color{blue}{\frac{z}{a}}\right) \]
    5. Applied rewrites50.1%

      \[\leadsto t \cdot \left(-4.5 \cdot \color{blue}{\frac{z}{a}}\right) \]
    6. Applied rewrites50.1%

      \[\leadsto t \cdot \left(\frac{-4.5}{a} \cdot z\right) \]

    if -5.0000000000000001e296 < (*.f64 (*.f64 z #s(literal 9 binary64)) t) < 2.0000000000000002e227

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in z around 0

      \[\leadsto \frac{\color{blue}{-9 \cdot \left(t \cdot z\right) + x \cdot y}}{a \cdot 2} \]
    3. Applied rewrites91.0%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(-9, t \cdot z, x \cdot y\right)}}{a \cdot 2} \]
    4. Applied rewrites91.0%

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

    if 2.0000000000000002e227 < (*.f64 (*.f64 z #s(literal 9 binary64)) t)

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in t around inf

      \[\leadsto \color{blue}{t \cdot \left(\frac{-9}{2} \cdot \frac{z}{a} + \frac{1}{2} \cdot \frac{x \cdot y}{a \cdot t}\right)} \]
    3. Applied rewrites78.4%

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

      \[\leadsto t \cdot \left(\frac{-9}{2} \cdot \color{blue}{\frac{z}{a}}\right) \]
    5. Applied rewrites50.1%

      \[\leadsto t \cdot \left(-4.5 \cdot \color{blue}{\frac{z}{a}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 72.8% accurate, 0.8× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := \frac{x \cdot 0.5}{a\_m} \cdot y\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+40}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 1000000000:\\ \;\;\;\;z \cdot \left(\frac{t}{a\_m} \cdot -4.5\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (let* ((t_1 (* (/ (* x 0.5) a_m) y)))
   (*
    a_s
    (if (<= (* x y) -5e+40)
      t_1
      (if (<= (* x y) 1000000000.0) (* z (* (/ t a_m) -4.5)) t_1)))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = ((x * 0.5) / a_m) * y;
	double tmp;
	if ((x * y) <= -5e+40) {
		tmp = t_1;
	} else if ((x * y) <= 1000000000.0) {
		tmp = z * ((t / a_m) * -4.5);
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m =     private
a\_s =     private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: t_1
    real(8) :: tmp
    t_1 = ((x * 0.5d0) / a_m) * y
    if ((x * y) <= (-5d+40)) then
        tmp = t_1
    else if ((x * y) <= 1000000000.0d0) then
        tmp = z * ((t / a_m) * (-4.5d0))
    else
        tmp = t_1
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = ((x * 0.5) / a_m) * y;
	double tmp;
	if ((x * y) <= -5e+40) {
		tmp = t_1;
	} else if ((x * y) <= 1000000000.0) {
		tmp = z * ((t / a_m) * -4.5);
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	t_1 = ((x * 0.5) / a_m) * y
	tmp = 0
	if (x * y) <= -5e+40:
		tmp = t_1
	elif (x * y) <= 1000000000.0:
		tmp = z * ((t / a_m) * -4.5)
	else:
		tmp = t_1
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(Float64(Float64(x * 0.5) / a_m) * y)
	tmp = 0.0
	if (Float64(x * y) <= -5e+40)
		tmp = t_1;
	elseif (Float64(x * y) <= 1000000000.0)
		tmp = Float64(z * Float64(Float64(t / a_m) * -4.5));
	else
		tmp = t_1;
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	t_1 = ((x * 0.5) / a_m) * y;
	tmp = 0.0;
	if ((x * y) <= -5e+40)
		tmp = t_1;
	elseif ((x * y) <= 1000000000.0)
		tmp = z * ((t / a_m) * -4.5);
	else
		tmp = t_1;
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(N[(N[(x * 0.5), $MachinePrecision] / a$95$m), $MachinePrecision] * y), $MachinePrecision]}, N[(a$95$s * If[LessEqual[N[(x * y), $MachinePrecision], -5e+40], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1000000000.0], N[(z * N[(N[(t / a$95$m), $MachinePrecision] * -4.5), $MachinePrecision]), $MachinePrecision], t$95$1]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \frac{x \cdot 0.5}{a\_m} \cdot y\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+40}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \cdot y \leq 1000000000:\\
\;\;\;\;z \cdot \left(\frac{t}{a\_m} \cdot -4.5\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -5.00000000000000003e40 or 1e9 < (*.f64 x y)

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x \cdot y}{a}} \]
    3. Applied rewrites51.6%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{a}} \]
    4. Applied rewrites52.1%

      \[\leadsto \frac{x \cdot 0.5}{a} \cdot \color{blue}{y} \]

    if -5.00000000000000003e40 < (*.f64 x y) < 1e9

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{-9}{2} \cdot \frac{t \cdot z}{a}} \]
    3. Applied rewrites49.3%

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a}} \]
    4. Applied rewrites50.2%

      \[\leadsto z \cdot \color{blue}{\left(\frac{t}{a} \cdot -4.5\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 6: 72.8% accurate, 0.8× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := \left(\frac{0.5}{a\_m} \cdot x\right) \cdot y\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+40}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 1000000000:\\ \;\;\;\;z \cdot \left(\frac{t}{a\_m} \cdot -4.5\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (let* ((t_1 (* (* (/ 0.5 a_m) x) y)))
   (*
    a_s
    (if (<= (* x y) -5e+40)
      t_1
      (if (<= (* x y) 1000000000.0) (* z (* (/ t a_m) -4.5)) t_1)))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = ((0.5 / a_m) * x) * y;
	double tmp;
	if ((x * y) <= -5e+40) {
		tmp = t_1;
	} else if ((x * y) <= 1000000000.0) {
		tmp = z * ((t / a_m) * -4.5);
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m =     private
a\_s =     private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: t_1
    real(8) :: tmp
    t_1 = ((0.5d0 / a_m) * x) * y
    if ((x * y) <= (-5d+40)) then
        tmp = t_1
    else if ((x * y) <= 1000000000.0d0) then
        tmp = z * ((t / a_m) * (-4.5d0))
    else
        tmp = t_1
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = ((0.5 / a_m) * x) * y;
	double tmp;
	if ((x * y) <= -5e+40) {
		tmp = t_1;
	} else if ((x * y) <= 1000000000.0) {
		tmp = z * ((t / a_m) * -4.5);
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	t_1 = ((0.5 / a_m) * x) * y
	tmp = 0
	if (x * y) <= -5e+40:
		tmp = t_1
	elif (x * y) <= 1000000000.0:
		tmp = z * ((t / a_m) * -4.5)
	else:
		tmp = t_1
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(Float64(Float64(0.5 / a_m) * x) * y)
	tmp = 0.0
	if (Float64(x * y) <= -5e+40)
		tmp = t_1;
	elseif (Float64(x * y) <= 1000000000.0)
		tmp = Float64(z * Float64(Float64(t / a_m) * -4.5));
	else
		tmp = t_1;
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	t_1 = ((0.5 / a_m) * x) * y;
	tmp = 0.0;
	if ((x * y) <= -5e+40)
		tmp = t_1;
	elseif ((x * y) <= 1000000000.0)
		tmp = z * ((t / a_m) * -4.5);
	else
		tmp = t_1;
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(N[(N[(0.5 / a$95$m), $MachinePrecision] * x), $MachinePrecision] * y), $MachinePrecision]}, N[(a$95$s * If[LessEqual[N[(x * y), $MachinePrecision], -5e+40], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 1000000000.0], N[(z * N[(N[(t / a$95$m), $MachinePrecision] * -4.5), $MachinePrecision]), $MachinePrecision], t$95$1]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := \left(\frac{0.5}{a\_m} \cdot x\right) \cdot y\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot y \leq -5 \cdot 10^{+40}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \cdot y \leq 1000000000:\\
\;\;\;\;z \cdot \left(\frac{t}{a\_m} \cdot -4.5\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -5.00000000000000003e40 or 1e9 < (*.f64 x y)

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x \cdot y}{a}} \]
    3. Applied rewrites51.6%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{a}} \]
    4. Applied rewrites52.1%

      \[\leadsto \frac{x \cdot 0.5}{a} \cdot \color{blue}{y} \]
    5. Applied rewrites52.1%

      \[\leadsto \left(\frac{0.5}{a} \cdot x\right) \cdot y \]

    if -5.00000000000000003e40 < (*.f64 x y) < 1e9

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{-9}{2} \cdot \frac{t \cdot z}{a}} \]
    3. Applied rewrites49.3%

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a}} \]
    4. Applied rewrites50.2%

      \[\leadsto z \cdot \color{blue}{\left(\frac{t}{a} \cdot -4.5\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 7: 72.6% accurate, 0.8× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := 0.5 \cdot \frac{x \cdot y}{a\_m}\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+36}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 3800000000:\\ \;\;\;\;z \cdot \left(\frac{t}{a\_m} \cdot -4.5\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (let* ((t_1 (* 0.5 (/ (* x y) a_m))))
   (*
    a_s
    (if (<= (* x y) -1e+36)
      t_1
      (if (<= (* x y) 3800000000.0) (* z (* (/ t a_m) -4.5)) t_1)))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = 0.5 * ((x * y) / a_m);
	double tmp;
	if ((x * y) <= -1e+36) {
		tmp = t_1;
	} else if ((x * y) <= 3800000000.0) {
		tmp = z * ((t / a_m) * -4.5);
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m =     private
a\_s =     private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: t_1
    real(8) :: tmp
    t_1 = 0.5d0 * ((x * y) / a_m)
    if ((x * y) <= (-1d+36)) then
        tmp = t_1
    else if ((x * y) <= 3800000000.0d0) then
        tmp = z * ((t / a_m) * (-4.5d0))
    else
        tmp = t_1
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = 0.5 * ((x * y) / a_m);
	double tmp;
	if ((x * y) <= -1e+36) {
		tmp = t_1;
	} else if ((x * y) <= 3800000000.0) {
		tmp = z * ((t / a_m) * -4.5);
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	t_1 = 0.5 * ((x * y) / a_m)
	tmp = 0
	if (x * y) <= -1e+36:
		tmp = t_1
	elif (x * y) <= 3800000000.0:
		tmp = z * ((t / a_m) * -4.5)
	else:
		tmp = t_1
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(0.5 * Float64(Float64(x * y) / a_m))
	tmp = 0.0
	if (Float64(x * y) <= -1e+36)
		tmp = t_1;
	elseif (Float64(x * y) <= 3800000000.0)
		tmp = Float64(z * Float64(Float64(t / a_m) * -4.5));
	else
		tmp = t_1;
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	t_1 = 0.5 * ((x * y) / a_m);
	tmp = 0.0;
	if ((x * y) <= -1e+36)
		tmp = t_1;
	elseif ((x * y) <= 3800000000.0)
		tmp = z * ((t / a_m) * -4.5);
	else
		tmp = t_1;
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(0.5 * N[(N[(x * y), $MachinePrecision] / a$95$m), $MachinePrecision]), $MachinePrecision]}, N[(a$95$s * If[LessEqual[N[(x * y), $MachinePrecision], -1e+36], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 3800000000.0], N[(z * N[(N[(t / a$95$m), $MachinePrecision] * -4.5), $MachinePrecision]), $MachinePrecision], t$95$1]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := 0.5 \cdot \frac{x \cdot y}{a\_m}\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot y \leq -1 \cdot 10^{+36}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \cdot y \leq 3800000000:\\
\;\;\;\;z \cdot \left(\frac{t}{a\_m} \cdot -4.5\right)\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -1.00000000000000004e36 or 3.8e9 < (*.f64 x y)

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x \cdot y}{a}} \]
    3. Applied rewrites51.6%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{a}} \]

    if -1.00000000000000004e36 < (*.f64 x y) < 3.8e9

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{-9}{2} \cdot \frac{t \cdot z}{a}} \]
    3. Applied rewrites49.3%

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a}} \]
    4. Applied rewrites50.2%

      \[\leadsto z \cdot \color{blue}{\left(\frac{t}{a} \cdot -4.5\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 8: 71.1% accurate, 0.8× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ \begin{array}{l} t_1 := 0.5 \cdot \frac{x \cdot y}{a\_m}\\ a\_s \cdot \begin{array}{l} \mathbf{if}\;x \cdot y \leq -0.0009:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;x \cdot y \leq 3800000000:\\ \;\;\;\;-4.5 \cdot \frac{t \cdot z}{a\_m}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m)
 :precision binary64
 (let* ((t_1 (* 0.5 (/ (* x y) a_m))))
   (*
    a_s
    (if (<= (* x y) -0.0009)
      t_1
      (if (<= (* x y) 3800000000.0) (* -4.5 (/ (* t z) a_m)) t_1)))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = 0.5 * ((x * y) / a_m);
	double tmp;
	if ((x * y) <= -0.0009) {
		tmp = t_1;
	} else if ((x * y) <= 3800000000.0) {
		tmp = -4.5 * ((t * z) / a_m);
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m =     private
a\_s =     private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    real(8) :: t_1
    real(8) :: tmp
    t_1 = 0.5d0 * ((x * y) / a_m)
    if ((x * y) <= (-0.0009d0)) then
        tmp = t_1
    else if ((x * y) <= 3800000000.0d0) then
        tmp = (-4.5d0) * ((t * z) / a_m)
    else
        tmp = t_1
    end if
    code = a_s * tmp
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	double t_1 = 0.5 * ((x * y) / a_m);
	double tmp;
	if ((x * y) <= -0.0009) {
		tmp = t_1;
	} else if ((x * y) <= 3800000000.0) {
		tmp = -4.5 * ((t * z) / a_m);
	} else {
		tmp = t_1;
	}
	return a_s * tmp;
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	t_1 = 0.5 * ((x * y) / a_m)
	tmp = 0
	if (x * y) <= -0.0009:
		tmp = t_1
	elif (x * y) <= 3800000000.0:
		tmp = -4.5 * ((t * z) / a_m)
	else:
		tmp = t_1
	return a_s * tmp
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	t_1 = Float64(0.5 * Float64(Float64(x * y) / a_m))
	tmp = 0.0
	if (Float64(x * y) <= -0.0009)
		tmp = t_1;
	elseif (Float64(x * y) <= 3800000000.0)
		tmp = Float64(-4.5 * Float64(Float64(t * z) / a_m));
	else
		tmp = t_1;
	end
	return Float64(a_s * tmp)
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp_2 = code(a_s, x, y, z, t, a_m)
	t_1 = 0.5 * ((x * y) / a_m);
	tmp = 0.0;
	if ((x * y) <= -0.0009)
		tmp = t_1;
	elseif ((x * y) <= 3800000000.0)
		tmp = -4.5 * ((t * z) / a_m);
	else
		tmp = t_1;
	end
	tmp_2 = a_s * tmp;
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := Block[{t$95$1 = N[(0.5 * N[(N[(x * y), $MachinePrecision] / a$95$m), $MachinePrecision]), $MachinePrecision]}, N[(a$95$s * If[LessEqual[N[(x * y), $MachinePrecision], -0.0009], t$95$1, If[LessEqual[N[(x * y), $MachinePrecision], 3800000000.0], N[(-4.5 * N[(N[(t * z), $MachinePrecision] / a$95$m), $MachinePrecision]), $MachinePrecision], t$95$1]]), $MachinePrecision]]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
\begin{array}{l}
t_1 := 0.5 \cdot \frac{x \cdot y}{a\_m}\\
a\_s \cdot \begin{array}{l}
\mathbf{if}\;x \cdot y \leq -0.0009:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;x \cdot y \leq 3800000000:\\
\;\;\;\;-4.5 \cdot \frac{t \cdot z}{a\_m}\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 x y) < -8.9999999999999998e-4 or 3.8e9 < (*.f64 x y)

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot \frac{x \cdot y}{a}} \]
    3. Applied rewrites51.6%

      \[\leadsto \color{blue}{0.5 \cdot \frac{x \cdot y}{a}} \]

    if -8.9999999999999998e-4 < (*.f64 x y) < 3.8e9

    1. Initial program 91.0%

      \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
    2. Taylor expanded in x around 0

      \[\leadsto \color{blue}{\frac{-9}{2} \cdot \frac{t \cdot z}{a}} \]
    3. Applied rewrites49.3%

      \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 9: 49.3% accurate, 1.8× speedup?

\[\begin{array}{l} a\_m = \left|a\right| \\ a\_s = \mathsf{copysign}\left(1, a\right) \\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\ [x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\ \\ a\_s \cdot \left(-4.5 \cdot \frac{t \cdot z}{a\_m}\right) \end{array} \]
a\_m = (fabs.f64 a)
a\_s = (copysign.f64 #s(literal 1 binary64) a)
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
(FPCore (a_s x y z t a_m) :precision binary64 (* a_s (* -4.5 (/ (* t z) a_m))))
a\_m = fabs(a);
a\_s = copysign(1.0, a);
assert(x < y && y < z && z < t && t < a_m);
assert(x < y && y < z && z < t && t < a_m);
double code(double a_s, double x, double y, double z, double t, double a_m) {
	return a_s * (-4.5 * ((t * z) / a_m));
}
a\_m =     private
a\_s =     private
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
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(a_s, x, y, z, t, a_m)
use fmin_fmax_functions
    real(8), intent (in) :: a_s
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a_m
    code = a_s * ((-4.5d0) * ((t * z) / a_m))
end function
a\_m = Math.abs(a);
a\_s = Math.copySign(1.0, a);
assert x < y && y < z && z < t && t < a_m;
assert x < y && y < z && z < t && t < a_m;
public static double code(double a_s, double x, double y, double z, double t, double a_m) {
	return a_s * (-4.5 * ((t * z) / a_m));
}
a\_m = math.fabs(a)
a\_s = math.copysign(1.0, a)
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
[x, y, z, t, a_m] = sort([x, y, z, t, a_m])
def code(a_s, x, y, z, t, a_m):
	return a_s * (-4.5 * ((t * z) / a_m))
a\_m = abs(a)
a\_s = copysign(1.0, a)
x, y, z, t, a_m = sort([x, y, z, t, a_m])
x, y, z, t, a_m = sort([x, y, z, t, a_m])
function code(a_s, x, y, z, t, a_m)
	return Float64(a_s * Float64(-4.5 * Float64(Float64(t * z) / a_m)))
end
a\_m = abs(a);
a\_s = sign(a) * abs(1.0);
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
x, y, z, t, a_m = num2cell(sort([x, y, z, t, a_m])){:}
function tmp = code(a_s, x, y, z, t, a_m)
	tmp = a_s * (-4.5 * ((t * z) / a_m));
end
a\_m = N[Abs[a], $MachinePrecision]
a\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
NOTE: x, y, z, t, and a_m should be sorted in increasing order before calling this function.
code[a$95$s_, x_, y_, z_, t_, a$95$m_] := N[(a$95$s * N[(-4.5 * N[(N[(t * z), $MachinePrecision] / a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a\_m = \left|a\right|
\\
a\_s = \mathsf{copysign}\left(1, a\right)
\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\\\
[x, y, z, t, a_m] = \mathsf{sort}([x, y, z, t, a_m])\\
\\
a\_s \cdot \left(-4.5 \cdot \frac{t \cdot z}{a\_m}\right)
\end{array}
Derivation
  1. Initial program 91.0%

    \[\frac{x \cdot y - \left(z \cdot 9\right) \cdot t}{a \cdot 2} \]
  2. Taylor expanded in x around 0

    \[\leadsto \color{blue}{\frac{-9}{2} \cdot \frac{t \cdot z}{a}} \]
  3. Applied rewrites49.3%

    \[\leadsto \color{blue}{-4.5 \cdot \frac{t \cdot z}{a}} \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025153 
(FPCore (x y z t a)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, I"
  :precision binary64
  (/ (- (* x y) (* (* z 9.0) t)) (* a 2.0)))