ó
¡¼™\c           @  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	 m
 Z
 m Z d d l m Z m Z d d l m Z d e f d	 „  ƒ  YZ d
 „  e e <d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sÝ   Module for SymPy containers

    (SymPy objects that store other SymPy objects)

    The containers implemented in this module are subclassed to Basic.
    They are supposed to work seamlessly within the SymPy framework.
iÿÿÿÿ(   t   print_functiont   division(   t   OrderedDict(   t   Basic(   t   as_intt   ranget
   MutableSet(   t   sympifyt	   converter(   t   iterablet   Tuplec           B  sª   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e
 Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d d „ Z RS(   sÑ  
    Wrapper around the builtin tuple object

    The Tuple is a subclass of Basic, so that it works well in the
    SymPy framework.  The wrapped tuple is available as self.args, but
    you can also access elements or slices with [:] syntax.

    Parameters
    ==========

    sympify : bool
        If ``False``, ``sympify`` is not called on ``args``. This
        can be used for speedups for very large tuples where the
        elements are known to already be sympy objects.

    Example
    =======

    >>> from sympy import symbols
    >>> from sympy.core.containers import Tuple
    >>> a, b, c, d = symbols('a b c d')
    >>> Tuple(a, b, c)[1:]
    (b, c)
    >>> Tuple(a, b, c).subs(a, d)
    (d, b, c)

    c         O  s;   | j  d t ƒ r% d „  | Dƒ } n  t j |  | Œ } | S(   NR   c         s  s   |  ] } t  | ƒ Vq d  S(   N(   R   (   t   .0t   arg(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pys	   <genexpr>3   s    (   t   gett   TrueR   t   __new__(   t   clst   argst   kwargst   obj(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR   1   s    c           sO   t  | t ƒ rD | j t ˆ  ƒ ƒ } t ‡  f d †  t | Œ  Dƒ Œ  Sˆ  j | S(   Nc         3  s   |  ] } ˆ  j  | Vq d  S(   N(   R   (   R   t   j(   t   self(    s4   lib/python2.7/site-packages/sympy/core/containers.pys	   <genexpr>:   s    (   t
   isinstancet   slicet   indicest   lenR
   R   R   (   R   t   iR   (    (   R   s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __getitem__7   s     c         C  s   t  |  j ƒ S(   N(   R   R   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __len__=   s    c         C  s   | |  j  k S(   N(   R   (   R   t   item(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __contains__@   s    c         C  s   t  |  j ƒ S(   N(   t   iterR   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __iter__C   s    c         C  sK   t  | t ƒ r# t |  j | j Œ  St  | t ƒ rC t |  j | Œ  St Sd  S(   N(   R   R
   R   t   tuplet   NotImplemented(   R   t   other(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __add__F   s
    c         C  sK   t  | t ƒ r# t | j |  j Œ  St  | t ƒ rC t | |  j Œ  St Sd  S(   N(   R   R
   R   R!   R"   (   R   R#   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __radd__N   s
    c         C  sN   y t  | ƒ } Wn' t k
 r9 t d t | ƒ ƒ ‚ n X|  j |  j | Œ  S(   Ns3   Can't multiply sequence by non-integer of type '%s'(   R   t
   ValueErrort	   TypeErrort   typet   funcR   (   R   R#   t   n(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __mul__V   s
    c         C  s2   t  | t ƒ r% t t |  ƒ j | ƒ S|  j | k S(   N(   R   R   t   superR
   t   __eq__R   (   R   R#   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR-   _   s    c         C  s2   t  | t ƒ r% t t |  ƒ j | ƒ S|  j | k S(   N(   R   R   R,   R
   t   __ne__R   (   R   R#   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR.   d   s    c         C  s   t  |  j ƒ S(   N(   t   hashR   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __hash__i   s    c           s   t  ‡  f d †  |  j Dƒ ƒ S(   Nc         3  s   |  ] } | j  ˆ  ƒ Vq d  S(   N(   t
   _to_mpmath(   R   t   a(   t   prec(    s4   lib/python2.7/site-packages/sympy/core/containers.pys	   <genexpr>m   s    (   R!   R   (   R   R3   (    (   R3   s4   lib/python2.7/site-packages/sympy/core/containers.pyR1   l   s    c         C  s   t  |  j | j k  ƒ S(   N(   R   R   (   R   R#   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __lt__o   s    c         C  s   t  |  j | j k ƒ S(   N(   R   R   (   R   R#   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __le__r   s    c         C  s   |  j  j | ƒ S(   sB   T.count(value) -> integer -- return number of occurrences of value(   R   t   count(   R   t   value(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   tuple_countw   s    c         C  sa   | d k r( | d k r( |  j j | ƒ S| d k rG |  j j | | ƒ S|  j j | | | ƒ Sd S(   s„   T.index(value, [start, [stop]]) -> integer -- return first index of value.
           Raises ValueError if the value is not present.N(   t   NoneR   t   index(   R   R7   t   startt   stop(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR:   {   s
    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R    R$   R%   R+   t   __rmul__R-   R.   R0   R1   R4   R5   R8   R9   R:   (    (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR
      s$   															c         C  s
   t  |  Œ  S(   N(   R
   (   t   tup(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   <lambda>’   t    c           s   ‡  f d †  } | S(   s  
    Decorator that converts any tuple in the function arguments into a Tuple.

    The motivation for this is to provide simple user interfaces.  The user can
    call a function with regular tuples in the argument, and the wrapper will
    convert them to Tuples before handing them to the function.

    >>> from sympy.core.containers import tuple_wrapper
    >>> def f(*args):
    ...    return args
    >>> g = tuple_wrapper(f)

    The decorated function g sees only the Tuple argument:

    >>> g(0, (1, 2), 3)
    (0, (1, 2), 3)

    c            sY   g  } xC |  D]; } t  | ƒ t k r; | j t | Œ  ƒ q | j | ƒ q Wˆ  | | Ž  S(   N(   R(   R!   t   appendR
   (   R   t   kw_argst   newargsR   (   t   method(    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   wrap_tuples¨   s    (    (   RG   RH   (    (   RG   s4   lib/python2.7/site-packages/sympy/core/containers.pyt   tuple_wrapper•   s    t   Dictc           B  s’   e  Z d  Z d „  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d d
 „ Z d „  Z d „  Z e d „  ƒ Z RS(   s;  
    Wrapper around the builtin dict object

    The Dict is a subclass of Basic, so that it works well in the
    SymPy framework.  Because it is immutable, it may be included
    in sets, but its values must all be given at instantiation and
    cannot be changed afterwards.  Otherwise it behaves identically
    to the Python dict.

    >>> from sympy.core.containers import Dict

    >>> D = Dict({1: 'one', 2: 'two'})
    >>> for key in D:
    ...    if key == 1:
    ...        print('%s %s' % (key, D[key]))
    1 one

    The args are sympified so the 1 and 2 are Integers and the values
    are Symbols. Queries automatically sympify args so the following work:

    >>> 1 in D
    True
    >>> D.has('one') # searches keys and values
    True
    >>> 'one' in D # not in the keys
    False
    >>> D[1]
    one

    c         G  só   t  | ƒ d k r` t | d t t f ƒ r` g  | d j ƒ  D] \ } } t | | ƒ ^ q< } nY t | ƒ r­ t d „  | Dƒ ƒ r­ g  | D] \ } } t | | ƒ ^ q‰ } n t d ƒ ‚ t	 | ƒ } t
 j |  | ƒ } | | _ t | ƒ | _ | S(   Ni   i    c         s  s!   |  ] } t  | ƒ d  k Vq d S(   i   N(   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pys	   <genexpr>Ö   s    s<   Pass Dict args as Dict((k1, v1), ...) or Dict({k1: v1, ...})(   R   R   t   dictRJ   t   itemsR
   R	   t   allR'   t	   frozensetR   R   t   elementst   _dict(   R   R   t   kt   vRL   RO   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR   Ó   s    +5"+	c         C  s   |  j  t | ƒ S(   s   x.__getitem__(y) <==> x[y](   RP   R   (   R   t   key(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR   à   s    c         C  s   t  d ƒ ‚ d  S(   Ns   SymPy Dicts are Immutable(   t   NotImplementedError(   R   RS   R7   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __setitem__ä   s    c         C  s   t  |  j ƒ S(   N(   R!   RO   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR   ç   s    c         C  s   |  j  j ƒ  S(   s8   D.items() -> list of D's (key, value) pairs, as 2-tuples(   RP   RL   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyRL   ë   s    c         C  s   |  j  j ƒ  S(   s   D.keys() -> list of D's keys(   RP   t   keys(   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyRV   ï   s    c         C  s   |  j  j ƒ  S(   s    D.values() -> list of D's values(   RP   t   values(   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyRW   ó   s    c         C  s   t  |  j ƒ S(   s   x.__iter__() <==> iter(x)(   R   RP   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR    ÷   s    c         C  s   |  j  j ƒ  S(   s   x.__len__() <==> len(x)(   RP   R   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR   û   s    c         C  s   |  j  j t | ƒ | ƒ S(   s<   D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.(   RP   R   R   (   R   RS   t   default(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR   ÿ   s    c         C  s   t  | ƒ |  j k S(   s6   D.__contains__(k) -> True if D has a key k, else False(   R   RP   (   R   RS   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR     s    c         C  s   t  |  j | j k  ƒ S(   N(   R   R   (   R   R#   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR4     s    c         C  s)   d d l  m } t t |  j d | ƒƒ S(   Niÿÿÿÿ(   t   default_sort_keyRS   (   t   sympy.utilitiesRY   R!   t   sortedR   (   R   RY   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   _sorted_args
  s    N(   R=   R>   R?   R   R   RU   t   propertyR   RL   RV   RW   R    R   R9   R   R   R4   R\   (    (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyRJ   ³   s   										t
   OrderedSetc           B  sq   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z e d „ Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z RS(   c         C  s2   | r" t  d „  | Dƒ ƒ |  _ n t  ƒ  |  _ d  S(   Nc         s  s   |  ] } | d  f Vq d  S(   N(   R9   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pys	   <genexpr>  s    (   R   t   map(   R   R	   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __init__  s    c         C  s   t  |  j ƒ S(   N(   R   R_   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR     s    c         C  s   | |  j  k S(   N(   R_   (   R   RS   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR     s    c         C  s   d  |  j | <d  S(   N(   R9   R_   (   R   RS   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   add  s    c         C  s   |  j  j | ƒ d  S(   N(   R_   t   pop(   R   RS   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   discard   s    c         C  s   |  j  j d | ƒ d S(   Nt   lasti    (   R_   t   popitem(   R   Rd   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyRb   #  s    c         c  s#   x |  j  j ƒ  D] } | Vq Wd  S(   N(   R_   RV   (   R   RS   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR    &  s    c         C  s=   |  j  s d |  j j f Sd |  j j t |  j  j ƒ  ƒ f S(   Ns   %s()s   %s(%r)(   R_   t	   __class__R=   t   listRV   (   R   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   __repr__*  s    	c         C  s@   g  } x* |  D]" } | | k r | j  | ƒ q q W|  j | ƒ S(   N(   RD   Rf   (   R   R#   t   resultt   val(    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   intersection/  s
    c         C  s@   g  } x* |  D]" } | | k r | j  | ƒ q q W|  j | ƒ S(   N(   RD   Rf   (   R   R#   Ri   Rj   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt
   difference6  s
    c         C  s"   x | D] } |  j  | ƒ q Wd  S(   N(   Ra   (   R   R	   Rj   (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   update=  s    N(   R=   R>   R9   R`   R   R   Ra   Rc   R   Rb   R    Rh   Rk   Rl   Rm   (    (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyR^     s   								N(   R?   t
   __future__R    R   t   collectionsR   t   sympy.core.basicR   t   sympy.core.compatibilityR   R   R   t   sympy.core.sympifyR   R   t   sympy.utilities.iterablesR	   R
   R!   RI   RJ   R^   (    (    (    s4   lib/python2.7/site-packages/sympy/core/containers.pyt   <module>   s   ~	]