ó
~9­\c           @  s  d  d l  m Z 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 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 d d l m Z m Z m Z m Z d  d l  Z  d „  Z! d	 „  Z" d
 „  Z# e$ d „ Z% d g Z& d S(   iÿÿÿÿ(   t   print_functiont   division(   t   fzerot   from_man_expt   from_intt   from_rationalt   fonet   fhalft   bitcountt   to_intt   to_strt   mpf_mult   mpf_divt   mpf_subt   mpf_addt   mpf_sqrtt   mpf_pit   mpf_cosh_sinht   pi_fixedt   mpf_cost   mpf_sin(   t   igcd(   t   rangei   (   t   _sqrt_mod_prime_powert   legendre_symbolt   jacobi_symbolt   is_quad_residueNc          C  s:  d }  d g |  a  d g |  a t |  d ƒ d } xh t d | ƒ D]W } t  | d k rD x> t | | |  | ƒ D]# } t  | d k rq | t  | <qq qq WqD qD Wx” t d |  ƒ D]ƒ } t  | d k rã | t  | <| d t | <q¯ n  t  | } | | } | | d k rt | | t | <q¯ t | | d t | <q¯ Wd  S(   Ni
   i   i    i   g      à?i   i † (   t   _factort   _totientt   intR   (   t   maxnt   limt   it   jt   xt   y(    (    s8   lib/python2.7/site-packages/sympy/ntheory/partitions_.pyt   _pre   s&    


c         C  s€  | d k r t  S| } d } t | } x( | | d k rP | | } | d 7} q) W| | } d d |  } t | ƒ } | d k rx| d k rZd | }	 |	 | |	 } | t d | d |	 ƒ |	 } t | d | d ƒ d }
 t t t d |
 ƒ | | ƒ t |	 ƒ | ƒ } t t t d	 | t |
 d |
 ƒ ƒ t	 t | ƒ | ƒ | ƒ t
 | | ƒ | ƒ S| d k rNd | }	 |	 | |	 } | d k r¯| t d
 | d d |	 ƒ |	 } n  t | d | d ƒ d }
 t t t d |
 ƒ | | ƒ t |	 ƒ | ƒ } t t t d d	 | d t |
 d ƒ ƒ t	 t | d ƒ | ƒ | ƒ t
 | | ƒ | ƒ S| | | } | | d k rª| d k r¦t t t d | ƒ ƒ t	 t | ƒ | ƒ | ƒ St St | | ƒ s½t S| | d | d } | t d | d | ƒ } t | | | ƒ d }
 t t t d |
 ƒ | | ƒ t | ƒ | ƒ } t t t d t d | ƒ ƒ t	 t | ƒ | ƒ | ƒ t | | ƒ | ƒ S| d k s| d k rqt | d ƒ t | d ƒ } } d | | } | | |  | d d | t | | | | t | d | ƒ | } | | |  | d d | t | | | | t | d | ƒ | } t t | | | ƒ t | | | ƒ | ƒ S| d k rd |  d t d t | d | ƒ | } d |  d | d d d | d d d } t t t d	 ƒ t | | | ƒ | ƒ t | | | ƒ ƒ Sd |  d t d t | d | ƒ | } d |  | d d d d d } t t | | | ƒ t | | | ƒ | ƒ S(   s‹    Compute the inner sum in HRR formula [1]_

    References
    ==========

    .. [1] http://msp.org/pjm/1956/6-1/pjm-v6-n1-p18-p.pdf

    i   i    i   i   i   i	   i   i   iÿÿÿÿi@   i@  i   i€   i    (   R   R   R   t   powR   R   R   R   R   R   R   R   R   R   R   R   R   t   _a(   t   nt   kt   prect   k1t   et   pt   k2t   vt   pit   modt   mt   argt   _phit   d1t   d2t   n1t   n2(    (    s8   lib/python2.7/site-packages/sympy/ntheory/partitions_.pyR&   &   s    	



(
%"++(*.	*"c         C  sÜ   t  | ƒ } t | ƒ } t | | | ƒ } t t  |  ƒ t d d | ƒ | ƒ } t | | ƒ } t t | | ƒ | ƒ \ }	 }
 t t | | ƒ t t | | ƒ | ƒ | ƒ } t t | |	 ƒ t |
 | | ƒ | ƒ } t | | ƒ S(   s„   
    Compute the sinh term in the outer sum of the HRR formula.
    The constants sqrt(2/3*pi) and sqrt(8) must be precomputed.
    i   i   (   R   R   R   R   R   R   R   R   (   R'   R!   R)   t   sq23pit   sqrt8R/   t   at   bt   ct   cht   sht   Dt   E(    (    s8   lib/python2.7/site-packages/sympy/ntheory/partitions_.pyt   _d|   s    $'c      
   C  s  t  |  ƒ }  |  d k  r d S|  d k rB d d d d d d g |  Sd t ƒ  k r[ t ƒ  n  t  t j d |  d d	 t j d
 |  ƒ t j d ƒ d ƒ t j d d ƒ } t  | d d ƒ } } t } t d t  d |  d	 d
 ƒ ƒ } | d k rt d ƒ ‚ n  t	 t
 t d d | ƒ | ƒ t | ƒ | ƒ } t
 t d ƒ | ƒ } x¬ t d | ƒ D]› }	 t |  |	 | ƒ }
 t |  |	 | | | ƒ } t | t	 |
 | ƒ | ƒ } | r×t d |	 d | t |
 d ƒ t | d ƒ ƒ n  t t t | ƒ ƒ ƒ d } qXWt  t t | t | ƒ ƒ ƒ S(   sã  
    Calculate the partition function P(n), i.e. the number of ways that
    n can be written as a sum of positive integers.

    P(n) is computed using the Hardy-Ramanujan-Rademacher formula [1]_.


    The correctness of this implementation has been tested through 10**10.

    Examples
    ========

    >>> from sympy.ntheory import npartitions
    >>> npartitions(25)
    1958

    References
    ==========

    .. [1] http://mathworld.wolfram.com/PartitionFunctionP.html

    i    i   i   i   i   i   R   g      @g      à?i   i
   gš™™™™™ñ?id   i   g¸…ëQ¸Î?s   Input too bigi   t   stept   ofi2   i † (   R   t   globalsR$   t   mathR/   t   logR   t   maxt
   ValueErrorR   R   R   R   R   R   R&   RA   R   t   printR
   R   t   absR	   R   (   R'   t   verboset   pbitsR)   R,   t   st   MR8   R9   t   qR:   t   d(    (    s8   lib/python2.7/site-packages/sympy/ntheory/partitions_.pyt   npartitionsŽ   s4    
%!-. RQ   ('   t
   __future__R    R   t   mpmath.libmpR   R   R   R   R   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   t   sympy.core.numbersR   t   sympy.core.compatibilityR   t   residue_ntheoryR   R   R   R   RE   R$   R&   RA   t   FalseRQ   t   __all__(    (    (    s8   lib/python2.7/site-packages/sympy/ntheory/partitions_.pyt   <module>   s   |"		V	6