Quotient of products

Percentage Accurate: 86.4% → 93.5%
Time: 1.6s
Alternatives: 8
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}

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 8 alternatives:

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

Initial Program: 86.4% 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: 93.5% accurate, 0.3× speedup?

\[\begin{array}{l} [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\ [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\ \\ \begin{array}{l} t_0 := \frac{\frac{a2}{b2} \cdot a1}{b1}\\ \mathbf{if}\;b1 \cdot b2 \leq -4 \cdot 10^{+105}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-260}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-294}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;b1 \cdot b2 \leq 10^{+172}:\\ \;\;\;\;\frac{a2}{b1 \cdot b2} \cdot a1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (/ (* (/ a2 b2) a1) b1)))
   (if (<= (* b1 b2) -4e+105)
     t_0
     (if (<= (* b1 b2) -2e-260)
       (/ (* a1 a2) (* b1 b2))
       (if (<= (* b1 b2) 5e-294)
         t_0
         (if (<= (* b1 b2) 1e+172) (* (/ a2 (* b1 b2)) a1) t_0))))))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
	double t_0 = ((a2 / b2) * a1) / b1;
	double tmp;
	if ((b1 * b2) <= -4e+105) {
		tmp = t_0;
	} else if ((b1 * b2) <= -2e-260) {
		tmp = (a1 * a2) / (b1 * b2);
	} else if ((b1 * b2) <= 5e-294) {
		tmp = t_0;
	} else if ((b1 * b2) <= 1e+172) {
		tmp = (a2 / (b1 * b2)) * a1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = ((a2 / b2) * a1) / b1
    if ((b1 * b2) <= (-4d+105)) then
        tmp = t_0
    else if ((b1 * b2) <= (-2d-260)) then
        tmp = (a1 * a2) / (b1 * b2)
    else if ((b1 * b2) <= 5d-294) then
        tmp = t_0
    else if ((b1 * b2) <= 1d+172) then
        tmp = (a2 / (b1 * b2)) * a1
    else
        tmp = t_0
    end if
    code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = ((a2 / b2) * a1) / b1;
	double tmp;
	if ((b1 * b2) <= -4e+105) {
		tmp = t_0;
	} else if ((b1 * b2) <= -2e-260) {
		tmp = (a1 * a2) / (b1 * b2);
	} else if ((b1 * b2) <= 5e-294) {
		tmp = t_0;
	} else if ((b1 * b2) <= 1e+172) {
		tmp = (a2 / (b1 * b2)) * a1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
def code(a1, a2, b1, b2):
	t_0 = ((a2 / b2) * a1) / b1
	tmp = 0
	if (b1 * b2) <= -4e+105:
		tmp = t_0
	elif (b1 * b2) <= -2e-260:
		tmp = (a1 * a2) / (b1 * b2)
	elif (b1 * b2) <= 5e-294:
		tmp = t_0
	elif (b1 * b2) <= 1e+172:
		tmp = (a2 / (b1 * b2)) * a1
	else:
		tmp = t_0
	return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
function code(a1, a2, b1, b2)
	t_0 = Float64(Float64(Float64(a2 / b2) * a1) / b1)
	tmp = 0.0
	if (Float64(b1 * b2) <= -4e+105)
		tmp = t_0;
	elseif (Float64(b1 * b2) <= -2e-260)
		tmp = Float64(Float64(a1 * a2) / Float64(b1 * b2));
	elseif (Float64(b1 * b2) <= 5e-294)
		tmp = t_0;
	elseif (Float64(b1 * b2) <= 1e+172)
		tmp = Float64(Float64(a2 / Float64(b1 * b2)) * a1);
	else
		tmp = t_0;
	end
	return tmp
end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = ((a2 / b2) * a1) / b1;
	tmp = 0.0;
	if ((b1 * b2) <= -4e+105)
		tmp = t_0;
	elseif ((b1 * b2) <= -2e-260)
		tmp = (a1 * a2) / (b1 * b2);
	elseif ((b1 * b2) <= 5e-294)
		tmp = t_0;
	elseif ((b1 * b2) <= 1e+172)
		tmp = (a2 / (b1 * b2)) * a1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(N[(a2 / b2), $MachinePrecision] * a1), $MachinePrecision] / b1), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -4e+105], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-260], N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-294], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 1e+172], N[(N[(a2 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision] * a1), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{\frac{a2}{b2} \cdot a1}{b1}\\
\mathbf{if}\;b1 \cdot b2 \leq -4 \cdot 10^{+105}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-260}:\\
\;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\

\mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-294}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;b1 \cdot b2 \leq 10^{+172}:\\
\;\;\;\;\frac{a2}{b1 \cdot b2} \cdot a1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 b1 b2) < -3.9999999999999998e105 or -1.99999999999999992e-260 < (*.f64 b1 b2) < 5.0000000000000003e-294 or 1.0000000000000001e172 < (*.f64 b1 b2)

    1. Initial program 77.4%

      \[\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. associate-*l/N/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{a2}{b2} \cdot a1}}{b1} \]
      7. lift-/.f6492.5

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

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

    if -3.9999999999999998e105 < (*.f64 b1 b2) < -1.99999999999999992e-260

    1. Initial program 94.7%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing

    if 5.0000000000000003e-294 < (*.f64 b1 b2) < 1.0000000000000001e172

    1. Initial program 93.1%

      \[\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-/.f6485.0

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

      \[\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-*.f6493.8

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

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

Alternative 2: 94.9% accurate, 0.2× speedup?

\[\begin{array}{l} [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\ [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\ \\ \begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+296}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{b1} \cdot a2\\ \mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-222}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_0 \leq 10^{-259}:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+233}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a2}{b2}}{b1} \cdot a1\\ \end{array} \end{array} \]
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (/ (* a1 a2) (* b1 b2))))
   (if (<= t_0 -2e+296)
     (* (/ (/ a1 b2) b1) a2)
     (if (<= t_0 -2e-222)
       t_0
       (if (<= t_0 1e-259)
         (* (/ a2 b1) (/ a1 b2))
         (if (<= t_0 2e+233) t_0 (* (/ (/ a2 b2) b1) a1)))))))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_0 <= -2e+296) {
		tmp = ((a1 / b2) / b1) * a2;
	} else if (t_0 <= -2e-222) {
		tmp = t_0;
	} else if (t_0 <= 1e-259) {
		tmp = (a2 / b1) * (a1 / b2);
	} else if (t_0 <= 2e+233) {
		tmp = t_0;
	} else {
		tmp = ((a2 / b2) / b1) * a1;
	}
	return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (a1 * a2) / (b1 * b2)
    if (t_0 <= (-2d+296)) then
        tmp = ((a1 / b2) / b1) * a2
    else if (t_0 <= (-2d-222)) then
        tmp = t_0
    else if (t_0 <= 1d-259) then
        tmp = (a2 / b1) * (a1 / b2)
    else if (t_0 <= 2d+233) then
        tmp = t_0
    else
        tmp = ((a2 / b2) / b1) * a1
    end if
    code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_0 <= -2e+296) {
		tmp = ((a1 / b2) / b1) * a2;
	} else if (t_0 <= -2e-222) {
		tmp = t_0;
	} else if (t_0 <= 1e-259) {
		tmp = (a2 / b1) * (a1 / b2);
	} else if (t_0 <= 2e+233) {
		tmp = t_0;
	} else {
		tmp = ((a2 / b2) / b1) * a1;
	}
	return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
