Quotient of products

Percentage Accurate: 86.4% → 98.1%
Time: 3.0s
Alternatives: 5
Speedup: 1.0×

Specification

?
\[\frac{a1 \cdot a2}{b1 \cdot b2} \]
(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]
\frac{a1 \cdot a2}{b1 \cdot b2}

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.4% accurate, 1.0× speedup?

\[\frac{a1 \cdot a2}{b1 \cdot b2} \]
(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]
\frac{a1 \cdot a2}{b1 \cdot b2}

Alternative 1: 98.1% accurate, 0.2× speedup?

\[\begin{array}{l} t_0 := \mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)\\ t_1 := \mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)\\ t_2 := \frac{t\_1}{\mathsf{max}\left(\left|b1\right|, \left|b2\right|\right)}\\ t_3 := \mathsf{min}\left(\left|b1\right|, \left|b2\right|\right)\\ \mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \begin{array}{l} \mathbf{if}\;t\_0 \cdot t\_1 \leq 2.6 \cdot 10^{-62}:\\ \;\;\;\;t\_2 \cdot \frac{t\_0}{t\_3}\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_2 \cdot t\_0}{t\_3}\\ \end{array}\right)\right)\right) \end{array} \]
(FPCore (a1 a2 b1 b2)
  :precision binary64
  (let* ((t_0 (fmin (fabs a1) (fabs a2)))
       (t_1 (fmax (fabs a1) (fabs a2)))
       (t_2 (/ t_1 (fmax (fabs b1) (fabs b2))))
       (t_3 (fmin (fabs b1) (fabs b2))))
  (*
   (copysign 1.0 a1)
   (*
    (copysign 1.0 a2)
    (*
     (copysign 1.0 b1)
     (*
      (copysign 1.0 b2)
      (if (<= (* t_0 t_1) 2.6e-62)
        (* t_2 (/ t_0 t_3))
        (/ (* t_2 t_0) t_3))))))))
double code(double a1, double a2, double b1, double b2) {
	double t_0 = fmin(fabs(a1), fabs(a2));
	double t_1 = fmax(fabs(a1), fabs(a2));
	double t_2 = t_1 / fmax(fabs(b1), fabs(b2));
	double t_3 = fmin(fabs(b1), fabs(b2));
	double tmp;
	if ((t_0 * t_1) <= 2.6e-62) {
		tmp = t_2 * (t_0 / t_3);
	} else {
		tmp = (t_2 * t_0) / t_3;
	}
	return copysign(1.0, a1) * (copysign(1.0, a2) * (copysign(1.0, b1) * (copysign(1.0, b2) * tmp)));
}
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = fmin(Math.abs(a1), Math.abs(a2));
	double t_1 = fmax(Math.abs(a1), Math.abs(a2));
	double t_2 = t_1 / fmax(Math.abs(b1), Math.abs(b2));
	double t_3 = fmin(Math.abs(b1), Math.abs(b2));
	double tmp;
	if ((t_0 * t_1) <= 2.6e-62) {
		tmp = t_2 * (t_0 / t_3);
	} else {
		tmp = (t_2 * t_0) / t_3;
	}
	return Math.copySign(1.0, a1) * (Math.copySign(1.0, a2) * (Math.copySign(1.0, b1) * (Math.copySign(1.0, b2) * tmp)));
}
def code(a1, a2, b1, b2):
	t_0 = fmin(math.fabs(a1), math.fabs(a2))
	t_1 = fmax(math.fabs(a1), math.fabs(a2))
	t_2 = t_1 / fmax(math.fabs(b1), math.fabs(b2))
	t_3 = fmin(math.fabs(b1), math.fabs(b2))
	tmp = 0
	if (t_0 * t_1) <= 2.6e-62:
		tmp = t_2 * (t_0 / t_3)
	else:
		tmp = (t_2 * t_0) / t_3
	return math.copysign(1.0, a1) * (math.copysign(1.0, a2) * (math.copysign(1.0, b1) * (math.copysign(1.0, b2) * tmp)))
