Quotient of products

Percentage Accurate: 86.5% → 98.6%
Time: 2.5s
Alternatives: 5
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{a1 \cdot a2}{b1 \cdot b2} \end{array} \]
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
double code(double a1, double a2, double b1, double b2) {
	return (a1 * a2) / (b1 * b2);
}
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(a1, a2, b1, b2)
use fmin_fmax_functions
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: b1
    real(8), intent (in) :: b2
    code = (a1 * a2) / (b1 * b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
	return (a1 * a2) / (b1 * b2);
}
def code(a1, a2, b1, b2):
	return (a1 * a2) / (b1 * b2)
function code(a1, a2, b1, b2)
	return Float64(Float64(a1 * a2) / Float64(b1 * b2))
end
function tmp = code(a1, a2, b1, b2)
	tmp = (a1 * a2) / (b1 * b2);
end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{a1 \cdot a2}{b1 \cdot b2}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 5 alternatives:

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

Initial Program: 86.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{a1 \cdot a2}{b1 \cdot b2} \end{array} \]
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
double code(double a1, double a2, double b1, double b2) {
	return (a1 * a2) / (b1 * b2);
}
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(a1, a2, b1, b2)
use fmin_fmax_functions
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: b1
    real(8), intent (in) :: b2
    code = (a1 * a2) / (b1 * b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
	return (a1 * a2) / (b1 * b2);
}
def code(a1, a2, b1, b2):
	return (a1 * a2) / (b1 * b2)
function code(a1, a2, b1, b2)
	return Float64(Float64(a1 * a2) / Float64(b1 * b2))
end
function tmp = code(a1, a2, b1, b2)
	tmp = (a1 * a2) / (b1 * b2);
end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{a1 \cdot a2}{b1 \cdot b2}
\end{array}

Alternative 1: 98.6% accurate, 0.6× speedup?

\[\begin{array}{l} a1\_m = \left|a1\right| \\ a1\_s = \mathsf{copysign}\left(1, a1\right) \\ a2\_m = \left|a2\right| \\ a2\_s = \mathsf{copysign}\left(1, a2\right) \\ b1\_m = \left|b1\right| \\ b1\_s = \mathsf{copysign}\left(1, b1\right) \\ b2\_m = \left|b2\right| \\ b2\_s = \mathsf{copysign}\left(1, b2\right) \\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\ \\ b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \begin{array}{l} \mathbf{if}\;a1\_m \cdot a2\_m \leq 5 \cdot 10^{-49}:\\ \;\;\;\;\frac{\frac{a1\_m}{b1\_m} \cdot a2\_m}{b2\_m}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a2\_m}{b2\_m} \cdot a1\_m}{b1\_m}\\ \end{array}\right)\right)\right) \end{array} \]
a1\_m = (fabs.f64 a1)
a1\_s = (copysign.f64 #s(literal 1 binary64) a1)
a2\_m = (fabs.f64 a2)
a2\_s = (copysign.f64 #s(literal 1 binary64) a2)
b1\_m = (fabs.f64 b1)
b1\_s = (copysign.f64 #s(literal 1 binary64) b1)
b2\_m = (fabs.f64 b2)
b2\_s = (copysign.f64 #s(literal 1 binary64) b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
(FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m)
 :precision binary64
 (*
  b2_s
  (*
   b1_s
   (*
    a2_s
    (*
     a1_s
     (if (<= (* a1_m a2_m) 5e-49)
       (/ (* (/ a1_m b1_m) a2_m) b2_m)
       (/ (* (/ a2_m b2_m) a1_m) b1_m)))))))
a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	double tmp;
	if ((a1_m * a2_m) <= 5e-49) {
		tmp = ((a1_m / b1_m) * a2_m) / b2_m;
	} else {
		tmp = ((a2_m / b2_m) * a1_m) / b1_m;
	}
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)));
}
a1\_m =     private
a1\_s =     private
a2\_m =     private
a2\_s =     private
b1\_m =     private
b1\_s =     private
b2\_m =     private
b2\_s =     private
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_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(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
use fmin_fmax_functions
    real(8), intent (in) :: b2_s
    real(8), intent (in) :: b1_s
    real(8), intent (in) :: a2_s
    real(8), intent (in) :: a1_s
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2_m
    real(8), intent (in) :: b1_m
    real(8), intent (in) :: b2_m
    real(8) :: tmp
    if ((a1_m * a2_m) <= 5d-49) then
        tmp = ((a1_m / b1_m) * a2_m) / b2_m
    else
        tmp = ((a2_m / b2_m) * a1_m) / b1_m
    end if
    code = b2_s * (b1_s * (a2_s * (a1_s * tmp)))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	double tmp;
	if ((a1_m * a2_m) <= 5e-49) {
		tmp = ((a1_m / b1_m) * a2_m) / b2_m;
	} else {
		tmp = ((a2_m / b2_m) * a1_m) / b1_m;
	}
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)));
}
a1\_m = math.fabs(a1)
a1\_s = math.copysign(1.0, a1)
a2\_m = math.fabs(a2)
a2\_s = math.copysign(1.0, a2)
b1\_m = math.fabs(b1)
b1\_s = math.copysign(1.0, b1)
b2\_m = math.fabs(b2)
b2\_s = math.copysign(1.0, b2)
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m):
	tmp = 0
	if (a1_m * a2_m) <= 5e-49:
		tmp = ((a1_m / b1_m) * a2_m) / b2_m
	else:
		tmp = ((a2_m / b2_m) * a1_m) / b1_m
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)))
a1\_m = abs(a1)
a1\_s = copysign(1.0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0, b2)
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	tmp = 0.0
	if (Float64(a1_m * a2_m) <= 5e-49)
		tmp = Float64(Float64(Float64(a1_m / b1_m) * a2_m) / b2_m);
	else
		tmp = Float64(Float64(Float64(a2_m / b2_m) * a1_m) / b1_m);
	end
	return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * tmp))))
