B
    [              $   @   s  d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lmZ dddgZi ZeeZG dd de Z!e! Z"dJddZ#defddZ$dd Z%dd Z&dd Z'dd Z(dd Z)dZ*d d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCg$Z+x e+D ]\Z,Z-e&e,e*e-  qZW edDdE Z.edFdG Z/ddHl0m1Z1m2Z2 dIS )Kz4Module for querying SymPy objects about assumptions.    )print_functiondivision)sympify)cacheit)
Relational)to_cnfAndNotOrImplies
EquivalentBooleanFunctionBooleanAtom)satisfiable)global_assumptions	PredicateAppliedPredicate)
deprecated)memoize_propertyboundedinfinityinfinitesimalc               @   sV  e Zd ZdZedd Zedd Zedd Zedd	 Zed
d Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zeedddddd Zed d! Zeed"d#ddd$d% Zeed&d'ddd(d) Zed*d+ Zed,d- Zed.d/ Zed0d1 Zed2d3 Zed4d5 Zed6d7 Zed8d9 Zed:d; Zed<d= Zed>d? Z ed@dA Z!edBdC Z"edDdE Z#edFdG Z$edHdI Z%edJdK Z&edLdM Z'edNdO Z(edPdQ Z)edRdS Z*edTdU Z+edVdW Z,edXdY Z-edZd[ Z.ed\d] Z/ed^d_ Z0ed`da Z1edbdc Z2ddS )eAssumptionKeysz@
    This class contains all the supported keys by ``ask``.
    c             C   s   t dS )z
        Hermitian predicate.

        ``ask(Q.hermitian(x))`` is true iff ``x`` belongs to the set of
        Hermitian operators.

        References
        ==========

        .. [1] http://mathworld.wolfram.com/HermitianOperator.html

        	hermitian)r   )self r   4lib/python3.7/site-packages/sympy/assumptions/ask.pyr   $   s    zAssumptionKeys.hermitianc             C   s   t dS )aH  
        Antihermitian predicate.

        ``Q.antihermitian(x)`` is true iff ``x`` belongs to the field of
        antihermitian operators, i.e., operators in the form ``x*I``, where
        ``x`` is Hermitian.

        References
        ==========

        .. [1] http://mathworld.wolfram.com/HermitianOperator.html

        antihermitian)r   )r   r   r   r   r   5   s    zAssumptionKeys.antihermitianc             C   s   t dS )a@  
        Real number predicate.

        ``Q.real(x)`` is true iff ``x`` is a real number, i.e., it is in the
        interval `(-\infty, \infty)`.  Note that, in particular the infinities
        are not real. Use ``Q.extended_real`` if you want to consider those as
        well.

        A few important facts about reals:

        - Every real number is positive, negative, or zero.  Furthermore,
          because these sets are pairwise disjoint, each real number is exactly
          one of those three.

        - Every real number is also complex.

        - Every real number is finite.

        - Every real number is either rational or irrational.

        - Every real number is either algebraic or transcendental.

        - The facts ``Q.negative``, ``Q.zero``, ``Q.positive``,
          ``Q.nonnegative``, ``Q.nonpositive``, ``Q.nonzero``, ``Q.integer``,
          ``Q.rational``, and ``Q.irrational`` all imply ``Q.real``, as do all
          facts that imply those facts.

        - The facts ``Q.algebraic``, and ``Q.transcendental`` do not imply
          ``Q.real``; they imply ``Q.complex``. An algebraic or transcendental
          number may or may not be real.

        - The "non" facts (i.e., ``Q.nonnegative``, ``Q.nonzero``,
          ``Q.nonpositive`` and ``Q.noninteger``) are not equivalent to not the
          fact, but rather, not the fact *and* ``Q.real``.  For example,
          ``Q.nonnegative`` means ``~Q.negative & Q.real``. So for example,
          ``I`` is not nonnegative, nonzero, or nonpositive.

        Examples
        ========

        >>> from sympy import Q, ask, symbols
        >>> x = symbols('x')
        >>> ask(Q.real(x), Q.positive(x))
        True
        >>> ask(Q.real(0))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Real_number

        real)r   )r   r   r   r   r   G   s    7zAssumptionKeys.realc             C   s   t dS )a  
        Extended real predicate.

        ``Q.extended_real(x)`` is true iff ``x`` is a real number or
        `\{-\infty, \infty\}`.

        See documentation of ``Q.real`` for more information about related facts.

        Examples
        ========

        >>> from sympy import ask, Q, oo, I
        >>> ask(Q.extended_real(1))
        True
        >>> ask(Q.extended_real(I))
        False
        >>> ask(Q.extended_real(oo))
        True

        extended_real)r   )r   r   r   r   r      s    zAssumptionKeys.extended_realc             C   s   t dS )a;  
        Imaginary number predicate.

        ``Q.imaginary(x)`` is true iff ``x`` can be written as a real
        number multiplied by the imaginary unit ``I``. Please note that ``0``
        is not considered to be an imaginary number.

        Examples
        ========

        >>> from sympy import Q, ask, I
        >>> ask(Q.imaginary(3*I))
        True
        >>> ask(Q.imaginary(2 + 3*I))
        False
        >>> ask(Q.imaginary(0))
        False

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Imaginary_number

        	imaginary)r   )r   r   r   r   r       s    zAssumptionKeys.imaginaryc             C   s   t dS )a  
        Complex number predicate.

        ``Q.complex(x)`` is true iff ``x`` belongs to the set of complex
        numbers. Note that every complex number is finite.

        Examples
        ========

        >>> from sympy import Q, Symbol, ask, I, oo
        >>> x = Symbol('x')
        >>> ask(Q.complex(0))
        True
        >>> ask(Q.complex(2 + 3*I))
        True
        >>> ask(Q.complex(oo))
        False

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Complex_number

        complex)r   )r   r   r   r   r!      s    zAssumptionKeys.complexc             C   s   t dS )aD  
        Algebraic number predicate.

        ``Q.algebraic(x)`` is true iff ``x`` belongs to the set of
        algebraic numbers. ``x`` is algebraic if there is some polynomial
        in ``p(x)\in \mathbb\{Q\}[x]`` such that ``p(x) = 0``.

        Examples
        ========

        >>> from sympy import ask, Q, sqrt, I, pi
        >>> ask(Q.algebraic(sqrt(2)))
        True
        >>> ask(Q.algebraic(I))
        True
        >>> ask(Q.algebraic(pi))
        False

        References
        ==========

        .. [1] http://en.wikipedia.org/wiki/Algebraic_number
        	algebraic)r   )r   r   r   r   r"      s    zAssumptionKeys.algebraicc             C   s   t dS )z
        Transcedental number predicate.

        ``Q.transcendental(x)`` is true iff ``x`` belongs to the set of
        transcendental numbers. A transcendental number is a real
        or complex number that is not algebraic.

        transcendental)r   )r   r   r   r   r#      s    zAssumptionKeys.transcendentalc             C   s   t dS )a}  
        Integer predicate.

        ``Q.integer(x)`` is true iff ``x`` belongs to the set of integer numbers.

        Examples
        ========

        >>> from sympy import Q, ask, S
        >>> ask(Q.integer(5))
        True
        >>> ask(Q.integer(S(1)/2))
        False

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Integer

        integer)r   )r   r   r   r   r$      s    zAssumptionKeys.integerc             C   s   t dS )a  
        Rational number predicate.

        ``Q.rational(x)`` is true iff ``x`` belongs to the set of
        rational numbers.

        Examples
        ========

        >>> from sympy import ask, Q, pi, S
        >>> ask(Q.rational(0))
        True
        >>> ask(Q.rational(S(1)/2))
        True
        >>> ask(Q.rational(pi))
        False

        References
        ==========

        https://en.wikipedia.org/wiki/Rational_number

        rational)r   )r   r   r   r   r%     s    zAssumptionKeys.rationalc             C   s   t dS )a&  
        Irrational number predicate.

        ``Q.irrational(x)`` is true iff ``x``  is any real number that
        cannot be expressed as a ratio of integers.

        Examples
        ========

        >>> from sympy import ask, Q, pi, S, I
        >>> ask(Q.irrational(0))
        False
        >>> ask(Q.irrational(S(1)/2))
        False
        >>> ask(Q.irrational(pi))
        True
        >>> ask(Q.irrational(I))
        False

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Irrational_number

        
irrational)r   )r   r   r   r   r&   +  s    zAssumptionKeys.irrationalc             C   s   t dS )ah  
        Finite predicate.

        ``Q.finite(x)`` is true if ``x`` is neither an infinity
        nor a ``NaN``. In other words, ``ask(Q.finite(x))`` is true for all ``x``
        having a bounded absolute value.

        Examples
        ========

        >>> from sympy import Q, ask, Symbol, S, oo, I
        >>> x = Symbol('x')
        >>> ask(Q.finite(S.NaN))
        False
        >>> ask(Q.finite(oo))
        False
        >>> ask(Q.finite(1))
        True
        >>> ask(Q.finite(2 + 3*I))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Finite

        finite)r   )r   r   r   r   r'   H  s    zAssumptionKeys.finiter'   i$  z1.0)Z
