Ë
    7^(h71  ã                   óâ  — d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZmZmZmZmZ ddl m!Z!m"Z"m#Z# ddl$m%Z%m&Z& ddl'm(Z( ddgZ)da*d„ Z+ G d„ de«      Z,d„ Z-d„ Z.d„ Z/e,j`                  jc                  ee«      d„ «       Z2e,j`                  jc                  ee«      d„ «       Z3e,j`                  jc                  ee«      d„ «       Z4y)zAbstract tensor product.é    )ÚAdd)ÚExpr)ÚKindDispatcher)ÚMul)ÚPow)Úsympify)ÚDenseMatrix)ÚImmutableDenseMatrix)Ú
prettyForm©Úsympy_deprecation_warning)ÚDagger)ÚKetKindÚ_KetKindÚBraKindÚ_BraKindÚOperatorKindÚ_OperatorKind)Únumpy_ndarrayÚscipy_sparse_matrixÚmatrix_tensor_product)ÚKetÚBra)ÚTrÚTensorProductÚtensor_product_simpFc                 ó   — | a y)a»  Set flag controlling whether tensor products of states should be
    printed as a combined bra/ket or as an explicit tensor product of different
    bra/kets. This is a global setting for all TensorProduct class instances.

    Parameters
    ----------
    combine : bool
        When true, tensor product states are combined into one ket/bra, and
        when false explicit tensor product notation is used between each
        ket/bra.
    N)Ú_combined_printing)Úcombineds    úa/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/physics/quantum/tensorproduct.pyÚcombined_tensor_printingr!   )   s
   € ð "Ñó    c                   ó~   — e Zd ZdZdZ edd¬«      Zed„ «       Zd„ Z	e
d„ «       Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)r   a  The tensor product of two or more arguments.

    For matrices, this uses ``matrix_tensor_product`` to compute the Kronecker
    or tensor product matrix. For other objects a symbolic ``TensorProduct``
    instance is returned. The tensor product is a non-commutative
    multiplication that is used primarily with operators and states in quantum
    mechanics.

    Currently, the tensor product distinguishes between commutative and
    non-commutative arguments.  Commutative arguments are assumed to be scalars
    and are pulled out in front of the ``TensorProduct``. Non-commutative
    arguments remain in the resulting ``TensorProduct``.

    Parameters
    ==========

    args : tuple
        A sequence of the objects to take the tensor product of.

    Examples
    ========

    Start with a simple tensor product of SymPy matrices::

        >>> from sympy import Matrix
        >>> from sympy.physics.quantum import TensorProduct

        >>> m1 = Matrix([[1,2],[3,4]])
        >>> m2 = Matrix([[1,0],[0,1]])
        >>> TensorProduct(m1, m2)
        Matrix([
        [1, 0, 2, 0],
        [0, 1, 0, 2],
        [3, 0, 4, 0],
        [0, 3, 0, 4]])
        >>> TensorProduct(m2, m1)
        Matrix([
        [1, 2, 0, 0],
        [3, 4, 0, 0],
        [0, 0, 1, 2],
        [0, 0, 3, 4]])

    We can also construct tensor products of non-commutative symbols:

        >>> from sympy import Symbol
        >>> A = Symbol('A',commutative=False)
        >>> B = Symbol('B',commutative=False)
        >>> tp = TensorProduct(A, B)
        >>> tp
        AxB

    We can take the dagger of a tensor product (note the order does NOT reverse
    like the dagger of a normal product):

        >>> from sympy.physics.quantum import Dagger
        >>> Dagger(tp)
        Dagger(A)xDagger(B)

    Expand can be used to distribute a tensor product across addition:

        >>> C = Symbol('C',commutative=False)
        >>> tp = TensorProduct(A+B,C)
        >>> tp
        (A + B)xC
        >>> tp.expand(tensorproduct=True)
        AxC + BxC
    FÚTensorProduct_kind_dispatcherT)Úcommutativec                 óF   — d„ | j                   D «       } | j                  |Ž S )zBCalculate the kind of a tensor product by looking at its children.c              3   ó4   K  — | ]  }|j                   –— Œ y ­w©N)Úkind)Ú.0Úas     r    ú	<genexpr>z%TensorProduct.kind.<locals>.<genexpr>„   s   è ø€ Ò/ �Q—V•VÑ/ùs   ‚)ÚargsÚ_kind_dispatcher)ÚselfÚ	arg_kindss     r    r)   zTensorProduct.kind�   s%   € ñ 0 T§Y¡YÔ/ˆ	Ø$ˆt×$Ñ$ iÐ0Ð0r"   c                 ó$  — t        |d   t        t        t        t        f«      rt        |Ž S | j                  t        |«      «      \  }}t        |Ž }t        |«      dk(  r|S t        |«      dk(  r||d   z  S t        j                  | g|¢­Ž }||z  S )Nr   é   )Ú
