# SymPy - Querying

The assumptions module in SymPy package contains tools for extracting information about expressions. The module defines ask() function for this purpose.

sympy.assumptions.ask(property)


Following properties provide useful information about an expression −

algebraic(x)

To be algebraic, a number must be a root of a non-zero polynomial equation with rational coefficients. √2 because √2 is a solution to x2 − 2 = 0, so it is algebraic.

complex(x)

Complex number predicate. It is true if and only if x belongs to the set of complex numbers.

composite(x)

Composite number predicate returned by ask(Q.composite(x)) is true if and only if x is a positive integer and has at least one positive divisor other than 1 and the number itself.

even, odd

The ask() returns true of x is in the set of even numbers and set of odd numbers respectively.

imaginary

This property represents Imaginary number predicate. It is true if x can be written as a real number multiplied by the imaginary unit I.

integer

This property returned by Q.integer(x) returns true of x belong to set of even numbers.

rational, irrational

Q.irrational(x) is true if and only if x is any real number that cannot be expressed as a ratio of integers. For example, pi is an irrational number.

positive, negative

Predicates to check if number is positive or negative

zero, nonzero

Predicates to heck if a number is zero or not

>>> from sympy import *
>>> x=Symbol('x')
>>> x=10
False
(True, True)
>>> x,y=symbols("x y")
>>> x,y=5,10
(False, True)
(False, True)
>>> x,y= 2*I, 4+5*I