Quotient of products

Percentage Accurate: 86.7% → 93.3%
Time: 3.3s
Alternatives: 6
Speedup: 0.4×

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 6 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.7% 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);
}
real(8) function code(a1, a2, b1, b2)
    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.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+188}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{b2} \cdot \left(a2 \cdot \frac{a1}{b1}\right)\\ \end{array} \end{array} \]
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (* a2 (/ a1 (* b1 b2)))))
   (if (<= (* b1 b2) -2e+94)
     (/ (/ a1 b2) (/ b1 a2))
     (if (<= (* b1 b2) -2e-197)
       t_0
       (if (<= (* b1 b2) 5e-228)
         (/ (/ a2 b2) (/ b1 a1))
         (if (<= (* b1 b2) 2e+188) t_0 (* (/ 1.0 b2) (* a2 (/ a1 b1)))))))))
double code(double a1, double a2, double b1, double b2) {
	double t_0 = a2 * (a1 / (b1 * b2));
	double tmp;
	if ((b1 * b2) <= -2e+94) {
		tmp = (a1 / b2) / (b1 / a2);
	} else if ((b1 * b2) <= -2e-197) {
		tmp = t_0;
	} else if ((b1 * b2) <= 5e-228) {
		tmp = (a2 / b2) / (b1 / a1);
	} else if ((b1 * b2) <= 2e+188) {
		tmp = t_0;
	} else {
		tmp = (1.0 / b2) * (a2 * (a1 / b1));
	}
	return tmp;
}
real(8) function code(a1, a2, b1, b2)
    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 * (a1 / (b1 * b2))
    if ((b1 * b2) <= (-2d+94)) then
        tmp = (a1 / b2) / (b1 / a2)
    else if ((b1 * b2) <= (-2d-197)) then
        tmp = t_0
    else if ((b1 * b2) <= 5d-228) then
        tmp = (a2 / b2) / (b1 / a1)
    else if ((b1 * b2) <= 2d+188) then
        tmp = t_0
    else
        tmp = (1.0d0 / b2) * (a2 * (a1 / b1))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = a2 * (a1 / (b1 * b2));
	double tmp;
	if ((b1 * b2) <= -2e+94) {
		tmp = (a1 / b2) / (b1 / a2);
	} else if ((b1 * b2) <= -2e-197) {
		tmp = t_0;
	} else if ((b1 * b2) <= 5e-228) {
		tmp = (a2 / b2) / (b1 / a1);
	} else if ((b1 * b2) <= 2e+188) {
		tmp = t_0;
	} else {
		tmp = (1.0 / b2) * (a2 * (a1 / b1));
	}
	return tmp;
}
def code(a1, a2, b1, b2):
	t_0 = a2 * (a1 / (b1 * b2))
	tmp = 0
	if (b1 * b2) <= -2e+94:
		tmp = (a1 / b2) / (b1 / a2)
	elif (b1 * b2) <= -2e-197:
		tmp = t_0
	elif (b1 * b2) <= 5e-228:
		tmp = (a2 / b2) / (b1 / a1)
	elif (b1 * b2) <= 2e+188:
		tmp = t_0
	else:
		tmp = (1.0 / b2) * (a2 * (a1 / b1))
	return tmp
function code(a1, a2, b1, b2)
	t_0 = Float64(a2 * Float64(a1 / Float64(b1 * b2)))
	tmp = 0.0
	if (Float64(b1 * b2) <= -2e+94)
		tmp = Float64(Float64(a1 / b2) / Float64(b1 / a2));
	elseif (Float64(b1 * b2) <= -2e-197)
		tmp = t_0;
	elseif (Float64(b1 * b2) <= 5e-228)
		tmp = Float64(Float64(a2 / b2) / Float64(b1 / a1));
	elseif (Float64(b1 * b2) <= 2e+188)
		tmp = t_0;
	else
		tmp = Float64(Float64(1.0 / b2) * Float64(a2 * Float64(a1 / b1)));
	end
	return tmp
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = a2 * (a1 / (b1 * b2));
	tmp = 0.0;
	if ((b1 * b2) <= -2e+94)
		tmp = (a1 / b2) / (b1 / a2);
	elseif ((b1 * b2) <= -2e-197)
		tmp = t_0;
	elseif ((b1 * b2) <= 5e-228)
		tmp = (a2 / b2) / (b1 / a1);
	elseif ((b1 * b2) <= 2e+188)
		tmp = t_0;
	else
		tmp = (1.0 / b2) * (a2 * (a1 / b1));
	end
	tmp_2 = tmp;
