Average Error: 11.5 → 3.0
Time: 3.5s
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}\\ \mathbf{if}\;t_0 \leq -1 \cdot 10^{+304}:\\ \;\;\;\;\frac{a2}{b2 \cdot \frac{b1}{a1}}\\ \mathbf{elif}\;t_0 \leq -5 \cdot 10^{-267}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+294}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{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 -1e+304)
     (/ a2 (* b2 (/ b1 a1)))
     (if (<= t_0 -5e-267)
       t_0
       (if (<= t_0 0.0)
         (* a1 (/ (/ a2 b2) b1))
         (if (<= t_0 5e+294) t_0 (* (/ a2 b2) (/ a1 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 <= -1e+304) {
		tmp = a2 / (b2 * (b1 / a1));
	} else if (t_0 <= -5e-267) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = a1 * ((a2 / b2) / b1);
	} else if (t_0 <= 5e+294) {
		tmp = t_0;
	} else {
		tmp = (a2 / b2) * (a1 / b1);
	}
	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) :: tmp
    t_0 = (a1 * a2) / (b1 * b2)
    if (t_0 <= (-1d+304)) then
        tmp = a2 / (b2 * (b1 / a1))
    else if (t_0 <= (-5d-267)) then
        tmp = t_0
    else if (t_0 <= 0.0d0) then
        tmp = a1 * ((a2 / b2) / b1)
    else if (t_0 <= 5d+294) then
        tmp = t_0
    else
        tmp = (a2 / b2) * (a1 / b1)
    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 tmp;
	if (t_0 <= -1e+304) {
		tmp = a2 / (b2 * (b1 / a1));
	} else if (t_0 <= -5e-267) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = a1 * ((a2 / b2) / b1);
	} else if (t_0 <= 5e+294) {
		tmp = t_0;
	} else {
		tmp = (a2 / b2) * (a1 / b1);
	}
	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)
	tmp = 0
	if t_0 <= -1e+304:
		tmp = a2 / (b2 * (b1 / a1))
	elif t_0 <= -5e-267:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = a1 * ((a2 / b2) / b1)
	elif t_0 <= 5e+294:
		tmp = t_0
	else:
		tmp = (a2 / b2) * (a1 / b1)
	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))
	tmp = 0.0
	if (t_0 <= -1e+304)
		tmp = Float64(a2 / Float64(b2 * Float64(b1 / a1)));
	elseif (t_0 <= -5e-267)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = Float64(a1 * Float64(Float64(a2 / b2) / b1));
	elseif (t_0 <= 5e+294)
		tmp = t_0;
	else
		tmp = Float64(Float64(a2 / b2) * Float64(a1 / b1));
	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);
	tmp = 0.0;
	if (t_0 <= -1e+304)
		tmp = a2 / (b2 * (b1 / a1));
	elseif (t_0 <= -5e-267)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = a1 * ((a2 / b2) / b1);
	elseif (t_0 <= 5e+294)
		tmp = t_0;
	else
		tmp = (a2 / b2) * (a1 / b1);
	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]}, If[LessEqual[t$95$0, -1e+304], N[(a2 / N[(b2 * N[(b1 / a1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, -5e-267], t$95$0, If[LessEqual[t$95$0, 0.0], N[(a1 * N[(N[(a2 / b2), $MachinePrecision] / b1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+294], t$95$0, N[(N[(a2 / b2), $MachinePrecision] * N[(a1 / b1), $MachinePrecision]), $MachinePrecision]]]]]]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
\mathbf{if}\;t_0 \leq -1 \cdot 10^{+304}:\\
\;\;\;\;\frac{a2}{b2 \cdot \frac{b1}{a1}}\\

\mathbf{elif}\;t_0 \leq -5 \cdot 10^{-267}:\\
\;\;\;\;t_0\\

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

\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+294}:\\
\;\;\;\;t_0\\

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


\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.5
Target11.4
Herbie3.0
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation

  1. Split input into 4 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -9.9999999999999994e303

    1. Initial program 62.2

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Simplified32.8

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

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

      \[\leadsto \color{blue}{\frac{a1 \cdot a2}{b2 \cdot b1}} \]
    5. Simplified16.2

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

    if -9.9999999999999994e303 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -4.9999999999999999e-267 or 0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 4.9999999999999999e294

    1. Initial program 0.7

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Simplified8.1

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

      \[\leadsto a1 \cdot \color{blue}{\left(\frac{a2}{b1} \cdot \frac{1}{b2}\right)} \]
    4. Applied egg-rr0.7

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

    if -4.9999999999999999e-267 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 0.0

    1. Initial program 13.4

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Simplified7.8

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

      \[\leadsto a1 \cdot \color{blue}{\left(\frac{a2}{b1} \cdot \frac{1}{b2}\right)} \]
    4. Applied egg-rr4.6

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

    if 4.9999999999999999e294 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 60.0

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Simplified44.0

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

      \[\leadsto \color{blue}{\frac{1}{\frac{b1 \cdot b2}{a1 \cdot a2}}} \]
    4. Applied egg-rr7.1

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -1 \cdot 10^{+304}:\\ \;\;\;\;\frac{a2}{b2 \cdot \frac{b1}{a1}}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -5 \cdot 10^{-267}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;a1 \cdot \frac{\frac{a2}{b2}}{b1}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 5 \cdot 10^{+294}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{b2} \cdot \frac{a1}{b1}\\ \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)))