ó
¡¼™\c           @  sX   d  Z  d d l m Z m Z d d l m Z d e f d „  ƒ  YZ d „  Z d „  Z	 d S(	   sñ  
Interval Arithmetic for plotting.
This module does not implement interval arithmetic accurately and
hence cannot be used for purposes other than plotting. If you want
to use interval arithmetic, use mpmath's interval arithmetic.

The module implements interval arithmetic using numpy and
python floating points. The rounding up and down is not handled
and hence this is not an accurate implementation of interval
arithmetic.

The module uses numpy for speed which cannot be achieved with mpmath.
iÿÿÿÿ(   t   print_functiont   division(   t	   nsimplifyt   intervalc           B  sø   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ 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 e Z d „  Z d „  Z d „  Z e Z e Z d „  Z d „  Z d „  Z RS(   s    Represents an interval containing floating points as start and
    end of the interval
    The is_valid variable tracks whether the interval obtained as the
    result of the function is in the domain and is continuous.
    - True: Represents the interval result of a function is continuous and
            in the domain of the function.
    - False: The interval argument of the function was not in the domain of
             the function, hence the is_valid of the result interval is False
    - None: The function was not continuous over the interval or
            the function's argument interval is partly in the domain of the
            function

    The comparison of two intervals returns a tuple of two 3-valued logic
    values.

    The first value determines the comparison as follows:
    - True: If the comparison is True throughout the intervals.
    - False: If the comparison is False throughout the intervals.
    - None: If the comparison is True for some part of the intervals.

    The second value is determined as follows:
    - True: If both the intervals in comparison are valid.
    - False: If at least one of the intervals is False, else
    - None
    c         O  s  | j  d t ƒ |  _ t | ƒ d k r‡ t | d t ƒ r^ | d j | d j |  _ |  _ qt | d ƒ |  _ t | d ƒ |  _ n„ t | ƒ d k rÿ | d | d k  rÖ t | d ƒ |  _ t | d ƒ |  _ qt | d ƒ |  _ t | d ƒ |  _ n t	 d ƒ ‚ d  S(   Nt   is_validi   i    i   s9   interval takes a maximum of two float values as arguments(
   t   popt   TrueR   t   lent
   isinstanceR   t   startt   endt   floatt
   ValueError(   t   selft   argst   kwargs(    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __init__B   s    $c         C  s   |  j  |  j d S(   Ng       @(   R	   R
   (   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   midV   s    c         C  s   |  j  |  j S(   N(   R
   R	   (   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   widthZ   s    c         C  s   d |  j  |  j f S(   Ns   interval(%f, %f)(   R	   R
   (   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __repr__^   s    c         C  s   d |  j  |  j f S(   Ns   [%f, %f](   R	   R
   (   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __str__a   s    c         C  s
  t  | t t f ƒ r] |  j | k  r1 t |  j f S|  j | k rM t |  j f Sd  |  j f Sn© t  | t	 ƒ r|  j t k sŠ | j t k r“ t } n- |  j d  k s± | j d  k rº d  } n t } |  j | j k  rÜ t | f S|  j | j k rø t | f Sd  | f St
 Sd  S(   N(   R   t   intR   R
   R   R   R	   t   Falset   NoneR   t   NotImplemented(   R   t   othert   valid(    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __lt__d   s$    		


c         C  s   t  | t t f ƒ r] |  j | k r1 t |  j f S|  j | k  rM t |  j f Sd  |  j f Sn  t  | t	 ƒ ry | j
 |  ƒ St Sd  S(   N(   R   R   R   R	   R   R   R
   R   R   R   R   R   (   R   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __gt__|   s    c         C  s2  t  | t t f ƒ ri |  j | k r@ |  j | k r@ t |  j f S| |  k rY d  |  j f St |  j f Sn  t  | t	 ƒ r*|  j t k s– | j t k rŸ t } n- |  j d  k s½ | j d  k rÆ d  } n t } |  j | j k rú |  j | j k rú t | f S|  j
 | ƒ d d  k	 rt | f Sd  | f Sn t Sd  S(   Ni    (   R   R   R   R	   R
   R   R   R   R   R   R   R   (   R   R   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __eq__‰   s$    		$

c         C  s/  t  | t t f ƒ ri |  j | k r@ |  j | k r@ t |  j f S| |  k rY d  |  j f St |  j f Sn  t  | t	 ƒ r'|  j t k s– | j t k rŸ t } n- |  j d  k s½ | j d  k rÆ d  } n t } |  j | j k rú |  j | j k rú t | f S|  j
 | ƒ d d  k	 rt | f Sd  | f St Sd  S(   Ni    (   R   R   R   R	   R
   R   R   R   R   R   R   R   (   R   R   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __ne__¢   s$    		$


c         C  s
  t  | t t f ƒ r] |  j | k r1 t |  j f S|  j | k rM t |  j f Sd  |  j f Sn  t  | t	 ƒ r|  j t k sŠ | j t k r“ t } n- |  j d  k s± | j d  k rº d  } n t } |  j | j k rÜ t | f S|  j | j k rø t | f Sd  | f St
 Sd  S(   N(   R   R   R   R
   R   R   R	   R   R   R   R   (   R   R   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __le__º   s$    		


c         C  s}   t  | t t f ƒ r] |  j | k r1 t |  j f S|  j | k  rM t |  j f Sd  |  j f Sn t  | t	 ƒ ry | j
 |  ƒ Sd  S(   N(   R   R   R   R	   R   R   R
   R   R   R   R   (   R   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __ge__Ò   s    c         C  s	  t  | t t f ƒ rl |  j r9 t |  j | |  j | ƒ S|  j | } |  j | } t | | d |  j ƒSn™ t  | t ƒ r|  j | j } |  j | j } |  j rº | j rº t | | ƒ S|  j t k sØ | j t k rë t | | d t ƒSt | | d d  ƒSn t	 Sd  S(   NR   (
   R   R   R   R   R   R	   R
   R   R   R   (   R   R   R	   R
   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __add__Ý   s    	c         C  sö   t  | t t f ƒ rE |  j | } |  j | } t | | d |  j ƒSt  | t ƒ rî |  j | j } |  j | j } |  j r§ | j r§ t |  j | j |  j | j ƒ S|  j t k sÅ | j t k rØ t | | d t ƒSt | | d d  ƒSn t	 Sd  S(   NR   (
   R   R   R   R	   R
   R   R   R   R   R   (   R   R   R	   R
   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __sub__ô   s    !c         C  si   t  | t t f ƒ rE | |  j } | |  j } t | | d |  j ƒSt  | t ƒ ra | j |  ƒ St Sd  S(   NR   (	   R   R   R   R
   R	   R   R   R"   R   (   R   R   R	   R
   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __rsub__  s    c         C  s@   |  j  r t |  j |  j ƒ St |  j |  j d |  j  ƒSd  S(   NR   (   R   R   R
   R	   (   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __neg__  s    	c         C  sV  t  | t ƒ r|  j t k s- | j t k rM t t d ƒ t d ƒ d t ƒS|  j d  k sk | j d  k r‹ t t d ƒ t d ƒ d d  ƒSg  } | j |  j | j ƒ | j |  j | j ƒ | j |  j | j ƒ | j |  j | j ƒ t	 | ƒ } t
 | ƒ } t | | ƒ Sn= t  | t t f ƒ rNt |  j | |  j | d |  j ƒSt Sd  S(   Nt   infR   (   R   R   R   R   R   R   t   appendR	   R
   t   mint   maxR   R   (   R   R   t   intersR	   R
   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __mul__  s       $c         C  sW   t  | t t f ƒ r1 |  j | k o0 |  j | k S|  j | j k oR | j |  j k Sd  S(   N(   R   R   R   R	   R
   (   R   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __contains__,  s    c         C  sR   t  | t t f ƒ r. t | ƒ } | j |  ƒ St  | t ƒ rJ | j |  ƒ St Sd  S(   N(   R   R   R   R   t   __div__R   (   R   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __rdiv__2  s    c         C  sú  |  j  s, t t d ƒ t d ƒ d |  j  ƒSt | t t f ƒ r‹ | d k rm t t d ƒ t d ƒ d t ƒSt |  j | |  j | ƒ Snkt | t ƒ rò| j  t k s¸ |  j  t k rØ t t d ƒ t d ƒ d t ƒS| j  d  k sö |  j  d  k rt t d ƒ t d ƒ d d  ƒSd | k rBt t d ƒ t d ƒ d d  ƒS|  } | j d k  rh| } | } n  g  } | j	 | j | j ƒ | j	 | j | j ƒ | j	 | j | j ƒ | j	 | j | j ƒ t
 | ƒ } t | ƒ } t | | ƒ Sn t Sd  S(   NR%   R   i    (   R   R   R   R   R   R   R	   R
   R   R&   R(   R'   R   (   R   R   t   thisR)   R	   R
   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyR,   ;  s4    	#    
c         C  sµ   d d l  m } m } |  j s# |  St | t ƒ rF | | | |  ƒ ƒ St | t t f ƒ r­ | d k  r~ d |  j t	 | ƒ ƒ St | ƒ | k r t
 |  | ƒ St |  | ƒ Sn t Sd  S(   Ni   (   t   expt   logi    (   t   lib_intervalR/   R0   R   R   R   R   R   t   __pow__t   abst   _pow_intt
   _pow_floatR   (   R   R   R/   R0   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyR2   g  s    	c         C  s  t  | t t f ƒ rö |  j s" |  S| d k  rØ |  j d k r] t t d ƒ t d ƒ d t ƒSt |  j ƒ } | j	 ƒ  \ } } | d d k r® t t d ƒ t d ƒ d t ƒSt
 | ƒ |  j } | } t | | ƒ Sqt | |  j | |  j ƒ Sn  t  | t ƒ r| j |  ƒ St Sd  S(   Ni    R%   R   i   (   R   R   R   R   R   R   R   R   R	   t   as_numer_denomR3   R
   R2   R   (   R   R   t   power_rationalt   numt   denomR	   R
   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __rpow__y  s$    	 c         C  s   t  |  j |  j |  j f ƒ S(   N(   t   hashR   R	   R
   (   R   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   __hash__’  s    (   t   __name__t
   __module__t   __doc__R   t   propertyR   R   R   R   R   R   R   R   R   R    R!   t   __radd__R"   R#   R$   R*   t   __rmul__R+   R-   R,   t   __truediv__t   __rtruediv__R2   R:   R<   (    (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyR   '   s6   												
						)		c         C  s”  t  | ƒ } | j ƒ  \ } } | d d k rŽ t |  j ƒ | } t |  j ƒ | } | d k  r{ t d t | | ƒ ƒ } n t | | ƒ } | S| d d k r|  j d k  rÍ t t d ƒ t d ƒ d t ƒS|  j d k  rö t d |  j | d d ƒSt |  j | |  j | ƒ Sn| |  j d k  r:t |  j ƒ | } n |  j | } |  j d k  rmt |  j ƒ | } n |  j | } t | | d |  j
 ƒSd S(   s1   Evaluates an interval raised to a floating point.i   i    R%   R   N(   R   R6   R3   R	   R
   R   R(   R   R   R   R   (   t   intert   powerR7   R8   R9   R	   R
   t   ret(    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyR5   –  s,     c         C  sž   t  | ƒ } | d @r1 t |  j | |  j | ƒ S|  j d k  r |  j d k r d } t |  j | |  j | ƒ } t | | ƒ St |  j | |  j | ƒ Sd S(   s0   Evaluates an interval raised to an integer poweri   i    N(   R   R   R	   R
   R(   (   RE   RF   R	   R
   (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyR4   ·  s    
N(
   R?   t
   __future__R    R   t   sympy.simplify.simplifyR   t   objectR   R5   R4   (    (    (    sN   lib/python2.7/site-packages/sympy/plotting/intervalmath/interval_arithmetic.pyt   <module>   s   ÿ p	!