# Ticket #5848: untabify.patch

File untabify.patch, 222.1 KB (added by jhpalmieri, 12 years ago)
• ## sage/algebras/algebra_order.py

# HG changeset patch
# User John H. Palmieri <palmieri@math.washington.edu>
# Date 1240353484 25200
# Node ID 203bbc5a8a5f0e862e4459b7f6f241db61bc2e8e
# Parent  84d47cdd70031673e4000de43c4582938656f12e
untabify

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/algebras/algebra_order.py
 a def __contains__(self, x): if isinstance(x, AlgebraOrderElement) and x.parent() is self: return True return True elif isinstance(x, AlgebraElement) \ and x.parent() is self.ambient_algebra(): M = self.inverse_embedding_matrix() M = MatrixSpace(K,n) self.__embedding_matrix = M([ x.ambient_algebra_element().vector() for x in self.basis() ]) return self.__embedding_matrix def inverse_embedding_matrix(self): r""" Return the inverse of the $n\times n$ matrix whose rows are return self.__inverse_embedding_matrix except ZeroDivisionError: raise AttributeError, "Basis for quaternion order is not of full rank." def module(self): r""" Convert this algebra order into a module over the base ring.
• ## sage/algebras/algebra_order_element.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/algebras/algebra_order_element.py
 a """ The trace of the element with respect to its action by left or right multiplication on the order. """ """ R = self.parent().base_ring() return R(self.__ambient_algebra_element.trace()) def norm(self): """ The determinant (= norm) of the element with respect to its action by left or right multiplication on the order. """ """ R = self.parent().base_ring() return R(self.__ambient_algebra_element.norm()) """ The characteristic polynomial of the element with respect to its action by left or right multiplication on the order. """ """ R = self.parent().base_ring() P = PolynomialRing(R, var) return P(self.__ambient_algebra_element.charpoly('x')) """ The minimal polynomial of the element with respect to its action by left or right multiplication on the order. """ """ R = self.parent().base_ring() P = PolynomialRing(R, var) return P(self.__element.minpoly())
• ## sage/algebras/algebra_order_ideal.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/algebras/algebra_order_ideal.py
 a return AlgebraOrderIdealElement(self, x, check=check) def __contains__(self, x): if isinstance(x, AlgebraOrderIdealElement) and x.parent() is self: return True if isinstance(x, AlgebraOrderIdealElement) and x.parent() is self: return True elif isinstance(x, AlgebraElement) \ and x.parent() is self.ambient_algebra(): return NotImplementedError
• ## sage/algebras/group_algebra.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/algebras/group_algebra.py
 a self.group(), an element of self.base_ring(), or an element of self.group(). -- check (boolean): whether or not to check that the given elements really do lie in self.group(). Chiefly provided to speed up arithmetic operations with elements that have already been checked to lie in the group. really do lie in self.group(). Chiefly provided to speed up arithmetic operations with elements that have already been checked to lie in the group. OUTPUT: -- a GroupAlgebraElement instance whose parent is self.
• ## sage/algebras/quatalg/quaternion_algebra_element.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/algebras/quatalg/quaternion_algebra_element.pyx
 a """ #return 2*self[0] mpz_mul_si(U1, self.x, 2) mpz_mul_si(U1, self.x, 2) cdef Rational result = PY_NEW(Rational) mpq_set_num(result.value, U1) mpq_set_den(result.value, self.d)
• ## sage/calculus/calculus.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/calculus/calculus.py
 a return z def is_field(self): """ """ Returns True, since the callable symbolic expression ring is (for the most part) a field. sage: g.parent().is_field() True """ return True return True def _an_element_impl(self): """
• ## sage/coding/guava.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/coding/guava.py
 a sage: C.minimum_distance() 4 sage: C.gen_mat() [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1] [0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1] [0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1] [0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1] [0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1] [0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1] [0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1] [0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1] [0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1] [0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1] [0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1] [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1] [0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1] [0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1] [0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1] [0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1] [0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1] [0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1] [0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1] [0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1] [0 0 0 0 0 1 0 1 0 0 0 0 0 1 0 1] [0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1] AUTHOR: David Joyner (11-2005) """
• ## sage/coding/linear_code.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/coding/linear_code.py
 a sage: v = vector(GF(5),[1,0,0,2,1,0]) sage: C.decode(v) (2, 0, 0, 2, 1, 0) sage: F = GF(4,"a") sage: C = HammingCode(2,F) sage: v = vector(F, [1,0,0,a,1]) sage: C.decode(v) (1, 0, 0, 1, 1) sage: C.decode(v, method="nearest neighbor") (1, 0, 0, 1, 1) sage: C.decode(v, method="guava") (1, 0, 0, 1, 1) sage: F = GF(4,"a") sage: C = HammingCode(2,F) sage: v = vector(F, [1,0,0,a,1]) sage: C.decode(v) (1, 0, 0, 1, 1) sage: C.decode(v, method="nearest neighbor") (1, 0, 0, 1, 1) sage: C.decode(v, method="guava") (1, 0, 0, 1, 1) Does not work for very long codes since the syndrome table grows too large. else: c0 = QQ((n-d)*C.spectrum()[d])/rising_factorial(n-d0-1,d0+2) if i==3 or i==4: if d>d0: if d>d0: c0 = rising_factorial(d-d0,d0+1)*C.spectrum()[d]/((q-1)*rising_factorial(n-d0,d0+1)) else: c0 = C.spectrum()[d]/((q-1)*rising_factorial(n-d0,d0+1))
• ## sage/combinat/crystals/crystals.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/crystals/crystals.py
 a return self.cartan_type().root_system().ambient_space() def cartan_type(self): """ Returns the Cartan type of the associated crystal """ Returns the Cartan type of the associated crystal EXAMPLES:: EXAMPLES:: sage: C = CrystalOfLetters(['A',2]) sage: C.cartan_type() ['A', 2] sage: C.cartan_type() ['A', 2] """ return self._cartan_type return self._cartan_type def index_set(self): """ Returns the index set of the Dynkin diagram underlying the given crystal """ Returns the index set of the Dynkin diagram underlying the given crystal EXAMPLES: sage: C = CrystalOfLetters(['A', 5]) sage: C.index_set() [1, 2, 3, 4, 5] EXAMPLES: sage: C = CrystalOfLetters(['A', 5]) sage: C.index_set() [1, 2, 3, 4, 5] """ return self.cartan_type().index_set() return self.cartan_type().index_set() def Lambda(self): """ hlist = {} mlist = {} for x in self.highest_weight_vectors(): for x in self.highest_weight_vectors(): k = x.weight() if k in hlist: hlist[k] += 1 return self.parent().index_set() def cartan_type(self): """ Returns the cartan type associated to self """ Returns the cartan type associated to self EXAMPLES:: sage: C = CrystalOfLetters(['A', 5]) sage: C(1).cartan_type() ['A', 5] EXAMPLES:: sage: C = CrystalOfLetters(['A', 5]) sage: C(1).cartan_type() ['A', 5] """ return self.parent().cartan_type() return self.parent().cartan_type() def weight(self): """ sage: C(1).weight() (1, 0, 0, 0, 0, 0) """ return self.Phi() - self.Epsilon() return self.Phi() - self.Epsilon() def e(self, i): r""" (1, 0, 0, 0, 0, 0) """ Lambda = self.parent().Lambda() return sum(self.epsilon(i) * Lambda[i] for i in self.index_set()) return sum(self.epsilon(i) * Lambda[i] for i in self.index_set()) def Phi(self): """ (1, 1, 0, 0, 0, 0) """ Lambda = self.parent().Lambda() return sum(self.phi(i) * Lambda[i] for i in self.index_set()) return sum(self.phi(i) * Lambda[i] for i in self.index_set()) def s(self, i): r""" Returns the reflection of self along its i-string EXAMPLES:: sage: C = CrystalOfTableaux(['A',2], shape=[2,1]) sage: b=C(rows=[[1,1],[3]]) sage: b.s(1) [[2, 2], [3]] sage: b=C(rows=[[1,2],[3]]) sage: b.s(2) [[1, 2], [3]] sage: T=CrystalOfTableaux(['A',2],shape=[4]) sage: t=T(rows=[[1,2,2,2]]) sage: t.s(1) [[1, 1, 1, 2]] """ r""" Returns the reflection of self along its i-string EXAMPLES:: sage: C = CrystalOfTableaux(['A',2], shape=[2,1]) sage: b=C(rows=[[1,1],[3]]) sage: b.s(1) [[2, 2], [3]] sage: b=C(rows=[[1,2],[3]]) sage: b.s(2) [[1, 2], [3]] sage: T=CrystalOfTableaux(['A',2],shape=[4]) sage: t=T(rows=[[1,2,2,2]]) sage: t.s(1) [[1, 1, 1, 2]] """ d = self.phi(i)-self.epsilon(i) b = self if d > 0: for j in range(d): b = b.f(i) else: for j in range(-d): b = b.e(i) return b b = self if d > 0: for j in range(d): b = b.f(i) else: for j in range(-d): b = b.e(i) return b def is_highest_weight(self): r""" Returns True if self is a highest weight. EXAMPLES:: sage: C = CrystalOfLetters(['A',5]) sage: C(1).is_highest_weight() True sage: C(2).is_highest_weight() False """ return all(self.e(i) == None for i in self.index_set()) r""" Returns True if self is a highest weight. EXAMPLES:: sage: C = CrystalOfLetters(['A',5]) sage: C(1).is_highest_weight() True sage: C(2).is_highest_weight() False """ return all(self.e(i) == None for i in self.index_set()) class CrystalBacktracker(GenericBacktracker): def __init__(self, crystal):
