o
    oh5#                     @   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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)gcdlegendrejacobi   )_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*   m/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/ntheory/partitions_.py_pre   s*   

r,   c                 C   sV  |dkrt S |}d}t| }|| dkr"|| }|d7 }|| dks|| }dd|   }t|}|dkrR|dkrd| }	|	||	  }|td|d |	 |	 }t|d|d d }
tttd|
 ||t|	|}tttd	| t|
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   t|
d t	t|d ||t
|||S |||  }|| dkr|dkrtttd|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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rd|  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      	         @   i@  r          )r   r    r   powr   r
   r	   r   r   r   r   r   r   r   r   r   r!   _a)nkpreck1epk2vpimodmarg_phid1d2n1n2r*   r*   r+   r7   $   s   	





$,
$ r7   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	   )r8   r'   r:   sq23pisqrt8r@   abcchshDEr*   r*   r+   _dz   s   

rR   r8   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   r0   r   r   r   )r8   prevr?   pentar&   npsr*   r*   r+   _partition_rec   s   
rX   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   r1   
   r   g?d   ,      r0   K   gUUUUUU?c                    s<   t j} || ||| d   t ||  |   S )Nr   )mathsqrtsinh)r8   Nr`   c1c2c3r*   r+   _M   s   6z_partition.<locals>._Mr/   (   r   zInput too bigr.   2   )rX   cache_lengthglobalsr,   r"   r_   r@   loglog2r`   maxceil
ValueErrorr   r	   r   r   r   r   r#   r7   rR   r   r   absr   r   )r8   pbitsr:   r=   rg   bigsmallrb   erMrW   rI   rJ   qrK   dr*   rc   r+   
_partition   s`   	
ry   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|   )r8   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   sympy.external.gmpyr   r   r   residue_ntheoryr   r   sympy.utilities.decoratorr   sympy.utilities.memoizationr   r_   	itertoolsr   r,   r7   rR   r"   rX   ry   r   r*   r*   r*   r+   <module>   s$   H V
M