本文整理汇总了Python中sage.matrix.constructor.Matrix.rank方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.rank方法的具体用法?Python Matrix.rank怎么用?Python Matrix.rank使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.matrix.constructor.Matrix
的用法示例。
在下文中一共展示了Matrix.rank方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import rank [as 别名]
class _FiniteBasisConverter:
def __init__(self, P, comb_mod, basis):
r"""
Basis should be a finite set of polynomials
"""
self._poly_ring = P
self._module = comb_mod
self._basis = basis
max_deg = max([self._poly_ring(b).degree() for b in self._basis])
monoms = []
for b in self._basis:
poly = self._poly_ring(b)
monoms += poly.monomials()
monoms_list = tuple(Set(monoms))
# check if the basis represented in terms of Monomials is efficient
degs = [self._poly_ring(m).degree() for m in monoms]
min_deg, max_deg = min(degs), max(degs)
monoms_obj = Monomials(self._poly_ring, (min_deg, max_deg + 1))
if monoms_obj.cardinality() < 2 * len(monoms_list):
computational_basis = monoms_obj
else:
computational_basis = monoms_list
self._monomial_module = PolynomialFreeModule(
P=self._poly_ring, basis=computational_basis)
cols = [self._monomial_module(b).to_vector() for b in self._basis]
self._basis_mat = Matrix(cols).transpose()
if self._basis_mat.ncols() > self._basis_mat.rank():
raise ValueError(
"Basis polynomials are not linearly independent")
def convert(self, p):
r"""
Algorithm is to convert all polynomials into monomials and use
linear algebra to solve for the appropriate coefficients in this
common basis.
"""
try:
p_vect = self._monomial_module(p).to_vector()
decomp = self._basis_mat.solve_right(p_vect)
except ValueError:
raise ValueError(
"Value %s is not spanned by the basis polynomials" % p)
polys = [v[1] * self._module.monomial(v[0])
for v in zip(self._basis, decomp)]
module_p = sum(polys, self._module.zero())
return module_p
示例2: is_start_of_basis
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import rank [as 别名]
def is_start_of_basis(self, List):
r"""
Determines if the inputed list of OMS families can be extended to a basis of this space.
More precisely, it checks that the elements of ``List`` are linearly independent modulo
the uniformizer (by checking the total measures).
INPUT:
- ``list`` -- a list of OMS's
OUTPUT:
- True/False
"""
for Phi in List:
assert Phi.valuation() >= 0, "Symbols must be integral"
R = self.base().base()
List = [Phi.list_of_total_measures_at_fixed_weight() for Phi in List]
d = len(List)
A = Matrix(R.residue_field(), d, len(List[0]), List)
Verbose("A =", A)
return A.rank() == d
示例3: Conic
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import rank [as 别名]
#.........这里部分代码省略.........
if names is None:
names = F
F = base_field
base_field = None
if isinstance(F, (list,tuple)):
if len(F) == 1:
return Conic(base_field, F[0], names)
if names == None:
names = 'x,y,z'
if len(F) == 5:
L=[]
for f in F:
if isinstance(f, SchemeMorphism_point_affine):
C = Sequence(f, universe = base_field)
if len(C) != 2:
raise TypeError, "points in F (=%s) must be planar"%F
C.append(1)
elif isinstance(f, SchemeMorphism_point_projective_field):
C = Sequence(f, universe = base_field)
elif isinstance(f, (list, tuple)):
C = Sequence(f, universe = base_field)
if len(C) == 2:
C.append(1)
else:
raise TypeError, "F (=%s) must be a sequence of planar " \
"points" % F
if len(C) != 3:
raise TypeError, "points in F (=%s) must be planar" % F
P = C.universe()
if not is_IntegralDomain(P):
raise TypeError, "coordinates of points in F (=%s) must " \
"be in an integral domain" % F
L.append(Sequence([C[0]**2, C[0]*C[1], C[0]*C[2], C[1]**2,
C[1]*C[2], C[2]**2], P.fraction_field()))
M=Matrix(L)
if unique and M.rank() != 5:
raise ValueError, "points in F (=%s) do not define a unique " \
"conic" % F
con = Conic(base_field, Sequence(M.right_kernel().gen()), names)
con.point(F[0])
return con
F = Sequence(F, universe = base_field)
base_field = F.universe().fraction_field()
temp_ring = PolynomialRing(base_field, 3, names)
(x,y,z) = temp_ring.gens()
if len(F) == 3:
return Conic(F[0]*x**2 + F[1]*y**2 + F[2]*z**2)
if len(F) == 6:
return Conic(F[0]*x**2 + F[1]*x*y + F[2]*x*z + F[3]*y**2 + \
F[4]*y*z + F[5]*z**2)
raise TypeError, "F (=%s) must be a sequence of 3 or 6" \
"coefficients" % F
if is_QuadraticForm(F):
F = F.matrix()
if is_Matrix(F) and F.is_square() and F.ncols() == 3:
if names == None:
names = 'x,y,z'
temp_ring = PolynomialRing(F.base_ring(), 3, names)
F = vector(temp_ring.gens()) * F * vector(temp_ring.gens())
if not is_MPolynomial(F):
raise TypeError, "F (=%s) must be a three-variable polynomial or " \
"a sequence of points or coefficients" % F
if F.total_degree() != 2:
raise TypeError, "F (=%s) must have degree 2" % F
if base_field == None:
base_field = F.base_ring()
if not is_IntegralDomain(base_field):
raise ValueError, "Base field (=%s) must be a field" % base_field
base_field = base_field.fraction_field()
if names == None:
names = F.parent().variable_names()
pol_ring = PolynomialRing(base_field, 3, names)
if F.parent().ngens() == 2:
(x,y,z) = pol_ring.gens()
F = pol_ring(F(x/z,y/z)*z**2)
if F == 0:
raise ValueError, "F must be nonzero over base field %s" % base_field
if F.total_degree() != 2:
raise TypeError, "F (=%s) must have degree 2 over base field %s" % \
(F, base_field)
if F.parent().ngens() == 3:
P2 = ProjectiveSpace(2, base_field, names)
if is_PrimeFiniteField(base_field):
return ProjectiveConic_prime_finite_field(P2, F)
if is_FiniteField(base_field):
return ProjectiveConic_finite_field(P2, F)
if is_RationalField(base_field):
return ProjectiveConic_rational_field(P2, F)
if is_NumberField(base_field):
return ProjectiveConic_number_field(P2, F)
return ProjectiveConic_field(P2, F)
raise TypeError, "Number of variables of F (=%s) must be 2 or 3" % F
示例4: basis_of_short_vectors
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import rank [as 别名]
def basis_of_short_vectors(self, show_lengths=False, safe_flag=None):
"""
Return a basis for `ZZ^n` made of vectors with minimal lengths Q(`v`).
OUTPUT: a tuple of vectors, and optionally a tuple of values for
each vector.
EXAMPLES::
sage: Q = DiagonalQuadraticForm(ZZ, [1,3,5,7])
sage: Q.basis_of_short_vectors()
((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1))
sage: Q.basis_of_short_vectors(True)
(((1, 0, 0, 0), (0, 1, 0, 0), (0, 0, 1, 0), (0, 0, 0, 1)), (1, 3, 5, 7))
The returned vectors are immutable::
sage: v = Q.basis_of_short_vectors()[0]
sage: v
(1, 0, 0, 0)
sage: v[0] = 0
Traceback (most recent call last):
...
ValueError: vector is immutable; please change a copy instead (use copy())
"""
if safe_flag is not None:
from sage.misc.superseded import deprecation
deprecation(18673, "The safe_flag argument to basis_of_short_vectors() is deprecated and no longer used")
## Set an upper bound for the number of vectors to consider
Max_number_of_vectors = 10000
## Generate a PARI matrix for the associated Hessian matrix
M_pari = self.__pari__()
## Run through all possible minimal lengths to find a spanning set of vectors
n = self.dim()
M1 = Matrix([[0]])
vec_len = 0
while M1.rank() < n:
vec_len += 1
pari_mat = M_pari.qfminim(vec_len, Max_number_of_vectors)[2]
number_of_vecs = ZZ(pari_mat.matsize()[1])
vector_list = []
for i in range(number_of_vecs):
new_vec = vector([ZZ(x) for x in list(pari_mat[i])])
vector_list.append(new_vec)
## Make a matrix from the short vectors
if len(vector_list) > 0:
M1 = Matrix(vector_list)
## Organize these vectors by length (and also introduce their negatives)
max_len = vec_len // 2
vector_list_by_length = [[] for _ in range(max_len + 1)]
for v in vector_list:
l = self(v)
vector_list_by_length[l].append(v)
vector_list_by_length[l].append(vector([-x for x in v]))
## Make a matrix from the column vectors (in order of ascending length).
sorted_list = []
for i in range(len(vector_list_by_length)):
for v in vector_list_by_length[i]:
sorted_list.append(v)
sorted_matrix = Matrix(sorted_list).transpose()
## Determine a basis of vectors of minimal length
pivots = sorted_matrix.pivots()
basis = tuple(sorted_matrix.column(i) for i in pivots)
for v in basis:
v.set_immutable()
## Return the appropriate result
if show_lengths:
pivot_lengths = tuple(self(v) for v in basis)
return basis, pivot_lengths
else:
return basis