end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp_2 = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	tmp = 0.0;
	if ((a1_m * a2_m) <= 5e-49)
		tmp = ((a1_m / b1_m) * a2_m) / b2_m;
	else
		tmp = ((a2_m / b2_m) * a1_m) / b1_m;
	end
	tmp_2 = b2_s * (b1_s * (a2_s * (a1_s * tmp)));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * If[LessEqual[N[(a1$95$m * a2$95$m), $MachinePrecision], 5e-49], N[(N[(N[(a1$95$m / b1$95$m), $MachinePrecision] * a2$95$m), $MachinePrecision] / b2$95$m), $MachinePrecision], N[(N[(N[(a2$95$m / b2$95$m), $MachinePrecision] * a1$95$m), $MachinePrecision] / b1$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \begin{array}{l}
\mathbf{if}\;a1\_m \cdot a2\_m \leq 5 \cdot 10^{-49}:\\
\;\;\;\;\frac{\frac{a1\_m}{b1\_m} \cdot a2\_m}{b2\_m}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{a2\_m}{b2\_m} \cdot a1\_m}{b1\_m}\\


\end{array}\right)\right)\right)
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 a1 a2) < 4.9999999999999999e-49

    1. Initial program 84.0%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{a1 \cdot a2}}{b1 \cdot b2} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b1 \cdot b2}} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}} \]
      4. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{\frac{a1 \cdot a2}{b1}}{b2}} \]
      5. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{a1 \cdot a2}{b1}}{b2}} \]
      6. associate-*l/N/A

        \[\leadsto \frac{\color{blue}{\frac{a1}{b1} \cdot a2}}{b2} \]
      7. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{a1}{b1} \cdot a2}}{b2} \]
      8. lower-/.f6489.2

        \[\leadsto \frac{\color{blue}{\frac{a1}{b1}} \cdot a2}{b2} \]
    4. Applied rewrites89.2%

      \[\leadsto \color{blue}{\frac{\frac{a1}{b1} \cdot a2}{b2}} \]

    if 4.9999999999999999e-49 < (*.f64 a1 a2)

    1. Initial program 83.5%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{a1 \cdot a2}}{b1 \cdot b2} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b1 \cdot b2}} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}} \]
      4. times-fracN/A

        \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
      5. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
      7. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{a2}{b2}} \cdot \frac{a1}{b1} \]
      8. lower-/.f6480.2

        \[\leadsto \frac{a2}{b2} \cdot \color{blue}{\frac{a1}{b1}} \]
    4. Applied rewrites80.2%

      \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
    5. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{a2}{b2}} \cdot \frac{a1}{b1} \]
      3. lift-/.f64N/A

        \[\leadsto \frac{a2}{b2} \cdot \color{blue}{\frac{a1}{b1}} \]
      4. associate-*r/N/A

        \[\leadsto \color{blue}{\frac{\frac{a2}{b2} \cdot a1}{b1}} \]
      5. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\frac{a2}{b2} \cdot a1\right)}{\mathsf{neg}\left(b1\right)}} \]
      6. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\frac{a2}{b2} \cdot a1\right)}{\mathsf{neg}\left(b1\right)}} \]
      7. distribute-lft-neg-inN/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(\frac{a2}{b2}\right)\right) \cdot a1}}{\mathsf{neg}\left(b1\right)} \]
      8. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{\left(\mathsf{neg}\left(\frac{a2}{b2}\right)\right) \cdot a1}}{\mathsf{neg}\left(b1\right)} \]
      9. distribute-neg-fracN/A

        \[\leadsto \frac{\color{blue}{\frac{\mathsf{neg}\left(a2\right)}{b2}} \cdot a1}{\mathsf{neg}\left(b1\right)} \]
      10. lower-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{\mathsf{neg}\left(a2\right)}{b2}} \cdot a1}{\mathsf{neg}\left(b1\right)} \]
      11. lower-neg.f64N/A

        \[\leadsto \frac{\frac{\color{blue}{-a2}}{b2} \cdot a1}{\mathsf{neg}\left(b1\right)} \]
      12. lower-neg.f6485.2

        \[\leadsto \frac{\frac{-a2}{b2} \cdot a1}{\color{blue}{-b1}} \]
    6. Applied rewrites85.2%

      \[\leadsto \color{blue}{\frac{\frac{-a2}{b2} \cdot a1}{-b1}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a1 \cdot a2 \leq 5 \cdot 10^{-49}:\\ \;\;\;\;\frac{\frac{a1}{b1} \cdot a2}{b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a2}{b2} \cdot a1}{b1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 95.3% accurate, 0.3× speedup?

\[\begin{array}{l} a1\_m = \left|a1\right| \\ a1\_s = \mathsf{copysign}\left(1, a1\right) \\ a2\_m = \left|a2\right| \\ a2\_s = \mathsf{copysign}\left(1, a2\right) \\ b1\_m = \left|b1\right| \\ b1\_s = \mathsf{copysign}\left(1, b1\right) \\ b2\_m = \left|b2\right| \\ b2\_s = \mathsf{copysign}\left(1, b2\right) \\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\ \\ \begin{array}{l} t_0 := \frac{a1\_m \cdot a2\_m}{b1\_m \cdot b2\_m}\\ b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq 10^{+272}\right):\\ \;\;\;\;\frac{a2\_m}{b1\_m} \cdot \frac{a1\_m}{b2\_m}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array}\right)\right)\right) \end{array} \end{array} \]
a1\_m = (fabs.f64 a1)
a1\_s = (copysign.f64 #s(literal 1 binary64) a1)
a2\_m = (fabs.f64 a2)
a2\_s = (copysign.f64 #s(literal 1 binary64) a2)
b1\_m = (fabs.f64 b1)
b1\_s = (copysign.f64 #s(literal 1 binary64) b1)
b2\_m = (fabs.f64 b2)
b2\_s = (copysign.f64 #s(literal 1 binary64) b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
(FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m)
 :precision binary64
 (let* ((t_0 (/ (* a1_m a2_m) (* b1_m b2_m))))
   (*
    b2_s
    (*
     b1_s
     (*
      a2_s
      (*
       a1_s
       (if (or (<= t_0 0.0) (not (<= t_0 1e+272)))
         (* (/ a2_m b1_m) (/ a1_m b2_m))
         t_0)))))))
a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	double t_0 = (a1_m * a2_m) / (b1_m * b2_m);
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= 1e+272)) {
		tmp = (a2_m / b1_m) * (a1_m / b2_m);
	} else {
		tmp = t_0;
	}
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)));
}
a1\_m =     private
a1\_s =     private
a2\_m =     private
a2\_s =     private
b1\_m =     private
b1\_s =     private
b2\_m =     private
b2\_s =     private
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_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(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
use fmin_fmax_functions
    real(8), intent (in) :: b2_s
    real(8), intent (in) :: b1_s
    real(8), intent (in) :: a2_s
    real(8), intent (in) :: a1_s
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2_m
    real(8), intent (in) :: b1_m
    real(8), intent (in) :: b2_m
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (a1_m * a2_m) / (b1_m * b2_m)
    if ((t_0 <= 0.0d0) .or. (.not. (t_0 <= 1d+272))) then
        tmp = (a2_m / b1_m) * (a1_m / b2_m)
    else
        tmp = t_0
    end if
    code = b2_s * (b1_s * (a2_s * (a1_s * tmp)))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	double t_0 = (a1_m * a2_m) / (b1_m * b2_m);
	double tmp;
	if ((t_0 <= 0.0) || !(t_0 <= 1e+272)) {
		tmp = (a2_m / b1_m) * (a1_m / b2_m);
	} else {
		tmp = t_0;
	}
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)));
}
a1\_m = math.fabs(a1)
a1\_s = math.copysign(1.0, a1)
a2\_m = math.fabs(a2)
a2\_s = math.copysign(1.0, a2)
b1\_m = math.fabs(b1)
b1\_s = math.copysign(1.0, b1)
b2\_m = math.fabs(b2)
b2\_s = math.copysign(1.0, b2)
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m):
	t_0 = (a1_m * a2_m) / (b1_m * b2_m)
	tmp = 0
	if (t_0 <= 0.0) or not (t_0 <= 1e+272):
		tmp = (a2_m / b1_m) * (a1_m / b2_m)
	else:
		tmp = t_0
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)))
a1\_m = abs(a1)
a1\_s = copysign(1.0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0, b2)
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	t_0 = Float64(Float64(a1_m * a2_m) / Float64(b1_m * b2_m))
	tmp = 0.0
	if ((t_0 <= 0.0) || !(t_0 <= 1e+272))
		tmp = Float64(Float64(a2_m / b1_m) * Float64(a1_m / b2_m));
	else
		tmp = t_0;
	end
	return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * tmp))))
