Average Error: 11.0 → 2.9
Time: 19.4s
Precision: 64
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -1.3207011670277236 \cdot 10^{-263}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.35378439927382 \cdot 10^{-267}:\\ \;\;\;\;\frac{\frac{a1}{b1} \cdot a2}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.6301067955831595 \cdot 10^{+297}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\
\;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -1.3207011670277236 \cdot 10^{-263}:\\
\;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.35378439927382 \cdot 10^{-267}:\\
\;\;\;\;\frac{\frac{a1}{b1} \cdot a2}{b2}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.6301067955831595 \cdot 10^{+297}:\\
\;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\

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

\end{array}
double f(double a1, double a2, double b1, double b2) {
        double r5899006 = a1;
        double r5899007 = a2;
        double r5899008 = r5899006 * r5899007;
        double r5899009 = b1;
        double r5899010 = b2;
        double r5899011 = r5899009 * r5899010;
        double r5899012 = r5899008 / r5899011;
        return r5899012;
}

double f(double a1, double a2, double b1, double b2) {
        double r5899013 = a1;
        double r5899014 = a2;
        double r5899015 = r5899013 * r5899014;
        double r5899016 = b1;
        double r5899017 = b2;
        double r5899018 = r5899016 * r5899017;
        double r5899019 = r5899015 / r5899018;
        double r5899020 = -inf.0;
        bool r5899021 = r5899019 <= r5899020;
        double r5899022 = r5899013 / r5899017;
        double r5899023 = r5899016 / r5899014;
        double r5899024 = r5899022 / r5899023;
        double r5899025 = -1.3207011670277236e-263;
        bool r5899026 = r5899019 <= r5899025;
        double r5899027 = 1.35378439927382e-267;
        bool r5899028 = r5899019 <= r5899027;
        double r5899029 = r5899013 / r5899016;
        double r5899030 = r5899029 * r5899014;
        double r5899031 = r5899030 / r5899017;
        double r5899032 = 1.6301067955831595e+297;
        bool r5899033 = r5899019 <= r5899032;
        double r5899034 = r5899033 ? r5899019 : r5899024;
        double r5899035 = r5899028 ? r5899031 : r5899034;
        double r5899036 = r5899026 ? r5899019 : r5899035;
        double r5899037 = r5899021 ? r5899024 : r5899036;
        return r5899037;
}

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.0
Target10.8
Herbie2.9
\[\frac{a1}{b1} \cdot \frac{a2}{b2}\]

Derivation

  1. Split input into 3 regimes
  2. if (/ (* a1 a2) (* b1 b2)) < -inf.0 or 1.6301067955831595e+297 < (/ (* a1 a2) (* b1 b2))

    1. Initial program 59.7

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

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

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

      \[\leadsto \color{blue}{\frac{1}{b2} \cdot \frac{a1 \cdot a2}{b1}}\]
    6. Using strategy rm
    7. Applied associate-/l*14.1

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

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

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

    if -inf.0 < (/ (* a1 a2) (* b1 b2)) < -1.3207011670277236e-263 or 1.35378439927382e-267 < (/ (* a1 a2) (* b1 b2)) < 1.6301067955831595e+297

    1. Initial program 0.7

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

    if -1.3207011670277236e-263 < (/ (* a1 a2) (* b1 b2)) < 1.35378439927382e-267

    1. Initial program 13.1

      \[\frac{a1 \cdot a2}{b1 \cdot b2}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity13.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -1.3207011670277236 \cdot 10^{-263}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.35378439927382 \cdot 10^{-267}:\\ \;\;\;\;\frac{\frac{a1}{b1} \cdot a2}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 1.6301067955831595 \cdot 10^{+297}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b2}}{\frac{b1}{a2}}\\ \end{array}\]

Reproduce

herbie shell --seed 2019158 +o rules:numerics
(FPCore (a1 a2 b1 b2)
  :name "Quotient of products"

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

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