end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e+94], N[(N[(a1 / b2), $MachinePrecision] / N[(b1 / a2), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-197], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-228], N[(N[(a2 / b2), $MachinePrecision] / N[(b1 / a1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+188], t$95$0, N[(N[(1.0 / b2), $MachinePrecision] * N[(a2 * N[(a1 / b1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\
\mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\
\;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\

\mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+188}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{b2} \cdot \left(a2 \cdot \frac{a1}{b1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (*.f64 b1 b2) < -2e94

    1. Initial program 80.4%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. times-frac86.6%

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

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
    4. Step-by-step derivation
      1. frac-times80.4%

        \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}} \]
      2. *-commutative80.4%

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

        \[\leadsto \color{blue}{\frac{a1}{b2} \cdot \frac{a2}{b1}} \]
      4. clear-num99.7%

        \[\leadsto \frac{a1}{b2} \cdot \color{blue}{\frac{1}{\frac{b1}{a2}}} \]
      5. un-div-inv99.8%

        \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{\frac{b1}{a2}}} \]
    5. Applied egg-rr99.8%

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

    if -2e94 < (*.f64 b1 b2) < -2e-197 or 4.99999999999999972e-228 < (*.f64 b1 b2) < 2e188

    1. Initial program 86.9%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. associate-/l*94.4%

        \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
      2. *-commutative94.4%

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

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

      \[\leadsto \color{blue}{\frac{a1}{\frac{b2}{\frac{a2}{b1}}}} \]
    4. Step-by-step derivation
      1. associate-/l*94.4%

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2 \cdot b1}{a2}}} \]
      2. *-commutative94.4%

        \[\leadsto \frac{a1}{\frac{\color{blue}{b1 \cdot b2}}{a2}} \]
      3. associate-/r/97.4%

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

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

    if -2e-197 < (*.f64 b1 b2) < 4.99999999999999972e-228

    1. Initial program 79.4%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. times-frac96.2%

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

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
    4. Step-by-step derivation
      1. *-commutative96.2%

        \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
      2. clear-num96.2%

        \[\leadsto \frac{a2}{b2} \cdot \color{blue}{\frac{1}{\frac{b1}{a1}}} \]
      3. un-div-inv96.2%

        \[\leadsto \color{blue}{\frac{\frac{a2}{b2}}{\frac{b1}{a1}}} \]
    5. Applied egg-rr96.2%

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

    if 2e188 < (*.f64 b1 b2)

    1. Initial program 87.2%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. associate-/l*73.7%

        \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
      2. *-commutative73.7%

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

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

      \[\leadsto \color{blue}{\frac{a1}{\frac{b2}{\frac{a2}{b1}}}} \]
    4. Step-by-step derivation
      1. associate-/r/91.9%

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

        \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b2 \cdot b1}} \]
      3. *-un-lft-identity87.2%

        \[\leadsto \frac{\color{blue}{1 \cdot \left(a1 \cdot a2\right)}}{b2 \cdot b1} \]
      4. times-frac99.8%

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

        \[\leadsto \frac{1}{b2} \cdot \color{blue}{\left(\frac{a1}{b1} \cdot a2\right)} \]
    5. Applied egg-rr96.4%

      \[\leadsto \color{blue}{\frac{1}{b2} \cdot \left(\frac{a1}{b1} \cdot a2\right)} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification97.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+188}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{b2} \cdot \left(a2 \cdot \frac{a1}{b1}\right)\\ \end{array} \]

Alternative 2: 93.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\ t_1 := \frac{a1}{b2} \cdot \frac{a2}{b1}\\ \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (* a2 (/ a1 (* b1 b2)))) (t_1 (* (/ a1 b2) (/ a2 b1))))
   (if (<= (* b1 b2) -2e+94)
     t_1
     (if (<= (* b1 b2) -2e-197)
       t_0
       (if (<= (* b1 b2) 5e-228)
         (* (/ a2 b2) (/ a1 b1))
         (if (<= (* b1 b2) 2e+251) t_0 t_1))))))
