Ë
    7^(h¡-  ã                   óR  — d Z ddlmZmZmZ ddlmZ ddlmZm	Z	 ddl
mZmZ ddlmZmZ ddlmZmZ ddlmZ dd	„Zdd„Zdd„Zej                   e_         dd„Zd„ Zd„ Zej                   e_         dd„Zd„ Zd„ Zej                   e_         d„ Zdd„Zdd„Z ej                   e _         y
)zd
Discrete Fourier Transform, Number Theoretic Transform,
Walsh Hadamard Transform, Mobius Transform
é    )ÚSÚSymbolÚsympify)Ú
expand_mul)ÚpiÚI)ÚsinÚcos)ÚisprimeÚprimitive_root)ÚibinÚiterable)Úas_intc           	      óJ  — t        | «      st        d«      ‚| D �cg c]  }t        |«      ‘Œ }}t        d„ |D «       «      rt	        d«      ‚t        |«      }|dk  r|S |j                  «       dz
  }||dz
  z  r
|dz  }d|z  }|t        j                  g|t        |«      z
  z  z  }t        d|«      D ]7  }t        t        ||d¬«      ddd	…   d«      }||k  sŒ'||   ||   c||<   ||<   Œ9 |rd
t        z  |z  ndt        z  |z  }	|�|	j                  |dz   «      }	t        |dz  «      D �cg c]&  }t        |	|z  «      t        t!        |	|z  «      z  z   ‘Œ( }
}d}||k  rv|dz  ||z  }}t        d||«      D ]Q  }t        |«      D ]A  }|||z      t#        |||z   |z      |
||z     z  «      }}||z   ||z
  c|||z   <   |||z   |z   <   ŒC ŒS |dz  }||k  rŒv|r7|�"|D �cg c]  }||z  j                  |«      ‘Œ c}n|D �cg c]  }||z  ‘Œ	 c}}|S c c}w c c}w c c}w c c}w )z3Utility function for the Discrete Fourier TransformzAExpected a sequence of numeric coefficients for Fourier Transformc              3   óF   K  — | ]  }|j                  t        «      –— Œ y ­w©N)Úhasr   )Ú.0Úxs     úW/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/discrete/transforms.pyú	<genexpr>z%_fourier_transform.<locals>.<genexpr>   s   è ø€ Ò
$˜Qˆ1�5‰5”�=Ñ
$ùs   ‚!z"Expected non-symbolic coefficientsé   é   T©ÚstrNéÿÿÿÿéþÿÿÿr   )r   Ú	TypeErrorr   ÚanyÚ
ValueErrorÚlenÚ
bit_lengthr   ÚZeroÚrangeÚintr   r   Úevalfr
   r   r	   r   )ÚseqÚdpsÚinverseÚargÚaÚnÚbÚiÚjÚangÚwÚhÚhfÚutÚuÚvr   s                    r   Ú_fourier_transformr7      sq  € ô �CŒ=Üð 0ó 1ð 	1ð "%Ö%˜#Œ��Ð%€AÐ%Ü
