Average Error: 11.4 → 3.7
Time: 5.2s
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 -1.7956579752851291 \cdot 10^{-292}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 4.1253792486547885 \cdot 10^{+274}:\\ \;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{\frac{1}{b2}}{b1}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{\sqrt{b2}} \cdot \frac{\frac{a2}{\sqrt{b2}}}{b1}\\ \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 -1.7956579752851291 \cdot 10^{-292}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 4.1253792486547885 \cdot 10^{+274}:\\
\;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{\frac{1}{b2}}{b1}\\

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


\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 -1.7956579752851291e-292)
       t_0
       (if (<= t_0 0.0)
         t_1
         (if (<= t_0 4.1253792486547885e+274)
           (* (* a1 a2) (/ (/ 1.0 b2) b1))
           (* (/ a1 (sqrt b2)) (/ (/ a2 (sqrt b2)) b1))))))))
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 <= -1.7956579752851291e-292) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = t_1;
	} else if (t_0 <= 4.1253792486547885e+274) {
		tmp = (a1 * a2) * ((1.0 / b2) / b1);
	} else {
		tmp = (a1 / sqrt(b2)) * ((a2 / sqrt(b2)) / b1);
	}
	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.3
Herbie3.7
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0 or -1.79565797528512915e-292 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0

    1. Initial program 18.4

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

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

    if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.79565797528512915e-292

    1. Initial program 0.9

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

    if 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.1253792486547885e274

    1. Initial program 0.8

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

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

      \[\leadsto \left(a1 \cdot a2\right) \cdot \color{blue}{\frac{1}{b2 \cdot b1}} \]
    5. Using strategy rm
    6. Applied associate-/r*_binary641.2

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

    if 4.1253792486547885e274 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 54.8

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

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

      \[\leadsto \left(a1 \cdot a2\right) \cdot \color{blue}{\frac{1}{b2 \cdot b1}} \]
    5. Using strategy rm
    6. Applied *-un-lft-identity_binary6455.2

      \[\leadsto \left(a1 \cdot a2\right) \cdot \frac{\color{blue}{1 \cdot 1}}{b2 \cdot b1} \]
    7. Applied times-frac_binary6455.2

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

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

      \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b2}} \cdot \frac{1}{b1} \]
    10. Using strategy rm
    11. Applied add-sqr-sqrt_binary6448.8

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

      \[\leadsto \color{blue}{\left(\frac{a1}{\sqrt{b2}} \cdot \frac{a2}{\sqrt{b2}}\right)} \cdot \frac{1}{b1} \]
    13. Applied associate-*l*_binary6422.7

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

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

    \[\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 -1.7956579752851291 \cdot 10^{-292}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 4.1253792486547885 \cdot 10^{+274}:\\ \;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{\frac{1}{b2}}{b1}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{\sqrt{b2}} \cdot \frac{\frac{a2}{\sqrt{b2}}}{b1}\\ \end{array} \]

Reproduce

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

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

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