Пример #1
0
        def _acted_upon_(self, scalar, self_on_left=False):
            """
            Return the action of ``scalar`` on ``self``.

            EXAMPLES::

                sage: S = SymmetricGroupAlgebra(QQ, 3)
                sage: C = S.cellular_basis()
                sage: W = S.cell_module([2,1])
                sage: elt = W.an_element(); elt
                2*W[[1, 2], [3]] + 2*W[[1, 3], [2]]
                sage: sc = C.an_element(); sc
                3*C([2, 1], [[1, 3], [2]], [[1, 2], [3]])
                 + 2*C([2, 1], [[1, 3], [2]], [[1, 3], [2]])
                 + 2*C([3], [[1, 2, 3]], [[1, 2, 3]])
                sage: sc * elt
                10*W[[1, 3], [2]]

                sage: s = S.an_element(); s
                [1, 2, 3] + 2*[1, 3, 2] + 3*[2, 1, 3] + [3, 1, 2]
                sage: s * elt
                11*W[[1, 2], [3]] - 3/2*W[[1, 3], [2]]

                sage: 1/2 * elt
                W[[1, 2], [3]] + W[[1, 3], [2]]
            """
            # Check for elements coercable to the base ring first
            ret = CombinatorialFreeModule.Element._acted_upon_(
                self, scalar, self_on_left)
            if ret is not None:
                return ret
            # See message in CombinatorialFreeModuleElement._acted_upon_
            P = self.parent()
            if isinstance(scalar,
                          Element) and scalar.parent() is not P._algebra:
                # Temporary needed by coercion (see Polynomial/FractionField tests).
                if not P._algebra.has_coerce_map_from(scalar.parent()):
                    return None
                scalar = P._algebra(scalar)

            if self_on_left:
                raise NotImplementedError
                #scalar = scalar.cellular_involution()
            mc = self._monomial_coefficients
            scalar_mc = scalar.monomial_coefficients(copy=False)
            D = linear_combination([(P._action_basis(
                x, k)._monomial_coefficients, scalar_mc[x] * mc[k]) for k in mc
                                    for x in scalar_mc],
                                   factor_on_left=False)

            return P._from_dict(D, remove_zeros=False)
Пример #2
0
        def _acted_upon_(self, scalar, self_on_left=False):
            """
            Return the action of ``scalar`` on ``self``.

            EXAMPLES::

                sage: S = SymmetricGroupAlgebra(QQ, 3)
                sage: C = S.cellular_basis()
                sage: W = S.cell_module([2,1])
                sage: elt = W.an_element(); elt
                2*W[[1, 2], [3]] + 2*W[[1, 3], [2]]
                sage: sc = C.an_element(); sc
                3*C([2, 1], [[1, 3], [2]], [[1, 2], [3]])
                 + 2*C([2, 1], [[1, 3], [2]], [[1, 3], [2]])
                 + 2*C([3], [[1, 2, 3]], [[1, 2, 3]])
                sage: sc * elt
                10*W[[1, 3], [2]]

                sage: s = S.an_element(); s
                [1, 2, 3] + 2*[1, 3, 2] + 3*[2, 1, 3] + [3, 1, 2]
                sage: s * elt
                11*W[[1, 2], [3]] - 3/2*W[[1, 3], [2]]

                sage: 1/2 * elt
                W[[1, 2], [3]] + W[[1, 3], [2]]
            """
            # Check for elements coercable to the base ring first
            ret = CombinatorialFreeModule.Element._acted_upon_(self, scalar, self_on_left)
            if ret is not None:
                return ret
            # See message in CombinatorialFreeModuleElement._acted_upon_
            P = self.parent()
            if isinstance(scalar, Element) and scalar.parent() is not P._algebra:
                # Temporary needed by coercion (see Polynomial/FractionField tests).
                if not P._algebra.has_coerce_map_from(scalar.parent()):
                    return None
                scalar = P._algebra( scalar )

            if self_on_left:
                raise NotImplementedError
                #scalar = scalar.cellular_involution()
            mc = self._monomial_coefficients
            scalar_mc = scalar.monomial_coefficients(copy=False)
            D = linear_combination([(P._action_basis(x, k)._monomial_coefficients,
                                     scalar_mc[x] * mc[k])
                                    for k in mc for x in scalar_mc],
                                   factor_on_left=False)

            return P._from_dict(D, remove_zeros=False)
Пример #3
0
    def __truediv__(self, x):
        """
        Division by coefficients.

        EXAMPLES::

            sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)
            sage: x / 2
            1/2*x
            sage: W.<x,y,z> = DifferentialWeylAlgebra(ZZ)
            sage: a = 2*x + 4*y*z
            sage: a / 2
            2*y*z + x
        """
        F = self.parent()
        D = self.__monomials
        if F.base_ring().is_field():
            x = F.base_ring()( x )
            x_inv = x**-1
            D = blas.linear_combination( [ ( D, x_inv ) ] )

            return self.__class__(F, D)

        return self.__class__(F, {t: D[t]._divide_if_possible(x) for t in D})