Ñ
$ !Ô
$Ô$ÜÐ=Ó>Ð>äˆA‹€AØˆ1‚uØˆà	�‰‹˜Ñ€AØˆ!ˆa‰%‚yØ	ˆQ‰ˆØˆq‰DˆàŒ!�&‰&ˆ�1”s˜1“v‘:Ñ	Ñ€AÜ�1�a‹[ò $ˆÜ”�Q˜˜tÔ$¡T r TÑ*¨AÓ.ˆØˆq‹5Ø˜1™˜q ™tˆJˆAˆa‰D�!�A’$ð$ñ
 ˆ"ŒR‰%�Š' !¤B¡$ q¡&€Cà
€Ø�i‰i˜˜a™Ó ˆä,1°!°q±&«MÖ: qŒˆS�‰U‹”aœ˜C ™E›
‘lÓ	"Ð:€AÐ:à	€AØ
ˆqŠ&Ø�a‘˜˜a™ˆBˆÜ�q˜!˜Q“ò 	7ˆAÜ˜2“Yò 7�Ø˜˜Q™‘x¤¨A¨a°!©e°b©j©M¸!¸BÀ¹F¹)Ñ,CÓ!D�1�Ø*+¨a©%°°Q±Ð'��!�a‘%‘˜!˜A ™E B™Jš-ñ7ð	7ð 	
ˆQ‰ˆð ˆq‹&ñ Ø-0¨_ qÖ) !ˆa�‰c�[‰[˜ÕÓ)Ø/0Ö!1¨! ! A£#Ò!1ð 	
ð €HùòO 	&ùò0 	;ùò *ùÚ!1s   ›HÄ,+HÇHÈ H Nc                 ó   — t        | |¬«      S )am  
    Performs the Discrete Fourier Transform (**DFT**) in the complex domain.

    The sequence is automatically padded to the right with zeros, as the
    *radix-2 FFT* requires the number of sample points to be a power of 2.

    This method should be used with default arguments only for short sequences
    as the complexity of expressions increases with the size of the sequence.

    Parameters
    ==========

    seq : iterable
        The sequence on which **DFT** is to be applied.
    dps : Integer
        Specifies the number of decimal digits for precision.

    Examples
    ========

    >>> from sympy import fft, ifft

    >>> fft([1, 2, 3, 4])
    [10, -2 - 2*I, -2, -2 + 2*I]
    >>> ifft(_)
    [1, 2, 3, 4]

    >>> ifft([1, 2, 3, 4])
    [5/2, -1/2 + I/2, -1/2, -1/2 - I/2]
    >>> fft(_)
    [1, 2, 3, 4]

    >>> ifft([1, 7, 3, 4], dps=15)
    [3.75, -0.5 - 0.75*I, -1.75, -0.5 + 0.75*I]
    >>> fft(_)
    [1.0, 7.0, 3.0, 4.0]

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm
    .. [2] https://mathworld.wolfram.com/FastFourierTransform.html

    )r(   ©r7   ©r'   r(   s     r   Úfftr;   F   s   € ô\ ˜c sÔ+Ð+ó    c                 ó   — t        | |d¬«      S )NT)r(   r)   r9   r:   s     r   Úifftr>   w   s   € Ü˜c s°DÔ9Ð9r<   c                 ó  — t        | «      st        d«      ‚t        |«      }t        |«      st	        d«      ‚| D �cg c]  }t        |«      |z  ‘Œ }}t        |«      }|dk  r|S |j                  «       dz
  }||dz
  z  r
|dz  }d|z  }|dz
  |z  rt	        d«      ‚|dg|t        |«      z
  z  z  }t        d|«      D ]7  }t        t        ||d¬«      d	d	d
…   d«      }	||	k  sŒ'||	   ||   c||<   ||	<   Œ9 t        |«      }
t        |
|dz
  |z  |«      }|rt        ||dz
  |«      }dg|dz  z  }t        d|dz  «      D ]  }||dz
     |z  |z  ||<   Œ d}||k  rs|dz  ||z  }}t        d||«      D ]N  }t        |«      D ]>  }	|||	z      |||	z   |z      |||	z     z  }}||z   |z  ||z
  |z  c|||	z   <   |||	z   |z   <   Œ@ ŒP |dz  }||k  rŒs|r%t        ||dz
  |«      }|D �cg c]
  }||z  |z  ‘Œ }}|S c c}w c c}w )z3Utility function for the Number Theoretic TransformzJExpected a sequence of integer coefficients for Number Theoretic Transformz5Expected prime modulus for Number Theoretic Transformr   r   z/Expected prime modulus of the form (m*2**k + 1)r   Tr   Nr   )r   r   r   r   r    r!   r"   r$   r%   r   r   Úpow)r'   Úprimer)   Úpr   r+   r,   r-   r.   r/   ÚprÚrtr1   r2   r3   r4   r5   r6   Úrvs                      r   Ú_number_theoretic_transformrF   ƒ   sœ  € ô �CŒ=Üð 9ó :ð 	:ô 	ˆu‹€AÜ�1Œ:Üð 5ó 6ð 	6ð !$Ö$˜1Œ�‹�Q‹Ð$€AÐ$äˆA‹€AØˆ1‚uØˆà	�‰‹˜Ñ€AØˆ!ˆa‰%‚yØ	ˆQ‰ˆØˆq‰Dˆà	ˆA‰�‚{ÜÐJÓKÐKàˆ!ˆˆa”#�a“&‰jÑ	Ñ€AÜ�1�a‹[ò $ˆÜ”�Q˜˜tÔ$¡T r TÑ*¨AÓ.ˆØˆq‹5Ø˜1™˜q ™tˆJˆAˆa‰D�!�A’$ð$ô
 
