Average Error: 11.2 → 2.7
Time: 2.4s
Precision: 64
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -6.40588661831116472 \cdot 10^{-296}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -0.0:\\ \;\;\;\;\frac{a1}{\frac{b1}{a2} \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 2.37991482612767615 \cdot 10^{284}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\
\;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -6.40588661831116472 \cdot 10^{-296}:\\
\;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -0.0:\\
\;\;\;\;\frac{a1}{\frac{b1}{a2} \cdot b2}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 2.37991482612767615 \cdot 10^{284}:\\
\;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\

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

\end{array}
double code(double a1, double a2, double b1, double b2) {
	return ((a1 * a2) / (b1 * b2));
}
double code(double a1, double a2, double b1, double b2) {
	double VAR;
	if ((((a1 * a2) / (b1 * b2)) <= -inf.0)) {
		VAR = ((a1 / b1) / (b2 / a2));
	} else {
		double VAR_1;
		if ((((a1 * a2) / (b1 * b2)) <= -6.405886618311165e-296)) {
			VAR_1 = ((a1 * a2) / (b1 * b2));
		} else {
			double VAR_2;
			if ((((a1 * a2) / (b1 * b2)) <= -0.0)) {
				VAR_2 = (a1 / ((b1 / a2) * b2));
			} else {
				double VAR_3;
				if ((((a1 * a2) / (b1 * b2)) <= 2.379914826127676e+284)) {
					VAR_3 = ((a1 * a2) / (b1 * b2));
				} else {
					VAR_3 = ((a1 / b1) / (b2 / a2));
				}
				VAR_2 = VAR_3;
			}
			VAR_1 = VAR_2;
		}
		VAR = VAR_1;
	}
	return VAR;
}

Error

Bits error versus a1

Bits error versus a2

Bits error versus b1

Bits error versus b2

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.2
Target11.1
Herbie2.7
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* a1 a2) (* b1 b2)) < -inf.0 or 2.379914826127676e+284 < (/ (* a1 a2) (* b1 b2))

    1. Initial program 60.3

      \[\frac{a1 \cdot a2}{b1 \cdot b2}\]
    2. Using strategy rm
    3. Applied associate-/l*40.1

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity40.1

      \[\leadsto \frac{a1}{\frac{b1 \cdot b2}{\color{blue}{1 \cdot a2}}}\]
    6. Applied times-frac15.9

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

      \[\leadsto \color{blue}{\frac{\frac{a1}{\frac{b1}{1}}}{\frac{b2}{a2}}}\]
    8. Simplified9.0

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

    if -inf.0 < (/ (* a1 a2) (* b1 b2)) < -6.405886618311165e-296 or -0.0 < (/ (* a1 a2) (* b1 b2)) < 2.379914826127676e+284

    1. Initial program 0.8

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

    if -6.405886618311165e-296 < (/ (* a1 a2) (* b1 b2)) < -0.0

    1. Initial program 13.1

      \[\frac{a1 \cdot a2}{b1 \cdot b2}\]
    2. Using strategy rm
    3. Applied associate-/l*6.8

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}}\]
    4. Using strategy rm
    5. Applied associate-/l*3.9

      \[\leadsto \frac{a1}{\color{blue}{\frac{b1}{\frac{a2}{b2}}}}\]
    6. Using strategy rm
    7. Applied associate-/r/3.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -6.40588661831116472 \cdot 10^{-296}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -0.0:\\ \;\;\;\;\frac{a1}{\frac{b1}{a2} \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 2.37991482612767615 \cdot 10^{284}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \end{array}\]

Reproduce

herbie shell --seed 2020102 +o rules:numerics
(FPCore (a1 a2 b1 b2)
  :name "Quotient of products"
  :precision binary64

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

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