Average Error: 11.0 → 2.8
Time: 3.6s
Precision: binary64
\[ \begin{array}{c}[a1, a2] = \mathsf{sort}([a1, a2])\\ [b1, b2] = \mathsf{sort}([b1, b2])\\ \end{array} \]
\[\frac{a1 \cdot a2}{b1 \cdot b2} \]
\[\begin{array}{l} t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+304}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq -1 \cdot 10^{-284}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 10^{+232}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \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))) (t_1 (* (/ a2 b1) (/ a1 b2))))
   (if (<= t_0 -2e+304)
     t_1
     (if (<= t_0 -1e-284)
       t_0
       (if (<= t_0 0.0)
         t_1
         (if (<= t_0 1e+232) t_0 (/ (/ a1 b1) (/ b2 a2))))))))
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 t_1 = (a2 / b1) * (a1 / b2);
	double tmp;
	if (t_0 <= -2e+304) {
		tmp = t_1;
	} else if (t_0 <= -1e-284) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = t_1;
	} else if (t_0 <= 1e+232) {
		tmp = t_0;
	} else {
		tmp = (a1 / b1) / (b2 / a2);
	}
	return tmp;
}
real(8) function code(a1, a2, b1, b2)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: b1
    real(8), intent (in) :: b2
    code = (a1 * a2) / (b1 * b2)
end function
real(8) function code(a1, a2, b1, b2)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: b1
    real(8), intent (in) :: b2
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (a1 * a2) / (b1 * b2)
    t_1 = (a2 / b1) * (a1 / b2)
    if (t_0 <= (-2d+304)) then
        tmp = t_1
    else if (t_0 <= (-1d-284)) then
        tmp = t_0
    else if (t_0 <= 0.0d0) then
        tmp = t_1
    else if (t_0 <= 1d+232) then
        tmp = t_0
    else
        tmp = (a1 / b1) / (b2 / a2)
    end if
    code = tmp
end function
public static double code(double a1, double a2, double b1, double b2) {
	return (a1 * a2) / (b1 * b2);
}
public static double code(double a1, double a2, double b1, double b2) {
	double t_0 = (a1 * a2) / (b1 * b2);
	double t_1 = (a2 / b1) * (a1 / b2);
	double tmp;
	if (t_0 <= -2e+304) {
		tmp = t_1;
	} else if (t_0 <= -1e-284) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = t_1;
	} else if (t_0 <= 1e+232) {
		tmp = t_0;
	} else {
		tmp = (a1 / b1) / (b2 / a2);
	}
	return tmp;
}
def code(a1, a2, b1, b2):
	return (a1 * a2) / (b1 * b2)
def code(a1, a2, b1, b2):
	t_0 = (a1 * a2) / (b1 * b2)
	t_1 = (a2 / b1) * (a1 / b2)
	tmp = 0
	if t_0 <= -2e+304:
		tmp = t_1
	elif t_0 <= -1e-284:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = t_1
	elif t_0 <= 1e+232:
		tmp = t_0
	else:
		tmp = (a1 / b1) / (b2 / a2)
	return tmp
function code(a1, a2, b1, b2)
	return Float64(Float64(a1 * a2) / Float64(b1 * b2))
end
function code(a1, a2, b1, b2)
	t_0 = Float64(Float64(a1 * a2) / Float64(b1 * b2))
	t_1 = Float64(Float64(a2 / b1) * Float64(a1 / b2))
	tmp = 0.0
	if (t_0 <= -2e+304)
		tmp = t_1;
	elseif (t_0 <= -1e-284)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = t_1;
	elseif (t_0 <= 1e+232)
		tmp = t_0;
	else
		tmp = Float64(Float64(a1 / b1) / Float64(b2 / a2));
	end
	return tmp
end
function tmp = code(a1, a2, b1, b2)
	tmp = (a1 * a2) / (b1 * b2);
end
function tmp_2 = code(a1, a2, b1, b2)
	t_0 = (a1 * a2) / (b1 * b2);
	t_1 = (a2 / b1) * (a1 / b2);
	tmp = 0.0;
	if (t_0 <= -2e+304)
		tmp = t_1;
	elseif (t_0 <= -1e-284)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = t_1;
	elseif (t_0 <= 1e+232)
		tmp = t_0;
	else
		tmp = (a1 / b1) / (b2 / a2);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, b1_, b2_] := N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]
code[a1_, a2_, b1_, b2_] := Block[{t$95$0 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+304], t$95$1, If[LessEqual[t$95$0, -1e-284], t$95$0, If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 1e+232], t$95$0, N[(N[(a1 / b1), $MachinePrecision] / N[(b2 / a2), $MachinePrecision]), $MachinePrecision]]]]]]]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+304}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq -1 \cdot 10^{-284}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_0 \leq 10^{+232}:\\
\;\;\;\;t_0\\

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


\end{array}

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

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.9999999999999999e304 or -1.00000000000000004e-284 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0

    1. Initial program 17.5

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied egg-rr3.8

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

    if -1.9999999999999999e304 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.00000000000000004e-284 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.00000000000000006e232

    1. Initial program 0.7

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied egg-rr16.0

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
    3. Taylor expanded in a1 around 0 0.7

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

    if 1.00000000000000006e232 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 47.1

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Applied egg-rr11.2

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
    3. Applied egg-rr10.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -2 \cdot 10^{+304}:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -1 \cdot 10^{-284}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 10^{+232}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \end{array} \]

Reproduce

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

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

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