本文整理汇总了Python中sympy.logic.inference.satisfiable函数的典型用法代码示例。如果您正苦于以下问题:Python satisfiable函数的具体用法?Python satisfiable怎么用?Python satisfiable使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了satisfiable函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: ask_full_inference
def ask_full_inference(proposition, assumptions):
"""
Method for inferring properties about objects.
"""
if not satisfiable(And(known_facts_cnf, assumptions, proposition)):
return False
if not satisfiable(And(known_facts_cnf, assumptions, Not(proposition))):
return True
return None
开发者ID:SwaathiRamesh,项目名称:sympy,代码行数:10,代码来源:ask.py
示例2: test_satisfiable_non_symbols
def test_satisfiable_non_symbols():
x, y = symbols('x y')
assumptions = Q.zero(x*y)
facts = Implies(Q.zero(x*y), Q.zero(x) | Q.zero(y))
query = ~Q.zero(x) & ~Q.zero(y)
refutations = [
{Q.zero(x): True, Q.zero(x*y): True},
{Q.zero(y): True, Q.zero(x*y): True},
{Q.zero(x): True, Q.zero(y): True, Q.zero(x*y): True},
{Q.zero(x): True, Q.zero(y): False, Q.zero(x*y): True},
{Q.zero(x): False, Q.zero(y): True, Q.zero(x*y): True}]
assert not satisfiable(And(assumptions, facts, query), algorithm='dpll')
assert satisfiable(And(assumptions, facts, ~query), algorithm='dpll') in refutations
assert not satisfiable(And(assumptions, facts, query), algorithm='dpll2')
assert satisfiable(And(assumptions, facts, ~query), algorithm='dpll2') in refutations
开发者ID:A-turing-machine,项目名称:sympy,代码行数:15,代码来源:test_inference.py
示例3: test_satisfiable_all_models
def test_satisfiable_all_models():
from sympy.abc import A, B
assert next(satisfiable(False, all_models=True)) is False
assert list(satisfiable((A >> ~A) & A , all_models=True)) == [False]
assert list(satisfiable(True, all_models=True)) == [{true: true}]
models = [{A: True, B: False}, {A: False, B: True}]
result = satisfiable(A ^ B, all_models=True)
models.remove(next(result))
models.remove(next(result))
raises(StopIteration, lambda: next(result))
assert not models
assert list(satisfiable(Equivalent(A, B), all_models=True)) == \
[{A: False, B: False}, {A: True, B: True}]
models = [{A: False, B: False}, {A: False, B: True}, {A: True, B: True}]
for model in satisfiable(A >> B, all_models=True):
models.remove(model)
assert not models
# This is a santiy test to check that only the required number
# of solutions are generated. The expr below has 2**100 - 1 models
# which would time out the test if all are generated at once.
from sympy import numbered_symbols
from sympy.logic.boolalg import Or
sym = numbered_symbols()
X = [next(sym) for i in range(100)]
result = satisfiable(Or(*X), all_models=True)
for i in range(10):
assert next(result)
开发者ID:A-turing-machine,项目名称:sympy,代码行数:31,代码来源:test_inference.py
示例4: satask
def satask(proposition, assumptions=True, context=global_assumptions, use_known_facts=True, iterations=oo):
relevant_facts = get_all_relevant_facts(
proposition, assumptions, context, use_known_facts=use_known_facts, iterations=iterations
)
can_be_true = satisfiable(And(proposition, assumptions, relevant_facts, *context))
can_be_false = satisfiable(And(~proposition, assumptions, relevant_facts, *context))
if can_be_true and can_be_false:
return None
if can_be_true and not can_be_false:
return True
if not can_be_true and can_be_false:
return False
if not can_be_true and not can_be_false:
# TODO: Run additional checks to see which combination of the
# assumptions, global_assumptions, and relevant_facts are
# inconsistent.
raise ValueError("Inconsistent assumptions")
开发者ID:Sam-Tygier,项目名称:sympy,代码行数:22,代码来源:satask.py
示例5: equals
def equals(self, other):
"""
Returns if the given formulas have the same truth table.
For two formulas to be equal they must have the same literals.
Examples
========
>>> from sympy.abc import A, B, C
>>> from sympy.logic.boolalg import And, Or, Not
>>> (A >> B).equals(~B >> ~A)
True
>>> Not(And(A, B, C)).equals(And(Not(A), Not(B), Not(C)))
False
>>> Not(And(A, Not(A))).equals(Or(B, Not(B)))
False
"""
from sympy.logic.inference import satisfiable
return self.atoms() == other.atoms() and \
not satisfiable(Not(Equivalent(self, other)))
开发者ID:Bercio,项目名称:sympy,代码行数:21,代码来源:boolalg.py
示例6: equals
def equals(self, other):
"""
Returns if the given formulas have the same truth table.
For two formulas to be equal they must have the same literals.
Examples
========
>>> from sympy.abc import A, B, C
>>> from sympy.logic.boolalg import And, Or, Not
>>> (A >> B).equals(~B >> ~A)
True
>>> Not(And(A, B, C)).equals(And(Not(A), Not(B), Not(C)))
False
>>> Not(And(A, Not(A))).equals(Or(B, Not(B)))
False
"""
from sympy.logic.inference import satisfiable
from sympy.core.relational import Relational
if self.has(Relational) or other.has(Relational):
raise NotImplementedError('handling of relationals')
return self.atoms() == other.atoms() and \
not satisfiable(Not(Equivalent(self, other)))
开发者ID:artcompiler,项目名称:artcompiler.github.com,代码行数:24,代码来源:boolalg.py
示例7: ask
def ask(proposition, assumptions=True, context=global_assumptions):
"""
Method for inferring properties about objects.
**Syntax**
* ask(proposition)
* ask(proposition, assumptions)
where ``proposition`` is any boolean expression
Examples
========
>>> from sympy import ask, Q, pi
>>> from sympy.abc import x, y
>>> ask(Q.rational(pi))
False
>>> ask(Q.even(x*y), Q.even(x) & Q.integer(y))
True
>>> ask(Q.prime(x*y), Q.integer(x) & Q.integer(y))
False
**Remarks**
Relations in assumptions are not implemented (yet), so the following
will not give a meaningful result.
>>> ask(Q.positive(x), Q.is_true(x > 0)) # doctest: +SKIP
It is however a work in progress.
"""
if not isinstance(proposition, (BooleanFunction, AppliedPredicate, bool)):
raise TypeError("proposition must be a valid logical expression")
if not isinstance(assumptions, (BooleanFunction, AppliedPredicate, bool)):
raise TypeError("assumptions must be a valid logical expression")
if isinstance(proposition, AppliedPredicate):
key, expr = proposition.func, sympify(proposition.arg)
else:
key, expr = Q.is_true, sympify(proposition)
assumptions = And(assumptions, And(*context))
local_facts = _extract_facts(assumptions, expr)
if local_facts is not None and satisfiable(And(local_facts, known_facts_cnf)) is False:
raise ValueError("inconsistent assumptions %s" % assumptions)
# direct resolution method, no logic
res = key(expr)._eval_ask(assumptions)
if res is not None:
return res
if assumptions is True:
return
if local_facts in (None, True):
return
# See if there's a straight-forward conclusion we can make for the inference
if local_facts.is_Atom:
if key in known_facts_dict[local_facts]:
return True
if Not(key) in known_facts_dict[local_facts]:
return False
elif local_facts.func is And and all(k in known_facts_dict for k in local_facts.args):
for assum in local_facts.args:
if assum.is_Atom:
if key in known_facts_dict[assum]:
return True
if Not(key) in known_facts_dict[assum]:
return False
elif assum.func is Not and assum.args[0].is_Atom:
if key in known_facts_dict[assum]:
return False
if Not(key) in known_facts_dict[assum]:
return True
elif (isinstance(key, Predicate) and
local_facts.func is Not and local_facts.args[0].is_Atom):
if local_facts.args[0] in known_facts_dict[key]:
return False
# Failing all else, we do a full logical inference
return ask_full_inference(key, local_facts, known_facts_cnf)
开发者ID:abhi2705,项目名称:sympy,代码行数:86,代码来源:ask.py
示例8: ask
def ask(expr, key, assumptions=True, context=global_assumptions, disable_preprocessing=False):
"""
Method for inferring properties about objects.
**Syntax**
* ask(expression, key)
* ask(expression, key, assumptions)
where expression is any SymPy expression
**Examples**
>>> from sympy import ask, Q, Assume, pi
>>> from sympy.abc import x, y
>>> ask(pi, Q.rational)
False
>>> ask(x*y, Q.even, Assume(x, Q.even) & Assume(y, Q.integer))
True
>>> ask(x*y, Q.prime, Assume(x, Q.integer) & Assume(y, Q.integer))
False
**Remarks**
Relations in assumptions are not implemented (yet), so the following
will not give a meaningful result.
>> ask(x, positive=True, Assume(x>0))
It is however a work in progress and should be available before
the official release
"""
expr = sympify(expr)
if type(key) is not Predicate:
key = getattr(Q, str(key))
assumptions = And(assumptions, And(*context))
# direct resolution method, no logic
if not disable_preprocessing:
res = eval_predicate(key, expr, assumptions)
if res is not None:
return res
if assumptions is True:
return
if not expr.is_Atom:
return
assumptions = eliminate_assume(assumptions, expr)
if assumptions is None or assumptions is True:
return
# See if there's a straight-forward conclusion we can make for the inference
if not disable_preprocessing:
if assumptions.is_Atom:
if key in known_facts_dict[assumptions]:
return True
if Not(key) in known_facts_dict[assumptions]:
return False
elif assumptions.func is And:
for assum in assumptions.args:
if assum.is_Atom:
if key in known_facts_dict[assum]:
return True
if Not(key) in known_facts_dict[assum]:
return False
elif assum.func is Not and assum.args[0].is_Atom:
if key in known_facts_dict[assum]:
return False
if Not(key) in known_facts_dict[assum]:
return True
elif assumptions.func is Not and assumptions.args[0].is_Atom:
if assumptions.args[0] in known_facts_dict[key]:
return False
# Failing all else, we do a full logical inference
# If it's not consistent with the assumptions, then it can't be true
if not satisfiable(And(known_facts_cnf, assumptions, key)):
return False
# If the negation is unsatisfiable, it is entailed
if not satisfiable(And(known_facts_cnf, assumptions, Not(key))):
return True
# Otherwise, we don't have enough information to conclude one way or the other
return None
开发者ID:fgrosshans,项目名称:sympy,代码行数:85,代码来源:ask.py
示例9: test_satisfiable
def test_satisfiable():
A, B, C = symbols('A,B,C')
assert satisfiable(A & (A >> B) & ~B) is False
开发者ID:FireJade,项目名称:sympy,代码行数:3,代码来源:test_inference.py
示例10: eval
def eval(variable, expr):
if satisfiable(expr) == False:
return false
return Exist(variable, expr, evaluate=False)
开发者ID:worldmaker18349276,项目名称:magicpy,代码行数:4,代码来源:logicplus.py
示例11: test_satisfiable_1
def test_satisfiable_1():
"""We prove expr entails alpha proving expr & ~B is unsatisfiable"""
A, B, C = symbols('ABC')
assert satisfiable(A & (A >> B) & ~B) == False
开发者ID:ryanGT,项目名称:sympy,代码行数:4,代码来源:test_inference.py
示例12: test_satisfiable_bool
def test_satisfiable_bool():
from sympy.core.singleton import S
assert satisfiable(true) == {true: true}
assert satisfiable(S.true) == {true: true}
assert satisfiable(false) is False
assert satisfiable(S.false) is False
开发者ID:A-turing-machine,项目名称:sympy,代码行数:6,代码来源:test_inference.py
示例13: test_satisfiable_bool
def test_satisfiable_bool():
assert satisfiable(True) == {}
assert satisfiable(False) == False
开发者ID:B-Rich,项目名称:sympy,代码行数:3,代码来源:test_inference.py
示例14: test_satisfiable
def test_satisfiable():
A, B, C = symbols("A,B,C")
assert satisfiable(A & (A >> B) & ~B) == False
开发者ID:ness01,项目名称:sympy,代码行数:3,代码来源:test_inference.py
示例15: print
if (i == "AND") or (i == "&&") or (i == "and") or (i == "∧"):
tokenized_input.append("&")
continue
# or
if (i == "OR") or (i == "||") or (i == "or") or (i == "∨"):
tokenized_input.append("|")
continue
# not
if (i == "NOT") or (i == "not") or (i == "!") or (i == "¬"):
tokenized_input.append("~")
continue
# XOR
if (i == "XOR") or (i == "xor") or (i == "^"):
tokenized_input.append("^")
continue
tokenized_input.append(i)
print("Tokenized: " + str(tokenized_input))
string = " ".join(tokenized_input)
print("string: " + string)
sym = sympify(str(string), convert_xor=False)
sat = satisfiable(sym, all_models=True)
for x in sat: # print all possibilities
print(x)
开发者ID:matthiaskrgr,项目名称:logic_py,代码行数:30,代码来源:main.py
注:本文中的sympy.logic.inference.satisfiable函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论