本文整理匯總了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("")