+
    
þÎjý  ã                   óŽ   € ^ 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	 tR
 tR t ! R R]4      tR# )é    )ÚAdd)ÚTuple)ÚExpr)ÚMul)ÚPow)Údefault_sort_key)Úsympify)ÚMatrixc                ó$  € \        V 4      p \        V \        4      '       do   V P                  '       g[   V P                  '       gI   V P
                  '       g7   V P                  '       g%   V P                  '       d   V P                  '       d   R# R# )zHelper method used in TrTF)	r	   Ú
isinstancer   Ú
is_IntegerÚis_FloatÚis_RationalÚ	is_NumberÚ	is_SymbolÚis_commutative)Úes   &ÚQ/opt/data/home/.local/lib/python3.14/site-packages/sympy/physics/quantum/trace.pyÚ
_is_scalarr      sV   € ô 	�‹
€AÜ�!”T×ÒØ�L�LˆL˜AŸJŸJ˜JØ�M�MˆM˜QŸ[Ÿ[˜[Ø�[�[ˆ[˜Q×-×-Ð-ááó    c                ó,  € \        V 4      ^8X  d   V # \        V \        R7      p\        V 4       UUu. uF  w  r#W18X  g   K  VNK  	  ppp\	        V 4      pVP                  V 4       VP                  \        V 4      V^ ,          ,           4       \        \        V4      ^,
          4       Uu. uF  q%WB,          WB^,           ,           .NK  	  ppVP                  \        V4      4      pWTV,          WG,          \        V 4      ,            pV# u uppi u upi )a  Cyclic permutations based on canonical ordering

Explanation
===========

This method does the sort based ascii values while
a better approach would be to used lexicographic sort.

TODO: Handle condition such as symbols have subscripts/superscripts
in case of lexicographic sort

)Úkey)	ÚlenÚminr   Ú	enumerateÚlistÚextendÚappendÚrangeÚindex)	ÚlÚmin_itemÚiÚxÚindicesÚleÚsublistÚidxÚ	ordered_ls	   &        r   Ú_cycle_permuter*      sí   € ô ˆ1ƒv�„{Øˆä�1Ô*Ô+€HÜ& qœ\Ô;™\‘T�Q¨Q©]�qˆq™\€GÑ;ä	ˆa‹€BØ‡I�Iˆa„Lð ‡N�N”3�q“6˜G A�JÕ&Ô'ô ”S˜“\ AÕ%Ô&ó(Ù&ð 45�7•:˜g¨!¥e�nÐ-Ó.Ù&ð ð (ð
 �-‰-œ˜G›Ó
%€CØ˜3•< ¥¬s°1«vÕ 5Ð6€IàÐùó' <ùò(s   ²
DÁDÂ+!Dc                ó�   € \        V 4      ^8X  d   V # \        V RR 4      pVP                  V ^ R 4       \        V!  P                  # )z\this just moves the last arg to first position
to enable expansion of args
A,B,A ==> A**2,B
Néÿÿÿÿ)r   r   r   r   Úargs)r!   r$   s   & r   Ú_rearrange_argsr.   B   sC   € ô
 ˆ1ƒv�„{ØˆäˆQˆrˆsˆV‹€AØ‡H�HˆQˆq�ˆWÔÜ�‰7�<‰<Ðr   c                   ó\   a € ] tR t^Ot o RtR t]R 4       tR t]R 4       t	R t
R tRtV tR	# )
ÚTra)  Generic Trace operation than can trace over:

a) SymPy matrix
b) operators
c) outer products

Parameters
==========
o : operator, matrix, expr
i : tuple/list indices (optional)

Examples
========

# TODO: Need to handle printing

a) Trace(A+B) = Tr(A) + Tr(B)
b) Trace(scalar*Operator) = scalar*Trace(Operator)

>>> from sympy.physics.quantum.trace import Tr
>>> from sympy import symbols, Matrix
>>> a, b = symbols('a b', commutative=True)
>>> A, B = symbols('A B', commutative=False)
>>> Tr(a*A,[2])
a*Tr(A)
>>> m = Matrix([[1,2],[1,1]])
>>> Tr(m)
2

c           	     ó¼  € \        V4      ^8X  dV   \        V^,          \        \        \        34      '       g   \        V^,          4      pM\        V^,          !  pV^ ,          pM/\        V4      ^8X  d   \        4       pV^ ,          pM\        R4      h\        V\        4      '       d   VP                  4       # \        VR4      '       d,   \        VP                  4      '       d   VP                  4       # \        V\        4      '       d-   \        VP                   Uu. uF  p\        WB4      NK  	  up!  # \        V\        4      '       dm   VP                  4       w  rV\        V4      ^ 8X  d
   \        V!  # \        P                   ! V \        V!  V4      p\        V4      ^ 8”  d   \        V!  V,          # T# \        V\"        4      '       d^   \%        VP                  ^ ,          4      '       d%   \%        VP                  ^,          4      '       d   V# \        P                   ! WV4      # \%        V4      '       d   V# \        P                   ! WV4      # u upi )ztConstruct a Trace object.

Parameters
==========
args = SymPy expression
indices = tuple/list if indices, optional

z5Arguments to Tr should be of form (expr[, [indices]])Útrace)r   r   r   r   ÚtupleÚ
ValueErrorr
   r2   ÚhasattrÚcallabler   r-   r0   r   Úargs_cncr   Ú__new__r   r   )Úclsr-   r%   ÚexprÚargÚc_partÚnc_partÚobjs   &*      r   r8   Ú
