示例#1
0
    def is_finite(self):
        """
        The Cartesian product is finite if all of its inputs are
        finite, or if any input is empty.

        EXAMPLES::

            sage: from sage.combinat.cartesian_product import CartesianProduct_iters
            sage: CartesianProduct_iters(ZZ, []).is_finite()
            True
            sage: CartesianProduct_iters(4,4).is_finite()
            Traceback (most recent call last):
            ...
            ValueError: Unable to determine whether this product is finite
        """
        finites = [_is_finite(L, fallback=None) for L in self.iters]
        if any(f is None for f in finites):
            raise ValueError(
                "Unable to determine whether this product is finite")
        if all(f is True for f in finites):
            return True
        lens = [_len(L) for L in self.iters]
        if any(l == 0 for l in lens):
            return True
        return False
示例#2
0
    def is_finite(self):
        """
        The cartesian product is finite if all of its inputs are
        finite, or if any input is empty.

        EXAMPLES::

            sage: CartesianProduct(ZZ, []).is_finite()
            True
            sage: CartesianProduct(4,4).is_finite()
            Traceback (most recent call last):
            ...
            ValueError: Unable to determine whether this product is finite
        """
        finites = [_is_finite(L, fallback=None) for L in self.iters]
        if any(f is None for f in finites):
            raise ValueError("Unable to determine whether this product is finite")
        if all(f is True for f in finites):
            return True
        lens = [_len(L) for L in self.iters]
        if any(l == 0 for l in lens):
            return True
        return False