Example #1
0
    def __init__(self,
                 A,
                 stream=None,
                 order=None,
                 aorder=None,
                 aorder_changed=True,
                 is_initialized=False,
                 name=None):
        """
        EXAMPLES::

            sage: L = LazyPowerSeriesRing(QQ)
            sage: f = L()
            sage: loads(dumps(f))
            Uninitialized lazy power series
        """
        AlgebraElement.__init__(self, A)
        self._stream = stream
        self.order = unk if order is None else order
        self.aorder = unk if aorder is None else aorder
        if self.aorder == inf:
            self.order = inf
        self.aorder_changed = aorder_changed
        self.is_initialized = is_initialized
        self._zero = A.base_ring().zero()
        self._name = name
Example #2
0
    def __init__(self, A, elt=None, check=True):
        """
        TESTS::

            sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1,0], [0,1]]), Matrix([[0,1], [0,0]])])
            sage: A(QQ(4))
            Traceback (most recent call last):
            ...
            TypeError: elt should be a vector, a matrix, or an element of the base field

            sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]), Matrix([[0,1], [-1,0]])])
            sage: elt = B(Matrix([[1,1], [-1,1]])); elt
            e0 + e1
            sage: TestSuite(elt).run()
            sage: B(Matrix([[0,1], [1,0]]))
            Traceback (most recent call last):
            ...
            ValueError: matrix does not define an element of the algebra
        """
        AlgebraElement.__init__(self, A)
        k = A.base_ring()
        n = A.degree()
        if elt is None:
            self._vector = vector(k, n)
            self._matrix = Matrix(k, n)
        else:
            if isinstance(elt, int):
                elt = Integer(elt)
            elif isinstance(elt, list):
                elt = vector(elt)
            if A == elt.parent():
                self._vector = elt._vector.base_extend(k)
                self._matrix = elt._matrix.base_extend(k)
            elif k.has_coerce_map_from(elt.parent()):
                e = k(elt)
                if e == 0:
                    self._vector = vector(k, n)
                    self._matrix = Matrix(k, n)
                elif A.is_unitary():
                    self._vector = A._one * e
                    self._matrix = Matrix.identity(k, n) * e
                else:
                    raise TypeError("algebra is not unitary")
            elif is_Vector(elt):
                self._vector = elt.base_extend(k)
                self._matrix = Matrix(
                    k, sum([elt[i] * A.table()[i] for i in range(n)]))
            elif is_Matrix(elt):
                if not A.is_unitary():
                    raise TypeError("algebra is not unitary")
                self._vector = A._one * elt
                if not check or sum(
                    [self._vector[i] * A.table()[i] for i in range(n)]) == elt:
                    self._matrix = elt
                else:
                    raise ValueError(
                        "matrix does not define an element of the algebra")
            else:
                raise TypeError("elt should be a vector, a matrix, " +
                                "or an element of the base field")
    def __init__(self, A, elt=None, check=True):
        """
        TESTS::

            sage: A = FiniteDimensionalAlgebra(GF(3), [Matrix([[1,0], [0,1]]), Matrix([[0,1], [0,0]])])
            sage: A(QQ(4))
            Traceback (most recent call last):
            ...
            TypeError: elt should be a vector, a matrix, or an element of the base field

            sage: B = FiniteDimensionalAlgebra(QQ, [Matrix([[1,0], [0,1]]), Matrix([[0,1], [-1,0]])])
            sage: elt = B(Matrix([[1,1], [-1,1]])); elt
            e0 + e1
            sage: TestSuite(elt).run()
            sage: B(Matrix([[0,1], [1,0]]))
            Traceback (most recent call last):
            ...
            ValueError: matrix does not define an element of the algebra
        """
        AlgebraElement.__init__(self, A)
        k = A.base_ring()
        n = A.degree()
        if elt is None:
            self._vector = vector(k, n)
            self._matrix = Matrix(k, n)
        else:
            if isinstance(elt, int):
                elt = Integer(elt)
            elif isinstance(elt, list):
                elt = vector(elt)
            if A == elt.parent():
                self._vector = elt._vector.base_extend(k)
                self._matrix = elt._matrix.base_extend(k)
            elif k.has_coerce_map_from(elt.parent()):
                e = k(elt)
                if e == 0:
                    self._vector = vector(k, n)
                    self._matrix = Matrix(k, n)
                elif A.is_unitary():
                    self._vector = A._one * e
                    self._matrix = Matrix.identity(k, n) * e
                else:
                    raise TypeError("algebra is not unitary")
            elif is_Vector(elt):
                self._vector = elt.base_extend(k)
                self._matrix = Matrix(k, sum([elt[i] * A.table()[i] for i in xrange(n)]))
            elif is_Matrix(elt):
                if not A.is_unitary():
                    raise TypeError("algebra is not unitary")
                self._vector = A._one * elt
                if not check or sum([self._vector[i]*A.table()[i] for i in xrange(n)]) == elt:
                    self._matrix = elt
                else:
                    raise ValueError("matrix does not define an element of the algebra")
            else:
                raise TypeError("elt should be a vector, a matrix, " +
                                "or an element of the base field")
