Average Error: 11.7 → 2.3
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:\\ \;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\ \mathbf{elif}\;t_0 \leq -2.358156 \cdot 10^{-318}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{elif}\;t_0 \leq 7.21919068566089 \cdot 10^{+306}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(a1 \cdot \frac{1}{b2}\right) \cdot \frac{a2}{b1}\\ \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:\\
\;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\

\mathbf{elif}\;t_0 \leq -2.358156 \cdot 10^{-318}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;t_0 \leq 7.21919068566089 \cdot 10^{+306}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;\left(a1 \cdot \frac{1}{b2}\right) \cdot \frac{a2}{b1}\\


\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))
     (* a1 (/ (/ a2 b2) b1))
     (if (<= t_0 -2.358156e-318)
       t_0
       (if (<= t_0 0.0)
         (* (/ a2 b2) (/ a1 b1))
         (if (<= t_0 7.21919068566089e+306)
           t_0
           (* (* a1 (/ 1.0 b2)) (/ a2 b1))))))))
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 = a1 * ((a2 / b2) / b1);
	} else if (t_0 <= -2.358156e-318) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = (a2 / b2) * (a1 / b1);
	} else if (t_0 <= 7.21919068566089e+306) {
		tmp = t_0;
	} else {
		tmp = (a1 * (1.0 / b2)) * (a2 / b1);
	}
	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.7
Target11.1
Herbie2.3
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation

  1. Split input into 4 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-/l*_binary6432.6

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
    3. Applied div-inv_binary6432.6

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

      \[\leadsto a1 \cdot \color{blue}{\frac{a2}{b2 \cdot b1}} \]
    5. Applied associate-/r*_binary6417.6

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

    if -inf.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.35816e-318 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 7.21919068566088994e306

    1. Initial program 0.8

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

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

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

      \[\leadsto a1 \cdot \color{blue}{\frac{a2}{b2 \cdot b1}} \]
    5. Applied pow1_binary648.1

      \[\leadsto a1 \cdot \color{blue}{{\left(\frac{a2}{b2 \cdot b1}\right)}^{1}} \]
    6. Applied pow1_binary648.1

      \[\leadsto \color{blue}{{a1}^{1}} \cdot {\left(\frac{a2}{b2 \cdot b1}\right)}^{1} \]
    7. Applied pow-prod-down_binary648.1

      \[\leadsto \color{blue}{{\left(a1 \cdot \frac{a2}{b2 \cdot b1}\right)}^{1}} \]
    8. Simplified0.8

      \[\leadsto {\color{blue}{\left(\frac{a1 \cdot a2}{b2 \cdot b1}\right)}}^{1} \]

    if -2.35816e-318 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0

    1. Initial program 14.5

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

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

    if 7.21919068566088994e306 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 63.9

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied associate-/l*_binary6446.6

      \[\leadsto \color{blue}{\frac{a1}{\frac{b1 \cdot b2}{a2}}} \]
    3. Applied div-inv_binary6446.7

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -\infty:\\ \;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -2.358156 \cdot 10^{-318}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 7.21919068566089 \cdot 10^{+306}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\left(a1 \cdot \frac{1}{b2}\right) \cdot \frac{a2}{b1}\\ \end{array} \]

Reproduce

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

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

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