コード例 #1
0
ファイル: weyl_algebra.py プロジェクト: sagemathinc/smc-sage
    def __div__(self, x, self_on_left=False):
        """
        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
            if self_on_left:
                D = dict_linear_combination([(D, x_inv)], factor_on_left=False)
            else:
                D = dict_linear_combination([(D, x_inv)])

            return self.__class__(F, D)

        return self.__class__(F, {t: _divide_if_possible(D[t], x) for t in D})
コード例 #2
0
ファイル: weyl_algebra.py プロジェクト: acrlakshman/sage
    def __div__(self, x, self_on_left=False):
        """
        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
            if self_on_left:
                D = dict_linear_combination( [ ( D, x_inv ) ], factor_on_left=False )
            else:
                D = dict_linear_combination( [ ( D, x_inv ) ] )

            return self.__class__(F, D)

        return self.__class__(F, {t: _divide_if_possible(D[t], x) for t in D})
コード例 #3
0
        def __init__(self, A, dictionary=None, dual=None):
            """
            Create an element of a dual basis.

            INPUT:

            - ``self`` -- an element of the symmetric functions in a dual basis

            At least one of the following must be specified. The one (if
            any) which is not provided will be computed.

            - ``dictionary`` -- an internal dictionary for the
              monomials and coefficients of ``self``

            - ``dual`` -- self as an element of the 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(0)

            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 = dict_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)
コード例 #4
0
ファイル: dual.py プロジェクト: sageb0t/testsage
        def __init__(self, A, dictionary=None, dual=None):
            """
            Create an element of a dual basis.

            INPUT:

            - ``self`` -- an element of the symmetric functions in a dual basis

            At least one of the following must be specified. The one (if
            any) which is not provided will be computed.

            - ``dictionary`` -- an internal dictionary for the
              monomials and coefficients of ``self``

            - ``dual`` -- self as an element of the 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(0)

            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 = dict_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)