本文整理汇总了Python中sympy.utilities.iterables.has_dups函数的典型用法代码示例。如果您正苦于以下问题:Python has_dups函数的具体用法?Python has_dups怎么用?Python has_dups使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了has_dups函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __new__
def __new__(cls, partition):
"""
Generates a new partition object.
This method also verifies if the arguments passed are
valid and raises a ValueError if they are not.
Examples
========
>>> from sympy.combinatorics.partitions import Partition
>>> a = Partition([[1, 2], [3]])
>>> a
{{1, 2}, {3}}
>>> a.partition
[[1, 2], [3]]
>>> len(a)
2
>>> a.members
(1, 2, 3)
"""
args = partition
if not all(isinstance(part, list) for part in args):
raise ValueError("Partition should be a list of lists.")
# sort so we have a canonical reference for RGS
partition = sorted(sum(partition, []), key=default_sort_key)
if has_dups(partition):
raise ValueError("Partition contained duplicated elements.")
obj = C.FiniteSet.__new__(cls, map(C.FiniteSet, args))
obj.members = tuple(partition)
obj.size = len(partition)
return obj
开发者ID:FireJade,项目名称:sympy,代码行数:35,代码来源:partitions.py
示例2: preprocess
def preprocess(cls, gens):
if isinstance(gens, Basic):
gens = (gens,)
elif len(gens) == 1 and hasattr(gens[0], '__iter__'):
gens = gens[0]
if gens == (None,):
gens = ()
elif has_dups(gens):
raise GeneratorsError("duplicated generators: %s" % str(gens))
elif any(gen.is_commutative is False for gen in gens):
raise GeneratorsError("non-commutative generators: %s" % str(gens))
return tuple(gens)
开发者ID:alhirzel,项目名称:sympy,代码行数:14,代码来源:polyoptions.py
示例3: eval
def eval(cls, *args):
if all(isinstance(a, (int, Integer)) for a in args):
return eval_levicivita(*args)
if has_dups(args):
return S.Zero
开发者ID:FireJade,项目名称:sympy,代码行数:5,代码来源:tensor_functions.py
示例4: pde_separate
def pde_separate(eq, fun, sep, strategy='mul'):
"""Separate variables in partial differential equation either by additive
or multiplicative separation approach. It tries to rewrite an equation so
that one of the specified variables occurs on a different side of the
equation than the others.
:param eq: Partial differential equation
:param fun: Original function F(x, y, z)
:param sep: List of separated functions [X(x), u(y, z)]
:param strategy: Separation strategy. You can choose between additive
separation ('add') and multiplicative separation ('mul') which is
default.
Examples
========
>>> from sympy import E, Eq, Function, pde_separate, Derivative as D
>>> from sympy.abc import x, t
>>> u, X, T = map(Function, 'uXT')
>>> eq = Eq(D(u(x, t), x), E**(u(x, t))*D(u(x, t), t))
>>> pde_separate(eq, u(x, t), [X(x), T(t)], strategy='add')
[exp(-X(x))*Derivative(X(x), x), exp(T(t))*Derivative(T(t), t)]
>>> eq = Eq(D(u(x, t), x, 2), D(u(x, t), t, 2))
>>> pde_separate(eq, u(x, t), [X(x), T(t)], strategy='mul')
[Derivative(X(x), x, x)/X(x), Derivative(T(t), t, t)/T(t)]
See Also
========
pde_separate_add, pde_separate_mul
"""
do_add = False
if strategy == 'add':
do_add = True
elif strategy == 'mul':
do_add = False
else:
assert ValueError('Unknown strategy: %s' % strategy)
if isinstance(eq, Equality):
if eq.rhs != 0:
return pde_separate(Eq(eq.lhs - eq.rhs), fun, sep, strategy)
assert eq.rhs == 0
# Handle arguments
orig_args = list(fun.args)
subs_args = []
for s in sep:
for j in range(0, len(s.args)):
subs_args.append(s.args[j])
if do_add:
functions = reduce(operator.add, sep)
else:
functions = reduce(operator.mul, sep)
# Check whether variables match
if len(subs_args) != len(orig_args):
raise ValueError("Variable counts do not match")
# Check for duplicate arguments like [X(x), u(x, y)]
if has_dups(subs_args):
raise ValueError("Duplicate substitution arguments detected")
# Check whether the variables match
if set(orig_args) != set(subs_args):
raise ValueError("Arguments do not match")
# Substitute original function with separated...
result = eq.lhs.subs(fun, functions).doit()
# Divide by terms when doing multiplicative separation
if not do_add:
eq = 0
for i in result.args:
eq += i/functions
result = eq
svar = subs_args[0]
dvar = subs_args[1:]
return _separate(result, svar, dvar)
开发者ID:AALEKH,项目名称:sympy,代码行数:84,代码来源:pde.py
示例5: test_has_dups
def test_has_dups():
assert has_dups(set()) is False
assert has_dups(range(3)) is False
assert has_dups([1, 2, 1]) is True
开发者ID:Acebulf,项目名称:sympy,代码行数:4,代码来源:test_iterables.py
注:本文中的sympy.utilities.iterables.has_dups函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论