当前位置: 首页>>代码示例>>Python>>正文


Python MatrixSpace.basis方法代码示例

本文整理汇总了Python中sage.matrix.matrix_space.MatrixSpace.basis方法的典型用法代码示例。如果您正苦于以下问题:Python MatrixSpace.basis方法的具体用法?Python MatrixSpace.basis怎么用?Python MatrixSpace.basis使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sage.matrix.matrix_space.MatrixSpace的用法示例。


在下文中一共展示了MatrixSpace.basis方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: pairs

# 需要导入模块: from sage.matrix.matrix_space import MatrixSpace [as 别名]
# 或者: from sage.matrix.matrix_space.MatrixSpace import basis [as 别名]
class SubsetPairs:
    """The collection of all pairs (E,B) where E and B are subsets of Z_p^d."""
    def __init__(self, modulus, dimension):
        self.modulus = int(modulus) #The modulus p
        self.dimension = int(dimension) #The dimension d
        self.field = FiniteField(modulus) #The underlying field
        self.space = MatrixSpace(self.field, 1, dimension) #The space of vectors in Z_p^d viewed as matrices
        self.elements = list(self.space) #An actual list of those vectors
        self.basis = self.space.basis() #The standard basis for the vector space
    # Preliminary construction of the possible subsets of size "size", implemented as a python generator.
    # This is a huge speed bottleneck. Right now I just have it throwing out subsets if their vectors are not "in order" so
    # permutations of the same set are eliminated. There are faster ways to do this, but I haven't found one that is elegant yet.
    def subsets(self, size):
        for elem in MatrixSpace(self.field, self.dimension, size):
            passing = True
            for i in range(size - 1):
                if self.elements.index(Matrix(elem.transpose()[i])) >= self.elements.index(Matrix(elem.transpose()[i+1])):
                    passing = False
                    break
            if passing == True:
                yield(elem)
    # Create the sets of the first type which contain the zero vector and the standard basis vectors.
    # Note that these are not the only type of vectors which need to be checked in general, 
    # so this can only find certain types of counterexamples.
    def firstsets(self, size):
        for elem in self.subsets(size):
            if elem.columns()[0] == 0 * elem.columns()[0] and elem.rref() == elem and elem.rank() == min(size, self.dimension):
                yield(elem)
    # Create the sets of the second type which contain the zero vector.
    def secondsets(self, size):
        for elem in self.subsets(size):
            if elem.columns()[0] == 0 * elem.columns()[0]:
                yield(elem)
    # Create the log-Hadamard matrix for a given pair of subsets.
    def loghadamard(self, E, B):
        return E.transpose() * B
    # Check if the difference of two rows is balanced.
    def row_difference(self, row0, row1):
        difference_vector = list(row0 - row1)
        counters = {}
        for i in range(self.modulus):
            counters[i] = 0
        for entry in difference_vector:
            value = difference_vector[entry]
            counters[value] = counters[value] + 1
        for i in range(self.modulus - 1):
            if counters[i] != counters[i+1]:
                return False
        return True
    # Perform the appropriate tests on all subsets not already eliminated.
    # At the moment this still tests (B,E) even after (E,B) has been tested.
    def runtest(self, size):
        for elem0 in S.firstsets(size):
            for elem1 in S.secondsets(size):
                H = self.loghadamard(elem0, elem1)
                passing = True
                for i,j in [(i,j) for i in range(size) for j in range(size)]:
                    if i != j and self.row_difference(H[i], H[j]) == False:
                        print(H[i], H[j], H[i]-H[j]) #Comment if you don't want to watch pairs of vectors and their differences pour down the screen.
                        passing = False
                        break
                if passing == True:
                    print(elem0, elem1, H)
                    print("")
开发者ID:caten2,项目名称:FugledeProject,代码行数:66,代码来源:Fuglede.py


注:本文中的sage.matrix.matrix_space.MatrixSpace.basis方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。