end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp_2 = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	t_0 = (a1_m * a2_m) / (b1_m * b2_m);
	tmp = 0.0;
	if ((t_0 <= 0.0) || ~((t_0 <= 1e+272)))
		tmp = (a2_m / b1_m) * (a1_m / b2_m);
	else
		tmp = t_0;
	end
	tmp_2 = b2_s * (b1_s * (a2_s * (a1_s * tmp)));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := Block[{t$95$0 = N[(N[(a1$95$m * a2$95$m), $MachinePrecision] / N[(b1$95$m * b2$95$m), $MachinePrecision]), $MachinePrecision]}, N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * If[Or[LessEqual[t$95$0, 0.0], N[Not[LessEqual[t$95$0, 1e+272]], $MachinePrecision]], N[(N[(a2$95$m / b1$95$m), $MachinePrecision] * N[(a1$95$m / b2$95$m), $MachinePrecision]), $MachinePrecision], t$95$0]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
\begin{array}{l}
t_0 := \frac{a1\_m \cdot a2\_m}{b1\_m \cdot b2\_m}\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0 \lor \neg \left(t\_0 \leq 10^{+272}\right):\\
\;\;\;\;\frac{a2\_m}{b1\_m} \cdot \frac{a1\_m}{b2\_m}\\

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


\end{array}\right)\right)\right)
\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0 or 1.0000000000000001e272 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 78.9%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{a1 \cdot a2}}{b1 \cdot b2} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b1 \cdot b2}} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\color{blue}{a2 \cdot a1}}{b1 \cdot b2} \]
      5. times-fracN/A

        \[\leadsto \color{blue}{\frac{a2}{b1} \cdot \frac{a1}{b2}} \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{a2}{b1} \cdot \frac{a1}{b2}} \]
      7. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{a2}{b1}} \cdot \frac{a1}{b2} \]
      8. lower-/.f6488.0

        \[\leadsto \frac{a2}{b1} \cdot \color{blue}{\frac{a1}{b2}} \]
    4. Applied rewrites88.0%

      \[\leadsto \color{blue}{\frac{a2}{b1} \cdot \frac{a1}{b2}} \]

    if 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e272

    1. Initial program 99.5%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing
  3. Recombined 2 regimes into one program.
  4. Final simplification90.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0 \lor \neg \left(\frac{a1 \cdot a2}{b1 \cdot b2} \leq 10^{+272}\right):\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 91.3% accurate, 0.4× speedup?

