Average Error: 11.6 → 2.7
Time: 4.1s
Precision: binary64
Cost: 2512
\[ \begin{array}{c}[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{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{if}\;t_0 \leq -2 \cdot 10^{+250}:\\ \;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\ \mathbf{elif}\;t_0 \leq -2 \cdot 10^{-312}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_0 \leq 0:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_0 \leq 5 \cdot 10^{+298}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \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 (* (/ a1 b1) (/ a2 b2))))
   (if (<= t_0 -2e+250)
     (/ (* a2 (/ a1 b1)) b2)
     (if (<= t_0 -2e-312)
       t_0
       (if (<= t_0 0.0) t_1 (if (<= t_0 5e+298) t_0 t_1))))))
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 = (a1 / b1) * (a2 / b2);
	double tmp;
	if (t_0 <= -2e+250) {
		tmp = (a2 * (a1 / b1)) / b2;
	} else if (t_0 <= -2e-312) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = t_1;
	} else if (t_0 <= 5e+298) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 = (a1 / b1) * (a2 / b2)
    if (t_0 <= (-2d+250)) then
        tmp = (a2 * (a1 / b1)) / b2
    else if (t_0 <= (-2d-312)) then
        tmp = t_0
    else if (t_0 <= 0.0d0) then
        tmp = t_1
    else if (t_0 <= 5d+298) then
        tmp = t_0
    else
        tmp = t_1
    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 = (a1 / b1) * (a2 / b2);
	double tmp;
	if (t_0 <= -2e+250) {
		tmp = (a2 * (a1 / b1)) / b2;
	} else if (t_0 <= -2e-312) {
		tmp = t_0;
	} else if (t_0 <= 0.0) {
		tmp = t_1;
	} else if (t_0 <= 5e+298) {
		tmp = t_0;
	} else {
		tmp = t_1;
	}
	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 = (a1 / b1) * (a2 / b2)
	tmp = 0
	if t_0 <= -2e+250:
		tmp = (a2 * (a1 / b1)) / b2
	elif t_0 <= -2e-312:
		tmp = t_0
	elif t_0 <= 0.0:
		tmp = t_1
	elif t_0 <= 5e+298:
		tmp = t_0
	else:
		tmp = t_1
	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(a1 / b1) * Float64(a2 / b2))
	tmp = 0.0
	if (t_0 <= -2e+250)
		tmp = Float64(Float64(a2 * Float64(a1 / b1)) / b2);
	elseif (t_0 <= -2e-312)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = t_1;
	elseif (t_0 <= 5e+298)
		tmp = t_0;
	else
		tmp = t_1;
	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 = (a1 / b1) * (a2 / b2);
	tmp = 0.0;
	if (t_0 <= -2e+250)
		tmp = (a2 * (a1 / b1)) / b2;
	elseif (t_0 <= -2e-312)
		tmp = t_0;
	elseif (t_0 <= 0.0)
		tmp = t_1;
	elseif (t_0 <= 5e+298)
		tmp = t_0;
	else
		tmp = t_1;
	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[(a1 / b1), $MachinePrecision] * N[(a2 / b2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+250], N[(N[(a2 * N[(a1 / b1), $MachinePrecision]), $MachinePrecision] / b2), $MachinePrecision], If[LessEqual[t$95$0, -2e-312], t$95$0, If[LessEqual[t$95$0, 0.0], t$95$1, If[LessEqual[t$95$0, 5e+298], t$95$0, t$95$1]]]]]]
\frac{a1 \cdot a2}{b1 \cdot b2}
\begin{array}{l}
t_0 := \frac{a1 \cdot a2}{b1 \cdot b2}\\
t_1 := \frac{a1}{b1} \cdot \frac{a2}{b2}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+250}:\\
\;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\

\mathbf{elif}\;t_0 \leq -2 \cdot 10^{-312}:\\
\;\;\;\;t_0\\

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

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

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original11.6
Target11.1
Herbie2.7
\[\frac{a1}{b1} \cdot \frac{a2}{b2} \]

