Fix cartesianProduct: default order should be lexicographically sorted (issue 9878)

The problem was that the default order was reverse-lexicographic, because of the order of static if in handling the case where one of the inputs may be infinite. Swapping the order of the static ifs produces the nicer ordering when both ranges are finite.