Module for querying SymPy objects about 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
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.
Method for inferring properties about objects.
Compute the various forms of knowledge compilation used by the assumptions system.
This function is typically applied to the variables known_facts and known_facts_keys defined at the bottom of this file.
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