本文整理汇总了Python中sage.rings.all.ZZ.one方法的典型用法代码示例。如果您正苦于以下问题:Python ZZ.one方法的具体用法?Python ZZ.one怎么用?Python ZZ.one使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.rings.all.ZZ
的用法示例。
在下文中一共展示了ZZ.one方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mult_order
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def mult_order(x):
ct = ZZ.one()
cur = x
while cur != one:
cur *= x
ct += ZZ.one()
return ZZ(ct)
示例2: __iter__
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def __iter__(self):
"""
Iterate over ``self``.
EXAMPLES::
sage: S = SignedPermutations(2)
sage: [x for x in S]
[[1, 2], [1, -2], [-1, 2], [-1, -2],
[2, 1], [2, -1], [-2, 1], [-2, -1]]
"""
pmone = [ZZ.one(), -ZZ.one()]
for p in self._P:
for c in itertools.product(pmone, repeat=self._n):
yield self.element_class(self, c, p)
示例3: phi
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def phi(self, i):
r"""
Return `\varphi_i` of ``self``.
EXAMPLES::
sage: S = crystals.OddNegativeRoots(['A', [2,2]])
sage: mg = S.module_generator()
sage: [mg.phi(i) for i in S.index_set()]
[0, 0, 1, 0, 0]
sage: b = mg.f(0)
sage: [b.phi(i) for i in S.index_set()]
[0, 1, 0, 1, 0]
sage: b = mg.f_string([0,1,0,-1,0,-1]); b
{-e[-2]+e[1], -e[-2]+e[2], -e[-1]+e[1]}
sage: [b.phi(i) for i in S.index_set()]
[2, 0, 0, 1, 1]
TESTS::
sage: S = crystals.OddNegativeRoots(['A', [2,1]])
sage: def count_f(x, i):
....: ret = -1
....: while x is not None:
....: x = x.f(i)
....: ret += 1
....: return ret
sage: for x in S:
....: for i in S.index_set():
....: assert x.phi(i) == count_f(x, i)
"""
if i == 0:
return ZZ.zero() if (-1,1) in self.value else ZZ.one()
count = 0
ret = 0
if i < 0:
lst = sorted(self.value, key=lambda x: (x[1], -x[0]))
for val in reversed(lst):
# We don't have to check val[1] because this is an odd root
if val[0] == i:
if count == 0:
ret += 1
else:
count -= 1
elif val[0] == i - 1:
count += 1
else: # i > 0
lst = sorted(self.value, key=lambda x: (-x[0], -x[1]))
for val in lst:
# We don't have to check val[0] because this is an odd root
if val[1] == i:
if count == 0:
ret += 1
else:
count -= 1
elif val[1] == i + 1:
count += 1
return ret
示例4: long_element
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def long_element(self, index_set=None):
"""
Return the longest element of ``self``, or of the
parabolic subgroup corresponding to the given ``index_set``.
INPUT:
- ``index_set`` -- (optional) a subset (as a list or iterable)
of the nodes of the indexing set
EXAMPLES::
sage: S = SignedPermutations(4)
sage: S.long_element()
[-1, -2, -3, -4]
TESTS:
Check that this is the element of maximal length (:trac:`25200`)::
sage: S = SignedPermutations(4)
sage: S.long_element().length() == max(x.length() for x in S)
True
sage: all(SignedPermutations(n).long_element().length() == n^2
....: for n in range(2,10))
True
"""
if index_set is not None:
return super(SignedPermutations, self).long_element()
return self.element_class(self, [-ZZ.one()] * self._n, self._P.one())
示例5: iterator_fast
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def iterator_fast(n, l):
"""
Iterate over all ``l`` weighted integer vectors with total weight ``n``.
INPUT:
- ``n`` -- an integer
- ``l`` -- the weights in weakly decreasing order
EXAMPLES::
sage: from sage.combinat.integer_vector_weighted import iterator_fast
sage: list(iterator_fast(3, [2,1,1]))
[[1, 1, 0], [1, 0, 1], [0, 3, 0], [0, 2, 1], [0, 1, 2], [0, 0, 3]]
sage: list(iterator_fast(2, [2]))
[[1]]
Test that :trac:`20491` is fixed::
sage: type(list(iterator_fast(2, [2]))[0][0])
<type 'sage.rings.integer.Integer'>
"""
if n < 0:
return
zero = ZZ.zero()
one = ZZ.one()
if not l:
if n == 0:
yield []
return
if len(l) == 1:
if n % l[0] == 0:
yield [n // l[0]]
return
k = 0
cur = [n // l[k] + one]
rem = n - cur[-1] * l[k] # Amount remaining
while cur:
cur[-1] -= one
rem += l[k]
if rem == zero:
yield cur + [zero] * (len(l) - len(cur))
elif cur[-1] < zero or rem < zero:
rem += cur.pop() * l[k]
k -= 1
elif len(l) == len(cur) + 1:
if rem % l[-1] == zero:
yield cur + [rem // l[-1]]
else:
k += 1
cur.append(rem // l[k] + one)
rem -= cur[-1] * l[k]
示例6: one
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def one(self):
"""
Return the identity element of ``self``.
EXAMPLES::
sage: S = SignedPermutations(4)
sage: S.one()
[1, 2, 3, 4]
"""
return self.element_class(self, [ZZ.one()] * self._n, self._P.identity())
示例7: simple_reflection
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def simple_reflection(self, i):
r"""
Return the ``i``-th simple reflection of ``self``.
EXAMPLES::
sage: S = SignedPermutations(4)
sage: S.simple_reflection(1)
[2, 1, 3, 4]
sage: S.simple_reflection(4)
[1, 2, 3, -4]
"""
if i not in self.index_set():
raise ValueError("i must be in the index set")
if i < self._n:
p = list(range(1, self._n + 1))
p[i - 1] = i + 1
p[i] = i
return self.element_class(self, [ZZ.one()] * self._n, self._P(p))
temp = [ZZ.one()] * self._n
temp[-1] = -ZZ.one()
return self.element_class(self, temp, self._P.identity())
示例8: cardinality
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def cardinality(self):
r"""
Return the cardinality of ``self``, which is `\infty`.
EXAMPLES::
sage: F = FreeMonoid(2005, 'a')
sage: F.cardinality()
+Infinity
"""
if self.__ngens == 0:
from sage.rings.all import ZZ
return ZZ.one()
from sage.rings.infinity import infinity
return infinity
示例9: F
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def F(self):
"""
Return the degree of the residue field extension of this valuation
over the Gauss valuation, i.e., 1.
EXAMPLES::
sage: R.<u> = Qq(4,5)
sage: S.<x> = R[]
sage: v = GaussValuation(S)
sage: v.F()
1
"""
from sage.rings.all import ZZ
return ZZ.one()
示例10: E
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def E(self):
"""
Return the ramification index of this valuation over its underlying
Gauss valuation, i.e., 1.
EXAMPLES::
sage: R.<u> = Qq(4,5)
sage: S.<x> = R[]
sage: v = GaussValuation(S)
sage: v.E()
1
"""
from sage.rings.all import ZZ
return ZZ.one()
示例11: ConstantFormsSpaceFunctor
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def ConstantFormsSpaceFunctor(group):
r"""
Construction functor for the space of constant forms.
When determining a common parent between a ring
and a forms ring or space this functor is first
applied to the ring.
EXAMPLES::
sage: from sage.modular.modform_hecketriangle.functors import (ConstantFormsSpaceFunctor, FormsSpaceFunctor)
sage: ConstantFormsSpaceFunctor(4) == FormsSpaceFunctor("holo", 4, 0, 1)
True
sage: ConstantFormsSpaceFunctor(4)
ModularFormsFunctor(n=4, k=0, ep=1)
"""
return FormsSpaceFunctor("holo", group, QQ.zero(), ZZ.one())
示例12: _element_constructor_
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def _element_constructor_(self, x):
"""
Construct an element of ``self`` from ``x``.
TESTS::
sage: S = SignedPermutations(3)
sage: x = S([(+1,1), (-1,3), (-1,2)]); x
[1, -3, -2]
sage: x == S([[+1,-1,-1], [1,3,2]])
True
sage: x == S([1, -3, -2])
True
"""
if isinstance(x, list):
if isinstance(x[0], tuple):
c = []
p = []
for k in x:
if len(k) != 2:
raise ValueError("input must be pairs (sign, element)")
if k[0] != 1 and k[0] != -1:
raise ValueError("the sign must be +1 or -1")
c.append(ZZ(k[0]))
p.append(k[1])
return self.element_class(self, c, self._P(p))
if len(x) == self._n:
c = []
p = []
one = ZZ.one()
for v in x:
if v > 0:
c.append(one)
p.append(v)
else:
c.append(-one)
p.append(-v)
return self.element_class(self, c, self._P(p))
if len(x) != 2:
raise ValueError("input must be a pair of a list of signs and a permutation")
if any(s != 1 and s != -1 for s in x[0]):
raise ValueError("the sign must be +1 or -1")
return self.element_class(self, [ZZ(v) for v in x[0]], self._P(x[1]))
示例13: Birkhoff_polytope
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def Birkhoff_polytope(self, n):
"""
Return the Birkhoff polytope with `n!` vertices.
The vertices of this polyhedron are the (flattened) `n` by `n`
permutation matrices. So the ambient vector space has dimension `n^2`
but the dimension of the polyhedron is `(n-1)^2`.
INPUT:
- ``n`` -- a positive integer giving the size of the permutation matrices.
.. SEEALSO::
:meth:`sage.matrix.matrix2.Matrix.as_sum_of_permutations` -- return
the current matrix as a sum of permutation matrices
EXAMPLES::
sage: b3 = polytopes.Birkhoff_polytope(3)
sage: b3.f_vector()
(1, 6, 15, 18, 9, 1)
sage: print b3.ambient_dim(), b3.dim()
9 4
sage: b3.is_lattice_polytope()
True
sage: p3 = b3.ehrhart_polynomial() # optional - latte_int
sage: p3 # optional - latte_int
1/8*t^4 + 3/4*t^3 + 15/8*t^2 + 9/4*t + 1
sage: [p3(i) for i in [1,2,3,4]] # optional - latte_int
[6, 21, 55, 120]
sage: [len((i*b3).integral_points()) for i in [1,2,3,4]]
[6, 21, 55, 120]
sage: b4 = polytopes.Birkhoff_polytope(4)
sage: print b4.n_vertices(), b4.ambient_dim(), b4.dim()
24 16 9
"""
from itertools import permutations
verts = []
for p in permutations(range(n)):
verts.append( [ZZ.one() if p[i]==j else ZZ.zero() for j in range(n) for i in range(n) ] )
return Polyhedron(vertices=verts, base_ring=ZZ)
示例14: cardinality
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def cardinality(self):
"""
Return the cardinality of ``self``.
EXAMPLES::
sage: IntegerVectors(3, 3, min_part=1).cardinality()
1
sage: IntegerVectors(5, 3, min_part=1).cardinality()
6
sage: IntegerVectors(13, 4, max_part=4).cardinality()
20
sage: IntegerVectors(k=4, max_part=3).cardinality()
256
sage: IntegerVectors(k=3, min_part=2, max_part=4).cardinality()
27
sage: IntegerVectors(13, 4, min_part=2, max_part=4).cardinality()
16
"""
if self.k is None:
if self.n is None:
return PlusInfinity()
if ('max_length' not in self.constraints
and self.constraints.get('min_part', 0) <= 0):
return PlusInfinity()
elif ('max_part' in self.constraints
and self.constraints['max_part'] != PlusInfinity()):
if (self.n is None and len(self.constraints) == 2
and 'min_part' in self.constraints
and self.constraints['min_part'] >= 0):
num = self.constraints['max_part'] - self.constraints['min_part'] + 1
return Integer(num ** self.k)
if len(self.constraints) == 1:
m = self.constraints['max_part']
if self.n is None:
return Integer((m + 1) ** self.k)
if m >= self.n:
return Integer(binomial(self.n + self.k - 1, self.n))
# do by inclusion / exclusion on the number
# i of parts greater than m
return Integer(sum( (-1)**i * binomial(self.n+self.k-1-i*(m+1), self.k-1) \
* binomial(self.k,i) for i in range(self.n/(m+1)+1) ))
return ZZ.sum(ZZ.one() for x in self)
示例15: long_element
# 需要导入模块: from sage.rings.all import ZZ [as 别名]
# 或者: from sage.rings.all.ZZ import one [as 别名]
def long_element(self, index_set=None):
"""
Return the longest element of ``self``, or of the
parabolic subgroup corresponding to the given ``index_set``.
INPUT:
- ``index_set`` -- (optional) a subset (as a list or iterable)
of the nodes of the indexing set
EXAMPLES::
sage: S = SignedPermutations(4)
sage: S.long_element()
[-4, -3, -2, -1]
"""
if index_set is not None:
return super(SignedPermutations, self).long_element()
p = range(self._n, 0, -1)
return self.element_class(self, [-ZZ.one()] * self._n, self._P(p))