Average Error: 11.2 → 4.0
Time: 5.1s
Precision: binary64
\[[a1, a2]=\mathsf{sort}([a1, a2])\]
\[[b1, b2]=\mathsf{sort}([b1, b2])\]
\[\frac{a1 \cdot a2}{b1 \cdot b2} \]
\[\begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t_0 \leq -8.466466328893688 \cdot 10^{+180}:\\ \;\;\;\;\frac{\frac{a1}{b1 \cdot b2}}{\frac{1}{a2}}\\ \mathbf{elif}\;t_0 \leq -1.913926 \cdot 10^{-318}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 1.9964924777458289 \cdot 10^{-292}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;t_0 \leq 3.336443235690429 \cdot 10^{+265}:\\ \;\;\;\;\frac{1}{\frac{b1 \cdot b2}{a1 \cdot a2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{\frac{b2}{\frac{a2}{b1}}}\\ \end{array} \]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -8.466466328893688 \cdot 10^{+180}:\\
\;\;\;\;\frac{\frac{a1}{b1 \cdot b2}}{\frac{1}{a2}}\\

\mathbf{elif}\;t_0 \leq -1.913926 \cdot 10^{-318}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 1.9964924777458289 \cdot 10^{-292}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\

\mathbf{elif}\;t_0 \leq 3.336443235690429 \cdot 10^{+265}:\\
\;\;\;\;\frac{1}{\frac{b1 \cdot b2}{a1 \cdot a2}}\\

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


\end{array}
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (/ (* a1 a2) (* b1 b2))))
   (if (<= t_0 -8.466466328893688e+180)
     (/ (/ a1 (* b1 b2)) (/ 1.0 a2))
     (if (<= t_0 -1.913926e-318)
       t_0
       (if (<= t_0 1.9964924777458289e-292)
         (* (/ a1 b1) (/ a2 b2))
         (if (<= t_0 3.336443235690429e+265)
           (/ 1.0 (/ (* b1 b2) (* a1 a2)))
           (/ a1 (/ b2 (/ a2 b1)))))))))
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 t_0 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_0 <= -8.466466328893688e+180) {
		tmp = (a1 / (b1 * b2)) / (1.0 / a2);
	} else if (t_0 <= -1.913926e-318) {
		tmp = t_0;
	} else if (t_0 <= 1.9964924777458289e-292) {
		tmp = (a1 / b1) * (a2 / b2);
	} else if (t_0 <= 3.336443235690429e+265) {
		tmp = 1.0 / ((b1 * b2) / (a1 * a2));
	} else {
		tmp = a1 / (b2 / (a2 / b1));
	}
	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.2
Target11.6
Herbie4.0
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation

  1. Split input into 5 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -8.46646632889368804e180

    1. Initial program 25.9

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied associate-/l*_binary6419.7

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
    3. Applied div-inv_binary6419.7

      \[\leadsto \frac{a1}{\color{blue}{\left(b1 \cdot b2\right) \cdot \frac{1}{a2}}} \]
    4. Applied associate-/r*_binary6419.4

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

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

    if -8.46646632889368804e180 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.9139263e-318

    1. Initial program 1.0

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied associate-/l*_binary646.5

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
    3. Taylor expanded in a1 around 0 1.0

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

    if -1.9139263e-318 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.99649247774582888e-292

    1. Initial program 13.3

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied times-frac_binary642.5

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

    if 1.99649247774582888e-292 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 3.3364432356904289e265

    1. Initial program 0.7

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied clear-num_binary640.8

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

    if 3.3364432356904289e265 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 53.9

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied associate-/l*_binary6442.9

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
    3. Applied div-inv_binary6442.9

      \[\leadsto \frac{a1}{\color{blue}{\left(b1 \cdot b2\right) \cdot \frac{1}{a2}}} \]
    4. Applied add-cube-cbrt_binary6443.2

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{a1} \cdot \sqrt[3]{a1}\right) \cdot \sqrt[3]{a1}}}{\left(b1 \cdot b2\right) \cdot \frac{1}{a2}} \]
    5. Applied times-frac_binary6444.8

      \[\leadsto \color{blue}{\frac{\sqrt[3]{a1} \cdot \sqrt[3]{a1}}{b1 \cdot b2} \cdot \frac{\sqrt[3]{a1}}{\frac{1}{a2}}} \]
    6. Applied frac-times_binary6443.2

      \[\leadsto \color{blue}{\frac{\left(\sqrt[3]{a1} \cdot \sqrt[3]{a1}\right) \cdot \sqrt[3]{a1}}{\left(b1 \cdot b2\right) \cdot \frac{1}{a2}}} \]
    7. Simplified42.9

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

      \[\leadsto \frac{a1}{\color{blue}{\frac{b2 \cdot b1}{a2}}} \]
    9. Applied associate-/l*_binary6414.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -8.466466328893688 \cdot 10^{+180}:\\ \;\;\;\;\frac{\frac{a1}{b1 \cdot b2}}{\frac{1}{a2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -1.913926 \cdot 10^{-318}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 1.9964924777458289 \cdot 10^{-292}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 3.336443235690429 \cdot 10^{+265}:\\ \;\;\;\;\frac{1}{\frac{b1 \cdot b2}{a1 \cdot a2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{\frac{b2}{\frac{a2}{b1}}}\\ \end{array} \]

Reproduce

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

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

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