ó
    ‰*£h¡-  ã                   ó`  • S r SSKJrJrJr  SSKJr  SSKJrJ	r	  SSK
JrJr  SSKJrJr  SSKJrJr  SSKJr  SS	 jrSS jrSS jr\R                   \l         SS jrS rS r\R                   \l         SS jrS rS r\R                   \l         S rSS jrSS jr \R                   \ l         g
)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           	      ó~  • [        U 5      (       d  [        S5      eU  Vs/ s H  n[        U5      PM     nn[        S U 5       5      (       a  [	        S5      e[        U5      nUS:  a  U$ UR                  5       S-
  nXUS-
  -  (       a
  US-  nSU-  nU[        R                  /U[        U5      -
  -  -  n[        SU5       H1  n[        [        XvSS9SSS	2   S5      nXx:  d  M$  XH   XG   sXG'   XH'   M3     U(       a  S
[        -  U-  OS[        -  U-  n	Ub  U	R                  US-   5      n	[        US-  5       Vs/ s H%  n[        X—-  5      [        [!        X—-  5      -  -   PM'     n
nSnXµ::  ap  US-  X[-  pÜ[        SX[5       HL  n[        U5       H:  nXGU-      [#        XGU-   U-      X­U-     -  5      pþXï-   Xï-
  sXGU-   '   XGU-   U-   '   M<     MN     US-  nXµ::  a  Mp  U(       a>  Ub%  U Vs/ s H  nUU-  R                  U5      PM     snOU Vs/ s H  nUU-  PM
     snnU$ s  snf s  snf s  snf s  snf )z3Utility function for the Discrete Fourier TransformzAExpected a sequence of numeric coefficients for Fourier Transformc              3   óJ   #   • U  H  oR                  [        5      v •  M     g 7f©N)Úhasr   )Ú.0Úxs     ÚV/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/discrete/transforms.pyÚ	<genexpr>Ú%_fourier_transform.<locals>.<genexpr>   s   é € Ð
$¢!˜Q�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_transformr8      sE  € ô �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Ó.ˆØ�5Ø™˜q™tˆJˆA‰D�!“$ñ ö
 ˆ"ŒR‰%�Š' !¤B¡$ q¡&€Cà
�Ø�i‰i˜˜a™Ó ˆä,1°!°q±&¬MÓ:ªM qŒˆS‰U‹”aœ˜C™E›
‘lÔ	"©M€AÐ:à	€AØ
‹&Ø�a‘˜™ˆBÜ�q˜!–ˆAÜ˜2–Y�Ø˜Q™‘x¤¨A°!©e°b©j©M¸!À¹F¹)Ñ,CÓ!D�1Ø*+©%°±Ð'��a‘%‘˜! ™E B™J›-ó ñ  ð 	
ˆQ‰ˆð �&ö Ø-0©_¡qÓ)¢q !ˆa�‰c�[‰[˜Ö¡qÒ)Ù/0Ó!1ªq¨! ! A¤#©qÑ!1ð 	
ð €HùòO 	&ùò0 	;ùò *ùÚ!1s    H+Ä?,H0Ç2H5ÈH:Nc                 ó   • [        XS9$ )añ  
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)   ©r8   ©r(   r)   s     r   Úfftr<   F   s   € ô\ ˜cÑ+Ð+ó    c                 ó   • [        XSS9$ )NT)r)   r*   r:   r;   s     r   Úifftr?   w   s   € Ü˜c°DÑ9Ð9r=   c           	      ó6  • [        U 5      (       d  [        S5      e[        U5      n[        U5      (       d  [	        S5      eU  Vs/ s H  n[        U5      U-  PM     nn[        U5      nUS:  a  U$ UR                  5       S-
  nXfS-
  -  (       a
  US-  nSU-  nUS-
  U-  (       a  [	        S5      eUS/U[        U5      -
  -  -  n[        SU5       H1  n[        [        X‡SS9S	S	S
2   S5      n	X‰:  d  M$  XY   XX   sXX'   XY'   M3     [        U5      n
[        X£S-
  U-  U5      nU(       a  [        X³S-
  U5      nS/US-  -  n[        SUS-  5       H  nXÈS-
     U-  U-  XÈ'   M     SnXÖ::  ap  US-  Xm-  pþ[        SXm5       HL  n[        U5       H:  n	XXU	-      XXU	-   U-      XÏU	-     -  nnUU-   U-  UU-
  U-  sXXU	-   '   XXU	-   U-   '   M<     MN     US-  nXÖ::  a  Mp  U(       a&  [        XcS-
  U5      nU Vs/ s H
  oDU-  U-  PM     nnU$ s  snf s  snf )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/   r0   ÚprÚrtr2   r3   r4   r5   r6   r7   Úrvs                      r   Ú_number_theoretic_transformrG   ƒ   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Ó.ˆØ�5Ø™˜q™tˆJˆA‰D�!“$ñ ô
 
˜Ó	€Bä	ˆR�a‘%˜A‘˜qÓ	!€BÞÜ�˜‘U˜AÓˆà	
ˆˆQ�!‰V‰€AÜ�1�a˜1‘fÖˆØ�Q‘‰x˜‰{˜Q‰ˆ‹ñ ð 	
€AØ
‹&Ø�a‘˜™ˆBÜ�q˜!–ˆAÜ˜2–Y�Ø˜Q™‘x  q¡5¨2¡:¡¨q°a±©yÑ!8�1�Ø+,¨q©5°A©+¸¸A¹À±{Ð'��a‘%‘˜! ™E B™J›-ó ñ  ð 	
ˆQ‰ˆð �&ö Ü�˜‘E˜1ÓˆÙ Ó!šq˜!ˆr‰T�AŒX™qˆÐ!à€HùòW 	%ùòR "s   ÁHÇ<Hc                 ó   • [        XS9$ )aÞ  
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

)rB   ©rG   ©r(   rB   s     r   ÚnttrK   ½   s   € ôP ' sÑ8Ð8r=   c                 ó   • [        XSS9$ )NT)rB   r*   rI   rJ   s     r   ÚinttrM   è   s   € Ü& sÀÑFÐFr=   c                 ó,  • [        U 5      (       d  [        S5      eU  Vs/ s H  n[        U5      PM     nn[        U5      nUS:  a  U$ XDS-
  -  (       a  SUR	                  5       -  nU[
        R                  /U[        U5      -
  -  -  nSnXT::  a\  US-  n[        SXE5       H;  n[        U5       H)  nX7U-      X7U-   U-      p©Xš-   Xš-
  sX7U-   '   X7U-   U-   '   M+     M=     US-  nXT::  a  M\  U(       a  U Vs/ s H  o»U-  PM	     nnU$ s  snf s  snf )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-   r3   r4   r/   r0   r6   r7   r   s               r   Ú_walsh_hadamard_transformrP   ô   s(  € ô �C�=‰=Üð 7ó 8ð 	8ñ "%Ó%¢˜#Œ�Ž¡€AÐ%ÜˆA‹€AØˆ1ƒuØˆàˆa‰%‡yØˆq�|‰|‹~ÑˆàŒ!�&‰&ˆ�1”s˜1“v‘:Ñ	Ñ€AØ	€AØ
‹&Ø�!‰VˆÜ�q˜!–ˆAÜ˜2–Y�Ø˜Q™‘x  q¡5¨2¡:¡�1Ø*+©%°±Ð'��a‘%‘˜! ™E B™J›-ó ñ  ð 	
ˆQ‰ˆð �&ö ÙÓš!�QˆqŒS™!ˆÐà€Hùò+ 	&ùò& s    DÃ:Dc                 ó   • [        U 5      $ )aî  
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

©rP   ©r(   s    r   ÚfwhtrT     s   € ôH % SÓ)Ð)r=   c                 ó   • [        U SS9$ )NT)r*   rR   rS   s    r   ÚifwhtrV   :  s   € Ü$ S°$Ñ7Ð7r=   c                 óD  • [        U 5      (       d  [        S5      eU  Vs/ s H  n[        U5      PM     nn[        U5      nUS:  a  U$ XUS-
  -  (       a  SUR	                  5       -  nU[
        R                  /U[        U5      -
  -  -  nU(       aE  SnXe:  a<  [        U5       H!  nXv-  (       d  M  XG==   XXv-     -  -  ss'   M#     US-  nXe:  a  M<  U$ SnXe:  a<  [        U5       H!  nXv-  (       a  M  XG==   XXv-     -  -  ss'   M#     US-  nXe:  a  M<  U$ s  snf )zXUtility function for performing Mobius Transform using
Yate's Dynamic Programming methodz#Expected a sequence of coefficientsr   r   rO   )r(   ÚsgnÚsubsetr+   r,   r-   r/   r0   s           r   Ú_mobius_transformrZ   F  s  € ô �C�=‰=ÜÐ=Ó>Ð>á!$Ó%¢˜#Œ�Ž¡€AÐ%äˆA‹€AØˆ1ƒuØˆàˆa‰%‡yØˆq�|‰|‹~ÑˆàŒ!�&‰&ˆ�1”s˜1“v‘:Ñ	Ñ€AæØˆØ‹eÜ˜1–X�Ø—5‘5Ø“D˜C !¡%¡™LÑ(•Dñ ð �‰FˆAð	 �eð €Hð ˆØ‹eÜ˜1–X�Ø—5ÙØ“˜˜a™e™H™Ñ$•ñ ð �‰FˆAð �eð €Hùò9 	&s    Dc                 ó   • [        U SUS9$ )af  
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   ©rX   rY   ©rZ   ©r(   rY   s     r   Úmobius_transformr_   l  s   € ôp ˜S b°Ñ8Ð8r=   c                 ó   • [        U SUS9$ )Nr   r\   r]   r^   s     r   Úinverse_mobius_transformra   ¦  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   r8   r<   r?   rG   rK   rM   rP   rT   rV   rZ   r_   ra   © r=   r   Ú<module>rk      s    ðñ÷
 *Ñ )Ý *ß $ß =ß 1ß 4Ý 'ô.ôb.,ôb:ð �{‰{€„ô7òt(9òVGð �{‰{€„ôò>$*òN8ð —‘€„ò#ôL89ôt9ð $4×#;Ñ#;Ð Õ  r=   