+
    i                     &   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   &*   y/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/physics/quantum/qft.pyr#   RkGate.__new__1   s    t9>;dB  aG6= !VV$$!V= ~~d#||C'$' 44T:    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       zz!}r-   c                (    V P                   R ,          # ):Nr3   Nr4   r6   s   &r+   targetsRkGate.targetsP   s    zz"~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13tvv;??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Aq6As4<
+B2+Ea+GQRUXY]Y_Y_U`I`+a'b#cdee!1F:< 	<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    t9><tC  7d1g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    $$5W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__$DwN  yy

 CH+OBMQE$K9,7q C$JT
# #,79BM 	 O'? ::a=A,SDJJqM1A-BHMH??W$,#a'OO";<=?H 9 Os   -E?/E.EEc                ^    \        V P                  ^ ,          V P                  ^,          4      # )    )rg   r5   r6   s   &r+   r;   Fourier.targets   s    TZZ]DJJqM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eE23E"5)'1G5=)	AveU/CDWL * 4 *+Aqy&*q.9'AG ,r-   c                B    \        V P                  4       V,          4      # r/   )r   r~   )r7   qubitsr^   s   &&,r+   _apply_operator_QubitQFT._apply_operator_Qubit   s    dnn&v-..r-   c                (    \        V P                  !  # r/   )r   r'   r6   s   &r+   _eval_inverseQFT._eval_inverse   s    TYYr-   c                f    \        ^\        ,          \        ,          V P                  ,          4      # )r    r   r   r   re   r6   s   &r+   rf   	QFT.omega   s    1R4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qy&*q.9'AG ,5)EeEM23	AveR!V/DEgM 4"5)'1G * r-   c                (    \        V P                  !  # r/   )r   r'   r6   s   &r+   r   IQFT._eval_inverse   s    DIIr-   c                f    \        R\        ,          \        ,          V P                  ,          4      # )r    r   r6   s   &r+   rf   
IQFT.omega   s    2b57499$%%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-   