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 instance sympy.Q.

sympy.assumptions.ask.ask(proposition, assumptions=True, context={})[source]

Function to evaluate the proposition with assumptions.


proposition : Boolean

Proposition which will be evaluated to boolean value. If this is not AppliedPredicate, it will be wrapped by Q.is_true.

assumptions : Boolean, 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.


True, False, or None


TypeError : proposition or assumptions is not valid logical expression.

ValueError : assumptions are inconsistent.


This function evaluates the proposition to True or False if the truth value can be determined. If not, it returns None.

It should be discerned from refine() which, when applied to a proposition, simplifies the argument to symbolic Boolean instead of Python built-in True, False or None.


  • ask(proposition)

    Evaluate the proposition in global assumption context.

  • ask(proposition, assumptions)

    Evaluate the proposition with respect to assumptions in global assumption context.


>>> from sympy import ask, Q, pi
>>> from import x, y
>>> ask(Q.rational(pi))
>>> ask(Q.even(x*y), Q.even(x) & Q.integer(y))
>>> ask(*x), Q.integer(x))

If the truth value cannot be determined, None will be returned.

>>> print(ask(Q.odd(3*x))) # cannot determine unless we know x

ValueError is raised if assumptions are inconsistent.

>>> ask(Q.integer(x), Q.even(x) & Q.odd(x))
Traceback (most recent call last):
ValueError: inconsistent assumptions Q.even(x) & Q.odd(x)


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


Simplification using assumptions. Proposition is not reduced to None if the truth value cannot be determined.

sympy.assumptions.ask.register_handler(key, handler)[source]

Register a handler in the ask system. key must be a string and handler a class inheriting from AskHandler.

Deprecated since version 1.8.: Use multipledispatch handler instead. See Predicate.

sympy.assumptions.ask.remove_handler(key, handler)[source]

Removes a handler from the ask system.

Deprecated since version 1.8.: Use multipledispatch handler instead. See Predicate.