ó
¡¼™\c           @  s6   d  Z  d d l m Z m Z d e f d „  ƒ  YZ d S(   s   
Replacement rules.
iÿÿÿÿ(   t   print_functiont   divisiont	   Transformc           B  s;   e  Z d  Z d „  d „ Z d „  Z d „  Z d d „ Z RS(   s¿  
    Immutable mapping that can be used as a generic transformation rule.

    Parameters
    ----------
    transform : callable
        Computes the value corresponding to any key.
    filter : callable, optional
        If supplied, specifies which objects are in the mapping.

    Examples
    ========

    >>> from sympy.core.rules import Transform
    >>> from sympy.abc import x

    This Transform will return, as a value, one more than the key:

    >>> add1 = Transform(lambda x: x + 1)
    >>> add1[1]
    2
    >>> add1[x]
    x + 1

    By default, all values are considered to be in the dictionary. If a filter
    is supplied, only the objects for which it returns True are considered as
    being in the dictionary:

    >>> add1_odd = Transform(lambda x: x + 1, lambda x: x%2 == 1)
    >>> 2 in add1_odd
    False
    >>> add1_odd.get(2, 0)
    0
    >>> 3 in add1_odd
    True
    >>> add1_odd[3]
    4
    >>> add1_odd.get(3, 0)
    4
    c         C  s   t  S(   N(   t   True(   t   x(    (    s/   lib/python2.7/site-packages/sympy/core/rules.pyt   <lambda>2   t    c         C  s   | |  _  | |  _ d  S(   N(   t
   _transformt   _filter(   t   selft	   transformt   filter(    (    s/   lib/python2.7/site-packages/sympy/core/rules.pyt   __init__2   s    	c         C  s   |  j  | ƒ S(   N(   R   (   R	   t   item(    (    s/   lib/python2.7/site-packages/sympy/core/rules.pyt   __contains__6   s    c         C  s,   |  j  | ƒ r |  j | ƒ St | ƒ ‚ d  S(   N(   R   R   t   KeyError(   R	   t   key(    (    s/   lib/python2.7/site-packages/sympy/core/rules.pyt   __getitem__9   s    c         C  s   | |  k r |  | S| Sd  S(   N(    (   R	   R   t   default(    (    s/   lib/python2.7/site-packages/sympy/core/rules.pyt   get?   s    N(   t   __name__t
   __module__t   __doc__R   R   R   t   NoneR   (    (    (    s/   lib/python2.7/site-packages/sympy/core/rules.pyR      s
   (		N(   R   t
   __future__R    R   t   objectR   (    (    (    s/   lib/python2.7/site-packages/sympy/core/rules.pyt   <module>   s   