+
    
þÎj  ã                   ó&  € R t ^ RIHt ^ RIHtHtHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt ^ R	IHt ^ R
IHt ^ RIHtHtHtHtHtHtHtH t  ^ RI!H"t" . ROt# ! R R]4      t$]$t% ! R R]4      t& ! R R]&4      t' ! R R]&4      t(R# )at  An implementation of qubits and gates acting on them.

Todo:

* Update docstrings.
* Update tests.
* Implement apply using decompose.
* Implement represent using decompose or something smarter. For this to
  work we first have to implement represent for SWAP.
* Decide if we want upper index to be inclusive in the constructor.
* Fix the printing of Rk gates in plotting.
)ÚExpr)ÚIÚIntegerÚpi©ÚSymbol)Úexp)ÚMatrix)Úsqrt)Úqapply)ÚQuantumErrorÚQExpr)Úeye)Úmatrix_tensor_product)ÚGateÚHadamardGateÚSwapGateÚOneQubitGateÚCGateÚ	PhaseGateÚTGateÚZGate)ÚsignÚQFTÚIQFTÚRkGatec                   ó|   a € ] tR t^,t o RtRtRtR t]R 4       t	]
R 4       t]
R 4       t]
R 4       tRR	 ltR
tV tR# )r   z This is the R_k gate of the QTF.ÚRkÚRc                óX  € \        V4      ^8w  d   \        RV,          4      hV^ ,          pV^,          pV^8X  d   \        V4      # V^8X  d   \        V4      # V^8X  d   \	        V4      # V P                  V4      p\        P                  ! V .VO5!  pV P                  V4      Vn	        V# )é   z)Rk gates only take two arguments, got: %r)
Úlenr   r   r   r   Ú
_eval_argsr   Ú__new__Ú_eval_hilbert_spaceÚhilbert_space)ÚclsÚargsÚtargetÚkÚinsts   &*   ÚO/opt/data/home/.local/lib/python3.14/site-packages/sympy/physics/quantum/qft.pyr#   ÚRkGate.__new__1   s£   € Üˆt‹9˜Œ>ÜØ;¸dÕBóð ð �a•ˆØ��GˆØ�Œ6Ü˜“=Ð Ø�!ŒVÜ˜VÓ$Ð$Ø�!ŒVÜ˜“=Ð Ø�~‰~˜dÓ#ˆÜ�|Š|˜CÐ' $Ó'ˆØ ×4Ñ4°TÓ:ˆÔØˆó    c                ó.   € \         P                  ! V4      # ©N)r   r"   )r&   r'   s   &&r+   r"   ÚRkGate._eval_argsF   s   € ô ×Ò Ó%Ð%r-   c                ó(   € V P                   ^,          # ©é   ©Úlabel©Úselfs   &r+   r)   ÚRkGate.kL   ó   € à�z‰z˜!�}Ðr-   c                ó(   € V P                   R ,          # ):Nr3   Nr4   r6   s   &r+   ÚtargetsÚRkGate.targetsP   s   € à�z‰z˜"�~Ðr-   c                óR   € R V P                   : R\        V P                  4      : R 2# )Ú$Ú_)Úgate_name_latexÚstrr)   r6   s   &r+   Úgate_name_plotÚRkGate.gate_name_plotT   s   � à!×1Ô1´3°t·v±v¶;Ð?Ð?r-   c                ó.  € VR 8X  d~   \        ^^ .^ \        \        V P                  4      \	        ^4      ,          \
        ,          \        ,          \	        ^4      \        V P                  4      ,          ,          4      ..4      # \        RV,          4      h)Úsympyz#Invalid format for the R_k gate: %r)	r	   r   r   r)   r   r   r   ÚabsÚNotImplementedError)r7   Úformats   &&r+   Úget_target_matrixÚRkGate.get_target_matrixX   st   € Ø�WÔÜ˜A˜q˜6 A¤s¬4°·±«<¼À»
