Average Error: 11.4 → 2.7
Time: 11.7s
Precision: 64
\[\frac{a1 \cdot a2}{b1 \cdot b2}\]
\[\begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\ \;\;\;\;\frac{a1}{b1 \cdot \frac{b2}{a2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -1.510660628541362523085079504704820761096 \cdot 10^{-304}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 0.0:\\ \;\;\;\;a1 \cdot \frac{\frac{a2}{b1}}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 6.531518740514209178472903159258198398389 \cdot 10^{292}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \end{array}\]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
\mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\
\;\;\;\;\frac{a1}{b1 \cdot \frac{b2}{a2}}\\

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

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 0.0:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b1}}{b2}\\

\mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 6.531518740514209178472903159258198398389 \cdot 10^{292}:\\
\;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\

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

\end{array}
double f(double a1, double a2, double b1, double b2) {
        double r9506654 = a1;
        double r9506655 = a2;
        double r9506656 = r9506654 * r9506655;
        double r9506657 = b1;
        double r9506658 = b2;
        double r9506659 = r9506657 * r9506658;
        double r9506660 = r9506656 / r9506659;
        return r9506660;
}

double f(double a1, double a2, double b1, double b2) {
        double r9506661 = a1;
        double r9506662 = a2;
        double r9506663 = r9506661 * r9506662;
        double r9506664 = b1;
        double r9506665 = b2;
        double r9506666 = r9506664 * r9506665;
        double r9506667 = r9506663 / r9506666;
        double r9506668 = -inf.0;
        bool r9506669 = r9506667 <= r9506668;
        double r9506670 = r9506665 / r9506662;
        double r9506671 = r9506664 * r9506670;
        double r9506672 = r9506661 / r9506671;
        double r9506673 = -1.5106606285413625e-304;
        bool r9506674 = r9506667 <= r9506673;
        double r9506675 = 0.0;
        bool r9506676 = r9506667 <= r9506675;
        double r9506677 = r9506662 / r9506664;
        double r9506678 = r9506677 / r9506665;
        double r9506679 = r9506661 * r9506678;
        double r9506680 = 6.531518740514209e+292;
        bool r9506681 = r9506667 <= r9506680;
        double r9506682 = r9506661 / r9506664;
        double r9506683 = r9506682 / r9506670;
        double r9506684 = r9506681 ? r9506667 : r9506683;
        double r9506685 = r9506676 ? r9506679 : r9506684;
        double r9506686 = r9506674 ? r9506667 : r9506685;
        double r9506687 = r9506669 ? r9506672 : r9506686;
        return r9506687;
}

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

Derivation

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

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity29.8

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

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

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

    if -inf.0 < (/ (* a1 a2) (* b1 b2)) < -1.5106606285413625e-304 or 0.0 < (/ (* a1 a2) (* b1 b2)) < 6.531518740514209e+292

    1. Initial program 0.9

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

    if -1.5106606285413625e-304 < (/ (* a1 a2) (* b1 b2)) < 0.0

    1. Initial program 13.2

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

      \[\leadsto \color{blue}{\frac{\frac{a1 \cdot a2}{b1}}{b2}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity5.9

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

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

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

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

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

    if 6.531518740514209e+292 < (/ (* a1 a2) (* b1 b2))

    1. Initial program 60.7

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

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}}\]
    4. Using strategy rm
    5. Applied *-un-lft-identity45.6

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} = -\infty:\\ \;\;\;\;\frac{a1}{b1 \cdot \frac{b2}{a2}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le -1.510660628541362523085079504704820761096 \cdot 10^{-304}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 0.0:\\ \;\;\;\;a1 \cdot \frac{\frac{a2}{b1}}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \le 6.531518740514209178472903159258198398389 \cdot 10^{292}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \end{array}\]

Reproduce

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

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

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