m
SGFc           @   sB  d  Z  h  d d <d d <d d <d d <d	 d
 <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d <d d  <d! d" <d# d$ <d% d& <d' d( <d) d* <d+ d, <d- d. <d/ d0 <Z h  Z x: e i   D], \ Z Z d1 e e f d2 Ue e d3 e <q We Z h  d d4 <d d5 <d d6 <d7 d8 <d9 d: <d d; <d< d= <d> d? <Z x, e i   D] \ Z Z d@ e e f d2 UqWe	 e
 e f \ Z Z Z d2 k Z e i dA  Z e e i e i dB  Z [ dC k l Z dD e f dE     YZ [ dF   Z dG   Z dH   Z dI   Z dJ   Z dK   Z dL   Z h  dM e <dN e <dO e <dP e <dQ e <dR e <dS e <Z [ [ [ [ [ [ dT   Z  dU   Z! dV   Z" dW k# l$ Z$ h  Z% dX e$ f dY     YZ& [ [ dZ   Z' e& e i( d[ e i( i  Z( e& e i)  Z) d e( d\  Z d2 S(]   sy   Objects to describe real quantities (with units of measurement).

$Id: quantity.py,v 1.47 2007/07/08 02:09:23 eddy Exp $
i   t   grouchii   t   harpii   t   yottai   t   zettai   t   exai   t   petai   t   terai	   t   gigai   t   megai   t   kiloi   t   hectoi   t   decait   deciit   centiit   milliit   microit   nanoit   picoit   femtoit   attoit   zeptoit   yoctoit   harpoit   grouchos	   %s = 1e%dNs   e%+dt   kibit   mebit   gibii   t   tebii   t   pebit   exbii   t   zebii   t   yobis   %s = 1024 ** %dc         C   s.   |  o | |   }  n |  o |  d Sn d  S(   Ns   
(   t   textt   strip(   R    R!   (    (    t*   /home/eddy/.sys/py/study/value/quantity.pyt	   _cleandocK   s      c         C   s  |  d  d j o |  d  |  d }	 }  n d }	 d } y | |  d  \ } } WnU t j
 oI y | |  d  \ } } Wn  t j
 o |  d } } q Xd } n X| |  } y | | d  \ } }
 Wn  t j
 o | d } }
 n X| d d j oT | d } | d j o
 d } n |
 o | |
 d  d |
 d } q| d } nO | d d j o= | d } | o | d
  d | d
 |
 } qd |
 } n | d j o~ | d d j om t |  d j o# | d d !d | d } d } q-| d j o& | d d d t |  } d } q-n | d
 d j o | d j o | d
  } n | oG d | } y | | } Wn t j
 o | | } qX| | } n d } |	 | | S(   s  Computes the representation of qSample.

    Arguments (both required, none more allowed):
      text -- preliminary representation of a number
      times -- the text to put between a number and a quantifier to serve as
               `multiplication' in the resulting string.

    Result has form [sign]digits[.digits][quantifier] where: quantifier may be,
    for instance, times + 'mega', meaning the appropriate power of 10, else it
    is explicitly [e[sign]digits], e.g. 'e6', an exponent; in which case the
    exponent is a multiple of three.  The mantissa, digits[.digits], is always
    in the range .1 to 1000 and only exceeds 100 if at least three significant
    digits are available and, by so doing, we can avoid the need for a
    [quantifier].  If the exponent is given as [e[sign]digits] and the
    representation is exact, the e will be an E, e.g. the integer 4000 is 4E3.
    Exact numbers will also elide their decimal point if it is the last
    character of the mantissa, rough ones are less likely to. i   s   -+t    t   et   Et   0t   .i   iii   s   .0i    i   s   e%+dN(   ii   (   ii   (   R    t   signt   gluet   splitt   headt   tailt
   ValueErrort   a2it   exponentt   upt   downt   lent   _e2qt   mult   KeyErrort   times(   R    R7   R4   R+   R/   R,   R*   R0   R1   R)   R2   R-   R5   (    (    R"   t   _massage_textO   s`           
 
 
 
 
  (   s   Samplet   qSamplec           B   s;   t  Z e i Z e d  Z e d  Z d   Z d   Z RS(   Nc         C   s   | |  i d  S(   Ns    * (   t   masht   selft   _sample_repr(   R;   t   ignoredR:   (    (    R"   t   _lazy_get__repr_   s    c         C   s   | |  i d  S(   Nt    (   R:   R;   R<   (   R;   R=   R:   (    (    R"   t   _lazy_get__str_   s    c         C   s   |  i d S(   Ni   (   R;   t   span(   R;   R=   (    (    R"   t   _lazy_get_high_   s    c         C   s   |  i d S(   Ni    (   R;   RA   (   R;   R=   (    (    R"   t   _lazy_get_low_   s    (	   t   __name__t
   __module__t   SampleR>   t   _lazy_get__sample_repr_R8   R@   RB   RC   (    (    (    R"   R9      s
   		c          C   s\  d  k  } d  k } d k l }	 l } d   } | i | i | d  }
 | i | i | d  } | i	 | i	 | d  } | i | i | d  } | d  }  | d  } | i | i | d	  } | i | i d
  d  } d   } | i | d  } | i | d  } | i | d  } h  d | |	 d  <d | |	 d  <d | i |	 d  <d | i |	 | i d d  <d | |	 d  <d | i |	 d  <d |
 d  <d | d   <d! | d"  <d# | d$  <d% | d&  <d' | d(  <d) | i d*  <d+ | i d,  <d- | i d.  <d/ | d0  <d1 | i | d2  <d3 d4   <S(5   N(   s   radians   secondc         C   s8   y | |   SWn# t t f j
 o | |   Sn Xd  S(   N(   t   st   valR.   t	   TypeErrort   c(   RI   RH   RK   (    (    R"   t   chose   s     c         C   s   | |  | |  S(   N(   RH   RI   t   xpt   px(   RI   RM   RN   RH   (    (    R"   t   exp   s    c         C   s   | |  | |  S(   N(   RH   RI   t   lgt   gl(   RI   RP   RQ   RH   (    (    R"   t   ln   s    c         C   s   | |  | |  S(   N(   RH   RI   t   act   ca(   RI   RS   RT   RH   (    (    R"   t   arccos   s    c         C   s   | |  | |  S(   N(   RH   RI   t   ast   sa(   RI   RV   RW   RH   (    (    R"   t   arcsin   s    c         C   s   | d |   S(   Nf1.0(   RS   RI   (   RI   RS   (    (    R"   t   arcsec   s    c         C   s   | d |   S(   Nf1.0(   RV   RI   (   RI   RV   (    (    R"   t   arccosec   s    c         C   s6   y | |  | |  |  SWn t j
 o d Sn Xd  S(   Ni   (   RK   RI   RH   t   ZeroDivisionError(   RI   RH   t   xRK   (    (    R"   t   sinc   s      i   c         C   s'   |  d j o |  | |   | Sn d S(   Ni    (   RI   RR   t   ln2(   RI   RR   R^   (    (    R"   t   Shannon   s     c         C   s#   |  i d d j o |  i Sn |  S(   Ni   (   RI   t   imagt   real(   RI   (    (    R"   t   simple   s     c         C   s   | | |    S(   N(   RH   RS   RI   (   RI   RS   RH   (    (    R"   t   arccosh   s    c         C   s   | | |    S(   N(   RH   RV   RI   (   RI   RV   RH   (    (    R"   t   arcsinh   s    c         C   s   | | |    S(   N(   RH   t   atRI   (   RI   Re   RH   (    (    R"   t   arctanh   s    t   arcCosc         C   s   | |  i |  S(   N(   t   rt   vt   evaluatet   a(   Ri   Rk   Rh   (    (    R"   t   <lambda>   s    t   arcSinc         C   s   | |  i |  S(   N(   Rh   Ri   Rj   Rk   (   Ri   Rk   Rh   (    (    R"   Rl      s    t   arcTanc         C   s   | |  i |  S(   N(   Rh   Ri   Rj   Rk   (   Ri   Rk   Rh   (    (    R"   Rl      s    t   arcCoTani   c         C   s   | | |  i |  S(   N(   Rh   t   qRi   Rj   Rk   (   Ri   Rk   Rh   Rp   (    (    R"   Rl      s    t   arcSecc         C   s   | |  i | d   S(   Nc         C   s   | d |   S(   Nf1.0(   t   fR\   (   R\   Rr   (    (    R"   Rl      s    (   Rh   Ri   Rj   Rk   (   Ri   Rk   Rh   (    (    R"   Rl      s    t   arcCoSecc         C   s   | |  i | d   S(   Nc         C   s   | d |   S(   Nf1.0(   Rr   R\   (   R\   Rr   (    (    R"   Rl      s    (   Rh   Ri   Rj   Rk   (   Ri   Rk   Rh   (    (    R"   Rl      s    RO   c         C   s   |  i |  S(   N(   Ri   Rj   R%   (   Ri   R%   (    (    R"   Rl      s    t   logc         C   s   |  i |  S(   N(   Ri   Rj   t   l(   Ri   Ru   (    (    R"   Rl      s    R_   c         C   s   |  i |  S(   N(   Ri   Rj   RH   (   Ri   RH   (    (    R"   Rl      s    Rc   c         C   s   |  i |  S(   N(   Ri   Rj   Rk   (   Ri   Rk   (    (    R"   Rl      s    Rd   c         C   s   |  i |  S(   N(   Ri   Rj   Rk   (   Ri   Rk   (    (    R"   Rl      s    Rf   c         C   s   |  i |  S(   N(   Ri   Rj   Rk   (   Ri   Rk   (    (    R"   Rl      s    t   coshc         C   s   |  i |  S(   N(   Ri   Rj   RK   (   Ri   RK   (    (    R"   Rl      s    t   sinhc         C   s   |  i |  S(   N(   Ri   Rj   RH   (   Ri   RH   (    (    R"   Rl      s    t   tanhc         C   s   |  i |  S(   N(   Ri   Rj   t   t(   Ri   Ry   (    (    R"   Rl      s    R]   c         C   s   |  i |  S(   N(   Ri   Rj   RH   (   Ri   RH   (    (    R"   Rl      s    t   Lorentzc         C   s   | |  i S(   N(   RK   Ri   Rx   (   Ri   RK   (    (    R"   Rl      s    t   Dopplerc         C   s
   |  i i S(   N(   Ri   Rt   Rz   (   Ri   (    (    R"   Rl      s    (   t   cmatht   matht   SIt   radiant   secondRL   RO   Rt   RR   t   acosRU   t   asinRX   RY   RZ   t   sinR]   R_   Rb   t   acoshRc   t   asinhRd   t   atanhRf   t   atant   piRv   Rw   Rx   t   light(   RY   RL   R_   RR   RZ   Rb   RX   R   R|   R   RO   RU   Rf   Rc   R]   R}   Rd   (    (    R"   t   scalar   s     		c          C   s   d k  l }  l } l } l } d k l } | d  } | | d  } h  d | | d  <d |  | d  <d	 | | d
  <d d   <d d   <d | d  <d | | d d  <d d   <S(   N(   s   coss   sins   tans   pi(   s   radianc         C   s   |  | i |  S(   N(   Rp   Rh   Rj   Rr   (   Rp   Rr   Rh   (    (    R"   t   angeval   s    c         C   s;   y |  | i |  |  SWn t j
 o d | Sn Xd  S(   Ni   (   RI   Rh   Rj   RH   R[   (   RI   Rh   RH   (    (    R"   R]      s      t   Sinc         C   s   | |  |  S(   N(   Rk   Ri   RH   (   Ri   RH   Rk   (    (    R"   Rl      s    t   Cosc         C   s   | |  |  S(   N(   Rk   Ri   RK   (   Ri   RK   Rk   (    (    R"   Rl      s    t   Tanc         C   s   | |  |  S(   N(   Rk   Ri   Ry   (   Ri   Ry   Rk   (    (    R"   Rl      s    t   Secc         C   s   d |  i S(   Nf1.0(   Ri   R   (   Ri   (    (    R"   Rl      s    t   CoSecc         C   s   d |  i S(   Nf1.0(   Ri   R   (   Ri   (    (    R"   Rl      s    t   SinCc         C   s
   | |   S(   N(   RH   Ri   (   Ri   RH   (    (    R"   Rl      s    t   CoTani   c         C   s   | |  i S(   N(   Rp   Ri   R   (   Ri   Rp   (    (    R"   Rl      s    t   iExpc         C   s   |  i d |  i S(   Nx0.01.0(   Ri   R   R   (   Ri   (    (    R"   Rl      s    (	   R}   t   cosR   t   tanR   R~   R   R   R]   (   R   R]   R   R   R   R   R   (    (    R"   t   angle   s
    c          C   s9   d k  l }  l } h  d |  i |  d  <d d   <S(   N(   s   seconds   radianRz   c         C   s   |  | i S(   N(   Ri   RK   Rf   (   Ri   RK   (    (    R"   Rl      s    R{   c         C   s
   |  i i S(   N(   Ri   Rz   RO   (   Ri   (    (    R"   Rl      s    (   R~   R   R   R   (   R   R   (    (    R"   t   speed   s    c          C   sa   d k  l } l } d | | d d  }  | i | d d  } h  d |  <d |  <d | <S(	   N(   s   seconds   metref9.8066499999999994i   c         C   s   |  | S(   N(   Ri   t   g(   Ri   R   (    (    R"   t   weigh  s    c         C   s   |  | S(   N(   Ri   t   cc(   Ri   R   (    (    R"   t   energy  s    t   weightt   forceR   (   R~   R   t   metreR   R   R   (   R   R   R   R   (    (    R"   t   mass   s    c          C   s1   d k  l }  |  i |  d d  } h  d | <S(   N(   s   secondi   c         C   s   |  | S(   N(   Ri   R   (   Ri   R   (    (    R"   R     s    R   (   R~   R   R   R   (   R   R   (    (    R"   R     s    c          C   s.   d k  l }  l } h  d d | |  d  <S(   N(   s   seconds   metreR   iJxc         C   s   |  | S(   N(   Ri   RK   (   Ri   RK   (    (    R"   Rl     s    (   R~   R   R   (   R   R   (    (    R"   t   time  s    c          C   sS   d k  l }  |  d  } d   } h  d | <d | <d | <d | <d | <S(	   N(   s   Kelvinc         C   s   |  | d S(   Nf273.16000000000003(   Ri   t   K(   Ri   R   (    (    R"   t   C  s    c         C   s   |  i d d S(   Nf1.8i    (   Ri   t   Celsius(   Ri   (    (    R"   t   F  s    t
   CentigradeR   R   t
   FahrenheitR   (   R~   t   KelvinR   R   (   R   R   R   (    (    R"   t   thermal  s    	R$   t   rads   m/st   kgRH   R   s   (m/s)**2.kgc         C   s   |  i   } | i |  | i   } h  } x | D]y } y |  | } Wn t	 j
 o d } n Xy | | } Wn t	 j
 o d } n X| | } | o | | | <q2 q2 W| S(   Ni    (   t   thist   copyt   copt   updatet   thatt   keyst   resultt   keyt   itR6   Re   t   sum(   R   R   R   R   R   R   R   Re   (    (    R"   t   adddict  s$         
 c         C   s   |  i   } | i |  | i   } h  } x | D]y } y |  | } Wn t	 j
 o d } n Xy | | } Wn t	 j
 o d } n X| | } | o | | | <q2 q2 W| S(   Ni    (   R   R   R   R   R   R   R   R   R   R6   Re   R   (   R   R   R   R   R   R   R   Re   (    (    R"   t   subdict/  s$         
 c         C   sn   h  } | o] y | i } Wn t j
 o n Xx7 |  i   D]% \ } } | o | | | | <q= q= Wn | S(   N(   R   t   scalet   mediant   AttributeErrort   dictt   itemsR   RI   (   R   R   RI   R   R   (    (    R"   t	   scaledict@  s       (   s   Objectt   Quantityc           B   s  t  Z e i Z h  d  d  d  d  d  Z d   Z d  d  d  Z d   Z d   Z	 e i
 Z d  d  Z
 d   Z d   Z e i Z d	   Z e h  h  d
  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d  k Z g  e i d  Z e i d  Z [ d   Z  d   Z! d   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d   Z( e( d  Z) e( d   Z* e( d!  Z+ e+ Z, e( d"  Z- e- Z. e( d#  Z/ [( d$   Z0 d%   Z1 d&   Z2 e2 Z3 Z4 Z5 Z6 Z7 Z8 Z9 Z: d'   Z; d(   Z< d)   Z= d*   Z> d+   Z? d,   Z@ d-   ZA d.   ZB d/   ZC d0   ZD d1   ZE d2 d3 d4 d  d  d5   eF iG d6  ZH d7   ZI d8   ZJ RS(9   Nc         O   s  t  |  i | |  t | t  o8 | i d j o | i	 } q[ | | i | i	 } } n t | t  o  t | | i	  | i } } n t | t  p t d |  } n! t | t  p t |  } n | o y | i   f  } }	 Wn" t t f j
 o | g }	 n Xx_ | D]W }
 |
 i	 | j o t d |
 |   n |	 o |	 i |
 i  q| i |
 i  qW|	 o t |	  } q| } n | d j	 o t |  } n | | | |  _ |  _	 |  _ |  i | p | | p |  d S(   sY  Initialises an object representing a quantity.

        Arguments:

          scale -- (a Quantity or) a scalar, e.g. integer, long or float: it
          must support addition with and multiplication by at least these types.

          [units] -- (a Quantity or) a dictionary with string keys and integer
          values, or a Quantity.  Each key names a unit of measurement: the
          whole dictionary represents the product of pow(key, units[key]) over
          all keys, so {'kg':1, 'm':2, 's':-2} denotes kg.m.m/s/s, aka the
          Joule.  If omitted, an empty dictionary is used (indicating a
          dimensionless quantity).

          [doc] -- a documentation string for the quantity (default None).
          This may alternatively be set by the .document(doc) method.

          [nom] -- a short name by which to refer to the quantity.

          [fullname] -- a long name (capitalised, if appropriate) for the
          quantity. [This and nom act as fall-backs for one another: if you give
          either of them, it serves as the default for the other.]

          [sample] -- a sequence of quantities which should be equal to this
          one.

        The first two arguments, scale and units, may be Quantity instances: in
        which case each contributes its scale and units to the new Quantity,
        effectively multiplicatively. i   t   bests   Sample of wrong dimensionsN(   t   applyR;   t   _Quantity__obinitt   argst   whatt
   isinstancet   unitsR   t   _Quantity__scalet   _Quantity__unitsR   R   RF   R9   t   sampleR   t   newt   rowRJ   R   RI   t   appendR   t   doct   NoneR#   t   __doc__t   _Quantity__namet   nomt   fullname(   R;   R   R   R   R   R   R   R   R   R   RI   R   (    (    R"   t   __init__U  s>             
 c         C   sO   |  i |  i } } t | t  o t t | i	 f | i
  } n t | |  S(   s   Returns a quantity in a primitive form.

        The primitive form doesn't try to use quantifiers when printing itself,
        or other fancy stuff.  This is intended for use by derived classes when
        sorting out their representations ... N(   R;   R   R   R   R   R   R9   R   RF   t   mirrort   dirR   (   R;   R   R   (    (    R"   t
   _primitive  s
     c         C   s,   | o | |  _ n | o | |  _ n d  S(   N(   R   R;   t   _short_name_R   t   _long_name_(   R;   R   R   (    (    R"   t   __name  s      c         C   sq   t  |  } | p d  Sn y |  i d } Wn t j
 o d  } n X| o | d | |  _ n
 | |  _ d  S(   NR   s   
(   R#   R   R;   t   __dict__t   oldR   R   R   (   R;   R   R   (    (    R"   t   document  s        c         C   s    |  i i |  i | d   d  S(   Nt   observe(   R;   R   R   t   _Quantity__addcheck_R   (   R;   R   (    (    R"   R     s    c         C   s%   |  i |  i i |  |  i i    S(   N(   R;   t   _Quantity__obcopyR   R   t   funcR   (   R;   R   (    (    R"   R     s    c         C   s   t  |  i |  i | d   S(   Nt   compare(   t   cmpR;   R   R   t   other(   R;   R   (    (    R"   t   __cmp__  s    c         C   sG   t  |  i  } x1 |  i i   D]  \ } } | | At  |  A} q W| S(   N(   t   hashR;   R   t   hR   R   t   kRi   (   R;   R=   R   Ri   R   (    (    R"   t   _lazy_get__lazy_hash_  s
     c         C   sH   |  i } y | | } Wn  t j
 o |  i |  Sn X| |   Sd  S(   N(   R;   t   _kind_lazy_propst   bokR   Rr   R6   t   _Quantity__lazy_late_(   R;   R   R   Rr   (    (    R"   t   _lazy_late_  s    	  c         C   sl   |  i } y | | SWn t j
 o n Xy | | } Wn t j
 o | } n X|   } | | | <| S(   N(	   R;   t	   _unit_strR   t   cacheR6   R   Rr   t   emptyR   (   R;   t   igR   R   R   Rr   R   R   (    (    R"   t   _lazy_get__kind_lazy_props_  s    	    	
c         C   s   |  i |  i i |  h   S(   s)  Return result of passing self to the given scalar function.

	Takes a single argument, a callable, typically a function such as
	math.exp which can only handle inputs of type scalar; returns the
	appropriate Quantity obtained by supplying self to this function; but
	raises TypeError unless self is dimensionless.  Result is always
	dimensionless.

	Note that self.copy(f) will do the corresponding thing but giving the
	result the same units as self, whatever these may be; .copy() makes no
	attempt to check whether what you asked for makes sense ... N(   R;   t	   _quantityt   _scalarR   Rr   (   R;   Rr   (    (    R"   Rj     s     c         C   s   t  |  i  S(   N(   t   floatR;   R   (   R;   (    (    R"   t	   __float__  s    c         C   s   t  |  i  S(   N(   t   longR;   R   (   R;   (    (    R"   t   __long__  s    c         C   s   t  |  i  S(   N(   t   intR;   R   (   R;   (    (    R"   t   __int__  s    c         C   s'   |  i o t d |  i   n |  i S(   Ns   not dimensionless(   R;   R   RJ   R   R   (   R;   R=   (    (    R"   t   _lazy_get__scalar_  s    
 c         C   s   d |  i j S(   Ni    (   R;   R   (   R;   (    (    R"   t   __nonzero__  s    c         C   sG   y |  i SWn t j
 o n X|  i d    } |  _ |  | _ | S(   Nc         C   s   |  S(   N(   R\   (   R\   (    (    R"   Rl     s    (   R;   t   _Quantity__negR   R   t   ans(   R;   R   (    (    R"   t   __neg__  s      	c         C   s;   y |  i SWn t j
 o n X|  i t  } |  _ | S(   N(   R;   t   _Quantity__absR   R   t   absR   (   R;   R   (    (    R"   t   __abs__  s      c         C   s   y> |  i | i j o  t | d |  i | i   n | i SWn> t j
 o2 |  i o t | d | |  i   n | Sn Xd S(   s  Checks for additive compatibility and unpacks.

        Arguments:

          other -- another quantity, which should have the same dimensions as
          self; may be a scalar iff self is dimensionless.

          why -- string, e.g. '+' or 'compare', describing what caller is doing:
          used in raising errors.

        Returns other's scalar aspect or raises a TypeError. s    with differing dimensionss(    between scalar and dimensioned quantityN(   R;   R   R   RJ   t   whyR   R   R   (   R;   R   R   (    (    R"   t   __addcheck_  s     


c         C   si   y | d } Wn- t j
 o! d k l } | i |  n X|  i |  i i | |  i
 | d   |  S(   sw  Returns the angle whose Cos and Sin are in the same ratio as self and other.

        Combines self, as the adjacent side, with its one argument, as the
        opposite side, of a right-angle triangle; they must have the same units,
        but we're not fussy what those are.  Returns the angle (as a Quantity,
        with units of angle) between the hypotenuse and self.
i    (   s   radiant   arcTan2N(   R   R   t
   IndexErrorR~   R   R;   R   R   t   joinR   R   R   (   R;   R   R   R   R   (    (    R"   R    s      c         C   s(   |  i |  i i | |  i | d    S(   Nt
   Hypotenuse(   R;   t   _Quantity__kinR   R  R   R   R   (   R;   R   R   (    (    R"   t   __hypot.  s    c         G   s*   |  } x | D] } | i |  } q W| S(   N(   R;   RI   t   othersR   t   _Quantity__hypot(   R;   R  R   RI   (    (    R"   R  3  s
     c         C   s   |  i | |  i  S(   N(   R;   R   R   R   (   R;   R   (    (    R"   t   __kin:  s    c         C   s    |  i |  i |  i | d   S(   Nt   +(   R;   R  R   R   R   (   R;   R   (    (    R"   t   __add__<  s    c         C   s    |  i |  i |  i | d   S(   Nt   -(   R;   R  R   R   R   (   R;   R   (    (    R"   t   __sub__=  s    c         C   s    |  i |  i |  i | d   S(   Nt   %(   R;   R  R   R   R   (   R;   R   (    (    R"   t   __mod__>  s    c         C   s    |  i |  i | d  |  i  S(   NR  (   R;   R  R   R   R   (   R;   R   (    (    R"   t   __radd__@  s    c         C   s    |  i |  i | d  |  i  S(   NR  (   R;   R  R   R   R   (   R;   R   (    (    R"   t   __rsub__A  s    c         C   s    |  i |  i | d  |  i  S(   NR  (   R;   R  R   R   R   (   R;   R   (    (    R"   t   __rmod__B  s    c         C   s.   t  |  t  o |  i |  i f Sn |  h  f S(   N(   R   R   R   R   R   (   R   (    (    R"   t   unpackE  s    c         C   s5   | |  \ } } |  i |  i | t |  i |   S(   N(	   t   grabR   t   ott   herR;   R   R   R   R   (   R;   R   R  R  R  (    (    R"   t   __mul__J  s    c         C   s5   | |  \ } } |  i | |  i t | |  i   S(   N(	   R  R   R  R  R;   R   R   R   R   (   R;   R   R  R  R  (    (    R"   t   __rmul__N  s    c         C   sI   | |  \ } } | p t |  n |  i |  i | t |  i	 |   S(   N(
   R  R   R  R  R[   R;   R   R   R   R   (   R;   R   R  R  R  (    (    R"   t   __div__R  s     c         C   s5   | |  \ } } |  i | |  i t | |  i   S(   N(	   R  R   R  R  R;   R   R   R   R   (   R;   R   R  R  R  (    (    R"   t   __rdiv__X  s    c         C   sT   | |  \ } } | o t d |   n |  i t |  i |  t	 |  i
 |   S(   Ns   raising to a dimensioned power(   R  R   t   whRe   RJ   R;   R   t   powR   R   R   (   R;   R   R  R  Re   (    (    R"   t   __pow__]  s     c         C   s   |  i } | i | i | i S(   N(   R;   R   RH   t   hight   lowR   (   R;   R=   RH   (    (    R"   t   _lazy_get_accuracy_f  s    	c         C   s4   |  i i \ } } t | |  i  t | |  i  f S(   N(   R;   R   RA   t   lot   hiR   R   (   R;   R   R"  R#  (    (    R"   t   _lazy_get_span_k  s    c         C   s"   t  |  i |  } t | |  i  S(   sH   generic method for statistics, packaging those for __scale with __units N(   t   getattrR;   R   t   whicht   statR   R   (   R;   R&  R'  (    (    R"   t   _lazy_get_best_o  s     c         C   s
   |  i i S(   N(   R;   R   t	   dispersal(   R;   R=   (    (    R"   t   _lazy_get_dispersal_x  s    c         C   s"   |  i |  i i t |  i d   S(   Ni   (   R;   R   R   t   varianceR   R   (   R;   R=   (    (    R"   t   _lazy_get_variance_y  s    c         C   s   |  i S(   N(   R;   t	   _full_str(   R;   (    (    R"   t   __str__~  s    c         C   s
   |  i   S(   N(   R;   t   unit_string(   R;   R=   (    (    R"   t   _lazy_get__unit_str_  s    c         C   s   t  |  i  p d S(   Nt   ?(   t   strR;   R   (   R;   R=   (    (    R"   t   _lazy_get__number_str_  s    c         C   s   |  i S(   N(   R;   t
   _full_repr(   R;   (    (    R"   t   __repr__  s    c         C   s   |  i S(   N(   R;   R   (   R;   R=   (    (    R"   t   _lazy_get__number_repr_  s    c         C   sb   h  } xU |  i i   D]D \ } } y | | i |  Wq t j
 o | g | | <q Xq W| S(   N(   t   powsR;   R   R   R   RI   R   R6   (   R;   R=   RI   R7  R   (    (    R"   t   _lazy_get__quantity_stinu_bok_  s       c         C   s   |  i |  i } } | d  d j o | | Sn | p | Sn y2 h  d d <d d <d d <d d <| } Wn\ t j
 oP | d	 d
 j o
 d } q d | j p | d	 d j o
 d } q d } n Xd } | | | S(   Ni   t   /s   -1R  s   -1.t   1R$   s   1.is   . 	
R(   t
   0123456789R?   (   R;   R   t   _number_strt   unit   numR6   t   pad(   R;   R=   R>  R?  R=  (    (    R"   t   _lazy_get__full_str_  s       2 
 
c         C   s=   t  d  } |  i d |  i d d d d d d d	 d
 d |  S(   Nc         C   sV   g  } xI |  D]A } y | i | | i  Wq t j
 o | i |  q Xq W| S(   N(   t   outR   R   R   Ru   R   R6   (   R   Ru   R   RA  (    (    R"   t   lookup  s       R   R7   t   *t   Timess    * t   divideR9  t   Divides    / t   lookemup(   t   _terse_dictRB  R;   R/  t   _number_repr(   R;   R=   RB  (    (    R"   t   _lazy_get__full_repr_  s
    c         C   s   |  i i   } | i   | i   x d | j o | i d  q& WxE | D]< } | d j  o Pn x! | | j o | i |  qh WqM Wt |  S(   Ni    (	   R;   t   _quantity_stinu_bokR   t   valst   sortt   reverset   removeRI   t   tuple(   R;   R=   RL  RI   (    (    R"   t   _lazy_get__quantity_stinu_skey_  s    

      R$   R(   R9  c         C   s   |  S(   N(   Rh   (   Rh   (    (    R"   Rl     s    c         C   s  | d j o
 | } n | p
 | } n t |  d }	 } |  i
 } x|  i D]} | d j o  |	 p | o | | } q n | d j  o | | } n qN | | |  }
 t |
  | |
 |  d } } } y | | |  } Wn t j
 o n0 X| o' | | | |  } | t |  } n | d j o! | d j o d | | f } n | | } t |  } | d j o} y6 y t |  } Wn t j
 o t |  } n XWn t t f j
 o n X| | j o
 | } n d | | f } n | | } qN W|	 | S(   sH  Generates representations of a quantity.

        All arguments are optional and should be given by name when given.

          scale -- a prefix string to which to join the unit representation
          built by this routine: in particular, if given, it will be joined to
          this unit representation by a suitable times or divide operator.  If a
          non-string is given for scale, its repr() is used.

          times, divide -- strings, default '.' and '/', to be used to denote
          multiplication and division in compact texts, e.g. kg.m/s.

          Times, Divide -- strings, defaulting to times and divide, to be used
          to denote multiplication and division in spread-out texts,
          e.g. kg.m / s^2^.

          lookemup -- a function taking a sequence of strings and returning a
          similar sequence in which each string may have been replaced with an
          alternative: typically, the strings in the input list will be short
          names of units, to be converted to long names where known,
          e.g. [ kg ] -> [ kilogramme ], or vice versa.

        I hope to be able to do something smarter when I can see when to say J
        rather than kg.m.m/s/s, and etc.  But that will probably involve
        creating a units base-class to replace the present _quantity_unit_bok
        dictionary. R$   i    i   s   (%s%s)s   %s**%sN(   RD  R   R7   RF  RE  R2  R   R,   R-   R;   RK  R7  t   _quantity_stinu_skeyt   pRG  R   R3   R  t   langt   topt   bott   worR6   t   moreR   R   t   ipt   OverflowErrorR   R   R.   (   R;   R   R7   RE  RD  RF  RG  R  RY  R,   R   RW  R-   RX  RT  R7  RV  RS  RU  (    (    R"   R/    sR      
 
	
   #   
    
c         C   s-   y |  i | SWn t j
 o d Sn Xd  S(   Ni    (   R;   R   t   unitR6   (   R;   R[  (    (    R"   t   _unit_order  s      c         C   s   |  i | |  S(   N(   R;   t	   __class__R   R   (   R;   R   R   (    (    R"   R     s    (K   RD   RE   t   ObjectR   R   R   R   R   R   R   R   R   R   R   R   R   t   kind_prop_lookupR   Rj   R   R   R   R   R   R   R   R   R}   t   atan2R  t   hypotR	  R  R  R  R  R  R  R  R  R  R  R  R  t   __truediv__R  t   __rtruediv__R  R!  R$  R(  RC   RB   t   _lazy_get_width_t   _lazy_get_errors_t   _lazy_get_median_t   _lazy_get_mean_t   _lazy_get_mode_t   _lazy_get_dispersor_R*  R,  R.  R0  R3  R5  R6  R8  R@  RJ  RQ  t   stringt
   joinfieldsR/  R\  R   (    (    (    R"   R   R  sz   	H																															"												$Q	c         K   s8   t  t d h  |  d <| |  | f |  } | t |  <| S(   Ni   (   R   R   R   R   R   R   R   RH  (   R   R   R   R   R   (    (    R"   t	   base_unit  s    *
R   c         C   s   |  | | S(   N(   t   midt   tolt   flat(   Rm  Rn  Ro  (    (    R"   R   #  s    (*   R   t   _quantifier_dictionaryt   _exponent_to_quantifierR   t   _keyt   _valR   t   dekat   _pow1024_dictionaryR   R   R   t   Kit   Mit   GiRj  R!   R#   R+   t   atoiR8   R   RF   R9   R   R   R   R   R   R   R   R_  R   R   R   t   objectR^  RH  R   Rl  t   tophatt   upward(    R9   Rs  R   R   R   R   Rq  R   R   R   R^  Rt  R   RH  Rj  R#   Rl  Rv  Rw  R_  Ru  R   R   R8   Rr  R   RF   Rp  R   R{  Rx  R|  (    (    R"   R1     sP   " N 	N	8						E			 	