isinstanceÚMatrixÚImmutableMatrixr   r   r   Úflattenr   r   Úlenr   Ú__new__)Úclsr-   Úc_partÚnew_argsÚtps        r    r8   zTensorProduct.__new__‡   s”   € Ü�d˜1‘g¤¬¼Ü4Gð Iô Jä(¨$Ð/Ð/ØŸ;™;¤w¨t£}Ó5Ñˆ�Ü�f�ˆÜˆx‹=˜AÒØˆMÜ�‹]˜aÒØ˜H Q™KÑ'Ð'ä—‘˜cÐ- HÒ-ˆBØ˜B‘;Ðr"   c                 óÂ   — g }g }|D ]S  }|j                  «       \  }}|j                  t        |«      «       |j                  t	        j
                  |«      «       ŒU ||fS r(   )Úargs_cncÚextendÚlistÚappendr   Ú
_from_args)r9   r-   r:   Únc_partsÚargÚcpÚncps          r    r6   zTensorProduct.flatten•   s^   € ð ˆØˆØò 	1ˆCØ—l‘l“n‰GˆB�Ø�M‰Mœ$˜r›(Ô#Ø�O‰OœCŸN™N¨3Ó/Õ0ð	1ð �xÐÐr"   c                 ó^   — t        | j                  D �cg c]  }t        |«      ‘Œ c}Ž S c c}w r(   )r   r-   r   )r/   Úis     r    Ú_eval_adjointzTensorProduct._eval_adjoint    s#   € Ü°$·)±)Ö<¨Qœv a�yÒ<Ð=Ð=ùÒ<s   ”*c                 ó2   — t        |Ž j                  d¬«      S )NT)Útensorproduct)r   Úexpand)r/   Úruler-   Úhintss       r    Ú_eval_rewritezTensorProduct._eval_rewrite£   s   € Ü˜dÐ#×*Ñ*¸Ð*Ó>Ð>r"   c                 óf  — t        | j                  «      }d}t        |«      D ]‹  }t        | j                  |   t        t
        t        f«      r|dz   }||j                  | j                  |   «      z   }t        | j                  |   t        t
        t        f«      r|dz   }||dz
  k7  sŒ‡|dz   }Œ� |S )NÚ ú(ú)r2   Úx)r7   r-   Úranger3   r   r   r   Ú_print)r/   Úprinterr-   ÚlengthÚsrH   s         r    Ú	_sympystrzTensorProduct._sympystr¦   sŸ   € Ü�T—Y‘Y“ˆØˆÜ�v“ò 	ˆAÜ˜$Ÿ)™) A™,¬¬c´3¨Ô8Ø˜‘G�Ø�G—N‘N 4§9¡9¨Q¡<Ó0Ñ0ˆAÜ˜$Ÿ)™) A™,¬¬c´3¨Ô8Ø˜‘G�Ø�F˜Q‘J‹Ø˜‘G‘ð	ð ˆr"   c                 óÒ  — t         �rðt        d„ | j                  D «       «      st        d„ | j                  D «       «      �r·t        | j                  «      } |j                  dg|¢­Ž }t        |«      D �]"  } |j                  dg|¢­Ž }t        | j                  |   j                  «      }t        |«      D ]f  } |j                  | j                  |   j                  |   g|¢­Ž }	t        |j                  |	«      Ž }||dz
  k7  sŒPt        |j                  d«      Ž }Œh t        | j                  |   j                  «      dkD  rt        |j                  dd¬«      Ž }t        |j                  |«      Ž }||dz
  k7  s�Œt        |j                  d«      Ž }�Œ% t        |j                  | j                  d	   j                  «      Ž }t        |j                  | j                  d	   j                  «      Ž }|S t        | j                  «      } |j                  dg|¢­Ž }t        |«      D ]¹  } |j                  | j                  |   g|¢­Ž }t        | j                  |   t        t        f«      rt        |j                  d
