Average Error: 11.5 → 3.2
Time: 2.2s
Precision: 64
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -1.47074278660312632 \cdot 10^{289}:\\ \;\;\;\;a1 \cdot \frac{\frac{a2}{b1}}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -3.4007182049068929 \cdot 10^{-296}:\\ \;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -0.0:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.42043341085146038 \cdot 10^{298}:\\ \;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1 \cdot \frac{a2}{b1}}{b2}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -1.47074278660312632 \cdot 10^{289}:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b1}}{b2}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -3.4007182049068929 \cdot 10^{-296}:\\
\;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}\\

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

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.42043341085146038 \cdot 10^{298}:\\
\;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}\\

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

\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)) <= -1.4707427866031263e+289)) {
		VAR = (a1 * ((a2 / b1) / b2));
	} else {
		double VAR_1;
		if ((((a1 * a2) / (b1 * b2)) <= -3.400718204906893e-296)) {
			VAR_1 = ((a1 * a2) * (1.0 / (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)) <= 1.4204334108514604e+298)) {
					VAR_3 = ((a1 * a2) * (1.0 / (b1 * b2)));
				} else {
					VAR_3 = ((a1 * (a2 / b1)) / b2);
				}
				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.5
Target11.4
Herbie3.2
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 4 regimes
  2. if (/ (* a1 a2) (* b1 b2)) < -1.4707427866031263e+289

    1. Initial program 52.2

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

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

      \[\leadsto \frac{\frac{a1 \cdot a2}{b1}}{\color{blue}{1 \cdot b2}}\]
    6. Applied *-un-lft-identity31.5

      \[\leadsto \frac{\frac{a1 \cdot a2}{\color{blue}{1 \cdot b1}}}{1 \cdot b2}\]
    7. Applied times-frac19.3

      \[\leadsto \frac{\color{blue}{\frac{a1}{1} \cdot \frac{a2}{b1}}}{1 \cdot b2}\]
    8. Applied times-frac17.2

      \[\leadsto \color{blue}{\frac{\frac{a1}{1}}{1} \cdot \frac{\frac{a2}{b1}}{b2}}\]
    9. Simplified17.2

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

    if -1.4707427866031263e+289 < (/ (* a1 a2) (* b1 b2)) < -3.400718204906893e-296 or -0.0 < (/ (* a1 a2) (* b1 b2)) < 1.4204334108514604e+298

    1. Initial program 0.9

      \[\frac{a1 \cdot a2}{b1 \cdot b2}\]
    2. Using strategy rm
    3. Applied div-inv1.3

      \[\leadsto \color{blue}{\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}}\]

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

    1. Initial program 13.2

      \[\frac{a1 \cdot a2}{b1 \cdot b2}\]
    2. Using strategy rm
    3. Applied times-frac2.6

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

    if 1.4204334108514604e+298 < (/ (* a1 a2) (* b1 b2))

    1. Initial program 61.7

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -1.47074278660312632 \cdot 10^{289}:\\ \;\;\;\;a1 \cdot \frac{\frac{a2}{b1}}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -3.4007182049068929 \cdot 10^{-296}:\\ \;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -0.0:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.42043341085146038 \cdot 10^{298}:\\ \;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1 \cdot \frac{a2}{b1}}{b2}\\ \end{array}\]

Reproduce

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

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

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