Average Error: 11.9 → 1.8
Time: 7.1s
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}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -4.217247420283257 \cdot 10^{+302}:\\ \;\;\;\;\frac{1}{\frac{\sqrt[3]{b1} \cdot \sqrt[3]{b1}}{\frac{\sqrt[3]{a2} \cdot \sqrt[3]{a2}}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}}}} \cdot \frac{a1}{\frac{\sqrt[3]{b1}}{\frac{\sqrt[3]{a2}}{\sqrt[3]{b2}}}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -2.300420913112 \cdot 10^{-310}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0 \lor \neg \left(\frac{a1 \cdot a2}{b1 \cdot b2} \leq 6.2999843586282166 \cdot 10^{+302}\right):\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1 \cdot a2}{\frac{b1}{\frac{1}{b2}}}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -4.217247420283257 \cdot 10^{+302}:\\
\;\;\;\;\frac{1}{\frac{\sqrt[3]{b1} \cdot \sqrt[3]{b1}}{\frac{\sqrt[3]{a2} \cdot \sqrt[3]{a2}}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}}}} \cdot \frac{a1}{\frac{\sqrt[3]{b1}}{\frac{\sqrt[3]{a2}}{\sqrt[3]{b2}}}}\\

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

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0 \lor \neg \left(\frac{a1 \cdot a2}{b1 \cdot b2} \leq 6.2999843586282166 \cdot 10^{+302}\right):\\
\;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\

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

\end{array}
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (if (<= (/ (* a1 a2) (* b1 b2)) -4.217247420283257e+302)
   (*
    (/
     1.0
     (/
      (* (cbrt b1) (cbrt b1))
      (/ (* (cbrt a2) (cbrt a2)) (* (cbrt b2) (cbrt b2)))))
    (/ a1 (/ (cbrt b1) (/ (cbrt a2) (cbrt b2)))))
   (if (<= (/ (* a1 a2) (* b1 b2)) -2.300420913112e-310)
     (/ (* a1 a2) (* b1 b2))
     (if (or (<= (/ (* a1 a2) (* b1 b2)) 0.0)
             (not (<= (/ (* a1 a2) (* b1 b2)) 6.2999843586282166e+302)))
       (* (/ a1 b1) (/ a2 b2))
       (/ (* a1 a2) (/ b1 (/ 1.0 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 (((a1 * a2) / (b1 * b2)) <= -4.217247420283257e+302) {
		tmp = (1.0 / ((cbrt(b1) * cbrt(b1)) / ((cbrt(a2) * cbrt(a2)) / (cbrt(b2) * cbrt(b2))))) * (a1 / (cbrt(b1) / (cbrt(a2) / cbrt(b2))));
	} else if (((a1 * a2) / (b1 * b2)) <= -2.300420913112e-310) {
		tmp = (a1 * a2) / (b1 * b2);
	} else if ((((a1 * a2) / (b1 * b2)) <= 0.0) || !(((a1 * a2) / (b1 * b2)) <= 6.2999843586282166e+302)) {
		tmp = (a1 / b1) * (a2 / b2);
	} else {
		tmp = (a1 * a2) / (b1 / (1.0 / 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.9
Target11.1
Herbie1.8
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.217247420283257e302

    1. Initial program 60.6

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

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

      \[\leadsto \frac{a1}{\color{blue}{\frac{b1}{\frac{a2}{b2}}}}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt_binary6418.5

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

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

      \[\leadsto \frac{a1}{\frac{b1}{\color{blue}{\frac{\sqrt[3]{a2} \cdot \sqrt[3]{a2}}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}} \cdot \frac{\sqrt[3]{a2}}{\sqrt[3]{b2}}}}}\]
    9. Applied add-cube-cbrt_binary6418.7

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

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

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

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

    if -4.217247420283257e302 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.300420913112001e-310

    1. Initial program 0.7

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

    if -2.300420913112001e-310 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0 or 6.2999843586282166e302 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 24.0

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

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

    if 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 6.2999843586282166e302

    1. Initial program 0.8

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

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

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

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

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

      \[\leadsto \frac{a1}{\color{blue}{\frac{1}{a2} \cdot \frac{b1}{\frac{1}{b2}}}}\]
    9. Applied associate-/r*_binary640.9

      \[\leadsto \color{blue}{\frac{\frac{a1}{\frac{1}{a2}}}{\frac{b1}{\frac{1}{b2}}}}\]
    10. Simplified0.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -4.217247420283257 \cdot 10^{+302}:\\ \;\;\;\;\frac{1}{\frac{\sqrt[3]{b1} \cdot \sqrt[3]{b1}}{\frac{\sqrt[3]{a2} \cdot \sqrt[3]{a2}}{\sqrt[3]{b2} \cdot \sqrt[3]{b2}}}} \cdot \frac{a1}{\frac{\sqrt[3]{b1}}{\frac{\sqrt[3]{a2}}{\sqrt[3]{b2}}}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -2.300420913112 \cdot 10^{-310}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0 \lor \neg \left(\frac{a1 \cdot a2}{b1 \cdot b2} \leq 6.2999843586282166 \cdot 10^{+302}\right):\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1 \cdot a2}{\frac{b1}{\frac{1}{b2}}}\\ \end{array}\]

Alternatives

Reproduce

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

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

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