Example #4
0
        def __init__(self, parent, x):
            """
            Initialize ``self``.

            EXAMPLES::

                sage: F.<x,y,z> = FreeAlgebra(QQ)
                sage: J = JordanAlgebra(F)
                sage: a,b,c = map(J, F.gens())
                sage: TestSuite(a + 2*b - c).run()
            """
            self._x = x
            AlgebraElement.__init__(self, parent)
Example #5
0
        def __init__(self, parent, s, v):
            """
            Initialize ``self``.

            TESTS::

                sage: m = matrix([[0,1],[1,1]])
                sage: J.<a,b,c> = JordanAlgebra(m)
                sage: TestSuite(a + 2*b - c).run()
            """
            self._s = s
            self._v = v
            AlgebraElement.__init__(self, parent)
Example #6
0
    def __init__(self, parent, monomials):
        """
        Initialize ``self``.

        TESTS::

            sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)
            sage: dx,dy,dz = W.differentials()
            sage: elt = ((x^3-z)*dx + dy)^2
            sage: TestSuite(elt).run()
        """
        AlgebraElement.__init__(self, parent)
        self.__monomials = monomials
Example #7
0
    def __init__(self, parent):
        r"""
        Create an element of a Hecke algebra.

        EXAMPLES::

            sage: R = ModularForms(Gamma0(7), 4).hecke_algebra()
            sage: sage.modular.hecke.hecke_operator.HeckeAlgebraElement(R) # please don't do this!
            Generic element of a structure
        """
        if not algebra.is_HeckeAlgebra(parent):
            raise TypeError("parent (=%s) must be a Hecke algebra" % parent)
        AlgebraElement.__init__(self, parent)
Example #8
0
    def __init__(self, parent, monomials):
        """
        Initialize ``self``.

        TESTS::

            sage: W.<x,y,z> = DifferentialWeylAlgebra(QQ)
            sage: dx,dy,dz = W.differentials()
            sage: elt = ((x^3-z)*dx + dy)^2
            sage: TestSuite(elt).run()
        """
        AlgebraElement.__init__(self, parent)
        self.__monomials = monomials
Example #9
0
    def __init__(self, parent):
        r"""
        Create an element of a Hecke algebra.

        EXAMPLES::

            sage: R = ModularForms(Gamma0(7), 4).hecke_algebra()
            sage: sage.modular.hecke.hecke_operator.HeckeAlgebraElement(R) # please don't do this!
            Generic element of a structure
        """
        if not algebra.is_HeckeAlgebra(parent):
            raise TypeError("parent (=%s) must be a Hecke algebra"%parent)
        AlgebraElement.__init__(self, parent)
Example #10
0
        def __init__(self, parent, x):
            """
            Initialize ``self``.

            EXAMPLES::

                sage: F.<x,y,z> = FreeAlgebra(QQ)
                sage: J = JordanAlgebra(F)
                sage: a,b,c = map(J, F.gens())
                sage: TestSuite(a + 2*b - c).run()
            """
            self._x = x
            AlgebraElement.__init__(self, parent)
Example #11
0
        def __init__(self, parent, s, v):
            """
            Initialize ``self``.

            TESTS::

                sage: m = matrix([[0,1],[1,1]])
                sage: J.<a,b,c> = JordanAlgebra(m)
                sage: TestSuite(a + 2*b - c).run()
            """
            self._s = s
            self._v = v
            AlgebraElement.__init__(self, parent)
