def __init__(self): r""" TESTS:: sage: NN = NonNegativeIntegerSemiring(); NN Non negative integer semiring sage: NN.category() Join of Category of semirings and Category of commutative monoids and Category of infinite enumerated sets and Category of facade sets sage: TestSuite(NN).run() """ NonNegativeIntegers.__init__(self, category=(Semirings().Commutative(), InfiniteEnumeratedSets()) )
def __init__(self): r""" TESTS:: sage: NN = NonNegativeIntegerSemiring(); NN Non negative integer semiring sage: NN.category() Join of Category of semirings and Category of infinite enumerated sets and Category of facade sets sage: TestSuite(NN).run() """ NonNegativeIntegers.__init__(self, category=(Semirings(), InfiniteEnumeratedSets()) )
def __init__(self): """ TESTS:: sage: from sage.combinat.ordered_tree import OrderedTrees_all sage: B = OrderedTrees_all() sage: B.cardinality() +Infinity sage: it = iter(B) sage: (next(it), next(it), next(it), next(it), next(it)) ([], [[]], [[], []], [[[]]], [[], [], []]) sage: next(it).parent() Ordered trees sage: B([]) [] sage: B is OrderedTrees_all() True sage: TestSuite(B).run() # long time """ DisjointUnionEnumeratedSets.__init__(self, Family(NonNegativeIntegers(), OrderedTrees_size), facade=True, keepkey=False)
def __init__(self, enumset): """ EXAMPLES:: sage: from sage.sets.family import EnumeratedFamily sage: f = EnumeratedFamily(Permutations(3)) sage: TestSuite(f).run() sage: f = Family(NonNegativeIntegers()) sage: TestSuite(f).run() TESTS: Check that category and keys are set correctly (:trac:`28274`):: sage: from sage.sets.family import EnumeratedFamily sage: f = EnumeratedFamily(Permutations(4)) sage: f.category() Category of finite enumerated sets sage: list(f.keys()) == list(range(f.cardinality())) True sage: Family(Permutations()).keys() Non negative integers """ if enumset.cardinality() == Infinity: baseset = NonNegativeIntegers() else: baseset = range(enumset.cardinality()) LazyFamily.__init__(self, baseset, enumset.unrank) self.enumset = enumset
def __init__(self,R, index_set=None, central_elements=None, category=None, element_class=None, prefix=None, **kwds): """ Initialize self. TESTS:: sage: V = lie_conformal_algebras.Virasoro(QQ) sage: TestSuite(V).run() """ self._generators = Family(index_set) E = cartesian_product([index_set, NonNegativeIntegers()]) if central_elements is not None: self._generators = DisjointUnionEnumeratedSets([index_set, Family(central_elements)]) E = DisjointUnionEnumeratedSets((cartesian_product([ Family(central_elements), {Integer(0)}]),E)) super(FreelyGeneratedLieConformalAlgebra,self).__init__(R, basis_keys=E, element_class=element_class, category=category, prefix=prefix, **kwds) if central_elements is not None: self._central_elements = Family(central_elements) else: self._central_elements = tuple()
def __init__(self, **keywords): DisjointUnionEnumeratedSets.__init__( self, Family(NonNegativeIntegers(), lambda i: Relations_size(i, **keywords)), facade=True, keepkey=False, category=(Posets(), EnumeratedSets())) self._sign = None self._initialise_properties(keywords)
def grading_set(self): """ Return the set ``self`` is graded by. By default, this is the set of non-negative integers. EXAMPLES:: sage: SetsWithGrading().example().grading_set() Non negative integers """ return NonNegativeIntegers()
def __init__(self, base_ring): """ EXAMPLES:: sage: H = GradedHopfAlgebrasWithBasis(QQ).Connected().example() sage: TestSuite(H).run() """ CombinatorialFreeModule.__init__( self, base_ring, NonNegativeIntegers(), category=GradedHopfAlgebrasWithBasis(base_ring).Connected())
def __init__(self, max_entry=None): r""" Initialize ``self``. TESTS:: sage: CT = CompositionTableaux() sage: TestSuite(CT).run() """ self.max_entry = max_entry CT_n = lambda n: CompositionTableaux_size(n, max_entry) DisjointUnionEnumeratedSets.__init__(self, Family(NonNegativeIntegers(), CT_n), facade=True, keepkey = False)
def __init__(self): """ TESTS:: sage: sum(x**len(t) for t in ....: set(RootedTree(t) for t in OrderedTrees(6))) x^5 + x^4 + 3*x^3 + 6*x^2 + 9*x sage: sum(x**len(t) for t in RootedTrees(6)) x^5 + x^4 + 3*x^3 + 6*x^2 + 9*x sage: TestSuite(RootedTrees()).run() # long time """ DisjointUnionEnumeratedSets.__init__( self, Family(NonNegativeIntegers(), RootedTrees_size), facade=True, keepkey=False)
def __init__(self, n=None): r""" EXAMPLES:: sage: from sage.combinat.baxter_permutations import BaxterPermutations_all sage: BaxterPermutations_all() Baxter permutations """ self.element_class = Permutations().element_class from sage.sets.non_negative_integers import NonNegativeIntegers from sage.sets.family import Family DisjointUnionEnumeratedSets.__init__(self, Family(NonNegativeIntegers(), BaxterPermutations_size), facade=False, keepkey=False)
def __init__(self): r""" Initializes the class of all standard super tableaux. TESTS:: sage: from sage.combinat.super_tableau import StandardSuperTableaux_all sage: SST = StandardSuperTableaux_all(); SST Standard super tableaux sage: TestSuite(SST).run() """ StandardSuperTableaux.__init__(self) DisjointUnionEnumeratedSets.__init__(self, Family(NonNegativeIntegers(), StandardSuperTableaux_size), facade=True, keepkey=False)
def __init__(self, R, g): r""" Initialize ``self``. EXAMPLES:: sage: L = lie_algebras.SymplecticDerivation(QQ, 5) sage: TestSuite(L).run() """ if g < 4: raise ValueError("g must be at least 4") cat = LieAlgebras(R).WithBasis().Graded() self._g = g d = Family(NonNegativeIntegers(), lambda n: Partitions(n, min_length=2, max_part=2*g)) indices = DisjointUnionEnumeratedSets(d) InfinitelyGeneratedLieAlgebra.__init__(self, R, index_set=indices, category=cat) IndexedGenerators.__init__(self, indices, sorting_key=self._basis_key)
def __init__(self, R, q): r""" Initialize ``self``. EXAMPLES:: sage: AW = algebras.AskeyWilson(QQ) sage: TestSuite(AW).run() # long time """ self._q = q cat = Algebras(Rings().Commutative()).WithBasis() indices = cartesian_product([NonNegativeIntegers()]*6) CombinatorialFreeModule.__init__(self, R, indices, prefix='AW', sorting_key=_basis_key, sorting_reverse=True, category=cat) self._assign_names('A,B,C,a,b,g')
def basis(self): """ Return a basis of ``self``. EXAMPLES:: sage: W.<x,y> = DifferentialWeylAlgebra(QQ) sage: B = W.basis() sage: it = iter(B) sage: [it.next() for i in range(20)] [1, x, y, dx, dy, x^2, x*y, x*dx, x*dy, y^2, y*dx, y*dy, dx^2, dx*dy, dy^2, x^3, x^2*y, x^2*dx, x^2*dy, x*y^2] """ n = self._n I = IntegerListsLex(NonNegativeIntegers(), length=n * 2) one = self.base_ring().one() f = lambda x: self.element_class(self, { (tuple(x[:n]), tuple(x[n:])): one }) return Family(I, f, name="basis map")
def __init__(self): """ TESTS:: sage: from sage.combinat.binary_tree import BinaryTrees_all sage: B = BinaryTrees_all() sage: B.cardinality() +Infinity sage: it = iter(B) sage: (it.next(), it.next(), it.next(), it.next(), it.next()) (., [., .], [., [., .]], [[., .], .], [., [., [., .]]]) sage: it.next().parent() Binary trees sage: B([]) [., .] sage: B is BinaryTrees_all() True sage: TestSuite(B).run() """ DisjointUnionEnumeratedSets.__init__( self, Family(NonNegativeIntegers(), BinaryTrees_size), facade=True, keepkey = False)
def build_alphabet(data=None, names=None, name=None): r""" Return an object representing an ordered alphabet. INPUT: - ``data`` -- the letters of the alphabet; it can be: * a list/tuple/iterable of letters; the iterable may be infinite * an integer `n` to represent `\{1, \ldots, n\}`, or infinity to represent `\NN` - ``names`` -- (optional) a list for the letters (i.e. variable names) or a string for prefix for all letters; if given a list, it must have the same cardinality as the set represented by ``data`` - ``name`` -- (optional) if given, then return a named set and can be equal to : ``'lower', 'upper', 'space', 'underscore', 'punctuation', 'printable', 'binary', 'octal', 'decimal', 'hexadecimal', 'radix64'``. You can use many of them at once, separated by spaces : ``'lower punctuation'`` represents the union of the two alphabets ``'lower'`` and ``'punctuation'``. Alternatively, ``name`` can be set to ``"positive integers"`` (or ``"PP"``) or ``"natural numbers"`` (or ``"NN"``). ``name`` cannot be combined with ``data``. EXAMPLES: If the argument is a Set, it just returns it:: sage: build_alphabet(ZZ) is ZZ True sage: F = FiniteEnumeratedSet('abc') sage: build_alphabet(F) is F True If a list, tuple or string is provided, then it builds a proper Sage class (:class:`~sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet`):: sage: build_alphabet([0,1,2]) {0, 1, 2} sage: F = build_alphabet('abc'); F {'a', 'b', 'c'} sage: print(type(F).__name__) TotallyOrderedFiniteSet_with_category If an integer and a set is given, then it constructs a :class:`~sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet`:: sage: build_alphabet(3, ['a','b','c']) {'a', 'b', 'c'} If an integer and a string is given, then it considers that string as a prefix:: sage: build_alphabet(3, 'x') {'x0', 'x1', 'x2'} If no data is provided, ``name`` may be a string which describe an alphabet. The available names decompose into two families. The first one are 'positive integers', 'PP', 'natural numbers' or 'NN' which refer to standard set of numbers:: sage: build_alphabet(name="positive integers") Positive integers sage: build_alphabet(name="PP") Positive integers sage: build_alphabet(name="natural numbers") Non negative integers sage: build_alphabet(name="NN") Non negative integers The other families for the option ``name`` are among 'lower', 'upper', 'space', 'underscore', 'punctuation', 'printable', 'binary', 'octal', 'decimal', 'hexadecimal', 'radix64' which refer to standard set of charaters. Theses names may be combined by separating them by a space:: sage: build_alphabet(name="lower") {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'} sage: build_alphabet(name="hexadecimal") {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'} sage: build_alphabet(name="decimal punctuation") {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', ',', '.', ';', ':', '!', '?'} In the case the alphabet is built from a list or a tuple, the order on the alphabet is given by the elements themselves:: sage: A = build_alphabet([0,2,1]) sage: A(0) < A(2) True sage: A(2) < A(1) False If a different order is needed, you may use :class:`~sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet` and set the option ``facade`` to ``False``. That way, the comparison fits the order of the input:: sage: A = TotallyOrderedFiniteSet([4,2,6,1], facade=False) sage: A(4) < A(2) True sage: A(1) < A(6) False Be careful, the element of the set in the last example are no more integers and do not compare equal with integers:: sage: type(A.an_element()) <class 'sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet_with_category.element_class'> sage: A(1) == 1 False sage: 1 == A(1) False We give an example of an infinite alphabet indexed by the positive integers and the prime numbers:: sage: build_alphabet(oo, 'x') Lazy family (x(i))_{i in Non negative integers} sage: build_alphabet(Primes(), 'y') Lazy family (y(i))_{i in Set of all prime numbers: 2, 3, 5, 7, ...} TESTS:: sage: Alphabet(3, name="punctuation") Traceback (most recent call last): ... ValueError: name cannot be specified with any other argument sage: Alphabet(8, ['e']*10) Traceback (most recent call last): ... ValueError: invalid value for names sage: Alphabet(8, x) Traceback (most recent call last): ... ValueError: invalid value for names sage: Alphabet(name=x, names="punctuation") Traceback (most recent call last): ... ValueError: name cannot be specified with any other argument sage: Alphabet(x) Traceback (most recent call last): ... ValueError: unable to construct an alphabet from the given parameters """ # If both 'names' and 'data' are defined if name is not None and (data is not None or names is not None): raise ValueError("name cannot be specified with any other argument") # Swap arguments if we need to to try and make sure we have "good" user input if isinstance(names, integer_types + (Integer,)) or names == Infinity \ or (data is None and names is not None): data,names = names,data # data is an integer if isinstance(data, integer_types + (Integer,)): if names is None: from sage.sets.integer_range import IntegerRange return IntegerRange(Integer(data)) if isinstance(names, str): return TotallyOrderedFiniteSet([names + '%d'%i for i in range(data)]) if len(names) == data: return TotallyOrderedFiniteSet(names) raise ValueError("invalid value for names") if data == Infinity: data = NonNegativeIntegers() # data is an iterable if isinstance(data, (tuple, list, str, range)) or data in Sets(): if names is not None: if not isinstance(names, str): raise TypeError("names must be a string when data is a set") return Family(data, lambda i: names + str(i), name=names) if data in Sets(): return data return TotallyOrderedFiniteSet(data) # Alphabet defined from a name if name is not None: if not isinstance(name, str): raise TypeError("name must be a string") if name == "positive integers" or name == "PP": from sage.sets.positive_integers import PositiveIntegers return PositiveIntegers() if name == "natural numbers" or name == "NN": return NonNegativeIntegers() data = [] for alpha_name in name.split(' '): try: data.extend(list(set_of_letters[alpha_name])) except KeyError: raise TypeError("name is not recognized") return TotallyOrderedFiniteSet(data) # Alphabet(**nothing**) if data is None: # name is also None from sage.structure.parent import Set_PythonType return Set_PythonType(object) raise ValueError("unable to construct an alphabet from the given parameters")
def build_alphabet(data=None, names=None, name=None): r""" Returns an object representing an ordered alphabet. EXAMPLES: If the argument is a Set, it just returns it:: sage: build_alphabet(ZZ) is ZZ True sage: F = FiniteEnumeratedSet('abc') sage: build_alphabet(F) is F True If a list, tuple or string is provided, then it builds a proper Sage class (:class:`~sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet`):: sage: build_alphabet([0,1,2]) {0, 1, 2} sage: F = build_alphabet('abc'); F {'a', 'b', 'c'} sage: print type(F).__name__ TotallyOrderedFiniteSet_with_category If no data is provided, ``name`` may be a string which describe an alphabet. The available names decompose into two families. The first one are 'positive integers', 'PP', 'natural numbers' or 'NN' which refer to standard set of numbers:: sage: build_alphabet(name="positive integers") Positive integers sage: build_alphabet(name="PP") Positive integers sage: build_alphabet(name="natural numbers") Non negative integers sage: build_alphabet(name="NN") Non negative integers The other families for the option ``name`` are among 'lower', 'upper', 'space', 'underscore', 'punctuation', 'printable', 'binary', 'octal', 'decimal', 'hexadecimal', 'radix64' which refer to standard set of charaters. Theses names may be combined by separating them by a space:: sage: build_alphabet(name="lower") {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'} sage: build_alphabet(name="hexadecimal") {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'} sage: build_alphabet(name="decimal punctuation") {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', ',', '.', ';', ':', '!', '?'} In the case the alphabet is built from a list or a tuple, the order on the alphabet is given by the elements themselves:: sage: A = build_alphabet([0,2,1]) sage: A(0) < A(2) True sage: A(2) < A(1) False If a different order is needed, you may use :class:`~sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet` and set the option ``facade`` to ``False``. That way, the comparison fits the order of the input:: sage: A = TotallyOrderedFiniteSet([4,2,6,1], facade=False) sage: A(4) < A(2) True sage: A(1) < A(6) False Be careful, the element of the set in the last example are no more integers and do not compare equal with integers:: sage: type(A.an_element()) <class 'sage.sets.totally_ordered_finite_set.TotallyOrderedFiniteSet_with_category.element_class'> sage: A(1) == 1 False sage: 1 == A(1) False """ if data in Sets(): return data if isinstance(data, (int, long, Integer)): if names is None: from sage.sets.integer_range import IntegerRange return IntegerRange(Integer(data)) elif len(names) == data: return TotallyOrderedFiniteSet(data) elif isinstance(names, str): return TotallyOrderedFiniteSet( [names + '%d' % i for i in xrange(data)]) raise ValueError("not possible") elif data == Infinity: if names is None: return NonNegativeIntegers() else: Family(NonNegativeIntegers(), lambda i: 'x%d' % i) if data is None and name is None: from sage.structure.parent import Set_PythonType return Set_PythonType(object) if data is None: if name == "positive integers" or name == "PP": from sage.sets.positive_integers import PositiveIntegers return PositiveIntegers() elif name == "natural numbers" or name == "NN": return NonNegativeIntegers() else: names = name.split(' ') data = [] for name in names: if name in set_of_letters: data.extend(list(set_of_letters[name])) else: raise TypeError("name is not recognized") return TotallyOrderedFiniteSet(data) raise TypeError("name is not recognized") elif isinstance(data, (tuple, list, str)): return TotallyOrderedFiniteSet(data)