+
    i0                        ^ RI Ht ^ RIHtHtHtHt ^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHtHt ^ RIHtHtHtHtHtHtHtHtHtHtHtHtHtHtH t H!t!H"t"H#t#H$t$H%t%H&t& ^ RI'H(t( ^ R	I)H*t* ^ R
I+H,t, ^ RI-H.t. ^ RI/H0t0H1t1H2t2H3t3 ^ RI4H5t5 ^ RI6H7t7 ^ RI8H9t9 R t:R t;R t<R t=R t>R t?R t@R tAR tBR tCR tDR tER tFR tGR tHR tIR  tJR! tKR" tLR# tMR$ tNR% tOR& tPR' tQR( tRR) tSR*# )+    )Mul)IIntegerRationalpi)Wildsymbols)exp)sqrt)MatrixImmutableMatrix)XGateYGateZGaterandom_circuitCNOTIdentityGateHXYSTZSwapGate	gate_simp	gate_sortCNotGateTGateHadamardGate	PhaseGateUGateCGate)
Commutator)AntiCommutator)	represent)qapply)QubitIntQubitqubit_to_matrixmatrix_to_qubit)matrix_to_zero)	sqrt2_inv)Daggerc                 x   \        ^4      p V P                  ^8X  g   Q hV P                  ^8X  g   Q h\        R4      p\        R4      p\        V4      p\        V4      p\        V4      pW48X  g   Q hW58w  g   Q hWT8w  g   Q h\	        W!4      p\	        W!4      p\	        W4      pWg8X  g   Q hWh8w  g   Q hWx8w  g   Q hR# )zTest a basic gate.i0i1N)r   
min_qubitsnqubitsr   r   )	hr/   r0   h0_w1h0_w2h1_w1
cnot_10_w1
cnot_10_w2
cnot_01_w1s	            c/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/physics/quantum/tests/test_gate.py	test_gater;      s    QA<<199>>	dB	dBEEE>>>>>>bJbJbJ#########    c                     \        R 4      w  rr#\        W.W#..4      p\        RV4      p\        V^R7      V8X  g   Q h\	        V\        R4      ,          4      V \        R4      ,          V\        R4      ,          ,           8X  g   Q h\	        V\        R4      ,          4      V\        R4      ,          V\        R4      ,          ,           8X  g   Q h\        RV4      p\        V^R7      p\        ^4       FI  pV\        \        V^4      4      ,          \        \	        V\        V^4      ,          4      4      8X  d   KI  Q h	  R# )a,b,c,dr2   01Nr      )	r	   r   r!   r%   r&   r'   ranger)   r(   )	abcduMatu1u2u2Repis	            r:   
test_UGaterO   /   s   #JA!A6A6"#D 
tT	BR#t+++"U3Z- AeCjL1U3Z<$????"U3Z- AeCjL1U3Z<$???? 
tT	Bb!$E1X_Xa^44F2hq!n#4567 	7 7 r<   c                    \        . RO. RO. RO. R	O.4      p \        \        ^\        ^ 4      4      ^R7      V 8X  g   Q h\        R
\        ^ 4      4      p\        V^R7      \        . RO. RO. RO. RO. RO. RO. RO. RO.4      8X  g   Q h\        R\        ^4      4      p\	        V\        R4      ,          4      \        \        V\        R4      ,          ^R7      4      8X  g   Q h\	        V\        R4      ,          4      \        \        V\        R4      ,          ^R7      4      8X  g   Q h\        ^\        ^ 4      4      p\        RR^ ^ ^ \        ) 3^ ^ \        ^ 334      p\        VP                  4       ^R7      V8X  g   Q h\        ^ \        ^4      4      p\        R4      p\	        V\        R4      ,          4      \        R4      ) 8X  g   Q h\        \        V\        R4      ,          ^R7      4      \        R4      ) 8X  g   Q h\        VP                  4       ^R7      V8X  g   Q h\        ^ \        ^4      4      p\	        V\        R4      ,          4      \        \        R4      ,          8X  g   Q h\        \        V\        R4      ,          ^R7      4      \        \        R4      ,          8X  g   Q h\        V4      V8X  g   Q h\        V^4      \        V4      8X  g   Q h\        V4      VP                  4       8X  g   Q h\        V4      V8w  g   Q h\        V4      VP                  4       8X  g   Q h\        V4      \        VR4      8X  g   Q h\        VR4      VP                  4       8X  g   Q hR# )zTest the general CGate.r?   1001000011NrD   r   r   r   r   rD   r   r   r   r   r   rD   r   r   rD   r   )rD      )rD   r   r   r   r   r   r   r   )r   rD   r   r   r   r   r   r   )r   r   rD   r   r   r   r   r   )r   r   r   rD   r   r   r   r   )r   r   r   r   rD   r   r   r   )r   r   r   r   r   rD   r   r   )r   r   r   r   r   r   r   rD   )r   r   r   r   r   r   rD   r   )   r   )rT   rU   rW   )r   r   r   rZ   )r   r%   r"   r   r&   r'   r*   r   r   	decomposer   r    r-   powinverse)
CNOTMatrixToffoliGateCYGateCYGate_matrixCZGateCZGate_matrix
CPhaseGates          r:   
test_cgatere   A   s    	|\<@BJU1eAh'3zAAA a)K[!,%'?AY6 9*	   a)K+eFm+,	+eFm";QGHI I I+eFm+,	+eFm";QGHI I I 1eAhF	|aAr]Q1aLACM V%%'3}DDD1eAhFACM&t$%%+5559VE$K%7CD	t   V%%'3}DDDq)A,'J*U4[()	%+  9Zd%;QGH	%+   &>V###vq>VF^+++&>V^^----*+++*!3!3!5555*Z!4444z2*"4"4"6666r<   c                  |   \        R 4      w  rr#\        W.W#..4      p\        . RO. RO^ ^ W.^ ^ W#..4      p\        R	V4      p\        ^V4      p\	        V^R7      V8X  g   Q h\        V\        R4      ,          4      V \        R4      ,          V\        R4      ,          ,           8X  g   Q h\        V\        R4      ,          4      V\        R4      ,          V\        R4      ,          ,           8X  g   Q h\        V\        R4      ,          4      \        R4      8X  g   Q h\        V\        R4      ,          4      \        R4      8X  g   Q h\        R
V4      p\	        V^R7      p	\        ^4       FI  p
V	\        \        V
^4      4      ,          \        \        V\        V
^4      ,          4      4      8X  d   KI  Q h	  R# )r>   r?   10rS   0100NrT   rU   rB   rC   )
r	   r   r!   r"   r%   r&   r'   rE   r)   r(   )rF   rG   rH   rI   rJ   cMatrK   cu1rL   rM   rN   s              r:   test_UGate_CGate_comborl   v   sp   #JA!A6A6"#D<1a|aA\JKD 
tT	B
2,CS!$,,,#eDk/"admadm&CCCC#eDk/"admadm&CCCC#eDk/"eDk111#eDk/"eDk111 
tT	Bb!$E1X_Xa^44F2hq!n#4567 	7 7 r<   c            	         \        R 4      w  rr#\        W.W#..4      p\        W^,           ^ ^ .V^,           V^ ^ .^ ^ W^,           .^ ^ V^,           V..4      p\        ^ 4      \	        ^ V4      ,           p\        V^R7      V8X  g   Q h\        ^\        ^4      ,          ^\        ^4      ,          .\        \        ^4      ,          \        ) \        ^4      ,          ..4      p\        \        ^^4      \        ^,          ,           \        ^^4      \        ^,          ,
          .\        ^^4      \        ^,          ,
          \        ^^4      \        ^,          ,           ..4      p\        ^^ .^ \        ..4      p	\	        ^ V4      p