Example #12
0
    def __init__(self, parent, comp=None, name=None, latex_name=None):
        r"""
        Construct a mixed form.

        TESTS::

            sage: M = Manifold(2, 'M')
            sage: U = M.open_subset('U') ; V = M.open_subset('V')
            sage: M.declare_union(U,V)
            sage: c_xy.<x,y> = U.chart() ; c_uv.<u,v> = V.chart()
            sage: transf = c_xy.transition_map(c_uv, (x+y, x-y),
            ....:                   intersection_name='W', restrictions1= x>0,
            ....:                   restrictions2= u+v>0)
            sage: inv = transf.inverse()
            sage: e_xy = c_xy.frame(); e_uv = c_uv.frame()
            sage: omega = M.diff_form(1, name='omega')
            sage: omega[c_xy.frame(),0] = y*x
            sage: eta = M.diff_form(2, name='eta')
            sage: eta[c_uv.frame(),0,1] = u*v^2
            sage: A = M.mixed_form_algebra()
            sage: f = A([x, omega, eta], name='F')
            sage: f.add_comp_by_continuation(e_uv, V.intersection(U), c_uv)
            sage: f.add_comp_by_continuation(e_xy, V.intersection(U), c_xy)
            sage: TestSuite(f).run(skip='_test_pickling')

        """
        if parent is None:
            raise ValueError("a parent must be provided")
        # Add this element (instance) to the set of parent algebra:
        AlgebraElement.__init__(self, parent)
        # Get the underlying vector field module:
        vmodule = parent._vmodule
        # Define attributes:
        self._vmodule = vmodule
        self._dest_map = vmodule._dest_map
        self._domain = vmodule._domain
        self._ambient_domain = vmodule._ambient_domain
        self._max_deg = vmodule._ambient_domain.dim()
        # Set components:
        if comp is None:
            self._comp = [
                self._domain.diff_form(j) for j in range(self._max_deg + 1)
            ]
        else:
            self._comp = comp
        # Set names:
        self._name = name
        if latex_name is None:
            self._latex_name = self._name
        else:
            self._latex_name = latex_name
Example #13
0
    def __init__(self, parent):
        r"""
        Initialize ``self``.

        TESTS::

            sage: M = Manifold(2, 'M', structure='topological')
            sage: X.<x,y> = M.chart()
            sage: from sage.manifolds.coord_func import CoordFunction
            sage: f = CoordFunction(X.function_ring())

        """
        AlgebraElement.__init__(self, parent)
        self._nc = len(parent._chart[:])    # number of coordinates
Example #14
0
    def __init__(self, parent):
        r"""
        Initialize ``self``.

        TEST::

            sage: M = Manifold(2, 'M', structure='topological')
            sage: X.<x,y> = M.chart()
            sage: from sage.manifolds.coord_func import CoordFunction
            sage: f = CoordFunction(X.function_ring())

        """
        AlgebraElement.__init__(self, parent)
        self._nc = len(parent._chart[:])    # number of coordinates
    def __init__(self, parent, terms, prec=infinity):
        """
        Kontsevich graph series.

        Formal power series with graph sums as coefficients.

        EXAMPLES::

            sage: K = KontsevichGraphSums(QQ)
            sage: star_product_terms = {0 : K([(1, KontsevichGraph({'F' : {}, \
            ....:   'G' : {}}, ground_vertices=('F','G'), immutable=True))])}
            sage: S.<h> = KontsevichGraphSeriesRng(K, star_product_terms = \
            ....:   star_product_terms, default_prec = 0)
            sage: S(star_product_terms)
            1*(Kontsevich graph with 0 vertices on 2 ground vertices) + O(h^1)
        """
        AlgebraElement.__init__(self, parent)
        self._terms = terms
        self._prec = prec
Example #16
0
    def __init__(self, A, stream=None, order=None, aorder=None, aorder_changed=True, is_initialized=False, name=None):
        """
        EXAMPLES::

            sage: L = LazyPowerSeriesRing(QQ)
            sage: f = L()
            sage: loads(dumps(f))
            Uninitialized lazy power series
        """
        AlgebraElement.__init__(self, A)
        self._stream = stream
        self.order = unk if order is None else order
        self.aorder = unk if aorder is None else aorder
        if self.aorder == inf:
            self.order = inf
        self.aorder_changed = aorder_changed
        self.is_initialized = is_initialized
        self._zero = A.base_ring().zero()
        self._name = name