• ## sage/combinat/crystals/tensor_product.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/crystals/tensor_product.py
 a It has 8 elements:: sage: T.list() [[2, 1, 1], [2, 1, 2], [2, 1, 3], [3, 1, 3], [3, 2, 3], [3, 1, 1], [3, 1, 2], [3, 2, 2]] [[2, 1, 1], [2, 1, 2], [2, 1, 3], [3, 1, 3], [3, 2, 3], [3, 1, 1], [3, 1, 2], [3, 2, 2]] One can also check the Cartan type of the crystal:: sage: T.cartan_type() ['A', 2] ['A', 2] Other examples include crystals of tableaux (which internally are represented as tensor products obtained by reading the tableaux columnwise):: sage: C = CrystalOfTableaux(['A',3], shape=[1,1,0]) sage: D = CrystalOfTableaux(['A',3], shape=[1,0,0]) sage: T = TensorProductOfCrystals(C,D, generators=[[C(rows=[[1], [2]]), D(rows=[[1]])], [C(rows=[[2], [3]]), D(rows=[[1]])]]) sage: T.cardinality() 24 sage: T.check() True sage: T.module_generators [[[[1], [2]], [[1]]], [[[2], [3]], [[1]]]] sage: [x.weight() for x in T.module_generators] [(2, 1, 0, 0), (1, 1, 1, 0)] sage: D = CrystalOfTableaux(['A',3], shape=[1,0,0]) sage: T = TensorProductOfCrystals(C,D, generators=[[C(rows=[[1], [2]]), D(rows=[[1]])], [C(rows=[[2], [3]]), D(rows=[[1]])]]) sage: T.cardinality() 24 sage: T.check() True sage: T.module_generators [[[[1], [2]], [[1]]], [[[2], [3]], [[1]]]] sage: [x.weight() for x in T.module_generators] [(2, 1, 0, 0), (1, 1, 1, 0)] If no module generators are specified, we obtain the full tensor product:: sage: C=CrystalOfLetters(['A',2]) sage: T=TensorProductOfCrystals(C,C) sage: T.list() [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]] sage: T.cardinality() 9 sage: T=TensorProductOfCrystals(C,C) sage: T.list() [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]] sage: T.cardinality() 9 For a tensor product of crystals without module generators, the default implementation of module_generators contains all elements this needs to be implemented for the specific crystal separately:: sage: T.module_generators.list() [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]] [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [2, 3], [3, 1], [3, 2], [3, 3]] For classical highest weight crystals, it is also possible to list all highest weight elements:: sage: C = CrystalOfLetters(['A',2]) sage: T = TensorProductOfCrystals(C,C,C,generators=[[C(2),C(1),C(1)],[C(1),C(2),C(1)]]) sage: T.highest_weight_vectors() [[2, 1, 1], [1, 2, 1]] sage: T = TensorProductOfCrystals(C,C,C,generators=[[C(2),C(1),C(1)],[C(1),C(2),C(1)]]) sage: T.highest_weight_vectors() [[2, 1, 1], [1, 2, 1]] """ if options.has_key('generators'): if all(isinstance(crystal,ClassicalCrystal) for crystal in crystals): sage: T == loads(dumps(T)) True """ crystals = [ crystal for crystal in crystals] crystals = [ crystal for crystal in crystals] self._name = "The tensor product of the crystals %s"%crystals self.crystals = crystals if options.has_key('cartan_type'): height = minus else: height = height - plus + minus return height return height def epsilon(self, i): """ l = self.positions_of_unmatched_minus(i, dual=True, reverse=True) l.reverse() return [len(self)-1-l[j] for j in range(len(l))] class CrystalOfTableaux(CrystalOfWords, ClassicalCrystal): r""" Crystals of tableaux. Input: a Cartan Type type and "shape", a True sage: T.list() [[[1]], [[2]], [[-2]], [[-1]]] sage: T = CrystalOfTableaux(['A',2], shapes = [[],[1],[2]]) sage: T.list() [[], [[1]], [[2]], [[3]], [[1, 1]], [[1, 2]], [[2, 2]], [[1, 3]], [[2, 3]], [[3, 3]]] sage: T.module_generators ([], [[1]], [[1, 1]]) sage: T = CrystalOfTableaux(['B',2],shape=[3]) sage: T(rows=[[1,1,0]]) [[1, 1, 0]] sage: T = CrystalOfTableaux(['A',2], shapes = [[],[1],[2]]) sage: T.list() [[], [[1]], [[2]], [[3]], [[1, 1]], [[1, 2]], [[2, 2]], [[1, 3]], [[2, 3]], [[3, 3]]] sage: T.module_generators ([], [[1]], [[1, 1]]) sage: T = CrystalOfTableaux(['B',2],shape=[3]) sage: T(rows=[[1,1,0]]) [[1, 1, 0]] Input tests:: The next example checks whether a given tableau is in fact a valid type C tableau or not: sage: T = CrystalOfTableaux(['C',3], shape = [2,2,2]) sage: t = T(rows=[[1,3],[2,-3],[3,-1]]) sage: t in T.list() True sage: t = T(rows=[[2,3],[3,-3],[-3,-2]]) sage: t in T.list() False sage: t = T(rows=[[1,3],[2,-3],[3,-1]]) sage: t in T.list() True sage: t = T(rows=[[2,3],[3,-3],[-3,-2]]) sage: t in T.list() False """ def __init__(self, type, shape = None, shapes = None): """ True """ self.letters = CrystalOfLetters(type) if shape is not None: assert shapes is None shapes = (shape,) assert shapes is not None CrystalOfWords.__init__(self) module_generators = tuple(self.module_generator(la) for la in shapes) if shape is not None: assert shapes is None shapes = (shape,) assert shapes is not None CrystalOfWords.__init__(self) module_generators = tuple(self.module_generator(la) for la in shapes) self.module_generators = module_generators self._name = "The crystal of tableaux of type %s and shape(s) %s"%(type, str(shapes)) def cartan_type(self): """ Returns the Cartan type of the associated crystal """ Returns the Cartan type of the associated crystal EXAMPLES:: sage: T = CrystalOfTableaux(['A',3], shape = [2,2]) sage: T.cartan_type() ['A', 3] EXAMPLES:: sage: T = CrystalOfTableaux(['A',3], shape = [2,2]) sage: T.cartan_type() ['A', 3] """ return self.letters.cartan_type() return self.letters.cartan_type() def module_generator(self, shape): """ This yields the module generator (or highest weight element) of a classical crystal of given shape. The module generator is the unique tableau with equal shape and content. EXAMPLE: sage: T = CrystalOfTableaux(['D',3], shape = [1,1]) sage: T.module_generator([1,1]) [[1], [2]] """ type = self.cartan_type() if type[0] == 'D' and len(shape) == type[1] and shape[type[1]-1] < 0: invert = True shape[type[1]-1]=-shape[type[1]-1] else: invert = False p = Partition(shape).conjugate() # The column canonical tableau, read by columns module_generator = flatten([[p[j]-i for i in range(p[j])] for j in range(len(p))]) if invert: for i in range(type[1]): if module_generator[i] == type[1]: module_generator[i] = -type[1] return self(*[self.letters(x) for x in module_generator]) """ This yields the module generator (or highest weight element) of a classical crystal of given shape. The module generator is the unique tableau with equal shape and content. EXAMPLE: sage: T = CrystalOfTableaux(['D',3], shape = [1,1]) sage: T.module_generator([1,1]) [[1], [2]] """ type = self.cartan_type() if type[0] == 'D' and len(shape) == type[1] and shape[type[1]-1] < 0: invert = True shape[type[1]-1]=-shape[type[1]-1] else: invert = False p = Partition(shape).conjugate() # The column canonical tableau, read by columns module_generator = flatten([[p[j]-i for i in range(p[j])] for j in range(len(p))]) if invert: for i in range(type[1]): if module_generator[i] == type[1]: module_generator[i] = -type[1] return self(*[self.letters(x) for x in module_generator]) def __call__(self, *args, **options): """ True """ if len(args) == 1: if isinstance(args[0], CrystalOfTableauxElement): if args[0].parent() == parent: return args[0] else: raise ValueError, "Inconsistent parent" elif isinstance(args[0], Tableau_class): options['rows'] = args[0] if options.has_key('list'): list = options['list'] if isinstance(args[0], CrystalOfTableauxElement): if args[0].parent() == parent: return args[0] else: raise ValueError, "Inconsistent parent" elif isinstance(args[0], Tableau_class): options['rows'] = args[0] if options.has_key('list'): list = options['list'] elif options.has_key('rows'): rows=options['rows'] #            list=Tableau(rows).to_word_by_column() rows=Tableau(rows).conjugate() list=[] for col in rows: col.reverse() list+=col rows=Tableau(rows).conjugate() list=[] for col in rows: col.reverse() list+=col elif options.has_key('columns'): columns=options['columns'] list=[] sage: type(t[0][0]) sage: T = CrystalOfTableaux(['D',3], shape = [1,1]) sage: t=T(rows=[[-3],[3]]).to_tableau(); t [[-3], [3]] sage: t=T(rows=[[3],[-3]]).to_tableau(); t [[3], [-3]] sage: T = CrystalOfTableaux(['D',3], shape = [1,1]) sage: t=T(rows=[[-3],[3]]).to_tableau(); t [[-3], [3]] sage: t=T(rows=[[3],[-3]]).to_tableau(); t [[3], [-3]] """ if self._list == []: return Tableau([]) tab = [ [self[0].value] ] for i in range(1,len(self)): if self[i-1] <= self[i]: tab.append([self[i].value]) else: l = len(tab)-1 tab[l].append(self[i].value) for x in tab: x.reverse() return Tableau(tab).conjugate() if self._list == []: return Tableau([]) tab = [ [self[0].value] ] for i in range(1,len(self)): if self[i-1] <= self[i]: tab.append([self[i].value]) else: l = len(tab)-1 tab[l].append(self[i].value) for x in tab: x.reverse() return Tableau(tab).conjugate()

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/matrices/dancing_links.pyx
 a initialised using the same row list. TESTS: sage: from sage.combinat.matrices.dancing_links import dlx_solver sage: from sage.combinat.matrices.dancing_links import dlx_solver sage: rows = [[0,1,2]] sage: X = dlx_solver(rows) sage: Z = dlx_solver(rows)
• ## sage/combinat/partition.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/partition.py
 a [[0, 2], [2, 0]] sage: Partition([6,3,3,1,1,1]).outside_corners() [[0, 6], [1, 3], [3, 1], [6, 0]] sage: Partition([]).outside_corners() [[0, 0]] """ p = self if p == Partition([]): return [[0,0]] sage: Partition([]).outside_corners() [[0, 0]] """ p = self if p == Partition([]): return [[0,0]] res = [ [0, p[0]] ] for i in range(1, len(p)): if p[i-1] != p[i]:
• ## sage/combinat/posets/poset_examples.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/posets/poset_examples.py
 a element_labels = dict([[s,"".join(map(str,s.reduced_word_lexmin()))] for s in Permutations(n)]) def weak_covers(s): return [v for v in s.bruhat_succ() if s.length() + (s.inverse()*v).length() == v.length()] s.length() + (s.inverse()*v).length() == v.length()] return Poset(dict([[s,weak_covers(s)] for s in Permutations(n)]),element_labels) #def PosetExamples(n,uc=None):
• ## sage/combinat/posets/posets.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/posets/posets.py
 a """ if label_elements and element_labels is None: element_labels = self._elements return self.hasse_diagram().plot(label_elements=label_elements, element_labels=element_labels, label_font_size=label_font_size, label_font_color=label_font_color, vertex_size=vertex_size,vertex_colors=vertex_colors,**kwds) return self.hasse_diagram().plot(label_elements=label_elements, element_labels=element_labels, label_font_size=label_font_size, label_font_color=label_font_color, vertex_size=vertex_size,vertex_colors=vertex_colors,**kwds) def show(self, label_elements=True, element_labels=None, label_font_size=12,label_font_color='black',
• ## sage/combinat/ribbon_tableau.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/ribbon_tableau.py
 a ##     // Generic function for driving into the graph of partitions coding all ribbons ##     // tableaux of a given shape and weight ##     ////////////////////////////////////////////////////////////////////////////////////////// ##     //This function construct the graph of the set of k-ribbon tableaux ##     //of a given skew shape and a given weight. ##     //The first argument is always a skew partition.
• ## sage/combinat/root_system/type_G.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/root_system/type_G.py
 a """ EXAMPLES: sage: CartanType(['G',2]).root_system().ambient_space().simple_roots() Finite family {1: (0, 1, -1), 2: (1, -2, 1)} Finite family {1: (0, 1, -1), 2: (1, -2, 1)} """ return self._term(1)-self._term(2) if i == 1 else self._term(0)-2*self._term(1)+self._term(2)
• ## sage/combinat/sloane_functions.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/sloane_functions.py
 a def s2(self, n, k): """ Returns the Stirling number S2(n,k) of the 2nd kind. EXAMPLES:: sage: sloane.A008277.s2(4,2) 7 """ Returns the Stirling number S2(n,k) of the 2nd kind. EXAMPLES:: sage: sloane.A008277.s2(4,2) 7 """ return combinat.stirling_number2(n,k) def _eval(self, n): def _repr_(self): """ EXAMPLES:: sage: sloane.A002378._repr_() 'Oblong (or pronic, or heteromecic) numbers: n(n+1).' """ sage: [sloane.A000120._eval(n) for n in range(10)] [0, 1, 1, 2, 1, 2, 2, 3, 1, 2] """ """ return self.f(n) class A010060(SloaneSequence): """ SloaneSequence.__init__(self, offset=0) self._b = [] self._a0a1d = (0,1,2) self._a0a1d = (0,1,2) self._precompute(2)  # force precomputation, e.g. a(0) will fail when asked first def _repr_(self): """ SloaneSequence.__init__(self, offset=0) self._b = [] self._a0a1d = (1,1,1) self._a0a1d = (1,1,1) self._precompute(2)  # force precomputation, e.g. a(0) will fail when asked first def _repr_(self): - Jaap Spies (2007-01-23) """ SloaneSequence.__init__(self, offset=1) self._a0a1d = (0,1,3) self._a0a1d = (0,1,3) self._b = [] self._k = self.offset + 1 - Jaap Spies (2007-01-13) """ SloaneSequence.__init__(self, offset=2) self._a0a1d = (0,1,4) self._b = [] self._k = self.offset + 1 self._a0a1d = (0,1,4) self._b = [] self._k = self.offset + 1 def _repr_(self): """ - Jaap Spies (2007-01-13) """ SloaneSequence.__init__(self, offset=3) self._a0a1d = (0,1,5) self._a0a1d = (0,1,5) self._b = [] self._k = self.offset + 1 - Jaap Spies (2007-01-23) """ SloaneSequence.__init__(self, offset=1) self._a0a1d = (6,43,6) self._a0a1d = (6,43,6) self._k = self.offset + 1 self._b = [] - Jaap Spies (2007-01-23) """ SloaneSequence.__init__(self, offset=0) self._a0a1d = (0,2,1) self._a0a1d = (0,2,1) self._b = [] self._precompute(2) self._k1 = 2 def _repr_(self): """ EXAMPLES:: sage: sloane.A079922._repr_() 'Solutions to the Dancing School problem with n girls and n+3 boys' """ EXAMPLES:: sage: sloane.A079922._repr_() 'Solutions to the Dancing School problem with n girls and n+3 boys' """ return "Solutions to the Dancing School problem with n girls and n+3 boys" def _repr_(self): """ EXAMPLES:: sage: sloane.A079923._repr_() 'Solutions to the Dancing School problem with n girls and n+4 boys' """ EXAMPLES:: sage: sloane.A079923._repr_() 'Solutions to the Dancing School problem with n girls and n+4 boys' """ return "Solutions to the Dancing School problem with n girls and n+4 boys" def _eval(self, n): 'Sequence of Uppuluri-Carpenter numbers' """ return "Sequence of Uppuluri-Carpenter numbers" # A000100  a(n) = number of compositions of n in which the maximum part size is 3. Milestone!
