+
    
þÎj�e  ã                   óÆ  € R t ^ RI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 ^ 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 ^ RIH t  ^ RI!H"t" ^ RI#H$t$H%t% ^ RI&H't' . R'Ot( ! R R]4      t) ! R R])]4      t* ! R R])]4      t+ ! R R])4      t, ! R R],]*4      t- ! R R],]+4      t.R t/R  t0R(R! lt1R)R" lt2R)R# lt3R(R$ lt4R% t5R(R& lt6R# )*z�Qubits for quantum computing.

Todo:
* Finish implementing measurement logic. This should include POVM.
* Update docstrings.
* Update tests.
N)ÚAdd)ÚMul)ÚInteger)ÚPow)ÚS)Ú	conjugate)Úlog©Ú_sympify)Ú
SYMPY_INTS)ÚMatrixÚzeros)Ú
prettyForm)ÚComplexSpace)ÚKetÚBraÚState)ÚQuantumError©Ú	represent)Únumpy_ndarrayÚscipy_sparse_matrix)ÚbitcountÚQubitÚQubitBraÚIntQubitÚIntQubitBrac                   ó†   a € ] tR t^5t o Rt]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       tR tR tR	 tR
tV tR# )Ú
QubitStatez"Base class for Qubit and QubitBra.c                ó†  € \        V4      ^8X  d1   \        V^ ,          \        4      '       d   V^ ,          P                  # \        V4      ^8X  dY   \        V^ ,          \        4      '       d<   \
        ;QJ d    . R V^ ,           4       F  NK  	  5M! R V^ ,           4       4      pM,\
        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      p\
        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      pV F:  pV\        P                  \        P                  39  g   K*  \        RV,          4      h	  V# )é   c              3   ón   "  € T F+  qR 8X  d   \         P                  M\         P                  x € K-  	  R# 5i)Ú0N©r   ÚZeroÚOne©Ú.0Úqbs   & ÚQ/opt/data/home/.local/lib/python3.14/site-packages/sympy/physics/quantum/qubit.pyÚ	<genexpr>Ú(QubitState._eval_args.<locals>.<genexpr>E   s!   é € ÐKÁ7¸R¨#¤Iœ!Ÿ&š&´1·5±5Ô8Ã7ùs   ‚35c              3   ó€   "  € T F4  qR 8X  d   \         P                  MVR8X  d   \         P                  MTx € K6  	  R# 5i)r"   Ú1Nr#   r&   s   & r)   r*   r+   G   s,   é € Ð]ÑX\ÐRT¨#¤Iœ!Ÿ&š&¸BÀ#¼I´1·5²5È2ÔMÓX\ùs   ‚<>c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5i©Nr	   )r'   Úargs   & r)   r*   r+   H   s   é € Ð3©d s”X˜c—]�]«dùó   ‚z$Qubit values must be 0 or 1, got: %r)
ÚlenÚ
isinstancer   Úqubit_valuesÚstrÚtupler   r$   r%   Ú
ValueError)ÚclsÚargsÚelements   && r)   Ú
_eval_argsÚQubitState._eval_args<   sî   € ô ˆt‹9˜Œ>œj¨¨a­´*×=Ò=Ø˜•7×'Ñ'Ð'ô ˆt‹9˜Œ>œj¨¨a­´#×6Ò6ß”5ÑKÀ4ÈÆ7ÓK—5‘5ÑKÀ4ÈÆ7ÓKÓK‰Dç”5Ñ]ÑX\Ó]—5‘5Ñ]ÑX\Ó]Ó]ˆDßŒuÑ3©dÓ3�u‰uÑ3©dÓ3Ó3ˆó ˆGØœqŸv™v¤q§u¡u˜oÖ-Ü Ø:¸WÕDóFð Fñ ð ˆó    c                ó8   € \        ^4      \        V4      ,          # ©é   )r   r2   )r8   r9   s   &&r)   Ú_eval_hilbert_spaceÚQubitState._eval_hilbert_spaceQ   s   € ä˜A‹¤ D£	Õ)Ð)r=   c                ó,   € \        V P                  4      # )z"The number of Qubits in the state.)r2   r4   ©Úselfs   &r)   Ú	dimensionÚQubitState.dimensionY   s   € ô �4×$Ñ$Ó%Ð%r=   c                ó   € V P                   # r/   ©rF   rD   s   &r)   ÚnqubitsÚQubitState.nqubits^   s   € à�~‰~Ðr=   c                ó   € V P                   # )z,Returns the values of the qubits as a tuple.)ÚlabelrD   s   &r)   r4   ÚQubitState.qubit_valuesb   s   € ð �z‰zÐr=   c                ó   € V P                   # r/   rI   rD   s   &r)   Ú__len__ÚQubitState.__len__k   s   € Ø�~‰~Ðr=   c                ój   € V P                   \        V P                  V,
          ^,
          4      ,          # )r    )r4   ÚintrF   )rE   Úbits   &&r)   Ú__getitem__ÚQubitState.__getitem__n   s&   € Ø× Ñ ¤ T§^¡^°cÕ%9¸AÕ%=Ó!>Õ?Ð?r=   c                óä   € \        V P                  4      pV F=  p\        V P                  V,
          ^,
          4      pW$,          ^8X  d   ^ W$&   K9  ^W$&   K?  	  V P                  ! \        V4      !  # )zFlip the bit(s) given.)Úlistr4   rS   rF   Ú	__class__r6   )rE   ÚbitsÚnewargsÚirT   s   &*   r)   ÚflipÚQubitState.flipu   sa   € ä�t×(Ñ(Ó)ˆÛˆAÜ�d—n‘n qÕ(¨1Õ,Ó-ˆCØ�|˜qÔ Ø �“à �“ñ ð �~Š~œu W›~Ñ.Ð.r=   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__Úclassmethodr;   rA   ÚpropertyrF   rJ   r4   rP   rU   r]   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r)   r   r   5   s�   ø‡ € Ù,ð ñó ðð( ñ*ó ð*ð ñ&ó ð&ð ñó ðð ñó ðòò@÷	/ð 	/r=   r   c                   óR   a € ] tR t^�t o Rt]R 4       tR tR tR t	R t