Õ+BÄ2Õ+EÄaÕ+GÌÐQRËÔUXÐY]×Y_ÑY_ÓU`ÕI`Õ+aÓ'bÐ#cÐdÓeÐeÜ!Ø1°FÕ:ó<ð 	<r-   © N)rE   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Ú	gate_namer@   r#   Úclassmethodr"   Úpropertyr)   r;   rB   rI   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r+   r   r   ,   ss   ø‡ € Ù*Ø€IØ€Oòð* ñ&ó ð&ð
 ñó ðð ñó ðð ñ@ó ð@÷<ò <r-   c                   ó€   a € ] tR t^bt o Rt]R 4       tR tR t]	R 4       t
]	R 4       t]	R 4       t]	R 4       tR	tV tR
# )ÚFourierz@Superclass of Quantum Fourier and Inverse Quantum Fourier Gates.c                ó²   € \        V4      ^8w  d   \        RV,          4      hV^ ,          V^,          8¼  d   \        R4      h\        P                  ! V4      # )r    z*QFT/IQFT only takes two arguments, got: %rz!Start must be smaller than finish)r!   r   r   r"   )r7   r'   s   &&r+   r"   ÚFourier._eval_argse   sO   € äˆt‹9˜Œ>ÜØ<¸tÕCóð ð ��7�d˜1•gÔÜÐBÓCÐCÜ�Š˜tÓ$Ð$r-   c                ó&   € V P                   ! R/ VB # )Nr/   )Ú_represent_ZGate)r7   Úoptionss   &,r+   Ú_represent_default_basisÚ Fourier._represent_default_basiso   s   € Ø×$Ò$Ñ5¨WÑ5Ð5r-   c                ó¤  € VP                  R^ 4      pV^ 8X  d   \        R4      hW0P                  8  d   \        RV,          4      hV P                  pV P                  p\        V4       UUu. uFB  p\        V4       Uu. uF)  pVWv,          V,          ,          \        V4      ,          NK+  	  upNKD  	  ppp\        V4      p	V P                  ^ ,          ^ 8w  d.   \        \        ^V P                  ^ ,          ,          4      V	4      p	V P                  V8  d-   \        V	\        ^W0P                  ,
          ,          4      4      p	V	# u upi u uppi )z&
Represents the (I)QFT In the Z Basis
Únqubitsz.The number of qubits must be given as nqubits.z2The number of qubits %r is too small for the gate.)Úgetr   Ú
min_qubitsÚsizeÚomegaÚranger
   r	   r5   r   r   )
r7   Úbasisr^   rb   re   rf   ÚjÚiÚarrayFTÚmatrixFTs
   &&,       r+   r]   ÚFourier._represent_ZGater   s9  € ð —+‘+˜i¨Ó+ˆØ�aŒ<ÜØ@óBð Bà—_‘_Ô$ÜØDÀwÕNóð ð �y‰yˆØ—
‘
ˆô CHÈÄ+ôOÙBM¸Q¬E°$¬Kó9Ù,7 qð Ø�C�$�JõÜ˜T›
÷#ð #Ù,7ô9ÙBMð 	ñ Oä˜'“?ˆð �:‰:�a�=˜AÔÜ,¬S°°D·J±J¸qµMÕ1AÓ-BÀHÓMˆHØ�?‰?˜WÔ$Ü,Øœ#˜a '¯O©OÕ";Õ<Ó=ó?ˆHð ˆùò9ùó Os   Á-EÁ?/EÂ.EÅEc                ó^   € \        V P                  ^ ,          V P                  ^,          4      # )é    )rg   r5   r6   s   &r+   r;   ÚFourier.targets�   s   € ä�T—Z‘Z •] D§J¡J¨q¥MÓ2Ð2r-   c                ó(   € V P                   ^,          # r2   r4   r6   s   &r+   rd   ÚFourier.min_qubits“   r9   r-   c                óf   € ^V P                   ^,          V P                   ^ ,          ,
          ,          # )z"Size is the size of the QFT matrixr4   r6   s   &r+   re   ÚFourier.size—   s$   € ð �4—:‘:˜a•= 4§:¡:¨a¥=Õ0Õ1Ð1r-   c                ó   € \        R 4      # )rf   r   r6   s   &r+   rf   ÚFourier.omegaœ   s   € ä�g‹Ðr-   rK   N)rL   rM   rN   rO   rP   rR   r"   r_   r]   rS   r;   rd   re   rf   rT   rU   rV   s   @r+   rY   rY   b   st   ø‡ € ÙJàñ%ó ð%ò6òð: ñ3ó ð3ð ñó ðð ñ2ó ð2ð ñó ör-   rY   c                   óN   a € ] tR t^¡t o RtR tR tR tR tR t	]
R 4       tRtV tR# )r   z&The forward quantum Fourier transform.c           
     óÊ  € V P                   ^ ,          pV P                   ^,          p^p\        \        W4      4       F]  p\        V4      V,          p\        WA,
          4       F3  p\	        WE,
          ^,
          \        WE^,           4      4      V,          pK5  	  K_  	  \        W!,
          ^,          4       F)  p\        WQ,           W%,
          ^,
          4      V,          pK+  	  V# )z%Decomposes QFT into elementary gates.)r5   Úreversedrg   r   r   r   r   )r7   ÚstartÚfinishÚcircuitÚlevelrj   s   &     r+   Ú	decomposeÚQFT.decompose§   s«   € à—