\        \        ^ 4      V
,          ^R7      V8X  g   Q h\        V
\        ^ 4      ,          ^R7      V	8X  g   Q hR# )zv w f gr?   N)
r	   r   r   r   r!   r%   r   r   r   r   )vwfguMat1cMat1rK   uMat2cMat2_1cMat2_2rL   s              r:   test_UGate_OneQubitGate_comborw      s   #JA!aVaV,-EQAq!$q1uaA&6Aqa%8H1aQRUVQVXYJZ[\E	
1a	BR#u,,,aQi473aQi!DG5LMNEx1~!+Xa^ac-AB1~!+Xa^ac-ABD EGq!fq!f%&G	q%BQqT"Wa(G333R!Wa(G333r<   c                     \        ^ 4      \        R4      ,          p \        V ^R7      pV\        \        \        ^ ^ .4      8X  g   Q hR# )z-Test the representation of the hadamard gate.ri   r?   N)r   r'   r%   r   r,   circuitanswers     r:   test_represent_hadamardr|      s<    1oeDk)Gw*FVY	1a89999r<   c                 ~    \        ^ 4      \        R4      ,          p \        V ^R7      p\        . RO4      V8X  g   Q hR# )z&Test the representation of the X gate.ri   r?   NrU   )r   r'   r%   r   ry   s     r:   test_represent_xgater~      3    AhuT{"Gw*F,6)))r<   c                     \        ^ 4      \        R4      ,          p \        V ^R7      pV^ ,          ^ 8X  d/   V^,          \        8X  d   V^,          ^ 8X  d   V^,          ^ 8X  g   Q hR# )z&Test the representation of the Y gate.ri   r?   N)r   r'   r%   r   ry   s     r:   test_represent_ygater      sW    AhuT{"Gw*F!9>fQi1nq	Q6!9>* *)r<   c                 ~    \        ^ 4      \        R4      ,          p \        V ^R7      p\        . RO4      V8X  g   Q hR# )z&Test the representation of the Z gate.ri   r?   NrT   )r   r'   r%   r   ry   s     r:   test_represent_zgater      r   r<   c                     \        ^ 4      \        R4      ,          p \        V ^R7      p\        ^ \        ^ ^ .4      V8X  g   Q hR# )z&Test the representation of the S gate.rh   r?   N)r    r'   r%   r   r   ry   s     r:   test_represent_phasegater      s;    l5;&Gw*F1aA,6)))r<   c                     \        ^ 4      \        R4      ,          p \        ^ \        \        \
        ,          ^,          4      ^ ^ .4      \        V ^R7      8X  g   Q hR# )z&Test the representation of the T gate.rh   r?   N)r   r'   r   r
   r   r   r%   rz   s    r:   test_represent_tgater      sC    AhuT{"G1c!B$q&k1a()Yw-JJJJr<   c                 2   \        ^ 4      \        ^ 4      ,          \        ^ 4      ,          \        ^ 4      ,          \	        R4      ,          p \        V ^R7      p\        \        \        ^4      ,          \        \        ^4      ,          ^ ^ .4      V8X  g   Q hR# )z$Test a compound gate representation.ri   r?   N)	r   r   r   r   r'   r%   r   r   r   ry   s     r:   test_compound_gatesr      sg    AhuQxa(a8tDGw*F1T!W9aQiA./6999r<   c                 p   \        ^^ 4      p \        V ^R7      \        . RO. RO. RO. RO.4      8X  g   Q hV \        R4      ,          p \	        \        V ^R7      4      \        V 4      8X  g   Q h\        ^^ 4      p \        V 4      V 8X  g   Q h\        \        V 4      4      V 8X  g   Q hW ,          ^8X  g   Q hR# )zTest the CNOT gate.r?   111NrT   rU   rV   rW   )r   r%   r   r'   r*   r&   r-   r   s    r:   test_cnot_gater      s    q!nGWa(lL,GHI I IeEl"G9Wa89w   q!nG'?g%%%&/"g---?ar<   c                    \         \        \        \        \        \
        3 FU  p \        V ! ^4      V ! ^4      ,          V ! ^ 4      ,          4      V ! ^ 4      V ! ^4      ,          V ! ^4      ,          8X  d   KU  Q h	  \        \        ^4      \        ^ 4      ^,          ,          \        ^ ^4      ,          \        ^4      ,          \        ^ 4      ,          4      pV\        ^ 4      ^,          \        ^ ^4      ,          \        ^ 4      ,          \        ^4      ^,          ,          8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      \        ^ 4      ) \        ^ 4      ,          8X  g   Q h\        \        ^ 4      \        ^ 4      ^,          ,          4      \        ^ 4      ^,          \        ^ 4      ,          8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      \        ^ 4      ) \        ^ 4      ,          8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      \        ^ 4      ) \        ^ 4      ,          8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      \        ^ 4      ) \        ^ 4      ,          8X  g   Q h\        \        ^ 4      \	        ^ 4      ,          4      \	        ^ 4      \        ^ 4      ,          8X  g   Q h\        \        ^ 4      \	        ^ 4      ,          4      \	        ^ 4      \        ^ 4      ,          8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      \        ^ 4      \        ^ 4      ,          8X  g   Q h\        \        ^ 4      \        ^ ^4      ,          4      \        ^ ^4      \        ^ 4      ,          8X  g   Q h\        \	        ^ 4      \        ^ ^4      ,          4      \        ^ ^4      \	        ^ 4      ,          8X  g   Q h\        \        ^ 4      \        ^ ^4      ,          4      \        ^ ^4      \        ^ 4      ,          8X  g   Q h\        \        ^4      \        ^ ^4      ,          4      \        ^ ^4      \        ^4      ,          8X  g   Q hR# )zTest gate_sort.N)r   r   r   r   r   r   r   r   )rq   es     r:   test_gate_sortr      s   Aq!Q1ad1Q4(AaD1IadN:::  !A$qtQw,tAqz)!A$.qt34A!aQ
"1Q4'!a////QqT!A$YAaD51:---QqT!A$'\"adAgadl222QqT!A$YAaD51:---QqT!A$YAaD51:---QqT!A$YAaD51:---QqT!A$Y1Q4!9,,,QqT!A$Y1Q4!9,,,QqT!A$Y1Q4!9,,,QqT$q!*_%aAaD888QqT$q!*_%aAaD888QqT$q!*_%aAaD888QqT$q!*_%aAaD888r<   c                    \        ^ 4      \        ^4      ,          \        ^ 4      ^,          ,          \        ^ ^4      ,          \        ^4      ^,          ,          \        ^ 4      ,          \        ^4      ^,          ,          \	        ^4      ^,          ,          p \        V 4      \        ^ 4      \        ^ ^4      ,          \	        ^4      ,          \        ^ 4      ,          \        ^4      ,          8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      ^8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      ^8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      ^8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      ^8X  g   Q h\        \        ^ 4      \        ^ 4      ,          4      \	        ^ 4      8X  g   Q h\        \	        ^ 4      \	        ^ 4      ,          4      \        ^ 4      8X  g   Q h\        \        ^4      4      \        ^4      8X  g   Q h\        \        ^ 4      ^,          \        ^ 4      ^,          ,           4      \        ^4      8X  g   Q hR# )zTest gate_simp.N)	r   r   r   r   r   r   r   r   r   )r   s    r:   test_gate_simpr      s   	!QqT	!A$'$q!*$QqT1W,QqT1!A$'9!A$'AAQ<1Q4Q
?1Q4/!4QqT9999QqT!A$Y1$$$QqT!A$Y1$$$QqT!A$Y1$$$QqT!A$Y1$$$QqT!A$Y1Q4'''QqT!A$Y1Q4'''WQZ GAJ...QqT1WqtQw&'71:555r<   c            	        \        R4      p \        \        ^^ 4      P                  4       ^R7      V 8X  g   Q h\	        \        ^^4      \        R4      ,          4      \        R4      8X  g   Q h^p\        V4       FT  p\        V4       FB  p\        \        W#4      VR7      \        \        W#4      P                  4       VR7      8X  d   KB  Q h	  KV  	  R# )zTest the SWAP gate.r?   00101000N)rT   rW   rU   rV   )r   r%   r   r[   r&   r'   rE   )swap_gate_matrixr2   rN   js       r:   test_swap_gater     s    @BXa^--/;?OOOO(1a.v./5=@@@G7^qAXa^W=(1.224gFG G G  r<   c            
        \         \        \        \        \        \
        \        3 F  p \         \        \        \        \        \
        \        3 F  p\        V ! ^ 4      V! ^ 4      4      p\        \        V^RR7      4      p\        \        VP                  4       ^RR7      4      pW48X  g   Q h\        V ! ^ 4      V! ^4      4      pVP                  4       ^ 8X  d   K  Q h	  K  	  R# )z-Test single qubit gate commutation relations.sympyr2   formatN)r   r   r   r   r   r   r   r#   r+   r%   doitg1g2r   rF   rG   s        r:   test_one_qubit_commutatorsr     s    Q1aA.Aq!Q2B2a5"Q%(AyAgFGAy1WMNA6M62a5"Q%(A668q= = 3 /r<   c            
        \         \        \        \        \        3 F  p \         \        \        \        \        3 F  p\        V ! ^ 4      V! ^ 4      4      p\        \        V^RR7      4      p\        \        VP                  4       ^RR7      4      pW48X  g   Q h\        V ! ^ 4      V! ^4      4      p\        \        V^RR7      4      p\        \        VP                  4       ^RR7      4      pW48X  d   K  Q h	  K  	  R# )z1Test single qubit gate anticommutation relations.r   r   N)	r   r   r   r   r   r$   r+   r%   r   r   s        r:   test_one_qubit_anticommutatorsr     s    Q1a(Aq!,Br!ube,AyAgFGAy1WMNA6M6r!ube,AyAgFGAy1WMNA6M6 - )r<   c                 N   \        \        ^ ^4      \        ^ 4      4      P                  4       ^ 8X  g   Q h\        \        ^ ^4      \	        ^ 4      4      P                  4       ^ 8X  g   Q h\        \        ^ ^4      \        ^ 4      4      P                  4       ^ 8X  g   Q h\        \        ^ ^4      \        ^4      4      P                  4       ^ 8X  g   Q h\        \        ^ ^4      \        ^ ^4      4      P                  4       ^ 8X  g   Q h\        \        ^ ^4      \        ^ ^4      4      P                  4       ^ 8X  g   Q h\        \        ^ ^4      \        ^ ^4      4      P                  4       ^ 8X  g   Q h\        \        ^^4      \        ^^ 4      4      P                  4       ^ 8X  g   Q hR# )z)Test commutators of involving CNOT gates.N)r#   r   r   r   r   r   r    r<   r:   test_cnot_commutatorsr   -  sJ   d1aj!A$',,.!333d1aj!A$',,.!333d1aj!A$',,.!333d1aj!A$',,.!333d1aj$q!*-224999d1aj$q!*-224999d1aj$q!*-224999d1aj$q!*-224999r<   c                      \        ^
^4      p \        V \        4      '       g   Q h\        V ^R7      pVP                  R8X  g   Q h\        V\
        4      '       g   Q hR# )
   r?   N)   r   )r   