double code(double a1, double a2, double b1, double b2) {
	double t_0 = a2 * (a1 / (b1 * b2));
	double t_1 = (a1 / b2) * (a2 / b1);
	double tmp;
	if ((b1 * b2) <= -2e+94) {
		tmp = t_1;
	} else if ((b1 * b2) <= -2e-197) {
		tmp = t_0;
	} else if ((b1 * b2) <= 5e-228) {
		tmp = (a2 / b2) * (a1 / b1);
	} else if ((b1 * b2) <= 2e+251) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a1, a2, b1, b2)
    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 * (a1 / (b1 * b2))
    t_1 = (a1 / b2) * (a2 / b1)
    if ((b1 * b2) <= (-2d+94)) then
        tmp = t_1
    else if ((b1 * b2) <= (-2d-197)) then
        tmp = t_0
    else if ((b1 * b2) <= 5d-228) then
        tmp = (a2 / b2) * (a1 / b1)
    else if ((b1 * b2) <= 2d+251) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = a2 * (a1 / (b1 * b2));
	double t_1 = (a1 / b2) * (a2 / b1);
	double tmp;
	if ((b1 * b2) <= -2e+94) {
		tmp = t_1;
	} else if ((b1 * b2) <= -2e-197) {
		tmp = t_0;
	} else if ((b1 * b2) <= 5e-228) {
		tmp = (a2 / b2) * (a1 / b1);
	} else if ((b1 * b2) <= 2e+251) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a1, a2, b1, b2):
	t_0 = a2 * (a1 / (b1 * b2))
	t_1 = (a1 / b2) * (a2 / b1)
	tmp = 0
	if (b1 * b2) <= -2e+94:
		tmp = t_1
	elif (b1 * b2) <= -2e-197:
		tmp = t_0
	elif (b1 * b2) <= 5e-228:
		tmp = (a2 / b2) * (a1 / b1)
	elif (b1 * b2) <= 2e+251:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a1, a2, b1, b2)
	t_0 = Float64(a2 * Float64(a1 / Float64(b1 * b2)))
	t_1 = Float64(Float64(a1 / b2) * Float64(a2 / b1))
	tmp = 0.0
	if (Float64(b1 * b2) <= -2e+94)
		tmp = t_1;
	elseif (Float64(b1 * b2) <= -2e-197)
		tmp = t_0;
	elseif (Float64(b1 * b2) <= 5e-228)
		tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1));
	elseif (Float64(b1 * b2) <= 2e+251)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = a2 * (a1 / (b1 * b2));
	t_1 = (a1 / b2) * (a2 / b1);
	tmp = 0.0;
	if ((b1 * b2) <= -2e+94)
		tmp = t_1;
	elseif ((b1 * b2) <= -2e-197)
		tmp = t_0;
	elseif ((b1 * b2) <= 5e-228)
		tmp = (a2 / b2) * (a1 / b1);
	elseif ((b1 * b2) <= 2e+251)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 / b2), $MachinePrecision] * N[(a2 / b1), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e+94], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-197], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-228], N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+251], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\
t_1 := \frac{a1}{b2} \cdot \frac{a2}{b1}\\
\mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 b1 b2) < -2e94 or 2.0000000000000001e251 < (*.f64 b1 b2)

    1. Initial program 80.6%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. associate-/l*81.7%

        \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
      2. *-commutative81.7%

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

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

      \[\leadsto \color{blue}{\frac{a1}{\frac{b2}{\frac{a2}{b1}}}} \]
    4. Step-by-step derivation
      1. associate-/r/99.0%

        \[\leadsto \color{blue}{\frac{a1}{b2} \cdot \frac{a2}{b1}} \]
      2. *-commutative99.0%

        \[\leadsto \color{blue}{\frac{a2}{b1} \cdot \frac{a1}{b2}} \]
    5. Applied egg-rr99.0%

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

    if -2e94 < (*.f64 b1 b2) < -2e-197 or 4.99999999999999972e-228 < (*.f64 b1 b2) < 2.0000000000000001e251

    1. Initial program 87.9%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. associate-/l*92.7%

        \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
      2. *-commutative92.7%

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

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2}{\frac{a2}{b1}}}} \]
    3. Simplified86.2%

      \[\leadsto \color{blue}{\frac{a1}{\frac{b2}{\frac{a2}{b1}}}} \]
    4. Step-by-step derivation
      1. associate-/l*92.7%

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2 \cdot b1}{a2}}} \]
      2. *-commutative92.7%

        \[\leadsto \frac{a1}{\frac{\color{blue}{b1 \cdot b2}}{a2}} \]
      3. associate-/r/96.8%

        \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]
    5. Applied egg-rr96.8%

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

    if -2e-197 < (*.f64 b1 b2) < 4.99999999999999972e-228

    1. Initial program 79.4%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. times-frac96.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\ \;\;\;\;\frac{a1}{b2} \cdot \frac{a2}{b1}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b2} \cdot \frac{a2}{b1}\\ \end{array} \]

