Esempio n. 1
0
    def __init__(self, set, function, name=None):
        """
        TESTS::

            sage: from sage.sets.family import LazyFamily
            sage: f = LazyFamily([3,4,7], lambda i: 2*i); f
            Lazy family (<lambda>(i))_{i in [3, 4, 7]}
            sage: TestSuite(f).run()

        Check for :trac:`5538`::

            sage: l = [3,4,7]
            sage: f = LazyFamily(l, lambda i: 2*i)
            sage: l[1] = 18
            sage: f
            Lazy family (<lambda>(i))_{i in [3, 4, 7]}
        """
        if set in FiniteEnumeratedSets():
            category = FiniteEnumeratedSets()
        elif set in InfiniteEnumeratedSets():
            category = InfiniteEnumeratedSets()
        elif isinstance(set, (list, tuple, range, CombinatorialClass)):
            category = FiniteEnumeratedSets()
        else:
            category = EnumeratedSets()

        Parent.__init__(self, category=category)

        self.set = copy(set)
        self.function = function
        self.function_name = name
Esempio n. 2
0
    def __init__(self, set, function, name=None):
        """
        TESTS::

            sage: from sage.sets.family import LazyFamily
            sage: f = LazyFamily([3,4,7], lambda i: 2*i); f
            Lazy family (<lambda>(i))_{i in [3, 4, 7]}
            sage: TestSuite(f).run()   # __contains__ is not implemented
            Failure ...
            The following tests failed: _test_an_element, _test_enumerated_set_contains, _test_some_elements

        Check for bug #5538::

            sage: l = [3,4,7]
            sage: f = LazyFamily(l, lambda i: 2*i);
            sage: l[1] = 18
            sage: f
            Lazy family (<lambda>(i))_{i in [3, 4, 7]}
        """
        from sage.combinat.combinat import CombinatorialClass  # workaround #12482

        if set in FiniteEnumeratedSets():
            category = FiniteEnumeratedSets()
        elif set in InfiniteEnumeratedSets():
            category = InfiniteEnumeratedSets()
        elif isinstance(set, (list, tuple, CombinatorialClass)):
            category = FiniteEnumeratedSets()
        else:
            category = EnumeratedSets()

        Parent.__init__(self, category=category)
        from copy import copy
        self.set = copy(set)
        self.function = function
        self.function_name = name
Esempio n. 3
0
        def __init_18449__(self, set, function, name=None):
            """
            patched __init__ function from ticket #18449
            """
            from sage.combinat.combinat import CombinatorialClass  # workaround #12482
            from sage.structure.parent import Parent

            category = EnumeratedSets()
            if set in FiniteEnumeratedSets():
                category = FiniteEnumeratedSets()
            elif set in InfiniteEnumeratedSets():
                category = InfiniteEnumeratedSets()
            elif isinstance(set, (list, tuple)):
                category = FiniteEnumeratedSets()
            elif isinstance(set, CombinatorialClass):
                try:
                    if set.is_finite():
                        category = FiniteEnumeratedSets()
                except NotImplementedError:
                    pass
            Parent.__init__(self, category=category)
            from copy import copy

            self.set = copy(set)
            self.function = function
            self.function_name = name
Esempio n. 4
0
    def __init__(self, family, facade=True, keepkey=False, category=None):
        """
        TESTS::

            sage: U = DisjointUnionEnumeratedSets({1: FiniteEnumeratedSet([1,2,3]),
            ....:                                  2: FiniteEnumeratedSet([4,5,6])})
            sage: TestSuite(U).run()

            sage: X = DisjointUnionEnumeratedSets({i: Partitions(i) for i in range(5)})
            sage: TestSuite(X).run()
        """
        self._family = family
        self._facade = facade
        if facade:
            if family in FiniteEnumeratedSets():
                self._facade_for = tuple(family)
            else:
                # This allows the test suite to pass its tests by essentially
                #   stating that this is a facade for any parent. Technically
                #   this is wrong, but in practice, it will not have much
                #   of an effect.
                self._facade_for = True
        self._keepkey = keepkey
        if self._is_category_initialized():
            return
        if category is None:
            # try to guess if the result is infinite or not.
            if self._family in InfiniteEnumeratedSets():
                category = InfiniteEnumeratedSets()
            elif self._family.last().cardinality() == Infinity:
                category = InfiniteEnumeratedSets()
            else:
                category = FiniteEnumeratedSets()
        Parent.__init__(self, facade=facade, category=category)