Example #17
0
 def __init__(self, parent, x=None, check=1, construct=False, **kwds):
     AlgebraElement.__init__(self, parent)
     self._parent = parent
     if x is None:
         self._coeffs = []
         return
     R = parent.base_ring()
     if isinstance(x, list):
         if check:
             self._coeffs = [R(t) for t in x]
             self.__normalize()
         else:
             self._coeffs = x
         return
     if isinstance(x, OrePolynomial):
         if x._parent is self._parent:
             x = list(x.list())
         elif R.has_coerce_map_from(x._parent):
             try:
                 if x.is_zero():
                     self._coeffs = []
                     return
             except (AttributeError, TypeError):
                 pass
             x = [x]
         else:
             self._coeffs = [R(a, **kwds) for a in x.list()]
             if check:
                 self.__normalize()
             return
     elif isinstance(x, int) and x == 0:
         self._coeffs = []
         return
     elif isinstance(x, dict):
         x = _dict_to_list(x, R.zero())
     elif not isinstance(x, list):
         x = [x]
     if check:
         self._coeffs = [R(z, **kwds) for z in x]
         self.__normalize()
     else:
         self._coeffs = x
 def __init__(self, parent, precision, coefficient_function, components, bounding_precision ) :
     r"""
     INPUT:
         - ``parent``       -- An instance of :class:~`fourier_expansion_framework.monoidpowerseries.monoidpowerseries_ambient.MonoidPowerSeriesAmbient_abstract`.
         - ``precision``    -- A filter for the parent's action.
         - ``coefficient_function`` -- A function returning for each pair of characters and
                                       monoid element a Fourier coefficients.
         - ``components``   -- ``None`` or a list of characters. A list of components that do not
                               vanish. If ``None`` no component is assumed to be zero.
     
     TESTS::
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_lazyelement import *
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_ring import *
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_basicmonoids import *
         sage: emps = EquivariantMonoidPowerSeriesRing( NNMonoid(), TrivialCharacterMonoid("1", QQ), TrivialRepresentation("1", QQ) )
         sage: h = EquivariantMonoidPowerSeries_algebraelement_lazy(emps, emps.action().filter(3), lambda (ch, k) : 1, None, None)
     """
     AlgebraElement.__init__(self, parent)
     EquivariantMonoidPowerSeries_abstract_lazy.__init__(self, parent, precision,
              coefficient_function, components, bounding_precision)
Example #19
0
 def __init__(self, parent, polynomial):
     r"""
     INPUT:
         - ``parent``     -- An instance of :class:~`fourier_expansion_framework.gradedexpansions.gradedexpansion_ring.GradedExpansionRing_class`.
         - ``polynomial`` -- A polynomial in the polynomial ring underlying the parent.
     
     TESTS::
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_basicmonoids import *
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_ring import *
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_element import *
         sage: from psage.modform.fourier_expansion_framework.gradedexpansions.gradedexpansion_grading import DegreeGrading
         sage: from psage.modform.fourier_expansion_framework.gradedexpansions.gradedexpansion_ring import *
         sage: from psage.modform.fourier_expansion_framework.gradedexpansions.gradedexpansion_element import *
         sage: mps = MonoidPowerSeriesRing(QQ, NNMonoid(False))
         sage: P.<a,b> = QQ[]
         sage: ger = GradedExpansionRing_class(Sequence([MonoidPowerSeries(mps, {1: 1}, mps.monoid().filter(4))]), Sequence([MonoidPowerSeries(mps, {1: 1, 2: 3}, mps.monoid().filter(4))]), P.ideal(a - b), DegreeGrading((1,2)))
         sage: h = GradedExpansion_class(ger, a^2)
     """
     AlgebraElement.__init__(self, parent)
     GradedExpansion_abstract.__init__(self, parent, polynomial)
