本文整理匯總了Python中sage.groups.perm_gps.permgroup_named.SymmetricGroup類的典型用法代碼示例。如果您正苦於以下問題:Python SymmetricGroup類的具體用法?Python SymmetricGroup怎麽用?Python SymmetricGroup使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SymmetricGroup類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: reflection_group
def reflection_group(self, type="matrix"):
"""
Return the reflection group corresponding to ``self``.
EXAMPLES::
sage: C = CartanMatrix(['A',3])
sage: C.reflection_group()
Weyl Group of type ['A', 3] (as a matrix group acting on the root space)
"""
from sage.groups.perm_gps.permgroup_named import SymmetricGroup
RS = self.root_space()
G = RS.weyl_group()
if type == "matrix":
return G
elif type == "permutation":
assert G.is_finite()
Phi = RS.roots()
gens = {}
S = SymmetricGroup(len(Phi))
for i in self.index_set():
pi = S([ Phi.index( beta.simple_reflection(i) ) + 1 for beta in Phi ])
gens[i] = pi
return S.subgroup( gens[i] for i in gens )
else:
raise ValueError("The reflection group is only available as a matrix group or as a permutation group.")
示例2: SymmetricPresentation
def SymmetricPresentation(n):
r"""
Build the Symmetric group of order `n!` as a finitely presented group.
INPUT:
- ``n`` -- The size of the underlying set of arbitrary symbols being acted
on by the Symmetric group of order `n!`.
OUTPUT:
Symmetric group as a finite presentation, implementation uses GAP to find an
isomorphism from a permutation representation to a finitely presented group
representation. Due to this fact, the exact output presentation may not be
the same for every method call on a constant ``n``.
EXAMPLES::
sage: S4 = groups.presentation.Symmetric(4)
sage: S4.as_permutation_group().is_isomorphic(SymmetricGroup(4))
True
TESTS::
sage: S = [groups.presentation.Symmetric(i) for i in range(1,4)]; S[0].order()
1
sage: S[1].order(), S[2].as_permutation_group().is_isomorphic(DihedralGroup(3))
(2, True)
sage: S5 = groups.presentation.Symmetric(5)
sage: perm_S5 = S5.as_permutation_group(); perm_S5.is_isomorphic(SymmetricGroup(5))
True
sage: groups.presentation.Symmetric(8).order()
40320
"""
from sage.groups.perm_gps.permgroup_named import SymmetricGroup
from sage.groups.free_group import _lexi_gen
n = Integer(n)
perm_rep = SymmetricGroup(n)
GAP_fp_rep = libgap.Image(libgap.IsomorphismFpGroupByGenerators(perm_rep, perm_rep.gens()))
image_gens = GAP_fp_rep.FreeGeneratorsOfFpGroup()
name_itr = _lexi_gen() # Python generator object for variable names
F = FreeGroup([next(name_itr) for x in perm_rep.gens()])
ret_rls = tuple(
[F(rel_word.TietzeWordAbstractWord(image_gens).sage()) for rel_word in GAP_fp_rep.RelatorsOfFpGroup()]
)
return FinitelyPresentedGroup(F, ret_rls)
示例3: _get_random_ribbon_graph
def _get_random_ribbon_graph(self):
r"""
Return a random ribbon graph with right parameters.
"""
n = random.randint(self.min_num_seps,self.max_num_seps)
S = SymmetricGroup(2*n)
e = S([(2*i+1,2*i+2) for i in xrange(n)])
f = S.random_element()
P = PermutationGroup([e,f])
while not P.is_transitive():
f = S.random_element()
P = PermutationGroup([e,f])
return RibbonGraph(
edges=[e(i+1)-1 for i in xrange(2*n)],
faces=[f(i+1)-1 for i in xrange(2*n)])
示例4: to_character
def to_character(self):
r"""
Return the character of the representation.
EXAMPLES:
The trivial character::
sage: rho = SymmetricGroupRepresentation([3])
sage: chi = rho.to_character(); chi
Character of Symmetric group of order 3! as a permutation group
sage: chi.values()
[1, 1, 1]
sage: all(chi(g) == 1 for g in SymmetricGroup(3))
True
The sign character::
sage: rho = SymmetricGroupRepresentation([1,1,1])
sage: chi = rho.to_character(); chi
Character of Symmetric group of order 3! as a permutation group
sage: chi.values()
[1, -1, 1]
sage: all(chi(g) == g.sign() for g in SymmetricGroup(3))
True
The defining representation::
sage: triv = SymmetricGroupRepresentation([4])
sage: hook = SymmetricGroupRepresentation([3,1])
sage: def_rep = lambda p : triv(p).block_sum(hook(p)).trace()
sage: map(def_rep, Permutations(4))
[4, 2, 2, 1, 1, 2, 2, 0, 1, 0, 0, 1, 1, 0, 2, 1, 0, 0, 0, 1, 1, 2, 0, 0]
sage: [p.to_matrix().trace() for p in Permutations(4)]
[4, 2, 2, 1, 1, 2, 2, 0, 1, 0, 0, 1, 1, 0, 2, 1, 0, 0, 0, 1, 1, 2, 0, 0]
"""
from sage.groups.perm_gps.permgroup_named import SymmetricGroup
Sym = SymmetricGroup(sum(self._partition))
values = [self(g).trace() for g in Sym.conjugacy_classes_representatives()]
return Sym.character(values)
示例5: _get_random_cylinder_diagram
def _get_random_cylinder_diagram(self):
r"""
Return a random cylinder diagram with right parameters
"""
test = False
while test:
n = random.randint(self.min_num_seps,self.max_num_seps)
S = SymmetricGroup(2*n)
bot = S.random_element()
b = [[i-1 for i in c] for c in bot.cycle_tuples(singletons=True)]
p = Partitions(2*n,length=len(b)).random_element()
top = S([i+1 for i in canonical_perm(p)])
t = [[i-1 for i in c] for c in top.cycle_tuples(singletons=True)]
prandom.shuffle(t)
c = CylinderDiagram(zip(b,t))
test = c.is_connected()
return c
示例6: CyclicCodeFromGeneratingPolynomial
def CyclicCodeFromGeneratingPolynomial(n,g,ignore=True):
r"""
If g is a polynomial over GF(q) which divides `x^n-1` then
this constructs the code "generated by g" (ie, the code associated
with the principle ideal `gR` in the ring
`R = GF(q)[x]/(x^n-1)` in the usual way).
The option "ignore" says to ignore the condition that (a) the
characteristic of the base field does not divide the length (the
usual assumption in the theory of cyclic codes), and (b) `g`
must divide `x^n-1`. If ignore=True, instead of returning
an error, a code generated by `gcd(x^n-1,g)` is created.
EXAMPLES::
sage: P.<x> = PolynomialRing(GF(3),"x")
sage: g = x-1
sage: C = codes.CyclicCodeFromGeneratingPolynomial(4,g); C
Linear code of length 4, dimension 3 over Finite Field of size 3
sage: P.<x> = PolynomialRing(GF(4,"a"),"x")
sage: g = x^3+1
sage: C = codes.CyclicCodeFromGeneratingPolynomial(9,g); C
Linear code of length 9, dimension 6 over Finite Field in a of size 2^2
sage: P.<x> = PolynomialRing(GF(2),"x")
sage: g = x^3+x+1
sage: C = codes.CyclicCodeFromGeneratingPolynomial(7,g); C
Linear code of length 7, dimension 4 over Finite Field of size 2
sage: C.generator_matrix()
[1 1 0 1 0 0 0]
[0 1 1 0 1 0 0]
[0 0 1 1 0 1 0]
[0 0 0 1 1 0 1]
sage: g = x+1
sage: C = codes.CyclicCodeFromGeneratingPolynomial(4,g); C
Linear code of length 4, dimension 3 over Finite Field of size 2
sage: C.generator_matrix()
[1 1 0 0]
[0 1 1 0]
[0 0 1 1]
On the other hand, CyclicCodeFromPolynomial(4,x) will produce a
ValueError including a traceback error message: "`x` must
divide `x^4 - 1`". You will also get a ValueError if you
type
::
sage: P.<x> = PolynomialRing(GF(4,"a"),"x")
sage: g = x^2+1
followed by CyclicCodeFromGeneratingPolynomial(6,g). You will also
get a ValueError if you type
::
sage: P.<x> = PolynomialRing(GF(3),"x")
sage: g = x^2-1
sage: C = codes.CyclicCodeFromGeneratingPolynomial(5,g); C
Linear code of length 5, dimension 4 over Finite Field of size 3
followed by C = CyclicCodeFromGeneratingPolynomial(5,g,False), with
a traceback message including "`x^2 + 2` must divide
`x^5 - 1`".
"""
P = g.parent()
x = P.gen()
F = g.base_ring()
p = F.characteristic()
if not(ignore) and p.divides(n):
raise ValueError('The characteristic %s must not divide %s'%(p,n))
if not(ignore) and not(g.divides(x**n-1)):
raise ValueError('%s must divide x^%s - 1'%(g,n))
gn = GCD([g,x**n-1])
d = gn.degree()
coeffs = Sequence(gn.list())
r1 = Sequence(coeffs+[0]*(n - d - 1))
Sn = SymmetricGroup(n)
s = Sn.gens()[0] # assumes 1st gen of S_n is (1,2,...,n)
rows = [permutation_action(s**(-i),r1) for i in range(n-d)]
MS = MatrixSpace(F,n-d,n)
return LinearCode(MS(rows))
示例7: reorder
def reorder(self, order):
"""
Return a new isogeny class with the curves reordered.
INPUT:
- ``order`` -- None, a string or an iterable over all curves
in this class. See
:meth:`sage.schemes.elliptic_curves.ell_rational_field.EllipticCurve_rational_field.isogeny_class`
for more details.
OUTPUT:
- Another :class:`IsogenyClass_EC` with the curves reordered
(and matrices and maps changed as appropriate)
EXAMPLES::
sage: isocls = EllipticCurve('15a1').isogeny_class(use_tuple=False)
sage: print "\n".join([repr(C) for C in isocls.curves])
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 10*x - 10 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 5*x + 2 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 + 35*x - 28 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 135*x - 660 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 80*x + 242 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 110*x - 880 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 2160*x - 39540 over Rational Field
sage: isocls2 = isocls.reorder('lmfdb')
sage: print "\n".join([repr(C) for C in isocls2.curves])
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 2160*x - 39540 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 135*x - 660 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 110*x - 880 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 80*x + 242 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 10*x - 10 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 - 5*x + 2 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 over Rational Field
Elliptic Curve defined by y^2 + x*y + y = x^3 + x^2 + 35*x - 28 over Rational Field
"""
if order is None or isinstance(order, basestring) and order == self._algorithm:
return self
if isinstance(order, basestring):
if order == "lmfdb":
reordered_curves = sorted(self.curves, key = lambda E: E.a_invariants())
else:
reordered_curves = list(self.E.isogeny_class(algorithm=order, use_tuple=False))
elif isinstance(order, (list, tuple, IsogenyClass_EC)):
reordered_curves = list(order)
if len(reordered_curves) != len(self.curves):
raise ValueError("Incorrect length")
else:
raise TypeError("order parameter should be a string, list of curves or isogeny class")
need_perm = self._mat is not None
cpy = self.copy()
curves = []
perm = []
for E in reordered_curves:
try:
j = self.curves.index(E)
except ValueError:
try:
j = self.curves.index(E.minimal_model())
except ValueError:
raise ValueError("order does not yield a permutation of curves")
curves.append(self.curves[j])
if need_perm: perm.append(j+1)
cpy.curves = tuple(curves)
if need_perm:
from sage.groups.perm_gps.permgroup_named import SymmetricGroup
perm = SymmetricGroup(len(self.curves))(perm)
cpy._mat = perm.matrix() * self._mat * (~perm).matrix()
if self._maps is not None:
n = len(self._maps)
cpy._maps = [self._maps[perm(i+1)-1] for i in range(n)]
for i in range(n):
cpy._maps[i] = [cpy._maps[i][perm(j+1)-1] for j in range(n)]
else:
cpy._mat = None
cpy._maps = None
return cpy