R tRtV tR	# )
r   a  A multi-qubit ket in the computational (z) basis.

We use the normal convention that the least significant qubit is on the
right, so ``|00001>`` has a 1 in the least significant qubit.

Parameters
==========

values : list, str
    The qubit values as a list of ints ([0,0,0,1,1,]) or a string ('011').

Examples
========

Create a qubit in a couple of different ways and look at their attributes:

    >>> from sympy.physics.quantum.qubit import Qubit
    >>> Qubit(0,0,0)
    |000>
    >>> q = Qubit('0101')
    >>> q
    |0101>

    >>> q.nqubits
    4
    >>> len(q)
    4
    >>> q.dimension
    4
    >>> q.qubit_values
    (0, 1, 0, 1)

We can flip the value of an individual qubit:

    >>> q.flip(1)
    |0111>

We can take the dagger of a Qubit to get a bra:

    >>> from sympy.physics.quantum.dagger import Dagger
    >>> Dagger(q)
    <0101|
    >>> type(Dagger(q))
    <class 'sympy.physics.quantum.qubit.QubitBra'>

Inner products work as expected:

    >>> ip = Dagger(q)*q
    >>> ip
    <0101|0101>
    >>> ip.doit()
    1
c                ó   € \         # r/   )r   rD   s   &r)   Ú
dual_classÚQubit.dual_class¸   ó   € äˆr=   c                óx   € V P                   VP                   8X  d   \        P                  # \        P                  # r/   )rM   r   r%   r$   ©rE   ÚbraÚhintss   &&,r)   Ú_eval_innerproduct_QubitBraÚ!Qubit._eval_innerproduct_QubitBra¼   s$   € Ø�:‰:˜Ÿ™Ô"Ü—5‘5ˆLä—6‘6ˆMr=   c                ó&   € V P                   ! R/ VB # )Nr/   )Ú_represent_ZGate)rE   Úoptionss   &,r)   Ú_represent_default_basisÚQubit._represent_default_basisÂ   s   € Ø×$Ò$Ñ5¨WÑ5Ð5r=   c                óÄ  € VP                  RR4      p^p^ p\        V P                  4       F  pWTV,          ,          pV^,          pK  	  ^ .^V P                  ,          ,          p^V\	        V4      &   VR8X  d   \        V4      # VR8X  d&   ^ RIpVP                  VRR7      P                  4       # VR8X  d(   ^ RI	H
p	 V	P                  VRR7      P                  4       # R# )	zBRepresent this qubits in the computational basis (ZGate).
        ÚformatÚsympyÚnumpyNÚcomplex)Údtypeúscipy.sparse)Úsparse)ÚgetÚreversedr4   rF   rS   r   r~   ÚarrayÚ	transposeÚscipyr‚   Ú