\[\begin{array}{l} a1\_m = \left|a1\right| \\ a1\_s = \mathsf{copysign}\left(1, a1\right) \\ a2\_m = \left|a2\right| \\ a2\_s = \mathsf{copysign}\left(1, a2\right) \\ b1\_m = \left|b1\right| \\ b1\_s = \mathsf{copysign}\left(1, b1\right) \\ b2\_m = \left|b2\right| \\ b2\_s = \mathsf{copysign}\left(1, b2\right) \\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\ \\ b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \begin{array}{l} \mathbf{if}\;\frac{a1\_m \cdot a2\_m}{b1\_m \cdot b2\_m} \leq 2 \cdot 10^{-72}:\\ \;\;\;\;\frac{a2\_m}{b1\_m \cdot b2\_m} \cdot a1\_m\\ \mathbf{else}:\\ \;\;\;\;\frac{a1\_m}{b1\_m \cdot b2\_m} \cdot a2\_m\\ \end{array}\right)\right)\right) \end{array} \]
a1\_m = (fabs.f64 a1)
a1\_s = (copysign.f64 #s(literal 1 binary64) a1)
a2\_m = (fabs.f64 a2)
a2\_s = (copysign.f64 #s(literal 1 binary64) a2)
b1\_m = (fabs.f64 b1)
b1\_s = (copysign.f64 #s(literal 1 binary64) b1)
b2\_m = (fabs.f64 b2)
b2\_s = (copysign.f64 #s(literal 1 binary64) b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
(FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m)
 :precision binary64
 (*
  b2_s
  (*
   b1_s
   (*
    a2_s
    (*
     a1_s
     (if (<= (/ (* a1_m a2_m) (* b1_m b2_m)) 2e-72)
       (* (/ a2_m (* b1_m b2_m)) a1_m)
       (* (/ a1_m (* b1_m b2_m)) a2_m)))))))
a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	double tmp;
	if (((a1_m * a2_m) / (b1_m * b2_m)) <= 2e-72) {
		tmp = (a2_m / (b1_m * b2_m)) * a1_m;
	} else {
		tmp = (a1_m / (b1_m * b2_m)) * a2_m;
	}
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)));
}
a1\_m =     private
a1\_s =     private
a2\_m =     private
a2\_s =     private
b1\_m =     private
b1\_s =     private
b2\_m =     private
b2\_s =     private
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_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(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
use fmin_fmax_functions
    real(8), intent (in) :: b2_s
    real(8), intent (in) :: b1_s
    real(8), intent (in) :: a2_s
    real(8), intent (in) :: a1_s
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2_m
    real(8), intent (in) :: b1_m
    real(8), intent (in) :: b2_m
    real(8) :: tmp
    if (((a1_m * a2_m) / (b1_m * b2_m)) <= 2d-72) then
        tmp = (a2_m / (b1_m * b2_m)) * a1_m
    else
        tmp = (a1_m / (b1_m * b2_m)) * a2_m
    end if
    code = b2_s * (b1_s * (a2_s * (a1_s * tmp)))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	double tmp;
	if (((a1_m * a2_m) / (b1_m * b2_m)) <= 2e-72) {
		tmp = (a2_m / (b1_m * b2_m)) * a1_m;
	} else {
		tmp = (a1_m / (b1_m * b2_m)) * a2_m;
	}
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)));
}
a1\_m = math.fabs(a1)
a1\_s = math.copysign(1.0, a1)
a2\_m = math.fabs(a2)
a2\_s = math.copysign(1.0, a2)
b1\_m = math.fabs(b1)
b1\_s = math.copysign(1.0, b1)
b2\_m = math.fabs(b2)
b2\_s = math.copysign(1.0, b2)
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m):
	tmp = 0
	if ((a1_m * a2_m) / (b1_m * b2_m)) <= 2e-72:
		tmp = (a2_m / (b1_m * b2_m)) * a1_m
	else:
		tmp = (a1_m / (b1_m * b2_m)) * a2_m
	return b2_s * (b1_s * (a2_s * (a1_s * tmp)))