Example #20
0
 def __init__(self, parent, precision, coefficient_function, components, bounding_precision ) :
     r"""
     INPUT:
         - ``parent``       -- An instance of :class:~`fourier_expansion_framework.monoidpowerseries.monoidpowerseries_ambient.MonoidPowerSeriesAmbient_abstract`.
         - ``precision``    -- A filter for the parent's action.
         - ``coefficient_function`` -- A function returning for each pair of characters and
                                       monoid element a Fourier coefficients.
         - ``components``   -- ``None`` or a list of characters. A list of components that do not
                               vanish. If ``None`` no component is assumed to be zero.
     
     TESTS::
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_lazyelement import *
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_ring import *
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_basicmonoids import *
         sage: emps = EquivariantMonoidPowerSeriesRing( NNMonoid(), TrivialCharacterMonoid("1", QQ), TrivialRepresentation("1", QQ) )
         sage: h = EquivariantMonoidPowerSeries_algebraelement_lazy(emps, emps.action().filter(3), lambda (ch, k) : 1, None, None)
     """
     AlgebraElement.__init__(self, parent)
     EquivariantMonoidPowerSeries_abstract_lazy.__init__(self, parent, precision,
              coefficient_function, components, bounding_precision)
Example #21
0
 def __init__(self, parent, polynomial) :
     r"""
     INPUT:
         - ``parent``     -- An instance of :class:~`fourier_expansion_framework.gradedexpansions.gradedexpansion_ring.GradedExpansionRing_class`.
         - ``polynomial`` -- A polynomial in the polynomial ring underlying the parent.
     
     TESTS::
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_basicmonoids import *
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_ring import *
         sage: from psage.modform.fourier_expansion_framework.monoidpowerseries.monoidpowerseries_element import *
         sage: from psage.modform.fourier_expansion_framework.gradedexpansions.gradedexpansion_grading import DegreeGrading
         sage: from psage.modform.fourier_expansion_framework.gradedexpansions.gradedexpansion_ring import *
         sage: from psage.modform.fourier_expansion_framework.gradedexpansions.gradedexpansion_element import *
         sage: mps = MonoidPowerSeriesRing(QQ, NNMonoid(False))
         sage: P.<a,b> = QQ[]
         sage: ger = GradedExpansionRing_class(Sequence([MonoidPowerSeries(mps, {1: 1}, mps.monoid().filter(4))]), Sequence([MonoidPowerSeries(mps, {1: 1, 2: 3}, mps.monoid().filter(4))]), P.ideal(a - b), DegreeGrading((1,2)))
         sage: h = GradedExpansion_class(ger, a^2)
     """
     AlgebraElement.__init__(self, parent)
     GradedExpansion_abstract.__init__(self, parent, polynomial)        
Example #22
0
    def __init__(self, parent, numerator, denominator=None, simplify=True):
        r"""
        Initialize this element.

        TESTS::

            sage: R.<t> = GF(5)[]
            sage: der = R.derivation()
            sage: A.<d> = R['d', der]
            sage: K = A.fraction_field()
            sage: f = K.random_element()

            sage: # TestSuite(f).run()
        """
        AlgebraElement.__init__(self, parent)
        ring = parent._ring
        numerator = ring(numerator)
        if denominator is None:
            denominator = ring.one()
        else:
            denominator = ring(denominator)
            if not denominator:
                raise ZeroDivisionError("denominator must be nonzero")
        # We normalize the fraction
        if numerator:
            if simplify and parent._simplification:
                D = numerator.left_gcd(denominator, monic=False)
                numerator, _ = numerator.left_quo_rem(D)
                denominator, _ = denominator.left_quo_rem(D)
            s = denominator.leading_coefficient()
            if s != 1:
                s = ~s
                numerator = s * numerator
                denominator = s * denominator
            self._numerator = numerator
            self._denominator = denominator
        else:
            self._numerator = ring.zero()
            self._denominator = ring.one()
    def __init__(self, A, x):
        """
        Create the element x of the FreeAlgebraQuotient A.

        EXAMPLES::

            sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ)
            sage: sage.algebras.free_algebra_quotient.FreeAlgebraQuotientElement(H, i)
            i
            sage: a = sage.algebras.free_algebra_quotient.FreeAlgebraQuotientElement(H, 1); a
            1
            sage: a in H
            True

        TESTS::

            sage: TestSuite(i).run()
        """
        AlgebraElement.__init__(self, A)
        Q = self.parent()

        if isinstance(x, FreeAlgebraQuotientElement) and x.parent() == Q:
            self.__vector = Q.module()(x.vector())
            return
        if isinstance(x, (Integer,) + integer_types):
            self.__vector = Q.module().gen(0) * x
            return
        elif isinstance(x, FreeModuleElement) and x.parent() is Q.module():
            self.__vector = x
            return
        elif isinstance(x, FreeModuleElement) and x.parent() == A.module():
            self.__vector = x
            return
        R = A.base_ring()
        M = A.module()
        F = A.monoid()
        B = A.monomial_basis()

        if isinstance(x, (Integer,) +  integer_types):
            self.__vector = x*M.gen(0)
        elif isinstance(x, RingElement) and not isinstance(x, AlgebraElement) and x in R:
            self.__vector = x * M.gen(0)
        elif isinstance(x, FreeMonoidElement) and x.parent() is F:
            if x in B:
                self.__vector = M.gen(B.index(x))
            else:
                raise AttributeError("Argument x (= %s) is not in monomial basis"%x)
        elif isinstance(x, list) and len(x) == A.dimension():
            try:
                self.__vector = M(x)
            except TypeError:
                raise TypeError("Argument x (= %s) is of the wrong type."%x)
        elif isinstance(x, FreeAlgebraElement) and x.parent() is A.free_algebra():
            # Need to do more work here to include monomials not
            # represented in the monomial basis.
            self.__vector = M(0)
            for m, c in six.iteritems(x._FreeAlgebraElement__monomial_coefficients):
                self.__vector += c*M.gen(B.index(m))
        elif isinstance(x, dict):
            self.__vector = M(0)
            for m, c in six.iteritems(x):
                self.__vector += c*M.gen(B.index(m))
        elif isinstance(x, AlgebraElement) and x.parent().ambient_algebra() is A:
            self.__vector = x.ambient_algebra_element().vector()
        else:
            raise TypeError("Argument x (= %s) is of the wrong type."%x)