Derivation

  1. Split input into 3 regimes
  2. if (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -1.9999999999999998e250

    1. Initial program 42.6

      \[\frac{a1 \cdot a2}{b1 \cdot b2} \]
    2. Simplified26.4

      \[\leadsto \color{blue}{a2 \cdot \frac{a1}{b1 \cdot b2}} \]
      Proof
      (*.f64 a2 (/.f64 a1 (*.f64 b1 b2))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (/.f64 a1 (*.f64 b1 b2)) a2)): 0 points increase in error, 0 points decrease in error
      (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))): 49 points increase in error, 42 points decrease in error
    3. Applied egg-rr19.2

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

    if -1.9999999999999998e250 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -2.0000000000019e-312 or -0.0 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < 5.0000000000000003e298

    1. Initial program 0.8

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

    if -2.0000000000019e-312 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2)) < -0.0 or 5.0000000000000003e298 < (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))

    1. Initial program 22.6

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

      \[\leadsto \color{blue}{\frac{a1}{b1} \cdot \frac{a2}{b2}} \]
      Proof
      (*.f64 (/.f64 a1 b1) (/.f64 a2 b2)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= times-frac_binary64 (/.f64 (*.f64 a1 a2) (*.f64 b1 b2))): 62 points increase in error, 69 points decrease in error
  3. Recombined 3 regimes into one program.
  4. Final simplification2.7

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -2 \cdot 10^{+250}:\\ \;\;\;\;\frac{a2 \cdot \frac{a1}{b1}}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq -2 \cdot 10^{-312}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 0:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{elif}\;\frac{a1 \cdot a2}{b1 \cdot b2} \leq 5 \cdot 10^{+298}:\\ \;\;\;\;\frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \end{array} \]

Alternatives

Alternative 1
Error3.9
Cost1996
\[\begin{array}{l} t_0 := \frac{a1}{b1} \cdot \frac{a2}{b2}\\ t_1 := \frac{a1 \cdot a2}{b1 \cdot b2}\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{-312}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_1 \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;t_1 \leq 5 \cdot 10^{+298}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error8.3
Cost1228
\[\begin{array}{l} t_0 := a1 \cdot \frac{a2}{b1 \cdot b2}\\ t_1 := a1 \cdot \frac{\frac{a2}{b2}}{b1}\\ \mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+184}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b1 \cdot b2 \leq -1 \cdot 10^{-140}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{-200}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error8.1
Cost1228
\[\begin{array}{l} t_0 := a1 \cdot \frac{\frac{a2}{b2}}{b1}\\ \mathbf{if}\;b1 \cdot b2 \leq -5 \cdot 10^{+187}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq -5 \cdot 10^{-267}:\\ \;\;\;\;a2 \cdot \frac{a1}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 2 \cdot 10^{-200}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \end{array} \]
Alternative 4
Error6.7
Cost1228
\[\begin{array}{l} t_0 := a1 \cdot \frac{a2}{b1 \cdot b2}\\ t_1 := \frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+267}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-191}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-264}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 5
Error6.7
Cost1228
\[\begin{array}{l} t_0 := \frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+267}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-191}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-264}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{\frac{b1 \cdot b2}{a2}}\\ \end{array} \]
Alternative 6
Error7.3
Cost1228
\[\begin{array}{l} \mathbf{if}\;b1 \cdot b2 \leq -1 \cdot 10^{+300}:\\ \;\;\;\;\frac{a2}{\frac{b1}{\frac{a1}{b2}}}\\ \mathbf{elif}\;b1 \cdot b2 \leq -2 \cdot 10^{-191}:\\ \;\;\;\;a1 \cdot \frac{a2}{b1 \cdot b2}\\ \mathbf{elif}\;b1 \cdot b2 \leq 5 \cdot 10^{-264}:\\ \;\;\;\;\frac{a1}{b1} \cdot \frac{a2}{b2}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{\frac{b1 \cdot b2}{a2}}\\ \end{array} \]
Alternative 7
Error11.3
Cost448
\[a1 \cdot \frac{a2}{b1 \cdot b2} \]

Error

Reproduce

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

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

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