Esempio n. 5
0
    def __init__(self, starting_weight):
        """
        EXAMPLES::

            sage: C = crystals.LSPaths(['A',2,1],[-1,0,1]); C
            The crystal of LS paths of type ['A', 2, 1] and weight -Lambda[0] + Lambda[2]
            sage: C.R
            Root system of type ['A', 2, 1]
            sage: C.weight
            -Lambda[0] + Lambda[2]
            sage: C.weight.parent()
            Extended weight space over the Rational Field of the Root system of type ['A', 2, 1]
            sage: C.module_generators
            [(-Lambda[0] + Lambda[2],)]

        TESTS::

            sage: C = crystals.LSPaths(['A',2,1], [-1,0,1])
            sage: TestSuite(C).run() # long time
            sage: C = crystals.LSPaths(['E',6], [1,0,0,0,0,0])
            sage: TestSuite(C).run()
        """
        cartan_type = starting_weight.parent().cartan_type()
        self.R = RootSystem(cartan_type)
        self.weight = starting_weight
        if not self.weight.parent().base_ring().has_coerce_map_from(QQ):
            raise ValueError(
                "Please use the weight space, rather than weight lattice for your weights"
            )
        self._cartan_type = cartan_type
        self._name = "The crystal of LS paths of type %s and weight %s" % (
            cartan_type, starting_weight)
        if cartan_type.is_affine():
            if all(i >= 0 for i in starting_weight.coefficients()):
                Parent.__init__(self,
                                category=(RegularCrystals(),
                                          HighestWeightCrystals(),
                                          InfiniteEnumeratedSets()))
            elif starting_weight.parent().is_extended():
                Parent.__init__(self,
                                category=(RegularCrystals(),
                                          InfiniteEnumeratedSets()))
            else:
                Parent.__init__(self,
                                category=(RegularCrystals(), FiniteCrystals()))
        else:
            Parent.__init__(self, category=ClassicalCrystals())

        if starting_weight == starting_weight.parent().zero():
            initial_element = self(tuple([]))
        else:
            initial_element = self(tuple([starting_weight]))
        self.module_generators = [initial_element]
Esempio n. 6
0
    def basis(self, reg=None):
        from sage.sets.set import Set

        assert hasattr(self, "_domain")

        from functools import partial
        from sage.sets.set_from_iterator import EnumeratedSetFromIterator

        if reg is None:
            reg = region()
        reg = reg.intersect(self.bbox())
        reg2 = (reg + self._totaloff).var_mult(
            dict(list(zip(("t", "e", "s"), self._signs))))
        iterfunc = partial(self.__degree_walker_tc,
                           idx=len(self._factors) - 1,
                           elems=[],
                           reg=reg2)
        sz = 0
        for var in ("t", "e", "s"):
            ma, mi = reg.max(var), reg.min(var)
            if mi > ma:
                return Set(())
            sz += ma - mi
        category = (FiniteEnumeratedSets()
                    if sz < +Infinity else InfiniteEnumeratedSets())
        return EnumeratedSetFromIterator(
            iterfunc,
            category=category,
            cache=False,
            name="basis in %s of %s" % (reg, self._domain),
        )
Esempio n. 7
0
    def __init__(self, wt, WLR):
        r"""
        Initialize ``self``.

        EXAMPLES::

            sage: La = RootSystem(['A', 2]).weight_lattice().fundamental_weights()
            sage: RC = crystals.RiggedConfigurations(La[1] + La[2])
            sage: TestSuite(RC).run()

            sage: La = RootSystem(['A', 2, 1]).weight_lattice().fundamental_weights()
            sage: RC = crystals.RiggedConfigurations(La[0])
            sage: TestSuite(RC).run() # long time
        """
        self._cartan_type = WLR.cartan_type()
        self._wt = wt
        self._rc_index = self._cartan_type.index_set()
        self._rc_index_inverse = {i: ii for ii, i in enumerate(self._rc_index)}
        # We store the Cartan matrix for the vacancy number calculations for speed
        self._cartan_matrix = self._cartan_type.cartan_matrix()
        if self._cartan_type.is_finite():
            category = ClassicalCrystals()
        else:
            category = (RegularCrystals(), HighestWeightCrystals(),
                        InfiniteEnumeratedSets())
        Parent.__init__(self, category=category)
        n = self._cartan_type.rank()  #== len(self._cartan_type.index_set())
        self.module_generators = (self.element_class(
            self, partition_list=[[] for i in range(n)]), )
