ó
~9­\c           @  s2  d  Z  d d l m Z m Z d d l m Z m Z d d l m Z d d l	 m
 Z
 d d l m Z e d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! g ƒ Z e j j ƒ  Z e j d" ƒ e e ƒ Z d# e f d$ „  ƒ  YZ d% „  Z d& „  Z d' „  Z d( e f d) „  ƒ  YZ d* S(+   s&  
This module contains the machinery handling assumptions.

All symbolic objects have assumption attributes that can be accessed via
.is_<assumption name> attribute.

Assumptions determine certain properties of symbolic objects and can
have 3 possible values: True, False, None.  True is returned if the
object has the property and False is returned if it doesn't or can't
(i.e. doesn't make sense):

    >>> from sympy import I
    >>> I.is_algebraic
    True
    >>> I.is_real
    False
    >>> I.is_prime
    False

When the property cannot be determined (or when a method is not
implemented) None will be returned, e.g. a generic symbol, x, may or
may not be positive so a value of None is returned for x.is_positive.

By default, all symbolic values are in the largest set in the given context
without specifying the property. For example, a symbol that has a property
being integer, is also real, complex, etc.

Here follows a list of possible assumption names:

.. glossary::

    commutative
        object commutes with any other object with
        respect to multiplication operation.

    complex
        object can have only values from the set
        of complex numbers.

    imaginary
        object value is a number that can be written as a real
        number multiplied by the imaginary unit ``I``.  See
        [3]_.  Please note, that ``0`` is not considered to be an
        imaginary number, see
        `issue #7649 <https://github.com/sympy/sympy/issues/7649>`_.

    real
        object can have only values from the set
        of real numbers.

    integer
        object can have only values from the set
        of integers.

    odd
    even
        object can have only values from the set of
        odd (even) integers [2]_.

    prime
        object is a natural number greater than ``1`` that has
        no positive divisors other than ``1`` and itself.  See [6]_.

    composite
        object is a positive integer that has at least one positive
        divisor other than ``1`` or the number itself.  See [4]_.

    zero
        object has the value of ``0``.

    nonzero
        object is a real number that is not zero.

    rational
        object can have only values from the set
        of rationals.

    algebraic
        object can have only values from the set
        of algebraic numbers [11]_.

    transcendental
        object can have only values from the set
        of transcendental numbers [10]_.

    irrational
        object value cannot be represented exactly by Rational, see [5]_.

    finite
    infinite
        object absolute value is bounded (arbitrarily large).
        See [7]_, [8]_, [9]_.

    negative
    nonnegative
        object can have only negative (nonnegative)
        values [1]_.

    positive
    nonpositive
        object can have only positive (only
        nonpositive) values.

    hermitian
    antihermitian
        object belongs to the field of hermitian
        (antihermitian) operators.

Examples
========

    >>> from sympy import Symbol
    >>> x = Symbol('x', real=True); x
    x
    >>> x.is_real
    True
    >>> x.is_complex
    True

See Also
========

.. seealso::

    :py:class:`sympy.core.numbers.ImaginaryUnit`
    :py:class:`sympy.core.numbers.Zero`
    :py:class:`sympy.core.numbers.One`

Notes
=====

Assumption values are stored in obj._assumptions dictionary or
are returned by getter methods (with property decorators) or are
attributes of objects/classes.


References
==========

.. [1] https://en.wikipedia.org/wiki/Negative_number
.. [2] https://en.wikipedia.org/wiki/Parity_%28mathematics%29
.. [3] https://en.wikipedia.org/wiki/Imaginary_number
.. [4] https://en.wikipedia.org/wiki/Composite_number
.. [5] https://en.wikipedia.org/wiki/Irrational_number
.. [6] https://en.wikipedia.org/wiki/Prime_number
.. [7] https://en.wikipedia.org/wiki/Finite
.. [8] https://docs.python.org/3/library/math.html#math.isfinite
.. [9] http://docs.scipy.org/doc/numpy/reference/generated/numpy.isfinite.html
.. [10] https://en.wikipedia.org/wiki/Transcendental_number
.. [11] https://en.wikipedia.org/wiki/Algebraic_number

iÿÿÿÿ(   t   print_functiont   division(   t	   FactRulest   FactKB(   t	   BasicMeta(   t   integer_types(   t   shuffles   integer        ->  rationals   rational       ->  reals   rational       ->  algebraics   algebraic      ->  complexs   real           ->  complexs   real           ->  hermitians   imaginary      ->  complexs    imaginary      ->  antihermitians   complex        ->  commutatives"   odd            ==  integer & !evens!   even           ==  integer & !odds-   real           ==  negative | zero | positives'   transcendental ==  complex & !algebraics(   negative       ==  nonpositive & nonzeros(   positive       ==  nonnegative & nonzeros,   zero           ==  nonnegative & nonpositives#   nonpositive    ==  real & !positives#   nonnegative    ==  real & !negatives    zero           ->  even & finites%   prime          ->  integer & positives.   composite      ->  integer & positive & !primes,   !composite     ->  !positive | !even | primes#   irrational     ==  real & !rationals   imaginary      ->  !reals   infinite       ->  !finites"   noninteger     ==  real & !integers   nonzero        ==  real & !zerot   polart	   StdFactKBc           B  s8   e  Z d  Z e Z d d „ Z d „  Z e d „  ƒ Z	 RS(   st   A FactKB specialised for the built-in rules

    This is the only kind of FactKB that Basic objects should use.
    c         C  sY   | s i  |  _  n- t | t ƒ s3 | j ƒ  |  _  n | j |  _  | rU |  j | ƒ n  d  S(   N(   t
   _generatort
   isinstanceR   t   copyt	   generatort   deduce_all_facts(   t   selft   facts(    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyt   __init__×   s    c         C  s   |  j  |  ƒ S(   N(   t	   __class__(   R   (    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyR   â   s    c         C  s   |  j  j ƒ  S(   N(   R	   R   (   R   (    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyR   å   s    N(
   t   __name__t
   __module__t   __doc__t   _assume_rulest   rulest   NoneR   R   t   propertyR   (    (    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyR   Ð   s
   	c         C  s   d |  S(   s=   Convert a fact name to the name of the corresponding propertys   is_%s(    (   t   fact(    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyt   as_propertyê   s    c           s(   ‡  f d †  } t  ˆ  ƒ | _ t | ƒ S(   s6   Create the automagic property corresponding to a fact.c           sX   y |  j  ˆ  SWnB t k
 rS |  j  |  j k rF |  j j ƒ  |  _  n  t ˆ  |  ƒ SXd  S(   N(   t   _assumptionst   KeyErrort   default_assumptionsR   t   _ask(   R   (   R   (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyt   getitò   s    (   R   t	   func_nameR   (   R   R   (    (   R   s5   lib/python2.7/site-packages/sympy/core/assumptions.pyt   make_propertyï   s    c   	      C  sõ   | j  } | j } | j |  d ƒ y | |  } Wn t k
 rC n3 X| | ƒ } | d k	 rv | j |  | f f ƒ | St t j |  ƒ } t	 | ƒ x[ | D]S } | | k r² qš n  | | k rš t
 | | ƒ | j |  ƒ } | d k	 rí | Sqš qš Wd S(   s£  
    Find the truth value for a property of an object.

    This function is called when a request is made to see what a fact
    value is.

    For this we use several techniques:

    First, the fact-evaluation function is tried, if it exists (for
    example _eval_is_integer). Then we try related facts. For example

        rational   -->   integer

    another example is joined rule:

        integer & !odd  --> even

    so in the latter case if we are looking at what 'even' value is,
    'integer' and 'odd' facts will be asked.

    In all cases, when we settle on some fact value, its implications are
    deduced, and the result is cached in ._assumptions.
    N(   R   t   _prop_handlert   _tellR   R   R   t   listR   t   prereqR   R   t   get(	   R   t   objt   assumptionst   handler_mapt   evaluatet   aR%   t   pkt   ret_val(    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyR   þ   s,    		
t   ManagedPropertiesc           B  s   e  Z d  Z d „  Z RS(   s0   Metaclass for classes with old-style assumptionsc         O  sl  t  j |  | | Ž i  } xu t D]m } t | ƒ } |  j j | d ƒ } t | t t t	 d  ƒ f ƒ r  | d  k	 r€ t | ƒ } n  | | | <q  q  Wi  } xE t |  j ƒ D]4 } t | d d  ƒ }	 |	 d  k	 r§ | j |	 ƒ q§ q§ W| j | ƒ | |  _ t | ƒ |  _ i  |  _ x@ t D]8 } t |  d | d  ƒ }
 |
 d  k	 r|
 |  j | <qqWx3 |  j j ƒ  D]" \ } } t |  t | ƒ | ƒ q`Wt ƒ  } x? |  j D]4 } t | d d  ƒ } | d  k	 r™| j | ƒ q™q™WxO | t |  j ƒ D]: } t | ƒ } | |  j k råt |  | t | ƒ ƒ qåqåWxB t D]: } t | ƒ } t |  | ƒ s*t |  | t | ƒ ƒ q*q*Wd  S(   Nt    t   _explicit_class_assumptionss   _eval_is_%sR   (   R   R   t   _assume_definedR   t   __dict__R&   R
   t   boolR   t   typeR   t   reversedt	   __bases__t   getattrt   updateR0   R   R   R"   t   itemst   setattrt   setR!   t   hasattr(   t   clst   argst   kwst
   local_defst   kt   attrnamet   vt   defst   baseR(   t   eval_is_metht   derived_from_basesR   R   t   pname(    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyR   <  sJ    			(   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyR.   :  s   N(   R   t
   __future__R    R   t   sympy.core.factsR   R   t   sympy.core.coreR   t   sympy.core.compatibilityR   t   randomR   R   t   defined_factsR   R1   t   addt	   frozensetR   R   R!   R   R.   (    (    (    s5   lib/python2.7/site-packages/sympy/core/assumptions.pyt   <module>˜   sR   			<