d¬«      Ž }t        |j                  |«      Ž }||dz
  k7  sŒ|j                  rt        |j                  d«      Ž }Œ£t        |j                  d«      Ž }Œ» |S )Nc              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr(   ©r3   r   ©r*   rD   s     r    r,   z(TensorProduct._pretty.<locals>.<genexpr>¶   ó   è ø€ Ò?¨c”Z ¤S×)Ñ?ùó   ‚c              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr(   ©r3   r   r^   s     r    r,   z(TensorProduct._pretty.<locals>.<genexpr>·   r_   r`   rQ   r2   ú, ú{ú})ÚleftÚrightr   rR   rS   u   â¨‚ zx )r   Úallr-   r7   rV   rU   r   rg   Úparensrf   ÚlbracketÚrbracketr3   r   r   Ú_use_unicode)
r/   rW   r-   rX   ÚpformrH   Ú
next_pformÚlength_iÚjÚ
part_pforms
             r    Ú_prettyzTensorProduct._pretty³   s“  € æÜÑ?°T·Y±YÔ?Ô?ÜÑ?°T·Y±YÔ?Õ?ä˜Ÿ™“^ˆFØ"�G—N‘N 2Ð-¨Ò-ˆEÜ˜6“]ó @�Ø+˜WŸ^™^¨BÐ6°Ò6�
Ü˜tŸy™y¨™|×0Ñ0Ó1�Ü˜x›ò I�AØ!/ §¡°·	±	¸!±×0AÑ0AÀ!Ñ0DÐ!LÀtÒ!L�JÜ!+¨Z×-=Ñ-=¸jÓ-IÐ!J�JØ˜H q™LÓ(Ü%/°×1AÑ1AÀ$Ó1GÐ%H™
ð	Iô �t—y‘y ‘|×(Ñ(Ó)¨AÒ-Ü!+Ø#×*Ñ*°¸3Ð*Ó?ð"A�Jä" E§K¡K°
Ó$;Ð<�Ø˜ ™
”?Ü&¨¯©°IÓ(>Ð?’Eð@ô   §
¡
¨4¯9©9°Q©<×+@Ñ+@Ó AÐBˆEÜ §¡¨D¯I©I°a©L×,AÑ,AÓ BÐCˆEØˆLä�T—Y‘Y“ˆØ�—‘˜rÐ) DÒ)ˆÜ�v“ò 	@ˆAØ'˜Ÿ™¨¯	©	°!©Ð<°tÒ<ˆJÜ˜$Ÿ)™) A™,¬¬c¨
Ô3Ü'Ø×&Ñ&¨C°sÐ&Ó;ð�
ô  §¡¨JÓ 7Ð8ˆEØ�F˜Q‘J‹Ø×'Ò'Ü&¨¯©Ð4\Ó(]Ð^‘Eä&¨¯©°IÓ(>Ð?‘Eð	@ð ˆr"   c                 ó  — t         rÇt        d„ | j                  D «       «      st        d„ | j                  D «       «      r�d„ }dj                  | j                  D �cg c]/  } | |j                  |g|¢­Ž t        |j                  «      «      ‘Œ1 c}«      }d| j                  d   j                  ›|›| j                  d   j                  ›d�S t        | j                  «      }d}t        |«      D ]‰  }t        | j                  |   t        t        f«      r|d	z   }|dz    |j                  | j                  |   g|¢­Ž z   dz   }t        | j                  |   t        t        f«      r|d
z   }||dz
  k7  sŒ…|dz   }Œ‹ |S c c}w )Nc              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr(   r]   r^   s     r    r,   z'TensorProduct._latex.<locals>.<genexpr>â   r_   r`   c              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­wr(   rb   r^   s     r    r,   z'TensorProduct._latex.<locals>.<genexpr>ã   r_   r`   c                 ó   — |dk(  r| S d| z  S )Nr2   z\left\{%s\right\}© )ÚlabelÚnlabelss     r    Ú_label_wrapz)TensorProduct._latex.<locals>._label_wrapå   s   € Ø '¨1¢�uÐNÐ2FÈÑ2NÐNr"   rc   rd   r   re   rQ   z\left(z\right)r2   z\otimes )r   rh   r-   ÚjoinÚ_print_label_latexr7   Úlbracket_latexÚrbracket_latexrU   r3   r   r   rV   )r/   rW   r-   rz   rD   rY   rX   rH   s           r    Ú_latexzTensorProduct._latexß   sd  € åÜÑ?°T·Y±YÔ?Ô?ÜÑ?°T·Y±YÔ?Ô?òOð —
‘
ØBFÇ)Á)öMØ;>ñ (Ð(>¨×(>Ñ(>¸wÐ(NÈÒ(NÜ(+¨C¯H©H«õ7ò Mó N‰Að #'§)¡)¨A¡,×"=Ò"=¹qØ"&§)¡)¨A¡,×"=Ó"=ð?ð ?ô �T—Y‘Y“ˆØˆÜ�v“ò 		$ˆAÜ˜$Ÿ)™) A™,¬¬c¨
Ô3Ø˜	‘M�ð �C‘˜.˜'Ÿ.™.¨¯©°1©Ð=¸Ò=Ñ=ÀÑCˆAÜ˜$Ÿ)™) A™,¬¬c¨
Ô3Ø˜
‘N�Ø�F˜Q‘J‹Ø˜‘O‘ð		$ð ˆùò%Ms   Á4E>c           
      ól   — t        | j                  D �cg c]  } |j                  di |¤Ž‘Œ c}Ž S c c}w )Nrw   )r   r-   Údoit)r/   rN   Úitems      r    r�   zTensorProduct.doitü   s-   € Ü¸d¿i¹iÖH°d˜y˜tŸy™yÑ1¨5Ó1ÒHÐIÐIùÒHs   ”1c                 óº  — | j                   }g }t        t        |«      «      D ]«  }t        ||   t        «      sŒ||   j                   D ]‚  }t        |d| |fz   ||dz   d z   Ž }|j                  «       \  }}t        |«      dk(  r't        |d   t
        «      r|d   j                  «       f}|j                  t        |Ž t        |Ž z  «       Œ„  n |rt	        |Ž S | S )z*Distribute TensorProducts across addition.Nr2   r   )
