a
    kh##                     @   s   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 ddlmZmZ d dlmZ d dlmZ d dlZd dlmZ dd	 Zd
d Zdd ZeddgeedddZeedddZ edddddddZ!dS )    )fzerofrom_intfrom_rationalfonefhalfbitcountto_intmpf_mulmpf_divmpf_submpf_addmpf_sqrtmpf_pimpf_cosh_sinhmpf_cosmpf_sin   )_sqrt_mod_prime_poweris_quad_residue)
deprecated)recurrence_memoNcountc                  C   s   d} dg|  a dg|  at| d d }td|D ]:}t | dkr2t|| | |D ]}t | dkrR|t |< qRq2td| D ]h}t | dkr|t |< |d t|< qxt | }|| }|| dkrt| | t|< qxt| |d  t|< qxd S )N順 r   r         ?      )_factor_totientintrange)ZmaxnZlimijxy r%   G/var/www/auris/lib/python3.9/site-packages/sympy/ntheory/partitions_.py_pre   s&    

r'   c                 C   sd  |dkrt S |}d}t| }|| dkr:|| }|d7 }q|| }dd|   }t|}|dkr|dkrd| }	|	||	  }|td|d |	 |	 }t|d|d d }
tttd|
 ||t|	|}tttd	| d|
d   tt|||t	|||S |dkrd| }	|	||	  }|dkrF|td
|d d |	 |	 }t|d|d d }
tttd|
 ||t|	|}tttdd	|d   dd|
d    tt|d ||t	|||S |||  }|d dv rd	nd}|| dkr|dkrtt|tt|||S t
S t||s*t
S ||d  |d  }|td|d | }t|||d }
tttd|
 ||t||}tttd| tt|||t|||S |dks|dkrt|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|||S d|  d tdt| d | | }d| |d d d  d  d }tt|||t||||S )z Compute the inner sum in HRR formula [1]_

    References
    ==========

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

    r   r      r      	         @      )r      i@  r          )r   r   r   powr   r
   r	   r   r   r   r   r   r   mathgcdr   _a)nkprecZk1epZk2vpimodmargZjacobi3Z_phid1Zd2Zn1Zn2r%   r%   r&   r6   "   s    	





"




$,
$ r6   c                 C   s   t |}t|}t|||}tt | tdd||}t||}tt|||\}	}
tt||tt||||}tt||	t|
|||}t||S )z
    Compute the sinh term in the outer sum of the HRR formula.
    The constants sqrt(2/3*pi) and sqrt(8) must be precomputed.
    r   r(   )r   r   r
   r   r   r   r   r	   )r7   r"   r9   sq23pisqrt8r=   abcchshDEr%   r%   r&   _dy   s    
rK   )r7   returnc                 C   sz   d}d}t  D ]f}|d| d 7 }| | }|dk r6 qv|| }||d 8 }d|kr^||| 7 }||d rn| n|7 }q|S )zt Calculate the partition function P(n)

    Parameters
    ==========

    n : int
        nonnegative integer

    r   r+   r   r   r   )r7   prevr<   Zpentar!   npsr%   r%   r&   _partition_rec   s    
rP   c                    sB  | dk rdS | dkr$| t   dk s8t  dkr@| dk r@t | S dt vrPt  ttjd|  d d  td	|   td
 d td
 }t|d d  }}dtjd  dt	d   tjt	d d tjt	d  fdd}t
dt| d }|| |dk sJ |dkrB|| |dk rB|d }q|}|d }|| dkr|| d }|| | }dk r|}n|dkrN|}qN|}	|	dkrtdt}
tttdd||t||}ttd|}td|	D ]H}t| ||}t| ||||}t|
t|||}
ttt|d }qttt|
t|S )zX Calculate the partition function P(n)

    Parameters
    ==========

    n : int

    r   i@ F   r   i@8  r   g      @r   r,   
   r   g?d   ,      r+   K   gUUUUUU?c                    s<   t j} || ||| d   t ||  |   S )Nr   )r4   sqrtsinh)r7   NrW   Zc1c2c3r%   r&   _M   s    z_partition.<locals>._Mr*   (   r   zInput too bigr)   2   )rP   Zcache_lengthglobalsr'   r   r4   r=   loglog2rW   maxceil
ValueErrorr   r	   r   r   r   r   r    r6   rK   r   r   absr   r   )r7   Zpbitsr9   r;   r]   bigsmallrY   ZerMrO   rB   rC   qrD   dr%   rZ   r&   
_partition   sb    	



rl   zpThe `sympy.ntheory.partitions_.npartitions` has been moved to `sympy.functions.combinatorial.numbers.partition`.z1.13z%deprecated-ntheory-symbolic-functions)Zdeprecated_since_versionZactive_deprecations_targetFc                 C   s   ddl m} || S )a
  
    Calculate the partition function P(n), i.e. the number of ways that
    n can be written as a sum of positive integers.

    .. deprecated:: 1.13

        The ``npartitions`` function is deprecated. Use :class:`sympy.functions.combinatorial.numbers.partition`
        instead. See its documentation for more information. See
        :ref:`deprecated-ntheory-symbolic-functions` for details.

    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.functions.combinatorial.numbers import partition
    >>> partition(25)
    1958

    References
    ==========

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

    r   )	partition)Z%sympy.functions.combinatorial.numbersrm   )r7   verboseZfunc_partitionr%   r%   r&   npartitions   s    !ro   )F)"Zmpmath.libmpr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   Zresidue_ntheoryr   r   Zsympy.utilities.decoratorr   Zsympy.utilities.memoizationr   r4   	itertoolsr   r'   r6   rK   r   rP   rl   ro   r%   r%   r%   r&   <module>   s    HW
M