Average Error: 11.7 → 5.3
Time: 6.0s
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 -1.027465146776261 \cdot 10^{+296}:\\ \;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2.686121678391523 \cdot 10^{-295}:\\ \;\;\;\;\frac{a2 \cdot a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 1.7361396809959 \cdot 10^{-311}:\\ \;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 7.874769199228514 \cdot 10^{+270}:\\ \;\;\;\;\frac{a1}{\frac{b1 \cdot b2}{a2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{\frac{b1}{a2}}}{b2}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;b1 \cdot b2 \leq -1.027465146776261 \cdot 10^{+296}:\\
\;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{a1}{\frac{b1}{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) -1.027465146776261e+296)
   (/ (* a2 (/ a1 b1)) b2)
   (if (<= (* b1 b2) -2.686121678391523e-295)
     (/ (* a2 a1) (* b1 b2))
     (if (<= (* b1 b2) 1.7361396809959e-311)
       (/ (* a2 (/ a1 b1)) b2)
       (if (<= (* b1 b2) 7.874769199228514e+270)
         (/ 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) <= -1.027465146776261e+296) {
		tmp = (a2 * (a1 / b1)) / b2;
	} else if ((b1 * b2) <= -2.686121678391523e-295) {
		tmp = (a2 * a1) / (b1 * b2);
	} else if ((b1 * b2) <= 1.7361396809959e-311) {
		tmp = (a2 * (a1 / b1)) / b2;
	} else if ((b1 * b2) <= 7.874769199228514e+270) {
		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.7
Target11.4
Herbie5.3
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 4 regimes
  2. if (*.f64 b1 b2) < -1.02746514677626109e296 or -2.6861216783915232e-295 < (*.f64 b1 b2) < 1.73613968099587e-311

    1. Initial program 36.8

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

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

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

    if -1.02746514677626109e296 < (*.f64 b1 b2) < -2.6861216783915232e-295

    1. Initial program 5.8

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

    if 1.73613968099587e-311 < (*.f64 b1 b2) < 7.8747691992285138e270

    1. Initial program 5.6

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

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

    if 7.8747691992285138e270 < (*.f64 b1 b2)

    1. Initial program 20.5

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

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

      \[\leadsto \frac{\color{blue}{a2 \cdot \frac{a1}{b1}}}{b2}\]
    5. Taylor expanded around 0 9.6

      \[\leadsto \frac{\color{blue}{\frac{a1 \cdot a2}{b1}}}{b2}\]
    6. Using strategy rm
    7. Applied associate-/l*_binary64_58203.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -1.027465146776261 \cdot 10^{+296}:\\ \;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2.686121678391523 \cdot 10^{-295}:\\ \;\;\;\;\frac{a2 \cdot a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 1.7361396809959 \cdot 10^{-311}:\\ \;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 7.874769199228514 \cdot 10^{+270}:\\ \;\;\;\;\frac{a1}{\frac{b1 \cdot b2}{a2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{\frac{b1}{a2}}}{b2}\\ \end{array}\]

Reproduce

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

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

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