Average Error: 11.3 → 5.6
Time: 4.0s
Precision: binary64
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -3.742829709569337 \cdot 10^{+114}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq -6.441965215356643 \cdot 10^{-206}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2.0493010779246537 \cdot 10^{-260}:\\ \;\;\;\;\frac{\frac{a1}{b1} \cdot a2}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 1.1572837561305272 \cdot 10^{+224}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \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 -3.742829709569337 \cdot 10^{+114}:\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\

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

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

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

\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) -3.742829709569337e+114)
   (* (/ a1 b1) (/ a2 b2))
   (if (<= (* b1 b2) -6.441965215356643e-206)
     (* a1 (/ a2 (* b1 b2)))
     (if (<= (* b1 b2) 2.0493010779246537e-260)
       (/ (* (/ a1 b1) a2) b2)
       (if (<= (* b1 b2) 1.1572837561305272e+224)
         (* a1 (/ a2 (* b1 b2)))
         (* (/ 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) <= -3.742829709569337e+114) {
		tmp = (a1 / b1) * (a2 / b2);
	} else if ((b1 * b2) <= -6.441965215356643e-206) {
		tmp = a1 * (a2 / (b1 * b2));
	} else if ((b1 * b2) <= 2.0493010779246537e-260) {
		tmp = ((a1 / b1) * a2) / b2;
	} else if ((b1 * b2) <= 1.1572837561305272e+224) {
		tmp = a1 * (a2 / (b1 * b2));
	} 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.3
Target11.2
Herbie5.6
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 b1 b2) < -3.7428297095693369e114 or 1.1572837561305272e224 < (*.f64 b1 b2)

    1. Initial program 14.7

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

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

    if -3.7428297095693369e114 < (*.f64 b1 b2) < -6.44196521535664251e-206 or 2.0493010779246537e-260 < (*.f64 b1 b2) < 1.1572837561305272e224

    1. Initial program 4.4

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

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

      \[\leadsto \frac{a1}{\color{blue}{\frac{b1}{\frac{a2}{b2}}}}\]
    5. Using strategy rm
    6. Applied div-inv_binary64_248412.0

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

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

    if -6.44196521535664251e-206 < (*.f64 b1 b2) < 2.0493010779246537e-260

    1. Initial program 35.5

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -3.742829709569337 \cdot 10^{+114}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq -6.441965215356643 \cdot 10^{-206}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2.0493010779246537 \cdot 10^{-260}:\\ \;\;\;\;\frac{\frac{a1}{b1} \cdot a2}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 1.1572837561305272 \cdot 10^{+224}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \end{array}\]

Reproduce

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

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

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