本文整理汇总了Python中sympy.mpmath.libmp.libintmath.ifac函数的典型用法代码示例。如果您正苦于以下问题:Python ifac函数的具体用法?Python ifac怎么用?Python ifac使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ifac函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: rs_hadamard_exp
def rs_hadamard_exp(p1, inverse=False):
"""
return ``sum f_i/i!*x**i`` from ``sum f_i*x**i``,
where ``x`` is the first variable.
If ``invers=True`` return ``sum f_i*i!*x**i``
Examples
========
>>> from sympy.polys.domains import QQ
>>> from sympy.polys.rings import ring
>>> from sympy.polys.ring_series import rs_hadamard_exp
>>> R, x = ring('x', QQ)
>>> p = 1 + x + x**2 + x**3
>>> rs_hadamard_exp(p)
1/6*x**3 + 1/2*x**2 + x + 1
"""
R = p1.ring
if R.domain != QQ:
raise NotImplementedError
p = R.zero
if not inverse:
for exp1, v1 in p1.items():
p[exp1] = v1/int(ifac(exp1[0]))
else:
for exp1, v1 in p1.items():
p[exp1] = v1*int(ifac(exp1[0]))
return p
开发者ID:EnigmaKid,项目名称:sympy,代码行数:29,代码来源:ring_series.py
示例2: rank
def rank(self):
"""
Returns the lexicographic rank of the permutation.
Examples
========
>>> from sympy.combinatorics.permutations import Permutation
>>> p = Permutation([0,1,2,3])
>>> p.rank()
0
>>> p = Permutation([3,2,1,0])
>>> p.rank()
23
See Also
========
next_lex, unrank_lex
"""
rank = 0
rho = self.array_form[:]
n = self.size - 1
size = n + 1
psize = int(ifac(n))
for j in xrange(size - 1):
rank += rho[j]*psize
for i in xrange(j + 1, size):
if rho[i] > rho[j]:
rho[i] -= 1
psize //= n
n -= 1
return rank
开发者ID:hector1618,项目名称:sympy,代码行数:32,代码来源:permutations.py
示例3: unrank_nonlex
def unrank_nonlex(self, n, r):
"""
This is a linear time unranking algorithm that does not
respect lexicographic order [3].
Examples
========
>>> from sympy.combinatorics.permutations import Permutation
>>> Permutation.unrank_nonlex(4, 5)
Permutation([2, 0, 3, 1])
>>> Permutation.unrank_nonlex(4, -1)
Permutation([0, 1, 2, 3])
See Also
========
next_nonlex, rank_nonlex
"""
def _unrank1(n, r, a):
if n > 0:
a[n - 1], a[r % n] = a[r % n], a[n - 1]
_unrank1(n - 1, r//n, a)
id_perm = range(n)
n = int(n)
r = r % ifac(n)
_unrank1(n, r, id_perm)
return _new_from_array_form(id_perm)
开发者ID:hector1618,项目名称:sympy,代码行数:28,代码来源:permutations.py
示例4: unrank_trotterjohnson
def unrank_trotterjohnson(self, size, rank):
"""
Trotter Johnson permutation unranking. See [4] section 2.4.
Examples
========
>>> from sympy.combinatorics.permutations import Permutation
>>> Permutation.unrank_trotterjohnson(5,10)
Permutation([0, 3, 1, 2, 4])
See Also
========
rank_trotterjohnson, next_trotterjohnson
"""
perm = [0]*size
r2 = 0
n = ifac(size)
pj = 1
for j in range(2, size+1):
pj *= j
r1 = (rank * pj) // n
k = r1 - j*r2
if r2 % 2 == 0:
for i in range(j-1, j-k-1, -1):
perm[i] = perm[i-1]
perm[j-k-1] = j-1
else:
for i in range(j-1, k, -1):
perm[i] = perm[i-1]
perm[k] = j-1
r2 = r1
return _new_from_array_form(perm)
开发者ID:hector1618,项目名称:sympy,代码行数:33,代码来源:permutations.py
示例5: cardinality
def cardinality(self):
"""
Returns the number of all possible permutations.
Examples:
>>> from sympy.combinatorics.permutations import Permutation
>>> p = Permutation([0,1,2,3])
>>> p.cardinality
24
"""
return Integer(ifac(self.size))
开发者ID:ArchKaine,项目名称:sympy,代码行数:11,代码来源:permutations.py
示例6: unrank_trotterjohnson
def unrank_trotterjohnson(self, size, rank):
"""
Trotter Johnson permutation unranking. See [4].
Examples:
>>> from sympy.combinatorics.permutations import Permutation
>>> Permutation.unrank_trotterjohnson(5,10)
Permutation([0, 3, 1, 2, 4])
"""
perm = [0]*size
r2 = 0
for j in range(2, size+1):
r1 = (rank * ifac(j))//ifac(size)
k = r1 - j*r2
if r2 % 2 == 0:
for i in range(j-1, j-k-1, -1):
perm[i] = perm[i-1]
perm[j-k-1] = j-1
else:
for i in range(j-1, k, -1):
perm[i] = perm[i-1]
perm[k] = j-1
r2 = r1
return _new_from_array_form(perm)
开发者ID:ArchKaine,项目名称:sympy,代码行数:24,代码来源:permutations.py
示例7: next_nonlex
def next_nonlex(self):
"""
Returns the next permutation in nonlex order [3].
If self is the last permutation in this order it returns None.
Examples:
>>> from sympy.combinatorics.permutations import Permutation
>>> p = Permutation([2, 0, 3, 1]); p.rank_nonlex()
5
>>> p = p.next_nonlex(); p
Permutation([3, 0, 1, 2])
>>> p.rank_nonlex()
6
"""
r = self.rank_nonlex()
if r == ifac(self.size) - 1:
return None
return Permutation.unrank_nonlex(self.size, r + 1)
开发者ID:TeddyBoomer,项目名称:geophar,代码行数:18,代码来源:permutations.py
注:本文中的sympy.mpmath.libmp.libintmath.ifac函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论