‘
˜1•ˆØ—‘˜A•ˆØˆÜœe EÓ2Ö3ˆEÜ" 5Ó)¨'Õ1ˆGÜ˜5�=Ö)�Ü ¥	¨A¥¬v°eÀ½UÓ/CÓDÀWÕL’ó *ñ 4ô ˜�¨Õ*Ö+ˆAÜ˜q�y¨&­*°q­.Ó9¸'ÕAŠGñ ,àˆr-   c                óB   € \        V P                  4       V,          4      # r/   )r   r~   )r7   Úqubitsr^   s   &&,r+   Ú_apply_operator_QubitÚQFT._apply_operator_Qubit´   s   € Ü�d—n‘nÓ& vÕ-Ó.Ð.r-   c                ó(   € \        V P                  !  # r/   )r   r'   r6   s   &r+   Ú_eval_inverseÚQFT._eval_inverse·   s   € Ü�T—Y‘YÑÐr-   c                óf   € \        ^\        ,          \        ,          V P                  ,          4      # )r    ©r   r   r   re   r6   s   &r+   rf   Ú	QFT.omegaº   s   € ä�1”R•4œ•6˜$Ÿ)™)Õ#Ó$Ð$r-   rK   N)rL   rM   rN   rO   rP   rQ   r@   r~   r‚   r…   rS   rf   rT   rU   rV   s   @r+   r   r   ¡   s5   ø‡ € Ù0à€IØ€Oòò/ò ð ñ%ó ö%r-   c                   óH   a € ] tR t^¿t o RtR tRtR tR t]	R 4       t
RtV tR# )r   z&The inverse quantum Fourier transform.z
{QFT^{-1}}c           
     óÌ  € V P                   ^ ,          pV P                   ^,          p^p\        W!,
          ^,          4       F)  p\        WA,           W$,
          ^,
          4      V,          pK+  	  \        W4       Fg  p\        \        WQ,
          4      4       F4  p\	        WT,
          ^,
          \        WT) ^,
          4      4      V,          pK6  	  \        V4      V,          pKi  	  V# )z&Decomposes IQFT into elementary gates.)r'   rg   r   ry   r   r   r   )r7   rz   r{   r|   rj   r}   s   &     r+   r~   ÚIQFT.decomposeÅ   s­   € à—	‘	˜!•ˆØ—‘˜1•ˆØˆÜ˜�¨Õ*Ö+ˆAÜ˜q�y¨&­*°q­.Ó9¸'ÕAŠGñ ,ä˜5Ö)ˆEÜœe E¥MÓ2Ö3�Ü ¥	¨A¥¬v°e¸RÀ!½VÓ/DÓEÀgÕM’ñ 4ä" 5Ó)¨'Õ1ŠGñ *ð ˆr-   c                ó(   € \        V P                  !  # r/   )r   r'   r6   s   &r+   r…   ÚIQFT._eval_inverseÒ   s   € Ü�D—I‘I‰Ðr-   c                óf   € \        R\        ,          \        ,          V P                  ,          4      # )r    éþÿÿÿrˆ   r6   s   &r+   rf   Ú
IQFT.omegaÕ   s   € ä�2”b•5œ•7˜4Ÿ9™9Õ$Ó%Ð%r-   rK   N)rL   rM   rN   rO   rP   rQ   r@   r~   r…   rS   rf   rT   rU   rV   s   @r+   r   r   ¿   s0   ø‡ € Ù0à€IØ"€Oòòð ñ&ó ö&r-   N)r   r   r   r   ))rP   Úsympy.core.exprr   Úsympy.core.numbersr   r   r   Úsympy.core.symbolr   Ú&sympy.functions.elementary.exponentialr   Úsympy.matrices.denser	   Úsympy.functionsr
   Úsympy.physics.quantum.qapplyr   Úsympy.physics.quantum.qexprr   r   Úsympy.matricesr   Ú#sympy.physics.quantum.tensorproductr   Úsympy.physics.quantum.gater   r   r   r   r   r   r   r   Ú$sympy.functions.elementary.complexesr   Ú__all__r   r   rY   r   r   rK   r-   r+   Ú<module>rŸ      s�   ðñõ !ß /Ñ /Ý $Ý 6Ý 'Ý  å /ß ;Ý Ý E÷÷ ó õ 6ò€ô0<ˆ\ô 0<ðf €ô<ˆdô <ô~%ˆ'ô %ô<&ˆ7ö &r-   