useinsteadZissueZdeprecated_since_versionc             C   s   t dS )z4
        See documentation of ``Q.finite``.
        r'   )r   )r   r   r   r   r   g  s    zAssumptionKeys.boundedc             C   s   t dS )z
        Infinite number predicate.

        ``Q.infinite(x)`` is true iff the absolute value of ``x`` is
        infinity.

        infinite)r   )r   r   r   r   r(   o  s    
zAssumptionKeys.infiniter(   i$  c             C   s   t dS )z6
        See documentation of ``Q.infinite``.
        r(   )r   )r   r   r   r   r   {  s    zAssumptionKeys.infinityzeroi%  c             C   s   t dS )z2
        See documentation of ``Q.zero``.
        r)   )r   )r   r   r   r   r     s    zAssumptionKeys.infinitesimalc             C   s   t dS )a~  
        Positive real number predicate.

        ``Q.positive(x)`` is true iff ``x`` is real and `x > 0`, that is if ``x``
        is in the interval `(0, \infty)`.  In particular, infinity is not
        positive.

        A few important facts about positive numbers:

        - Note that ``Q.nonpositive`` and ``~Q.positive`` are *not* the same
          thing. ``~Q.positive(x)`` simply means that ``x`` is not positive,
          whereas ``Q.nonpositive(x)`` means that ``x`` is real and not
          positive, i.e., ``Q.nonpositive(x)`` is logically equivalent to
          `Q.negative(x) | Q.zero(x)``.  So for example, ``~Q.positive(I)`` is
          true, whereas ``Q.nonpositive(I)`` is false.

        - See the documentation of ``Q.real`` for more information about
          related facts.

        Examples
        ========

        >>> from sympy import Q, ask, symbols, I
        >>> x = symbols('x')
        >>> ask(Q.positive(x), Q.real(x) & ~Q.negative(x) & ~Q.zero(x))
        True
        >>> ask(Q.positive(1))
        True
        >>> ask(Q.nonpositive(I))
        False
        >>> ask(~Q.positive(I))
        True

        positive)r   )r   r   r   r   r*     s    $zAssumptionKeys.positivec             C   s   t dS )a  
        Negative number predicate.

        ``Q.negative(x)`` is true iff ``x`` is a real number and :math:`x < 0`, that is,
        it is in the interval :math:`(-\infty, 0)`.  Note in particular that negative
        infinity is not negative.

        A few important facts about negative numbers:

        - Note that ``Q.nonnegative`` and ``~Q.negative`` are *not* the same
          thing. ``~Q.negative(x)`` simply means that ``x`` is not negative,
          whereas ``Q.nonnegative(x)`` means that ``x`` is real and not
          negative, i.e., ``Q.nonnegative(x)`` is logically equivalent to
          ``Q.zero(x) | Q.positive(x)``.  So for example, ``~Q.negative(I)`` is
          true, whereas ``Q.nonnegative(I)`` is false.

        - See the documentation of ``Q.real`` for more information about
          related facts.

        Examples
        ========

        >>> from sympy import Q, ask, symbols, I
        >>> x = symbols('x')
        >>> ask(Q.negative(x), Q.real(x) & ~Q.positive(x) & ~Q.zero(x))
        True
        >>> ask(Q.negative(-1))
        True
        >>> ask(Q.nonnegative(I))
        False
        >>> ask(~Q.negative(I))
        True

        negative)r   )r   r   r   r   r+     s    $zAssumptionKeys.negativec             C   s   t dS )a  
        Zero number predicate.

        ``ask(Q.zero(x))`` is true iff the value of ``x`` is zero.

        Examples
        ========

        >>> from sympy import ask, Q, oo, symbols
        >>> x, y = symbols('x, y')
        >>> ask(Q.zero(0))
        True
        >>> ask(Q.zero(1/oo))
        True
        >>> ask(Q.zero(0*oo))
        False
        >>> ask(Q.zero(1))
        False
        >>> ask(Q.zero(x*y), Q.zero(x) | Q.zero(y))
        True

        r)   )r   )r   r   r   r   r)     s    zAssumptionKeys.zeroc             C   s   t dS )a	  
        Nonzero real number predicate.

        ``ask(Q.nonzero(x))`` is true iff ``x`` is real and ``x`` is not zero.  Note in
        particular that ``Q.nonzero(x)`` is false if ``x`` is not real.  Use
        ``~Q.zero(x)`` if you want the negation of being zero without any real
        assumptions.

        A few important facts about nonzero numbers:

        - ``Q.nonzero`` is logically equivalent to ``Q.positive | Q.negative``.

        - See the documentation of ``Q.real`` for more information about
          related facts.

        Examples
        ========

        >>> from sympy import Q, ask, symbols, I, oo
        >>> x = symbols('x')
        >>> print(ask(Q.nonzero(x), ~Q.zero(x)))
        None
        >>> ask(Q.nonzero(x), Q.positive(x))
        True
        >>> ask(Q.nonzero(x), Q.zero(x))
        False
        >>> ask(Q.nonzero(0))
        False
        >>> ask(Q.nonzero(I))
        False
        >>> ask(~Q.zero(I))
        True
        >>> ask(Q.nonzero(oo))  #doctest: +SKIP
        False

        nonzero)r   )r   r   r   r   r,     s    &zAssumptionKeys.nonzeroc             C   s   t dS )a  
        Nonpositive real number predicate.

        ``ask(Q.nonpositive(x))`` is true iff ``x`` belongs to the set of
        negative numbers including zero.

        - Note that ``Q.nonpositive`` and ``~Q.positive`` are *not* the same
          thing. ``~Q.positive(x)`` simply means that ``x`` is not positive,
          whereas ``Q.nonpositive(x)`` means that ``x`` is real and not
          positive, i.e., ``Q.nonpositive(x)`` is logically equivalent to
          `Q.negative(x) | Q.zero(x)``.  So for example, ``~Q.positive(I)`` is
          true, whereas ``Q.nonpositive(I)`` is false.

        Examples
        ========

        >>> from sympy import Q, ask, I
        >>> ask(Q.nonpositive(-1))
        True
        >>> ask(Q.nonpositive(0))
        True
        >>> ask(Q.nonpositive(1))
        False
        >>> ask(Q.nonpositive(I))
        False
        >>> ask(Q.nonpositive(-I))
        False

        nonpositive)r   )r   r   r   r   r-     s    zAssumptionKeys.nonpositivec             C   s   t dS )a  
        Nonnegative real number predicate.

        ``ask(Q.nonnegative(x))`` is true iff ``x`` belongs to the set of
        positive numbers including zero.

        - Note that ``Q.nonnegative`` and ``~Q.negative`` are *not* the same
          thing. ``~Q.negative(x)`` simply means that ``x`` is not negative,
          whereas ``Q.nonnegative(x)`` means that ``x`` is real and not
          negative, i.e., ``Q.nonnegative(x)`` is logically equivalent to
          ``Q.zero(x) | Q.positive(x)``.  So for example, ``~Q.negative(I)`` is
          true, whereas ``Q.nonnegative(I)`` is false.

        Examples
        ========

        >>> from sympy import Q, ask, I
        >>> ask(Q.nonnegative(1))
        True
        >>> ask(Q.nonnegative(0))
        True
        >>> ask(Q.nonnegative(-1))
        False
        >>> ask(Q.nonnegative(I))
        False
        >>> ask(Q.nonnegative(-I))
        False

        nonnegative)r   )r   r   r   r   r.   :  s    zAssumptionKeys.nonnegativec             C   s   t dS )at  
        Even number predicate.

        ``ask(Q.even(x))`` is true iff ``x`` belongs to the set of even
        integers.

        Examples
        ========

        >>> from sympy import Q, ask, pi
        >>> ask(Q.even(0))
        True
        >>> ask(Q.even(2))
        True
        >>> ask(Q.even(3))
        False
        >>> ask(Q.even(pi))
        False

        even)r   )r   r   r   r   r/   [  s    zAssumptionKeys.evenc             C   s   t dS )ae  
        Odd number predicate.

        ``ask(Q.odd(x))`` is true iff ``x`` belongs to the set of odd numbers.

        Examples
        ========

        >>> from sympy import Q, ask, pi
        >>> ask(Q.odd(0))
        False
        >>> ask(Q.odd(2))
        False
        >>> ask(Q.odd(3))
        True
        >>> ask(Q.odd(pi))
        False

        odd)r   )r   r   r   r   r0   s  s    zAssumptionKeys.oddc             C   s   t dS )a  
        Prime number predicate.

        ``ask(Q.prime(x))`` is true iff ``x`` is a natural number greater
        than 1 that has no positive divisors other than ``1`` and the
        number itself.

        Examples
        ========

        >>> from sympy import Q, ask
        >>> ask(Q.prime(0))
        False
        >>> ask(Q.prime(1))
        False
        >>> ask(Q.prime(2))
        True
        >>> ask(Q.prime(20))
        False
        >>> ask(Q.prime(-3))
        False

        prime)r   )r   r   r   r   r1     s    zAssumptionKeys.primec             C   s   t dS )a  
        Composite number predicate.

        ``ask(Q.composite(x))`` is true iff ``x`` is a positive integer and has
        at least one positive divisor other than ``1`` and the number itself.

        Examples
        ========

        >>> from sympy import Q, ask
        >>> ask(Q.composite(0))
        False
        >>> ask(Q.composite(1))
        False
        >>> ask(Q.composite(2))
        False
        >>> ask(Q.composite(20))
        True

        	composite)r   )r   r   r   r   r2     s    zAssumptionKeys.compositec             C   s   t dS )z
        Commutative predicate.

        ``ask(Q.commutative(x))`` is true iff ``x`` commutes with any other
        object with respect to multiplication operation.

        commutative)r   )r   r   r   r   r3     s    