˜Ó	€Bä	ˆR�!�a‘%˜A‘˜qÓ	!€BÙÜ��Q˜‘U˜AÓˆà	
ˆˆQ�!‰V‰€AÜ�1�a˜1‘fÓò ˆØ��Q‘‰x˜‰{˜Q‰ˆˆ!Šðð 	
€AØ
ˆqŠ&Ø�a‘˜˜a™ˆBˆÜ�q˜!˜Q“ò 	CˆAÜ˜2“Yò C�Ø˜˜Q™‘x  1 q¡5¨2¡:¡¨q°°a±©yÑ!8�1�Ø+,¨q©5°A©+¸¸A¹À±{Ð'��!�a‘%‘˜!˜A ™E B™Jš-ñCð	Cð 	
ˆQ‰ˆð ˆq‹&ñ Ü��A˜‘E˜1ÓˆØ Ö!˜!ˆQˆr‰T�A‹XÐ!ˆÐ!à€HùòW 	%ùòR "s   ¼G9Ç&G>c                 ó   — t        | |¬«      S )aR  
    Performs the Number Theoretic Transform (**NTT**), which specializes the
    Discrete Fourier Transform (**DFT**) over quotient ring `Z/pZ` for prime
    `p` instead of complex numbers `C`.

    The sequence is automatically padded to the right with zeros, as the
    *radix-2 NTT* requires the number of sample points to be a power of 2.

    Parameters
    ==========

    seq : iterable
        The sequence on which **DFT** is to be applied.
    prime : Integer
        Prime modulus of the form `(m 2^k + 1)` to be used for performing
        **NTT** on the sequence.

    Examples
    ========

    >>> from sympy import ntt, intt
    >>> ntt([1, 2, 3, 4], prime=3*2**8 + 1)
    [10, 643, 767, 122]
    >>> intt(_, 3*2**8 + 1)
    [1, 2, 3, 4]
    >>> intt([1, 2, 3, 4], prime=3*2**8 + 1)
    [387, 415, 384, 353]
    >>> ntt(_, prime=3*2**8 + 1)
    [1, 2, 3, 4]

    References
    ==========

    .. [1] http://www.apfloat.org/ntt.html
    .. [2] https://mathworld.wolfram.com/NumberTheoreticTransform.html
    .. [3] https://en.wikipedia.org/wiki/Discrete_Fourier_transform_(general%29

    )rA   ©rF   ©r'   rA   s     r   ÚnttrJ   ½   s   € ôP ' s°%Ô8Ð8r<   c                 ó   — t        | |d¬«      S )NT)rA   r)   rH   rI   s     r   ÚinttrL   è   s   € Ü& s°%ÀÔFÐFr<   c                 ó
  — t        | «      st        d«      ‚| D �cg c]  }t        |«      ‘Œ }}t        |«      }|dk  r|S ||dz
  z  rd|j	                  «       z  }|t
        j                  g|t        |«      z
  z  z  }d}||k  r_|dz  }t        d||«      D ]?  }t        |«      D ]/  }|||z      |||z   |z      }
}	|	|
z   |	|
z
  c|||z   <   |||z   |z   <   Œ1 ŒA |dz  }||k  rŒ_|r|D �cg c]  }||z  ‘Œ	 }}|S c c}w c c}w )z1Utility function for the Walsh Hadamard Transformz@Expected a sequence of coefficients for Walsh Hadamard Transformr   r   r   ©r   r   r   r!   r"   r   r#   r$   )r'   r)   r*   r+   r,   r2   r3   r.   r/   r5   r6   r   s               r   Ú_walsh_hadamard_transformrO   ô   sF  € ô �CŒ=Üð 7ó 8ð 	8ð "%Ö%˜#Œ��Ð%€AÐ%ÜˆA‹€AØˆ1‚uØˆàˆ!ˆa‰%‚yØˆq�|‰|‹~ÑˆàŒ!�&‰&ˆ�1”s˜1“v‘:Ñ	Ñ€AØ	€AØ
