Average Error: 11.6 → 5.5
Time: 3.9s
Precision: binary64
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;b1 \cdot b2 \le -3.720837941461105 \cdot 10^{286}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \le -2.51097602999619632 \cdot 10^{-213}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \le 2.43806413534 \cdot 10^{-314}:\\ \;\;\;\;\frac{1}{b2 \cdot \left(\frac{1}{a1} \cdot \frac{b1}{a2}\right)}\\ \mathbf{elif}\;b1 \cdot b2 \le 8.30808618925979213 \cdot 10^{220}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b1} \cdot a2}{b2}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;b1 \cdot b2 \le -3.720837941461105 \cdot 10^{286}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\

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

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

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

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

\end{array}
double code(double a1, double a2, double b1, double b2) {
	return ((double) (((double) (a1 * a2)) / ((double) (b1 * b2))));
}
double code(double a1, double a2, double b1, double b2) {
	double VAR;
	if ((((double) (b1 * b2)) <= -3.720837941461105e+286)) {
		VAR = ((double) (((double) (a1 / b1)) * ((double) (a2 / b2))));
	} else {
		double VAR_1;
		if ((((double) (b1 * b2)) <= -2.5109760299961963e-213)) {
			VAR_1 = ((double) (a2 * ((double) (a1 / ((double) (b1 * b2))))));
		} else {
			double VAR_2;
			if ((((double) (b1 * b2)) <= 2.4380641353373e-314)) {
				VAR_2 = ((double) (1.0 / ((double) (b2 * ((double) (((double) (1.0 / a1)) * ((double) (b1 / a2))))))));
			} else {
				double VAR_3;
				if ((((double) (b1 * b2)) <= 8.308086189259792e+220)) {
					VAR_3 = ((double) (a2 * ((double) (a1 / ((double) (b1 * b2))))));
				} else {
					VAR_3 = ((double) (((double) (((double) (a1 / b1)) * a2)) / 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.6
Target11.9
Herbie5.5
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 4 regimes
  2. if (* b1 b2) < -3.720837941461105e286

    1. Initial program 20.1

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

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

    if -3.720837941461105e286 < (* b1 b2) < -2.51097602999619632e-213 or 2.43806413534e-314 < (* b1 b2) < 8.30808618925979213e220

    1. Initial program 5.1

      \[\frac{a1 \cdot a2}{b1 \cdot b2}\]
    2. Taylor expanded around 0 5.1

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

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

    if -2.51097602999619632e-213 < (* b1 b2) < 2.43806413534e-314

    1. Initial program 43.1

      \[\frac{a1 \cdot a2}{b1 \cdot b2}\]
    2. Using strategy rm
    3. Applied clear-num43.1

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

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

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

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

    if 8.30808618925979213e220 < (* b1 b2)

    1. Initial program 17.2

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \le -3.720837941461105 \cdot 10^{286}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \le -2.51097602999619632 \cdot 10^{-213}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \le 2.43806413534 \cdot 10^{-314}:\\ \;\;\;\;\frac{1}{b2 \cdot \left(\frac{1}{a1} \cdot \frac{b1}{a2}\right)}\\ \mathbf{elif}\;b1 \cdot b2 \le 8.30808618925979213 \cdot 10^{220}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b1} \cdot a2}{b2}\\ \end{array}\]

Reproduce

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

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

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