a1\_m = abs(a1)
a1\_s = copysign(1.0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0, b2)
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	tmp = 0.0
	if (Float64(Float64(a1_m * a2_m) / Float64(b1_m * b2_m)) <= 2e-72)
		tmp = Float64(Float64(a2_m / Float64(b1_m * b2_m)) * a1_m);
	else
		tmp = Float64(Float64(a1_m / Float64(b1_m * b2_m)) * a2_m);
	end
	return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * tmp))))
end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp_2 = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	tmp = 0.0;
	if (((a1_m * a2_m) / (b1_m * b2_m)) <= 2e-72)
		tmp = (a2_m / (b1_m * b2_m)) * a1_m;
	else
		tmp = (a1_m / (b1_m * b2_m)) * a2_m;
	end
	tmp_2 = b2_s * (b1_s * (a2_s * (a1_s * tmp)));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * If[LessEqual[N[(N[(a1$95$m * a2$95$m), $MachinePrecision] / N[(b1$95$m * b2$95$m), $MachinePrecision]), $MachinePrecision], 2e-72], N[(N[(a2$95$m / N[(b1$95$m * b2$95$m), $MachinePrecision]), $MachinePrecision] * a1$95$m), $MachinePrecision], N[(N[(a1$95$m / N[(b1$95$m * b2$95$m), $MachinePrecision]), $MachinePrecision] * a2$95$m), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \begin{array}{l}
\mathbf{if}\;\frac{a1\_m \cdot a2\_m}{b1\_m \cdot b2\_m} \leq 2 \cdot 10^{-72}:\\
\;\;\;\;\frac{a2\_m}{b1\_m \cdot b2\_m} \cdot a1\_m\\

\mathbf{else}:\\
\;\;\;\;\frac{a1\_m}{b1\_m \cdot b2\_m} \cdot a2\_m\\


\end{array}\right)\right)\right)
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.9999999999999999e-72

    1. Initial program 87.7%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{a1 \cdot a2}}{b1 \cdot b2} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b1 \cdot b2}} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}} \]
      4. associate-/l*N/A

        \[\leadsto \color{blue}{a1 \cdot \frac{a2}{b1 \cdot b2}} \]
      5. *-commutativeN/A

        \[\leadsto \color{blue}{\frac{a2}{b1 \cdot b2} \cdot a1} \]
      6. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{a2}{b1 \cdot b2} \cdot a1} \]
      7. *-commutativeN/A

        \[\leadsto \frac{a2}{\color{blue}{b2 \cdot b1}} \cdot a1 \]
      8. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{\frac{a2}{b2}}{b1}} \cdot a1 \]
      9. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{a2}{b2}}{b1}} \cdot a1 \]
      10. lower-/.f6483.7

        \[\leadsto \frac{\color{blue}{\frac{a2}{b2}}}{b1} \cdot a1 \]
    4. Applied rewrites83.7%

      \[\leadsto \color{blue}{\frac{\frac{a2}{b2}}{b1} \cdot a1} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{a2}{b2}}}{b1} \cdot a1 \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{a2}{b2}}{b1}} \cdot a1 \]
      3. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{a2}{b2 \cdot b1}} \cdot a1 \]
      4. *-commutativeN/A

        \[\leadsto \frac{a2}{\color{blue}{b1 \cdot b2}} \cdot a1 \]
      5. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(a2\right)}{\mathsf{neg}\left(b1 \cdot b2\right)}} \cdot a1 \]
      6. distribute-frac-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{a2}{\mathsf{neg}\left(b1 \cdot b2\right)}\right)\right)} \cdot a1 \]
      7. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{a2}{\mathsf{neg}\left(\left(\mathsf{neg}\left(b1 \cdot b2\right)\right)\right)}} \cdot a1 \]
      8. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{a2}{\mathsf{neg}\left(\left(\mathsf{neg}\left(b1 \cdot b2\right)\right)\right)}} \cdot a1 \]
      9. remove-double-negN/A

        \[\leadsto \frac{a2}{\color{blue}{b1 \cdot b2}} \cdot a1 \]
      10. lower-*.f6483.8

        \[\leadsto \frac{a2}{\color{blue}{b1 \cdot b2}} \cdot a1 \]
    6. Applied rewrites83.8%

      \[\leadsto \color{blue}{\frac{a2}{b1 \cdot b2}} \cdot a1 \]

    if 1.9999999999999999e-72 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 76.6%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\color{blue}{a1 \cdot a2}}{b1 \cdot b2} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b1 \cdot b2}} \]
      3. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}} \]
      4. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]
      5. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]
      6. *-commutativeN/A

        \[\leadsto \frac{a1}{\color{blue}{b2 \cdot b1}} \cdot a2 \]
      7. associate-/r*N/A

        \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{b1}} \cdot a2 \]
      8. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{b1}} \cdot a2 \]
      9. lower-/.f6480.5

        \[\leadsto \frac{\color{blue}{\frac{a1}{b2}}}{b1} \cdot a2 \]
    4. Applied rewrites80.5%

      \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{b1} \cdot a2} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\color{blue}{\frac{a1}{b2}}}{b1} \cdot a2 \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{b1}} \cdot a2 \]
      3. associate-/l/N/A

        \[\leadsto \color{blue}{\frac{a1}{b2 \cdot b1}} \cdot a2 \]
      4. *-commutativeN/A

        \[\leadsto \frac{a1}{\color{blue}{b1 \cdot b2}} \cdot a2 \]
      5. frac-2negN/A

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(a1\right)}{\mathsf{neg}\left(b1 \cdot b2\right)}} \cdot a2 \]
      6. distribute-frac-negN/A

        \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{a1}{\mathsf{neg}\left(b1 \cdot b2\right)}\right)\right)} \cdot a2 \]
      7. distribute-neg-frac2N/A

        \[\leadsto \color{blue}{\frac{a1}{\mathsf{neg}\left(\left(\mathsf{neg}\left(b1 \cdot b2\right)\right)\right)}} \cdot a2 \]
      8. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{a1}{\mathsf{neg}\left(\left(\mathsf{neg}\left(b1 \cdot b2\right)\right)\right)}} \cdot a2 \]
      9. remove-double-negN/A

        \[\leadsto \frac{a1}{\color{blue}{b1 \cdot b2}} \cdot a2 \]
      10. lower-*.f6472.7

        \[\leadsto \frac{a1}{\color{blue}{b1 \cdot b2}} \cdot a2 \]
    6. Applied rewrites72.7%

      \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2}} \cdot a2 \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 97.7% accurate, 0.8× speedup?

