Ask¶
Module for querying SymPy objects about assumptions.
-
class
sympy.assumptions.ask.
AssumptionKeys
[source]¶ This class contains all the supported keys by
ask
. It should be accessed via the instancesympy.Q
.
-
sympy.assumptions.ask.
ask
(proposition, assumptions=True, context={})[source]¶ Function to evaluate the proposition with assumptions.
Syntax
- ask(proposition)
Evaluate the proposition in global assumption context.
- ask(proposition, assumptions)
Evaluate the proposition with respect to assumptions in global assumption context.
This function evaluates the proposition to
True
orFalse
if the truth value can be determined. If not, it returnsNone
.It should be discerned from
refine()
which, when applied to a proposition, simplifies the argument to symbolicBoolean
instead of Python built-inTrue
,False
orNone
.- Parameters
proposition : any boolean expression
Proposition which will be evaluated to boolean value. If this is not
AppliedPredicate
, it will be wrapped byQ.is_true
.assumptions : any boolean expression, optional
Local assumptions to evaluate the proposition.
context : AssumptionsContext, optional
Default assumptions to evaluate the proposition. By default, this is
sympy.assumptions.global_assumptions
variable.
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(4*x), Q.integer(x)) False
If the truth value cannot be determined,
None
will be returned.>>> print(ask(Q.odd(3*x))) # cannot determine unless we know x None
Remarks
Relations in assumptions are not implemented (yet), so the following will not give a meaningful result.
>>> ask(Q.positive(x), x > 0)
It is however a work in progress.
See also
sympy.assumptions.refine.refine
Simplification using assumptions. Proposition is not reduced to
None
if the truth value cannot be determined.
-
sympy.assumptions.ask.
ask_full_inference
(proposition, assumptions, known_facts_cnf)[source]¶ Method for inferring properties about objects.
-
sympy.assumptions.ask.
compute_known_facts
(known_facts, known_facts_keys)[source]¶ Compute the various forms of knowledge compilation used by the assumptions system.
Explanation
This function is typically applied to the results of the
get_known_facts
andget_known_facts_keys
functions defined at the bottom of this file.