Esempio n. 8
0
    def __init__(self, ct, La):
        r"""
        EXAMPLES::

            sage: La = RootSystem(['A',2]).weight_lattice().fundamental_weights()
            sage: M = crystals.NakajimaMonomials(['A',2], La[1]+La[2])
            sage: TestSuite(M).run()

            sage: La = RootSystem(['C',2,1]).weight_lattice(extended=True).fundamental_weights()
            sage: M = crystals.NakajimaMonomials(['C',2,1], La[0])
            sage: TestSuite(M).run(max_runs=100)
        """
        if ct.is_finite():
            cat = ClassicalCrystals()
        else:
            cat = (RegularCrystals(), HighestWeightCrystals(),
                   InfiniteEnumeratedSets())
        InfinityCrystalOfNakajimaMonomials.__init__(
            self, ct, cat, CrystalOfNakajimaMonomialsElement)
        self._cartan_type = ct
        self.hw = La
        gen = {}
        for j in range(len(La.support())):
            gen[(La.support()[j], 0)] = La.coefficients()[j]
        self.module_generators = (self.element_class(self, gen), )
Esempio n. 9
0
    def __init__(self, begin, end, step=Integer(1), middle_point=Integer(1)):
        r"""
        TESTS::

            sage: from sage.sets.integer_range import IntegerRangeFromMiddle
            sage: I = IntegerRangeFromMiddle(-100,100,10,0)
            sage: I.category()
            Category of facade finite enumerated sets
            sage: TestSuite(I).run()
            sage: I = IntegerRangeFromMiddle(Infinity,-Infinity,-37,0)
            sage: I.category()
            Category of facade infinite enumerated sets
            sage: TestSuite(I).run()

            sage: IntegerRange(0, 5, 1, -3)
            Traceback (most recent call last):
            ...
            ValueError: middle_point is not in the interval
        """
        self._begin = begin
        self._end = end
        self._step = step
        self._middle_point = middle_point
        if not middle_point in self:
            raise ValueError("middle_point is not in the interval")

        if (begin != Infinity and begin != -Infinity) and \
             (end != Infinity and end != -Infinity):
            Parent.__init__(self,
                            facade=IntegerRing(),
                            category=FiniteEnumeratedSets())
        else:
            Parent.__init__(self,
                            facade=IntegerRing(),
                            category=InfiniteEnumeratedSets())
Esempio n. 10
0
    def __init__(self, weights):
        """
        TESTS::

            sage: C = WeightedIntegerVectors([2,1,3])
            sage: C.__class__
            <class 'sage.combinat.integer_vector_weighted.WeightedIntegerVectors_all_with_category'>
            sage: C.category()
            Join of Category of sets with grading and Category of infinite enumerated sets
            sage: TestSuite(C).run()
        """
        self._weights = weights
        from sage.sets.all import Family, NonNegativeIntegers
        # Use "partial" to make the basis function (with the weights
        # argument specified) pickleable.  Otherwise, it seems to
        # cause problems...
        from functools import partial
        F = Family(NonNegativeIntegers(),
                   partial(WeightedIntegerVectors, weight=weights))
        DisjointUnionEnumeratedSets.__init__(
            self,
            F,
            facade=True,
            keepkey=False,
            category=(SetsWithGrading(), InfiniteEnumeratedSets()))