Пример #4
0
    def __truediv__(self, x):
        """
        Division by coefficients.

        EXAMPLES::

            sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)
            sage: x / 2
            1/2*x
            sage: W.<x,y,z> = DifferentialWeylAlgebra(ZZ)
            sage: a = 2*x + 4*y*z
            sage: a / 2
            2*y*z + x
        """
        F = self.parent()
        D = self.__monomials
        if F.base_ring().is_field():
            x = F.base_ring()(x)
            x_inv = x**-1
            D = blas.linear_combination([(D, x_inv)])

            return self.__class__(F, D)

        return self.__class__(F, {t: D[t]._divide_if_possible(x) for t in D})
Пример #5
0
        def __init__(self, A, dictionary=None, dual=None):
            """
            Create an element of a dual basis.

            TESTS::

                sage: m = SymmetricFunctions(QQ).monomial()
                sage: zee = sage.combinat.sf.sfa.zee
                sage: h = m.dual_basis(scalar=zee, prefix='h')
                sage: a = h([2])
                sage: ec = h._element_class
                sage: ec(h, dual=m([2]))
                -h[1, 1] + 2*h[2]
                sage: h(m([2]))
                -h[1, 1] + 2*h[2]
                sage: h([2])
                h[2]
                sage: h([2])._dual
                m[1, 1] + m[2]
                sage: m(h([2]))
                m[1, 1] + m[2]
            """
            if dictionary is None and dual is None:
                raise ValueError("you must specify either x or dual")

            parent = A
            base_ring = parent.base_ring()
            zero = base_ring.zero()

            if dual is None:
                # We need to compute the dual
                dual_dict = {}
                from_self_cache = parent._from_self_cache

                # Get the underlying dictionary for self
                s_mcs = dictionary

                # Make sure all the conversions from self to
                # to the dual basis have been precomputed
                for part in s_mcs:
                    if part not in from_self_cache:
                        parent._precompute(sum(part))

                # Create the monomial coefficient dictionary from the
                # the monomial coefficient dictionary of dual
                for s_part in s_mcs:
                    from_dictionary = from_self_cache[s_part]
                    for part in from_dictionary:
                        dual_dict[ part ] = dual_dict.get(part, zero) + base_ring(s_mcs[s_part]*from_dictionary[part])

                dual = parent._dual_basis._from_dict(dual_dict)


            if dictionary is None:
                # We need to compute the monomial coefficients dictionary
                dictionary = {}
                to_self_cache = parent._to_self_cache

                # Get the underlying dictionary for the dual
                d_mcs = dual._monomial_coefficients

                # Make sure all the conversions from the dual basis
                # to self have been precomputed
                for part in d_mcs:
                    if part not in to_self_cache:
                        parent._precompute(sum(part))

                # Create the monomial coefficient dictionary from the
                # the monomial coefficient dictionary of dual
                dictionary = blas.linear_combination( (to_self_cache[d_part], d_mcs[d_part]) for d_part in d_mcs)

            # Initialize self
            self._dual = dual
            classical.SymmetricFunctionAlgebra_classical.Element.__init__(self, A, dictionary)
Пример #6
0
        def __init__(self, A, dictionary=None, dual=None):
            """
            Create an element of a dual basis.

            TESTS::

                sage: m = SymmetricFunctions(QQ).monomial()
                sage: zee = sage.combinat.sf.sfa.zee
                sage: h = m.dual_basis(scalar=zee, prefix='h')
                sage: a = h([2])
                sage: ec = h._element_class
                sage: ec(h, dual=m([2]))
                -h[1, 1] + 2*h[2]
                sage: h(m([2]))
                -h[1, 1] + 2*h[2]
                sage: h([2])
                h[2]
                sage: h([2])._dual
                m[1, 1] + m[2]
                sage: m(h([2]))
                m[1, 1] + m[2]
            """
            if dictionary is None and dual is None:
                raise ValueError("you must specify either x or dual")

            parent = A
            base_ring = parent.base_ring()
            zero = base_ring.zero()

            if dual is None:
                # We need to compute the dual
                dual_dict = {}
                from_self_cache = parent._from_self_cache

                # Get the underlying dictionary for self
                s_mcs = dictionary

                # Make sure all the conversions from self to
                # to the dual basis have been precomputed
                for part in s_mcs:
                    if part not in from_self_cache:
                        parent._precompute(sum(part))

                # Create the monomial coefficient dictionary from the
                # the monomial coefficient dictionary of dual
                for s_part in s_mcs:
                    from_dictionary = from_self_cache[s_part]
                    for part in from_dictionary:
                        dual_dict[ part ] = dual_dict.get(part, zero) + base_ring(s_mcs[s_part]*from_dictionary[part])

                dual = parent._dual_basis._from_dict(dual_dict)


            if dictionary is None:
                # We need to compute the monomial coefficients dictionary
                dictionary = {}
                to_self_cache = parent._to_self_cache

                # Get the underlying dictionary for the dual
                d_mcs = dual._monomial_coefficients

                # Make sure all the conversions from the dual basis
                # to self have been precomputed
                for part in d_mcs:
                    if part not in to_self_cache:
                        parent._precompute(sum(part))

                # Create the monomial coefficient dictionary from the
                # the monomial coefficient dictionary of dual
                dictionary = blas.linear_combination( (to_self_cache[d_part], d_mcs[d_part]) for d_part in d_mcs)

            # Initialize self
            self._dual = dual
            classical.SymmetricFunctionAlgebra_classical.Element.__init__(self, A, dictionary)