def code(a1, a2, b1, b2):
	t_0 = (a1 * a2) / (b1 * b2)
	tmp = 0
	if t_0 <= -2e+296:
		tmp = ((a1 / b2) / b1) * a2
	elif t_0 <= -2e-222:
		tmp = t_0
	elif t_0 <= 1e-259:
		tmp = (a2 / b1) * (a1 / b2)
	elif t_0 <= 2e+233:
		tmp = t_0
	else:
		tmp = ((a2 / b2) / b1) * a1
	return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
function code(a1, a2, b1, b2)
	t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2))
	tmp = 0.0
	if (t_0 <= -2e+296)
		tmp = Float64(Float64(Float64(a1 / b2) / b1) * a2);
	elseif (t_0 <= -2e-222)
		tmp = t_0;
	elseif (t_0 <= 1e-259)
		tmp = Float64(Float64(a2 / b1) * Float64(a1 / b2));
	elseif (t_0 <= 2e+233)
		tmp = t_0;
	else
		tmp = Float64(Float64(Float64(a2 / b2) / b1) * a1);
	end
	return tmp
end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = (a1 * a2) / (b1 * b2);
	tmp = 0.0;
	if (t_0 <= -2e+296)
		tmp = ((a1 / b2) / b1) * a2;
	elseif (t_0 <= -2e-222)
		tmp = t_0;
	elseif (t_0 <= 1e-259)
		tmp = (a2 / b1) * (a1 / b2);
	elseif (t_0 <= 2e+233)
		tmp = t_0;
	else
		tmp = ((a2 / b2) / b1) * a1;
	end
	tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+296], N[(N[(N[(a1 / b2), $MachinePrecision] / b1), $MachinePrecision] * a2), $MachinePrecision], If[LessEqual[t$95$0, -2e-222], t$95$0, If[LessEqual[t$95$0, 1e-259], N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 2e+233], t$95$0, N[(N[(N[(a2 / b2), $MachinePrecision] / b1), $MachinePrecision] * a1), $MachinePrecision]]]]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+296}:\\
