Average Error: 11.8 → 5.2
Time: 4.6s
Precision: binary64
\[[a1, a2]=\mathsf{sort}([a1, a2])\]
\[[b1, b2]=\mathsf{sort}([b1, b2])\]
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2.7267614406301062 \cdot 10^{+231}:\\ \;\;\;\;\frac{a1 \cdot \frac{a2}{b1}}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2.8110658549312455 \cdot 10^{-177}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2.9965081420272 \cdot 10^{-320}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2.5525240515500717 \cdot 10^{-125}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 1.8177159422765735 \cdot 10^{+208}:\\ \;\;\;\;\frac{a1}{\frac{b1 \cdot b2}{a2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;b1 \cdot b2 \leq -2.7267614406301062 \cdot 10^{+231}:\\
\;\;\;\;\frac{a1 \cdot \frac{a2}{b1}}{b2}\\

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

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

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

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

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

\end{array}
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (if (<= (* b1 b2) -2.7267614406301062e+231)
   (/ (* a1 (/ a2 b1)) b2)
   (if (<= (* b1 b2) -2.8110658549312455e-177)
     (* a2 (/ a1 (* b1 b2)))
     (if (<= (* b1 b2) 2.9965081420272e-320)
       (* (/ a1 b1) (/ a2 b2))
       (if (<= (* b1 b2) 2.5525240515500717e-125)
         (* a2 (/ a1 (* b1 b2)))
         (if (<= (* b1 b2) 1.8177159422765735e+208)
           (/ a1 (/ (* b1 b2) a2))
           (* (/ a1 b1) (/ a2 b2))))))))
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 tmp;
	if ((b1 * b2) <= -2.7267614406301062e+231) {
		tmp = (a1 * (a2 / b1)) / b2;
	} else if ((b1 * b2) <= -2.8110658549312455e-177) {
		tmp = a2 * (a1 / (b1 * b2));
	} else if ((b1 * b2) <= 2.9965081420272e-320) {
		tmp = (a1 / b1) * (a2 / b2);
	} else if ((b1 * b2) <= 2.5525240515500717e-125) {
		tmp = a2 * (a1 / (b1 * b2));
	} else if ((b1 * b2) <= 1.8177159422765735e+208) {
		tmp = a1 / ((b1 * b2) / a2);
	} else {
		tmp = (a1 / b1) * (a2 / b2);
	}
	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.8
Target11.1
Herbie5.2
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 4 regimes
  2. if (*.f64 b1 b2) < -2.72676144063010621e231

    1. Initial program 18.3

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

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

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

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

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

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

      \[\leadsto a2 \cdot \color{blue}{\frac{a1}{b1 \cdot b2}}\]
    10. Using strategy rm
    11. Applied *-un-lft-identity_binary6417.8

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

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

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

      \[\leadsto \color{blue}{\frac{a2}{b1}} \cdot \frac{a1}{b2}\]
    15. Using strategy rm
    16. Applied associate-*r/_binary644.3

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

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

    if -2.72676144063010621e231 < (*.f64 b1 b2) < -2.8110658549312455e-177 or 2.99651e-320 < (*.f64 b1 b2) < 2.55252405155007167e-125

    1. Initial program 6.3

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

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

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

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

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

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

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

    if -2.8110658549312455e-177 < (*.f64 b1 b2) < 2.99651e-320 or 1.81771594227657351e208 < (*.f64 b1 b2)

    1. Initial program 25.3

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

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

    if 2.55252405155007167e-125 < (*.f64 b1 b2) < 1.81771594227657351e208

    1. Initial program 4.5

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2.7267614406301062 \cdot 10^{+231}:\\ \;\;\;\;\frac{a1 \cdot \frac{a2}{b1}}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2.8110658549312455 \cdot 10^{-177}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2.9965081420272 \cdot 10^{-320}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2.5525240515500717 \cdot 10^{-125}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 1.8177159422765735 \cdot 10^{+208}:\\ \;\;\;\;\frac{a1}{\frac{b1 \cdot b2}{a2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \end{array}\]

Reproduce

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

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

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