isinstancer   r%   shaper   )rH   ms     r:   test_random_circuitr   9  sR    r1Aa!QA77fa    r<   c                  D    \        ^^4      p \        V 4      pW8X  g   Q hR# rD   Nr   r-   xx_daggers     r:   test_hermitian_XGater   A       aAayHMMr<   c                  D    \        ^^4      p \        V 4      pW8X  g   Q hR# r   r   r-   yy_daggers     r:   test_hermitian_YGater   H  r   r<   c                  D    \        ^^4      p \        V 4      pW8X  g   Q hR# r   r   r-   zz_daggers     r:   test_hermitian_ZGater   O  r   r<   c                  R    \        ^^4      p \        V 4      pW,          ^8X  g   Q hR# r   r   r   s     r:   test_unitary_XGater   V  $    aAayHJ!OOr<   c                  R    \        ^^4      p \        V 4      pW,          ^8X  g   Q hR# r   r   r   s     r:   test_unitary_YGater   ]  r   r<   c                  R    \        ^^4      p \        V 4      pW,          ^8X  g   Q hR# r   r   r   s     r:   test_unitary_ZGater   d  r   r<   N)Tsympy.core.mulr   sympy.core.numbersr   r   r   r   sympy.core.symbolr   r	   &sympy.functions.elementary.exponentialr
   (sympy.functions.elementary.miscellaneousr   sympy.matricesr   r   sympy.physics.quantum.gater   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"    sympy.physics.quantum.commutatorr#   $sympy.physics.quantum.anticommutatorr$   sympy.physics.quantum.representr%   sympy.physics.quantum.qapplyr&   sympy.physics.quantum.qubitr'   r(   r)   r*   !sympy.physics.quantum.matrixutilsr+   !sympy.physics.quantum.matrixcacher,   sympy.physics.quantumr-   r;   rO   re   rl   rw   r|   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r<   r:   <module>r      s     9 9 - 6 9 2@ @ @ @ @ @ 8 ? 5 /  < 7 ($27$27j7*4:****K: 986
G
!	:!r<   