本文整理汇总了Python中sage.matrix.constructor.Matrix.change_ring方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.change_ring方法的具体用法?Python Matrix.change_ring怎么用?Python Matrix.change_ring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.matrix.constructor.Matrix
的用法示例。
在下文中一共展示了Matrix.change_ring方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_powers_and_mult
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import change_ring [as 别名]
def _get_powers_and_mult(self,a,b,c,d,lambd,vect):
r"""
Compute the action of a matrix on the basis elements.
EXAMPLES:
::
"""
try:
xnew = self._powers[(a,b,c,d)]
except KeyError:
R=self._PowerSeries
r=R([b,a])
s=R([d,c])
n=self._n
if self._depth == n+1:
rpows=[R(1)]
spows=[R(1)]
for ii in range(n):
rpows.append(r*rpows[ii])
spows.append(s*spows[ii])
x=Matrix(self._Rmod,n+1,n+1,0)
for ii in range(n+1):
y=rpows[ii]*spows[n-ii]
for jj in range(self._depth):
x[ii,jj]=y[jj]
else:
ratio = r*(s**(-1))
y = s**n
x = Matrix(self._Rmod,self._depth,self._depth,0)
for jj in range(self._depth):
x[0,jj] = y[jj]
for ii in range(1,self._depth):
y *= ratio
for jj in range(self._depth):
x[ii,jj] = y[jj]
xnew = x.change_ring(self._R) #ZZ)
# if self._Rmod is self._R:
# xnew = x
# else:
# #xnew = x.change_ring(self._R)
# xnew = x.change_ring(ZZ)
self._powers[(a,b,c,d)] = xnew
tmp = xnew*vect
return self._R(lambd)*tmp #.change_ring(self._R)
示例2: Matroid
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import change_ring [as 别名]
#.........这里部分代码省略.........
if want_regular:
# Construct the incidence matrix
# NOTE: we are not using Sage's built-in method because
# 1) we would need to fix the loops anyway
# 2) Sage will sort the columns, making it impossible to keep labels!
V = G.vertices()
n = G.num_verts()
A = Matrix(ZZ, n, m, 0)
mm = 0
for i, j, k in G.edge_iterator():
A[V.index(i), mm] = -1
A[V.index(j), mm] += 1 # So loops get 0
mm += 1
M = RegularMatroid(matrix=A, groundset=groundset)
want_regular = False # Save some time, since result is already regular
else:
M = GraphicMatroid(G, groundset=groundset)
# Matrices:
elif key in ['matrix', 'reduced_matrix']:
A = data
is_reduced = (key == 'reduced_matrix')
# Fix the representation
if not is_Matrix(A):
if base_ring is not None:
A = Matrix(base_ring, A)
else:
A = Matrix(A)
# Fix the ring
if base_ring is not None:
if A.base_ring() is not base_ring:
A = A.change_ring(base_ring)
elif A.base_ring() is ZZ and not want_regular: # Usually a rational matrix is intended, we presume.
A = A.change_ring(QQ)
base_ring = QQ
else:
base_ring = A.base_ring()
# Check groundset
if groundset is not None:
if not is_reduced:
if len(groundset) == A.ncols():
pass
elif len(groundset) == A.nrows() + A.ncols():
is_reduced = True
else:
raise ValueError("groundset size does not correspond to matrix size")
elif is_reduced:
if len(groundset) == A.nrows() + A.ncols():
pass
else:
raise ValueError("groundset size does not correspond to matrix size")
if is_reduced:
kw = dict(groundset=groundset, reduced_matrix=A)
else:
kw = dict(groundset=groundset, matrix=A)
if isinstance(base_ring, FiniteField):
q = base_ring.order()
else:
q = 0
if q == 2:
示例3: BIBD_from_arc_in_desarguesian_projective_plane
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import change_ring [as 别名]
def BIBD_from_arc_in_desarguesian_projective_plane(n,k,existence=False):
r"""
Returns a `(n,k,1)`-BIBD from a maximal arc in a projective plane.
This function implements a construction from Denniston [Denniston69]_, who
describes a maximal :meth:`arc
<sage.combinat.designs.bibd.BalancedIncompleteBlockDesign.arc>` in a
:func:`Desarguesian Projective Plane
<sage.combinat.designs.block_design.DesarguesianProjectivePlaneDesign>` of
order `2^k`. From two powers of two `n,q` with `n<q`, it produces a
`((n-1)(q+1)+1,n,1)`-BIBD.
INPUT:
- ``n,k`` (integers) -- must be powers of two (among other restrictions).
- ``existence`` (boolean) -- whether to return the BIBD obtained through
this construction (default), or to merely indicate with a boolean return
value whether this method *can* build the requested BIBD.
EXAMPLES:
A `(232,8,1)`-BIBD::
sage: from sage.combinat.designs.bibd import BIBD_from_arc_in_desarguesian_projective_plane
sage: from sage.combinat.designs.bibd import BalancedIncompleteBlockDesign
sage: D = BIBD_from_arc_in_desarguesian_projective_plane(232,8)
sage: BalancedIncompleteBlockDesign(232,D)
(232,8,1)-Balanced Incomplete Block Design
A `(120,8,1)`-BIBD::
sage: D = BIBD_from_arc_in_desarguesian_projective_plane(120,8)
sage: BalancedIncompleteBlockDesign(120,D)
(120,8,1)-Balanced Incomplete Block Design
Other parameters::
sage: all(BIBD_from_arc_in_desarguesian_projective_plane(n,k,existence=True)
....: for n,k in
....: [(120, 8), (232, 8), (456, 8), (904, 8), (496, 16),
....: (976, 16), (1936, 16), (2016, 32), (4000, 32), (8128, 64)])
True
Of course, not all can be built this way::
sage: BIBD_from_arc_in_desarguesian_projective_plane(7,3,existence=True)
False
sage: BIBD_from_arc_in_desarguesian_projective_plane(7,3)
Traceback (most recent call last):
...
ValueError: This function cannot produce a (7,3,1)-BIBD
REFERENCE:
.. [Denniston69] R. H. F. Denniston,
Some maximal arcs in finite projective planes.
Journal of Combinatorial Theory 6, no. 3 (1969): 317-319.
http://dx.doi.org/10.1016/S0021-9800(69)80095-5
"""
q = (n-1)//(k-1)-1
if (k % 2 or
q % 2 or
q <= k or
n != (k-1)*(q+1)+1 or
not is_prime_power(k) or
not is_prime_power(q)):
if existence:
return False
raise ValueError("This function cannot produce a ({},{},1)-BIBD".format(n,k))
if existence:
return True
n = k
# From now on, the code assumes the notations of [Denniston69] for n,q, so
# that the BIBD returned by the method will have the requested parameters.
from sage.rings.finite_rings.constructor import FiniteField as GF
from sage.libs.gap.libgap import libgap
from sage.matrix.constructor import Matrix
K = GF(q,'a')
one = K.one()
# An irreducible quadratic form over K[X,Y]
GO = libgap.GeneralOrthogonalGroup(-1,2,q)
M = libgap.InvariantQuadraticForm(GO)['matrix']
M = Matrix(M)
M = M.change_ring(K)
Q = lambda xx,yy : M[0,0]*xx**2+(M[0,1]+M[1,0])*xx*yy+M[1,1]*yy**2
# Here, the additive subgroup H (of order n) of K mentioned in
# [Denniston69] is the set of all elements of K of degree < log_n
# (seeing elements of K as polynomials in 'a')
K_iter = list(K) # faster iterations
log_n = is_prime_power(n,get_data=True)[1]
#.........这里部分代码省略.........
示例4: Matroid
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import change_ring [as 别名]
#.........这里部分代码省略.........
# 1. Attempt to use edge labels.
sl = G.edge_labels()
if len(sl) == len(set(sl)):
kwds['groundset'] = sl
# 2. If simple, use vertex tuples
elif not G.has_multiple_edges():
kwds['groundset'] = [(i, j) for i, j, k in G.edge_iterator()]
else:
# 3. Use numbers
kwds['groundset'] = range(m)
M = RegularMatroid(matrix=A, groundset=kwds['groundset'])
want_regular = False # Save some time, since result is already regular
# Matrices:
if 'matrix' in kwds or 'reduced_matrix' in kwds:
if 'matrix' in kwds:
A = kwds['matrix']
if 'reduced_matrix' in kwds:
A = kwds['reduced_matrix']
# Fix the representation
if not isinstance(A, sage.matrix.matrix.Matrix):
try:
if base_ring is not None:
A = Matrix(base_ring, A)
else:
A = Matrix(A)
except ValueError:
raise ValueError("input does not seem to contain a matrix.")
# Fix the ring
if base_ring is not None:
if A.base_ring() != base_ring:
A = A.change_ring(base_ring)
elif A.base_ring() == ZZ and not want_regular: # Usually a rational matrix is intended, we presume.
A = A.change_ring(QQ)
base_ring = QQ
else:
base_ring = A.base_ring()
# Determine groundset:
if 'matrix' in kwds:
if 'groundset' in kwds:
if len(kwds['groundset']) == A.nrows() + A.ncols():
kwds['reduced_matrix'] = A
kwds.pop('matrix')
else:
if len(kwds['groundset']) != A.ncols():
raise ValueError("groundset size does not correspond to matrix size.")
else:
kwds['groundset'] = range(A.ncols())
if 'reduced_matrix' in kwds:
if 'groundset' in kwds:
if len(kwds['groundset']) != A.nrows() + A.ncols():
raise ValueError("groundset size does not correspond to matrix size.")
else:
kwds['groundset'] = range(A.nrows() + A.ncols())
if 'matrix' in kwds:
if base_ring == GF(2):
M = BinaryMatroid(groundset=kwds['groundset'], matrix=A)
elif base_ring == GF(3):
M = TernaryMatroid(groundset=kwds['groundset'], matrix=A)
elif base_ring.is_field() and base_ring.order() == 4: # GF(4) can have different generators.
M = QuaternaryMatroid(groundset=kwds['groundset'], matrix=A)
else:
M = LinearMatroid(groundset=kwds['groundset'], matrix=A, ring=base_ring)