ó
¡¼™\c           @  s  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
 d  d l m Z d  d l m 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 m Z m Z m Z d  d l m Z d  d l m Z d e f d „  ƒ  YZ  d S(   iÿÿÿÿ(   t   print_functiont   division(   t   S(   t   Basic(   t   Tuple(   t   Expr(   t   Lambda(   t
   fuzzy_bool(   t   Symbolt   Dummy(   t   Andt
   as_Boolean(   t   Contains(   t   Sett   EmptySett   Uniont	   FiniteSet(   t   sift(   t
   filldedentt   ConditionSetc           B  sw   e  Z d  Z e j d „ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 d „  Z d „  Z d	 d „ Z RS(
   s  
    Set of elements which satisfies a given condition.

    {x | condition(x) is True for x in S}

    Examples
    ========

    >>> from sympy import Symbol, S, ConditionSet, pi, Eq, sin, Interval
    >>> from sympy.abc import x, y, z

    >>> sin_sols = ConditionSet(x, Eq(sin(x), 0), Interval(0, 2*pi))
    >>> 2*pi in sin_sols
    True
    >>> pi/2 in sin_sols
    False
    >>> 3*pi in sin_sols
    False
    >>> 5 in ConditionSet(x, x**2 > 4, S.Reals)
    True

    If the value is not in the base set, the result is false:

    >>> 5 in ConditionSet(x, x**2 > 4, Interval(2, 4))
    False

    Notes
    =====

    Symbols with assumptions should be avoided or else the
    condition may evaluate without consideration of the set:

    >>> n = Symbol('n', negative=True)
    >>> cond = (n > 0); cond
    False
    >>> ConditionSet(n, cond, S.Integers)
    EmptySet()

    In addition, substitution of a dummy symbol can only be
    done with a generic symbol with matching commutativity
    or else a symbol that has identical assumptions. If the
    base set contains the dummy symbol it is logically distinct
    and will be the target of substitution.

    >>> c = ConditionSet(x, x < 1, {x, z})
    >>> c.subs(x, y)
    ConditionSet(x, x < 1, {y, z})

    A second substitution is needed to change the dummy symbol, too:

    >>> _.subs(x, y)
    ConditionSet(y, y < 1, {y, z})

    And trying to replace the dummy symbol with anything but a symbol
    is ignored: the only change possible will be in the base set:

    >>> ConditionSet(y, y < 1, {y, z}).subs(y, 1)
    ConditionSet(y, y < 1, {z})
    >>> _.subs(y, 1)
    ConditionSet(y, y < 1, {z})

    Notes
    =====

    If no base set is specified, the universal set is implied:

    >>> ConditionSet(x, x < 1).base_set
    UniversalSet()

    Although expressions other than symbols may be used, this
    is discouraged and will raise an error if the expression
    is not found in the condition:

    >>> ConditionSet(x + 1, x + 1 < 1, S.Integers)
    ConditionSet(x + 1, x + 1 < 1, Integers)

    >>> ConditionSet(x + 1, x < 1, S.Integers)
    Traceback (most recent call last):
    ...
    ValueError: non-symbol dummy not recognized in condition

    Although the name is usually respected, it must be replaced if
    the base set is another ConditionSet and the dummy symbol
    and appears as a free symbol in the base set and the dummy symbol
    of the base set appears as a free symbol in the condition:

    >>> ConditionSet(x, x < y, ConditionSet(y, x + y < 2, S.Integers))
    ConditionSet(lambda, (lambda < y) & (lambda + x < 2), Integers)

    The best way to do anything with the dummy symbol is to access
    it with the sym property.

    >>> _.subs(_.sym, Symbol('_x'))
    ConditionSet(_x, (_x < y) & (_x + x < 2), Integers)
    c   
        sÔ  t  ˆ t t f ƒ rC t ˆ Œ  ‰ t ˆ  Œ  ‰  t j |  ˆ ˆ  | ƒ St ˆ  ƒ ‰  t  | t ƒ rm t | Œ  } n t  | t ƒ s‹ t	 d ƒ ‚ n  ˆ  t
 j k r¡ t
 j Sˆ  t
 j k r´ | St  | t ƒ rÇ | Sd  } t  | t ƒ r5t | ‡  ‡ f d †  ƒ } | d  r$t | t Œ  } t | d  Œ  } q5t | t Œ  Sn  t  | |  ƒ rS| j \ } } } ˆ | k rtt ˆ  | ƒ ‰  qSˆ | j k r¥t ˆ  | j i ˆ | 6ƒ ƒ ‰  qS| ˆ  j k rÜt ˆ  j i | ˆ 6ƒ | ƒ ‰  | ‰ qSt d ƒ } | ˆ  j k s| | j k rt t | ƒ ƒ } n  t ˆ  j i | ˆ 6ƒ | j i | | 6ƒ ƒ ‰  | ‰ n  t  ˆ t ƒ sŸt d ƒ } | ˆ  j i | ˆ 6ƒ j k rŸt d ƒ ‚ qŸn  t j |  ˆ ˆ  | ƒ }	 | d  k rÇ|	 St | |	 ƒ S(   Ns   expecting set for base_setc           s   t  ˆ  j ˆ |  ƒ ƒ S(   N(   R   t   subs(   t   _(   t	   conditiont   sym(    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyt   <lambda>‡   s   t   lambdas,   non-symbol dummy not recognized in condition(   t
   isinstanceR   t   tupleR   R   t   __new__R   t   setR   t	   TypeErrorR   t   falseR   t   truet   NoneR   t   Truet   argsR
   t   free_symbolst   xreplaceR   R	   t   strt
   ValueErrorR   (
   t   clsR   R   t   base_sett   knowt   siftedt   st   ct   dumt   rv(    (   R   R   s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyR   q   s^    
"		c         C  s   |  j  d S(   Ni    (   R#   (   t   self(    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyR   ©   t    c         C  s   |  j  d S(   Ni   (   R#   (   R0   (    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyR   ª   R1   c         C  s   |  j  d S(   Ni   (   R#   (   R0   (    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyR   «   R1   c         C  s'   |  j  \ } } } | j | j | j BS(   N(   R#   R$   (   R0   R,   R-   t   b(    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyR$   ­   s    c         C  s.   t  t |  j |  j ƒ | ƒ |  j j | ƒ ƒ S(   N(   R
   R   R   R   R)   t   contains(   R0   t   other(    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyR3   ²   s    c         C  sb  t  |  j t ƒ s |  S|  j \ } } } | | k rú | j | | ƒ } t  | t ƒ rç | j | j k sŽ t | j ƒ d k rÒ | j | j k rÒ | |  j	 k r° |  j
 | | | ƒ S|  j
 | | j | | ƒ | ƒ Sn  t t d ƒ ƒ ‚ n  |  j
 | | | ƒ S|  j j | | ƒ } |  j	 j | | ƒ } | t j k rLt | t | | ƒ | ƒ S|  j
 |  j | | ƒ S(   Ni   sð   
                    A dummy symbol can only be
                    replaced with a symbol having the same
                    assumptions or one having a single assumption
                    having the same commutativity.
                (   R   R   R   R#   R   R   t   assumptions0t   lent   is_commutativeR)   t   funcR'   R   R   R   R    R   R   (   R0   t   oldt   newR   t   condt   base(    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyt
   _eval_subs¶   s(    "c         C  sº   t  | |  j ƒ s t St  |  j t ƒ t  | j t ƒ k r> t S| rS t d ƒ ‚ n  | } t  |  j t ƒ r° t  | j t ƒ r° | j |  j | j j | j |  j ƒ | j ƒ } n  |  | k S(   Ns)   symbol arg not supported for ConditionSet(	   R   R8   t   FalseR   R   R'   R   R   R)   (   R0   R4   t   symbolt   o(    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyt   dummy_eqß   s    $$N(   t   __name__t
   __module__t   __doc__R   t   UniversalSetR   t   propertyR   R   R)   R$   R3   R=   R!   RA   (    (    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyR      s   _8		)N(!   t
   __future__R    R   t   sympyR   t   sympy.core.basicR   t   sympy.core.containersR   t   sympy.core.exprR   t   sympy.core.functionR   t   sympy.core.logicR   t   sympy.core.symbolR   R	   t   sympy.logic.boolalgR
   R   t   sympy.sets.containsR   t   sympy.sets.setsR   R   R   R   t   sympy.utilities.iterablesR   t   sympy.utilities.miscR   R   (    (    (    s6   lib/python2.7/site-packages/sympy/sets/conditionset.pyt   <module>   s   "