+
    i-                     b   R t ^ RIHtHtHt ^ RIHt ^ RIHtH	t	 ^ RI
HtHt ^ RIHtHt ^ RIHtHt ^ RIHt RR ltRR
 ltRR lt]P                   ]n         RR ltR tR t]P                   ]n         RR ltR tR t]P                   ]n         R tRR ltRR lt ]P                   ] n         R	# )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           	        \        V 4      '       g   \        R4      hV  Uu. uF  p\        V4      NK  	  pp\        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \	        R4      h\        V4      pV^8  d   V# VP                  4       ^,
          pWU^,
          ,          '       d   V^,          p^V,          pV\        P                  .V\        V4      ,
          ,          ,          p\        ^V4       FA  p\        \        WvRR7      RRR1,          ^4      pWx8  g   K,  WH,          WG,          uWG&   WH&   KC  	  V'       d   R	\        ,          V,          M^\        ,          V,          p	Ve   V	P                  V^,           4      p	\        V^,          4       Uu. uF5  p\        W,          4      \        \!        W,          4      ,          ,           NK7  	  p
p^pW8:  d   V^,          W[,          r\        ^ W[4       F  p\        V4       Fn  pWGV,           ,          \#        WGV,           V,           ,          WV,          ,          ,          4      rW,           W,
          uWGV,           &   WGV,           V,           &   Kp  	  K  	  V^,          pK  V'       dF   Ve)   V Uu. uF  pVV,          P                  V4      NK  	  upMV Uu. uF  pVV,          NK  	  uppV# u upi u upi u upi u upi )
z3Utility function for the Discrete Fourier TransformzAExpected a sequence of numeric coefficients for Fourier Transformc              3   J   "   T F  qP                  \        4      x  K  	  R # 5iN)hasr   ).0xs   & y/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/discrete/transforms.py	<genexpr>%_fourier_transform.<locals>.<genexpr>   s     
$!Q55==!s   !#TFz"Expected non-symbolic coefficientsstrN)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_transformr5      sS    C== 0 1 	1 "%%#A%
s
$!
$sss
$!
$$$=>>AA1u	Aa%yy	QqD!&&1s1v:	A1a[Qt$TrT*A.5qtJAD!$ 
 "R%'!B$q&C
iia ,1!q&M:MqSUaCE
l	"	"MA:	A
&aBq!A2YQxA!ebjM!F),C!D1*+%'a%!EBJ-    	
Q-0_q)q!ac[[q)/0!1q!!A##q!1 	
 HO 	&0 	; *!1s   K-.;K2.!K7K<Nc                    \        WR7      # )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&   r5   r%   r&   s   &&r   fftr9   F   s    \ c++    c                     \        WR R7      # )T)r&   r'   r7   r8   s   &&r   ifftr<   w   s    cD99r:   c           	        \        V 4      '       g   \        R4      h\        V4      p\        V4      '       g   \	        R4      hV  Uu. uF  p\        V4      V,          NK  	  pp\        V4      pV^8  d   V# VP                  4       ^,
          pWf^,
          ,          '       d   V^,          p^V,          pV^,
          V,          '       d   \	        R4      hV^ .V\        V4      ,
          ,          ,          p\        ^V4       FA  p\        \        WRR7      RRR1,          ^4      p	W8  g   K,  WY,          WX,          uWX&   WY&   KC  	  \        V4      p
\        W^,
          V,          V4      pV'       d   \        W^,
          V4      p^.V^,          ,          p\        ^V^,          4       F"  pW^,
          ,          V,          V,          W&   K$  	  ^pW8:  d   V^,          Wm,          r\        ^ Wm4       F  p\        V4       Fv  p	WXV	,           ,          WXV	,           V,           ,          WV	,          ,          ,          ppVV,           V,          VV,
          V,          uWXV	,           &   WXV	,           V,           &   Kx  	  K  	  V^,          pK  V'       d2   \        Wc^,
          V4      pV Uu. uF  qDV,          V,          NK  	  ppV# u upi u upi )z3Utility function for the Number Theoretic TransformzJExpected a sequence of integer coefficients for Number Theoretic Transformz5Expected prime modulus for Number Theoretic Transformz/Expected prime modulus of the form (m*2**k + 1)Tr   Nr   )r   r   r   r
   r   r   r    r"   r#   r   r   pow)r%   primer'   pr   r)   r*   r+   r,   r-   prrtr/   r0   r1   r2   r3   r4   rvs   &&&                r   _number_theoretic_transformrD      s[    C== 9 : 	: 	uA1:: 5 6 	6 !$$1QA$AA1u	Aa%yy	QqD	A{{JKK!a#a&j	A1a[Qt$TrT*A.5qtJAD!$ 
 
	B	Ra%Aq	!BUA	
Q!VA1a1fQx{Q  	
A
&aBq!A2YQxq52:qay!81+,q5A+A{'a%!EBJ-    	
QE1 !q!rTAXXq!HW 	%R "s   K
.Kc                    \        WR7      # )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

)r?   rD   r%   r?   s   &&r   nttrH      s    P 's88r:   c                     \        WR R7      # )T)r?   r'   rF   rG   s   &&r   inttrJ      s    &sFFr:   c                   \        V 4      '       g   \        R4      hV  Uu. uF  p\        V4      NK  	  pp\        V4      pV^8  d   V# WD^,
          ,          '       d   ^VP	                  4       ,          pV\
        P                  .V\        V4      ,
          ,          ,          p^pWT8:  d   V^,          p\        ^ WE4       Fc  p\        V4       FQ  pW7V,           ,          W7V,           V,           ,          rW,           W,
          uW7V,           &   W7V,           V,           &   KS  	  Ke  	  V^,          pK  V'       d   V Uu. uF  qV,          NK  	  ppV# u upi u upi )z1Utility function for the Walsh Hadamard Transformz@Expected a sequence of coefficients for Walsh Hadamard Transformr   r   r   r   r    r   r!   r"   )r%   r'   r(   r)   r*   r0   r1   r,   r-   r3   r4   r   s   &&          r   _walsh_hadamard_transformrM      s#    C== 7 8 	8 "%%#A%AA1ua%yyq||~!&&1s1v:	A	A
&!Vq!A2YQxq52:1*+%'a%!EBJ-    	
Q!QqSS!H+ 	&& s   EEc                    \        V 4      # )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

rM   r%   s   &r   fwhtrQ     s    H %S))r:   c                     \        V R R7      # )T)r'   rO   rP   s   &r   ifwhtrS   :  s    $S$77r:   c                   \        V 4      '       g   \        R4      hV  Uu. uF  p\        V4      NK  	  pp\        V4      pV^8  d   V# WU^,
          ,          '       d   ^VP	                  4       ,          pV\
        P                  .V\        V4      ,
          ,          ,          pV'       d`   ^pWe8  dU   \        V4       F:  pWv,          '       g   K  WG;;,          WWv,          ,          ,          ,          uu&   K<  	  V^,          pKZ   V# ^pWe8  dU   \        V4       F:  pWv,          '       d   K  WG;;,          WWv,          ,          ,          ,          uu&   K<  	  V^,          pKZ  V# u upi )zXUtility function for performing Mobius Transform using
Yate's Dynamic Programming methodz#Expected a sequence of coefficientsrL   )r%   sgnsubsetr(   r)   r*   r,   r-   s   &&&     r   _mobius_transformrW   F  s    C===>>!$%#A%AA1ua%yyq||~!&&1s1v:	Ae1X55DC!%L(D  FA	  H e1X55aeH$  FAH9 	&s   E+c                    \        V ^VR7      # )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

rU   rV   rW   r%   rV   s   &&r   mobius_transformr\   l  s    p Sb88r:   c                     \        V RVR7      # )   rY   r   rZ   r[   s   &&r   inverse_mobius_transformr_     s    Sb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   r5   r9   r<   rD   rH   rJ   rM   rQ   rS   rW   r\   r_    r:   r   <module>ri      s   
 * ) * $ = 1 4 '.b.,b: {{7t(9VG {{>$*N8 #L89t9 $4#;#;   r:   