zAssumptionKeys.commutativec             C   s   t dS )a3  
        Generic predicate.

        ``ask(Q.is_true(x))`` is true iff ``x`` is true. This only makes
        sense if ``x`` is a predicate.

        Examples
        ========

        >>> from sympy import ask, Q, symbols
        >>> x = symbols('x')
        >>> ask(Q.is_true(True))
        True

        is_true)r   )r   r   r   r   r4     s    zAssumptionKeys.is_truec             C   s   t dS )a  
        Symmetric matrix predicate.

        ``Q.symmetric(x)`` is true iff ``x`` is a square matrix and is equal to
        its transpose. Every square diagonal matrix is a symmetric matrix.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 2, 2)
        >>> Y = MatrixSymbol('Y', 2, 3)
        >>> Z = MatrixSymbol('Z', 2, 2)
        >>> ask(Q.symmetric(X*Z), Q.symmetric(X) & Q.symmetric(Z))
        True
        >>> ask(Q.symmetric(X + Z), Q.symmetric(X) & Q.symmetric(Z))
        True
        >>> ask(Q.symmetric(Y))
        False


        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Symmetric_matrix

        	symmetric)r   )r   r   r   r   r5     s    zAssumptionKeys.symmetricc             C   s   t dS )a  
        Invertible matrix predicate.

        ``Q.invertible(x)`` is true iff ``x`` is an invertible matrix.
        A square matrix is called invertible only if its determinant is 0.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 2, 2)
        >>> Y = MatrixSymbol('Y', 2, 3)
        >>> Z = MatrixSymbol('Z', 2, 2)
        >>> ask(Q.invertible(X*Y), Q.invertible(X))
        False
        >>> ask(Q.invertible(X*Z), Q.invertible(X) & Q.invertible(Z))
        True
        >>> ask(Q.invertible(X), Q.fullrank(X) & Q.square(X))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Invertible_matrix

        