r-   rU   r7   r3   r   r   r>   Ú_eval_expand_tensorproductrA   r   )	r/   rN   r-   Úadd_argsrH   Úaar<   r:   Únc_parts	            r    r„   z(TensorProduct._eval_expand_tensorproductÿ   sæ   € à�y‰yˆØˆÜ”s˜4“yÓ!ò 
	ˆAÜ˜$˜q™'¤3Õ'Ø˜q™'Ÿ,™,ò @�BÜ&¨¨R¨a¨°B°5Ñ(8¸4ÀÀAÁÀ¸<Ñ(GÐH�BØ&(§k¡k£m‘O�F˜Gô ˜7“| qÒ(¬Z¸À¹
ÄMÔ-RØ#*¨1¡:×#HÑ#HÓ#JÐ"M˜Ø—O‘O¤C¨ L´°g°Ñ$>Õ?ð@ñ ð
	ñ Ü˜�>Ð!àˆKr"   c           	      ód  — |j                  dd «      }| }|�t        |«      dk(  r7t        |j                  D �cg c]  }t	        |«      j                  «       ‘Œ c}Ž S t        t        |j                  «      D ��cg c]$  \  }}||v rt	        |«      j                  «       n|‘Œ& c}}Ž S c c}w c c}}w )NÚindicesr   )Úgetr7   r   r-   r   r�   Ú	enumerate)r/   Úkwargsr‰   ÚexprD   ÚidxÚvalues          r    Ú_eval_tracezTensorProduct._eval_trace  s    € Ø—*‘*˜Y¨Ó-ˆØˆàˆ?œc '›l¨aÒ/Ü°3·8±8Ö<¨Cœ˜C›Ÿ™�Ò<Ð=Ð=äÜ+4°S·X±XÓ+>÷@Ù'˜S %ð .1°G©^œ˜E›Ÿ™Ô)ÀÑFó @ð Að Aùò =ùó@s   ¸ B'Á9)B,
N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úis_commutativer   r.   Úpropertyr)   r8   Úclassmethodr6   rI   rO   rZ   rr   r   r�   r„   r�   rw   r"   r    r   r   9   su   „ ñBðF €Ná%Ð&EÐSWÔXÐàñ1ó ð1ò
ð ñ ó ð ò>ò?òò*òXò:Jòó*Ar"   c                 ó"   — t        ddd¬«       | S )aE  Simplify a Mul with tensor products.

    .. deprecated:: 1.14.
        The transformations applied by this function are not done automatically
        when tensor products are combined.

    Originally, the main use of this function is to simplify a ``Mul`` of
    ``TensorProduct``s to a ``TensorProduct`` of ``Muls``.
    z½
        tensor_product_simp_Mul has been deprecated. The transformations
        performed by this function are now done automatically when
        tensor products are multiplied.
        ú1.14údeprecated-tensorproduct-simp©Údeprecated_since_versionÚactive_deprecations_targetr   ©Úes    r    Útensor_product_simp_Mulr      s    € ô ð	ð
 "(Ø#Bõð €Hr"   c                 ó"   — t        ddd¬«       | S )zØEvaluates ``Pow`` expressions whose base is ``TensorProduct``

    .. deprecated:: 1.14.
        The transformations applied by this function are not done automatically
        when tensor products are combined.
    zÀ
        tensor_product_simp_Pow has been deprecated. The transformations
        performed by this function are now done automatically when
        tensor products are exponentiated.
        r™   rš   r›   r   rž   s    r    Útensor_product_simp_Powr¢   4  s    € ô ð	ð
 "(Ø#Bõð €Hr"   c                 ó"   — t        ddd¬«       | S )aÐ  Try to simplify and combine tensor products.

    .. deprecated:: 1.14.
        The transformations applied by this function are not done automatically
        when tensor products are combined.

    Originally, this function tried to pull expressions inside of ``TensorProducts``.
    It only worked for relatively simple cases where the products have
    only scalars, raw ``TensorProducts``, not ``Add``, ``Pow``, ``Commutators``
    of ``TensorProducts``.
    z·
        tensor_product_simp has been deprecated. The transformations
        performed by this function are now done automatically when
        tensor products are combined.
        r™   rš   r›   r   )rŸ   rN   s     r    r   r   G  s    € ô ð	ð
 "(Ø#Bõð €Hr"   c                 ó   — t         S r(   )r   ©Úe1Úe2s     r    Úfind_op_kindr¨   _  s   € äÐr"   c                 ó   — t         S r(   )r   r¥   s     r    Úfind_ket_kindrª   d  ó   € ä€Nr"   c                 ó   — t         S r(   )r   r¥   s     r    Úfind_bra_kindr­   i  r«   r"   N)5r”   Úsympy.core.addr   Úsympy.core.exprr   Úsympy.core.kindr   Úsympy.core.mulr   Úsympy.core.powerr   Úsympy.core.sympifyr   Úsympy.matrices.denser	   r4   Úsympy.matrices.immutabler
   r5   Ú sympy.printing.pretty.stringpictr   Úsympy.utilities.exceptionsr   Úsympy.physics.quantum.daggerr   Úsympy.physics.quantum.kindr   r   r   r   r   r   Ú!sympy.physics.quantum.matrixutilsr   r   r   Úsympy.physics.quantum.stater   r   Úsympy.physics.quantum.tracer   Ú__all__r   r!   r   r    r¢   r   r.   Úregisterr¨   rª   r­   rw   r"   r    ú<module>r¿      s÷   ðÙ å Ý  Ý *Ý Ý  Ý &Ý 6Ý LÝ 7Ý @å /÷÷ ÷
ñ ÷
 1Ý *ð Øð€ð Ð ò"ô cA�Dô cAòLò*ò&ð0 ×Ñ×(Ñ(¨¸ÓFñó Gðð ×Ñ×(Ñ(¨°8Ó<ñó =ðð ×Ñ×(Ñ(¨°8Ó<ñó =ñr"   