o
    3Ih##                     @   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dedefddZdedef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r6t|| | |D ]}t | dkr5|t |< q)qtd| D ]4}t | dkrO|t |< |d t|< q<t | }|| }|| dkrft| | t|< q<t| |d  t|< q<d S )N順 r   r         ?      )_factor_totientintrange)maxnlimijxy r'   Y/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/sympy/ntheory/partitions_.py_pre   s*   

r)   c                 C   sf  |dkrt S |}d}t| }|| dkr"|| }|d7 }|| dks|| }dd|   }t|}|dkrX|dkrd| }	|	||	  }|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r|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sb|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preck1epk2vpimodmargjacobi3_phid1d2n1n2r'   r'   r(   r8   "   s   	

"




$,
$ r8   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	   )r9   r$   r;   sq23pisqrt8rA   abcchshDEr'   r'   r(   _dy   s   

rT   r9   returnc                 C   s|   d}d}t  D ]4}|d| d 7 }| | }|dk r |S || }||d 8 }d|kr0||| 7 }||d r8| n|7 }q|S )zt Calculate the partition function P(n)

    Parameters
    ==========

    n : int
        nonnegative integer

    r   r-   r   r   r   )r9   prevr@   pentar#   npsr'   r'   r(   _partition_rec   s   
rZ   c                    sL  | dk rdS | dkr| t   dk st  dkr | dk r t | S dt vr(t  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 sJ |dkr|| |dk r|d }|dkr|| |dk s|}|d }|| dkr|| d }|| | }dk r|}n|dkr|}|| dks|}	|	dkrtdt}
tttdd||t||}ttd|}td|	D ]#}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   )r6   sqrtsinh)r9   Nra   c1c2c3r'   r(   _M   s   6z_partition.<locals>._Mr,   (   r   zInput too bigr+   2   )rZ   cache_lengthglobalsr)   r   r6   rA   loglog2ra   maxceil
ValueErrorr   r	   r   r   r   r   r    r8   rT   r   r   absr   r   )r9   pbitsr;   r>   rh   bigsmallrc   erMrY   rK   rL   qrM   dr'   rd   r(   
_partition   s`   	
rz   zpThe `sympy.ntheory.partitions_.npartitions` has been moved to `sympy.functions.combinatorial.numbers.partition`.z1.13z%deprecated-ntheory-symbolic-functions)deprecated_since_version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)%sympy.functions.combinatorial.numbersr}   )r9   verbosefunc_partitionr'   r'   r(   npartitions   s   !r   )F)"mpmath.libmpr   r   r   r   r   r   r   r	   r
   r   r   r   r   r   r   r   residue_ntheoryr   r   sympy.utilities.decoratorr   sympy.utilities.memoizationr   r6   	itertoolsr   r)   r8   rT   r   rZ   rz   r   r'   r'   r'   r(   <module>   s"   H W
M