csr_matrix)
rE   Úbasisrx   Ú_formatÚnÚdefinite_stateÚitÚresultÚnpr‚   s
   &&,       r)   rw   ÚQubit._represent_ZGateÅ   sÖ   € ð —+‘+˜h¨Ó0ˆØˆØˆÜ˜4×,Ñ,Ö-ˆBØ �dÕ"ˆNØ�!•ŠAñ .ð ��a˜Ÿ™Õ'Õ(ˆØ&'ˆŒs�>Ó"Ñ#Ø�gÔÜ˜&“>Ð!Ø˜ÔÛØ—8‘8˜F¨)�8Ó4×>Ñ>Ó@Ð@Ø˜Ô&Ý$Ø×$Ñ$ V°9Ð$Ó=×GÑGÓIÐIñ 'r=   c                ó°  € VP                  R . 4      p\        V4      p\        V4      ^ 8X  d    \        \        ^ V P                  4      4      pVP                  4        W,          p\        \        V4      ^,
          RR4       F$  pV P                  V\        WF,          4      4      pK&  	  \        V4      V P                  8X  d
   V^ ,          # \        V4      # )Úindiceséÿÿÿÿ)	rƒ   rX   r2   ÚrangerJ   ÚsortÚ_reduced_densityrS   Úmatrix_to_density)rE   rr   Úkwargsr’   Ú
sorted_idxÚnew_matr\   s   &&,    r)   Ú_eval_traceÚQubit._eval_traceÙ   s­   € Ø—*‘*˜Y¨Ó+ˆô ˜'“]ˆ
Üˆz‹?˜aÔÜœe A t§|¡|Ó4Ó5ˆJØ�‰Ôð •(ˆÜ”s˜:“¨Õ*¨B°Ö3ˆAà×+Ñ+¨G´S¸½Ó5GÓHŠGñ 4ô �
‹O˜tŸ|™|Ô+à˜1•:Ðä$ WÓ-Ð-r=   c           	     óL  € R p\        V3/ VB pVP                  pV^,          p\        4       P                  V4      p\	        V4       FW  p	\	        V4       FE  p
\	        ^4       F3  pV! W«V4      pV! W›V4      pW‰V
3;;,          W]V3,          ,          uu&   K5  	  KG  	  KY  	  V# )z‘Compute the reduced density matrix by tracing out one qubit.
The qubit argument should be of type Python int, since it is used
in bit operations
c                 ó‚   € ^V,          ^,
          pW,	          ^V,           ,          W,          ,           W,          ,           # r?   r_   )ÚjÚkÚqubitÚbit_masks   &&& r)   Úfind_index_that_is_projectedÚ<Qubit._reduced_density.<locals>.find_index_that_is_projectedô   s.   € Ø˜%•x !•|ˆHØ•Z Q¨¥YÕ/°AµLÕAÀQÅZÕPÐPr=   )r   Úcolsr   r   r”   )rE   Úmatrixr¡   rx   r£   Ú
old_matrixÚold_sizeÚnew_sizeÚ
new_matrixr\   rŸ   r    ÚcolÚrows   &&&,          r)   r–   ÚQubit._reduced_densityï   sž   € ò
	Qô ˜vÑ1¨Ñ1ˆ
Ø—?‘?ˆà˜Q•;ˆÜ“X—^‘^ HÓ-ˆ
ä�x–ˆAÜ˜8–_�Ü˜qž�AÙ6°q¸UÓC�CÙ6°q¸UÓC�CØ !˜t×$¨
¸°8Õ(<Õ<Õ$ó "ó %ñ !ð Ðr=   r_   N)r`   ra   rb   rc   rd   re   rm   rt   ry   rw   r›   r–   rg   rh   ri   s   @r)   r   r   �   s>   ø‡ € ñ4ðl ñó ðòò6òJò(.÷,ð r=   c                   ó4   a € ] tR tRt o Rt]R 4       tRtV tR# )r   i  aa  A multi-qubit bra in the computational (z) basis.

We use the normal convention that the least significant qubit is on the
right, so ``|00001>`` has a 1 in the least significant qubit.

Parameters
==========

values : list, str
    The qubit values as a list of ints ([0,0,0,1,1,]) or a string ('011').

See also
========

Qubit: Examples using qubits

c                ó   € \         # r/   )r   rD   s   &r)   rm   ÚQubitBra.dual_class  s   € äˆr=   r_   N©	r`   ra   rb   rc   rd   re   rm   rg   rh   ri   s   @r)   r   r     s   ø‡ € ñð" ñó ör=   c                   ób   a € ] tR tRt o Rt]R
R l4       t]R 4       tR tR t	R t
]	t]	tR	tV tR# )ÚIntQubitStatei  z>A base class for qubits that work with binary representations.Nc           
     ó  € \        V4      ^8X  d3   \        V^ ,          \        4      '       d   \        P                  V4      # \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g;   \        R\        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      : R24      hVeq   \        V\        \        34      '       g   \        R\        V4      ,          4      h\        V4      ^8w  d   \        RV: R	24      hV P                  V^ ,          V4      # \        V4      ^8X  dv   V^ ,          ^8”  dh   \        \        \        \        V^ ,          4      4      4      4      pV Uu. uF  qA^ ,          V,	          ^,          NK  	  pp\        P                  V4      # \        V4      ^8X  d/   V^,          ^8”  d!   V P                  V^ ,          V^,          4      # \        P                  V4      # u upi )
