1.. _assumptions_module:
2
3===========
4Assumptions
5===========
6
7.. automodule:: sympy.assumptions
8
9
10Predicate
11=========
12
13.. autoclass:: sympy.assumptions.assume::Predicate
14   :members:
15   :noindex:
16
17.. autoclass:: sympy.assumptions.assume::AppliedPredicate
18   :members:
19   :noindex:
20
21
22Querying
23========
24
25Queries are used to ask information about expressions. Main method for this
26is ``ask()``:
27
28.. autofunction:: sympy.assumptions.ask::ask
29   :noindex:
30
31``ask``'s optional second argument should be a boolean expression involving
32assumptions about objects in *expr*. Valid values include:
33
34    * ``Q.integer(x)``
35    * ``Q.positive(x)``
36    * ``Q.integer(x) & Q.positive(x)``
37    * etc.
38
39``Q`` is an object holding known predicates.
40
41See documentation for the logic module for a complete list of valid boolean
42expressions.
43
44You can also define a context so you don't have to pass that argument
45each time to function ``ask()``. This is done by using the assuming context manager
46from module sympy.assumptions. ::
47
48     >>> from sympy import *
49     >>> x = Symbol('x')
50     >>> y = Symbol('y')
51     >>> facts = Q.positive(x), Q.positive(y)
52     >>> with assuming(*facts):
53     ...     print(ask(Q.positive(2*x + y)))
54     True
55
56
57Contents
58========
59
60.. toctree::
61    :maxdepth: 3
62
63    ask.rst
64    assume.rst
65    refine.rst
66    predicates.rst
67
68
69Performance improvements
70========================
71
72On queries that involve symbolic coefficients, logical inference is used. Work on
73improving satisfiable function (sympy.logic.inference.satisfiable) should result
74in notable speed improvements.
75
76Logic inference used in one ask could be used to speed up further queries, and
77current system does not take advantage of this. For example, a truth maintenance
78system (https://en.wikipedia.org/wiki/Truth_maintenance_system) could be implemented.
79
80Misc
81====
82
83You can find more examples in the in the form of test under directory
84sympy/assumptions/tests/
85