Example #24
0
    def __init__(self, A, x):
        """
        Create the element x of the FreeAlgebraQuotient A.

        EXAMPLES::

            sage: H, (i,j,k) = sage.algebras.free_algebra_quotient.hamilton_quatalg(ZZ)
            sage: sage.algebras.free_algebra_quotient.FreeAlgebraQuotientElement(H, i)
            i
            sage: a = sage.algebras.free_algebra_quotient.FreeAlgebraQuotientElement(H, 1); a
            1
            sage: a in H
            True

        TESTS::

            sage: TestSuite(i).run()
        """
        AlgebraElement.__init__(self, A)
        Q = self.parent()

        if isinstance(x, FreeAlgebraQuotientElement) and x.parent() == Q:
            self.__vector = Q.module()(x.vector())
            return
        if isinstance(x, (int, long, Integer)):
            self.__vector = Q.module().gen(0) * x
            return
        elif isinstance(x, FreeModuleElement) and x.parent() is Q.module():
            self.__vector = x
            return
        elif isinstance(x, FreeModuleElement) and x.parent() == A.module():
            self.__vector = x
            return
        R = A.base_ring()
        M = A.module()
        F = A.monoid()
        B = A.monomial_basis()

        if isinstance(x, (int, long, Integer)):
            self.__vector = x*M.gen(0)
        elif isinstance(x, RingElement) and not isinstance(x, AlgebraElement) and x in R:
            self.__vector = x * M.gen(0)
        elif isinstance(x, FreeMonoidElement) and x.parent() is F:
            if x in B:
                self.__vector = M.gen(B.index(x))
            else:
                raise AttributeError("Argument x (= %s) is not in monomial basis"%x)
        elif isinstance(x, list) and len(x) == A.dimension():
            try:
                self.__vector = M(x)
            except TypeError:
                raise TypeError("Argument x (= %s) is of the wrong type."%x)
        elif isinstance(x, FreeAlgebraElement) and x.parent() is A.free_algebra():
            # Need to do more work here to include monomials not
            # represented in the monomial basis.
            self.__vector = M(0)
            for m, c in six.iteritems(x._FreeAlgebraElement__monomial_coefficients):
                self.__vector += c*M.gen(B.index(m))
        elif isinstance(x, dict):
            self.__vector = M(0)
            for m, c in six.iteritems(x):
                self.__vector += c*M.gen(B.index(m))
        elif isinstance(x, AlgebraElement) and x.parent().ambient_algebra() is A:
            self.__vector = x.ambient_algebra_element().vector()
        else:
            raise TypeError("Argument x (= %s) is of the wrong type."%x)