Average Error: 11.4 → 2.7
Time: 12.4s
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 r8550339 = a1;
        double r8550340 = a2;
        double r8550341 = r8550339 * r8550340;
        double r8550342 = b1;
        double r8550343 = b2;
        double r8550344 = r8550342 * r8550343;
        double r8550345 = r8550341 / r8550344;
        return r8550345;
}

double f(double a1, double a2, double b1, double b2) {
        double r8550346 = a1;
        double r8550347 = a2;
        double r8550348 = r8550346 * r8550347;
        double r8550349 = b1;
        double r8550350 = b2;
        double r8550351 = r8550349 * r8550350;
        double r8550352 = r8550348 / r8550351;
        double r8550353 = -inf.0;
        bool r8550354 = r8550352 <= r8550353;
        double r8550355 = r8550350 / r8550347;
        double r8550356 = r8550349 * r8550355;
        double r8550357 = r8550346 / r8550356;
        double r8550358 = -1.5106606285413625e-304;
        bool r8550359 = r8550352 <= r8550358;
        double r8550360 = 0.0;
        bool r8550361 = r8550352 <= r8550360;
        double r8550362 = r8550347 / r8550349;
        double r8550363 = r8550362 / r8550350;
        double r8550364 = r8550346 * r8550363;
        double r8550365 = 6.531518740514209e+292;
        bool r8550366 = r8550352 <= r8550365;
        double r8550367 = r8550346 / r8550349;
        double r8550368 = r8550367 / r8550355;
        double r8550369 = r8550366 ? r8550352 : r8550368;
        double r8550370 = r8550361 ? r8550364 : r8550369;
        double r8550371 = r8550359 ? r8550352 : r8550370;
        double r8550372 = r8550354 ? r8550357 : r8550371;
        return r8550372;
}

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 +o rules:numerics
(FPCore (a1 a2 b1 b2)
  :name "Quotient of products"

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

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