function code(a1, a2, b1, b2)
	t_0 = fmin(abs(a1), abs(a2))
	t_1 = fmax(abs(a1), abs(a2))
	t_2 = Float64(t_1 / fmax(abs(b1), abs(b2)))
	t_3 = fmin(abs(b1), abs(b2))
	tmp = 0.0
	if (Float64(t_0 * t_1) <= 2.6e-62)
		tmp = Float64(t_2 * Float64(t_0 / t_3));
	else
		tmp = Float64(Float64(t_2 * t_0) / t_3);
	end
	return Float64(copysign(1.0, a1) * Float64(copysign(1.0, a2) * Float64(copysign(1.0, b1) * Float64(copysign(1.0, b2) * tmp))))
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = min(abs(a1), abs(a2));
	t_1 = max(abs(a1), abs(a2));
	t_2 = t_1 / max(abs(b1), abs(b2));
	t_3 = min(abs(b1), abs(b2));
	tmp = 0.0;
	if ((t_0 * t_1) <= 2.6e-62)
		tmp = t_2 * (t_0 / t_3);
	else
		tmp = (t_2 * t_0) / t_3;
	end
	tmp_2 = (sign(a1) * abs(1.0)) * ((sign(a2) * abs(1.0)) * ((sign(b1) * abs(1.0)) * ((sign(b2) * abs(1.0)) * tmp)));