\;\;\;\;\frac{\frac{a1}{b2}}{b1} \cdot a2\\

\mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-222}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_0 \leq 10^{-259}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\

\mathbf{elif}\;t\_0 \leq 2 \cdot 10^{+233}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.99999999999999996e296

    1. Initial program 82.4%

      \[\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-/.f6495.3

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

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

    if -1.99999999999999996e296 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.0000000000000001e-222 or 1.0000000000000001e-259 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99999999999999995e233

    1. Initial program 98.9%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing

    if -2.0000000000000001e-222 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e-259

    1. Initial program 80.8%

      \[\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-/.f6491.5

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

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

    if 1.99999999999999995e233 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 70.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-/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-/.f6491.1

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

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

Alternative 3: 95.4% accurate, 0.2× speedup?

\[\begin{array}{l} [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\ [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\ \\ \begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{if}\;t\_0 \leq -2 \cdot 10^{+296}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{b1} \cdot a2\\ \mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-222}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_0 \leq 10^{-259}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 10^{+253}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (/ (* a1 a2) (* b1 b2))) (t_1 (* (/ a2 b1) (/ a1 b2))))
   (if (<= t_0 -2e+296)
     (* (/ (/ a1 b2) b1) a2)
     (if (<= t_0 -2e-222)
       t_0
       (if (<= t_0 1e-259) t_1 (if (<= t_0 1e+253) t_0 t_1))))))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a1 * a2) / (b1 * b2);
	double t_1 = (a2 / b1) * (a1 / b2);
	double tmp;
	if (t_0 <= -2e+296) {
		tmp = ((a1 / b2) / b1) * a2;
	} else if (t_0 <= -2e-222) {
		tmp = t_0;
	} else if (t_0 <= 1e-259) {
		tmp = t_1;
	} else if (t_0 <= 1e+253) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (a1 * a2) / (b1 * b2)
    t_1 = (a2 / b1) * (a1 / b2)
    if (t_0 <= (-2d+296)) then
        tmp = ((a1 / b2) / b1) * a2
    else if (t_0 <= (-2d-222)) then
        tmp = t_0
    else if (t_0 <= 1d-259) then
        tmp = t_1
    else if (t_0 <= 1d+253) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a1 * a2) / (b1 * b2);
	double t_1 = (a2 / b1) * (a1 / b2);
	double tmp;
	if (t_0 <= -2e+296) {
		tmp = ((a1 / b2) / b1) * a2;
	} else if (t_0 <= -2e-222) {
		tmp = t_0;
	} else if (t_0 <= 1e-259) {
		tmp = t_1;
	} else if (t_0 <= 1e+253) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
def code(a1, a2, b1, b2):
	t_0 = (a1 * a2) / (b1 * b2)
	t_1 = (a2 / b1) * (a1 / b2)
	tmp = 0
	if t_0 <= -2e+296:
		tmp = ((a1 / b2) / b1) * a2
	elif t_0 <= -2e-222:
		tmp = t_0
	elif t_0 <= 1e-259:
		tmp = t_1
	elif t_0 <= 1e+253:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