Alternative 3: 93.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\ t_1 := \frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (* a2 (/ a1 (* b1 b2)))) (t_1 (/ (/ a1 b2) (/ b1 a2))))
   (if (<= (* b1 b2) -2e+94)
     t_1
     (if (<= (* b1 b2) -2e-197)
       t_0
       (if (<= (* b1 b2) 5e-228)
         (* (/ a2 b2) (/ a1 b1))
         (if (<= (* b1 b2) 2e+251) t_0 t_1))))))
double code(double a1, double a2, double b1, double b2) {
	double t_0 = a2 * (a1 / (b1 * b2));
	double t_1 = (a1 / b2) / (b1 / a2);
	double tmp;
	if ((b1 * b2) <= -2e+94) {
		tmp = t_1;
	} else if ((b1 * b2) <= -2e-197) {
		tmp = t_0;
	} else if ((b1 * b2) <= 5e-228) {
		tmp = (a2 / b2) * (a1 / b1);
	} else if ((b1 * b2) <= 2e+251) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a1, a2, b1, b2)
    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 * (a1 / (b1 * b2))
    t_1 = (a1 / b2) / (b1 / a2)
    if ((b1 * b2) <= (-2d+94)) then
        tmp = t_1
    else if ((b1 * b2) <= (-2d-197)) then
        tmp = t_0
    else if ((b1 * b2) <= 5d-228) then
        tmp = (a2 / b2) * (a1 / b1)
    else if ((b1 * b2) <= 2d+251) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = a2 * (a1 / (b1 * b2));
	double t_1 = (a1 / b2) / (b1 / a2);
	double tmp;
	if ((b1 * b2) <= -2e+94) {
		tmp = t_1;
	} else if ((b1 * b2) <= -2e-197) {
		tmp = t_0;
	} else if ((b1 * b2) <= 5e-228) {
		tmp = (a2 / b2) * (a1 / b1);
	} else if ((b1 * b2) <= 2e+251) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a1, a2, b1, b2):
	t_0 = a2 * (a1 / (b1 * b2))
	t_1 = (a1 / b2) / (b1 / a2)
	tmp = 0
	if (b1 * b2) <= -2e+94:
		tmp = t_1
	elif (b1 * b2) <= -2e-197:
		tmp = t_0
	elif (b1 * b2) <= 5e-228:
		tmp = (a2 / b2) * (a1 / b1)
	elif (b1 * b2) <= 2e+251:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a1, a2, b1, b2)
	t_0 = Float64(a2 * Float64(a1 / Float64(b1 * b2)))
	t_1 = Float64(Float64(a1 / b2) / Float64(b1 / a2))
	tmp = 0.0
	if (Float64(b1 * b2) <= -2e+94)
		tmp = t_1;
	elseif (Float64(b1 * b2) <= -2e-197)
		tmp = t_0;
	elseif (Float64(b1 * b2) <= 5e-228)
		tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1));
	elseif (Float64(b1 * b2) <= 2e+251)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = a2 * (a1 / (b1 * b2));
	t_1 = (a1 / b2) / (b1 / a2);
	tmp = 0.0;
	if ((b1 * b2) <= -2e+94)
		tmp = t_1;
	elseif ((b1 * b2) <= -2e-197)
		tmp = t_0;
	elseif ((b1 * b2) <= 5e-228)
		tmp = (a2 / b2) * (a1 / b1);
	elseif ((b1 * b2) <= 2e+251)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 / b2), $MachinePrecision] / N[(b1 / a2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e+94], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-197], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-228], N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+251], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\