ˆqŠ&Ø�!‰VˆÜ�q˜!˜Q“ò 	7ˆAÜ˜2“Yò 7�Ø˜˜Q™‘x  1 q¡5¨2¡:¡�1�Ø*+¨a©%°°Q±Ð'��!�a‘%‘˜!˜A ™E B™Jš-ñ7ð	7ð 	
ˆQ‰ˆð ˆq‹&ñ ØÖ�QˆQˆq‹SÐˆÐà€Hùò+ 	&ùò& s   ›C;Ã+D c                 ó   — t        | «      S )aN  
    Performs the Walsh Hadamard Transform (**WHT**), and uses Hadamard
    ordering for the sequence.

    The sequence is automatically padded to the right with zeros, as the
    *radix-2 FWHT* requires the number of sample points to be a power of 2.

    Parameters
    ==========

    seq : iterable
        The sequence on which WHT is to be applied.

    Examples
    ========

    >>> from sympy import fwht, ifwht
    >>> fwht([4, 2, 2, 0, 0, 2, -2, 0])
    [8, 0, 8, 0, 8, 8, 0, 0]
    >>> ifwht(_)
    [4, 2, 2, 0, 0, 2, -2, 0]

    >>> ifwht([19, -1, 11, -9, -7, 13, -15, 5])
    [2, 0, 4, 0, 3, 10, 0, 0]
    >>> fwht(_)
    [19, -1, 11, -9, -7, 13, -15, 5]

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Hadamard_transform
    .. [2] https://en.wikipedia.org/wiki/Fast_Walsh%E2%80%93Hadamard_transform

    ©rO   ©r'   s    r   ÚfwhtrS     s   € ôH % SÓ)Ð)r<   c                 ó   — t        | d¬«      S )NT)r)   rQ   rR   s    r   ÚifwhtrU   :  s   € Ü$ S°$Ô7Ð7r<   c                 ó  — t        | «      st        d«      ‚| D �cg c]  }t        |«      ‘Œ }}t        |«      }|dk  r|S ||dz
  z  rd|j	                  «       z  }|t
        j                  g|t        |«      z
  z  z  }|r@d}||k  r7t        |«      D ]  }||z  sŒ	||xx   ||||z     z  z  cc<   Œ  |dz  }||k  rŒ7|S d}||k  r7t        |«      D ]  }||z  rŒ	||xx   ||||z     z  z  cc<   Œ  |dz  }||k  rŒ7|S c c}w )z\Utility function for performing Mobius Transform using
    Yate's Dynamic Programming methodz#Expected a sequence of coefficientsr   r   rN   )r'   ÚsgnÚsubsetr*   r+   r,   r.   r/   s           r   Ú_mobius_transformrY   F  s>  € ô �CŒ=ÜÐ=Ó>Ð>à!$Ö%˜#Œ��Ð%€AÐ%äˆA‹€AØˆ1‚uØˆàˆ!ˆa‰%‚yØˆq�|‰|‹~ÑˆàŒ!�&‰&ˆ�1”s˜1“v‘:Ñ	Ñ€AáØˆØ�!ŠeÜ˜1“Xò )�Ø�q“5Ø�a“D˜C  ! a¡%¡™LÑ(”Dð)ð �‰FˆAð	 �!‹eð €Hð ˆØ�!ŠeÜ˜1“Xò %�Ø�q’5ØØ�!“˜˜A˜a !™e™H™Ñ$”ð%ð �‰FˆAð �!‹eð €Hùò9 	&s   ›Dc                 ó   — t        | d|¬«      S )a
  
    Performs the Mobius Transform for subset lattice with indices of
    sequence as bitmasks.

    The indices of each argument, considered as bit strings, correspond
    to subsets of a finite set.

    The sequence is automatically padded to the right with zeros, as the
    definition of subset/superset based on bitmasks (indices) requires
    the size of sequence to be a power of 2.

    Parameters
    ==========

    seq : iterable
        The sequence on which Mobius Transform is to be applied.
    subset : bool
        Specifies if Mobius Transform is applied by enumerating subsets
        or supersets of the given set.

    Examples
    ========

    >>> from sympy import symbols
    >>> from sympy import mobius_transform, inverse_mobius_transform
    >>> x, y, z = symbols('x y z')

    >>> mobius_transform([x, y, z])
    [x, x + y, x + z, x + y + z]
    >>> inverse_mobius_transform(_)
    [x, y, z, 0]

    >>> mobius_transform([x, y, z], subset=False)
    [x + y + z, y, z, 0]
    >>> inverse_mobius_transform(_, subset=False)
    [x, y, z, 0]

    >>> mobius_transform([1, 2, 3, 4])
    [1, 3, 4, 10]
    >>> inverse_mobius_transform(_)
    [1, 2, 3, 4]
    >>> mobius_transform([1, 2, 3, 4], subset=False)
    [10, 6, 7, 4]
    >>> inverse_mobius_transform(_, subset=False)
    [1, 2, 3, 4]

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/M%C3%B6bius_inversion_formula
    .. [2] https://people.csail.mit.edu/rrw/presentations/subset-conv.pdf
    .. [3] https://arxiv.org/pdf/1211.0189.pdf

    r   ©rW   rX   ©rY   ©r'   rX   s     r   Úmobius_transformr^   l  s   € ôp ˜S b°Ô8Ð8r<   c                 ó   — t        | d|¬«      S )Nr   r[   r\   r]   s     r   Úinverse_mobius_transformr`   ¦  s   € Ü˜S b°Ô8Ð8r<   )Fr   )T)!Ú__doc__Ú
sympy.corer   r   r   Úsympy.core.functionr   Úsympy.core.numbersr   r   Ú(sympy.functions.elementary.trigonometricr	   r
   Úsympy.ntheoryr   r   Úsympy.utilities.iterablesr   r   Úsympy.utilities.miscr   r7   r;   r>   rF   rJ   rL   rO   rS   rU   rY   r^   r`   © r<   r   ú<module>rj      s    ðñ÷
 *Ñ )Ý *ß $ß =ß 1ß 4Ý 'ó.ób.,ób:ð �{‰{€„ó7òt(9òVGð �{‰{€„óò>$*òN8ð —‘€„ò#óL89ót9ð $4×#;Ñ#;Ð Õ  r<   