function code(a1, a2, b1, b2)
	t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2))
	t_1 = Float64(Float64(a2 / b1) * Float64(a1 / b2))
	tmp = 0.0
	if (t_0 <= -2e+296)
		tmp = Float64(Float64(Float64(a1 / b2) / b1) * a2);
	elseif (t_0 <= -2e-222)
		tmp = t_0;
	elseif (t_0 <= 1e-259)
		tmp = t_1;
	elseif (t_0 <= 1e+253)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = (a1 * a2) / (b1 * b2);
	t_1 = (a2 / b1) * (a1 / b2);
	tmp = 0.0;
	if (t_0 <= -2e+296)
		tmp = ((a1 / b2) / b1) * a2;
	elseif (t_0 <= -2e-222)
		tmp = t_0;
	elseif (t_0 <= 1e-259)
		tmp = t_1;
	elseif (t_0 <= 1e+253)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+296], N[(N[(N[(a1 / b2), $MachinePrecision] / b1), $MachinePrecision] * a2), $MachinePrecision], If[LessEqual[t$95$0, -2e-222], t$95$0, If[LessEqual[t$95$0, 1e-259], t$95$1, If[LessEqual[t$95$0, 1e+253], t$95$0, t$95$1]]]]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{if}\;t\_0 \leq -2 \cdot 10^{+296}:\\
\;\;\;\;\frac{\frac{a1}{b2}}{b1} \cdot a2\\

\mathbf{elif}\;t\_0 \leq -2 \cdot 10^{-222}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_0 \leq 10^{-259}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 10^{+253}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.99999999999999996e296

    1. Initial program 82.4%

      \[\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-/.f6495.3

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

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

    if -1.99999999999999996e296 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.0000000000000001e-222 or 1.0000000000000001e-259 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999994e252

    1. Initial program 98.9%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing

    if -2.0000000000000001e-222 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e-259 or 9.9999999999999994e252 < (/.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. *-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-/.f6492.3

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

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

Alternative 4: 93.6% accurate, 0.2× speedup?

\[\begin{array}{l} [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\ [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\ \\ \begin{array}{l} t_0 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\ t_1 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t\_1 \leq -2 \cdot 10^{-222}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_1 \leq 10^{-259}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq 10^{+253}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (* (/ a2 b1) (/ a1 b2))) (t_1 (/ (* a1 a2) (* b1 b2))))
   (if (<= t_1 -2e-222)
     t_1
     (if (<= t_1 1e-259) t_0 (if (<= t_1 1e+253) t_1 t_0)))))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a2 / b1) * (a1 / b2);
	double t_1 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_1 <= -2e-222) {
		tmp = t_1;
	} else if (t_1 <= 1e-259) {
		tmp = t_0;
	} else if (t_1 <= 1e+253) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(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
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (a2 / b1) * (a1 / b2)
    t_1 = (a1 * a2) / (b1 * b2)
    if (t_1 <= (-2d-222)) then
        tmp = t_1
    else if (t_1 <= 1d-259) then
        tmp = t_0
    else if (t_1 <= 1d+253) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a2 / b1) * (a1 / b2);
	double t_1 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_1 <= -2e-222) {
		tmp = t_1;
	} else if (t_1 <= 1e-259) {
		tmp = t_0;
	} else if (t_1 <= 1e+253) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
def code(a1, a2, b1, b2):
	t_0 = (a2 / b1) * (a1 / b2)
	t_1 = (a1 * a2) / (b1 * b2)
	tmp = 0
	if t_1 <= -2e-222:
		tmp = t_1
	elif t_1 <= 1e-259:
		tmp = t_0
	elif t_1 <= 1e+253:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
function code(a1, a2, b1, b2)
	t_0 = Float64(Float64(a2 / b1) * Float64(a1 / b2))
	t_1 = Float64(Float64(a1 * a2) / Float64(b1 * b2))
	tmp = 0.0
	if (t_1 <= -2e-222)
		tmp = t_1;
	elseif (t_1 <= 1e-259)
		tmp = t_0;
	elseif (t_1 <= 1e+253)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = (a2 / b1) * (a1 / b2);
	t_1 = (a1 * a2) / (b1 * b2);
	tmp = 0.0;
	if (t_1 <= -2e-222)
		tmp = t_1;
	elseif (t_1 <= 1e-259)
		tmp = t_0;
	elseif (t_1 <= 1e+253)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e-222], t$95$1, If[LessEqual[t$95$1, 1e-259], t$95$0, If[LessEqual[t$95$1, 1e+253], t$95$1, t$95$0]]]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