• ## sage/combinat/symmetric_group_algebra.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/symmetric_group_algebra.py
 a if star: it = it.restrict(it.size() - star) kt = kt.restrict(kt.size() - star) if it.shape() != kt.shape(): raise ValueError, "the two tableaux must be of the same shape" if value != 0: print value raise ValueError, "3.2.12.2 - %s"%tab for tab2 in StandardTableaux(part): #3.2.8 1 if e_ik(tab, tab2) - e(tab)*pi_ik(tab, tab2)*e(tab2)*(1/kappa(part)) != 0:
• ## sage/combinat/tableau.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/tableau.py
 a return sage.combinat.skew_tableau.SkewTableau(st).rectify() def promotion_inverse(self, n): """ Inverse promotion operator defined on rectangular tableaux using jeu de taquin EXAMPLES:: sage: t = Tableau([[1,2],[3,3]]) sage: t.promotion_inverse(2) [[1, 2], [2, 3]] sage: t = Tableau([[1,2],[2,3]]) sage: t.promotion_inverse(2) [[1, 1], [2, 3]] """ if not self.is_rectangular(): raise ValueError, "Tableau is not rectangular" s = self.shape()[0] l = self.weight()[0] word = [i for i in self.to_word() if i>1] word = [i-1 for i in word] t = Tableau([]) t = t.insert_word(word) t = t.to_list() if l1] word = [i-1 for i in word] t = Tableau([]) t = t.insert_word(word) t = t.to_list() if l
• ## sage/combinat/words/morphism.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/combinat/words/morphism.py
 a def _check_primitive(self): r""" Returns True if all the letters of the domain appear in all the images of letters of the domain. INPUT: -  self - the codomain must be an instance of Words EXAMPLES:: sage: m = WordMorphism('a->ab,b->ba') sage: m._check_primitive() True sage: fibo = WordMorphism('a->ab,b->a') sage: fibo._check_primitive() False sage: print WordMorphism({2:[4,5,6],3:[4,1,8]}) WordMorphism: 2->456, 3->418 sage: WordMorphism({2:[4,5,6],3:[4,1,8]})._check_primitive() False """ Returns True if all the letters of the domain appear in all the images of letters of the domain. INPUT: -  self - the codomain must be an instance of Words EXAMPLES:: sage: m = WordMorphism('a->ab,b->ba') sage: m._check_primitive() True sage: fibo = WordMorphism('a->ab,b->a') sage: fibo._check_primitive() False sage: print WordMorphism({2:[4,5,6],3:[4,1,8]}) WordMorphism: 2->456, 3->418 sage: WordMorphism({2:[4,5,6],3:[4,1,8]})._check_primitive() False """ if not is_Words(self.codomain()): raise TypeError, "codomain of self(=%s) must be an instance of Words"%self
• ## sage/crypto/cipher.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/crypto/cipher.py
 a EXAMPLES: None yet """ self._parent = parent self._key = key self._parent = parent self._key = key def __eq__(self, right): return type(self) == type(right) and self._parent == right._parent and self._key == right._key def __repr__(self): return str(self._key) return str(self._key) def key(self): return self._key # was str(self._key) EXAMPLES: None yet """ Cipher.__init__(self, parent, key) Cipher.__init__(self, parent, key) class PublicKeyCipher(Cipher): """ EXAMPLES: None yet """ Cipher.__init__(self, parent, key) self._public = public Cipher.__init__(self, parent, key) self._public = public
• ## sage/crypto/classical.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/crypto/classical.py
 a """ if not isinstance(S, StringMonoid_class): raise TypeError, "S (= %s) must be a string monoid."%S R = IntegerModRing(S.ngens()) M = MatrixSpace(R,m,m) R = IntegerModRing(S.ngens()) M = MatrixSpace(R,m,m) SymmetricKeyCryptosystem.__init__(self, S, S, M, block_length = m) def __call__(self, A): True """ M = self.key_space() R = M.base_ring() R = M.base_ring() m = M.nrows() N = Integer(self.cipher_domain().ngens()) while True: A = M([ randint(0,N-1) for i in range(m**2) ]) if N.gcd(A.det()) == 1: break while True: A = M([ randint(0,N-1) for i in range(m**2) ]) if N.gcd(A.det()) == 1: break return A def inverse_key(self, A): sage: c(e(M)) LAMAISONBLANCHE """ S = self.plaintext_space() M = self.key_space() if not A in M: raise TypeError, "A (= %s) must be a matrix in the key space of %s." % (A, self) m = self.block_length() MatZZ = MatrixSpace(ZZ,m) AZ = MatZZ([ [ A[i,j].lift() for j in range(m) ] for i in range(m) ]) AZ_adj = AZ.adjoint() u, r, s = xgcd(A.det().lift(),S.ngens()) if u != 1: raise ValueError, "Argument:\n\n%s\n\nis not invertible."%(A) S = self.plaintext_space() M = self.key_space() if not A in M: raise TypeError, "A (= %s) must be a matrix in the key space of %s." % (A, self) m = self.block_length() MatZZ = MatrixSpace(ZZ,m) AZ = MatZZ([ [ A[i,j].lift() for j in range(m) ] for i in range(m) ]) AZ_adj = AZ.adjoint() u, r, s = xgcd(A.det().lift(),S.ngens()) if u != 1: raise ValueError, "Argument:\n\n%s\n\nis not invertible."%(A) return r * A.parent()(AZ_adj) def encoding(self, M):
• ## sage/crypto/classical_cipher.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/crypto/classical_cipher.py
 a sage: E == loads(dumps(E)) True """ # TODO: some type checking that the key is an invertible matrix? SymmetricKeyCipher.__init__(self, parent, key) # TODO: some type checking that the key is an invertible matrix? SymmetricKeyCipher.__init__(self, parent, key) def __eq__(self, right): return type(self) == type(right) and self.parent() == right.parent() and self.key() == right.key() def __call__(self, M): S = self.domain() # = plaintext_space = ciphertext_space if not isinstance(M, StringMonoidElement) and M.parent() == S: raise TypeError, "Argument M (= %s) must be a string in the plaintext space." % M m = self.parent().block_length() if len(M) % m != 0: raise TypeError, "The length of M (= %s) must be a multiple of %s." % (M, m ) Alph = list(S.alphabet()) A = self.key() # A is an m x m matrix S = self.domain() # = plaintext_space = ciphertext_space if not isinstance(M, StringMonoidElement) and M.parent() == S: raise TypeError, "Argument M (= %s) must be a string in the plaintext space." % M m = self.parent().block_length() if len(M) % m != 0: raise TypeError, "The length of M (= %s) must be a multiple of %s." % (M, m ) Alph = list(S.alphabet()) A = self.key() # A is an m x m matrix R = A.parent().base_ring() V = FreeModule(R,m) Mstr = str(M) C = [] for i in range(len(M)//m): v = V([ Alph.index(Mstr[m*i+j]) for j in range(m) ]) C += (v * A).list() return S([ k.lift() for k in C ]) Mstr = str(M) C = [] for i in range(len(M)//m): v = V([ Alph.index(Mstr[m*i+j]) for j in range(m) ]) C += (v * A).list() return S([ k.lift() for k in C ]) def inverse(self): E = self.parent() try: B = E.inverse_key(self.key()) except: raise ValueError, "Argument\n\n%s\n\nmust be an invertible cipher." % self return E(B) try: B = E.inverse_key(self.key()) except: raise ValueError, "Argument\n\n%s\n\nmust be an invertible cipher." % self return E(B) class SubstitutionCipher(SymmetricKeyCipher): """ sage: E == loads(dumps(E)) True """ SymmetricKeyCipher.__init__(self, parent, key) SymmetricKeyCipher.__init__(self, parent, key) def __eq__(self, right): return type(self) == type(right) and self.parent() == right.parent() and self.key() == right.key() def __call__(self, M): S = self.domain() # = plaintext_space = ciphertext_space if not isinstance(M, StringMonoidElement) and M.parent() == S: raise TypeError, "Argument M (= %s) must be a string in the plaintext space." % M A = list(S.alphabet()) K = str(self.key()) # K is a string, while we want the indices: I = [ A.index(K[i]) for i in range(len(K)) ] Mstr = str(M) return S([ I[A.index(Mstr[i])] for i in range(len(Mstr)) ]) S = self.domain() # = plaintext_space = ciphertext_space if not isinstance(M, StringMonoidElement) and M.parent() == S: raise TypeError, "Argument M (= %s) must be a string in the plaintext space." % M A = list(S.alphabet()) K = str(self.key()) # K is a string, while we want the indices: I = [ A.index(K[i]) for i in range(len(K)) ] Mstr = str(M) return S([ I[A.index(Mstr[i])] for i in range(len(Mstr)) ]) def inverse(self): E = self.parent() K = E.inverse_key(self.key()) return E(K) K = E.inverse_key(self.key()) return E(K) class TranspositionCipher(SymmetricKeyCipher): """ sage: E == loads(dumps(E)) True """ n = parent.block_length() if isinstance(key, list) and not len(key) == n: raise ValueError, "key (= %s) must have block length %s" % (key, n) SymmetricKeyCipher.__init__(self, parent, key) n = parent.block_length() if isinstance(key, list) and not len(key) == n: raise ValueError, "key (= %s) must have block length %s" % (key, n) SymmetricKeyCipher.__init__(self, parent, key) def __call__(self, M, mode = "ECB"): S = self.domain() # = plaintext_space = ciphertext_space if not isinstance(M, StringMonoidElement) and M.parent() == S: raise TypeError, "Argument M (= %s) must be a string in the plaintext space." % M if not mode == "ECB": raise NotImplementedError, "Enciphering not implemented for mode (= %s) other than 'ECB'." % mode g = self.key() N = len(M) m = self.parent().block_length() if not N%m == 0: raise TypeError, "Argument M (= %s) must be a string of length k*%s." % (M, m) Melt = M._element_list # this uses the internal structure of string monoids # Caution: this is parsed as an outer loop in k and an inner loop in i: #     for k in range(N//m): #         for i in range(m): #             S([ Melt[g(i+1)-1+k*m] return S([ Melt[g(i+1)-1+k*m] for k in range(N//m) for i in range(m) ]) S = self.domain() # = plaintext_space = ciphertext_space if not isinstance(M, StringMonoidElement) and M.parent() == S: raise TypeError, "Argument M (= %s) must be a string in the plaintext space." % M if not mode == "ECB": raise NotImplementedError, "Enciphering not implemented for mode (= %s) other than 'ECB'." % mode g = self.key() N = len(M) m = self.parent().block_length() if not N%m == 0: raise TypeError, "Argument M (= %s) must be a string of length k*%s." % (M, m) Melt = M._element_list # this uses the internal structure of string monoids # Caution: this is parsed as an outer loop in k and an inner loop in i: #     for k in range(N//m): #         for i in range(m): #             S([ Melt[g(i+1)-1+k*m] return S([ Melt[g(i+1)-1+k*m] for k in range(N//m) for i in range(m) ]) def inverse(self): E = self.parent() K = E.inverse_key(self.key()) return E(K) K = E.inverse_key(self.key()) return E(K) class VigenereCipher(SymmetricKeyCipher): """ sage: E == loads(dumps(E)) True """ SymmetricKeyCipher.__init__(self, parent, key) SymmetricKeyCipher.__init__(self, parent, key) def __call__(self, M, mode = "ECB"): S = self.domain() # = plaintext_space = ciphertext_space if not isinstance(M, StringMonoidElement) and M.parent() == S: raise TypeError, "Argument M (= %s) must be a string in the plaintext space." % M if not mode == "ECB": raise NotImplementedError, "Enciphering not implemented for mode (= %s) other than 'ECB'." % mode K = self.key() m = self.parent().period() n = S.ngens() # This uses the internal structure of string monoids Melt = M._element_list Kelt = K._element_list return S([ (Melt[i]+Kelt[i%m])%n for i in range(len(M)) ]) S = self.domain() # = plaintext_space = ciphertext_space if not isinstance(M, StringMonoidElement) and M.parent() == S: raise TypeError, "Argument M (= %s) must be a string in the plaintext space." % M if not mode == "ECB": raise NotImplementedError, "Enciphering not implemented for mode (= %s) other than 'ECB'." % mode K = self.key() m = self.parent().period() n = S.ngens() # This uses the internal structure of string monoids Melt = M._element_list Kelt = K._element_list return S([ (Melt[i]+Kelt[i%m])%n for i in range(len(M)) ]) def inverse(self): E = self.parent() K = E.inverse_key(self.key()) return E(K) K = E.inverse_key(self.key()) return E(K)