r    c              3   óN   "  € T F  p\        V\        \        34      x € K  	  R # 5ir/   )r3   rS   r   ©r'   Úas   & r)   r*   Ú+IntQubitState._eval_args.<locals>.<genexpr>(  s   é € ÐA¹D°q”Z ¤C¬ >×2Ð2»Dùs   ‚#%FTzvalues must be integers, got (c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir/   )Útyper¶   s   & r)   r*   r¸   )  s   é € ÐI`Ñ[_ÐVWÌ$ÈqÏ'È'Ó[_ùr1   Ú)z$nqubits must be an integer, got (%s)ztoo many positional arguments (z ). should be (number, nqubits=n))r2   r3   r   r;   Úallr7   r6   rS   r   rº   Ú_eval_args_with_nqubitsr„   r”   r   Úabs)r8   r9   rJ   Úrvaluesr\   r4   s   &&&   r)   r;   ÚIntQubitState._eval_args"  sŒ  € ô ˆt‹9˜Œ>œj¨¨a­´*×=Ò=Ü×(Ñ(¨Ó.Ð.ç“ÑA¹DÓA——’ÑA¹DÓA×AÒAÝÇEÄEÑI`Ñ[_ÓI`ÇEÁEÑI`Ñ[_ÓI`ÖD`ÐbÓcÐcàÒÜ˜g¬¬W ~×6Ò6Ü Ð!GÌ$ÈwË-Õ!WÓXÐXÜ�4‹y˜AŒ~Ý Û[_Ðaócð cà×.Ñ.¨t°A­w¸Ó@Ð@ô ˆt‹9˜Œ>˜d 1�g¨œkäœu¤X¬c°$°qµ'«lÓ%;Ó<Ó=ˆGÙ8?Ó@¹°1 !�W¨�\¨Q×.Ð.¹ˆLÐ@Ü×(Ñ(¨Ó6Ð6ô �‹Y˜!Œ^  Q¥¨!¤Ø×.Ñ.¨t°A­w¸¸Q½Ó@Ð@ä×(Ñ(¨Ó.Ð.ùò As   Å:Hc                óò   € \        \        V4      4      pW#8  d   \        R V: RV: R24      h\        \	        V4      4       Uu. uF  qAV,	          ^,          NK  	  pp\
        P                  V4      # u upi )zcannot represent z with z bits)r   r¾   r7   r„   r”   r   r;   )r8   ÚnumberrJ   Úneedr\   r4   s   &&&   r)   r½   Ú%IntQubitState._eval_args_with_nqubits@  sl   € äœ˜F›Ó$ˆØŒ>ÝÛ6<»gÐFóHð Hä3;¼EÀ'»NÔ3KÓLÑ3K¨a 1�¨×)Ð)Ñ3KˆÐLÜ×$Ñ$ \Ó2Ð2ùò Ms   ÁA4c                óv   € ^ p^p\        V P                  4       F  pWV,          ,          pV^,          pK  	  V# )z(Return the numerical value of the qubit.)r„   r4   )rE   rÂ   r‹   r\   s   &   r)   Úas_intÚIntQubitState.as_intI  s<   € àˆØˆÜ˜$×+Ñ+Ö,ˆAØ˜•c�MˆFØ�Q•ŠAñ -ð ˆr=   c                ó4   € \        V P                  4       4      # r/   )r5   rÆ   )rE   Úprinterr9   s   &&*r)   Ú_print_labelÚIntQubitState._print_labelR  s   € Ü�4—;‘;“=Ó!Ð!r=   c                ó@   € V P                   ! V.VO5!  p\        V4      # r/   )rÊ   r   )rE   rÉ   r9   rM   s   &&* r)   Ú_print_label_prettyÚ!IntQubitState._print_label_prettyU  s"   € Ø×!Ò! 'Ð1¨DÓ1ˆÜ˜%Ó Ð r=   r_   r/   )r`   ra   rb   rc   rd   re   r;   r½   rÆ   rÊ   rÍ   Ú_print_label_reprÚ_print_label_latexrg   rh   ri   s   @r)   r³   r³     sK   ø‡ € ÙHàó/ó ð/ð: ñ3ó ð3òò"ò!ð %ÐØ%Ör=   r³   c                   ó:   a € ] tR tRt o Rt]R 4       tR tRtV t	R# )r   i]  a¤  A qubit ket that store integers as binary numbers in qubit values.

The differences between this class and ``Qubit`` are:

* The form of the constructor.
* The qubit values are printed as their corresponding integer, rather
  than the raw qubit values. The internal storage format of the qubit
  values in the same as ``Qubit``.

Parameters
==========

values : int, tuple
    If a single argument, the integer we want to represent in the qubit
    values. This integer will be represented using the fewest possible
    number of qubits.
    If a pair of integers and the second value is more than one, the first
    integer gives the integer to represent in binary form and the second
    integer gives the number of qubits to use.
    List of zeros and ones is also accepted to generate qubit by bit pattern.

nqubits : int
    The integer that represents the number of qubits.
    This number should be passed with keyword ``nqubits=N``.
    You can use this in order to avoid ambiguity of Qubit-style tuple of bits.
    Please see the example below for more details.

Examples
========

Create a qubit for the integer 5:

    >>> from sympy.physics.quantum.qubit import IntQubit
    >>> from sympy.physics.quantum.qubit import Qubit
    >>> q = IntQubit(5)
    >>> q
    |5>

We can also create an ``IntQubit`` by passing a ``Qubit`` instance.

    >>> q = IntQubit(Qubit('101'))
    >>> q
    |5>
    >>> q.as_int()
    5
    >>> q.nqubits
    3
    >>> q.qubit_values
    (1, 0, 1)

We can go back to the regular qubit form.

    >>> Qubit(q)
    |101>

Please note that ``IntQubit`` also accepts a ``Qubit``-style list of bits.
So, the code below yields qubits 3, not a single bit ``1``.

    >>> IntQubit(1, 1)
    |3>

To avoid ambiguity, use ``nqubits`` parameter.
Use of this keyword is recommended especially when you provide the values by variables.

    >>> IntQubit(1, nqubits=1)
    |1>
    >>> a = 1
    >>> IntQubit(a, nqubits=1)
    |1>
c                ó   € \         # r/   )r   rD   s   &r)   rm   ÚIntQubit.dual_class¤  s   € äÐr=   c                ó,   € \         P                  W4      # r/   )r   rt   rq   s   &&,r)   Ú_eval_innerproduct_IntQubitBraÚ'IntQubit._eval_innerproduct_IntQubitBra¨  s   € Ü×0Ñ0°Ó;Ð;r=   r_   N)
r`   ra   rb   rc   rd   re   rm   rÕ   rg   rh   ri   s   @r)   r   r   ]  s*   ø‡ € ñEðL ñó ð÷<ð <r=   c                   ó4   a € ] tR tRt o Rt]R 4       tRtV tR# )r   i«  zBA qubit bra that store integers as binary numbers in qubit values.c                ó   € \         # r/   )r   rD   s   &r)   rm   ÚIntQubitBra.dual_class®  ro   r=   r_   Nr±   ri   s   @r)   r   r   «  s   ø‡ € ÙLàñó ör=   c           	     ó”  € Rp\        V \        4      '       d   Rp\        V \        4      '       d   RpV P                  ^ ,          ^8X  d)   V P                  ^,          p\	        V^4      pRp\
        pMRV P                  ^,          ^8X  d)   V P                  ^ ,          p\	        V^4      pRp\        pM\        RV ,          4      h\        V\        4      '       g   \        RV ,          4      h^ p\        V4       F”  pV'       d   W^ 3,          pMV ^ V3,          pVR9   d   \        V4      pV'       g   K=  \        V4       U	u. uF  p	\        V^V	,          ,          ^ 8g  4      NK!  	  p
p	V
P                  4        WhV! V
!  ,          ,           pK–  	  \        V\        \        \        34      '       d   VP!                  4       pV# u up	i )	a  Convert from the matrix repr. to a sum of Qubit objects.

Parameters
----------
matrix : Matrix, numpy.matrix, scipy.sparse
    The matrix to build the Qubit representation of. This works with
    SymPy matrices, numpy matrices and scipy.sparse sparse matrices.

Examples
========

Represent a state and then go back to its qubit form:

    >>> from sympy.physics.quantum.qubit import matrix_to_qubit, Qubit
    >>> from sympy.physics.quantum.represent import represent
    >>> q = Qubit('01')
    >>> matrix_to_qubit(represent(q))
    |01>
r}   r~   r�   FTz*Matrix must be a row/column vector, got %rz>Matrix must be a row/column vector of size 2**nqubits, got: %r)r~   r�   )r3   r   r   Úshaper   r   r   r   r   r”   r   rS   Úreverser   r   r   Úexpand)r¦   r|   ÚmlistlenrJ   Úketr8   rŽ   r\   r:   ÚxÚqubit_arrays   &          r)   Úmatrix_to_qubitrâ   ¸  s’  € ð* €FÜ�&œ-×(Ò(ØˆÜ�&Ô-×.Ò.Øˆð ‡|�|�A…˜!ÔØ—<‘< •?ˆÜ�h Ó"ˆØˆÜ‰Ø	�‰�a�˜AÔ	Ø—<‘< •?ˆÜ�h Ó"ˆØˆÜ‰äØ8¸6ÕAó
ð 	
ô �gœw×'Ò'Üð 1Ø39õ:ó ;ð 	;ð €FÜ�8Ž_ˆßØ ˜T•l‰Gà˜Q ˜T•lˆGØÐ.Ô.Ü˜gÓ&ˆGß‰7ô <AÀ¼>ÓJ¹>°aœ3˜q A¨¥F�|¨qÑ0Ö1¹>ˆKÐJØ×ÑÔ!Ø¡c¨;Ñ&7Õ7Õ7ŠFñ ô �&œ3¤¤S˜/×*Ò*Ø—‘“ˆà€Mùò Ks   Å%Gc           
     ó   € ^ RI Hp V P                  4       pV UUu. uF?  q3^,           F0  qC^ ,          ^ 8w  g   K  \        \	        V.4      4      V^ ,          .NK2  	  KA  	  ppp\        V4      ^ 8X  d   \        P                  # V! V!  # u uppi )zŽ
Works by finding the eigenvectors and eigenvalues of the matrix.
We know we can decompose rho by doing:
sum(EigenVal*|Eigenvect><Eigenvect|)
)ÚDensity)Úsympy.physics.quantum.densityrä   Ú
eigenvectsrâ   r   r2   r   r$   )Úmaträ   Úeigenrà   Úvectorr9   s   &     r)   r—   r—   þ  s�   € õ 6Ø�N‰NÓ€Eá%*ôLÙ%* ¸1¿¸¨vÀ1ÅÈÁôŒ_œVØ	ˆ
óó Ø˜•dóÙ9=ñÙ%*ð 	ñ LäˆD‹	�QŒÜ�v‰vˆá˜‰~ÐùóLs
   œB
»&B
c                ó   € \        WR7      # )z§Converts an Add/Mul of Qubit objects into it's matrix representation

This function is the inverse of ``matrix_to_qubit`` and is a shorthand
for ``represent(qubit)``.
)r|   r   )r¡   r|   s   &&r)   Úqubit_to_matrixrë     s   € ô �UÔ*Ð*r=   c           
     óÚ  € \        W4      pVR8X  dÐ   . pV'       d   VP                  4       p\        VP                  4      p\	        \
        P                  ! V4      \
        P                  ! ^4      ,          4      p\        V4       FU  pW7,          '       g   K  VP                  \        \        WvR7      4      W7,          \        W7,          4      ,          34       KW  	  V# \        R4      h)a!  Perform an ensemble measurement of all qubits.

Parameters
==========

qubit : Qubit, Add
    The qubit to measure. This can be any Qubit or a linear combination
    of them.
format : str
    The format of the intermediate matrices to use. Possible values are
    ('sympy','numpy','scipy.sparse'). Currently only 'sympy' is
    implemented.

Returns
=======

result : list
    A list that consists of primitive states and their probabilities.

Examples
========

    >>> from sympy.physics.quantum.qubit import Qubit, measure_all
    >>> from sympy.physics.quantum.gate import H
    >>> from sympy.physics.quantum.qapply import qapply

    >>> c = H(0)*H(1)*Qubit('00')
    >>> c
    H(0)*H(1)*|00>
    >>> q = qapply(c)
    >>> measure_all(q)
    [(|00>, 1/4), (|01>, 1/4), (|10>, 1/4), (|11>, 1/4)]
r}   ©rJ   ú8This function cannot handle non-SymPy matrix formats yet)rë   Ú
normalizedÚmaxrÛ   rS   Úmathr   r”   Úappendr   r   r   ÚNotImplementedError)r¡   r|   Ú	normalizeÚmÚresultsÚsizerJ   r\   s   &&&     r)   Úmeasure_allrø     s­   € ôD 	˜Ó&€Aà�ÔØˆçØ—‘“ˆAä�1—7‘7‹|ˆÜ”d—h’h˜t“n¤T§X¢X¨a£[Õ0Ó1ˆÜ�t–ˆAØ�tŽtØ—‘Üœ8 AÔ7Ó8¸!½$¼yÈÍ»Õ:NÐOöñ ð
 ˆä!ØFó
ð 	
r=   c                óÂ  € \        W4      p\        V\        \        34      '       d   \	        V4      3pVR8X  dœ   V'       d   VP                  4       p\        WA4      p. pV Fn  p^ pW‡P                  V,          ^ ,          ,          pV^ 8w  g   K.  V'       d   \        VP                  4       4      p	M\        V4      p	VP                  V	V34       Kp  	  V# \        R4      h)a}  Perform a partial ensemble measure on the specified qubits.

Parameters
==========

qubits : Qubit
    The qubit to measure.  This can be any Qubit or a linear combination
    of them.
bits : tuple
    The qubits to measure.
format : str
    The format of the intermediate matrices to use. Possible values are
    ('sympy','numpy','scipy.sparse'). Currently only 'sympy' is
    implemented.

Returns
=======

result : list
    A list that consists of primitive states and their probabilities.

Examples
========

    >>> from sympy.physics.quantum.qubit import Qubit, measure_partial
    >>> from sympy.physics.quantum.gate import H
    >>> from sympy.physics.quantum.qapply import qapply

    >>> c = H(0)*H(1)*Qubit('00')
    >>> c
    H(0)*H(1)*|00>
    >>> q = qapply(c)
    >>> measure_partial(q, (0,))
    [(sqrt(2)*|00>/2 + sqrt(2)*|10>/2, 1/2), (sqrt(2)*|01>/2 + sqrt(2)*|11>/2, 1/2)]
r}   rî   )rë   r3   r   r   rS   rï   Ú_get_possible_outcomesÚHrâ   rò   ró   )
r¡   rZ   r|   rô   rõ   Úpossible_outcomesÚoutputÚoutcomeÚprob_of_outcomeÚnext_matrixs
   &&&&      r)   Úmeasure_partialr  T  sÓ   € ôH 	˜Ó&€Aä�$œ¤WÐ-×.Ò.Ü�D“	ˆ|ˆà�ÔßØ—‘“ˆAä2°1Ó;Ðð ˆÛ(ˆGð  ˆOØ§	¡	¨'Õ 1°1Õ5Õ5ˆOð  !Ö#ßÜ"1°'×2DÑ2DÓ2FÓ"G‘Kä"1°'Ó":�Kà—‘ØØ#ðö ñ )ð& ˆä!ØFó
ð 	
r=   c                ó6  € ^ RI p\        W4      pVR8X  dz   VP                  4       p\        WA4      pVP                  4       p^ pV FD  pWxP                  V,          ^ ,          ,          pWv8¼  g   K+  \        VP                  4       4      u # 	  R# \        R4      h)aI  Perform a partial oneshot measurement on the specified qubits.

A oneshot measurement is equivalent to performing a measurement on a
quantum system. This type of measurement does not return the probabilities
like an ensemble measurement does, but rather returns *one* of the
possible resulting states. The exact state that is returned is determined
by picking a state randomly according to the ensemble probabilities.

Parameters
----------
qubits : Qubit
    The qubit to measure.  This can be any Qubit or a linear combination
    of them.
bits : tuple
    The qubits to measure.
format : str
    The format of the intermediate matrices to use. Possible values are
    ('sympy','numpy','scipy.sparse'). Currently only 'sympy' is
    implemented.

Returns
-------
result : Qubit
    The qubit that the system collapsed to upon measurement.
Nr}   rî   )Úrandomrë   rï   rú   rû   râ   ró   )	r¡   rZ   r|   r  rõ   rü   Úrandom_numberÚ
total_probrþ   s	   &&&      r)   Úmeasure_partial_oneshotr  Ÿ  s�   € ó4 Ü˜Ó&€Aà�ÔØ�L‰L‹NˆÜ2°1Ó;Ðð Ÿ™›ˆØˆ
Û(ˆGð Ÿ9™9 WÕ,¨aÕ0Õ0ˆJØÖ*Ü& w×'9Ñ'9Ó';Ó<Ò<ó )ô "ØFó
ð 	
r=   c                ó(  € \        V P                  4      p\        \        P                  ! V4      R,           4      p. p\        ^\        V4      ,          4       F%  pVP                  \        ^V,          ^4      4       K'  	  . pV F  pVP                  ^V,          4       K  	  \        ^V,          4       FW  p^ p\        \        V4      4       F)  p	WVV	,          ,          '       g   K  W‰^,           ,          pK+  	  W,          WH,          V&   KY  	  V# )a°  Get the possible states that can be produced in a measurement.

Parameters
----------
m : Matrix
    The matrix representing the state of the system.
bits : tuple, list
    Which bits will be measured.

Returns
-------
result : list
    The list of possible states which can occur given this measurement.
    These are un-normalized so we can derive the probability of finding
    this state by taking the inner product with itself
çš™™™™™¹?)	rð   rÛ   rS   rñ   Úlog2r”   r2   rò   r   )
rõ   rZ   r÷   rJ   Úoutput_matricesr\   Ú	bit_masksrT   ÚtruenessrŸ   s
   &&        r)   rú   rú   Ï  sá   € ô( ˆq�w‰w‹<€DÜ”$—)’)˜D“/ BÕ&Ó'€Gð €OÜ�1œ˜D›	•>Ö"ˆØ×Ñœu Q¨¥Z°Ó3Ö4ñ #ð €IÛˆØ×Ñ˜˜c�Ö"ñ ô �1�g•:ÖˆØˆä”s˜9“~Ö&ˆAØ˜Q•<×ÖØ �EÕ!’ñ 'ð ()¥tˆÕ! !Ó$ñ ð Ðr=   c                ó”  € ^ RI p\        V 4      pVR8X  d©   VP                  4       pVP                  4       p^ p^ pV F1  pWWVP                  4       ,          ,          pWT8”  d    MV^,          pK3  	  \	        \        V\        \        P                  ! \        VP                  4      4      R,           4      R7      4      # \        R4      h)a  Perform a oneshot ensemble measurement on all qubits.

A oneshot measurement is equivalent to performing a measurement on a
quantum system. This type of measurement does not return the probabilities
like an ensemble measurement does, but rather returns *one* of the
possible resulting states. The exact state that is returned is determined
by picking a state randomly according to the ensemble probabilities.

Parameters
----------
qubits : Qubit
    The qubit to measure.  This can be any Qubit or a linear combination
    of them.
format : str
    The format of the intermediate matrices to use. Possible values are
    ('sympy','numpy','scipy.sparse'). Currently only 'sympy' is
    implemented.

Returns
-------
result : Qubit
    The qubit that the system collapsed to upon measurement.
Nr}   r  rí   rî   )r  rë   rï   r   r   r   rS   rñ   r	  rð   rÛ   ró   )r¡   r|   r  rõ   r  ÚtotalrŽ   r\   s   &&      r)   Úmeasure_all_oneshotr    s¦   € ó0 Ü˜Ó€Aà�ÔØ�L‰L‹NˆØŸ™›ˆØˆØˆÛˆAØ�q—{‘{“}•_Õ$ˆEØÔ$ÙØ�a�KŠFñ	 ô
 ”X˜f¬c´$·)²)¼CÀÇÁ»LÓ2IÈBÕ2NÓ.OÔPÓQÐQä!ØFó
ð 	
r=   )r   r   r   r   rë   râ   r—   rø   r  r  r  )r}   )r}   T)7rd   rñ   Úsympy.core.addr   Úsympy.core.mulr   Úsympy.core.numbersr   Úsympy.core.powerr   Úsympy.core.singletonr   Ú$sympy.functions.elementary.complexesr   Ú&sympy.functions.elementary.exponentialr   Úsympy.core.basicr
   Úsympy.external.gmpyr   Úsympy.matricesr   r   Ú sympy.printing.pretty.stringpictr   Úsympy.physics.quantum.hilbertr   Úsympy.physics.quantum.stater   r   r   Úsympy.physics.quantum.qexprr   Úsympy.physics.quantum.representr   Ú!sympy.physics.quantum.matrixutilsr   r   Úmpmath.libmp.libintmathr   Ú__all__r   r   r   r³   r   r   râ   r—   rë   rø   r  r  rú   r  r_   r=   r)   Ú<module>r"     sÙ   ðñó å Ý Ý &Ý  Ý "Ý :Ý 6Ý %Ý *ß (Ý 7å 6ß 7Ñ 7å 4Ý 5÷õ -ò€ô&I/�ô I/ôXDˆJ˜ô DôNˆz˜3ô ô.;&�Jô ;&ô|L<ˆ}˜eô L<ô\�- ô òCòLô +ô5
ôpH
ôV-
ò`0öf)
r=   