t_1 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t\_1 \leq -2 \cdot 10^{-222}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_1 \leq 10^{-259}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_1 \leq 10^{+253}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.0000000000000001e-222 or 1.0000000000000001e-259 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 9.9999999999999994e252

    1. Initial program 94.7%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing

    if -2.0000000000000001e-222 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.0000000000000001e-259 or 9.9999999999999994e252 < (/.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. *-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-/.f6492.3

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

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

Alternative 5: 89.4% accurate, 0.4× speedup?

\[\begin{array}{l} [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\ [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\ \\ \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 2 \cdot 10^{+233}:\\ \;\;\;\;\frac{\frac{a2 \cdot a1}{b1}}{b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a2}{b2} \cdot a1}{b1}\\ \end{array} \end{array} \]
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (if (<= (/ (* a1 a2) (* b1 b2)) 2e+233)
   (/ (/ (* a2 a1) b1) b2)
   (/ (* (/ a2 b2) a1) b1)))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
	double tmp;
	if (((a1 * a2) / (b1 * b2)) <= 2e+233) {
		tmp = ((a2 * a1) / b1) / b2;
	} else {
		tmp = ((a2 / b2) * a1) / b1;
	}
	return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(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
    real(8) :: tmp
    if (((a1 * a2) / (b1 * b2)) <= 2d+233) then
        tmp = ((a2 * a1) / b1) / b2
    else
        tmp = ((a2 / b2) * a1) / b1
    end if
    code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
	double tmp;
	if (((a1 * a2) / (b1 * b2)) <= 2e+233) {
		tmp = ((a2 * a1) / b1) / b2;
	} else {
		tmp = ((a2 / b2) * a1) / b1;
	}
	return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
def code(a1, a2, b1, b2):
	tmp = 0
	if ((a1 * a2) / (b1 * b2)) <= 2e+233:
		tmp = ((a2 * a1) / b1) / b2
	else:
		tmp = ((a2 / b2) * a1) / b1
	return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
function code(a1, a2, b1, b2)
	tmp = 0.0
	if (Float64(Float64(a1 * a2) / Float64(b1 * b2)) <= 2e+233)
		tmp = Float64(Float64(Float64(a2 * a1) / b1) / b2);
	else
		tmp = Float64(Float64(Float64(a2 / b2) * a1) / b1);
	end
	return tmp
end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
	tmp = 0.0;
	if (((a1 * a2) / (b1 * b2)) <= 2e+233)
		tmp = ((a2 * a1) / b1) / b2;
	else
		tmp = ((a2 / b2) * a1) / b1;
	end
	tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := If[LessEqual[N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision], 2e+233], N[(N[(N[(a2 * a1), $MachinePrecision] / b1), $MachinePrecision] / b2), $MachinePrecision], N[(N[(N[(a2 / b2), $MachinePrecision] * a1), $MachinePrecision] / b1), $MachinePrecision]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 2 \cdot 10^{+233}:\\
\;\;\;\;\frac{\frac{a2 \cdot a1}{b1}}{b2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99999999999999995e233

    1. Initial program 89.8%

      \[\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-/.f6485.8

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999995e233 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 70.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. times-fracN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 87.2% accurate, 0.4× speedup?

\[\begin{array}{l} [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\ [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\ \\ \begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t\_0 \leq 2 \cdot 10^{+213}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b1 \cdot b2} \cdot a2\\ \end{array} \end{array} \]
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (/ (* a1 a2) (* b1 b2))))
   (if (<= t_0 2e+213) t_0 (* (/ a1 (* b1 b2)) a2))))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_0 <= 2e+213) {
		tmp = t_0;
	} else {
		tmp = (a1 / (b1 * b2)) * a2;
	}
	return tmp;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(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
    real(8) :: t_0
    real(8) :: tmp
    t_0 = (a1 * a2) / (b1 * b2)
    if (t_0 <= 2d+213) then
        tmp = t_0
    else
        tmp = (a1 / (b1 * b2)) * a2
    end if
    code = tmp
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_0 <= 2e+213) {
		tmp = t_0;
	} else {
		tmp = (a1 / (b1 * b2)) * a2;
	}
	return tmp;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
