ó
~9­\c           @   sØ   d  Z  d d l m Z d d l m Z m Z m Z m Z m Z m	 Z	 m
 Z
 m Z m Z m Z 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 d	 e f d
 „  ƒ  YZ d S(   s   
Physical quantities.
iÿÿÿÿ(   t   division(   t   Abst   Addt
   AtomicExprt   Basict
   Derivativet   Functiont   Mult   Powt   St   Symbolt   sympify(   t   string_types(   t	   Dimensiont
   dimensions(   t   dimsys_defaultt   DimensionSystem(   t   Prefix(   t   SymPyDeprecationWarningt   Quantityc           B   s  e  Z d  Z e Z e Z e Z e Z e Z	 d d d d d d d d „ Z i  Z i  Z d d „ Z d d „ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d	 „  Z d
 „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z e d „  ƒ Z RS(   sX   
    Physical quantity: can be a unit of measure, a constant or a generic quantity.
    c	      	   K   sw  t  | t ƒ s t | ƒ } n  t  | t ƒ rU t  | t ƒ rU | | | } } } n  | d  k	 r‰ t d d d d d d d d ƒ j ƒ  n  | d  k	 r½ t d d d d d d d d	 ƒ j ƒ  n  | d  k rÒ | } n t  | t ƒ rð t | ƒ } n  t j |  | | ƒ }
 | |
 _ | |
 _	 | |
 _
 | |
 _ | |
 _ | |
 _ | d  k	 rW|
 j | ƒ n  | d  k	 rs|
 j | ƒ n  |
 S(
   Nt   deprecated_since_versions   1.3t   issueiï7  t   features   Quantity argumentst
   useinsteadt   SI_quantity_dimension_mapt   SI_quantity_scale_factors(   t
   isinstanceR
   R   t   NoneR   t   warnR   t   __new__t   _namet   _abbrevt   _latex_reprt   _unicode_reprt   _ascii_reprt   _mathml_reprt   set_dimensiont   set_scale_factor(   t   clst   namet   abbrevt	   dimensiont   scale_factort
   latex_reprt   pretty_unicode_reprt   pretty_ascii_reprt   mathml_presentation_reprt   assumptionst   obj(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR      sB    							t   SIc         C   sÙ   d d l  m } m } | d k r1 t d ƒ ‚ n  | } t | t j ƒ ss | d k rd t d ƒ } qÈ t d ƒ ‚ nU xR | j j	 t ƒ D]> } | g  | j
 D] } | j ^ q™ k r† t d | ƒ ‚ q† q† W| t j |  <d  S(   Niÿÿÿÿ(   R   R   R1   s   Currently only SI is supportedi   s   expected dimension or 1sB   Dimension %s is not registered in the dimensional dependency tree.(   t   sympy.physics.units.dimensionsR   R   t   NotImplementedErrorR   R   R   t
   ValueErrorR'   t   atomst   _dimensional_dependenciesR   R   (   t   selfR)   t   unit_systemR   R   t   dim_syst   dim_symt   i(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR$   X   s    %c         C   sh   | d k r t  d ƒ ‚ n  t | ƒ } | j d „  d „  ƒ } | j d „  d „  ƒ } | t j |  <d  S(   NR1   s   Currently only SI is supportedc         S   s   t  |  t ƒ S(   N(   R   R   (   t   x(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyt   <lambda>t   t    c         S   s   |  j  S(   N(   R*   (   R<   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR=   t   R>   c         S   s   t  |  t ƒ S(   N(   R   R   (   R<   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR=   v   R>   c         S   s   |  j  S(   N(   R*   (   R<   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR=   v   R>   (   R3   R   t   replaceR   R   (   R7   R*   R8   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR%   m   s    c         C   s   |  j  S(   N(   R   (   R7   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR'   y   s    c         C   s   t  j |  S(   N(   R   R   (   R7   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR)   }   s    c         C   s   |  j  S(   s   
        Symbol representing the unit name.

        Prepend the abbreviation with the prefix symbol if it is defines.
        (   R   (   R7   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR(   ‚   s    c         C   s   t  j j |  t j ƒ S(   sW   
        Overall magnitude of the quantity as compared to the canonical units.
        (   R   R   t   getR	   t   One(   R7   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR*   ‹   s    c         C   s
   |  j  j S(   N(   R*   t   is_positive(   R7   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyt   _eval_is_positive’   s    c         C   s   |  j  j ƒ  S(   N(   R*   t   is_constant(   R7   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyt   _eval_is_constant•   s    c         C   sA   t  |  j ƒ } | |  j k r% |  Sn  t S|  j |  j |  j ƒ } (   N(   R   R*   R   t   funcR'   R(   (   R7   R*   t   q(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyt	   _eval_Abs˜   s
    c         C   s#   t  | t ƒ r |  | k r |  Sd  S(   N(   R   R   (   R7   t   oldt   new(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyt
   _eval_subsŸ   s    c         C   sU  t  |  t ƒ r8 t g  |  j D] } t j | ƒ ^ q Œ  St  |  t ƒ r^ t j |  j ƒ |  j St  |  t ƒ r t j |  j d ƒ St  |  t	 ƒ r× t j |  j
 ƒ } x. |  j D]# \ } } | t j | ƒ | } q¬ W| St  |  t ƒ r5g  |  j D] } t j | ƒ ^ qð } t d „  | Dƒ ƒ r(t j S|  j | Œ  St  |  t ƒ rN|  j j St j S(   Ni    c         s   s   |  ] } | d  k Vq d S(   i   N(    (   t   .0R;   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pys	   <genexpr>²   s    (   R   R   t   argsR   t   get_dimensional_exprR   t   baset   expR   R   t   exprt   variable_countR   t   allR	   RA   RF   R)   R'   (   RQ   R;   t   dimt   independentt   countt   argRM   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyRN   £   s&    )%
c         C   s›  t  |  t ƒ r |  j |  j f St  |  t ƒ r‡ d } t d ƒ } x: |  j D]/ } t j | ƒ \ } } | | 9} | | 9} qJ W| | f St  |  t ƒ rî t j |  j	 ƒ \ } } t j |  j
 ƒ \ } } | j rØ d } n  | | | | | f St  |  t ƒ rŠt j |  j d ƒ \ } } xd |  j d D]U }	 t j |	 ƒ \ }
 } | | k rrt d j |	 | j | j ƒ ƒ ‚ n  | |
 7} q'W| | f St  |  t ƒ r
