Average Error: 11.4 → 5.3
Time: 2.6s
Precision: binary64
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2.2211230790851186 \cdot 10^{+188}:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq -1.2560827023635742 \cdot 10^{-204}:\\ \;\;\;\;\left(a2 \cdot a1\right) \cdot \frac{1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 6.526873840900358 \cdot 10^{-233}:\\ \;\;\;\;\frac{1}{b1} \cdot \left(a1 \cdot \frac{a2}{b2}\right)\\ \mathbf{elif}\;b1 \cdot b2 \leq 2.0537527697737033 \cdot 10^{+177}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;b1 \cdot b2 \leq -2.2211230790851186 \cdot 10^{+188}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\

\mathbf{elif}\;b1 \cdot b2 \leq -1.2560827023635742 \cdot 10^{-204}:\\
\;\;\;\;\left(a2 \cdot a1\right) \cdot \frac{1}{b1 \cdot b2}\\

\mathbf{elif}\;b1 \cdot b2 \leq 6.526873840900358 \cdot 10^{-233}:\\
\;\;\;\;\frac{1}{b1} \cdot \left(a1 \cdot \frac{a2}{b2}\right)\\

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

\mathbf{else}:\\
\;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{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.2211230790851186e+188)
   (* (/ a2 b1) (/ a1 b2))
   (if (<= (* b1 b2) -1.2560827023635742e-204)
     (* (* a2 a1) (/ 1.0 (* b1 b2)))
     (if (<= (* b1 b2) 6.526873840900358e-233)
       (* (/ 1.0 b1) (* a1 (/ a2 b2)))
       (if (<= (* b1 b2) 2.0537527697737033e+177)
         (* a2 (/ a1 (* b1 b2)))
         (* (/ a2 b1) (/ a1 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.2211230790851186e+188) {
		tmp = (a2 / b1) * (a1 / b2);
	} else if ((b1 * b2) <= -1.2560827023635742e-204) {
		tmp = (a2 * a1) * (1.0 / (b1 * b2));
	} else if ((b1 * b2) <= 6.526873840900358e-233) {
		tmp = (1.0 / b1) * (a1 * (a2 / b2));
	} else if ((b1 * b2) <= 2.0537527697737033e+177) {
		tmp = a2 * (a1 / (b1 * b2));
	} else {
		tmp = (a2 / b1) * (a1 / 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.4
Target11.1
Herbie5.3
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 4 regimes
  2. if (*.f64 b1 b2) < -2.22112307908511861e188 or 2.05375276977370331e177 < (*.f64 b1 b2)

    1. Initial program 14.6

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

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

      \[\leadsto \frac{a1}{\color{blue}{\frac{b1}{\frac{a2}{b2}}}}\]
    5. Using strategy rm
    6. Applied associate-/r/_binary648.0

      \[\leadsto \frac{a1}{\color{blue}{\frac{b1}{a2} \cdot b2}}\]
    7. Applied *-un-lft-identity_binary648.0

      \[\leadsto \frac{\color{blue}{1 \cdot a1}}{\frac{b1}{a2} \cdot b2}\]
    8. Applied times-frac_binary645.4

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

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

    if -2.22112307908511861e188 < (*.f64 b1 b2) < -1.2560827023635742e-204

    1. Initial program 4.5

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

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

    if -1.2560827023635742e-204 < (*.f64 b1 b2) < 6.52687384090035764e-233

    1. Initial program 36.1

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

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

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

      \[\leadsto \frac{a1}{\color{blue}{b1 \cdot \frac{1}{\frac{a2}{b2}}}}\]
    7. Applied *-un-lft-identity_binary6417.3

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

      \[\leadsto \color{blue}{\frac{1}{b1} \cdot \frac{a1}{\frac{1}{\frac{a2}{b2}}}}\]
    9. Simplified10.0

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

    if 6.52687384090035764e-233 < (*.f64 b1 b2) < 2.05375276977370331e177

    1. Initial program 4.9

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

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

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

      \[\leadsto \frac{a1}{\frac{b1}{\color{blue}{a2 \cdot \frac{1}{b2}}}}\]
    7. Applied *-un-lft-identity_binary6411.7

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

      \[\leadsto \frac{a1}{\color{blue}{\frac{1}{a2} \cdot \frac{b1}{\frac{1}{b2}}}}\]
    9. Applied *-un-lft-identity_binary644.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -2.2211230790851186 \cdot 10^{+188}:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq -1.2560827023635742 \cdot 10^{-204}:\\ \;\;\;\;\left(a2 \cdot a1\right) \cdot \frac{1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 6.526873840900358 \cdot 10^{-233}:\\ \;\;\;\;\frac{1}{b1} \cdot \left(a1 \cdot \frac{a2}{b2}\right)\\ \mathbf{elif}\;b1 \cdot b2 \leq 2.0537527697737033 \cdot 10^{+177}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \end{array}\]

Reproduce

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

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

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