ó
~9­\c           @  sÃ  d  Z  d d l m Z m Z d d l Z d d l m Z d d l m Z d d l	 Z	 e	 j
 d d k Z e rwe f Z e f Z e f Z e Z e	 j Z e Z e Z d „  Z e Z e j d	 ƒ Z e j d
 ƒ Z e j d ƒ Z d d l Z d d l m  Z  d d l! m" Z" e" Z# e$ e d ƒ Z% e& Z& d d l' m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- d d l. m/ Z/ d d l0 m1 Z1 n6d d l2 Z2 d d l3 Z3 e e3 j4 f Z e e f Z e e f Z e Z e	 j5 Z e Z e Z d „  Z d e f d „  ƒ  YZ e j d ƒ Z e j d ƒ Z e j d ƒ Z d d l6 Z e  Z  d d l" m" Z" d d l# m" Z# d d d „ Z% e8 Z& d d l m( Z( m) Z) m* Z* m+ Z+ m, Z, m- Z- d d „ Z/ e j9 d „ Z1 d „  Z: d dH d „  ƒ  YZ; e e< e; f d „ Z= d d „ Z> y d d  l0 m? Z? Wn! e@ k
 r!d d! l0 mA Z? n Xy d d" lB mC ZC Wn e@ k
 rRe jC ZC n XeD d# „ ZE d d$ „ ZF d% „  ZG d eD eH d& „ ZI d d' „ ZJ eJ d( d) ƒ jK ƒ  ZL d ZM eL d* k r4eL d+ k rõe d, d- d. d/ d0 d1 dI ƒZN eN rûd ZM qûn d2 ZL eM s4e d2 d- d3 d/ d0 d1 dJ ƒZN eN r1d4 ZM q1q4n  eL d) k rXeM rOd2 ZL qXd* ZL n  eL d2 k rŽeM rŽd d5 lO mP ZP eP d6 ƒ d* ZL n  e ZQ eL d2 k r¿eQ e eN jR d ƒ ƒ f 7ZQ n  d d7 l mS ZS d d8 l mT ZT d d9 lU mV ZV eS d: d; d< d= d> g ƒ ZW d? eX f d@ „  ƒ  YZY e ƒ  f eZ e e e[ e d ƒ f ƒ e\ e] e e^ dA „ Z_ dB eH dC „ Z` e	 j
 d  dK k rŽd dE l m` Z` n  y d dF l0 ma Za Wn e@ k
 r¾dG „  Za n Xd S(L   s®   
Reimplementations of constructs introduced in later versions of Python than
we support. Also some functions that are needed SymPy-wide and are located
here for easy import.
iÿÿÿÿ(   t   print_functiont   divisionN(   t   defaultdict(   t   import_modulei    i   c         C  s   |  S(   N(    (   t   x(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   u_decodeN   s    t   __code__t   __globals__t   __name__(   t   reduce(   t   StringIOt   exec(   t   Mappingt   Callablet   MutableMappingt
   MutableSett   Iterablet   Hashable(   t   unwrap(   t
   accumulatec         C  s   |  j  d ƒ S(   Ns   utf-8(   t   decode(   R   (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR   t   s    t   Iteratorc           B  s   e  Z d  „  Z RS(   c         C  s   t  |  ƒ j |  ƒ S(   N(   t   typet   __next__(   t   self(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   nextx   s    (   R   t
   __module__R   (    (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR   w   s   t	   func_codet   func_globalst	   func_namec         B  sc   | d k rB e j d ƒ } | j } | d k r< | j } n  ~ n | d k rW | } n  d d Ud S(   s   Execute code in a namespace.i   s   exec _code_ in _globs_, _locs_N(   t   Nonet   syst	   _getframet	   f_globalst   f_locals(   t   _code_t   _globs_t   _locs_t   frame(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   exec_…   s    		c           s™   ˆ  d k r d „  } n ‡  f d †  } |  } t | ƒ h } xV | |  ƒ r” |  j }  t |  ƒ } | | k r„ t d j | ƒ ƒ ‚ n  | j | ƒ q? W|  S(   s–  Get the object wrapped by *func*.

       Follows the chain of :attr:`__wrapped__` attributes returning the last
       object in the chain.

       *stop* is an optional callback accepting an object in the wrapper chain
       as its sole argument that allows the unwrapping to be terminated early if
       the callback returns a true value. If the callback never returns a true
       value, the last object in the chain is returned as usual. For example,
       :func:`signature` uses this to stop unwrapping if any object in the
       chain has a ``__signature__`` attribute defined.

       :exc:`ValueError` is raised if a cycle is encountered.

        c         S  s   t  |  d ƒ S(   Nt   __wrapped__(   t   hasattr(   t   f(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   _is_wrapper¦   s    c           s   t  |  d ƒ o ˆ  |  ƒ S(   NR(   (   R)   (   R*   (   t   stop(    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR+   ©   s    s!   wrapper loop when unwrapping {!r}N(   R   t   idR(   t
   ValueErrort   formatt   add(   t   funcR,   R+   R*   t   memot   id_func(    (   R,   s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR   •   s    	c         c  s<   |  d } | Vx& |  d D] } | | | ƒ } | Vq Wd  S(   Ni    i   (    (   t   iterableR1   t   statet   i(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR   µ   s
    
c           s5   d ˆ f ‡  ‡ f d †  ƒ  Y} t  j | d d i  ƒ S(   s  
    Create a base class with a metaclass.

    For example, if you have the metaclass

    >>> class Meta(type):
    ...     pass

    Use this as the metaclass by doing

    >>> from sympy.core.compatibility import with_metaclass
    >>> class MyClass(with_metaclass(Meta, object)):
    ...     pass

    This is equivalent to the Python 2::

        class MyClass(object):
            __metaclass__ = Meta

    or Python 3::

        class MyClass(object, metaclass=Meta):
            pass

    That is, the first argument is the metaclass, and the remaining arguments
    are the base classes. Note that if the base class is just ``object``, you
    may omit it.

    >>> MyClass.__mro__
    (<class '...MyClass'>, <... 'object'>)
    >>> type(MyClass)
    <class '...Meta'>

    t	   metaclassc             s   e  Z ‡  ‡ f d  †  Z RS(   c           s   ˆ | ˆ  | ƒ S(   N(    (   t   clst   namet
   this_basest   d(   t   basest   meta(    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   __new__å   s    (   R   R   R>   (    (   R<   R=   (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR7   ä   s   t   NewBase(    (   R   R>   (   R=   R<   R7   (    (   R<   R=   s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   with_metaclass½   s    't   NotIterablec           B  s   e  Z d  Z RS(   sÌ   
    Use this as mixin when creating a class which is not supposed to return
    true when iterable() is called on its instances. I.e. avoid infinite loop
    when calling e.g. list() on the instance
    (   R   R   t   __doc__(    (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyRA   ï   s   c         C  sQ   t  |  d ƒ r |  j Sy t |  ƒ Wn t k
 r8 t SX| rM t |  | ƒ St S(   sZ  
    Return a boolean indicating whether ``i`` is SymPy iterable.
    True also indicates that the iterator is finite, i.e. you e.g.
    call list(...) on the instance.

    When SymPy is working with iterables, it is almost always assuming
    that the iterable is not a string or a mapping, so those are excluded
    by default. If you want a pure Python definition, make exclude=None. To
    exclude multiple items, pass them as a tuple.

    You can also set the _iterable attribute to True or False on your class,
    which will override the checks here, including the exclude test.

    As a rule of thumb, some SymPy functions use this to check if they should
    recursively map over an object. If an object is technically iterable in
    the Python sense but does not desire this behavior (e.g., because its
    iteration is not finite, or because iteration might induce an unwanted
    computation), it should disable it by setting the _iterable attribute to False.

    See also: is_sequence

    Examples
    ========

    >>> from sympy.utilities.iterables import iterable
    >>> from sympy import Tuple
    >>> things = [[1], (1,), set([1]), Tuple(1), (j for j in [1, 2]), {1:2}, '1', 1]
    >>> for i in things:
    ...     print('%s %s' % (iterable(i), type(i)))
    True <... 'list'>
    True <... 'tuple'>
    True <... 'set'>
    True <class 'sympy.core.containers.Tuple'>
    True <... 'generator'>
    False <... 'dict'>
    False <... 'str'>
    False <... 'int'>

    >>> iterable({}, exclude=None)
    True
    >>> iterable({}, exclude=str)
    True
    >>> iterable("no", exclude=str)
    False

    t	   _iterable(   R)   RC   t   itert	   TypeErrort   Falset
   isinstancet   True(   R6   t   exclude(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR4   ÷   s    /c         C  s4   t  |  d ƒ r t |  ƒ p3 t | ƒ o3 t |  | ƒ S(   sÞ  
    Return a boolean indicating whether ``i`` is a sequence in the SymPy
    sense. If anything that fails the test below should be included as
    being a sequence for your application, set 'include' to that object's
    type; multiple types should be passed as a tuple of types.

    Note: although generators can generate a sequence, they often need special
    handling to make sure their elements are captured before the generator is
    exhausted, so these are not included by default in the definition of a
    sequence.

    See also: iterable

    Examples
    ========

    >>> from sympy.utilities.iterables import is_sequence
    >>> from types import GeneratorType
    >>> is_sequence([])
    True
    >>> is_sequence(set())
    False
    >>> is_sequence('abc')
    False
    >>> is_sequence('abc', include=str)
    True
    >>> generator = (c for c in 'abc')
    >>> is_sequence(generator)
    False
    >>> is_sequence(generator, include=(str, GeneratorType))
    True

    t   __getitem__(   R)   R4   t   boolRG   (   R6   t   include(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   is_sequence1  s    "(   t   zip_longest(   t   izip_longest(   t	   maketransc         C  sŠ   d d l  m } yO | r9 t |  t | f ƒ r9 t ‚ n  t |  ƒ } | |  k rZ t ‚ n  | SWn$ t k
 r… t d |  f ƒ ‚ n Xd S(   sn  
    Convert the argument to a builtin integer.

    The return value is guaranteed to be equal to the input. ValueError
    is raised if the input has a non-integral value. When ``strict`` is
    False, non-integer input that compares equal to the integer value
    will not raise an error.


    Examples
    ========

    >>> from sympy.core.compatibility import as_int
    >>> from sympy import sqrt, S

    The function is primarily concerned with sanitizing input for
    functions that need to work with builtin integers, so anything that
    is unambiguously an integer should be returned as an int:

    >>> as_int(S(3))
    3

    Floats, being of limited precision, are not assumed to be exact and
    will raise an error unless the ``strict`` flag is False. This
    precision issue becomes apparent for large floating point numbers:

    >>> big = 1e23
    >>> type(big) is float
    True
    >>> big == int(big)
    True
    >>> as_int(big)
    Traceback (most recent call last):
    ...
    ValueError: ... is not an integer
    >>> as_int(big, strict=False)
    99999999999999991611392

    Input that might be a complex representation of an integer value is
    also rejected by default:

    >>> one = sqrt(3 + 2*sqrt(2)) - sqrt(2)
    >>> int(one) == 1
    True
    >>> as_int(one)
    Traceback (most recent call last):
    ...
    ValueError: ... is not an integer
    iÿÿÿÿ(   t   Integers   %s is not an integerN(   t   sympy.core.numbersRQ   RG   t
   SYMPY_INTSRE   t   intR.   (   t   nt   strictRQ   t   result(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   as_inte  s    2		c         C  s½  d d l  m } d d l m } d d l m } m } d d l m } t |  | ƒ re |  j	 d | ƒ S| |  d t
 ƒr't |  t ƒ r› |  j ƒ  } t } n0 t |  t ƒ r¹ |  } t } n t |  ƒ } t } g  | D] }	 t |	 d | ƒ^ qÒ } | rt | ƒ } n  d t | ƒ t | ƒ f }
 } nk t |  t
 ƒ svy | |  ƒ }  Wn | k
 rYqvXt |  | ƒ rvt |  ƒ Sn  d	 d t |  ƒ f f }
 } |
 d	 |  j j f | | j j	 ƒ  | j f S(
   s¥  Return a key that can be used for sorting.

    The key has the structure:

    (class_key, (len(args), args), exponent.sort_key(), coefficient)

    This key is supplied by the sort_key routine of Basic objects when
    ``item`` is a Basic object or an object (other than a string) that
    sympifies to a Basic object. Otherwise, this function produces the
    key.

    The ``order`` argument is passed along to the sort_key routine and is
    used to determine how the terms *within* an expression are ordered.
    (See examples below) ``order`` options are: 'lex', 'grlex', 'grevlex',
    and reversed values of the same (e.g. 'rev-lex'). The default order
    value is None (which translates to 'lex').

    Examples
    ========

    >>> from sympy import S, I, default_sort_key, sin, cos, sqrt
    >>> from sympy.core.function import UndefinedFunction
    >>> from sympy.abc import x

    The following are equivalent ways of getting the key for an object:

    >>> x.sort_key() == default_sort_key(x)
    True

    Here are some examples of the key that is produced:

    >>> default_sort_key(UndefinedFunction('f'))
    ((0, 0, 'UndefinedFunction'), (1, ('f',)), ((1, 0, 'Number'),
        (0, ()), (), 1), 1)
    >>> default_sort_key('1')
    ((0, 0, 'str'), (1, ('1',)), ((1, 0, 'Number'), (0, ()), (), 1), 1)
    >>> default_sort_key(S.One)
    ((1, 0, 'Number'), (0, ()), (), 1)
    >>> default_sort_key(2)
    ((1, 0, 'Number'), (0, ()), (), 2)


    While sort_key is a method only defined for SymPy objects,
    default_sort_key will accept anything as an argument so it is
    more robust as a sorting key. For the following, using key=
    lambda i: i.sort_key() would fail because 2 doesn't have a sort_key
    method; that's why default_sort_key is used. Note, that it also
    handles sympification of non-string items likes ints:

    >>> a = [2, I, -I]
    >>> sorted(a, key=default_sort_key)
    [2, -I, I]

    The returned key can be used anywhere that a key can be specified for
    a function, e.g. sort, min, max, etc...:

    >>> a.sort(key=default_sort_key); a[0]
    2
    >>> min(a, key=default_sort_key)
    2

    Note
    ----

    The key returned is useful for getting items into a canonical order
    that will be the same across platforms. It is not directly useful for
    sorting lists of expressions:

    >>> a, b = x, 1/x

    Since ``a`` has only 1 term, its value of sort_key is unaffected by
    ``order``:

    >>> a.sort_key() == a.sort_key('rev-lex')
    True

    If ``a`` and ``b`` are combined then the key will differ because there
    are terms that can be ordered:

    >>> eq = a + b
    >>> eq.sort_key() == eq.sort_key('rev-lex')
    False
    >>> eq.as_ordered_terms()
    [x, 1/x]
    >>> eq.as_ordered_terms('rev-lex')
    [1/x, x]

    But since the keys for each of these terms are independent of ``order``'s
    value, they don't sort differently when they appear separately in a list:

    >>> sorted(eq.args, key=default_sort_key)
    [1/x, x]
    >>> sorted(eq.args, key=lambda i: default_sort_key(i, order='rev-lex'))
    [1/x, x]

    The order of terms obtained when using these keys is the order that would
    be obtained if those terms were *factors* in a product.

    Although it is useful for quickly putting expressions in canonical order,
    it does not sort expressions based on their complexity defined by the
    number of operations, power of variables and others:

    >>> sorted([sin(x)*cos(x), sin(x)], key=default_sort_key)
    [sin(x)*cos(x), sin(x)]
    >>> sorted([x, x**2, sqrt(x), x**3], key=default_sort_key)
    [sqrt(x), x, x**2, x**3]

    See Also
    ========

    ordered, sympy.core.expr.as_ordered_factors, sympy.core.expr.as_ordered_terms

    i   (   t   S(   t   Basic(   t   sympifyt   SympifyError(   R4   t   orderRI   i
   i    (   t	   singletonRY   t   basicRZ   R[   R\   t   compatibilityR4   RG   t   sort_keyt   string_typest   dictt   itemsRH   t   sett   listRF   t   default_sort_keyt   sortedt   lent   tuplet   strt	   __class__R   t   One(   t   itemR]   RY   RZ   R[   R\   R4   t   argst	   unorderedt   argt	   cls_index(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyRg   £  s:    s		%"c         C  s…   d d l  m } t |  | ƒ r, |  j | ƒ St |  ƒ rP d t d „  |  Dƒ ƒ St |  t ƒ r} d t d „  |  j ƒ  Dƒ ƒ Sd Sd S(   s  
    A helper for ordered() which returns the node count of ``e`` which
    for Basic objects is the number of Basic nodes in the expression tree
    but for other objects is 1 (unless the object is an iterable or dict
    for which the sum of nodes is returned).
    i   (   RZ   c         s  s   |  ] } t  | ƒ Vq d  S(   N(   t   _nodes(   t   .0t   ei(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pys	   <genexpr>Q  s    c         s  s+   |  ]! \ } } t  | ƒ t  | ƒ Vq d  S(   N(   Rs   (   Rt   t   kt   v(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pys	   <genexpr>S  s    N(   R_   RZ   RG   t   countR4   t   sumRc   Rd   (   t   eRZ   (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyRs   E  s    c         c  s¬  t  t ƒ } | ry t | t t f ƒ s3 | g } n  t | ƒ } | j d ƒ } xN |  D] } | | | ƒ j | ƒ qU Wn& | sŽ t d ƒ ‚ n  | d	 j |  ƒ xt	 | j
 ƒ  ƒ D]ò } t | | ƒ d k r}| rô t | | | | | ƒ | | <q}| r&t | | t t f d t d | ƒ| | <q}| r}d d l m } t | | | ƒ ƒ }	 t |	 ƒ d k rzt d |	 ƒ ‚ qzq}n  x | | D] }
 |
 VqˆW| j | ƒ q² Wd	 S(
   s  Return an iterator of the seq where keys are used to break ties in
    a conservative fashion: if, after applying a key, there are no ties
    then no other keys will be computed.

    Two default keys will be applied if 1) keys are not provided or 2) the
    given keys don't resolve all ties (but only if `default` is True). The
    two keys are `_nodes` (which places smaller expressions before large) and
    `default_sort_key` which (if the `sort_key` for an object is defined
    properly) should resolve any ties.

    If ``warn`` is True then an error will be raised if there were no
    keys remaining to break ties. This can be used if it was expected that
    there should be no ties between items that are not identical.

    Examples
    ========

    >>> from sympy.utilities.iterables import ordered
    >>> from sympy import count_ops
    >>> from sympy.abc import x, y

    The count_ops is not sufficient to break ties in this list and the first
    two items appear in their original order (i.e. the sorting is stable):

    >>> list(ordered([y + 2, x + 2, x**2 + y + 3],
    ...    count_ops, default=False, warn=False))
    ...
    [y + 2, x + 2, x**2 + y + 3]

    The default_sort_key allows the tie to be broken:

    >>> list(ordered([y + 2, x + 2, x**2 + y + 3]))
    ...
    [x + 2, y + 2, x**2 + y + 3]

    Here, sequences are sorted by length, then sum:

    >>> seq, keys = [[[1, 2, 1], [0, 3, 1], [1, 1, 3], [2], [1]], [
    ...    lambda x: len(x),
    ...    lambda x: sum(x)]]
    ...
    >>> list(ordered(seq, keys, default=False, warn=False))
    [[1], [2], [1, 2, 1], [0, 3, 1], [1, 1, 3]]

    If ``warn`` is True, an error will be raised if there were not
    enough keys to break ties:

    >>> list(ordered(seq, keys, default=False, warn=True))
    Traceback (most recent call last):
    ...
    ValueError: not enough keys to break ties


    Notes
    =====

    The decorated sort is one of the fastest ways to sort a sequence for
    which special item comparison is desired: the sequence is decorated,
    sorted on the basis of the decoration (e.g. making all letters lower
    case) and then undecorated. If one wants to break ties for items that
    have the same decorated value, a second key can be used. But if the
    second key is expensive to compute then it is inefficient to decorate
    all items with both keys: only those items having identical first key
    values need to be decorated. This function applies keys successively
    only when needed to break ties. By yielding an iterator, use of the
    tie-breaker is delayed as long as possible.

    This function is best used in cases when use of the first key is
    expected to be a good hashing function; if there are no unique hashes
    from application of a key then that key should not have been used. The
    exception, however, is that even if there are many collisions, if the
    first group is small and one does not need to process all items in the
    list then time will not be wasted sorting what one was not interested
    in. For example, if one were looking for the minimum in a list and
    there were several criteria used to define the sort order, then this
    function would be good at returning that quickly if the first group
    of candidates is small relative to the number of items being processed.

    i    s+   if default=False then keys must be providedi   t   defaultt   warniÿÿÿÿ(   t   uniqs!   not enough keys to break ties: %sN(   R   Rf   RG   Rj   t   popt   appendR.   R   t   extendRh   t   keysRi   t   orderedRs   Rg   RF   t   sympy.utilities.iterablesR}   (   t   seqR   R{   R|   R;   R*   t   aRv   R}   t   uRw   (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR‚   X  s6    P 	c         C  s   d d l  m } | |  | ƒ S(   Niÿÿÿÿ(   t   getenv(   t   osR‡   (   t   keyR{   R‡   (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   _getenvÑ  s    t   SYMPY_GROUND_TYPESt   autot   pythont   gmpy1t   gmpy2t   min_module_versions   2.0.0t   module_version_attrt   versiont   module_version_attr_call_argst   gmpys   1.13i   (   R|   sA   gmpy library is not installed, switching to 'python' ground types(   t
   namedtuple(   t   update_wrapper(   t   RLockt	   CacheInfot   hitst   missest   maxsizet   currsizet
   _HashedSeqc           B  s#   e  Z d  Z e d „ Z d „  Z RS(   t	   hashvaluec         C  s   | |  (| | ƒ |  _  d  S(   N(   Rž   (   R   t   tupt   hash(    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   __init__
  s    c         C  s   |  j  S(   N(   Rž   (   R   (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   __hash__  s    (   R   R   t	   __slots__R    R¡   R¢   (    (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR     s   c	           sÒ   |  }	 | rF | | j  ƒ  ƒ }
 |	 | 7}	 x |
 D] } |	 | 7}	 q/ Wn  | r˜ |	 | ‡  f d †  |  Dƒ ƒ 7}	 | rÈ |	 | ‡  f d †  |
 Dƒ ƒ 7}	 qÈ n0 | |	 ƒ d k rÈ ˆ  |	 d ƒ | k rÈ |	 d St |	 ƒ S(   sG   Make a cache key from optionally typed positional and keyword argumentsc         3  s   |  ] } ˆ  | ƒ Vq d  S(   N(    (   Rt   Rw   (   R   (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pys	   <genexpr>  s    c         3  s!   |  ] \ } } ˆ  | ƒ Vq d  S(   N(    (   Rt   Rv   Rw   (   R   (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pys	   <genexpr>  s    i   i    (   Rd   R   (   Ro   t   kwdst   typedt   kwd_markt	   fasttypesRh   Rj   R   Ri   R‰   t   sorted_itemsRn   (    (   R   s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt	   _make_key  s    
 &(id   c           s   ‡  ‡ f d †  } | S(   sœ  Least-recently-used cache decorator.

    If *maxsize* is set to None, the LRU features are disabled and the cache
    can grow without bound.

    If *typed* is True, arguments of different types will be cached separately.
    For example, f(3.0) and f(3) will be treated as distinct calls with
    distinct results.

    Arguments to the cached function must be hashable.

    View the cache statistics named tuple (hits, misses, maxsize, currsize) with
    f.cache_info().  Clear the cache and statistics with f.cache_clear().
    Access the underlying function with f.__wrapped__.

    See:  https://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used

    c           sg  t  ƒ  ‰ d d g ‰ d
 \ ‰  ‰ t ‰
 ˆ j ‰ t ‰ t ƒ  ‰	 g  ‰ ˆ ˆ d  d  g ˆ (ˆ g ‰ d \ ‰ ‰ ‰ ‰ ˆ d k r— ‡ ‡ ‡ f d †  } nr ˆ d  k rÍ ‡  ‡ ‡ ‡ ‡
 ‡ ‡ ‡ ‡ f	 d †  } n< ‡  ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡ ‡	 ‡
 ‡ ‡ ‡ ‡ ‡ f d †  } ‡  ‡ ‡ ‡	 ‡ ‡ f d †  } ‡ ‡	 ‡ ‡ f d	 †  } ˆ | _ | | _ | | _ t	 | ˆ ƒ S(   Ni    i   i   i   c            s#   ˆ |  | Ž  } ˆ ˆ  c d 7<| S(   Ni   (    (   Ro   R¤   RW   (   t   MISSESt   statst   user_function(    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   wrapperM  s    c            sn   ˆ |  | ˆ ƒ } ˆ | ˆ ƒ } | ˆ k	 rA ˆ ˆ  c d 7<| Sˆ |  | Ž  } | ˆ | <ˆ ˆ c d 7<| S(   Ni   (    (   Ro   R¤   R‰   RW   (	   t   HITSRª   t   cachet	   cache_gett   make_keyt   rootR«   R¥   R¬   (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR­   U  s    
c       	     sä  y( | s ˆ r! ˆ
 |  | ˆ ƒ n |  } Wn+ t  k
 rU ˆ ˆ c d 7<ˆ |  | Ž  SXˆ	  ˆ | ƒ } | d  k	 rè ˆ \ } | \ } } } } | | ˆ <| | ˆ <| ˆ } | | ˆ <| ˆ <| | ˆ <| | ˆ <ˆ ˆ  c d 7<| SWd  QXˆ |  | Ž  } ˆ	 Û ˆ \ } | ˆ k rn® ˆ ˆ ƒ ˆ k r”| }	 | |	 ˆ <| |	 ˆ <|	 ˆ } ˆ d <| ˆ }
 | ˆ } d  | ˆ <| ˆ <ˆ |
 =|	 ˆ | <n6 | ˆ } | | | | g } | | ˆ <| ˆ <ˆ | <ˆ ˆ c d 7<Wd  QX| S(   Ni   i    (   RE   R   (   Ro   R¤   R‰   t   linkR²   t	   link_prevt	   link_nextRW   t   lastt   oldroott   oldkeyt   oldvalue(   R®   t   KEYRª   t   NEXTt   PREVt   RESULTt   _lenR¯   R°   t   lockR±   R›   t   nonlocal_rootR«   R¥   R¬   (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyR­   c  sL    (	





	




c        
     s2   ˆ & t  ˆ ˆ  ˆ ˆ ˆ t ˆ ƒ ƒ SWd QXd S(   s   Report cache statisticsN(   t
   _CacheInfoRi   (    (   R®   Rª   R¯   R¿   R›   R«   (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt
   cache_info–  s    c            sE   ˆ 9 ˆ  j  ƒ  ˆ d }  |  |  d d g |  (d d g ˆ (Wd QXd S(   s$   Clear the cache and cache statisticsi    N(   t   clearR   (   R²   (   R¯   R¿   RÀ   R«   (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   cache_clear›  s
    

(   i    i   (   i    i   i   i   (
   Rc   R©   t   getRi   R—   R   R(   RÂ   RÄ   R–   (   R¬   R­   RÂ   RÄ   (   R›   R¥   (   R®   Rº   Rª   R»   R¼   R½   R¾   R¯   R°   R¿   R±   RÀ   R²   R«   R¬   s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   decorating_function=  s,    				*<3			(    (   R›   R¥   RÆ   (    (   R›   R¥   s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt	   lru_cache$  s    ki   (   RÇ   (   t   filterfalsec           s   t  ‡  f d †  | ƒ S(   Nc           s   ˆ  |  ƒ S(   N(    (   R   (   t   pred(    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   <lambda>³  t    (   t   filter(   RÉ   t   itr(    (   RÉ   s7   lib/python2.7/site-packages/sympy/core/compatibility.pyRÈ   ²  s    (    (    (    (   i   i   (b   RB   t
   __future__R    R   t   operatort   collectionsR   t   sympy.externalR   R   t   version_infot   PY3R   t   class_typesRT   t   integer_typesRk   Rb   t   longt   int_infot   unicodet   chrt   unichrR   t   objectR   t
   attrgettert   get_function_codet   get_function_globalst   get_function_namet   builtinst	   functoolsR	   t   ioR
   t	   cStringIOt   getattrR'   t   ranget   collections.abcR   R   R   R   R   R   t   inspectR   t	   itertoolsR   t   codecst   typest	   ClassTypet	   long_infot   __builtin__R   t   xrangeR0   R@   RA   Rc   R4   RM   RN   t   ImportErrorRO   t   stringRP   RH   RX   Rg   Rs   RF   R‚   RŠ   t   lowert   GROUND_TYPESt   HAS_GMPYR”   t   warningsR|   RS   t   mpzR•   R–   t	   threadingR—   RÁ   Rf   R   Re   t	   frozensetRh   Rj   Ri   R©   RÇ   RÈ   (    (    (    s7   lib/python2.7/site-packages/sympy/core/compatibility.pyt   <module>   sØ   6					.		. 	2:'>¢	y		
		‡