Average Error: 11.4 → 2.0
Time: 5.8s
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}\\ t_1 := \frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -9.14 \cdot 10^{-322}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{a2}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}} \cdot \frac{\frac{a1}{b1}}{\sqrt[3]{b2}}\\ \mathbf{elif}\;t_0 \leq 1.5489696528649269 \cdot 10^{+305}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -9.14 \cdot 10^{-322}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{a2}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}} \cdot \frac{\frac{a1}{b1}}{\sqrt[3]{b2}}\\

\mathbf{elif}\;t_0 \leq 1.5489696528649269 \cdot 10^{+305}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\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))) (t_1 (* (/ a1 b1) (/ a2 b2))))
   (if (<= t_0 (- INFINITY))
     t_1
     (if (<= t_0 -9.14e-322)
       t_0
       (if (<= t_0 0.0)
         (* (/ a2 (* (cbrt b2) (cbrt b2))) (/ (/ a1 b1) (cbrt b2)))
         (if (<= t_0 1.5489696528649269e+305) t_0 t_1))))))
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 t_1 = (a1 / b1) * (a2 / b2);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = t_1;
	} else if (t_0 <= -9.14e-322) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = (a2 / (cbrt(b2) * cbrt(b2))) * ((a1 / b1) / cbrt(b2));
	} else if (t_0 <= 1.5489696528649269e+305) {
		tmp = t_0;
	} else {
		tmp = t_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.4
Target11.6
Herbie2.0
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0 or 1.54896965286492688e305 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 63.3

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

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

    if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -9.14021e-322 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.54896965286492688e305

    1. Initial program 0.8

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

    if -9.14021e-322 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0

    1. Initial program 13.7

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

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

      \[\leadsto \frac{\color{blue}{a2 \cdot \frac{a1}{b1}}}{b2} \]
    5. Using strategy rm
    6. Applied add-cube-cbrt_binary644.1

      \[\leadsto \frac{a2 \cdot \frac{a1}{b1}}{\color{blue}{\left(\sqrt[3]{b2} \cdot \sqrt[3]{b2}\right) \cdot \sqrt[3]{b2}}} \]
    7. Applied times-frac_binary642.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -\infty:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -9.14 \cdot 10^{-322}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{a2}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}} \cdot \frac{\frac{a1}{b1}}{\sqrt[3]{b2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 1.5489696528649269 \cdot 10^{+305}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \end{array} \]

Reproduce

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

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

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