Esempio n. 11
0
    def __init__(self, crystals, weight, P):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: B = crystals.KirillovReshetikhin(['A',2,1], 1,1)
            sage: La = RootSystem(['A',2,1]).weight_lattice().fundamental_weights()
            sage: C = crystals.KyotoPathModel(B, La[0])
            sage: TestSuite(C).run() # long time
        """
        Parent.__init__(self,
                        category=(HighestWeightCrystals(),
                                  InfiniteEnumeratedSets()))

        self._cartan_type = crystals[0].cartan_type()
        self._weight = weight
        if weight.parent().is_extended():
            # public for TensorProductOfCrystals
            self.crystals = tuple([C.affinization() for C in crystals])
            self._epsilon_dicts = [{
                b.Epsilon(): self.crystals[i](b, 0)
                for b in B
            } for i, B in enumerate(crystals)]
            self._phi_dicts = [{b.Phi(): self.crystals[i](b, 0)
                                for b in B} for i, B in enumerate(crystals)]
        else:
            # public for TensorProductOfCrystals
            self.crystals = tuple(crystals)
            self._epsilon_dicts = [{b.Epsilon(): b
                                    for b in B} for B in crystals]
            self._phi_dicts = [{b.Phi(): b for b in B} for B in crystals]
        self.module_generators = (self.element_class(
            self, [self._phi_dicts[0][weight]]), )
Esempio n. 12
0
    def super_categories(self):
        r"""
        EXAMPLES::

            sage: AffineWeylGroups().super_categories()
            [Category of weyl groups, Category of infinite enumerated sets]
        """
        return [WeylGroups(), InfiniteEnumeratedSets()]
Esempio n. 13
0
    def __init__(self):
        r"""
        TESTS::

            sage: from sage.combinat.backtrack import PositiveIntegerSemigroup
            sage: PP = PositiveIntegerSemigroup()
        """
        SearchForest.__init__(self, facade = ZZ, category=(InfiniteEnumeratedSets(), CommutativeAdditiveSemigroups(), Monoids()))
Esempio n. 14
0
    def __init__(self, family, facade=True, keepkey=False):
        """
        TESTS::

            sage: U = DisjointUnionEnumeratedSets({1: FiniteEnumeratedSet([1,2,3]),
            ...                                    2: FiniteEnumeratedSet([4,5,6])})
            sage: TestSuite(U).run()
        """
        self._family = family
        self._facade = facade
        self._keepkey = keepkey
        # try to guess if the result is infinite or not.
        if self._family.cardinality() == Infinity:
            Parent.__init__(self, category=InfiniteEnumeratedSets())
        elif self._family.last().cardinality() == Infinity:
            Parent.__init__(self, category=InfiniteEnumeratedSets())
        else:
            Parent.__init__(self, category=FiniteEnumeratedSets())
Esempio n. 15
0
    def __init__(self):
        """
        TESTS::

            sage: PF = ParkingFunctions()
            sage: TestSuite(PF).run()
        """
        cat = InfiniteEnumeratedSets() & SetsWithGrading()
        Parent.__init__(self, category=cat)
    def __init__(self):
        """
        TESTS::

            sage: PF = NonDecreasingParkingFunctions()
            sage: PF == loads(dumps(PF))
            True
        """
        Parent.__init__(self, category=InfiniteEnumeratedSets())
Esempio n. 17
0
    def __init__(self, k):
        """
        TESTS::

            sage: IV = IntegerVectors(k=2)
            sage: TestSuite(IV).run()
        """
        self.k = k
        IntegerVectors.__init__(self, category=InfiniteEnumeratedSets())
Esempio n. 18
0
    def __init__(self):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: IV = IntegerVectors()
            sage: TestSuite(IV).run()
        """
        IntegerVectors.__init__(self, category=InfiniteEnumeratedSets())
Esempio n. 19
0
 def basis(self, region=None):
     # this assumes a _basis_walker method in the subquotient object
     wk = self._sq._basis_walker(region)
     if self._am.graded_basis(region).cardinality() < Infinity:
         cat = FiniteEnumeratedSets()
     else:
         cat = InfiniteEnumeratedSets()
     res = Family(wk, lambda i: i, lazy=True)
     res._refine_category_(cat)
     return res