invertible)r   )r   r   r   r   r6     s    zAssumptionKeys.invertiblec             C   s   t dS )a  
        Orthogonal matrix predicate.

        ``Q.orthogonal(x)`` is true iff ``x`` is an orthogonal matrix.
        A square matrix ``M`` is an orthogonal matrix if it satisfies
        ``M^TM = MM^T = I`` where ``M^T`` is the transpose matrix of
        ``M`` and ``I`` is an identity matrix. Note that an orthogonal
        matrix is necessarily invertible.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol, Identity
        >>> X = MatrixSymbol('X', 2, 2)
        >>> Y = MatrixSymbol('Y', 2, 3)
        >>> Z = MatrixSymbol('Z', 2, 2)
        >>> ask(Q.orthogonal(Y))
        False
        >>> ask(Q.orthogonal(X*Z*X), Q.orthogonal(X) & Q.orthogonal(Z))
        True
        >>> ask(Q.orthogonal(Identity(3)))
        True
        >>> ask(Q.invertible(X), Q.orthogonal(X))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Orthogonal_matrix

        
orthogonal)r   )r   r   r   r   r7     s    !zAssumptionKeys.orthogonalc             C   s   t dS )a6  
        Unitary matrix predicate.

        ``Q.unitary(x)`` is true iff ``x`` is a unitary matrix.
        Unitary matrix is an analogue to orthogonal matrix. A square
        matrix ``M`` with complex elements is unitary if :math:``M^TM = MM^T= I``
        where :math:``M^T`` is the conjugate transpose matrix of ``M``.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol, Identity
        >>> X = MatrixSymbol('X', 2, 2)
        >>> Y = MatrixSymbol('Y', 2, 3)
        >>> Z = MatrixSymbol('Z', 2, 2)
        >>> ask(Q.unitary(Y))
        False
        >>> ask(Q.unitary(X*Z*X), Q.unitary(X) & Q.unitary(Z))
        True
        >>> ask(Q.unitary(Identity(3)))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Unitary_matrix

        unitary)r   )r   r   r   r   r8   >  s    zAssumptionKeys.unitaryc             C   s   t dS )a=  
        Positive definite matrix predicate.

        If ``M`` is a :math:``n \times n`` symmetric real matrix, it is said
        to be positive definite if :math:`Z^TMZ` is positive for
        every non-zero column vector ``Z`` of ``n`` real numbers.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol, Identity
        >>> X = MatrixSymbol('X', 2, 2)
        >>> Y = MatrixSymbol('Y', 2, 3)
        >>> Z = MatrixSymbol('Z', 2, 2)
        >>> ask(Q.positive_definite(Y))
        False
        >>> ask(Q.positive_definite(Identity(3)))
        True
        >>> ask(Q.positive_definite(X + Z), Q.positive_definite(X) &
        ...     Q.positive_definite(Z))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Positive-definite_matrix

        positive_definite)r   )r   r   r   r   r9   ^  s    z AssumptionKeys.positive_definitec             C   s   t dS )a  
        Upper triangular matrix predicate.

        A matrix ``M`` is called upper triangular matrix if :math:`M_{ij}=0`
        for :math:`i<j`.

        Examples
        ========

        >>> from sympy import Q, ask, ZeroMatrix, Identity
        >>> ask(Q.upper_triangular(Identity(3)))
        True
        >>> ask(Q.upper_triangular(ZeroMatrix(3, 3)))
        True

        References
        ==========

        .. [1] http://mathworld.wolfram.com/UpperTriangularMatrix.html

        upper_triangular)r   )r   r   r   r   r:   ~  s    zAssumptionKeys.upper_triangularc             C   s   t dS )a  
        Lower triangular matrix predicate.

        A matrix ``M`` is called lower triangular matrix if :math:`a_{ij}=0`
        for :math:`i>j`.

        Examples
        ========

        >>> from sympy import Q, ask, ZeroMatrix, Identity
        >>> ask(Q.lower_triangular(Identity(3)))
        True
        >>> ask(Q.lower_triangular(ZeroMatrix(3, 3)))
        True

        References
        ==========

        .. [1] http://mathworld.wolfram.com/LowerTriangularMatrix.html
        lower_triangular)r   )r   r   r   r   r;     s    zAssumptionKeys.lower_triangularc             C   s   t dS )aq  
        Diagonal matrix predicate.

        ``Q.diagonal(x)`` is true iff ``x`` is a diagonal matrix. A diagonal
        matrix is a matrix in which the entries outside the main diagonal
        are all zero.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol, ZeroMatrix
        >>> X = MatrixSymbol('X', 2, 2)
        >>> ask(Q.diagonal(ZeroMatrix(3, 3)))
        True
        >>> ask(Q.diagonal(X), Q.lower_triangular(X) &
        ...     Q.upper_triangular(X))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Diagonal_matrix

        diagonal)r   )r   r   r   r   r<     s    zAssumptionKeys.diagonalc             C   s   t dS )a`  
        Fullrank matrix predicate.

        ``Q.fullrank(x)`` is true iff ``x`` is a full rank matrix.
        A matrix is full rank if all rows and columns of the matrix
        are linearly independent. A square matrix is full rank iff
        its determinant is nonzero.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol, ZeroMatrix, Identity
        >>> X = MatrixSymbol('X', 2, 2)
        >>> ask(Q.fullrank(X.T), Q.fullrank(X))
        True
        >>> ask(Q.fullrank(ZeroMatrix(3, 3)))
        False
        >>> ask(Q.fullrank(Identity(3)))
        True

        fullrank)r   )r   r   r   r   r=     s    zAssumptionKeys.fullrankc             C   s   t dS )a  
        Square matrix predicate.

        ``Q.square(x)`` is true iff ``x`` is a square matrix. A square matrix
        is a matrix with the same number of rows and columns.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol, ZeroMatrix, Identity
        >>> X = MatrixSymbol('X', 2, 2)
        >>> Y = MatrixSymbol('X', 2, 3)
        >>> ask(Q.square(X))
        True
        >>> ask(Q.square(Y))
        False
        >>> ask(Q.square(ZeroMatrix(3, 3)))
        True
        >>> ask(Q.square(Identity(3)))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Square_matrix

        square)r   )r   r   r   r   r>     s    zAssumptionKeys.squarec             C   s   t dS )a[  
        Integer elements matrix predicate.

        ``Q.integer_elements(x)`` is true iff all the elements of ``x``
        are integers.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 4, 4)
        >>> ask(Q.integer(X[1, 2]), Q.integer_elements(X))
        True

        integer_elements)r   )r   r   r   r   r?     s    zAssumptionKeys.integer_elementsc             C   s   t dS )aS  
        Real elements matrix predicate.

        ``Q.real_elements(x)`` is true iff all the elements of ``x``
        are real numbers.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 4, 4)
        >>> ask(Q.real(X[1, 2]), Q.real_elements(X))
        True

        real_elements)r   )r   r   r   r   r@     s    zAssumptionKeys.real_elementsc             C   s   t dS )a  
        Complex elements matrix predicate.

        ``Q.complex_elements(x)`` is true iff all the elements of ``x``
        are complex numbers.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 4, 4)
        >>> ask(Q.complex(X[1, 2]), Q.complex_elements(X))
        True
        >>> ask(Q.complex_elements(X), Q.integer_elements(X))
        True

        complex_elements)r   )r   r   r   r   rA   )  s    zAssumptionKeys.complex_elementsc             C   s   t dS )a  
        Singular matrix predicate.

        A matrix is singular iff the value of its determinant is 0.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 4, 4)
        >>> ask(Q.singular(X), Q.invertible(X))
        False
        >>> ask(Q.singular(X), ~Q.invertible(X))
        True

        References
        ==========

        .. [1] http://mathworld.wolfram.com/SingularMatrix.html

        singular)r   )r   r   r   r   rB   >  s    zAssumptionKeys.singularc             C   s   t dS )a  
        Normal matrix predicate.

        A matrix is normal if it commutes with its conjugate transpose.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 4, 4)
        >>> ask(Q.normal(X), Q.unitary(X))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Normal_matrix

        normal)r   )r   r   r   r   rC   W  s    zAssumptionKeys.normalc             C   s   t dS )a  
        Triangular matrix predicate.

        ``Q.triangular(X)`` is true if ``X`` is one that is either lower
        triangular or upper triangular.

        Examples
        ========
        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 4, 4)
        >>> ask(Q.triangular(X), Q.upper_triangular(X))
        True
        >>> ask(Q.triangular(X), Q.lower_triangular(X))
        True

        References
        ==========

        .. [1] https://en.wikipedia.org/wiki/Triangular_matrix

        
triangular)r   )r   r   r   r   rD   n  s    zAssumptionKeys.triangularc             C   s   t dS )aQ  
        Unit triangular matrix predicate.

        A unit triangular matrix is a triangular matrix with 1s
        on the diagonal.

        Examples
        ========

        >>> from sympy import Q, ask, MatrixSymbol
        >>> X = MatrixSymbol('X', 4, 4)
        >>> ask(Q.triangular(X), Q.unit_triangular(X))
        True

        unit_triangular)r   )r   r   r   r   rE     s    zAssumptionKeys.unit_triangularN)3__name__
__module____qualname____doc__predicate_memor   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r   r   r(   r   r   r*   r+   r)   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   r   r   r   r   r      sb   9&&(!!!#  r   Tc                s  t  tr(|r(t|  jd}|dk	r(|S t | tr6dS |  sDdS t | trb| j kr^| jS dS t | t	r| j
d jttfkr| j
d tkrtnt}|dd | j
d j
D  }  fdd| j
D }t | trdd |D }|r| j| S |rtdd	 |D r| j| S dS )
z
    Helper for ask().

    Extracts the facts relevant to the symbol from an assumption.
    Returns None if there is nothing to extract.
    FNr   c             S   s   g | ]
}| qS r   r   ).0argr   r   r   
<listcomp>  s    z"_extract_facts.<locals>.<listcomp>c                s   g | ]}t | qS r   )_extract_facts)rK   rL   )symbolr   r   rM     s    c             S   s   g | ]}|d k	r|qS )Nr   )rK   xr   r   r   rM     s    c             s   s   | ]}|d kV  qd S )Nr   )rK   rP   r   r   r   	<genexpr>  s    z!_extract_facts.<locals>.<genexpr>)
isinstancer   rN   reversedboolZhasr   rL   funcr	   argsr   r
   all)exprrO   Zcheck_reversed_relZrevclsrV   r   )rO   r   rN     s.    






rN   c       
         s6  ddl m} t| ttttfs&tdt|ttttfs@tdt| tr^| jt	| j
 }}ntjt	|  }}t|t| }t|}t||}t }t  |rtt||dkrtd| |||}|dk	rt|S |dkr|| ||dS |jr"| | kr
d	S t| | krdS nt|trt fd
d|jD rx|jD ]z}	|	jr| |	 krnd	S t| |	 krdS nBt|	trP|	jd jrP| |	 krdS t| |	 krPd	S qPW n>t|trt|tr|jd jr|jd  | krdS t|||}|dkr2|| ||dS |S )a  
    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(4*x), Q.integer(x))
    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)) # doctest: +SKIP

        It is however a work in progress.

    r   )sataskz.proposition must be a valid logical expressionz.assumptions must be a valid logical expressionFzinconsistent assumptions %sN)assumptionscontextTc             3   s   | ]}| kV  qd S )Nr   )rK   k)known_facts_dictr   r   rQ     s    zask.<locals>.<genexpr>)Zsympy.assumptions.sataskrZ   rR   r   r   rT   r   	TypeErrorrU   r   rL   Qr4   r   r   rN   get_known_facts_cnfget_known_facts_dictr   
ValueErrorZ	_eval_askZis_Atomr	   rW   rV   r   ask_full_inference)
propositionr[   r\   rZ   keyrX   Zlocal_factsknown_facts_cnfZresZassumr   )r^   r   ask  s\    !


rh   c             C   s0   t t||| sdS t t||t| s,dS dS )z9
    Method for inferring properties about objects.

    FTN)r   r   r	   )re   r[   rg   r   r   r   rd     s
    rd   c          
   C   sV   t | tkr| j} ytt| | W n* tk
rP   tt| t| |gd Y nX dS )a  
    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):
        ...         from sympy import log
        ...         return ask(Q.integer(log(expr + 1, 2)))
        >>> register_handler('mersenne', MersenneHandler)
        >>> ask(Q.mersenne(7))
        True

    )ZhandlersN)typer   namegetattrr`   Zadd_handlerAttributeErrorsetattr)rf   handlerr   r   r   register_handler+  s    ro   c             C   s&   t | tkr| j} tt| | dS )zFRemoves a handler from the ask system. Same syntax as register_handlerN)ri   r   rj   rk   r`   remove_handler)rf   rn   r   r   r   rp   E  s    rp   c             C   sP   i }xF| D ]>}|h||< x.| D ]&}||krt |||r|| | qW q
W |S )N)rd   add)known_facts_keysrg   mappingrf   Z	other_keyr   r   r   single_fact_lookupL  s    


rt   c                s   ddl m}m |d}d}d t| }|dd |jD }t||}t| t	d}d	d |D }	d
d |D }
| fddt
|	|
D d }|||f S )a   Compute the various forms of knowledge compilation used by the
    assumptions system.

    This function is typically applied to the results of the ``get_known_facts``
    and ``get_known_facts_keys`` functions defined at the bottom of
    this file.
    r   )dedentwrapa[      """
    The contents of this file are the return value of
    ``sympy.assumptions.ask.compute_known_facts``.

    Do NOT manually edit this file.
    Instead, run ./bin/ask_update.py.
    """

    from sympy.core.cache import cacheit
    from sympy.logic.boolalg import And, Not, Or
    from sympy.assumptions.ask import Q

    # -{ Known facts in Conjunctive Normal Form }-
    @cacheit
    def get_known_facts_cnf():
        return And(
            %s
        )

    # -{ Known facts in compressed sets }-
    @cacheit
    def get_known_facts_dict():
        return {
            %s
        }
    z
,
        z        c             S   s   g | ]}t |qS r   )str)rK   ar   r   r   rM     s    z'compute_known_facts.<locals>.<listcomp>)rf   c             S   s   g | ]}t |d  qS )r   )rw   )rK   ir   r   r   rM     s    c             S   s    g | ]}d t |d td qS )zset(%s)   )rf   )sortedrw   )rK   ry   r   r   r   rM     s    c          	      s,   g | ]$\}}d  d||f  ddqS )
z%s: %sF)Zsubsequent_indentZbreak_long_words)join)rK   r]   v)HANGrv   r   r   rM     s   ,)textwrapru   rv   r   r}   rV   rt   r{   itemsrw   zip)Zknown_factsrr   ru   Zfact_stringZLINEZcnfcrs   r   keysvaluesmr   )r   rv   r   compute_known_factsX  s    
r   zsympy.assumptions.handlers.%s)r   zsets.AskAntiHermitianHandler)r'   zcalculus.AskFiniteHandler)r3   ZAskCommutativeHandler)r!   zsets.AskComplexHandler)r2   zntheory.AskCompositeHandler)r/   zntheory.AskEvenHandler)r   zsets.AskExtendedRealHandler)r   zsets.AskHermitianHandler)r    zsets.AskImaginaryHandler)r$   zsets.AskIntegerHandler)r&   zsets.AskIrrationalHandler)r%   zsets.AskRationalHandler)r+   zorder.AskNegativeHandler)r,   zorder.AskNonZeroHandler)r-   zorder.AskNonPositiveHandler)r.   zorder.AskNonNegativeHandler)r)   zorder.AskZeroHandler)r*   zorder.AskPositiveHandler)r1   zntheory.AskPrimeHandler)r   zsets.AskRealHandler)r0   zntheory.AskOddHandler)r"   zsets.AskAlgebraicHandler)r4   zcommon.TautologicalHandler)r5   zmatrices.AskSymmetricHandler)r6   zmatrices.AskInvertibleHandler)r7   zmatrices.AskOrthogonalHandler)r8   zmatrices.AskUnitaryHandler)r9   z#matrices.AskPositiveDefiniteHandler)r:   z"matrices.AskUpperTriangularHandler)r;   z"matrices.AskLowerTriangularHandler)r<   zmatrices.AskDiagonalHandler)r=   zmatrices.AskFullRankHandler)r>   zmatrices.AskSquareHandler)r?   z"matrices.AskIntegerElementsHandler)r@   zmatrices.AskRealElementsHandler)rA   z"matrices.AskComplexElementsHandlerc               C   s   dd t jjD S )Nc             S   s(   g | ] }| d s|tkstt|qS )__)
startswithdeprecated_predicatesrk   r`   )rK   attrr   r   r   rM     s   
z(get_known_facts_keys.<locals>.<listcomp>)r`   	__class____dict__r   r   r   r   get_known_facts_keys  s    r   c            2   C   s  t ttjtj ttjtjttjtjttj	tjtjB ttj
tjB tjttj
tj ttjtjtj@ tj @ ttjtjttjtjttjtjttjtjB tjttjtj ttjtjtj @ ttjtjttjtj ttjtjB tjttjtj ttjtj
ttjtjtjB tjB ttjtj tj @ ttjtj ttjtjtjB ttjtjtjB ttjtjtjB ttjtjttjtjttjtj@ tjttjtjttjtjttjtj ttj!tjttjtjttj!tj"ttj!tj#ttj#tj$ttj"tj$ttj$tj"tj#B ttj"tj#@ tj!ttj!tj%ttj&tj$ttjtj'ttjtj ttj%tj ttj'tj @ tjttjtj( ttj)tj*ttj*tj+/S )N),r   r   r`   r(   r'   r   r!   r   r   r   r/   r0   r$   r1   r*   r2   r%   r"   r#   r    r   r&   r)   r+   r.   r-   r,   r7   r9   r8   rC   r6   r>   r<   r:   r;   rD   r5   rE   r=   rB   r?   r@   rA   r   r   r   r   get_known_facts  s`    r   )rb   ra   N)T)3rI   Z
__future__r   r   Z
sympy.corer   Zsympy.core.cacher   Zsympy.core.relationalr   Zsympy.logic.boolalgr   r   r	   r
   r   r   r   r   Zsympy.logic.inferencer   Zsympy.assumptions.assumer   r   r   Zsympy.core.decoratorsr   Zsympy.utilities.decoratorr   r   Zpredicate_storagerJ   objectr   r`   rN   rh   rd   ro   rp   rt   r   Z_val_templateZ	_handlersrj   valuer   r   Zsympy.assumptions.ask_generatedrb   ra   r   r   r   r   <module>   s   (         
!a76