• ## sage/crypto/cryptosystem.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/crypto/cryptosystem.py
 a key. """ def __init__(self, plaintext_space, ciphertext_space, key_space, block_length = 1, period = None): self._cipher_domain = plaintext_space self._cipher_codomain = ciphertext_space self._key_space = key_space self._block_length = block_length self._period = period self._cipher_domain = plaintext_space self._cipher_codomain = ciphertext_space self._key_space = key_space self._block_length = block_length self._period = period def __eq__(self,right): return type(self) == type(right) and  \ def plaintext_space(self): return self._cipher_domain return self._cipher_domain def cipher_domain(self): return self._cipher_domain return self._cipher_domain def ciphertext_space(self): return self._cipher_codomain return self._cipher_codomain def cipher_codomain(self): return self._cipher_codomain return self._cipher_codomain def key_space(self): return self._key_space return self._key_space def block_length(self): return self._block_length def period(self): if self._period is None: raise TypeError, "Argument has no associated period." return self._period if self._period is None: raise TypeError, "Argument has no associated period." return self._period class SymmetricKeyCryptosystem(Cryptosystem): """
• ## sage/crypto/lfsr.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/crypto/lfsr.py
 a IEEE Trans. Inform. Theory, vol. IT-15, pp. 122-127, Jan. 19 69. """ # Initialization: FF = s[0].base_ring() FF = s[0].base_ring() R = PolynomialRing(FF, "x") x = R.gen() C = R(1); B = R(1); m = 1; b = FF(1); L = 0; N = 0
• ## sage/crypto/mq/mpolynomialsystem.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/crypto/mq/mpolynomialsystem.py
 a R = arg1.ring() rounds = arg1.gens() elif isinstance(arg1, (list,tuple)): rounds = arg1 R = iter(rounds).next().parent() for f in rounds: if f.parent() is not R: raise TypeError("Generators must have same parent.") rounds = arg1 R = iter(rounds).next().parent() for f in rounds: if f.parent() is not R: raise TypeError("Generators must have same parent.") else: raise TypeError, "first parameter must be a MPolynomialRing" self._gens = list(gens) def __copy__(self): """ Return a copy of this round system. EXAMPLE:: """ Return a copy of this round system. EXAMPLE:: sage: sr = mq.SR(allow_zero_inversions=True) sage: F,s = sr.polynomial_system() sage: r = F.round(0) sage: r = F.round(0) sage: copy(r) [w100 + k000 + (a^3 + a + 1), w101 + k001 + (a^3 + 1), w102 + k002 + (a^3 + a^2 + 1), w103 + k003 + (a^3 + a^2 + a)] """ return MPolynomialRoundSystem_generic(self._ring, list(self._gens)) [w100 + k000 + (a^3 + a + 1), w101 + k001 + (a^3 + 1), w102 + k002 + (a^3 + a^2 + 1), w103 + k003 + (a^3 + a^2 + a)] """ return MPolynomialRoundSystem_generic(self._ring, list(self._gens)) def __cmp__(self, other): """ raise TypeError, "parameter not supported" def __copy__(self): """ Return a copy of self. While this is not a deep copy, only mutable members of this system are copied. EXAMPLE:: """ Return a copy of self. While this is not a deep copy, only mutable members of this system are copied. EXAMPLE:: sage: sr = mq.SR(allow_zero_inversions=True) sage: F,s = sr.polynomial_system() sage: copy(F) # indirect doctest Polynomial System with 40 Polynomials in 20 Variables """ return MPolynomialSystem_generic(self._ring, [r.__copy__() for r in self._rounds]) Polynomial System with 40 Polynomials in 20 Variables """ return MPolynomialSystem_generic(self._ring, [r.__copy__() for r in self._rounds]) def __cmp__(self, other): """
• ## sage/crypto/stream.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/crypto/stream.py
 a implementation is limited to the finite field of 2 elements only because of the dependence on binary strings. """ if field is None: field = FiniteField(2) if field.cardinality() != 2: raise NotImplementedError, "Not yet implemented." S = BinaryStrings() P = PolynomialRing(FiniteField(2),'x') if field is None: field = FiniteField(2) if field.cardinality() != 2: raise NotImplementedError, "Not yet implemented." S = BinaryStrings() P = PolynomialRing(FiniteField(2),'x') SymmetricKeyCryptosystem.__init__(self, S, S, None) self._field = field self._field = field def __eq__(self,right): return type(self) == type(right) and self._field == right._field INPUT: A polynomial and inital state of the LFSR. """ if not isinstance(key, (list,tuple)) and len(key) == 2: raise TypeError, "Argument key (= %s) must be a list of tuple of length 2" % key poly = key[0]; IS = key[1] if not isinstance(key, (list,tuple)) and len(key) == 2: raise TypeError, "Argument key (= %s) must be a list of tuple of length 2" % key poly = key[0]; IS = key[1] if not is_Polynomial(poly): raise TypeError, "poly (= %s) must be a polynomial." % poly if not isinstance(IS, (list,tuple)): raise TypeError, "IS (= %s) must be an initial in the key space."%K if len(IS) != poly.degree(): raise TypeError, \ "The length of IS (= %s) must equal the degree of poly (= %s)" % (IS, poly) "The length of IS (= %s) must equal the degree of poly (= %s)" % (IS, poly) return LFSRCipher(self, poly, IS) def __repr__(self): return "LFSR cryptosystem over %s" % self._field def encoding(self,M): S = self.cipher_domain() try: return S.encoding(M) except: raise TypeError, "Argument M = %s does not encode in the cipher domain" % M S = self.cipher_domain() try: return S.encoding(M) except: raise TypeError, "Argument M = %s does not encode in the cipher domain" % M class ShrinkingGeneratorCryptosystem(SymmetricKeyCryptosystem): """ sage: E Shrinking generator cryptosystem over Finite Field of size 2 """ if field is None: field = FiniteField(2) if field.cardinality() != 2: raise NotImplementedError, "Not yet implemented." S = BinaryStrings() P = PolynomialRing(field, 'x') if field is None: field = FiniteField(2) if field.cardinality() != 2: raise NotImplementedError, "Not yet implemented." S = BinaryStrings() P = PolynomialRing(field, 'x') SymmetricKeyCryptosystem.__init__(self, S, S, None) self._field = field self._field = field def __call__(self, key): """ OUTPUT: The shrinking generator cipher with key stream generator e1 and decimating cipher e2. """ if not isinstance(key, (list,tuple)) and len(key) == 2: raise TypeError, "Argument key (= %s) must be a list of tuple of length 2" % key e1 = key[0]; e2 = key[1] if not isinstance(key, (list,tuple)) and len(key) == 2: raise TypeError, "Argument key (= %s) must be a list of tuple of length 2" % key e1 = key[0]; e2 = key[1] if not isinstance(e1, LFSRCipher) or not isinstance(e2, LFSRCipher): raise TypeError, "The key (= (%s,%s)) must be a tuple of two LFSR ciphers." % key return ShrinkingGeneratorCipher(self, e1, e2) return "Shrinking generator cryptosystem over %s" % self._field def encoding(self,M): S = self.cipher_domain() try: return S.encoding(M) except: raise TypeError, "Argument M = %s does not encode in the cipher domain" % M S = self.cipher_domain() try: return S.encoding(M) except: raise TypeError, "Argument M = %s does not encode in the cipher domain" % M
• ## sage/databases/compressed_storage.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/databases/compressed_storage.py
 a # This is the original copyright notice: # #       $Id$ #       $Id$ # # Copyright (c) 1999 Tyler C. Sarna (tsarna@endicor.com) # All rights reserved.
• ## sage/dsage/interface/dsage_interface.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/dsage/interface/dsage_interface.py
 a """ Resubmits the current job. """ from twisted.internet import reactor from twisted.internet import reactor self.job_id = blockingCallFromThread(reactor, self._remoteobj.callRemote, 'submit_job', self._jdict)
• ## sage/ext/interactive_constructors_c.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/ext/interactive_constructors_c.pyx
 a sage: GF(9,'c') Finite Field in c of size 3^2 sage: c^3 2*c + 1 2*c + 1 ROLL YOUR OWN: If a constructor you would like to auto inject variables isn't made to do so by running this command your options