\[\begin{array}{l} a1\_m = \left|a1\right| \\ a1\_s = \mathsf{copysign}\left(1, a1\right) \\ a2\_m = \left|a2\right| \\ a2\_s = \mathsf{copysign}\left(1, a2\right) \\ b1\_m = \left|b1\right| \\ b1\_s = \mathsf{copysign}\left(1, b1\right) \\ b2\_m = \left|b2\right| \\ b2\_s = \mathsf{copysign}\left(1, b2\right) \\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\ \\ b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \left(\frac{a2\_m}{b2\_m} \cdot \frac{a1\_m}{b1\_m}\right)\right)\right)\right) \end{array} \]
a1\_m = (fabs.f64 a1)
a1\_s = (copysign.f64 #s(literal 1 binary64) a1)
a2\_m = (fabs.f64 a2)
a2\_s = (copysign.f64 #s(literal 1 binary64) a2)
b1\_m = (fabs.f64 b1)
b1\_s = (copysign.f64 #s(literal 1 binary64) b1)
b2\_m = (fabs.f64 b2)
b2\_s = (copysign.f64 #s(literal 1 binary64) b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
(FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m)
 :precision binary64
 (* b2_s (* b1_s (* a2_s (* a1_s (* (/ a2_m b2_m) (/ a1_m b1_m)))))))
a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	return b2_s * (b1_s * (a2_s * (a1_s * ((a2_m / b2_m) * (a1_m / b1_m)))));
}
a1\_m =     private
a1\_s =     private
a2\_m =     private
a2\_s =     private
b1\_m =     private
b1\_s =     private
b2\_m =     private
b2\_s =     private
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_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(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
use fmin_fmax_functions
    real(8), intent (in) :: b2_s
    real(8), intent (in) :: b1_s
    real(8), intent (in) :: a2_s
    real(8), intent (in) :: a1_s
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2_m
    real(8), intent (in) :: b1_m
    real(8), intent (in) :: b2_m
    code = b2_s * (b1_s * (a2_s * (a1_s * ((a2_m / b2_m) * (a1_m / b1_m)))))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	return b2_s * (b1_s * (a2_s * (a1_s * ((a2_m / b2_m) * (a1_m / b1_m)))));
}
a1\_m = math.fabs(a1)
a1\_s = math.copysign(1.0, a1)
a2\_m = math.fabs(a2)
a2\_s = math.copysign(1.0, a2)
b1\_m = math.fabs(b1)
b1\_s = math.copysign(1.0, b1)
b2\_m = math.fabs(b2)
b2\_s = math.copysign(1.0, b2)
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m):
	return b2_s * (b1_s * (a2_s * (a1_s * ((a2_m / b2_m) * (a1_m / b1_m)))))
a1\_m = abs(a1)
a1\_s = copysign(1.0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0, b2)
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * Float64(Float64(a2_m / b2_m) * Float64(a1_m / b1_m))))))
end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	tmp = b2_s * (b1_s * (a2_s * (a1_s * ((a2_m / b2_m) * (a1_m / b1_m)))));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * N[(N[(a2$95$m / b2$95$m), $MachinePrecision] * N[(a1$95$m / b1$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \left(\frac{a2\_m}{b2\_m} \cdot \frac{a1\_m}{b1\_m}\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 83.9%

    \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{a1 \cdot a2}}{b1 \cdot b2} \]
    2. lift-*.f64N/A

      \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b1 \cdot b2}} \]
    3. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}} \]
    4. times-fracN/A

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
    5. *-commutativeN/A

      \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
    6. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
    7. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{a2}{b2}} \cdot \frac{a1}{b1} \]
    8. lower-/.f6484.2

      \[\leadsto \frac{a2}{b2} \cdot \color{blue}{\frac{a1}{b1}} \]
  4. Applied rewrites84.2%

    \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
  5. Add Preprocessing

