Average Error: 11.4 → 2.6
Time: 4.5s
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}\\ \mathbf{if}\;t_0 \leq -\infty:\\ \;\;\;\;\frac{a2}{\frac{b2}{\frac{a1}{b1}}}\\ \mathbf{elif}\;t_0 \leq -1.6 \cdot 10^{-322}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{\frac{a1}{\sqrt[3]{b1} \cdot \sqrt[3]{b1}}}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}} \cdot \frac{\frac{a2}{\sqrt[3]{b1}}}{\sqrt[3]{b2}}\\ \mathbf{elif}\;t_0 \leq 8.976436028657778 \cdot 10^{+264}:\\ \;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{\frac{1}{b1}}{b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \end{array} \]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -\infty:\\
\;\;\;\;\frac{a2}{\frac{b2}{\frac{a1}{b1}}}\\

\mathbf{elif}\;t_0 \leq -1.6 \cdot 10^{-322}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;\frac{\frac{a1}{\sqrt[3]{b1} \cdot \sqrt[3]{b1}}}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}} \cdot \frac{\frac{a2}{\sqrt[3]{b1}}}{\sqrt[3]{b2}}\\

\mathbf{elif}\;t_0 \leq 8.976436028657778 \cdot 10^{+264}:\\
\;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{\frac{1}{b1}}{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
 (let* ((t_0 (/ (* a1 a2) (* b1 b2))))
   (if (<= t_0 (- INFINITY))
     (/ a2 (/ b2 (/ a1 b1)))
     (if (<= t_0 -1.6e-322)
       t_0
       (if (<= t_0 0.0)
         (*
          (/ (/ a1 (* (cbrt b1) (cbrt b1))) (* (cbrt b2) (cbrt b2)))
          (/ (/ a2 (cbrt b1)) (cbrt b2)))
         (if (<= t_0 8.976436028657778e+264)
           (* (* a1 a2) (/ (/ 1.0 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 t_0 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_0 <= -((double) INFINITY)) {
		tmp = a2 / (b2 / (a1 / b1));
	} else if (t_0 <= -1.6e-322) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = ((a1 / (cbrt(b1) * cbrt(b1))) / (cbrt(b2) * cbrt(b2))) * ((a2 / cbrt(b1)) / cbrt(b2));
	} else if (t_0 <= 8.976436028657778e+264) {
		tmp = (a1 * a2) * ((1.0 / 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.4
Target11.5
Herbie2.6
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation

  1. Split input into 5 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -inf.0

    1. Initial program 64.0

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied associate-/r*_binary6432.7

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

      \[\leadsto \frac{\color{blue}{a2 \cdot \frac{a1}{b1}}}{b2} \]
    4. Applied associate-/l*_binary6417.3

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

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

    1. Initial program 0.8

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied associate-/r*_binary648.8

      \[\leadsto \color{blue}{\frac{\frac{a1 \cdot a2}{b1}}{b2}} \]
    3. Taylor expanded in a1 around 0 0.8

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

    if -1.58101e-322 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0

    1. Initial program 14.4

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied associate-/r*_binary646.9

      \[\leadsto \color{blue}{\frac{\frac{a1 \cdot a2}{b1}}{b2}} \]
    3. Applied add-cube-cbrt_binary647.1

      \[\leadsto \frac{\frac{a1 \cdot a2}{b1}}{\color{blue}{\left(\sqrt[3]{b2} \cdot \sqrt[3]{b2}\right) \cdot \sqrt[3]{b2}}} \]
    4. Applied add-cube-cbrt_binary647.1

      \[\leadsto \frac{\frac{a1 \cdot a2}{\color{blue}{\left(\sqrt[3]{b1} \cdot \sqrt[3]{b1}\right) \cdot \sqrt[3]{b1}}}}{\left(\sqrt[3]{b2} \cdot \sqrt[3]{b2}\right) \cdot \sqrt[3]{b2}} \]
    5. Applied times-frac_binary643.8

      \[\leadsto \frac{\color{blue}{\frac{a1}{\sqrt[3]{b1} \cdot \sqrt[3]{b1}} \cdot \frac{a2}{\sqrt[3]{b1}}}}{\left(\sqrt[3]{b2} \cdot \sqrt[3]{b2}\right) \cdot \sqrt[3]{b2}} \]
    6. Applied times-frac_binary642.1

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

    if -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 8.97643602865777766e264

    1. Initial program 0.8

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

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

      \[\leadsto \frac{\frac{a1 \cdot a2}{b1}}{\color{blue}{1 \cdot b2}} \]
    4. Applied div-inv_binary647.4

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

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

    if 8.97643602865777766e264 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 53.5

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied times-frac_binary649.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -\infty:\\ \;\;\;\;\frac{a2}{\frac{b2}{\frac{a1}{b1}}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -1.6 \cdot 10^{-322}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{\frac{a1}{\sqrt[3]{b1} \cdot \sqrt[3]{b1}}}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}} \cdot \frac{\frac{a2}{\sqrt[3]{b1}}}{\sqrt[3]{b2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 8.976436028657778 \cdot 10^{+264}:\\ \;\;\;\;\left(a1 \cdot a2\right) \cdot \frac{\frac{1}{b1}}{b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \end{array} \]

Reproduce

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

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

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