def __init__(self, F, X): """ Create an element X of the DualAbelianGroup of F. EXAMPLES: sage: F = AbelianGroup(3,[7,8,9]) sage: Fd = DualAbelianGroup(F,names="ABC") sage: A,B,C = Fd.gens() sage: A*B^-1 in Fd True """ MonoidElement.__init__(self, F) self.__repr = None G = F.group() n = G.ngens() if isinstance(X, (int, Integer)) and X == 1: self.__element_vector = [0 for i in range(n)] elif isinstance(X, list): if len(X) != n: raise IndexError, \ "Argument length (= %s) must be %s."%(len(X), n) self.__element_vector = X else: raise TypeError, "Argument X (= %s) is of wrong type." % X
def __init__(self, F, x): """ Create the element x of the FreeAbelianMonoid F. EXAMPLES:: sage: F = FreeAbelianMonoid(5, 'abcde') sage: F Free abelian monoid on 5 generators (a, b, c, d, e) sage: F(1) 1 sage: a, b, c, d, e = F.gens() sage: a^2 * b^3 * a^2 * b^4 a^4*b^7 sage: F = FreeAbelianMonoid(5, 'abcde') sage: a, b, c, d, e = F.gens() sage: a in F True sage: a*b in F True """ MonoidElement.__init__(self, F) n = F.ngens() if isinstance(x, integer_types + (Integer,)) and x == 1: self._element_vector = tuple([0]*n) elif isinstance(x, (list, tuple)): if len(x) != n: raise IndexError("argument length (= %s) must be %s"%(len(x), n)) self._element_vector = tuple(x) else: raise TypeError("argument x (= %s) is of wrong type"%x)
def __init__(self, F, X): """ Create an element X of the DualAbelianGroup of F. EXAMPLES: sage: F = AbelianGroup(3,[7,8,9]) sage: Fd = DualAbelianGroup(F,names="ABC") sage: A,B,C = Fd.gens() sage: A*B^-1 in Fd True """ MonoidElement.__init__(self, F) self.__repr = None G = F.group() n = G.ngens() if isinstance(X, (int, Integer)) and X == 1: self.__element_vector = [ 0 for i in range(n) ] elif isinstance(X, list): if len(X) != n: raise IndexError, \ "Argument length (= %s) must be %s."%(len(X), n) self.__element_vector = X else: raise TypeError, "Argument X (= %s) is of wrong type."%X
def __init__(self, F, x): """ Create the element x of the FreeAbelianMonoid F. EXAMPLES:: sage: F = FreeAbelianMonoid(5, 'abcde') sage: F Free abelian monoid on 5 generators (a, b, c, d, e) sage: F(1) 1 sage: a, b, c, d, e = F.gens() sage: a^2 * b^3 * a^2 * b^4 a^4*b^7 sage: F = FreeAbelianMonoid(5, 'abcde') sage: a, b, c, d, e = F.gens() sage: a in F True sage: a*b in F True """ MonoidElement.__init__(self, F) n = F.ngens() if isinstance(x, integer_types + (Integer, )) and x == 1: self._element_vector = tuple([0] * n) elif isinstance(x, (list, tuple)): if len(x) != n: raise IndexError("argument length (= %s) must be %s" % (len(x), n)) self._element_vector = tuple(x) else: raise TypeError("argument x (= %s) is of wrong type" % x)
def __init__(self, F, x): """ Create the element x of the FreeAbelianMonoid F. EXAMPLES:: sage: F = FreeAbelianMonoid(5, 'abcde') sage: F Free abelian monoid on 5 generators (a, b, c, d, e) sage: F(1) 1 sage: a, b, c, d, e = F.gens() sage: a^2 * b^3 * a^2 * b^4 a^4*b^7 sage: F = FreeAbelianMonoid(5, 'abcde') sage: a, b, c, d, e = F.gens() sage: a in F True sage: a*b in F True """ MonoidElement.__init__(self, F) self.__repr = None n = F.ngens() if isinstance(x, (int, long, Integer)) and x == 1: self.__element_vector = [0 for i in range(n)] elif isinstance(x, list): if len(x) != n: raise IndexError("Argument length (= %s) must be %s." % (len(x), n)) self.__element_vector = x else: raise TypeError("Argument x (= %s) is of wrong type." % x)
def __init__(self, ring, gens, coerce=True): """ Initialize this ideal. INPUT: - ``ring`` -- A ring - ``gens`` -- The generators for this ideal - ``coerce`` -- (default: ``True``) If ``gens`` needs to be coerced into ``ring``. EXAMPLES:: sage: R.<x> = ZZ[] sage: R.ideal([4 + 3*x + x^2, 1 + x^2]) Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring """ self.__ring = ring if not isinstance(gens, (list, tuple)): gens = [gens] if coerce: gens = [ring(x) for x in gens] gens = tuple(gens) if len(gens)==0: gens=(ring.zero(),) self.__gens = gens MonoidElement.__init__(self, ring.ideal_monoid())
def __init__(self, F, x, check=True): """ Create the element `x` of the FreeMonoid `F`. This should typically be called by a FreeMonoid. """ MonoidElement.__init__(self, F) if isinstance(x, (int, long, Integer)): if x == 1: self._element_list = [] else: raise TypeError("Argument x (= %s) is of the wrong type."%x) elif isinstance(x, list): if check: x2 = [] for v in x: if not isinstance(v, tuple) and len(v) == 2: raise TypeError("x (= %s) must be a list of 2-tuples or 1."%x) if not (isinstance(v[0], (int,long,Integer)) and \ isinstance(v[1], (int,long,Integer))): raise TypeError("x (= %s) must be a list of 2-tuples of integers or 1."%x) if len(x2) > 0 and v[0] == x2[len(x2)-1][0]: x2[len(x2)-1] = (v[0], v[1]+x2[len(x2)-1][1]) else: x2.append(v) self._element_list = x2 else: self._element_list = list(x) # make copy, so user can't accidentally change monoid. else: # TODO: should have some other checks here... raise TypeError("Argument x (= %s) is of the wrong type."%x)
def __init__(self, F, x): """ Create the element x of the FreeAbelianMonoid F. EXAMPLES:: sage: F = FreeAbelianMonoid(5, 'abcde') sage: F Free abelian monoid on 5 generators (a, b, c, d, e) sage: F(1) 1 sage: a, b, c, d, e = F.gens() sage: a^2 * b^3 * a^2 * b^4 a^4*b^7 sage: F = FreeAbelianMonoid(5, 'abcde') sage: a, b, c, d, e = F.gens() sage: a in F True sage: a*b in F True """ MonoidElement.__init__(self, F) self.__repr = None n = F.ngens() if isinstance(x, (int, long, Integer)) and x == 1: self.__element_vector = [ 0 for i in range(n) ] elif isinstance(x, list): if len(x) != n: raise IndexError("Argument length (= %s) must be %s."%(len(x), n)) self.__element_vector = x else: raise TypeError("Argument x (= %s) is of wrong type."%x)
def __init__(self, F, x, check=True): """ Create the element `x` of the FreeMonoid `F`. This should typically be called by a FreeMonoid. """ MonoidElement.__init__(self, F) if isinstance(x, (int, long, Integer)): if x == 1: self._element_list = [] else: raise TypeError, "Argument x (= %s) is of the wrong type."%x elif isinstance(x, list): if check: x2 = [] for v in x: if not isinstance(v, tuple) and len(v) == 2: raise TypeError, "x (= %s) must be a list of 2-tuples or 1."%x if not (isinstance(v[0], (int,long,Integer)) and \ isinstance(v[1], (int,long,Integer))): raise TypeError, "x (= %s) must be a list of 2-tuples of integers or 1."%x if len(x2) > 0 and v[0] == x2[len(x2)-1][0]: x2[len(x2)-1] = (v[0], v[1]+x2[len(x2)-1][1]) else: x2.append(v) self._element_list = x2 else: self._element_list = list(x) # make copy, so user can't accidentally change monoid. else: # TODO: should have some other checks here... raise TypeError, "Argument x (= %s) is of the wrong type."%x
def __init__(self, ring, gens, coerce=True): """ Initialize this ideal. INPUT: - ``ring`` -- A ring - ``gens`` -- The generators for this ideal - ``coerce`` -- (default: ``True``) If ``gens`` needs to be coerced into ``ring``. EXAMPLES:: sage: R.<x> = ZZ[] sage: R.ideal([4 + 3*x + x^2, 1 + x^2]) Ideal (x^2 + 3*x + 4, x^2 + 1) of Univariate Polynomial Ring in x over Integer Ring """ self.__ring = ring if not isinstance(gens, (list, tuple)): gens = [gens] if coerce: gens = [ring(x) for x in gens] gens = tuple(gens) if len(gens) == 0: gens = (ring.zero(), ) self.__gens = gens MonoidElement.__init__(self, ring.ideal_monoid())
def __init__(self, parent, mat): r""" EXAMPLES:: sage: from sage.modular.pollack_stevens.sigma0 import Sigma0 sage: s = Sigma0(3)([1,4,3,3]) # indirect doctest sage: TestSuite(s).run() """ self._mat = mat MonoidElement.__init__(self, parent)
def __init__(self, ring, gens, coerce=True): self.__ring = ring if not isinstance(gens, (list, tuple)): gens = [gens] if coerce: gens = [ring(x) for x in gens] gens = tuple(gens) if len(gens)==0: gens=(ring.zero_element(),) self.__gens = gens MonoidElement.__init__(self, ring.ideal_monoid())
def __init__(self, parent, x): r""" Initialise elements. Input should be pair of elements of Sigma_0(p), as given by Pollack's code. Input: - parent : Sigma0Squared object in which this lives - x : tuple of two elements in underlying Sigma0 """ ## This is a child of the Sigma0Squared object chosen MonoidElement.__init__(self, parent) self._val = x self._g1 = x[0] self._g2 = x[1]
def __init__(self, parent, data, check=False): r""" INPUT: - ``parent`` - a free group - ``data`` - the data to be used - ``check`` - wether to check the consistency of the input is checked (default is ``True`` but it is much faster if ``check`` is set to ``False``) """ MonoidElement.__init__(self, parent) if check: self._data = list(data) self._check_alphabet() self._reduce() else: assert isinstance(data, list) self._data = data
def __init__(self, F, x): """ Create the element ``x`` of an indexed free abelian monoid ``F``. EXAMPLES:: sage: F = FreeAbelianMonoid(index_set=ZZ) sage: F.gen(1) F[1] sage: a,b,c,d,e = [F.gen(i) for i in range(5)] sage: x = a^2 * b^3 * a^2 * b^4; x F[0]^4*F[1]^7 sage: TestSuite(x).run() sage: F = FreeMonoid(index_set=tuple('abcde')) sage: a,b,c,d,e = F.gens() sage: a in F True sage: a*b in F True sage: TestSuite(a*d^2*e*c*a).run() """ MonoidElement.__init__(self, F) self._monomial = x
def __pow__(self, n): r""" Raise this element to the power n. EXAMPLE:: sage: K.<a> = NumberField(x^3 - 3*x + 8) sage: C=K.class_group() sage: c = C(2, a) sage: c^2 Fractional ideal class (2, a^2 + 2*a - 1) sage: c^3 Trivial principal fractional ideal class sage: c^1000 Fractional ideal class (2, a) sage: (c^2)^2 Fractional ideal class (2, a) """ # We use MonoidElement's __pow__ routine, since that does # repeated squaring, and hence the ideal gets reduced as # we go along; actually computing self._value ** n would # be disastrous. n = n % self.order() return MonoidElement.__pow__(self, n)
def __pow__(self, n): r""" Raise this element to the power n. EXAMPLES:: sage: K.<a> = NumberField(x^3 - 3*x + 8) sage: C=K.class_group() sage: c = C(2, a) sage: c^2 Fractional ideal class (4, a) sage: c^3 Trivial principal fractional ideal class sage: c^1000 Fractional ideal class (2, a) sage: (c^2)^2 Fractional ideal class (2, a) """ # We use MonoidElement's __pow__ routine, since that does # repeated squaring, and hence the ideal gets reduced as # we go along; actually computing self._value ** n would # be disastrous. n = n % self.order() return MonoidElement.__pow__(self, n)
def __init__(self, parent, path, check=True): """ Creates a path object. Type ``QuiverPath?`` for more information. TESTS:: sage: from sage.quivers.paths import QuiverPath sage: Q = DiGraph({1:{2:['a']}, 2:{3:['b']}}).path_semigroup() sage: p = Q([(1, 1), (1, 1)]) sage: Q([(1,3,'x')]) Traceback (most recent call last): ... ValueError: Cannot interpret [(1, 3, 'x')] as element of Partial semigroup formed by the directed paths of Multi-digraph on 3 vertices Note that QuiverPath should not be called directly, because the elements of the path semigroup associated with a quiver use a sub-class of QuiverPath. Nonetheless, just for test, we show that it *is* possible to create a path in a deprecated way:: sage: p == QuiverPath(Q, (1, 1)) True sage: Q([(1, 1), (1, 2, 'a'), (2, 2), (2, 3, 'b'), (3, 3)])._path ((1, 2, 'a'), (2, 3, 'b')) """ MonoidElement.__init__(self, parent=parent) # Normalise the given path, unless it is asserted that the input is # fine if not check: self._path = tuple(path) return if path == 1: # We do not guarantee that there is only one vertex. # However, this element certainly exists. v = parent.quiver().vertices()[0] self._path = ((v,v),) return E = parent.quiver().edges() if isinstance(path, QuiverPath): if path.parent() is parent: self._path = path._path return new_path = list(path._path) # A tuple is assumed to be an edge, anything else is assumed to be a # list of edges elif isinstance(path, tuple): new_path = [path] else: new_path = list(path) # Check that each edge in the path is valid good = True for x in new_path: if (len(x) < 2 or x[0] not in ZZ or x[1] not in ZZ or len(x) == 2 and x[0] != x[1] or len(x) == 3 and x not in E or len(x) > 3): good = False break if not good: raise ValueError("Cannot interpret %s as element of %s"%(path,parent)) # Delete trivial edges, and clear the path if not valid i = 0 while i + 1 < len(new_path): if new_path[i][1] != new_path[i + 1][0]: raise ValueError("Cannot interpret %s as element of %s"%(path,parent)) elif len(new_path[i])!=3: del new_path[i] else: i += 1 if len(new_path) > 1 and len(new_path[-1])!=3: del new_path[-1] self._path = tuple(new_path)