t j |  j d ƒ \ } } xH |  j D]= \ } } t j | ƒ \ } } | | | } | | | } q¿W| | f St  |  t ƒ rng  |  j D] } t j | ƒ ^ q#} |  j d „  | Dƒ Œ  |  j d „  | Dƒ Œ  f St  |  t ƒ r‡d |  f S|  t d ƒ f Sd S(   s=   Return tuple with factor expression and dimension expression.i   i    s/   Dimension of "{0}" is {1}, but it should be {2}c         s   s   |  ] } | d  Vq d S(   i    N(    (   RL   t   f(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pys	   <genexpr>â   s    c         s   s   |  ] } | d  Vq d S(   i   N(    (   RL   t   d(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pys	   <genexpr>ã   s    N(   R   R   R*   R)   R   R   RM   t   _collect_factor_and_dimensionR   RO   RP   t   is_dimensionlessR   R4   t   formatR'   R   RR   R   RF   (   RQ   t   factorR)   RW   t
   arg_factort   arg_dimRT   t
   exp_factort   exp_dimt   addendt   addend_factort
   addend_dimRU   RV   t   ifactort   idimt   fds(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyRZ   ¹   sR    

		

"
c         C   sJ   |  j  r |  j  Sd j t |  j ƒ d k r8 |  j d n
 |  j d ƒ Sd  S(   Ns   \text{{{}}}i   i   i    (   R    R\   t   lenRM   (   R7   t   printer(    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyt   _latexé   s    	c         C   s   d d l  m } | |  | ƒ S(   s±  
        Convert the quantity to another quantity of same dimensions.

        Examples
        ========

        >>> from sympy.physics.units import speed_of_light, meter, second
        >>> speed_of_light
        speed_of_light
        >>> speed_of_light.convert_to(meter/second)
        299792458*meter/second

        >>> from sympy.physics.units import liter
        >>> liter.convert_to(meter**3)
        meter**3/1000
        i   (   t
   convert_to(   t   utilRk   (   R7   t   otherRk   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyRk   ð   s    c         C   s
   |  j  j S(   s"   Return free symbols from quantity.(   R*   t   free_symbols(   R7   (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyRn     s    N(   t   __name__t
   __module__t   __doc__t   Truet   is_commutativet   is_realt   Falset	   is_numbert
   is_nonzerot	   _diff_wrtR   R   R   R   R$   R%   t   propertyR'   R)   R(   R*   RC   RE   RH   RK   t   staticmethodRN   RZ   Rj   Rk   Rn   (    (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyR      s4   	5					0		N(   Rq   t
   __future__R    t   sympyR   R   R   R   R   R   R   R   R	   R
   R   t   sympy.core.compatibilityR   t   sympy.physics.unitsR   R   R2   R   R   t   sympy.physics.units.prefixesR   t   sympy.utilities.exceptionsR   R   (    (    (    s=   lib/python2.7/site-packages/sympy/physics/units/quantities.pyt   <module>   s   L