Average Error: 11.3 → 3.3
Time: 3.6s
Precision: binary64
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -3.0886227990026322 \cdot 10^{+265}:\\ \;\;\;\;\frac{a2}{b1 \cdot \frac{b2}{a1}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -4.9315844250235 \cdot 10^{-317}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{a1}{\frac{b1}{\frac{a2}{b2}}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 1.673913532993364 \cdot 10^{+303}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{b2 \cdot \frac{b1}{a1}}{a2}}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -3.0886227990026322 \cdot 10^{+265}:\\
\;\;\;\;\frac{a2}{b1 \cdot \frac{b2}{a1}}\\

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

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\
\;\;\;\;\frac{a1}{\frac{b1}{\frac{a2}{b2}}}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 1.673913532993364 \cdot 10^{+303}:\\
\;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\

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

\end{array}
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (if (<= (/ (* a1 a2) (* b1 b2)) -3.0886227990026322e+265)
   (/ a2 (* b1 (/ b2 a1)))
   (if (<= (/ (* a1 a2) (* b1 b2)) -4.9315844250235e-317)
     (/ (* a1 a2) (* b1 b2))
     (if (<= (/ (* a1 a2) (* b1 b2)) 0.0)
       (/ a1 (/ b1 (/ a2 b2)))
       (if (<= (/ (* a1 a2) (* b1 b2)) 1.673913532993364e+303)
         (/ (* a1 a2) (* b1 b2))
         (/ 1.0 (/ (* b2 (/ b1 a1)) a2)))))))
double code(double a1, double a2, double b1, double b2) {
	return (((double) (a1 * a2)) / ((double) (b1 * b2)));
}
double code(double a1, double a2, double b1, double b2) {
	double tmp;
	if (((((double) (a1 * a2)) / ((double) (b1 * b2))) <= -3.0886227990026322e+265)) {
		tmp = (a2 / ((double) (b1 * (b2 / a1))));
	} else {
		double tmp_1;
		if (((((double) (a1 * a2)) / ((double) (b1 * b2))) <= -4.9315844250235e-317)) {
			tmp_1 = (((double) (a1 * a2)) / ((double) (b1 * b2)));
		} else {
			double tmp_2;
			if (((((double) (a1 * a2)) / ((double) (b1 * b2))) <= 0.0)) {
				tmp_2 = (a1 / (b1 / (a2 / b2)));
			} else {
				double tmp_3;
				if (((((double) (a1 * a2)) / ((double) (b1 * b2))) <= 1.673913532993364e+303)) {
					tmp_3 = (((double) (a1 * a2)) / ((double) (b1 * b2)));
				} else {
					tmp_3 = (1.0 / (((double) (b2 * (b1 / a1))) / a2));
				}
				tmp_2 = tmp_3;
			}
			tmp_1 = tmp_2;
		}
		tmp = tmp_1;
	}
	return tmp;
}

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.3
Target11.7
Herbie3.3
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -3.08862279900263218e265

    1. Initial program 44.7

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{b1 \cdot b2}{a1}}{a2}}}\]
    6. Simplified16.5

      \[\leadsto \frac{1}{\frac{\color{blue}{\frac{b1}{a1} \cdot b2}}{a2}}\]
    7. Taylor expanded around 0 44.7

      \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b1 \cdot b2}}\]
    8. Simplified16.5

      \[\leadsto \color{blue}{\frac{a2}{\frac{b1}{a1} \cdot b2}}\]
    9. Using strategy rm
    10. Applied div-inv_binary6416.6

      \[\leadsto \frac{a2}{\color{blue}{\left(b1 \cdot \frac{1}{a1}\right)} \cdot b2}\]
    11. Applied associate-*l*_binary6416.9

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

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

    if -3.08862279900263218e265 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.93158443e-317 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.673913532993364e303

    1. Initial program 0.8

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

    if -4.93158443e-317 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0

    1. Initial program 13.2

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

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

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

    if 1.673913532993364e303 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 62.8

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -3.0886227990026322 \cdot 10^{+265}:\\ \;\;\;\;\frac{a2}{b1 \cdot \frac{b2}{a1}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -4.9315844250235 \cdot 10^{-317}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{a1}{\frac{b1}{\frac{a2}{b2}}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 1.673913532993364 \cdot 10^{+303}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{b2 \cdot \frac{b1}{a1}}{a2}}\\ \end{array}\]

Reproduce

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

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

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