• ## sage/functions/constants.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/functions/constants.py
 a NaN """ Constant.__init__(self, {'matlab':'NaN'}) {'matlab':'NaN'}) def _repr_(self, simplify=True): """ golden_ratio """ Constant.__init__(self,{'mathematica':'N[(1+Sqrt[5])/2]','gp':'(1+sqrt(5))/2', 'maple':'(1+sqrt(5))/2','maxima':'(1+sqrt(5))/2', 'pari':'(1+sqrt(5))/2','octave':'(1+sqrt(5))/2', 'kash':'(1+Sqrt(5))/2'}) 'maple':'(1+sqrt(5))/2','maxima':'(1+sqrt(5))/2', 'pari':'(1+sqrt(5))/2','octave':'(1+sqrt(5))/2', 'kash':'(1+Sqrt(5))/2'}) def _repr_(self, simplify=True): """ EXAMPLES:: sage: RealField(100)(golden_ratio) 1.6180339887498948482045868344 """ return (R(1)+R(5).sqrt())/R(2) return (R(1)+R(5).sqrt())/R(2) def _algebraic_(self, field): """ log2 """ Constant.__init__(self,{'mathematica':'N[Log[2]]','kash':'Log(2)', 'maple':'log(2)','maxima':'log(2)','gp':'log(2)', 'pari':'log(2)','octave':'log(2)'}) 'maple':'log(2)','maxima':'log(2)','gp':'log(2)', 'pari':'log(2)','octave':'log(2)'}) def _repr_(self, simplify=True): """ euler_gamma """ Constant.__init__(self, {'kash':'EulerGamma(R)','maple':'gamma', {'kash':'EulerGamma(R)','maple':'gamma', 'mathematica':'EulerGamma','pari':'Euler', 'maxima':'%gamma', 'maxima':'euler_gamma'}) sage: RDF(khinchin) 2.68545200107 """ return R('2.685452001065306445309714835481795693820') return R('2.685452001065306445309714835481795693820') def __float__(self): twinprime """ Constant.__init__(self,{'maxima':'twinprime'}) #Twin prime is not implemented in any other algebra systems. #digits come from http://www.gn-50uma.de/alula/essays/Moree/Moree-details.en.shtml self.__value = "0.660161815846869573927812110014555778432623360284733413319448423335405642304495277143760031413839867911779005226693304002965847755123366227747165713213986968741097620630214153735434853131596097803669932135255299767199302474590593101082978291553834469297505205916657133653611991532464281301172462306379341060056466676584434063501649322723528968010934966475600478812357962789459842433655749375581854814173628678098705969498703841243363386589311969079150040573717814371081810615401233104810577794415613125444598860988997585328984038108718035525261719887112136382808782349722374224097142697441764455225265548994829771790977784043757891956590649994567062907828608828395990394287082529070521554595671723599449769037800675978761690802426600295711092099633708272559284672129858001148697941855401824639887493941711828528382365997050328725708087980662201068630474305201992394282014311102297265141514194258422242375342296879836738796224286600285358098482833679152235700192585875285961205994728621007171131607980572" self.__bits = len(self.__value)*3-1   # underestimate sage: RDF(twinprime) 0.660161815847 """ return R('0.660161815846869573927812110014555778432') return R('0.660161815846869573927812110014555778432') def __float__(self): sage: float(twinprime) 0.66016181584686962 """ return 0.660161815846869573927812110014555778432 return 0.660161815846869573927812110014555778432 twinprime = TwinPrime() sage: float(merten) 0.26149721284764277 """ return 0.261497212847642783755426838608695859051 return 0.261497212847642783755426838608695859051 merten = Merten() sage: float(brun) 1.902160583104 """ return 1.9021605831040 return 1.9021605831040 brun=Brun()
• ## sage/functions/functions.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/functions/functions.py
 a raise TypeError, "these objects are not comparable" if c: return c try: return cmp(maxima(self),maxima(right)) except TypeError: pass return cmp(maxima(self),maxima(right)) except TypeError: pass raise NotImplementedError, "equality testing for general mathematical functions not yet implemented (can't prove equality)."
• ## sage/functions/piecewise.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/functions/piecewise.py
 a self.length(),self.list()) def _latex_(self): r""" EXAMPLES:: sage: f1(x) = 1 sage: f2(x) = 1 - x sage: f = Piecewise([[(0,1),f1],[(1,2),f2]]) sage: latex(f) \begin{cases} x \ {\mapsto}\ 1 &\text{on $(0, 1)$}\cr x \ {\mapsto}\ 1 - x &\text{on $(1, 2)$}\cr \end{cases} :: sage: f(x) = sin(x*pi/2) sage: g(x) = 1-(x-1)^2 sage: h(x) = -x sage: P = Piecewise([[(0,1), f], [(1,3),g], [(3,5), h]]) sage: latex(P) \begin{cases} x \ {\mapsto}\ \sin \left( \frac{{\pi x}}{2} \right) &\text{on $(0, 1)$}\cr x \ {\mapsto}\ 1 - {\left( x - 1 \right)}^{2}  &\text{on $(1, 3)$}\cr x \ {\mapsto}\ -x &\text{on  $(3, 5)$}\cr \end{cases} """ r""" EXAMPLES:: sage: f1(x) = 1 sage: f2(x) = 1 - x sage: f = Piecewise([[(0,1),f1],[(1,2),f2]]) sage: latex(f) \begin{cases} x \ {\mapsto}\ 1 &\text{on $(0, 1)$}\cr x \ {\mapsto}\ 1 - x &\text{on $(1, 2)$}\cr \end{cases} :: sage: f(x) = sin(x*pi/2) sage: g(x) = 1-(x-1)^2 sage: h(x) = -x sage: P = Piecewise([[(0,1), f], [(1,3),g], [(3,5), h]]) sage: latex(P) \begin{cases} x \ {\mapsto}\ \sin \left( \frac{{\pi x}}{2} \right) &\text{on $(0, 1)$}\cr x \ {\mapsto}\ 1 - {\left( x - 1 \right)}^{2}  &\text{on $(1, 3)$}\cr x \ {\mapsto}\ -x &\text{on  $(3, 5)$}\cr \end{cases} """ from sage.misc.latex import latex tex = ['\\begin{cases}\n'] for (left, right), f in self.list(): -3*sin(2*x)/pi + 3*sin(x)/pi - 3*cos(x)/pi - 1/4 """ return self._fourier_series_helper(N, L, lambda n: F[n]) def plot_fourier_series_partial_sum(self,N,L,xmin,xmax, **kwds): r""" Plots the partial sum """ from sage.plot.all import plot return plot(self.fourier_series_partial_sum_hann(N,L), xmin, xmax, **kwds) def plot_fourier_series_partial_sum_filtered(self,N,L,F,xmin,xmax, **kwds): r""" Plots the partial sum """ from sage.plot.all import plot return plot(self.fourier_series_partial_sum_filtered(N,L,F), xmin, xmax, **kwds) def fourier_series_value(self,x,L): r""" Returns the value of the Fourier series coefficient of self at def __add__(self,other): """ Returns the piecewise defined function which is the sum of self and other. Does not require both domains be the same. EXAMPLES:: sage: x = PolynomialRing(QQ,'x').gen() sage: f1 = x^0 Returns the piecewise defined function which is the sum of self and other. Does not require both domains be the same. EXAMPLES:: sage: x = PolynomialRing(QQ,'x').gen() sage: f1 = x^0 sage: f2 = 1-x sage: f3 = 2*x sage: f4 = 10-x sage: f = Piecewise([[(0,1),f1],[(1,2),f2],[(2,3),f3],[(3,10),f4]]) sage: g1 = x-2 sage: g1 = x-2 sage: g2 = x-5 sage: g = Piecewise([[(0,5),g1],[(5,10),g2]]) sage: h = f+g sage: h sage: h = f+g sage: h Piecewise defined function with 5 parts, [[(0, 1), x - 1], [(1, 2), -1], [(2, 3), 3*x - 2], [(3, 5), 8], [(5, 10), 5]] Note that in this case the functions must be defined using polynomial expressions *not* using the lambda notation. """ Note that in this case the functions must be defined using polynomial expressions *not* using the lambda notation. """ F, G, intervals = self._make_compatible(other) fcn = [] for a,b in intervals: fcn.append([(a,b), F.which_function(b)+G.which_function(b)]) fcn.append([(a,b), F.which_function(b)+G.which_function(b)]) return Piecewise(fcn) def __mul__(self,other): r""" Returns the piecewise defined function which is the product of one piecewise function (self) with another one (other). EXAMPLES:: sage: x = PolynomialRing(QQ,'x').gen() sage: f1 = x^0 Returns the piecewise defined function which is the product of one piecewise function (self) with another one (other). EXAMPLES:: sage: x = PolynomialRing(QQ,'x').gen() sage: f1 = x^0 sage: f2 = 1-x sage: f3 = 2*x sage: f4 = 10-x sage: f = Piecewise([[(0,1),f1],[(1,2),f2],[(2,3),f3],[(3,10),f4]]) sage: g1 = x-2 sage: g1 = x-2 sage: g2 = x-5 sage: g = Piecewise([[(0,5),g1],[(5,10),g2]]) sage: h = f*g sage: h Piecewise defined function with 5 parts, [[(0, 1), x - 2], [(1, 2), -x^2 + 3*x - 2], [(2, 3), 2*x^2 - 4*x], [(3, 5), -x^2 + 12*x - 20], [(5, 10), -x^2 + 15*x - 50]] sage: h = f*g sage: h Piecewise defined function with 5 parts, [[(0, 1), x - 2], [(1, 2), -x^2 + 3*x - 2], [(2, 3), 2*x^2 - 4*x], [(3, 5), -x^2 + 12*x - 20], [(5, 10), -x^2 + 15*x - 50]] sage: g*(11/2) Piecewise defined function with 2 parts, [[(0, 5), 11/2*x - 11], [(5, 10), 11/2*x - 55/2]] Note that in this method the functions must be defined using polynomial expressions *not* using the lambda notation. """ Note that in this method the functions must be defined using polynomial expressions *not* using the lambda notation. """ ## needed for scalar multiplication if isinstance(other,Rational) or isinstance(other,Integer): return Piecewise([[(a,b), other*f] for (a,b),f in self.list()]) F, G, intervals = self._make_compatible(other) fcn = [] for a,b in intervals: fcn.append([(a,b),F.which_function(b)*G.which_function(b)]) fcn.append([(a,b),F.which_function(b)*G.which_function(b)]) return Piecewise(fcn) __rmul__ = __mul__
• ## sage/geometry/polyhedra.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/geometry/polyhedra.py
• ## sage/geometry/polytope.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/geometry/polytope.py
 a F = tmp_file open(F,'w').write(self.__data) c = '%s %s %s'%(polymake_command, F, cmd) polymake_processes = Popen([polymake_command, F, cmd],stdout=PIPE,stderr=PIPE) polymake_processes = Popen([polymake_command, F, cmd],stdout=PIPE,stderr=PIPE) ans, err = polymake_processes.communicate() if len(err) > 0: raise RuntimeError, err
• ## sage/graphs/graph.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/graphs/graph.py
 a Note that any additional keywords will be pased on to either the adjacency_matrix or weighted_adjacency_matrix method. AUTHORS: AUTHORS: - Tom Boothby EXAMPLES::
• ## sage/graphs/graph_database.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/graphs/graph_database.py
 a # set expression if not isinstance(kwds[key],list): if key == 'induced_subgraphs': qdict['expression'] = [key, 'regexp', '.*%s.*'%(graph.Graph(kwds[key]).canonical_label()).graph6_string()] else: qdict['expression'] = [key, '=', kwds[key]] if key == 'induced_subgraphs': qdict['expression'] = [key, 'regexp', '.*%s.*'%(graph.Graph(kwds[key]).canonical_label()).graph6_string()] else: qdict['expression'] = [key, '=', kwds[key]] elif key == 'degree_sequence': qdict['expression'] = [key, '=', degseq_to_data(kwds[key])] elif key != 'induced_subgraphs': # organize display if display_cols is not None: for col in display_cols: if col in graph_data: graph_data_disp.append(col) elif col in aut_grp: aut_grp_disp.append(col) elif col in degrees: degrees_disp.append(col) elif col in misc: misc_disp.append(col) elif col in spectrum: spectrum_disp.append(col) for col in display_cols: if col in graph_data: graph_data_disp.append(col) elif col in aut_grp: aut_grp_disp.append(col) elif col in degrees: degrees_disp.append(col) elif col in misc: misc_disp.append(col) elif col in spectrum: spectrum_disp.append(col) # finish filling master join with display tables for tab in disp_tables: if len(tab) > 1: master_join[tab[0]] = ('graph_id', 'graph_id') # join clause for display tables join_str = 'FROM graph_data ' for tab in master_join: join_str += 'INNER JOIN %s ON graph_data.graph_id=%s.graph_id '%(tab, tab) # construct sql syntax substring for display cols disp_str = 'SELECT graph_data.graph6, ' for col in graph_data_disp[1:]: if col != 'graph6': disp_str += 'graph_data.%s, '%col for col in aut_grp_disp[1:]: disp_str += 'aut_grp.%s, '%col for col in degrees_disp[1:]: disp_str += 'degrees.%s, '%col for col in misc_disp[1:]: disp_str += 'misc.%s, '%col for col in spectrum_disp[1:]: disp_str += 'spectrum.%s, '%col disp_str = disp_str.rstrip(', ') + ' ' # finish filling master join with display tables for tab in disp_tables: if len(tab) > 1: master_join[tab[0]] = ('graph_id', 'graph_id') # join clause for display tables join_str = 'FROM graph_data ' for tab in master_join: join_str += 'INNER JOIN %s ON graph_data.graph_id=%s.graph_id '%(tab, tab) # construct sql syntax substring for display cols disp_str = 'SELECT graph_data.graph6, ' for col in graph_data_disp[1:]: if col != 'graph6': disp_str += 'graph_data.%s, '%col for col in aut_grp_disp[1:]: disp_str += 'aut_grp.%s, '%col for col in degrees_disp[1:]: disp_str += 'degrees.%s, '%col for col in misc_disp[1:]: disp_str += 'misc.%s, '%col for col in spectrum_disp[1:]: disp_str += 'spectrum.%s, '%col disp_str = disp_str.rstrip(', ') + ' ' # substitue disp_str and join_str back into self's query string self.__query_string__ = re.sub('SELECT.*WHERE ', disp_str + join_str + \ 'WHERE ', self.__query_string__) # substitue disp_str and join_str back into self's query string self.__query_string__ = re.sub('SELECT.*WHERE ', disp_str + join_str + \ 'WHERE ', self.__query_string__) def show(self, max_field_size=20, with_picture=False): """
• ## sage/groups/abelian_gps/abelian_group_morphism.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/groups/abelian_gps/abelian_group_morphism.py
 a A set-theoretic map between AbelianGroups. """ def __init__(self, parent): Morphism.__init__(self, parent) Morphism.__init__(self, parent) def _repr_type(self): return "AbelianGroup" self._codomain = H if not(G.is_abelian()): raise TypeError, "Sorry, the groups must be abelian groups." if not(H.is_abelian()): if not(H.is_abelian()): raise TypeError, "Sorry, the groups must be abelian groups." G_domain = G.subgroup(genss) if G_domain.order() != G.order(): sage: phi._gap_init_() 'phi := GroupHomomorphismByImages(G,H,[x, y],[a, b])' """ G  = (self.domain())._gap_init_() H  = (self.range())._gap_init_() G  = (self.domain())._gap_init_() H  = (self.range())._gap_init_() # print G,H s3 = 'G:=%s; H:=%s'%(G,H) #print s3,"\n" cmd = ("%s := gensH["+str(i+1)+"]")%gensH[i] #print i,"  \n",cmd gap.eval(cmd) args = str(self.domaingens)+","+ str(self.codomaingens) args = str(self.domaingens)+","+ str(self.codomaingens) #print args,"\n" gap.eval("phi := GroupHomomorphismByImages(G,H,"+args+")") gap.eval("phi := GroupHomomorphismByImages(G,H,"+args+")") self.gap_hom_string = "phi := GroupHomomorphismByImages(G,H,"+args+")" return self.gap_hom_string def __call__( self, g ): """ Some python code for wrapping GAP's Images function but only for permutation groups. Returns an error if g is not in G. EXAMPLES:: sage: H = AbelianGroup(3, [2,3,4], names="abc") sage: a,b,c = H.gens() sage: G = AbelianGroup(2, [2,3], names="xy") sage: x,y = G.gens() sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b]) sage: phi(y*x) a*b sage: phi(y^2) b^2 """ Some python code for wrapping GAP's Images function but only for permutation groups. Returns an error if g is not in G. EXAMPLES:: sage: H = AbelianGroup(3, [2,3,4], names="abc") sage: a,b,c = H.gens() sage: G = AbelianGroup(2, [2,3], names="xy") sage: x,y = G.gens() sage: phi = AbelianGroupMorphism(G,H,[x,y],[a,b]) sage: phi(y*x) a*b sage: phi(y^2) b^2 """ G = g.parent() w = g.word_problem(self.domaingens) n = len(w) # g.word_problem is faster in general than word_problem(g) gens = self.codomaingens h = prod([gens[(self.domaingens).index(w[i][0])]**(w[i][1]) for i in range(n)]) return h return h