end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[Min[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[Max[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 / N[Max[N[Abs[b1], $MachinePrecision], N[Abs[b2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Min[N[Abs[b1], $MachinePrecision], N[Abs[b2], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$0 * t$95$1), $MachinePrecision], 2.6e-62], N[(t$95$2 * N[(t$95$0 / t$95$3), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$2 * t$95$0), $MachinePrecision] / t$95$3), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)\\
t_1 := \mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)\\
t_2 := \frac{t\_1}{\mathsf{max}\left(\left|b1\right|, \left|b2\right|\right)}\\
t_3 := \mathsf{min}\left(\left|b1\right|, \left|b2\right|\right)\\
\mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \cdot t\_1 \leq 2.6 \cdot 10^{-62}:\\
\;\;\;\;t\_2 \cdot \frac{t\_0}{t\_3}\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_2 \cdot t\_0}{t\_3}\\


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

    1. Initial program 86.4%

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

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

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

        \[\leadsto \frac{a1 \cdot a2}{\color{blue}{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-/.f6485.7%

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

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

    if 2.5999999999999999e-62 < (*.f64 a1 a2)

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 98.0% accurate, 0.2× speedup?

\[\mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \left(\frac{\mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)}{\mathsf{max}\left(\left|b1\right|, \left|b2\right|\right)} \cdot \frac{\mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)}{\mathsf{min}\left(\left|b1\right|, \left|b2\right|\right)}\right)\right)\right)\right) \]
(FPCore (a1 a2 b1 b2)
  :precision binary64
  (*
 (copysign 1.0 a1)
 (*
  (copysign 1.0 a2)
  (*
   (copysign 1.0 b1)
   (*
    (copysign 1.0 b2)
    (*
     (/ (fmax (fabs a1) (fabs a2)) (fmax (fabs b1) (fabs b2)))
     (/ (fmin (fabs a1) (fabs a2)) (fmin (fabs b1) (fabs b2)))))))))
double code(double a1, double a2, double b1, double b2) {
	return copysign(1.0, a1) * (copysign(1.0, a2) * (copysign(1.0, b1) * (copysign(1.0, b2) * ((fmax(fabs(a1), fabs(a2)) / fmax(fabs(b1), fabs(b2))) * (fmin(fabs(a1), fabs(a2)) / fmin(fabs(b1), fabs(b2)))))));
}
public static double code(double a1, double a2, double b1, double b2) {
	return Math.copySign(1.0, a1) * (Math.copySign(1.0, a2) * (Math.copySign(1.0, b1) * (Math.copySign(1.0, b2) * ((fmax(Math.abs(a1), Math.abs(a2)) / fmax(Math.abs(b1), Math.abs(b2))) * (fmin(Math.abs(a1), Math.abs(a2)) / fmin(Math.abs(b1), Math.abs(b2)))))));
}
def code(a1, a2, b1, b2):
	return math.copysign(1.0, a1) * (math.copysign(1.0, a2) * (math.copysign(1.0, b1) * (math.copysign(1.0, b2) * ((fmax(math.fabs(a1), math.fabs(a2)) / fmax(math.fabs(b1), math.fabs(b2))) * (fmin(math.fabs(a1), math.fabs(a2)) / fmin(math.fabs(b1), math.fabs(b2)))))))
function code(a1, a2, b1, b2)
	return Float64(copysign(1.0, a1) * Float64(copysign(1.0, a2) * Float64(copysign(1.0, b1) * Float64(copysign(1.0, b2) * Float64(Float64(fmax(abs(a1), abs(a2)) / fmax(abs(b1), abs(b2))) * Float64(fmin(abs(a1), abs(a2)) / fmin(abs(b1), abs(b2))))))))
end
function tmp = code(a1, a2, b1, b2)
	tmp = (sign(a1) * abs(1.0)) * ((sign(a2) * abs(1.0)) * ((sign(b1) * abs(1.0)) * ((sign(b2) * abs(1.0)) * ((max(abs(a1), abs(a2)) / max(abs(b1), abs(b2))) * (min(abs(a1), abs(a2)) / min(abs(b1), abs(b2)))))));
end
code[a1_, a2_, b1_, b2_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[(N[Max[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision] / N[Max[N[Abs[b1], $MachinePrecision], N[Abs[b2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[Min[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision] / N[Min[N[Abs[b1], $MachinePrecision], N[Abs[b2], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \left(\frac{\mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)}{\mathsf{max}\left(\left|b1\right|, \left|b2\right|\right)} \cdot \frac{\mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)}{\mathsf{min}\left(\left|b1\right|, \left|b2\right|\right)}\right)\right)\right)\right)
Derivation
  1. Initial program 86.4%

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

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

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

      \[\leadsto \frac{a1 \cdot a2}{\color{blue}{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-/.f6485.7%

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

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

Alternative 3: 97.6% accurate, 0.1× speedup?

\[\begin{array}{l} t_0 := \frac{\left|a1\right| \cdot \left|a2\right|}{\left|b1\right| \cdot \left|b2\right|}\\ t_1 := \frac{\left|a2\right|}{\left|b1\right|} \cdot \frac{\left|a1\right|}{\left|b2\right|}\\ \mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \begin{array}{l} \mathbf{if}\;t\_0 \leq 0:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+307}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array}\right)\right)\right) \end{array} \]
(FPCore (a1 a2 b1 b2)
  :precision binary64
  (let* ((t_0 (/ (* (fabs a1) (fabs a2)) (* (fabs b1) (fabs b2))))
       (t_1 (* (/ (fabs a2) (fabs b1)) (/ (fabs a1) (fabs b2)))))
  (*
   (copysign 1.0 a1)
   (*
    (copysign 1.0 a2)
    (*
     (copysign 1.0 b1)
     (*
      (copysign 1.0 b2)
      (if (<= t_0 0.0) t_1 (if (<= t_0 5e+307) t_0 t_1))))))))
double code(double a1, double a2, double b1, double b2) {
	double t_0 = (fabs(a1) * fabs(a2)) / (fabs(b1) * fabs(b2));
	double t_1 = (fabs(a2) / fabs(b1)) * (fabs(a1) / fabs(b2));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = t_1;
	} else if (t_0 <= 5e+307) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return copysign(1.0, a1) * (copysign(1.0, a2) * (copysign(1.0, b1) * (copysign(1.0, b2) * tmp)));
}
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = (Math.abs(a1) * Math.abs(a2)) / (Math.abs(b1) * Math.abs(b2));
	double t_1 = (Math.abs(a2) / Math.abs(b1)) * (Math.abs(a1) / Math.abs(b2));
	double tmp;
	if (t_0 <= 0.0) {
		tmp = t_1;
	} else if (t_0 <= 5e+307) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return Math.copySign(1.0, a1) * (Math.copySign(1.0, a2) * (Math.copySign(1.0, b1) * (Math.copySign(1.0, b2) * tmp)));
}
def code(a1, a2, b1, b2):
	t_0 = (math.fabs(a1) * math.fabs(a2)) / (math.fabs(b1) * math.fabs(b2))
	t_1 = (math.fabs(a2) / math.fabs(b1)) * (math.fabs(a1) / math.fabs(b2))
	tmp = 0
	if t_0 <= 0.0:
		tmp = t_1
	elif t_0 <= 5e+307:
		tmp = t_0
	else:
		tmp = t_1
	return math.copysign(1.0, a1) * (math.copysign(1.0, a2) * (math.copysign(1.0, b1) * (math.copysign(1.0, b2) * tmp)))
function code(a1, a2, b1, b2)
	t_0 = Float64(Float64(abs(a1) * abs(a2)) / Float64(abs(b1) * abs(b2)))
	t_1 = Float64(Float64(abs(a2) / abs(b1)) * Float64(abs(a1) / abs(b2)))
	tmp = 0.0
	if (t_0 <= 0.0)
		tmp = t_1;
	elseif (t_0 <= 5e+307)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return Float64(copysign(1.0, a1) * Float64(copysign(1.0, a2) * Float64(copysign(1.0, b1) * Float64(copysign(1.0, b2) * tmp))))
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = (abs(a1) * abs(a2)) / (abs(b1) * abs(b2));
	t_1 = (abs(a2) / abs(b1)) * (abs(a1) / abs(b2));
	tmp = 0.0;
	if (t_0 <= 0.0)
		tmp = t_1;
	elseif (t_0 <= 5e+307)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = (sign(a1) * abs(1.0)) * ((sign(a2) * abs(1.0)) * ((sign(b1) * abs(1.0)) * ((sign(b2) * abs(1.0)) * tmp)));
end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(N[Abs[a1], $MachinePrecision] * N[Abs[a2], $MachinePrecision]), $MachinePrecision] / N[(N[Abs[b1], $MachinePrecision] * N[Abs[b2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Abs[a2], $MachinePrecision] / N[Abs[b1], $MachinePrecision]), $MachinePrecision] * N[(N[Abs[a1], $MachinePrecision] / N[Abs[b2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 5e+307], t$95$0, t$95$1]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
t_0 := \frac{\left|a1\right| \cdot \left|a2\right|}{\left|b1\right| \cdot \left|b2\right|}\\
t_1 := \frac{\left|a2\right|}{\left|b1\right|} \cdot \frac{\left|a1\right|}{\left|b2\right|}\\
\mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_0 \leq 5 \cdot 10^{+307}:\\
\;\;\;\;t\_0\\

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


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

    1. Initial program 86.4%

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

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

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

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

        \[\leadsto \frac{a2 \cdot a1}{\color{blue}{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-/.f6486.8%

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

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

    if 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 5.0000000000000001e307

    1. Initial program 86.4%

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

Alternative 4: 91.6% accurate, 0.2× speedup?

\[\begin{array}{l} t_0 := \mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)\\ t_1 := \left|b2\right| \cdot \left|b1\right|\\ t_2 := \mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)\\ \mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \begin{array}{l} \mathbf{if}\;\left|b1\right| \cdot \left|b2\right| \leq 5 \cdot 10^{-30}:\\ \;\;\;\;\frac{t\_0}{t\_1} \cdot t\_2\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_2}{t\_1} \cdot t\_0\\ \end{array}\right)\right)\right) \end{array} \]
(FPCore (a1 a2 b1 b2)
  :precision binary64
  (let* ((t_0 (fmin (fabs a1) (fabs a2)))
       (t_1 (* (fabs b2) (fabs b1)))
       (t_2 (fmax (fabs a1) (fabs a2))))
  (*
   (copysign 1.0 a1)
   (*
    (copysign 1.0 a2)
    (*
     (copysign 1.0 b1)
     (*
      (copysign 1.0 b2)
      (if (<= (* (fabs b1) (fabs b2)) 5e-30)
        (* (/ t_0 t_1) t_2)
        (* (/ t_2 t_1) t_0))))))))
double code(double a1, double a2, double b1, double b2) {
	double t_0 = fmin(fabs(a1), fabs(a2));
	double t_1 = fabs(b2) * fabs(b1);
	double t_2 = fmax(fabs(a1), fabs(a2));
	double tmp;
	if ((fabs(b1) * fabs(b2)) <= 5e-30) {
		tmp = (t_0 / t_1) * t_2;
	} else {
		tmp = (t_2 / t_1) * t_0;
	}
	return copysign(1.0, a1) * (copysign(1.0, a2) * (copysign(1.0, b1) * (copysign(1.0, b2) * tmp)));
}
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = fmin(Math.abs(a1), Math.abs(a2));
	double t_1 = Math.abs(b2) * Math.abs(b1);
	double t_2 = fmax(Math.abs(a1), Math.abs(a2));
	double tmp;
	if ((Math.abs(b1) * Math.abs(b2)) <= 5e-30) {
		tmp = (t_0 / t_1) * t_2;
	} else {
		tmp = (t_2 / t_1) * t_0;
	}
	return Math.copySign(1.0, a1) * (Math.copySign(1.0, a2) * (Math.copySign(1.0, b1) * (Math.copySign(1.0, b2) * tmp)));
}
def code(a1, a2, b1, b2):
	t_0 = fmin(math.fabs(a1), math.fabs(a2))
	t_1 = math.fabs(b2) * math.fabs(b1)
	t_2 = fmax(math.fabs(a1), math.fabs(a2))
	tmp = 0
	if (math.fabs(b1) * math.fabs(b2)) <= 5e-30:
		tmp = (t_0 / t_1) * t_2
	else:
		tmp = (t_2 / t_1) * t_0
	return math.copysign(1.0, a1) * (math.copysign(1.0, a2) * (math.copysign(1.0, b1) * (math.copysign(1.0, b2) * tmp)))
function code(a1, a2, b1, b2)
	t_0 = fmin(abs(a1), abs(a2))
	t_1 = Float64(abs(b2) * abs(b1))
	t_2 = fmax(abs(a1), abs(a2))
	tmp = 0.0
	if (Float64(abs(b1) * abs(b2)) <= 5e-30)
		tmp = Float64(Float64(t_0 / t_1) * t_2);
	else
		tmp = Float64(Float64(t_2 / t_1) * t_0);
	end
	return Float64(copysign(1.0, a1) * Float64(copysign(1.0, a2) * Float64(copysign(1.0, b1) * Float64(copysign(1.0, b2) * tmp))))
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = min(abs(a1), abs(a2));
	t_1 = abs(b2) * abs(b1);
	t_2 = max(abs(a1), abs(a2));
	tmp = 0.0;
	if ((abs(b1) * abs(b2)) <= 5e-30)
		tmp = (t_0 / t_1) * t_2;
	else
		tmp = (t_2 / t_1) * t_0;
	end
	tmp_2 = (sign(a1) * abs(1.0)) * ((sign(a2) * abs(1.0)) * ((sign(b1) * abs(1.0)) * ((sign(b2) * abs(1.0)) * tmp)));
end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[Min[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[Abs[b2], $MachinePrecision] * N[Abs[b1], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Max[N[Abs[a1], $MachinePrecision], N[Abs[a2], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[a2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b1]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[b2]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(N[Abs[b1], $MachinePrecision] * N[Abs[b2], $MachinePrecision]), $MachinePrecision], 5e-30], N[(N[(t$95$0 / t$95$1), $MachinePrecision] * t$95$2), $MachinePrecision], N[(N[(t$95$2 / t$95$1), $MachinePrecision] * t$95$0), $MachinePrecision]]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
t_0 := \mathsf{min}\left(\left|a1\right|, \left|a2\right|\right)\\
t_1 := \left|b2\right| \cdot \left|b1\right|\\
t_2 := \mathsf{max}\left(\left|a1\right|, \left|a2\right|\right)\\
\mathsf{copysign}\left(1, a1\right) \cdot \left(\mathsf{copysign}\left(1, a2\right) \cdot \left(\mathsf{copysign}\left(1, b1\right) \cdot \left(\mathsf{copysign}\left(1, b2\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|b1\right| \cdot \left|b2\right| \leq 5 \cdot 10^{-30}:\\
\;\;\;\;\frac{t\_0}{t\_1} \cdot t\_2\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_2}{t\_1} \cdot t\_0\\


\end{array}\right)\right)\right)
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 b1 b2) < 4.9999999999999997e-30

    1. Initial program 86.4%

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

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

        \[\leadsto \color{blue}{\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}} \]
      3. lift-*.f64N/A

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

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

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

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

        \[\leadsto \color{blue}{\left(a1 \cdot \frac{1}{b1 \cdot b2}\right) \cdot a2} \]
      8. mult-flip-revN/A

        \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2}} \cdot a2 \]
      9. lower-/.f6486.4%

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

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

        \[\leadsto \frac{a1}{\color{blue}{b2 \cdot b1}} \cdot a2 \]
      12. lower-*.f6486.4%

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

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

    if 4.9999999999999997e-30 < (*.f64 b1 b2)

    1. Initial program 86.4%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{a2}{b1 \cdot b2} \cdot a1} \]
      6. lower-/.f6486.3%

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

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

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

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

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