Alternative 5: 86.9% accurate, 1.0× speedup?

\[\begin{array}{l} a1\_m = \left|a1\right| \\ a1\_s = \mathsf{copysign}\left(1, a1\right) \\ a2\_m = \left|a2\right| \\ a2\_s = \mathsf{copysign}\left(1, a2\right) \\ b1\_m = \left|b1\right| \\ b1\_s = \mathsf{copysign}\left(1, b1\right) \\ b2\_m = \left|b2\right| \\ b2\_s = \mathsf{copysign}\left(1, b2\right) \\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\ [a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\ \\ b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \left(\frac{a1\_m}{b1\_m \cdot b2\_m} \cdot a2\_m\right)\right)\right)\right) \end{array} \]
a1\_m = (fabs.f64 a1)
a1\_s = (copysign.f64 #s(literal 1 binary64) a1)
a2\_m = (fabs.f64 a2)
a2\_s = (copysign.f64 #s(literal 1 binary64) a2)
b1\_m = (fabs.f64 b1)
b1\_s = (copysign.f64 #s(literal 1 binary64) b1)
b2\_m = (fabs.f64 b2)
b2\_s = (copysign.f64 #s(literal 1 binary64) b2)
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
(FPCore (b2_s b1_s a2_s a1_s a1_m a2_m b1_m b2_m)
 :precision binary64
 (* b2_s (* b1_s (* a2_s (* a1_s (* (/ a1_m (* b1_m b2_m)) a2_m))))))
a1\_m = fabs(a1);
a1\_s = copysign(1.0, a1);
a2\_m = fabs(a2);
a2\_s = copysign(1.0, a2);
b1\_m = fabs(b1);
b1\_s = copysign(1.0, b1);
b2\_m = fabs(b2);
b2\_s = copysign(1.0, b2);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
assert(a1_m < a2_m && a2_m < b1_m && b1_m < b2_m);
double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / (b1_m * b2_m)) * a2_m))));
}
a1\_m =     private
a1\_s =     private
a2\_m =     private
a2\_s =     private
b1\_m =     private
b1\_s =     private
b2\_m =     private
b2\_s =     private
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_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(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
use fmin_fmax_functions
    real(8), intent (in) :: b2_s
    real(8), intent (in) :: b1_s
    real(8), intent (in) :: a2_s
    real(8), intent (in) :: a1_s
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2_m
    real(8), intent (in) :: b1_m
    real(8), intent (in) :: b2_m
    code = b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / (b1_m * b2_m)) * a2_m))))
end function
a1\_m = Math.abs(a1);
a1\_s = Math.copySign(1.0, a1);
a2\_m = Math.abs(a2);
a2\_s = Math.copySign(1.0, a2);
b1\_m = Math.abs(b1);
b1\_s = Math.copySign(1.0, b1);
b2\_m = Math.abs(b2);
b2\_s = Math.copySign(1.0, b2);
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
assert a1_m < a2_m && a2_m < b1_m && b1_m < b2_m;
public static double code(double b2_s, double b1_s, double a2_s, double a1_s, double a1_m, double a2_m, double b1_m, double b2_m) {
	return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / (b1_m * b2_m)) * a2_m))));
}
a1\_m = math.fabs(a1)
a1\_s = math.copysign(1.0, a1)
a2\_m = math.fabs(a2)
a2\_s = math.copysign(1.0, a2)
b1\_m = math.fabs(b1)
b1\_s = math.copysign(1.0, b1)
b2\_m = math.fabs(b2)
b2\_s = math.copysign(1.0, b2)
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
[a1_m, a2_m, b1_m, b2_m] = sort([a1_m, a2_m, b1_m, b2_m])
def code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m):
	return b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / (b1_m * b2_m)) * a2_m))))
a1\_m = abs(a1)
a1\_s = copysign(1.0, a1)
a2\_m = abs(a2)
a2\_s = copysign(1.0, a2)
b1\_m = abs(b1)
b1\_s = copysign(1.0, b1)
b2\_m = abs(b2)
b2\_s = copysign(1.0, b2)
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
a1_m, a2_m, b1_m, b2_m = sort([a1_m, a2_m, b1_m, b2_m])
function code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	return Float64(b2_s * Float64(b1_s * Float64(a2_s * Float64(a1_s * Float64(Float64(a1_m / Float64(b1_m * b2_m)) * a2_m)))))
end
a1\_m = abs(a1);
a1\_s = sign(a1) * abs(1.0);
a2\_m = abs(a2);
a2\_s = sign(a2) * abs(1.0);
b1\_m = abs(b1);
b1\_s = sign(b1) * abs(1.0);
b2\_m = abs(b2);
b2\_s = sign(b2) * abs(1.0);
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
a1_m, a2_m, b1_m, b2_m = num2cell(sort([a1_m, a2_m, b1_m, b2_m])){:}
function tmp = code(b2_s, b1_s, a2_s, a1_s, a1_m, a2_m, b1_m, b2_m)
	tmp = b2_s * (b1_s * (a2_s * (a1_s * ((a1_m / (b1_m * b2_m)) * a2_m))));
