diff --git a/src/sage/combinat/posets/poset_examples.py b/src/sage/combinat/posets/poset_examples.py index 1ac6d8ed409..899fbaeb49c 100644 --- a/src/sage/combinat/posets/poset_examples.py +++ b/src/sage/combinat/posets/poset_examples.py @@ -74,6 +74,12 @@ def __classcall__(cls, n = None): """ if n is None: return sage.categories.posets.Posets() + try: + n = Integer(n) + except TypeError: + raise TypeError("Number of elements must be an integer, not {0}.".format(n)) + if n < 0: + raise ValueError("Number of elements must be non-negative, not {0}.".format(n)) return FinitePosets_n(n) @staticmethod @@ -86,6 +92,16 @@ def BooleanLattice(n): sage: Posets.BooleanLattice(5) Finite lattice containing 32 elements """ + try: + n = Integer(n) + except TypeError: + raise TypeError("Number of elements must be an integer, not {0}.".format(n)) + if n < 0: + raise ValueError("Number of elements must be non-negative, not {0}.".format(n)) + if n==0: + return LatticePoset( ([0], []) ) + if n==1: + return LatticePoset( ([0,1], [[0,1]]) ) return LatticePoset([[Integer(x|(1<