• ## sage/groups/class_function.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/groups/class_function.py
 a Character of Symmetric group of order 5! as a permutation group sage: H = G.subgroup([(1,2,3), (1,2), (4,5)]) sage: chi.restrict(H) Character of Subgroup of SymmetricGroup(5) generated by [(4,5), (1,2), (1,2,3)] Character of Subgroup of SymmetricGroup(5) generated by [(4,5), (1,2), (1,2,3)] sage: chi.restrict(H).values() [3, -3, -3, -1, 0, 0] """ sage: G = SymmetricGroup(5) sage: H = G.subgroup([(1,2,3), (1,2), (4,5)]) sage: xi = H.trivial_character(); xi Character of Subgroup of SymmetricGroup(5) generated by [(4,5), (1,2), (1,2,3)] Character of Subgroup of SymmetricGroup(5) generated by [(4,5), (1,2), (1,2,3)] sage: xi.induct(G) Character of Symmetric group of order 5! as a permutation group sage: xi.induct(G).values()
• ## sage/groups/matrix_gps/matrix_group.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/groups/matrix_gps/matrix_group.py
 a ##             sage: gens = [MS([[1,0],[-1,1]]),MS([[1,1],[0,1]])] ##             sage: G = MatrixGroup(gens) ##             sage: G.conjugacy_class_representatives_gap() ##          ['[ [ Z(3)^0, 0*Z(3) ], [ 0*Z(3), Z(3)^0 ] ]', ##          '[ [ 0*Z(3), Z(3)^0 ], [ Z(3), Z(3)^0 ] ]', ##          ['[ [ Z(3)^0, 0*Z(3) ], [ 0*Z(3), Z(3)^0 ] ]', ##          '[ [ 0*Z(3), Z(3)^0 ], [ Z(3), Z(3)^0 ] ]', ##             '[ [ 0*Z(3), Z(3)^0 ], [ Z(3), Z(3) ] ]', ##             '[ [ 0*Z(3), Z(3) ], [ Z(3)^0, Z(3)^0 ] ]', ##                  '[ [ 0*Z(3), Z(3) ], [ Z(3)^0, Z(3) ] ]', ##                  '[ [ 0*Z(3), Z(3)^0 ], [ Z(3), 0*Z(3) ] ]', ##          '[ [ Z(3), 0*Z(3) ], [ 0*Z(3), Z(3) ] ]'] ##                  '[ [ 0*Z(3), Z(3) ], [ Z(3)^0, Z(3) ] ]', ##                  '[ [ 0*Z(3), Z(3)^0 ], [ Z(3), 0*Z(3) ] ]', ##          '[ [ Z(3), 0*Z(3) ], [ 0*Z(3), Z(3) ] ]'] ##         AUTHOR: David Joyner (1-2006) ##         """
• ## sage/groups/matrix_gps/matrix_group_morphism.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/groups/matrix_gps/matrix_group_morphism.py
 a A set-theoretic map between matrix groups. """ def __init__(self, parent): Morphism.__init__(self, parent) Morphism.__init__(self, parent) def _repr_type(self): return "MatrixGroup" MatrixGroupMorphism.__init__(self, homset)   # sets the parent G = homset.domain() H = homset.codomain() gaplist_gens = [gap(x) for x in G.gens()] gaplist_imgs = [gap(x) for x in imgsH] gaplist_gens = [gap(x) for x in G.gens()] gaplist_imgs = [gap(x) for x in imgsH] genss = '[%s]'%(','.join(str(v) for v in gaplist_gens)) imgss = '[%s]'%(','.join(str(v) for v in gaplist_imgs)) args = '%s, %s, %s, %s'%(G._gap_init_(), H._gap_init_(), genss, imgss) self._gap_str = 'GroupHomomorphismByImages(%s)'%args self._gap_hom_string = 'phi := %s'%self._gap_str phi0 = gap.eval(self._gap_hom_string) if phi0=="fail": phi0 = gap.eval(self._gap_hom_string) if phi0=="fail": raise ValueError,"The map "+str(gensG)+"-->"+str(imgsH)+" isn't a homomorphism." self.hom = gap.eval("phi") self.hom = gap.eval("phi") def _gap_init_(self): return self._gap_str def __call__( self, g ): """ Some python code for wrapping GAP's Images function for a matrix group G. Returns an error if g is not in G. EXAMPLES:: sage: F = GF(5); MS = MatrixSpace(F,2,2) sage: g = MS([1,1,0,1]) sage: G = MatrixGroup([g]) sage: phi = G.hom(G.gens()) sage: phi(G.0) [1 1] [0 1] sage: phi(G(g^2)) [1 2] [0 1] :: sage: F = GF(5); MS = MatrixSpace(F,2,2) sage: gens = [MS([1,2,  -1,1]),MS([1,1,  0,1])] sage: G = MatrixGroup(gens) sage: phi = G.hom(G.gens()) sage: phi(G.0) [1 2] [4 1] sage: phi(G.1) [1 1] [0 1] """ Some python code for wrapping GAP's Images function for a matrix group G. Returns an error if g is not in G. EXAMPLES:: sage: F = GF(5); MS = MatrixSpace(F,2,2) sage: g = MS([1,1,0,1]) sage: G = MatrixGroup([g]) sage: phi = G.hom(G.gens()) sage: phi(G.0) [1 1] [0 1] sage: phi(G(g^2)) [1 2] [0 1] :: sage: F = GF(5); MS = MatrixSpace(F,2,2) sage: gens = [MS([1,2,  -1,1]),MS([1,1,  0,1])] sage: G = MatrixGroup(gens) sage: phi = G.hom(G.gens()) sage: phi(G.0) [1 2] [4 1] sage: phi(G.1) [1 1] [0 1] """ cmd = self._gap_hom_string gap.eval(cmd) G = self.domain() F = G.base_ring() h = gap(g) return gap('Image(phi, %s)'%h.name())._matrix_(F) return gap('Image(phi, %s)'%h.name())._matrix_(F)
• ## sage/groups/perm_gps/permgroup.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/groups/perm_gps/permgroup.py
 a if p == 0: L = eval(gap.eval("GroupCohomology(%s,%s)"%(GG,n))) else: L = eval(gap.eval("GroupCohomology(%s,%s,%s)"%(GG,n,p))) L = eval(gap.eval("GroupCohomology(%s,%s,%s)"%(GG,n,p))) return AbelianGroup(len(L),L) def cohomology_part(self, n, p = 0): gap.eval("S := SylowSubgroup(%s,%s)"%(GG,p)) gap.eval("R:=ResolutionFiniteGroup(S,%s)"%(n+1)) gap.eval("HR:=HomToIntegers(R)") L = eval(gap.eval("Cohomology(HR,%s)"%n)) L = eval(gap.eval("Cohomology(HR,%s)"%n)) return AbelianGroup(len(L),L) def homology(self, n, p = 0): if p == 0: L = eval(gap.eval("GroupHomology(%s,%s)"%(GG,n))) else: L = eval(gap.eval("GroupHomology(%s,%s,%s)"%(GG,n,p))) L = eval(gap.eval("GroupHomology(%s,%s,%s)"%(GG,n,p))) return AbelianGroup(len(L),L) def homology_part(self, n, p = 0): gap.eval("S := SylowSubgroup(%s,%s)"%(GG,p)) gap.eval("R:=ResolutionFiniteGroup(S,%s)"%(n+1)) gap.eval("TR:=TensorWithIntegers(R);") L = eval(gap.eval("Homology(TR,%s)"%n)) L = eval(gap.eval("Homology(TR,%s)"%n)) return AbelianGroup(len(L),L) def character_table(self): L = gap("List([1..Length(%s)], i->Representative(%s[i]))"%( cl.name(),  cl.name())) return [PermutationGroup(gap_group=L[i])for i in range(1,n+1)] def normalizer(self, g): """ Returns the normalizer of g in self. if not (G.has_element(x)): return False return True def is_supersolvable(self): """ Returns True if the group is supersolvable. A finite group is gap.eval("cc := ConstituentsOfCharacter( pi )") M = gap.eval("M := MolienSeries(Sum(cc))") R = PolynomialRing(RationalField(),"x") x = R.gen() x = R.gen() nn = gap.eval("NumeratorOfRationalFunction(M)") dd = gap.eval("DenominatorOfRationalFunction(M)") FF = FractionField(R) GG = G._gap_init_() ff = gap.eval("ff := PoincareSeriesPrimePart(%s,%s,%s)"%(GG,p,n)) R = PolynomialRing(RationalField(),"x") x = R.gen() x = R.gen() nn = gap.eval("NumeratorOfRationalFunction(ff)").replace("x_1","x") dd = gap.eval("DenominatorOfRationalFunction(ff)").replace("x_1","x") FF = FractionField(R)
• ## sage/groups/perm_gps/permgroup_morphism.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/groups/perm_gps/permgroup_morphism.py
 a A set-theoretic map between PermutationGroups. """ def __init__(self, parent): Morphism.__init__(self, parent) Morphism.__init__(self, parent) def _repr_type(self): return "PermutationGroup" self._codomain = H if not(isinstance(G, PermutationGroup_generic)): raise TypeError, "Sorry, the groups must be permutation groups." if not(isinstance(H, PermutationGroup_generic)): if not(isinstance(H, PermutationGroup_generic)): raise TypeError, "Sorry, the groups must be permutation groups." G0  = G._gap_init_() H0  = H._gap_init_() G0  = G._gap_init_() H0  = H._gap_init_() self.gap_hom_string = gap_hom_str self._name = name self.hom = gap.eval(gap_hom_str) def __call__( self, g ): """ Some python code for wrapping GAP's Images function but only for permutation groups. Returns an error if g is not in G. """ Some python code for wrapping GAP's Images function but only for permutation groups. Returns an error if g is not in G. """ cmd = self.gap_hom_string gap.eval(cmd) return PermutationGroupElement(gap.eval("Image( "+self._name+", "+str(g)+")"),self.range(), check = True) return PermutationGroupElement(gap.eval("Image( "+self._name+", "+str(g)+")"),self.range(), check = True) class PermutationGroupMorphism_im_gens: """ self._codomain = H if not(isinstance(G, PermutationGroup_generic)): raise TypeError, "Sorry, the groups must be permutation groups." if not(isinstance(H, PermutationGroup_generic)): if not(isinstance(H, PermutationGroup_generic)): raise TypeError, "Sorry, the groups must be permutation groups." G0  = G._gap_init_() H0  = H._gap_init_() gaplist_gens = [gap_format(x) for x in gensG] gaplist_imgs = [gap_format(x) for x in imgsH] L = gaplist_gens if len(L) == 1: G0  = G._gap_init_() H0  = H._gap_init_() gaplist_gens = [gap_format(x) for x in gensG] gaplist_imgs = [gap_format(x) for x in imgsH] L = gaplist_gens if len(L) == 1: genss = "["+L[0]+"]" if len(L)>1: if len(L)>1: genss = "["+L[0]+''.join([","+L[i+1] for i in range(len(L)-1)])+"]" L = gaplist_imgs if len(L) == 1: L = gaplist_imgs if len(L) == 1: imgss = "["+L[0]+"]" if len(L)>1: if len(L)>1: imgss = "["+L[0]+''.join([","+L[i+1] for i in range(len(L)-1)])+"]" args = str(G0)+","+str(H0)+","+genss+","+ imgss phi0 = gap.eval("phi := GroupHomomorphismByImages("+args+")") args = str(G0)+","+str(H0)+","+genss+","+ imgss phi0 = gap.eval("phi := GroupHomomorphismByImages("+args+")") self.gap_hom_string = "phi := GroupHomomorphismByImages("+args+")" if phi0=="fail": if phi0=="fail": raise ValueError,"The map "+str(gensG)+"-->"+str(imgsH)+" isn't a homomorphism." self.hom = gap.eval("phi") self.hom = gap.eval("phi") def __repr__(self): return "Homomorphism : %s --> %s"%(self.domain(),self.range()) def __call__( self, g ): """ Some python code for wrapping GAP's Images function but only for permutation groups. Returns an error if g is not in G. EXAMPLES:: sage: G = CyclicPermutationGroup(4) Some python code for wrapping GAP's Images function but only for permutation groups. Returns an error if g is not in G. EXAMPLES:: sage: G = CyclicPermutationGroup(4) sage: gens = G.gens() sage: H = DihedralGroup(4) sage: phi = PermutationGroupMorphism_im_gens( G, H, gens, gens) sage: g = G([(1,3),(2,4)]); g (1,3)(2,4) (1,3)(2,4) sage: phi(g) (1,3)(2,4) """ (1,3)(2,4) """ return self.image(g) PermutationGroupMorphism = PermutationGroupMorphism_im_gens
