本文整理汇总了Python中sympy.core.logic.fuzzy_bool函数的典型用法代码示例。如果您正苦于以下问题:Python fuzzy_bool函数的具体用法?Python fuzzy_bool怎么用?Python fuzzy_bool使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fuzzy_bool函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __new__
def __new__(cls, name, **assumptions):
"""Symbols are identified by name and assumptions::
>>> from sympy import Symbol
>>> Symbol("x") == Symbol("x")
True
>>> Symbol("x", real=True) == Symbol("x", real=False)
False
"""
if 'dummy' in assumptions:
SymPyDeprecationWarning(
feature="Symbol('x', dummy=True)",
useinstead="Dummy() or symbols(..., cls=Dummy)"
).warn()
if assumptions.pop('dummy'):
return Dummy(name, **assumptions)
if assumptions.get('zero', False):
return S.Zero
is_commutative = fuzzy_bool(assumptions.get('commutative', True))
if is_commutative is None:
raise ValueError(
'''Symbol commutativity must be True or False.''')
assumptions['commutative'] = is_commutative
return Symbol.__xnew_cached_(cls, name, **assumptions)
开发者ID:BDGLunde,项目名称:sympy,代码行数:26,代码来源:symbol.py
示例2: __new__
def __new__(cls, name, **assumptions):
"""Symbols are identified by name and assumptions::
>>> from sympy import Symbol
>>> Symbol("x") == Symbol("x")
True
>>> Symbol("x", real=True) == Symbol("x", real=False)
False
"""
if "dummy" in assumptions:
SymPyDeprecationWarning(
feature="Symbol('x', dummy=True)",
useinstead="Dummy() or symbols(..., cls=Dummy)",
issue=3378,
deprecated_since_version="0.7.0",
).warn()
if assumptions.pop("dummy"):
return Dummy(name, **assumptions)
if assumptions.get("zero", False):
return S.Zero
is_commutative = fuzzy_bool(assumptions.get("commutative", True))
if is_commutative is None:
raise ValueError("""Symbol commutativity must be True or False.""")
assumptions["commutative"] = is_commutative
return Symbol.__xnew_cached_(cls, name, **assumptions)
开发者ID:nthorne,项目名称:sympy,代码行数:27,代码来源:symbol.py
示例3: _sanitize
def _sanitize(assumptions, obj=None):
"""Remove None, covert values to bool, check commutativity *in place*.
"""
# be strict about commutativity: cannot be None
is_commutative = fuzzy_bool(assumptions.get('commutative', True))
if is_commutative is None:
whose = '%s ' % obj.__name__ if obj else ''
raise ValueError(
'%scommutativity must be True or False.' % whose)
# sanitize other assumptions so 1 -> True and 0 -> False
for key in list(assumptions.keys()):
from collections import defaultdict
from sympy.utilities.exceptions import SymPyDeprecationWarning
keymap = defaultdict(lambda: None)
keymap.update({'bounded': 'finite', 'unbounded': 'infinite', 'infinitesimal': 'zero'})
if keymap[key]:
SymPyDeprecationWarning(
feature="%s assumption" % key,
useinstead="%s" % keymap[key],
issue=8071,
deprecated_since_version="0.7.6").warn()
assumptions[keymap[key]] = assumptions[key]
assumptions.pop(key)
key = keymap[key]
v = assumptions[key]
if v is None:
assumptions.pop(key)
continue
assumptions[key] = bool(v)
开发者ID:AStorus,项目名称:sympy,代码行数:32,代码来源:symbol.py
示例4: wrapper
def wrapper(*args, **kw_args):
"""
Assemble the args and kw_args to compute the hash.
It is important that kw_args be standardized since if they
have the same meaning but in different forms (e.g. one
kw_arg having a value of 1 for an object and another object
with identical args but a kw_arg of True) then two different
hashes will be computed and the two objects will not be identical.
"""
if kw_args:
keys = kw_args.keys()
# make keywords all the same
for k in keys:
kw_args[k] = fuzzy_bool(kw_args[k])
keys.sort()
items = [(k+'=', kw_args[k]) for k in keys]
k = args + tuple(items)
else:
k = args
k = k + tuple(map(lambda x: type(x), k))
try:
return func_cache_it_cache[k]
except KeyError:
pass
func_cache_it_cache[k] = r = func(*args, **kw_args)
return r
开发者ID:fgrosshans,项目名称:sympy,代码行数:28,代码来源:cache.py
示例5: pred
def pred(x):
if x is S.ImaginaryUnit:
return S.ImaginaryUnit
polar = x.is_polar
if polar:
return True
if polar is None:
return fuzzy_bool(x.is_nonnegative)
开发者ID:hrashk,项目名称:sympy,代码行数:8,代码来源:power.py
示例6: __new__
def __new__(cls, sym, condition, base_set=S.UniversalSet):
# nonlinsolve uses ConditionSet to return an unsolved system
# of equations (see _return_conditionset in solveset) so until
# that is changed we do minimal checking of the args
if isinstance(sym, (Tuple, tuple)): # unsolved eqns syntax
sym = Tuple(*sym)
condition = FiniteSet(*condition)
return Basic.__new__(cls, sym, condition, base_set)
condition = as_Boolean(condition)
if isinstance(base_set, set):
base_set = FiniteSet(*base_set)
elif not isinstance(base_set, Set):
raise TypeError('expecting set for base_set')
if condition is S.false:
return S.EmptySet
if condition is S.true:
return base_set
if isinstance(base_set, EmptySet):
return base_set
know = None
if isinstance(base_set, FiniteSet):
sifted = sift(
base_set, lambda _: fuzzy_bool(
condition.subs(sym, _)))
if sifted[None]:
know = FiniteSet(*sifted[True])
base_set = FiniteSet(*sifted[None])
else:
return FiniteSet(*sifted[True])
if isinstance(base_set, cls):
s, c, base_set = base_set.args
if sym == s:
condition = And(condition, c)
elif sym not in c.free_symbols:
condition = And(condition, c.xreplace({s: sym}))
elif s not in condition.free_symbols:
condition = And(condition.xreplace({sym: s}), c)
sym = s
else:
# user will have to use cls.sym to get symbol
dum = Symbol('lambda')
if dum in condition.free_symbols or \
dum in c.free_symbols:
dum = Dummy(str(dum))
condition = And(
condition.xreplace({sym: dum}),
c.xreplace({s: dum}))
sym = dum
if not isinstance(sym, Symbol):
s = Dummy('lambda')
if s not in condition.xreplace({sym: s}).free_symbols:
raise ValueError(
'non-symbol dummy not recognized in condition')
rv = Basic.__new__(cls, sym, condition, base_set)
return rv if know is None else Union(know, rv)
开发者ID:asmeurer,项目名称:sympy,代码行数:55,代码来源:conditionset.py
示例7: __new__
def __new__(cls, name, **assumptions):
if assumptions.get('zero', False):
return S.Zero
check_commutative = fuzzy_bool(assumptions.get('commutative', True))
if check_commutative is None:
raise ValueError(
'''commutativity symbol must take values eighter a True or False.''')
assumptions['commutative'] = check_commutative
for key in assumptions.keys():
assumptions[key] = bool(assumptions[key])
return sympy.Symbol.__xnew__(cls, name, uuid=str(int(round(1e16*random.random()))), **assumptions)
开发者ID:AMAN3003,项目名称:-Optimization_Problem_solver,代码行数:12,代码来源:interface.py
示例8: encloses_point
def encloses_point(self, p):
"""
Return True if p is enclosed by (is inside of) self.
Notes
-----
Being on the border of self is considered False.
Parameters
==========
p : Point
Returns
=======
encloses_point : True, False or None
See Also
========
sympy.geometry.point.Point
Examples
========
>>> from sympy import Ellipse, S
>>> from sympy.abc import t
>>> e = Ellipse((0, 0), 3, 2)
>>> e.encloses_point((0, 0))
True
>>> e.encloses_point(e.arbitrary_point(t).subs(t, S.Half))
False
>>> e.encloses_point((4, 0))
False
"""
p = Point(p, dim=2)
if p in self:
return False
if len(self.foci) == 2:
# if the combined distance from the foci to p (h1 + h2) is less
# than the combined distance from the foci to the minor axis
# (which is the same as the major axis length) then p is inside
# the ellipse
h1, h2 = [f.distance(p) for f in self.foci]
test = 2*self.major - (h1 + h2)
else:
test = self.radius - self.center.distance(p)
return fuzzy_bool(test.is_positive)
开发者ID:aprasanna,项目名称:sympy,代码行数:52,代码来源:ellipse.py
示例9: __new__
def __new__(cls, name, **assumptions):
if assumptions.get('zero', False):
return S.Zero
is_commutative = fuzzy_bool(assumptions.get('commutative', True))
if is_commutative is None:
raise ValueError(
'''Symbol commutativity must be True or False.''')
assumptions['commutative'] = is_commutative
for key in assumptions.keys():
assumptions[key] = bool(assumptions[key])
return sympy.Symbol.__xnew__(cls, name, uuid=str(int(round(1e16 * random.random()))),
**assumptions) # uuid.uuid1()
开发者ID:phantomas1234,项目名称:optlang,代码行数:13,代码来源:interface.py
示例10: __new__
def __new__(cls, sym, condition, base_set):
if condition == S.false:
return S.EmptySet
if condition == S.true:
return base_set
if isinstance(base_set, EmptySet):
return base_set
if isinstance(base_set, FiniteSet):
sifted = sift(base_set, lambda _: fuzzy_bool(condition.subs(sym, _)))
if sifted[None]:
return Union(FiniteSet(*sifted[True]),
Basic.__new__(cls, sym, condition, FiniteSet(*sifted[None])))
else:
return FiniteSet(*sifted[True])
return Basic.__new__(cls, sym, condition, base_set)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:15,代码来源:conditionset.py
示例11: _sanitize
def _sanitize(assumptions):
"""Remove None, covert values to bool, make sure commutativity is T/F"""
# be strict about commutativity
is_commutative = fuzzy_bool(assumptions.get('commutative', True))
if is_commutative is None:
raise ValueError(
'%s commutativity must be True or False.' % cls.__name__)
assumptions['commutative'] = is_commutative
# sanitize other assumptions so 1 -> True and 0 -> False
for key in list(assumptions.keys()):
v = assumptions[key]
if v is None:
assumptions.pop(key)
continue
assumptions[key] = bool(v)
开发者ID:norah911,项目名称:sympy,代码行数:17,代码来源:symbol.py
示例12: __new__
def __new__(cls, name, **assumptions):
"""Symbols are identified by name and assumptions::
>>> from sympy import Symbol
>>> Symbol("x") == Symbol("x")
True
>>> Symbol("x", real=True) == Symbol("x", real=False)
False
"""
is_commutative = fuzzy_bool(assumptions.get('commutative', True))
if is_commutative is None:
raise ValueError(
'''Symbol commutativity must be True or False.''')
assumptions['commutative'] = is_commutative
for key in assumptions.keys():
assumptions[key] = bool(assumptions[key])
return Symbol.__xnew_cached_(cls, name, **assumptions)
开发者ID:aiwku1277,项目名称:sympy,代码行数:19,代码来源:symbol.py
示例13: _sanitize
def _sanitize(assumptions, obj=None):
"""Remove None, covert values to bool, check commutativity *in place*.
"""
# be strict about commutativity
is_commutative = fuzzy_bool(assumptions.get('commutative', True))
if is_commutative is None:
whose = '%s ' % obj.__name__ if obj else ''
raise ValueError(
'%scommutativity must be True or False.' % whose)
assumptions['commutative'] = is_commutative
# sanitize other assumptions so 1 -> True and 0 -> False
for key in list(assumptions.keys()):
v = assumptions[key]
if v is None:
assumptions.pop(key)
continue
assumptions[key] = bool(v)
开发者ID:gitter-badger,项目名称:sympy,代码行数:19,代码来源:symbol.py
示例14: __new_stage2__
def __new_stage2__(cls, name, **assumptions):
if not isinstance(name, string_types):
raise TypeError("name should be a string, not %s" % repr(type(name)))
obj = Expr.__new__(cls)
obj.name = name
# TODO: Issue #8873: Forcing the commutative assumption here means
# later code such as ``srepr()`` cannot tell whether the user
# specified ``commutative=True`` or omitted it. To workaround this,
# we keep a copy of the assumptions dict, then create the StdFactKB,
# and finally overwrite its ``._generator`` with the dict copy. This
# is a bit of a hack because we assume StdFactKB merely copies the
# given dict as ``._generator``, but future modification might, e.g.,
# compute a minimal equivalent assumption set.
tmp_asm_copy = assumptions.copy()
# be strict about commutativity
is_commutative = fuzzy_bool(assumptions.get('commutative', True))
assumptions['commutative'] = is_commutative
obj._assumptions = StdFactKB(assumptions)
obj._assumptions._generator = tmp_asm_copy # Issue #8873
return obj
开发者ID:AStorus,项目名称:sympy,代码行数:23,代码来源:symbol.py
示例15: __new__
def __new__(cls, lhs, rhs=0, **options):
from sympy.core.add import Add
from sympy.core.logic import fuzzy_bool
from sympy.core.expr import _n2
from sympy.simplify.simplify import clear_coefficients
lhs = _sympify(lhs)
rhs = _sympify(rhs)
evaluate = options.pop('evaluate', global_evaluate[0])
if evaluate:
# If one expression has an _eval_Eq, return its results.
if hasattr(lhs, '_eval_Eq'):
r = lhs._eval_Eq(rhs)
if r is not None:
return r
if hasattr(rhs, '_eval_Eq'):
r = rhs._eval_Eq(lhs)
if r is not None:
return r
# If expressions have the same structure, they must be equal.
if lhs == rhs:
return S.true
elif all(isinstance(i, BooleanAtom) for i in (rhs, lhs)):
return S.false
# check finiteness
fin = L, R = [i.is_finite for i in (lhs, rhs)]
if None not in fin:
if L != R:
return S.false
if L is False:
if lhs == -rhs: # Eq(oo, -oo)
return S.false
return S.true
elif None in fin and False in fin:
return Relational.__new__(cls, lhs, rhs, **options)
if all(isinstance(i, Expr) for i in (lhs, rhs)):
# see if the difference evaluates
dif = lhs - rhs
z = dif.is_zero
if z is not None:
if z is False and dif.is_commutative: # issue 10728
return S.false
if z:
return S.true
# evaluate numerically if possible
n2 = _n2(lhs, rhs)
if n2 is not None:
return _sympify(n2 == 0)
# see if the ratio evaluates
n, d = dif.as_numer_denom()
rv = None
if n.is_zero:
rv = d.is_nonzero
elif n.is_finite:
if d.is_infinite:
rv = S.true
elif n.is_zero is False:
rv = d.is_infinite
if rv is None:
# if the condition that makes the denominator infinite does not
# make the original expression True then False can be returned
l, r = clear_coefficients(d, S.Infinity)
args = [_.subs(l, r) for _ in (lhs, rhs)]
if args != [lhs, rhs]:
rv = fuzzy_bool(Eq(*args))
if rv is True:
rv = None
elif any(a.is_infinite for a in Add.make_args(n)): # (inf or nan)/x != 0
rv = S.false
if rv is not None:
return _sympify(rv)
return Relational.__new__(cls, lhs, rhs, **options)
开发者ID:baoqchau,项目名称:sympy,代码行数:77,代码来源:relational.py
注:本文中的sympy.core.logic.fuzzy_bool函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论