t_1 := \frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\
\mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 b1 b2) < -2e94 or 2.0000000000000001e251 < (*.f64 b1 b2)

    1. Initial program 80.6%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. times-frac87.1%

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

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
    4. Step-by-step derivation
      1. frac-times80.6%

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

        \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b2 \cdot b1}} \]
      3. frac-times99.0%

        \[\leadsto \color{blue}{\frac{a1}{b2} \cdot \frac{a2}{b1}} \]
      4. clear-num99.0%

        \[\leadsto \frac{a1}{b2} \cdot \color{blue}{\frac{1}{\frac{b1}{a2}}} \]
      5. un-div-inv99.1%

        \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{\frac{b1}{a2}}} \]
    5. Applied egg-rr99.1%

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

    if -2e94 < (*.f64 b1 b2) < -2e-197 or 4.99999999999999972e-228 < (*.f64 b1 b2) < 2.0000000000000001e251

    1. Initial program 87.9%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. associate-/l*92.7%

        \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
      2. *-commutative92.7%

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

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2}{\frac{a2}{b1}}}} \]
    3. Simplified86.2%

      \[\leadsto \color{blue}{\frac{a1}{\frac{b2}{\frac{a2}{b1}}}} \]
    4. Step-by-step derivation
      1. associate-/l*92.7%

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2 \cdot b1}{a2}}} \]
      2. *-commutative92.7%

        \[\leadsto \frac{a1}{\frac{\color{blue}{b1 \cdot b2}}{a2}} \]
      3. associate-/r/96.8%

        \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]
    5. Applied egg-rr96.8%

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

    if -2e-197 < (*.f64 b1 b2) < 4.99999999999999972e-228

    1. Initial program 79.4%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. times-frac96.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \end{array} \]

Alternative 4: 93.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\ t_1 := \frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \end{array} \]
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (* a2 (/ a1 (* b1 b2)))) (t_1 (/ (/ a1 b2) (/ b1 a2))))
   (if (<= (* b1 b2) -2e+94)
     t_1
     (if (<= (* b1 b2) -2e-197)
       t_0
       (if (<= (* b1 b2) 5e-228)
         (/ (/ a2 b2) (/ b1 a1))
         (if (<= (* b1 b2) 2e+251) t_0 t_1))))))