• ## sage/groups/perm_gps/permgroup_named.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/groups/perm_gps/permgroup_named.py
 a """ Return True if this group is commutative. EXAMPLES: EXAMPLES: sage: C = CyclicPermutationGroup(8) sage: C.is_commutative() True """ Return True if this group is abelian. EXAMPLES: EXAMPLES: sage: C = CyclicPermutationGroup(8) sage: C.is_abelian() True return True def as_AbelianGroup(self): """ Returns the corresponding Abelian Group instance. EXAMPLES: """ Returns the corresponding Abelian Group instance. EXAMPLES: sage: C = CyclicPermutationGroup(8) sage: C.as_AbelianGroup() Multiplicative Abelian Group isomorphic to C8 """ n = self.order() """ n = self.order() a = list(factor(n)) invs = [x[0]**x[1] for x in a] G = AbelianGroup(len(a),invs) return G return G class KleinFourGroup(PermutationGroup_generic): def __init__(self): r""" sage: DihedralGroup(2) Dihedral group of order 4 as a permutation group sage: DihedralGroup(2).gens() [(3,4), (1,2)] [(3,4), (1,2)] sage: DihedralGroup(5).gens() [(1,2,3,4,5), (1,5)(2,4)] from sage.rings.arith import valuation t = valuation(q, 2) if 2**t != q or is_even(t): raise ValueError,"The ground field size %s must be an odd power of 2."%q raise ValueError,"The ground field size %s must be an odd power of 2."%q id = 'SuzukiGroup(IsPermGroup,%s)'%q PermutationGroup_generic.__init__(self, gap_group=id) self._q = q
• ## sage/gsl/dwt.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/gsl/dwt.pyx
 a if self.wavelet != NULL: gsl_wavelet_free(self.wavelet) gsl_wavelet_workspace_free(self.workspace) def forward_transform(self): gsl_wavelet_transform_forward(self.wavelet,self.data,self.stride,self.n,self.workspace)
• ## sage/interfaces/ecm.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/interfaces/ecm.py
 a child = pexpect.spawn(self.__cmd) cleaner.cleaner(child.pid, self.__cmd) child.timeout = None child.__del__ = nothing   # work around stupid exception ignored error child.__del__ = nothing   # work around stupid exception ignored error child.expect('[ECM]') child.sendline(str(n)) child.sendline("bad") # child.sendeof() child = pexpect.spawn(self.__cmd) cleaner.cleaner(child.pid, self.__cmd) child.timeout = None child.__del__ = nothing   # program around stupid exception ignored error child.__del__ = nothing   # program around stupid exception ignored error child.expect('[ECM]') child.sendline(str(n)) child.sendline("bad") # child.sendeof()
• ## sage/interfaces/macaulay2.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/interfaces/macaulay2.py
 a return P.eval('%s == 0'%self.name()) == 'false' def sage_polystring(self): """ If this Macaulay2 element is a polynomial, return a string representation of this polynomial that is suitable for evaluation in Python.  Thus * is used for multiplication and ** for exponentiation.   This function is primarily used internally. EXAMPLES: """ If this Macaulay2 element is a polynomial, return a string representation of this polynomial that is suitable for evaluation in Python.  Thus * is used for multiplication and ** for exponentiation.   This function is primarily used internally. EXAMPLES: sage: R = macaulay2.ring('QQ','(x,y)')               # optional sage: f = macaulay2('x^3 + 3*y^11 + 5')              # optional sage: print f                                        # optional x  + 3y   + 5 sage: f.sage_polystring()                            # optional 'x**3+3*y**11+5' """ """ return self.external_string().replace('^','**') def structure_sheaf(self):
• ## sage/interfaces/maxima.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/interfaces/maxima.py
 a self._synchronize() if len(line) > self.__eval_using_file_cutoff: # This implicitly uses the set method, then displays the result of the thing that was set. # This implicitly uses the set method, then displays the result of the thing that was set. # This only works when the input line is an expression.   But this is our only choice, since # batchmode doesn't display expressions to screen. a = self(line)
• ## sage/interfaces/phc.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/interfaces/phc.py
• ## sage/interfaces/singular.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/interfaces/singular.py
 a return P.eval('%s == 0'%self.name()) == '0' def sage_polystring(self): r""" If this Singular element is a polynomial, return a string representation of this polynomial that is suitable for evaluation in Python. Thus \* is used for multiplication and \*\* for exponentiation. This function is primarily used internally. The short=0 option *must* be set for the parent ring or this function will not work as expected. This option is set by default for rings created using singular.ring or set using ring_name.set_ring(). EXAMPLES:: sage: R = singular.ring(0,'(x,y)') sage: f = singular('x^3 + 3*y^11 + 5') sage: f x^3+3*y^11+5 sage: f.sage_polystring() 'x**3+3*y**11+5' """ r""" If this Singular element is a polynomial, return a string representation of this polynomial that is suitable for evaluation in Python. Thus \* is used for multiplication and \*\* for exponentiation. This function is primarily used internally. The short=0 option *must* be set for the parent ring or this function will not work as expected. This option is set by default for rings created using singular.ring or set using ring_name.set_ring(). EXAMPLES:: sage: R = singular.ring(0,'(x,y)') sage: f = singular('x^3 + 3*y^11 + 5') sage: f x^3+3*y^11+5 sage: f.sage_polystring() 'x**3+3*y**11+5' """ return str(self).replace('^','**')
• ## sage/libs/ntl/ntl_mat_GF2.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/libs/ntl/ntl_mat_GF2.pyx
 a def __invert__(self): """ Return $X = A^{-1}$; an error is raised if A is singular. Return $X = A^{-1}$; an error is raised if A is singular. EXAMPLES: sage: l = [0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, \
• ## sage/libs/ntl/ntl_mat_GF2E.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/libs/ntl/ntl_mat_GF2E.pyx
 a def __invert__(self): """ Return $X = A^{-1}$; an error is raised if A is singular. Return $X = A^{-1}$; an error is raised if A is singular. EXAMPLES: sage: ctx = ntl.GF2EContext([1,1,0,1,1,0,0,0,1])
• ## sage/libs/pari/gen.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/libs/pari/gen.pyx
 a 't_POL' """ # The following original code leaks memory: #        return str(type_name(typ(self.g))) # # This code is the usual workaround: #        cdef char* s= type_name(typ(self.g)) #        t=str(s) #        free(s) #        return(t) #        return str(type_name(typ(self.g))) # # This code is the usual workaround: #        cdef char* s= type_name(typ(self.g)) #        t=str(s) #        free(s) #        return(t) # However, it causes segfaults with t_INTs on some # machines, and errors about freeing non-aligned # pointers on others. So we settle for the following
• ## sage/matrix/constructor.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/matrix/constructor.py
 a entries = 0 entry_ring = rings.ZZ elif isinstance(args[0][0], (list, tuple)) or is_Vector(args[0][0]): # Ensure we have a list of lists, each inner list having the same number of elements first_len = len(args[0][0]) if not all( (isinstance(v, (list, tuple)) or is_Vector(v)) and len(v) == first_len for v in args[0]): raise ValueError, "List of rows is not valid (rows are wrong types or lengths)" # Ensure we have a list of lists, each inner list having the same number of elements first_len = len(args[0][0]) if not all( (isinstance(v, (list, tuple)) or is_Vector(v)) and len(v) == first_len for v in args[0]): raise ValueError, "List of rows is not valid (rows are wrong types or lengths)" # We have a list of rows or vectors if nrows is None: nrows = len(args[0]) elif nrows != len(args[0]): raise ValueError, "Number of rows does not match up with specified number." if ncols is None: ncols = len(args[0][0]) ncols = len(args[0][0]) elif ncols != len(args[0][0]): raise ValueError, "Number of columns does not match up with specified number."
• ## sage/matrix/matrix_double_dense.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/matrix/matrix_double_dense.pyx
 a [               2.0                3.0] [               4.0                5.0] Due to numerical noise issues on Intel Macs, the following fails if 1e-14 is changed to 1e-15: Due to numerical noise issues on Intel Macs, the following fails if 1e-14 is changed to 1e-15: sage: max((U*S*V.transpose()-m).list())<1e-14 # check True
• ## sage/matrix/matrix_mod2_dense.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/matrix/matrix_mod2_dense.pyx
 a INPUT: right -- Matrix k -- parameter $k$ for the Gray Code table size. If $k=0$ a suitable value is chosen by the function. ($0<= k <= 16$, default: 0) suitable value is chosen by the function. ($0<= k <= 16$, default: 0) EXAMPLE: sage: A = Matrix(GF(2), 4, 3, [0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1] ) multiplication as implemented in the M4RI library. REFERENCES: [AHU] A. Aho, J. Hopcroft, and J. Ullman. 'Chapter 6: [AHU] A. Aho, J. Hopcroft, and J. Ullman. 'Chapter 6: Matrix Multiplication and Related Operations.' The Design and Analysis of Computer Algorithms. Addison-Wesley, 1974. if self._nrows and self._ncols: mzd_copy(A._entries, self._entries) if self.subdivisions is not None: A.subdivide(*self.get_subdivisions()) def submatrix(self, lowr, lowc, nrows , ncols): """ Return submatrix from the index lowr,lowc (inclusive) with dimension nrows x ncols. Return submatrix from the index lowr,lowc (inclusive) with dimension nrows x ncols. INPUT: lowr -- index of start row True sage: A[1:200,1:200] == A.submatrix(1,1,199,199) True """ """ cdef Matrix_mod2_dense A cdef int highr, highc
• ## sage/matrix/matrix_modn_dense.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/matrix/matrix_modn_dense.pyx
 a self.cache('det', d2) return d2 else: return matrix_dense.Matrix_dense.determinant(self) return matrix_dense.Matrix_dense.determinant(self) def randomize(self, density=1): """
• ## sage/misc/darcs.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/misc/darcs.py
 a Run 'darcs cmd' where cmd is an arbitrary string in the darcs repository. """ darcs_ensure_installed() darcs_ensure_installed() if check_initialized and not self.__initialized: self.initialize() darcs_ensure_installed()
• ## sage/misc/edit_module.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/misc/edit_module.py
 a infile.readline() if infile.readline().find("*autogenerated*") >= 0: filename=filename[:-3]+'.sage' lineno = lineno-3 lineno = lineno-3 sageroot = sage.misc.sageinspect.SAGE_ROOT+'/' runbranches = ['local/lib/python/site-packages',
• ## sage/misc/hg.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/misc/hg.py
 a if self.__name == "SAGE Library Source Code": b = branch_current_hg() if b == '': b='main' elif b[-1] == '/': b = b[:-1] elif b[-1] == '/': b = b[:-1] print("Branch: %s"%b) SAGE_INCOMING_SERVER = os.getenv("SAGE_INCOMING_SERVER") if SAGE_INCOMING_SERVER is None: try: SAGE_INCOMING_SERVER = os.environ['SAGE_HG_SERVER'].strip('/') SAGE_INCOMING_SERVER = os.environ['SAGE_HG_SERVER'].strip('/') except KeyError: #print "Falling back to a hard coded sage server in misc/hg.py" SAGE_INCOMING_SERVER = DEFAULT_SERVER
• ## sage/modular/dirichlet.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/modular/dirichlet.py
 a r""" Return the "twisted" Kloosterman sum associated to this Dirichlet character. This includes Gauss sums, classical Kloosterman sums, Salie sums, etc. The Kloosterman sum associated to $\chi$ and the integers a,b is  K(a,b,\chi) = \sum_{r \in (\Z/m\Z)^\times} \chi(r)\,\zeta^{ar+br^{-1}}, EXAMPLES:: sage: G = DirichletGroup(3) sage: e = G([-1]) sage: e.kloosterman_sum(3,5) -2*zeta6 + 1 sage: G = DirichletGroup(20) sage: e = G([1 for  u in G.unit_gens()]) sage: e.kloosterman_sum(7,17) -2*zeta20^6 + 2*zeta20^4 + 4 sage: e = G([-1]) sage: e.kloosterman_sum(3,5) -2*zeta6 + 1 sage: G = DirichletGroup(20) sage: e = G([1 for  u in G.unit_gens()]) sage: e.kloosterman_sum(7,17) -2*zeta20^6 + 2*zeta20^4 + 4 """ G = self.parent() K = G.base_ring() def kloosterman_sum_numerical(self, prec=53, a=1,b=0): r""" Return the Kloosterman sum associated to this Dirichlet character as an approximate complex number with prec bits of precision. INPUT: -  prec -- integer (deafault: 53), *bits* of precision -  a -- integer, as for kloosterman_sum -  b -- integer, as for kloosterman_sum. EXAMPLES:: Return the Kloosterman sum associated to this Dirichlet character as an approximate complex number with prec bits of precision. INPUT: -  prec -- integer (deafault: 53), *bits* of precision -  a -- integer, as for kloosterman_sum -  b -- integer, as for kloosterman_sum. EXAMPLES:: sage: G = DirichletGroup(3) sage: e = G.0 sage: G = DirichletGroup(3) sage: e = G.0 The real component of the numerical value of e is near zero:: True sage: v.imag() 1.73205080757 sage: G = DirichletGroup(20) sage: e = G.1 sage: e.kloosterman_sum_numerical(53,3,11) 3.80422606518 - 3.80422606518*I """ G = self.parent() K = G.base_ring() if not (rings.is_CyclotomicField(K) or rings.is_RationalField(K)): sage: G = DirichletGroup(20) sage: e = G.1 sage: e.kloosterman_sum_numerical(53,3,11) 3.80422606518 - 3.80422606518*I """ G = self.parent() K = G.base_ring() if not (rings.is_CyclotomicField(K) or rings.is_RationalField(K)): raise NotImplementedError, "Kloosterman sums only currently implemented when the base ring is a cyclotomic field or QQ." phi = K.complex_embedding(prec) CC = phi.codomain() CC = phi.codomain() g = 0 m = G.modulus() zeta = CC.zeta(m) for c in range(1,m): for c in range(1,m): if arith.gcd(c,m)==1: e = rings.Mod(c,m) z = zeta ** (a*e + b*(e**(-1)))
• ## sage/modular/modform/eisenstein_submodule.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/modular/modform/eisenstein_submodule.py
 a ] sage: M = ModularForms(19,3).eisenstein_subspace() sage: M.eisenstein_series() sage: M.eisenstein_series() [ ] """ """ # TODO #def _compute_q_expansion_basis(self, prec): #B = EisensteinSubmodule_params._compute_q_expansion_basis(self, prec) #B = EisensteinSubmodule_params._compute_q_expansion_basis(self, prec) #raise NotImplementedError, "must restrict scalars down correctly."
• ## sage/modular/overconvergent/weightspace.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/modular/overconvergent/weightspace.py
 a """ # This should probably derive from Morphism or even from # AbelianGroupMorphism; but SAGE doesn't know about the abelian group # Z_p^*, so Hom(Z_p^*, C_p^*) is a bit beyond it! # AbelianGroupMorphism; but SAGE doesn't know about the abelian group # Z_p^*, so Hom(Z_p^*, C_p^*) is a bit beyond it! def __init__(self, parent): r""" WeightCharacter.__init__(self, parent) self.t = ZZ(t) % (self._p > 2 and (self._p - 1) or 2) # do we store w precisely? # do we store w precisely? if (w - 1).valuation() <= 0: raise ValueError, "Must send generator to something nearer 1" self.w = w
• ## sage/modular/quatalg/brandt.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/modular/quatalg/brandt.py
 a .. math: T_n[I]=\sum_{\phi} [J] T_n[I]=\sum_{\phi} [J] where '(n,pM)=1' and the sum is over cyclic '\mathcal{O}'-module homomorphisms '\phi :I\rightarrow J ' of degree 'n' up to isomorphism of 'J'. Equivalently one can sum over the inclusions of the submodules .. math: \theta_L(q)=\sum_{x \in L} q^{\frac{N(x)}{N(L)}} \theta_L(q)=\sum_{x \in L} q^{\frac{N(x)}{N(L)}} L.theta_series(T,q) returns a power series representing '\theta_L(q)' up to a precision of '\mathcal{O}(q^{T+1})'.
• ## sage/modules/free_module.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/modules/free_module.py
 a if self.is_ambient(): return sage.matrix.matrix_space.MatrixSpace(self.base_ring(), self.degree(), sparse=True)(1) else: if self._gram_matrix is None: if self._gram_matrix is None: B = self.basis_matrix() self._gram_matrix = B*B.transpose() self._gram_matrix = B*B.transpose() return self._gram_matrix def has_user_basis(self): quo = quomap.codomain() liftmap = quo.Hom(self)(L) return quomap.codomain(), quomap, liftmap return quomap.codomain(), quomap, liftmap ############################################################################### #
• ## sage/modules/free_module_element.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/modules/free_module_element.pyx
 a sage: vector(v, ZZ['x', 'y']) (2, 12, 22) sage: vector(vector((1, 6.8))) (1.00000000000000, 6.80000000000000) sage: vector(vector(SR, (1, sqrt(2)) ) ) (1, sqrt(2)) sage: vector(vector((1, 6.8))) (1.00000000000000, 6.80000000000000) sage: vector(vector(SR, (1, sqrt(2)) ) ) (1, sqrt(2)) """ if R is None: R = self.base_ring()

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/modules/free_quadratic_module.py
 a the ambient space), and B the basis matrix. EXAMPLES: sage: V = VectorSpace(QQ,4) sage: u = V([1/2,1/2,1/2,1/2]) sage: v = V([0,1,1,0]) sage: w = V([0,0,1,1]) sage: M = span([u,v,w], ZZ) sage: M.inner_product_matrix() == V.inner_product_matrix() True sage: L = M.submodule_with_basis([u,v,w]) sage: L.inner_product_matrix() == M.inner_product_matrix() True sage: L.gram_matrix() [1 1 1] [1 2 1] [1 1 2] sage: V = VectorSpace(QQ,4) sage: u = V([1/2,1/2,1/2,1/2]) sage: v = V([0,1,1,0]) sage: w = V([0,0,1,1]) sage: M = span([u,v,w], ZZ) sage: M.inner_product_matrix() == V.inner_product_matrix() True sage: L = M.submodule_with_basis([u,v,w]) sage: L.inner_product_matrix() == M.inner_product_matrix() True sage: L.gram_matrix() [1 1 1] [1 2 1] [1 1 2] """ if self.is_ambient(): return self.inner_product_matrix() return self.inner_product_matrix() else: if self._gram_matrix is None: A = self.inner_product_matrix() if self._gram_matrix is None: A = self.inner_product_matrix() B = self.basis_matrix() self._gram_matrix = B*A*B.transpose() self._gram_matrix = B*A*B.transpose() return self._gram_matrix def inner_product_matrix(self): [0 1 0] [0 0 1] The inner product does not have to be symmetric or definite. The inner product does not have to be symmetric or definite. sage: N = FreeModule(ZZ,2,inner_product_matrix=[[1,-1],[2,5]]) sage: N.inner_product_matrix() [ 1 -1] [ 2  5] sage: u, v = N.basis() sage: u.inner_product(v) -1 sage: v.inner_product(u) 2 sage: u, v = N.basis() sage: u.inner_product(v) -1 sage: v.inner_product(u) 2 The inner product matrix is defined with respect to the ambient space. The inner product matrix is defined with respect to the ambient space. sage: V = QQ^3 sage: u = V([1/2,1,1]) sage: v = V([1,1,1/2]) sage: M = span([u,v], ZZ) sage: M.inner_product_matrix() sage: V = QQ^3 sage: u = V([1/2,1,1]) sage: v = V([1,1,1/2]) sage: M = span([u,v], ZZ) sage: M.inner_product_matrix() [1 0 0] [0 1 0] [0 0 1] sage: M.inner_product_matrix() == V.inner_product_matrix() True sage: M.gram_matrix() [ 1/2 -3/4] [-3/4 13/4] sage: M.inner_product_matrix() == V.inner_product_matrix() True sage: M.gram_matrix() [ 1/2 -3/4] [-3/4 13/4] """ return self._inner_product_matrix
• ## sage/modules/matrix_morphism.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/modules/matrix_morphism.py
 a return H(MS(ims)) #D  = self.domain() #C  = self.codomain() #M  = self.matrix() #Mr = M.restrict_domain(sub) #return sub.Hom(C)(Mr) #C  = self.codomain() #M  = self.matrix() #Mr = M.restrict_domain(sub) #return sub.Hom(C)(Mr) def restrict_codomain(self, sub): """ Restrict this matrix morphism to a subspace sub of the codomain. The resulting morphism has the same domain as before, but a new codomain. """ A = self.matrix().restrict_codomain(sub.free_module()) Restrict this matrix morphism to a subspace sub of the codomain. The resulting morphism has the same domain as before, but a new codomain. """ A = self.matrix().restrict_codomain(sub.free_module()) H = sage.categories.homset.Hom(self.domain(), sub, self.domain().category()) return H(A)
• ## sage/monoids/string_monoid.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/monoids/string_monoid.py
• ## sage/rings/finite_field_ntl_gf2e.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/rings/finite_field_ntl_gf2e.pyx
 a ... NameError: name 'b' is not defined sage: R.=GF(2)[] sage: k(1+x+x^10+x^55) a^19 + a^17 + a^16 + a^15 + a^12 + a^11 + a^8 + a^6 + a^4 + a^2 + 1 sage: R.=GF(2)[] sage: k(1+x+x^10+x^55) a^19 + a^17 + a^16 + a^15 + a^12 + a^11 + a^8 + a^6 + a^4 + a^2 + 1 sage: V = k.vector_space() sage: v = V.random_element(); v
• ## sage/rings/integer_mod.pyx

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/rings/integer_mod.pyx
 a other must be coprime to the modulus of self. EXAMPLES:: EXAMPLES:: sage: a = mod(3,5) sage: b = mod(2,7) to other. The modulus of other must be coprime to the modulus of self. EXAMPLES:: EXAMPLES:: sage: a = mod(3,5) sage: b = mod(2,7) to other. The modulus of other must be coprime to the modulus of self. EXAMPLES:: EXAMPLES:: sage: a = mod(3,5^10) sage: b = mod(2,7)
• ## sage/rings/number_field/number_field.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/rings/number_field/number_field.py
 a return self.extension(f, names) def hilbert_class_polynomial(self, name='x'): r""" Compute the Hilbert class polynomial of this quadratic field. r""" Compute the Hilbert class polynomial of this quadratic field. Right now, this is only implemented for imaginary quadratic fields. EXAMPLES:: EXAMPLES:: sage: K. = QuadraticField(-3) sage: K.hilbert_class_polynomial() sage: K. = QuadraticField(-31) sage: K.hilbert_class_polynomial(name='z') z^3 + 39491307*z^2 - 58682638134*z + 1566028350940383 """ D = self.discriminant() """ D = self.discriminant() if D > 0: raise NotImplementedError, "Hilbert class polynomial is not implemented for real quadratic fields." # get all reduced quadratic forms # get all reduced quadratic forms from sage.quadratic_forms.binary_qf import BinaryQF_reduced_representatives rqf = BinaryQF_reduced_representatives(D) # compute needed  precision # (according to [http://arxiv.org/abs/0802.0979v1]) N = (D.abs()//3).isqrt()+1 h = len(rqf) a_s = [1/qf.a for qf in rqf] rqf = BinaryQF_reduced_representatives(D) # compute needed  precision # (according to [http://arxiv.org/abs/0802.0979v1]) N = (D.abs()//3).isqrt()+1 h = len(rqf) a_s = [1/qf.a for qf in rqf] from sage.rings.all import RR prec = RR(sum(a_s, 0)*5.1416*D.abs().isqrt()+h*2.48).floor()+1 prec = max(prec, 71) # set appropriate precision for further computing prec = RR(sum(a_s, 0)*5.1416*D.abs().isqrt()+h*2.48).floor()+1 prec = max(prec, 71) # set appropriate precision for further computing from sage.rings.all import ComplexField __CC = ComplexField(prec) __CC = ComplexField(prec) Dsqrt = D.sqrt(prec=prec) R = __CC['t'] R = __CC['t'] t = R.gen() pol = R(1) pol = R(1) for qf in rqf: tau = (qf.b+Dsqrt)/(qf.a<<1) jinv = pari(tau).ellj() pol = pol * (t - __CC(jinv)) coeffs = [cof.real().round() for cof in pol.coeffs()] coeffs = [cof.real().round() for cof in pol.coeffs()] R = ZZ[name] return R(coeffs) return R(coeffs)
• ## sage/rings/number_field/totallyreal_phc.py

diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/rings/number_field/totallyreal_phc.py
 a sage: __lagrange_bounds_phc(3,5,[8,1,2,0,1]) # optional [] sage: x, y = __lagrange_bounds_phc(3,2,[8,1,2,0,1]) # optional sage: x # optional sage: x # optional -1.3333333333333299 sage: y < 0.00000001 # optional True sage: y < 0.00000001 # optional True sage: __lagrange_bounds_phc(3,1,[8,1,2,0,1]) # optional [] """
diff -r 84d47cdd7003 -r 203bbc5a8a5f sage/rings/padics/local_generic.py