Tr.__new__n   s¿  € ô �‹I˜ŒNÜ˜d 1�g¬¬e´UÐ';×<Ò<Ü  Q¥›.‘ä  a¥™/�à˜•7‰DÜ�$‹i˜1ŒnÜ“gˆGØ˜•7‰Däð 3ó 4ð 4ô �dœF×#Ò#Ø—:‘:“<ÐÜ�T˜7×#Ò#¬°·±×(<Ò(<à—:‘:“<ÐÜ˜œc×"Ò"Ü°T·Y²YÓ?±Y¨cœ˜CÖ)±YÑ?Ñ@Ð@Ü˜œc×"Ò"Ø"Ÿm™m›o‰OˆFÜ�7‹|˜qÔ Ü˜F‘|Ð#ä—l’l 3¬¨W©°wÓ@�ô ,/¨v«;¸¬?”s˜F‘| CÕ'ÐCÀÐCÜ˜œc×"Ò"Ü˜4Ÿ9™9 Q�<×(Ò(Ü˜tŸy™y¨�|×,Ò,Ø�ä—|’| C¨wÓ7Ð7ä˜4× Ò Ø�ä—<’< ¨7Ó3Ð3ùò) @s   Ä!Ic                óX   € V P                   ^ ,          pVP                  pVP                  # ©r   )r-   ÚkindÚelement_kind)Úselfr:   Ú	expr_kinds   &  r   rB   ÚTr.kind£   s$   € à�y‰y˜�|ˆØ—I‘Iˆ	Ø×%Ñ%Ð%r   c                ó´   € \        V P                  ^ ,          R4      '       d5   V P                  ^ ,          P                  V P                  ^,          R7      # V # )aE  Perform the trace operation.

#TODO: Current version ignores the indices set for partial trace.

>>> from sympy.physics.quantum.trace import Tr
>>> from sympy.physics.quantum.operator import OuterProduct
>>> from sympy.physics.quantum.spin import JzKet, JzBra
>>> t = Tr(OuterProduct(JzKet(1,1), JzBra(1,1)))
>>> t.doit()
1

Ú_eval_trace)r%   )r5   r-   rH   )rD   Úhintss   &,r   ÚdoitÚTr.doit©   sB   € ô �4—9‘9˜Q•< ×/Ò/Ø—9‘9˜Q•<×+Ñ+°D·I±I¸aµLÐ+ÓAÐAàˆr   c                ó   € R # )T© )rD   s   &r   Ú	is_numberÚTr.is_number»   s   € ñ r   c                óž  € V^ 8”  d/   V\        V P                  ^ ,          P                  4      ,          pM7\        V4      \        V P                  ^ ,          P                  4      ,          ) p\        V P                  ^ ,          P                  V) R V P                  ^ ,          P                  ^ V)  ,           4      p\	        \        V!  4      # )a[  Permute the arguments cyclically.

Parameters
==========

pos : integer, if positive, shift-right, else shift-left

Examples
========

>>> from sympy.physics.quantum.trace import Tr
>>> from sympy import symbols
>>> A, B, C, D = symbols('A B C D', commutative=False)
>>> t = Tr(A*B*C*D)
>>> t.permute(2)
Tr(C*D*A*B)
>>> t.permute(-2)
Tr(C*D*A*B)

N)r   r-   Úabsr   r0   r   )rD   Úposr-   s   && r   ÚpermuteÚ
Tr.permuteÂ   s˜   € ð* �Œ7Øœ˜DŸI™I a�L×-Ñ-Ó.Õ.‰Cä˜“Hœs 4§9¡9¨Q¥<×#4Ñ#4Ó5Õ5Ð6ˆCä�D—I‘I˜a•L×%Ñ% s d eÐ,¨t¯y©y¸­|×/@Ñ/@ÀÀCÀ4Ð/HÕHÓIˆä”#˜‘,ÓÐr   c                ó   € \        V P                  ^ ,          \        4      '       d1   \        \	        V P                  ^ ,          P                  4      4      pMV P                  ^ ,          .p\        V4      V P                  ^,          3,           # rA   )r   r-   r   r*   r.   r3   )rD   r-   s   & r   Ú_hashable_contentÚTr._hashable_contentà   s]   € Ü�d—i‘i •l¤C×(Ò(Ü!¤/°$·)±)¸Aµ,×2CÑ2CÓ"DÓE‰Dà—I‘I˜a•L�>ˆDä�T‹{˜dŸi™i¨�lÐ-Õ-Ð-r   rM   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r8   ÚpropertyrB   rJ   rN   rS   rV   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r0   r0   O   sL   ø‡ € ñò<34ðj ñ&ó ð&ò
ð$ ñó ðò ÷<.ð .r   r0   N)Úsympy.core.addr   Úsympy.core.containersr   Úsympy.core.exprr   Úsympy.core.mulr   Úsympy.core.powerr   Úsympy.core.sortingr   Úsympy.core.sympifyr	   Úsympy.matricesr
   r   r*   r.   r0   rM   r   r   Ú<module>ri      s;   ðÝ Ý 'Ý  Ý Ý  Ý /Ý &Ý !òò%òP
ôW.ˆö W.r   