double code(double a1, double a2, double b1, double b2) {
	double t_0 = a2 * (a1 / (b1 * b2));
	double t_1 = (a1 / b2) / (b1 / a2);
	double tmp;
	if ((b1 * b2) <= -2e+94) {
		tmp = t_1;
	} else if ((b1 * b2) <= -2e-197) {
		tmp = t_0;
	} else if ((b1 * b2) <= 5e-228) {
		tmp = (a2 / b2) / (b1 / a1);
	} else if ((b1 * b2) <= 2e+251) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(a1, a2, b1, b2)
    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 * (a1 / (b1 * b2))
    t_1 = (a1 / b2) / (b1 / a2)
    if ((b1 * b2) <= (-2d+94)) then
        tmp = t_1
    else if ((b1 * b2) <= (-2d-197)) then
        tmp = t_0
    else if ((b1 * b2) <= 5d-228) then
        tmp = (a2 / b2) / (b1 / a1)
    else if ((b1 * b2) <= 2d+251) then
        tmp = t_0
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = a2 * (a1 / (b1 * b2));
	double t_1 = (a1 / b2) / (b1 / a2);
	double tmp;
	if ((b1 * b2) <= -2e+94) {
		tmp = t_1;
	} else if ((b1 * b2) <= -2e-197) {
		tmp = t_0;
	} else if ((b1 * b2) <= 5e-228) {
		tmp = (a2 / b2) / (b1 / a1);
	} else if ((b1 * b2) <= 2e+251) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(a1, a2, b1, b2):
	t_0 = a2 * (a1 / (b1 * b2))
	t_1 = (a1 / b2) / (b1 / a2)
	tmp = 0
	if (b1 * b2) <= -2e+94:
		tmp = t_1
	elif (b1 * b2) <= -2e-197:
		tmp = t_0
	elif (b1 * b2) <= 5e-228:
		tmp = (a2 / b2) / (b1 / a1)
	elif (b1 * b2) <= 2e+251:
		tmp = t_0
	else:
		tmp = t_1
	return tmp
function code(a1, a2, b1, b2)
	t_0 = Float64(a2 * Float64(a1 / Float64(b1 * b2)))
	t_1 = Float64(Float64(a1 / b2) / Float64(b1 / a2))
	tmp = 0.0
	if (Float64(b1 * b2) <= -2e+94)
		tmp = t_1;
	elseif (Float64(b1 * b2) <= -2e-197)
		tmp = t_0;
	elseif (Float64(b1 * b2) <= 5e-228)
		tmp = Float64(Float64(a2 / b2) / Float64(b1 / a1));
	elseif (Float64(b1 * b2) <= 2e+251)
		tmp = t_0;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = a2 * (a1 / (b1 * b2));
	t_1 = (a1 / b2) / (b1 / a2);
	tmp = 0.0;
	if ((b1 * b2) <= -2e+94)
		tmp = t_1;
	elseif ((b1 * b2) <= -2e-197)
		tmp = t_0;
	elseif ((b1 * b2) <= 5e-228)
		tmp = (a2 / b2) / (b1 / a1);
	elseif ((b1 * b2) <= 2e+251)
		tmp = t_0;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 / b2), $MachinePrecision] / N[(b1 / a2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e+94], t$95$1, If[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-197], t$95$0, If[LessEqual[N[(b1 * b2), $MachinePrecision], 5e-228], N[(N[(a2 / b2), $MachinePrecision] / N[(b1 / a1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(b1 * b2), $MachinePrecision], 2e+251], t$95$0, t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := a2 \cdot \frac{a1}{b1 \cdot b2}\\
t_1 := \frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\
\mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (*.f64 b1 b2) < -2e94 or 2.0000000000000001e251 < (*.f64 b1 b2)

    1. Initial program 80.6%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. times-frac87.1%

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

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
    4. Step-by-step derivation
      1. frac-times80.6%

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

        \[\leadsto \frac{a1 \cdot a2}{\color{blue}{b2 \cdot b1}} \]
      3. frac-times99.0%

        \[\leadsto \color{blue}{\frac{a1}{b2} \cdot \frac{a2}{b1}} \]
      4. clear-num99.0%

        \[\leadsto \frac{a1}{b2} \cdot \color{blue}{\frac{1}{\frac{b1}{a2}}} \]
      5. un-div-inv99.1%

        \[\leadsto \color{blue}{\frac{\frac{a1}{b2}}{\frac{b1}{a2}}} \]
    5. Applied egg-rr99.1%

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

    if -2e94 < (*.f64 b1 b2) < -2e-197 or 4.99999999999999972e-228 < (*.f64 b1 b2) < 2.0000000000000001e251

    1. Initial program 87.9%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. associate-/l*92.7%

        \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
      2. *-commutative92.7%

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

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2}{\frac{a2}{b1}}}} \]
    3. Simplified86.2%

      \[\leadsto \color{blue}{\frac{a1}{\frac{b2}{\frac{a2}{b1}}}} \]
    4. Step-by-step derivation
      1. associate-/l*92.7%

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2 \cdot b1}{a2}}} \]
      2. *-commutative92.7%

        \[\leadsto \frac{a1}{\frac{\color{blue}{b1 \cdot b2}}{a2}} \]
      3. associate-/r/96.8%

        \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]
    5. Applied egg-rr96.8%

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

    if -2e-197 < (*.f64 b1 b2) < 4.99999999999999972e-228

    1. Initial program 79.4%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. times-frac96.2%

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

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
    4. Step-by-step derivation
      1. *-commutative96.2%

        \[\leadsto \color{blue}{\frac{a2}{b2} \cdot \frac{a1}{b1}} \]
      2. clear-num96.2%

        \[\leadsto \frac{a2}{b2} \cdot \color{blue}{\frac{1}{\frac{b1}{a1}}} \]
      3. un-div-inv96.2%

        \[\leadsto \color{blue}{\frac{\frac{a2}{b2}}{\frac{b1}{a1}}} \]
    5. Applied egg-rr96.2%

      \[\leadsto \color{blue}{\frac{\frac{a2}{b2}}{\frac{b1}{a1}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification97.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2 \cdot 10^{+94}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-197}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{\frac{a2}{b2}}{\frac{b1}{a1}}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{+251}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \end{array} \]

Alternative 5: 91.9% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -4 \cdot 10^{+218} \lor \neg \left(b1 \cdot b2 \leq -2 \cdot 10^{-197}\right) \land b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \end{array} \end{array} \]
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (if (or (<= (* b1 b2) -4e+218)
         (and (not (<= (* b1 b2) -2e-197)) (<= (* b1 b2) 5e-228)))
   (* (/ a2 b2) (/ a1 b1))
   (* a2 (/ a1 (* b1 b2)))))
