
uPc           @   s   d  d l  m Z d  d l Z d  d l Z d  d l Z d   Z d   Z d   Z d d  Z d   Z	 d	   Z
 d
   Z d   Z d d  Z d   Z d   Z d   Z d   Z d S(   i(   t   divisionNc         C   sU   |  d k r d S|  d k r  |  Sd } x$ |  d k rL | |  9} |  d 8}  q) W| Sd S(   s   fact(n): Computes n factorial.i    i   N(    (   t   nt   prod(    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   fact   s    
c         C   sB   |  d k r d S|  d k r  d S|  d k r0 d S|  t  |  d  S(   s   dfact(n): Computes n factorial.i    i   ii   (   t   dfact(   R   (    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyR   &   s    c         C   s   | |  k r d S| d k  r  d S| t  |  d  k rC |  | } n  d } x3 t d |  D]" } | |  | 9} | | d } qY Wt  |  S(   s    binc(n, k): Computes n choose k.i    i   i   (   t   intt   range(   R   t   kt   rvt   j(    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   binc2   s      s   %11.7fc         C   s(   d | } x |  D] } | | Gq WHd S(   s!   printf_row(list, optional format)t    N(    (   t   rowt   fmtt   fmt_with_spacet   e(    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt
   printf_row@   s    
c         C   s   |  d 9}  | d 9} | d 9} t  t | |  |   d } d g | } |  } x+ t d |  D] } | | | <| | 7} q_ W| S(   sA   mfrange(start, step, end):  Similar to Matlab's [start:step:end].g      ?i   i    N(   R   t   roundt   Nonet   xrange(   t   startt   stept   endR   t   listt   currentt   i(    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   mfrangeI   s    



c         C   sc   |  d 9}  | d 9} | |  | } g  } |  } x. t  d |  D] } | j |  | | 7} q> W| S(   sC   frange(start, end, n):  Python's range(), for floats and complexes.g      ?i    (   R   t   append(   R   R   R   R   R   R   R   (    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   frangea   s    

c         C   sg   |  d 9}  | d 9} | |  d | } g  } |  } x. t  d |  D] } | j |  | | 9} qB W| S(   s=   mulfrange(start, end, n):  multiplicative range() for floats.g      ?i    (   R   R   (   R   R   R   R   R   R   R   (    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt	   mulfranget   s    

c         C   s   t  j |  j |  j  S(   s.   cphase(c):  returns complex phase: (-pi, +pi].(   t   matht   atan2t   imagt   real(   t   c(    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   cphase   s    i    y                c         C   sc   | d 9} | d 9} g  } t  | | |  } x0 | D]( } | j | |  t j d |   q3 W| S(   sV   ztrange(R, start_theta, end_theta, n):  R exp(i theta) for fixed R
	and varying theta.g      ?y              ?(   R   R   t   cmatht   exp(   t   Rt   start_thetat	   end_thetaR   t   centerR   t   thetast   theta(    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   ztrange   s    

&c         C   s_   |  d 9}  | d 9} g  } t  |  | |  } x, | D]$ } | j | t j d |   q3 W| S(   sR   ztrange(start_R, end_R, theta, n):  R exp(i theta) for varying R
	and fixed theta.g      ?y              ?(   R   R   R$   R%   (   t   start_Rt   end_RR+   R   R   t   RsR&   (    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   zrrange   s    

"c         C   s   d } t  |  } t |  |  } xM t d | d  D]8 } | d | | | | d | | d | | 7} q5 W| | | d | | d | | d 7} | S(   sF   numint(f, xarray):  Naive numerical integration for float and complex.i    i   g      ?i   (   t   lent   mapR   (   t   ft   xst   sumR   t   ysR   (    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   numint   s    6*c   	      C   s  t  |  } g  } | d } | d } |  |  } |  |  } | j | | | |  xh t d | d  D]S } | | d } | | d } |  |  } |  |  } | j | | | |  qk W| | d } | | d } |  |  } |  |  } | j | | | |  | S(   s0   numderiv(f, xarray):  Numerical differentiation.i    i   i   (   R1   R   R   (	   R3   R4   R   R   t   x0t   x1t   y0t   y1R   (    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   numderiv   s&    
 
     c         C   s;   g  } x. |  D]& } | j  | j  | j  | j  q W| S(   N(   R   R!   R    (   t   csR   R"   (    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   clist_to_rlist   s
    y                (   t
   __future__R    t   sysR   R$   R   R   R
   R   R   R   R   R#   R,   R0   R7   R<   R>   (    (    (    sD   /homepages/25/d321765456/htdocs/pub_http_internet/python/kerlutil.pyt   <module>   s    											