Average Error: 11.2 → 4.2
Time: 6.3s
Precision: binary64
Cost: 1996
\[ \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{a2}{b1} \cdot \frac{a1}{b2}\\ t_1 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{-316}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 10^{-287}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 10^{+290}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (a1 a2 b1 b2) :precision binary64 (/ (* a1 a2) (* b1 b2)))
(FPCore (a1 a2 b1 b2)
 :precision binary64
 (let* ((t_0 (* (/ a2 b1) (/ a1 b2))) (t_1 (/ (* a1 a2) (* b1 b2))))
   (if (<= t_1 -1e-316)
     t_1
     (if (<= t_1 1e-287) t_0 (if (<= t_1 1e+290) t_1 t_0)))))
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 = (a2 / b1) * (a1 / b2);
	double t_1 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_1 <= -1e-316) {
		tmp = t_1;
	} else if (t_1 <= 1e-287) {
		tmp = t_0;
	} else if (t_1 <= 1e+290) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	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 = (a2 / b1) * (a1 / b2)
    t_1 = (a1 * a2) / (b1 * b2)
    if (t_1 <= (-1d-316)) then
        tmp = t_1
    else if (t_1 <= 1d-287) then
        tmp = t_0
    else if (t_1 <= 1d+290) then
        tmp = t_1
    else
        tmp = t_0
    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 = (a2 / b1) * (a1 / b2);
	double t_1 = (a1 * a2) / (b1 * b2);
	double tmp;
	if (t_1 <= -1e-316) {
		tmp = t_1;
	} else if (t_1 <= 1e-287) {
		tmp = t_0;
	} else if (t_1 <= 1e+290) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a1, a2, b1, b2):
	return (a1 * a2) / (b1 * b2)
def code(a1, a2, b1, b2):
	t_0 = (a2 / b1) * (a1 / b2)
	t_1 = (a1 * a2) / (b1 * b2)
	tmp = 0
	if t_1 <= -1e-316:
		tmp = t_1
	elif t_1 <= 1e-287:
		tmp = t_0
	elif t_1 <= 1e+290:
		tmp = t_1
	else:
		tmp = t_0
	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(a2 / b1) * Float64(a1 / b2))
	t_1 = Float64(Float64(a1 * a2) / Float64(b1 * b2))
	tmp = 0.0
	if (t_1 <= -1e-316)
		tmp = t_1;
	elseif (t_1 <= 1e-287)
		tmp = t_0;
	elseif (t_1 <= 1e+290)
		tmp = t_1;
	else
		tmp = t_0;
	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 = (a2 / b1) * (a1 / b2);
	t_1 = (a1 * a2) / (b1 * b2);
	tmp = 0.0;
	if (t_1 <= -1e-316)
		tmp = t_1;
	elseif (t_1 <= 1e-287)
		tmp = t_0;
	elseif (t_1 <= 1e+290)
		tmp = t_1;
	else
		tmp = t_0;
	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[(a2 / b1), $MachinePrecision] * N[(a1 / b2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(a1 * a2), $MachinePrecision] / N[(b1 * b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-316], t$95$1, If[LessEqual[t$95$1, 1e-287], t$95$0, If[LessEqual[t$95$1, 1e+290], t$95$1, t$95$0]]]]]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := \frac{a2}{b1} \cdot \frac{a1}{b2}\\
t_1 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{-316}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;t_1 \leq 10^{-287}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;t_1 \leq 10^{+290}:\\
\;\;\;\;t_1\\

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.2
Target11.3
Herbie4.2
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -9.999999837e-317 or 1.00000000000000002e-287 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.00000000000000006e290

    1. Initial program 4.4

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

    if -9.999999837e-317 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 1.00000000000000002e-287 or 1.00000000000000006e290 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 21.6

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -1 \cdot 10^{-316}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 10^{-287}:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 10^{+290}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b1} \cdot \frac{a1}{b2}\\ \end{array} \]

Alternatives

Alternative 1
Error5.4
Cost1488
\[\begin{array}{l} t_0 := \frac{\frac{a1 \cdot a2}{b1}}{b2}\\ t_1 := \frac{a2}{b1 \cdot \frac{b2}{a1}}\\ \mathbf{if}\;a1 \cdot a2 \leq -5 \cdot 10^{+252}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \mathbf{elif}\;a1 \cdot a2 \leq -2 \cdot 10^{-176}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a1 \cdot a2 \leq 4 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a1 \cdot a2 \leq 10^{+97}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error5.4
Cost1488
\[\begin{array}{l} t_0 := \frac{\frac{a1 \cdot a2}{b1}}{b2}\\ t_1 := \frac{a2}{b1 \cdot \frac{b2}{a1}}\\ \mathbf{if}\;a1 \cdot a2 \leq -5 \cdot 10^{+252}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{elif}\;a1 \cdot a2 \leq -2 \cdot 10^{-176}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a1 \cdot a2 \leq 4 \cdot 10^{-260}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a1 \cdot a2 \leq 10^{+97}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error6.3
Cost1488
\[\begin{array}{l} t_0 := \frac{\frac{a1 \cdot a2}{b1}}{b2}\\ \mathbf{if}\;a1 \cdot a2 \leq -5 \cdot 10^{+252}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \mathbf{elif}\;a1 \cdot a2 \leq -2 \cdot 10^{-176}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a1 \cdot a2 \leq 4 \cdot 10^{-260}:\\ \;\;\;\;\frac{a2}{b1 \cdot \frac{b2}{a1}}\\ \mathbf{elif}\;a1 \cdot a2 \leq 4 \cdot 10^{+49}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \end{array} \]
Alternative 4
Error11.4
Cost844
\[\begin{array}{l} t_0 := \frac{a2}{b1 \cdot \frac{b2}{a1}}\\ t_1 := \frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \mathbf{if}\;b1 \leq -1.7234188384996582 \cdot 10^{+170}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b1 \leq -1 \cdot 10^{-70}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \leq 10^{-280}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error11.1
Cost844
\[\begin{array}{l} t_0 := \frac{a2}{b1 \cdot \frac{b2}{a1}}\\ \mathbf{if}\;a2 \leq -4.209175595830735 \cdot 10^{-243}:\\ \;\;\;\;\frac{a1}{\frac{b1}{\frac{a2}{b2}}}\\ \mathbf{elif}\;a2 \leq -2.2672867582817987 \cdot 10^{-290}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a2 \leq 5 \cdot 10^{+174}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Error11.0
Cost844
\[\begin{array}{l} \mathbf{if}\;a2 \leq -1.851104037340607 \cdot 10^{-168}:\\ \;\;\;\;\frac{a1}{\frac{b1}{\frac{a2}{b2}}}\\ \mathbf{elif}\;a2 \leq 6.631492490106206 \cdot 10^{-296}:\\ \;\;\;\;\frac{a1 \cdot \frac{a2}{b1}}{b2}\\ \mathbf{elif}\;a2 \leq 5 \cdot 10^{+174}:\\ \;\;\;\;\frac{\frac{a1}{b1}}{\frac{b2}{a2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b1 \cdot \frac{b2}{a1}}\\ \end{array} \]
Alternative 7
Error11.7
Cost448
\[\frac{a2}{b1 \cdot \frac{b2}{a1}} \]

Error

Reproduce

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

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

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