Alternative 5: 86.4% accurate, 1.0× speedup?

\[\frac{a1}{b2 \cdot b1} \cdot a2 \]
(FPCore (a1 a2 b1 b2)
  :precision binary64
  (* (/ a1 (* b2 b1)) a2))
double code(double a1, double a2, double b1, double b2) {
	return (a1 / (b2 * b1)) * a2;
}
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 / (b2 * b1)) * a2
end function
public static double code(double a1, double a2, double b1, double b2) {
	return (a1 / (b2 * b1)) * a2;
}
def code(a1, a2, b1, b2):
	return (a1 / (b2 * b1)) * a2
function code(a1, a2, b1, b2)
	return Float64(Float64(a1 / Float64(b2 * b1)) * a2)
end
function tmp = code(a1, a2, b1, b2)
	tmp = (a1 / (b2 * b1)) * a2;
end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 / N[(b2 * b1), $MachinePrecision]), $MachinePrecision] * a2), $MachinePrecision]
\frac{a1}{b2 \cdot b1} \cdot a2
Derivation
  1. Initial program 86.4%

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

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

      \[\leadsto \color{blue}{\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}} \]
    3. lift-*.f64N/A

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

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

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

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

      \[\leadsto \color{blue}{\left(a1 \cdot \frac{1}{b1 \cdot b2}\right) \cdot a2} \]
    8. mult-flip-revN/A

      \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2}} \cdot a2 \]
    9. lower-/.f6486.4%

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

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

      \[\leadsto \frac{a1}{\color{blue}{b2 \cdot b1}} \cdot a2 \]
    12. lower-*.f6486.4%

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

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

Developer Target 1: 85.7% accurate, 0.9× speedup?

\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]
(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]
\frac{a1}{b1} \cdot \frac{a2}{b2}

Reproduce

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

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

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