本文整理汇总了Python中sage.matrix.constructor.Matrix.swap_rows方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.swap_rows方法的具体用法?Python Matrix.swap_rows怎么用?Python Matrix.swap_rows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.matrix.constructor.Matrix
的用法示例。
在下文中一共展示了Matrix.swap_rows方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _normalize_2x2
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import swap_rows [as 别名]
def _normalize_2x2(G):
r"""
Normalize this indecomposable `2` by `2` block.
INPUT:
``G`` - a `2` by `2` matrix over `\ZZ_p`
with ``type = 'fixed-mod'`` of the form::
[2a b]
[ b 2c] * 2^n
with `b` of valuation 1.
OUTPUT:
A unimodular `2` by `2` matrix ``B`` over `\ZZ_p` with
``B * G * B.transpose()``
either::
[0 1] [2 1]
[1 0] * 2^n or [1 2] * 2^n
EXAMPLES::
sage: from sage.quadratic_forms.genera.normal_form import _normalize_2x2
sage: R = Zp(2, prec = 15, type = 'fixed-mod', print_mode='series', show_prec=False)
sage: G = Matrix(R, 2, [-17*2,3,3,23*2])
sage: B =_normalize_2x2(G)
sage: B * G * B.T
[2 1]
[1 2]
sage: G = Matrix(R,2,[-17*4,3,3,23*2])
sage: B = _normalize_2x2(G)
sage: B*G*B.T
[0 1]
[1 0]
sage: G = 2^3 * Matrix(R, 2, [-17*2,3,3,23*2])
sage: B = _normalize_2x2(G)
sage: B * G * B.T
[2^4 2^3]
[2^3 2^4]
"""
from sage.rings.all import PolynomialRing
from sage.modules.free_module_element import vector
B = copy(G.parent().identity_matrix())
R = G.base_ring()
P = PolynomialRing(R, 'x')
x = P.gen()
# The input must be an even block
odd1 = (G[0, 0].valuation() < G[1, 0].valuation())
odd2 = (G[1, 1].valuation() < G[1, 0].valuation())
if odd1 or odd2:
raise ValueError("Not a valid 2 x 2 block.")
scale = 2 ** G[0,1].valuation()
D = Matrix(R, 2, 2, [d // scale for d in G.list()])
# now D is of the form
# [2a b ]
# [b 2c]
# where b has valuation 1.
G = copy(D)
# Make sure G[1, 1] has valuation 1.
if D[1, 1].valuation() > D[0, 0].valuation():
B.swap_columns(0, 1)
D.swap_columns(0, 1)
D.swap_rows(0, 1)
if D[1, 1].valuation() != 1:
# this works because
# D[0, 0] has valuation at least 2
B[1, :] += B[0, :]
D = B * G * B.transpose()
assert D[1, 1].valuation() == 1
if mod(D.det(), 8) == 3:
# in this case we can transform D to
# 2 1
# 1 2
# Find a point of norm 2
# solve: 2 == D[1,1]*x^2 + 2*D[1,0]*x + D[0,0]
pol = (D[1,1]*x**2 + 2*D[1,0]*x + D[0,0]-2) // 2
# somehow else pari can get a hickup see `trac`:#24065
pol = pol // pol.leading_coefficient()
sol = pol.roots()[0][0]
B[0, 1] = sol
D = B * G * B.transpose()
# make D[0, 1] = 1
B[1, :] *= D[1, 0].inverse_of_unit()
D = B * G * B.transpose()
# solve: v*D*v == 2 with v = (x, -2*x+1)
if D[1, 1] != 2:
v = vector([x, -2*x + 1])
pol = (v*D*v - 2) // 2
# somehow else pari can get a hickup `trac`:#24065
pol = pol // pol.leading_coefficient()
sol = pol.roots()[0][0]
#.........这里部分代码省略.........