def __init__(self, p, a, b, s, t, sign): r""" Construct the similarity (x,y) mapsto (ax-by+s,bx+ay+t) if sign=1, and (ax+by+s,bx-ay+t) if sign=-1 """ if p is None: raise ValueError("The parent must be provided") if parent(a) is not p.base_ring(): raise ValueError("wrong parent for a") if parent(b) is not p.base_ring(): raise ValueError("wrong parent for b") if parent(s) is not p.base_ring(): raise ValueError("wrong parent for s") if parent(t) is not p.base_ring(): raise ValueError("wrong parent for t") if parent(sign) is not ZZ or not sign.is_unit(): raise ValueError("sign must be either 1 or -1.") self._a = a self._b = b self._s = s self._t = t self._sign = sign MultiplicativeGroupElement.__init__(self, p)
def __init__(self, F, x): """ Create the element x of the AbelianGroup F. EXAMPLES:: sage: F = AbelianGroup(5, [3,4,5,8,7], 'abcde') sage: a, b, c, d, e = F.gens() sage: a^2 * b^3 * a^2 * b^-4 a*b^3 sage: b^-11 b sage: a^-11 a sage: a*b in F True """ MultiplicativeGroupElement.__init__(self, F) self.__repr = None n = F.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 AbelianGroup F. EXAMPLES:: sage: F = AbelianGroup(5, [3,4,5,8,7], 'abcde') sage: a, b, c, d, e = F.gens() sage: a^2 * b^3 * a^2 * b^-4 a*b^3 sage: b^-11 b sage: a^-11 a sage: a*b in F True """ MultiplicativeGroupElement.__init__(self, F) self.__repr = None n = F.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, parent, rdict): r""" Create an eta product object. Usually called implicitly via EtaGroup_class.__call__ or the EtaProduct factory function. EXAMPLES:: sage: EtaGroupElement(EtaGroup(8), {1:24, 2:-24}) Eta product of level 8 : (eta_1)^24 (eta_2)^-24 sage: g = _; g == loads(dumps(g)) True """ MultiplicativeGroupElement.__init__(self, parent) self._N = self.parent().level() N = self._N if isinstance(rdict, EtaGroupElement): rdict = rdict._rdict # Note: This is needed because the "x in G" test tries to call G(x) # and see if it returns an error. So sometimes this will be getting # called with rdict being an eta product, not a dictionary. if rdict == 1: rdict = {} # Check Ligozat criteria sumR = sumDR = sumNoverDr = 0 prod = 1 for d in rdict.keys(): if N % d: raise ValueError("%s does not divide %s" % (d, N)) for d in rdict.keys(): if rdict[d] == 0: rdict.pop(d) continue sumR += rdict[d] sumDR += rdict[d] * d sumNoverDr += rdict[d] * N / d prod *= (N / d)**rdict[d] if sumR != 0: raise ValueError("sum r_d (=%s) is not 0" % sumR) if (sumDR % 24) != 0: raise ValueError("sum d r_d (=%s) is not 0 mod 24" % sumDR) if (sumNoverDr % 24) != 0: raise ValueError("sum (N/d) r_d (=%s) is not 0 mod 24" % sumNoverDr) if not is_square(prod): raise ValueError("product (N/d)^(r_d) (=%s) is not a square" % prod) self._sumDR = sumDR # this is useful to have around self._rdict = rdict self._keys = rdict.keys() # avoid factoring N every time
def __init__(self, parent, polys, edge, edge_rev, check=True, reduced=False): self._polys = tuple(polys) self._edges = tuple(edge) self._edges_rev = tuple(edge_rev) MultiplicativeGroupElement.__init__(self, parent) if not reduced: self._reduce() if check: self._check()
def __init__(self, parent, a, b, s, t): r'''Construct the similarity (x,y) mapsto (ax-by+s,bx+ay+t).''' if parent is None: raise ValueError("The parent must be provided") self._a=a self._b=b self._s=s self._t=t self._parent=parent MultiplicativeGroupElement.__init__(self,parent)
def __init__(self, parent, rdict): r""" Create an eta product object. Usually called implicitly via EtaGroup_class.__call__ or the EtaProduct factory function. EXAMPLE:: sage: EtaGroupElement(EtaGroup(8), {1:24, 2:-24}) Eta product of level 8 : (eta_1)^24 (eta_2)^-24 sage: g = _; g == loads(dumps(g)) True """ MultiplicativeGroupElement.__init__(self, parent) self._N = self.parent().level() N = self._N if isinstance(rdict, EtaGroupElement): rdict = rdict._rdict # Note: This is needed because the "x in G" test tries to call G(x) # and see if it returns an error. So sometimes this will be getting # called with rdict being an eta product, not a dictionary. if rdict == 1: rdict = {} # Check Ligozat criteria sumR = sumDR = sumNoverDr = 0 prod = 1 for d in rdict.keys(): if N % d: raise ValueError("%s does not divide %s" % (d, N)) for d in rdict.keys(): if rdict[d] == 0: rdict.pop(d) continue sumR += rdict[d] sumDR += rdict[d]*d sumNoverDr += rdict[d]*N/d prod *= (N/d)**rdict[d] if sumR != 0: raise ValueError("sum r_d (=%s) is not 0" % sumR) if (sumDR % 24) != 0: raise ValueError("sum d r_d (=%s) is not 0 mod 24" % sumDR) if (sumNoverDr % 24) != 0: raise ValueError("sum (N/d) r_d (=%s) is not 0 mod 24" % sumNoverDr) if not is_square(prod): raise ValueError("product (N/d)^(r_d) (=%s) is not a square" % prod) self._sumDR = sumDR # this is useful to have around self._rdict = rdict self._keys = rdict.keys() # avoid factoring N every time
def __init__(self, parent, **kwds): r""" Initialize ``self``. TESTS:: sage: L.<X,Y,Z> = LieAlgebra(QQ, 2, step=2) sage: G = L.lie_group() sage: g = G.exp(X) sage: TestSuite(g).run() """ MultiplicativeGroupElement.__init__(self, parent) DifferentiableManifold.Element.__init__(self, parent, **kwds)
def __init__(self, parent, colors, perm): """ Initialize ``self``. TESTS:: sage: C = ColoredPermutations(4, 3) sage: s1,s2,t = C.gens() sage: TestSuite(s1*s2*t).run() """ self._colors = tuple(colors) self._perm = perm MultiplicativeGroupElement.__init__(self, parent=parent)
def __init__(self, parent, x): r""" This should not be called directly EXAMPLES:: sage: from sage.combinat.root_system.fundamental_group import FundamentalGroupOfExtendedAffineWeylGroup sage: x = FundamentalGroupOfExtendedAffineWeylGroup(['A',4,1], prefix="f").an_element() sage: TestSuite(x).run() """ if x not in parent.special_nodes(): raise ValueError("%s is not a special node" % x) self._value = x MultiplicativeGroupElement.__init__(self, parent)
def __init__(self, parent, i, r, q): if parent is None: raise ValueError("The parent must be provided") # I should assert that the element lives in the domain of the group. assert i in ZZ assert r in _Q # Actually q should be in {1,-1,-i,i,j,-j,k,-k}. I'm not testing for that. assert q in _Q # There is one more condition. The group doesn't have full image... self._i=i self._r=r self._q=q self._parent=parent MultiplicativeGroupElement.__init__(self,parent)
def __init__(self, parent, a, b, s, t, sign): r'''Construct the similarity (x,y) mapsto (ax-by+s,bx+ay+t) if sign=1, and (ax+by+s,bx-ay+t) if sign=-1 ''' if parent is None: raise ValueError("The parent must be provided") self._a=a self._b=b self._s=s self._t=t if not (sign==1 or sign==-1): raise ValueError("sign must be either 1 or -1.") self._sign=sign self._parent=parent MultiplicativeGroupElement.__init__(self,parent)
def __init__(self, parent, word_rep=None, quaternion_rep=None, check=False): r''' Initialize. INPUT: - a list of the form [(g1,a1),(g2,a2),...,(gn,an)] where the gi are indices refering to fixed generators, and the ai are integers, or an element of the quaternion algebra ``self.parent().quaternion_algebra()``. ''' MultiplicativeGroupElement.__init__(self, parent) init_data = False self.has_word_rep = False self.has_quaternion_rep = False if word_rep is not None: self.word_rep = word_rep self.has_word_rep = True init_data = True if quaternion_rep is not None: if check: if not parent._is_in_order(quaternion_rep): raise ValueError('Quaternion (= %s) must be in order' % quaternion_rep) if parent.base_field() == QQ: rednrm = quaternion_rep.reduced_norm() if self.parent( ).discriminant != 1 else quaternion_rep.determinant() if rednrm != 1: raise ValueError('Quaternion must be of norm 1') else: rednrm = quaternion_rep.reduced_norm() if not rednrm.is_integral() or not (1 / rednrm).is_integral(): raise ValueError('Quaternion must be of unit norm') if self.has_word_rep: self.check_consistency(quaternion_rep, self.word_rep) self.quaternion_rep = quaternion_rep set_immutable(self.quaternion_rep) self.has_quaternion_rep = True init_data = True if init_data is False: raise ValueError('Must pass either quaternion_rep or word_rep')
def __init__(self, parent, *args): r''' Construct the translation (x,y) mapsto (x+s,y+t). Arguments: The first argument must be the parent. If there is one additional argument (call it a) then s=a[0] and t=a[1]. If there are two elements, these perscribe s and t. ''' if parent is None: raise ValueError("The parent must be provided") if len(args)==1: self._s=args[0][0] self._t=args[0][1] if len(args)==2: self._s=args[0] self._t=args[1] self._parent=parent MultiplicativeGroupElement.__init__(self,parent)
def __init__(self, parent, exponents): """ Create an element. EXAMPLES:: sage: F = AbelianGroup(3,[7,8,9]) sage: Fd = F.dual_group(names="ABC") sage: A,B,C = Fd.gens() sage: A*B^-1 in Fd True """ MultiplicativeGroupElement.__init__(self, parent) n = parent.ngens() if exponents == 1: self._exponents = tuple( ZZ.zero() for i in range(n) ) else: self._exponents = tuple( ZZ(e) for e in exponents ) if len(self._exponents) != n: raise IndexError('argument length (= %s) must be %s.'%(len(exponents), n))
def __init__(self, p, a, b, s, t, sign): r""" Construct the similarity (x,y) mapsto (ax-by+s,bx+ay+t) if sign=1, and (ax+by+s,bx-ay+t) if sign=-1 """ if p is None: raise ValueError("The parent must be provided") field = p._field if parent(a) is not field or \ parent(b) is not field or \ parent(s) is not field or \ parent(t) is not field: raise ValueError("wrong parent for a,b,s or t") self._a = a self._b = b self._s = s self._t = t if parent(sign) is not ZZ or not sign.is_unit(): raise ValueError("sign must be either 1 or -1.") self._sign = sign MultiplicativeGroupElement.__init__(self, p)
def __init__(self, parent, exponents): """ Create an element. EXAMPLES:: sage: F = AbelianGroup(3,[7,8,9]) sage: Fd = F.dual_group(names="ABC") sage: A,B,C = Fd.gens() sage: A*B^-1 in Fd True """ MultiplicativeGroupElement.__init__(self, parent) n = parent.ngens() if exponents == 1: self._exponents = tuple(ZZ.zero() for i in range(n)) else: self._exponents = tuple(ZZ(e) for e in exponents) if len(self._exponents) != n: raise IndexError('argument length (= %s) must be %s.' % (len(exponents), n))
def __init__(self, parent, x, check=True): """ Create an element of an arithmetic subgroup. INPUT: - parent - an arithmetic subgroup - x - data defining a 2x2 matrix over ZZ which lives in parent - check - if True, check that parent is an arithmetic subgroup, and that x defines a matrix of determinant 1 We tend not to create elements of arithmetic subgroups that aren't SL2Z, in order to avoid coercion issues (that is, the other arithmetic subgroups are "facade parents"). EXAMPLES:: sage: G = Gamma0(27) sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [4,1,27,7]) [ 4 1] [27 7] sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(Integers(3), [4,1,27,7]) Traceback (most recent call last): ... TypeError: parent (= Ring of integers modulo 3) must be an arithmetic subgroup sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [2,0,0,2]) Traceback (most recent call last): ... TypeError: matrix must have determinant 1 sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [2,0,0,2], check=False) [2, 0, 0, 2] sage: x = Gamma0(11)([2,1,11,6]) sage: x == loads(dumps(x)) True sage: x = Gamma0(5).0 sage: SL2Z(x) [1 1] [0 1] sage: x in SL2Z True """ if check: if not is_ArithmeticSubgroup(parent): raise TypeError, "parent (= %s) must be an arithmetic subgroup"%parent x = mi2x2(M2Z, x, copy=True, coerce=True) if x.determinant() != 1: raise TypeError, "matrix must have determinant 1" try: x.set_immutable() except AttributeError: pass MultiplicativeGroupElement.__init__(self, parent) self.__x = x
def __init__(self, parent, x, check=True): """ Create an element of an arithmetic subgroup. INPUT: - parent - an arithmetic subgroup - x - data defining a 2x2 matrix over ZZ which lives in parent - check - if True, check that parent is an arithmetic subgroup, and that x defines a matrix of determinant 1 We tend not to create elements of arithmetic subgroups that aren't SL2Z, in order to avoid coercion issues (that is, the other arithmetic subgroups are "facade parents"). EXAMPLES:: sage: G = Gamma0(27) sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [4,1,27,7]) [ 4 1] [27 7] sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(Integers(3), [4,1,27,7]) Traceback (most recent call last): ... TypeError: parent (= Ring of integers modulo 3) must be an arithmetic subgroup sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [2,0,0,2]) Traceback (most recent call last): ... TypeError: matrix must have determinant 1 sage: sage.modular.arithgroup.arithgroup_element.ArithmeticSubgroupElement(G, [2,0,0,2], check=False) [2, 0, 0, 2] sage: x = Gamma0(11)([2,1,11,6]) sage: x == loads(dumps(x)) True sage: x = Gamma0(5).0 sage: SL2Z(x) [1 1] [0 1] sage: x in SL2Z True """ if check: if not is_ArithmeticSubgroup(parent): raise TypeError, "parent (= %s) must be an arithmetic subgroup" % parent x = mi2x2(M2Z, x, copy=True, coerce=True) if x.determinant() != 1: raise TypeError, "matrix must have determinant 1" try: x.set_immutable() except AttributeError: pass MultiplicativeGroupElement.__init__(self, parent) self.__x = x