double code(double a1, double a2, double b1, double b2) {
	double tmp;
	if (((b1 * b2) <= -4e+218) || (!((b1 * b2) <= -2e-197) && ((b1 * b2) <= 5e-228))) {
		tmp = (a2 / b2) * (a1 / b1);
	} else {
		tmp = a2 * (a1 / (b1 * b2));
	}
	return tmp;
}
real(8) function code(a1, a2, b1, b2)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: b1
    real(8), intent (in) :: b2
    real(8) :: tmp
    if (((b1 * b2) <= (-4d+218)) .or. (.not. ((b1 * b2) <= (-2d-197))) .and. ((b1 * b2) <= 5d-228)) then
        tmp = (a2 / b2) * (a1 / b1)
    else
        tmp = a2 * (a1 / (b1 * b2))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double b1, double b2) {
	double tmp;
	if (((b1 * b2) <= -4e+218) || (!((b1 * b2) <= -2e-197) && ((b1 * b2) <= 5e-228))) {
		tmp = (a2 / b2) * (a1 / b1);
	} else {
		tmp = a2 * (a1 / (b1 * b2));
	}
	return tmp;
}
def code(a1, a2, b1, b2):
	tmp = 0
	if ((b1 * b2) <= -4e+218) or (not ((b1 * b2) <= -2e-197) and ((b1 * b2) <= 5e-228)):
		tmp = (a2 / b2) * (a1 / b1)
	else:
		tmp = a2 * (a1 / (b1 * b2))
	return tmp
function code(a1, a2, b1, b2)
	tmp = 0.0
	if ((Float64(b1 * b2) <= -4e+218) || (!(Float64(b1 * b2) <= -2e-197) && (Float64(b1 * b2) <= 5e-228)))
		tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1));
	else
		tmp = Float64(a2 * Float64(a1 / Float64(b1 * b2)));
	end
	return tmp
end
function tmp_2 = code(a1, a2, b1, b2)
	tmp = 0.0;
	if (((b1 * b2) <= -4e+218) || (~(((b1 * b2) <= -2e-197)) && ((b1 * b2) <= 5e-228)))
		tmp = (a2 / b2) * (a1 / b1);
	else
		tmp = a2 * (a1 / (b1 * b2));
	end
	tmp_2 = tmp;
end
code[a1_, a2_, b1_, b2_] := If[Or[LessEqual[N[(b1 * b2), $MachinePrecision], -4e+218], And[N[Not[LessEqual[N[(b1 * b2), $MachinePrecision], -2e-197]], $MachinePrecision], LessEqual[N[(b1 * b2), $MachinePrecision], 5e-228]]], N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a1 / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b1 \cdot b2 \leq -4 \cdot 10^{+218} \lor \neg \left(b1 \cdot b2 \leq -2 \cdot 10^{-197}\right) \land b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\
\;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 b1 b2) < -4.00000000000000033e218 or -2e-197 < (*.f64 b1 b2) < 4.99999999999999972e-228

    1. Initial program 75.3%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. times-frac94.2%

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

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

    if -4.00000000000000033e218 < (*.f64 b1 b2) < -2e-197 or 4.99999999999999972e-228 < (*.f64 b1 b2)

    1. Initial program 88.4%

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Step-by-step derivation
      1. associate-/l*91.4%

        \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
      2. *-commutative91.4%

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

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2}{\frac{a2}{b1}}}} \]
    3. Simplified88.0%

      \[\leadsto \color{blue}{\frac{a1}{\frac{b2}{\frac{a2}{b1}}}} \]
    4. Step-by-step derivation
      1. associate-/l*91.4%

        \[\leadsto \frac{a1}{\color{blue}{\frac{b2 \cdot b1}{a2}}} \]
      2. *-commutative91.4%

        \[\leadsto \frac{a1}{\frac{\color{blue}{b1 \cdot b2}}{a2}} \]
      3. associate-/r/93.1%

        \[\leadsto \color{blue}{\frac{a1}{b1 \cdot b2} \cdot a2} \]
    5. Applied egg-rr93.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -4 \cdot 10^{+218} \lor \neg \left(b1 \cdot b2 \leq -2 \cdot 10^{-197}\right) \land b1 \cdot b2 \leq 5 \cdot 10^{-228}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \end{array} \]

Alternative 6: 86.5% accurate, 1.0× speedup?

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

\\
\frac{a2}{b2} \cdot \frac{a1}{b1}
\end{array}
Derivation
  1. Initial program 84.1%

    \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
  2. Step-by-step derivation
    1. times-frac83.7%

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

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

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

Developer target: 86.5% accurate, 1.0× speedup?

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

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

Reproduce

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

  :herbie-target
  (* (/ a1 b1) (/ a2 b2))

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