Esempio n. 20
0
    def __init__(self):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: OS = OrderedSetPartitions()
            sage: TestSuite(OS).run()  # long time
        """
        Parent.__init__(self, category=InfiniteEnumeratedSets())
Esempio n. 21
0
 def __init__(self, ambient, iterable, size, mapfunc, unmapfunc):
     if size < Infinity:
         category = FiniteEnumeratedSets()
     else:
         category = InfiniteEnumeratedSets()
     Parent.__init__(self, ZZ, category=category)
     self.size = size
     self.fmap = mapfunc
     self.funm = unmapfunc
     self.keys = iterable
     self.am = ambient
Esempio n. 22
0
    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()) )
Esempio n. 23
0
    def __init__(self):
        r"""
        Initializes the class of all semistandard super tableaux.

        TESTS::

            sage: from sage.combinat.super_tableau import SemistandardSuperTableaux_all
            sage: SST = SemistandardSuperTableaux_all(); SST
            Semistandard super tableaux
        """
        Parent.__init__(self, category=InfiniteEnumeratedSets())
        SemistandardSuperTableaux.__init__(self)
Esempio n. 24
0
    def __init__(self):
        """
        TESTS::

            sage: NN = InfiniteEnumeratedSets().example()
            sage: NN
            An example of an infinite enumerated set: the non negative integers
            sage: NN.category()
            Category of infinite enumerated sets
            sage: TestSuite(NN).run()
        """
        Parent.__init__(self, category = InfiniteEnumeratedSets())
Esempio n. 25
0
    def __init__(self, n, category):
        r"""
        EXAMPLES::

            sage: Yinf = crystals.infinity.GeneralizedYoungWalls(3)
            sage: TestSuite(Yinf).run()
        """
        self._cartan_type = CartanType(['A', n, 1])
        if category is None:
            category = (HighestWeightCrystals(), InfiniteEnumeratedSets())
        Parent.__init__(self, category=category)
        self.module_generators = (self.element_class(self, []), )
    def __init__(self, family, facade=True, keepkey=False, category = None):
        """
        TESTS::

            sage: U = DisjointUnionEnumeratedSets({1: FiniteEnumeratedSet([1,2,3]),
            ....:                                  2: FiniteEnumeratedSet([4,5,6])})
            sage: TestSuite(U).run()
        """
        self._family = family
        self._facade  = facade
        self._keepkey = keepkey
        if self._is_category_initialized():
            return
        if category is None:
            # try to guess if the result is infinite or not.
            if self._family in InfiniteEnumeratedSets():
                category = InfiniteEnumeratedSets()
            elif self._family.last().cardinality() == Infinity:
                category = InfiniteEnumeratedSets()
            else:
                category = FiniteEnumeratedSets()
        Parent.__init__(self, category = category)
Esempio n. 27
0
    def __init__(self, category=None):
        """
        TESTS::

            sage: NN = NonNegativeIntegers()
            sage: NN
            Non negative integers
            sage: NN.category()
            Category of facade infinite enumerated sets
            sage: TestSuite(NN).run()
        """
        from sage.rings.integer_ring import ZZ
        Parent.__init__(self, facade = ZZ, category = InfiniteEnumeratedSets().or_subcategory(category) )
Esempio n. 28
0
    def __init__(self, is_infinite=False):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: C = Compositions()
            sage: TestSuite(C).run()
        """
        if is_infinite:
            Parent.__init__(self, category=InfiniteEnumeratedSets())
        else:
            Parent.__init__(self, category=FiniteEnumeratedSets())
    def __init__(self, cartan_type):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: B = crystals.infinity.Tableaux(['A',2])
            sage: TestSuite(B).run() # long time
        """
        Parent.__init__( self, category=(HighestWeightCrystals(), InfiniteEnumeratedSets()) )
        self._cartan_type = cartan_type
        self.letters = CrystalOfLetters(cartan_type)
        self.module_generators = (self.module_generator(),)
Esempio n. 30
0
    def __init__(self, category=None):
        """
        Initialize ``self``.

        EXAMPLES::

            sage: S = StandardRibbonShapedTableaux()
            sage: TestSuite(S).run()
        """
        if category is None:
            category = InfiniteEnumeratedSets()

        StandardSkewTableaux.__init__(self, category=category)