ó
k™xTc           @   sr   d  Z  d d l m Z d d l Z d „  Z e d „ Z e d k rn d d l Z e d e j	 d k ƒ d	 GHn  d S(
   s  
Approximating Log(BesselK[1/4,x]) using a Pade form.
Coefficients were fitted with gnuplot on numbers obtained from mathematica.

f(x) = (a0+a1*x+a2*x*x+a3*x*x*x+a4*x**4)/(1+b1*x+b2*x*x+b3*x*x*x+b4*x**4+b5*x**5)

The total range has been split in 3 regions:
0<x<=0.1 : Pade approx, 5+6 terms
0.1<x<=10: Pade approx, 4+5 terms
10<x<infty: Linear approx, 2 terms

No efforst have been made to ensure continuity, nor a rigorous error analyses has been
carried out. The error should be lower then a 5% over the x range 1E-4 to 100.
iÿÿÿÿ(   t   divisionNc         C   sæ   d  } d „  } |  d k  r% |  }  n  |  d k  rs d d d d d g } d	 d
 d d d d g } | | | |  ƒ } n  |  d k |  d k  @rÅ d d d d g } d	 d d d d g } | | | |  ƒ } n  |  d k râ d d |  } n  | S(   Nc         S   sx   d } d } x, t  |  ƒ D] \ } } | | | | 7} q Wx, t  | ƒ D] \ } } | | | | 7} qH W| | } | S(   sB    This computes an empirical pade approximation given coefficients i    (   t	   enumerate(   t   a_arrt   b_arrt   xt   topt   bottomt   nt   coeft   result(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/besselk.pyt   funct   s    
i    gš™™™™™¹?gLàÖÝü@gÍÌÌÌ4aø@g    CÈšAg   C^ÀûAg  ÀÀ§ -Âi   gffffV“à@g    ÐˆAg   QàVóAg   ^ßŽ Âg  @bÕMÂi
   g‚çÞÃ%Çú?g2ÉÈY¸@gfffffÆ+ÀgY†8ÖÅMÀgòAÏfÕ‡#@g¢—Q,·”@g
	bêøy¡?g ™Þ ^_N¿g;Sè¼Æ®ñ¿g"lxz¥,ð¿(   t   None(   R   R	   R
   t   at   b(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/besselk.pyt   log_besselk_1_4   s    	
c         C   s°   d d d d d d g } d d d	 d
 d d g } xy t  | | ƒ D]h \ } } t | ƒ } |  r„ | G| G| Gd t | | | ƒ GHn  t | | | ƒ d d k  s@ t ‚ q@ Wd  S(   Ng{®Gáz„?gš™™™™™©?gš™™™™™¹?g      à?g      @i2   g&�Ñ:ªý?gTÆ¿Ï¸pô?gÕz¿ÑŽ›ï?gzpwÖn»¤¿g•Ô	hbÀgh³êsµÝIÀid   g      Y@g       @(   t   zipR   t   abst   AssertionError(   t   debugt   xxt   yyR   t   yt   f(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/besselk.pyt   test2   s     &t   __main__s   -debugi   t   OK(
   t   __doc__t
   __future__R    t   libtbxR   t   FalseR   t   __name__t   syst   argv(    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/scitbx/math/besselk.pyt   <module>   s   		