Ask

Module for querying SymPy objects about assumptions.

class sympy.assumptions.ask.Q[source]

Supported ask keys.

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

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)) 

It is however a work in progress.

sympy.assumptions.ask.ask_full_inference(proposition, assumptions)[source]

Method for inferring properties about objects.

sympy.assumptions.ask.compute_known_facts()[source]

Compute the various forms of knowledge compilation used by the assumptions system.

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:

>>> from sympy.assumptions import register_handler, ask, Q
>>> from sympy.assumptions.handlers import AskHandler
>>> class MersenneHandler(AskHandler):
...     # Mersenne numbers are in the form 2**n + 1, n integer
...     @staticmethod
...     def Integer(expr, assumptions):
...         import math
...         return ask(Q.integer(math.log(expr + 1, 2)))
>>> register_handler('mersenne', MersenneHandler)
>>> ask(Q.mersenne(7))
True
sympy.assumptions.ask.remove_handler(key, handler)[source]

Removes a handler from the ask system. Same syntax as register_handler

Previous topic

Assumptions module

Next topic

Assume

This Page