本文整理汇总了Python中sage.matrix.constructor.Matrix.set_immutable方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.set_immutable方法的具体用法?Python Matrix.set_immutable怎么用?Python Matrix.set_immutable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.matrix.constructor.Matrix
的用法示例。
在下文中一共展示了Matrix.set_immutable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: linear_approximation_matrix
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import set_immutable [as 别名]
def linear_approximation_matrix(self):
"""
Return linear approximation matrix ``A`` for this S-box.
Let ``i_b`` be the ``b``-th bit of ``i`` and ``o_b`` the
``b``-th bit of ``o``. Then ``v = A[i,o]`` encodes the bias of
the equation ``sum( i_b * x_i ) = sum( o_b * y_i )`` if
``x_i`` and ``y_i`` represent the input and output variables
of the S-box.
See [He2002]_ for an introduction to linear cryptanalysis.
EXAMPLES::
sage: from sage.crypto.sbox import SBox
sage: S = SBox(7,6,0,4,2,5,1,3)
sage: S.linear_approximation_matrix()
[ 4 0 0 0 0 0 0 0]
[ 0 0 0 0 2 2 2 -2]
[ 0 0 -2 -2 -2 2 0 0]
[ 0 0 -2 2 0 0 -2 -2]
[ 0 2 0 2 -2 0 2 0]
[ 0 -2 0 2 0 2 0 2]
[ 0 -2 -2 0 0 -2 2 0]
[ 0 -2 2 0 -2 0 0 -2]
According to this matrix the first bit of the input is equal
to the third bit of the output 6 out of 8 times::
sage: for i in srange(8): print(S.to_bits(i)[0] == S.to_bits(S(i))[2])
False
True
True
True
False
True
True
True
"""
m = self.m
n = self.n
nrows = 1<<m
ncols = 1<<n
B = BooleanFunction(self.m)
L = []
for j in range(ncols):
for i in range(nrows):
B[i] = ZZ(self(i)&j).popcount()
L.append(B.walsh_hadamard_transform())
A = Matrix(ZZ, ncols, nrows, L)
A = -A.transpose()/2
A.set_immutable()
return A
示例2: HarmonicCocycles
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import set_immutable [as 别名]
class HarmonicCocycles(AmbientHeckeModule):
Element=HarmonicCocycleElement
r"""
This object represents a space of Gamma invariant harmonic cocycles valued in
a cofficient module.
INPUT:
- ``X`` - A BTQuotient object
- ``k`` - integer - The weight.
- ``prec`` - integer (Default: None). If specified, the precision for the coefficient module
- ``basis_matrix`` - integer (Default: None)
- ``base_field`` - (Default: None)
EXAMPLES:
::
AUTHORS:
- Cameron Franc (2012-02-20)
- Marc Masdeu
"""
def __init__(self,X,k,prec=None,basis_matrix=None,base_field=None):
self._k=k
self._X=X
self._E=self._X.get_edge_list()
self._V=self._X.get_vertex_list()
if prec is None:
self._prec=None
if base_field is None:
try:
self._R= X.get_splitting_field()
except AttributeError:
raise ValueError, "It looks like you are not using Magma as backend...and still we don't know how to compute splittings in that case!"
else:
pol=X.get_splitting_field().defining_polynomial().factor()[0][0]
self._R=base_field.extension(pol,pol.variable_name()).absolute_field(name='r')
self._U=OCVn(self._k-2,self._R)
else:
self._prec=prec
if base_field is None:
self._R=Qp(self._X._p,prec=prec)
else:
self._R=base_field
self._U=OCVn(self._k-2,self._R,self._k-1)
self.__rank = self._X.dimension_harmonic_cocycles(self._k)
if basis_matrix is not None:
self.__matrix=basis_matrix
self.__matrix.set_immutable()
assert self.__rank == self.__matrix.nrows()
AmbientHeckeModule.__init__(self, self._R, self.__rank, self._X.prime()*self._X.Nplus()*self._X.Nminus(), weight=self._k)
self._populate_coercion_lists_()
def base_extend(self,base_ring):
r"""
This function extends the base ring of the coefficient module.
INPUT:
- ``base_ring`` - a ring that has a coerce map from the current base ring
EXAMPLES:
::
"""
if not base_ring.has_coerce_map_from(self.base_ring()):
raise ValueError, "No coercion defined"
else:
return self.change_ring(base_ring)
def change_ring(self, new_base_ring):
r"""
This function changes the base ring of the coefficient module.
INPUT:
- ``new_base_ring'' - a ring that has a coerce map from the current base ring
EXAMPLES:
::
"""
if not new_base_ring.has_coerce_map_from(self.base_ring()):
raise ValueError, "No coercion defined"
else:
return self.__class__(self._X,self._k,prec=self._prec,basis_matrix=self.basis_matrix().change_ring(base_ring),base_field=new_base_ring)
def rank(self):
r"""
The rank (dimension) of ``self``.
EXAMPLES:
::
"""
return self.__rank
#.........这里部分代码省略.........
示例3: cartan_invariants_matrix
# 需要导入模块: from sage.matrix.constructor import Matrix [as 别名]
# 或者: from sage.matrix.constructor.Matrix import set_immutable [as 别名]
#.........这里部分代码省略.........
- `C_{i,j}` counts how many times `S_j` appears as
composition factor of `P^R_i`;
- `C_{i,j}=\dim Hom_A(P^L_i, P^L_j)`;
- `C_{i,j}` counts how many times `S_i^*` appears as
composition factor of `P^L_j`.
In the commutative case, the Cartan invariant matrix is
diagonal. In the context of solving systems of
multivariate polynomial equations of dimension zero, `A`
is the quotient of the polynomial ring by the ideal
generated by the equations, the simple modules correspond
to the roots, and the numbers `C_{i,i}` give the
multiplicities of those roots.
.. NOTE::
For simplicity, the current implementation assumes
that the index set `I` is of the form
`\{0,\dots,n-1\}`. Better indexations will be possible
in the future.
ALGORITHM:
The Cartan invariant matrix of `A` is computed from the
dimension of the summands of its peirce decomposition.
.. SEEALSO::
- :meth:`peirce_decomposition`
- :meth:`isotypic_projective_modules`
EXAMPLES:
For a semisimple algebra, in particular for group algebras
in chararacteristic zero, the Cartan invariants matrix is
the identity::
sage: A3 = SymmetricGroup(3).algebra(QQ)
sage: A3.cartan_invariants_matrix()
[1 0 0]
[0 1 0]
[0 0 1]
For the path algebra of a quiver, the Cartan invariants
matrix counts the number of paths between two vertices::
sage: A = Algebras(QQ).FiniteDimensional().WithBasis().example()
sage: A.cartan_invariants_matrix()
[1 2]
[0 1]
In the commutative case, the Cartan invariant matrix is diagonal::
sage: Z12 = Monoids().Finite().example(); Z12
An example of a finite multiplicative monoid: the integers modulo 12
sage: A = Z12.algebra(QQ)
sage: A.cartan_invariants_matrix()
[1 0 0 0 0 0 0 0 0]
[0 1 0 0 0 0 0 0 0]
[0 0 2 0 0 0 0 0 0]
[0 0 0 1 0 0 0 0 0]
[0 0 0 0 2 0 0 0 0]
[0 0 0 0 0 1 0 0 0]
[0 0 0 0 0 0 1 0 0]
[0 0 0 0 0 0 0 2 0]
[0 0 0 0 0 0 0 0 1]
With the algebra of the `0`-Hecke monoid::
sage: from sage.monoids.hecke_monoid import HeckeMonoid
sage: A = HeckeMonoid(SymmetricGroup(4)).algebra(QQ)
sage: A.cartan_invariants_matrix()
[1 0 0 0 0 0 0 0]
[0 2 1 0 1 1 0 0]
[0 1 1 0 1 0 0 0]
[0 0 0 1 0 1 1 0]
[0 1 1 0 1 0 0 0]
[0 1 0 1 0 2 1 0]
[0 0 0 1 0 1 1 0]
[0 0 0 0 0 0 0 1]
"""
from sage.rings.integer_ring import ZZ
A_quo = self.semisimple_quotient()
idempotents_quo = A_quo.central_orthogonal_idempotents()
# Dimension of simple modules
dim_simples = [sqrt(A_quo.principal_ideal(e).dimension()) for e in idempotents_quo]
# Orthogonal idempotents
idempotents = self.orthogonal_idempotents_central_mod_radical()
def C(i, j):
summand = self.peirce_summand(idempotents[i], idempotents[j])
return summand.dimension() / (dim_simples[i] * dim_simples[j])
m = Matrix(ZZ, len(idempotents), C)
m.set_immutable()
return m