def code(a1, a2, b1, b2):
	t_0 = (a1 * a2) / (b1 * b2)
	tmp = 0
	if t_0 <= 2e+213:
		tmp = t_0
	else:
		tmp = (a1 / (b1 * b2)) * a2
	return tmp
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
function code(a1, a2, b1, b2)
	t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2))
	tmp = 0.0
	if (t_0 <= 2e+213)
		tmp = t_0;
	else
		tmp = Float64(Float64(a1 / Float64(b1 * b2)) * a2);
	end
	return tmp
end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = (a1 * a2) / (b1 * b2);
	tmp = 0.0;
	if (t_0 <= 2e+213)
		tmp = t_0;
	else
		tmp = (a1 / (b1 * b2)) * a2;
	end
	tmp_2 = tmp;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 2e+213], t$95$0, N[(N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision] * a2), $MachinePrecision]]]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t\_0 \leq 2 \cdot 10^{+213}:\\
\;\;\;\;t\_0\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99999999999999997e213

    1. Initial program 89.7%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Add Preprocessing

    if 1.99999999999999997e213 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 71.1%

      \[\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-/.f6489.5

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

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

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

        \[\leadsto \frac{\color{blue}{\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. remove-double-negN/A

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

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

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

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

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

Alternative 7: 86.4% accurate, 1.0× speedup?

\[\begin{array}{l} [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\ [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\ \\ \frac{a2}{b1 \cdot b2} \cdot a1 \end{array} \]
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2) :precision binary64 (* (/ a2 (* b1 b2)) a1))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
	return (a2 / (b1 * b2)) * a1;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(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 = (a2 / (b1 * b2)) * a1
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
	return (a2 / (b1 * b2)) * a1;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
def code(a1, a2, b1, b2):
	return (a2 / (b1 * b2)) * a1
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
function code(a1, a2, b1, b2)
	return Float64(Float64(a2 / Float64(b1 * b2)) * a1)
end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
	tmp = (a2 / (b1 * b2)) * a1;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := N[(N[(a2 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision] * a1), $MachinePrecision]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\frac{a2}{b1 \cdot b2} \cdot a1
\end{array}
Derivation
  1. Initial program 86.4%

    \[\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-/.f6486.2

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

    \[\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-*.f6486.4

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

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

Alternative 8: 86.3% accurate, 1.0× speedup?

\[\begin{array}{l} [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\ [a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\ \\ \frac{a1}{b1 \cdot b2} \cdot a2 \end{array} \]
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
(FPCore (a1 a2 b1 b2) :precision binary64 (* (/ a1 (* b1 b2)) a2))
assert(a1 < a2 && a2 < b1 && b1 < b2);
assert(a1 < a2 && a2 < b1 && b1 < b2);
double code(double a1, double a2, double b1, double b2) {
	return (a1 / (b1 * b2)) * a2;
}
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 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(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 * b2)) * a2
end function
assert a1 < a2 && a2 < b1 && b1 < b2;
assert a1 < a2 && a2 < b1 && b1 < b2;
public static double code(double a1, double a2, double b1, double b2) {
	return (a1 / (b1 * b2)) * a2;
}
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
[a1, a2, b1, b2] = sort([a1, a2, b1, b2])
def code(a1, a2, b1, b2):
	return (a1 / (b1 * b2)) * a2
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
a1, a2, b1, b2 = sort([a1, a2, b1, b2])
function code(a1, a2, b1, b2)
	return Float64(Float64(a1 / Float64(b1 * b2)) * a2)
end
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
a1, a2, b1, b2 = num2cell(sort([a1, a2, b1, b2])){:}
function tmp = code(a1, a2, b1, b2)
	tmp = (a1 / (b1 * b2)) * a2;
end
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
NOTE: a1, a2, b1, and b2 should be sorted in increasing order before calling this function.
code[a1_, a2_, b1_, b2_] := N[(N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision] * a2), $MachinePrecision]
\begin{array}{l}
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\\\
[a1, a2, b1, b2] = \mathsf{sort}([a1, a2, b1, b2])\\
\\
\frac{a1}{b1 \cdot b2} \cdot a2
\end{array}
Derivation
  1. Initial program 86.4%

    \[\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-/.f6486.6

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

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

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

      \[\leadsto \frac{\color{blue}{\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. remove-double-negN/A

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

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

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

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

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

Reproduce

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