end
a1\_m = N[Abs[a1], $MachinePrecision]
a1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
a2\_m = N[Abs[a2], $MachinePrecision]
a2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b1\_m = N[Abs[b1], $MachinePrecision]
b1\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
b2\_m = N[Abs[b2], $MachinePrecision]
b2\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
NOTE: a1_m, a2_m, b1_m, and b2_m should be sorted in increasing order before calling this function.
code[b2$95$s_, b1$95$s_, a2$95$s_, a1$95$s_, a1$95$m_, a2$95$m_, b1$95$m_, b2$95$m_] := N[(b2$95$s * N[(b1$95$s * N[(a2$95$s * N[(a1$95$s * N[(N[(a1$95$m / N[(b1$95$m * b2$95$m), $MachinePrecision]), $MachinePrecision] * a2$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1\_m = \left|a1\right|
\\
a1\_s = \mathsf{copysign}\left(1, a1\right)
\\
a2\_m = \left|a2\right|
\\
a2\_s = \mathsf{copysign}\left(1, a2\right)
\\
b1\_m = \left|b1\right|
\\
b1\_s = \mathsf{copysign}\left(1, b1\right)
\\
b2\_m = \left|b2\right|
\\
b2\_s = \mathsf{copysign}\left(1, b2\right)
\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\\\
[a1_m, a2_m, b1_m, b2_m] = \mathsf{sort}([a1_m, a2_m, b1_m, b2_m])\\
\\
b2\_s \cdot \left(b1\_s \cdot \left(a2\_s \cdot \left(a1\_s \cdot \left(\frac{a1\_m}{b1\_m \cdot b2\_m} \cdot a2\_m\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 83.9%

    \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \frac{\color{blue}{a1 \cdot a2}}{b1 \cdot b2} \]
    2. lift-*.f64N/A

      \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b1 \cdot b2}} \]
    3. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}} \]
    4. associate-*l/N/A

      \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]
    5. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]
    6. *-commutativeN/A

      \[\leadsto \frac{a1}{\color{blue}{b2 \cdot b1}} \cdot a2 \]
    7. associate-/r*N/A

      \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{b1}} \cdot a2 \]
    8. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{b1}} \cdot a2 \]
    9. lower-/.f6483.1

      \[\leadsto \frac{\color{blue}{\frac{a1}{b2}}}{b1} \cdot a2 \]
  4. Applied rewrites83.1%

    \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{b1} \cdot a2} \]
  5. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \frac{\color{blue}{\frac{a1}{b2}}}{b1} \cdot a2 \]
    2. lift-/.f64N/A

      \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{b1}} \cdot a2 \]
    3. associate-/l/N/A

      \[\leadsto \color{blue}{\frac{a1}{b2 \cdot b1}} \cdot a2 \]
    4. *-commutativeN/A

      \[\leadsto \frac{a1}{\color{blue}{b1 \cdot b2}} \cdot a2 \]
    5. frac-2negN/A

      \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(a1\right)}{\mathsf{neg}\left(b1 \cdot b2\right)}} \cdot a2 \]
    6. distribute-frac-negN/A

      \[\leadsto \color{blue}{\left(\mathsf{neg}\left(\frac{a1}{\mathsf{neg}\left(b1 \cdot b2\right)}\right)\right)} \cdot a2 \]
    7. distribute-neg-frac2N/A

      \[\leadsto \color{blue}{\frac{a1}{\mathsf{neg}\left(\left(\mathsf{neg}\left(b1 \cdot b2\right)\right)\right)}} \cdot a2 \]
    8. lower-/.f64N/A

      \[\leadsto \color{blue}{\frac{a1}{\mathsf{neg}\left(\left(\mathsf{neg}\left(b1 \cdot b2\right)\right)\right)}} \cdot a2 \]
    9. remove-double-negN/A

      \[\leadsto \frac{a1}{\color{blue}{b1 \cdot b2}} \cdot a2 \]
    10. lower-*.f6481.1

      \[\leadsto \frac{a1}{\color{blue}{b1 \cdot b2}} \cdot a2 \]
  6. Applied rewrites81.1%

    \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2}} \cdot a2 \]
  7. Add Preprocessing

Developer Target 1: 97.7% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \frac{a1}{b1} \cdot \frac{a2}{b2} \end{array} \]
(FPCore (a1 a2 b1 b2) :precision binary64 (* (/ a1 b1) (/ a2 b2)))
double code(double a1, double a2, double b1, double b2) {
	return (a1 / b1) * (a2 / b2);
}
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(a1, a2, b1, b2)
use fmin_fmax_functions
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: b1
    real(8), intent (in) :: b2
    code = (a1 / b1) * (a2 / b2)
end function
public static double code(double a1, double a2, double b1, double b2) {
	return (a1 / b1) * (a2 / b2);
}
def code(a1, a2, b1, b2):
	return (a1 / b1) * (a2 / b2)
function code(a1, a2, b1, b2)
	return Float64(Float64(a1 / b1) * Float64(a2 / b2))
end
function tmp = code(a1, a2, b1, b2)
	tmp = (a1 / b1) * (a2 / b2);
end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{a1}{b1} \cdot \frac{a2}{b2}
\end{array}

Reproduce

?
herbie shell --seed 2025051 
(FPCore (a1 a2 b1 b2)
  :name "Quotient of products"
  :precision binary64

  :alt
  (! :herbie-platform default (* (/ a1 b1) (/ a2 b2)))

  (/ (* a1 a2) (* b1 b2)))