
    z	i                        S r SSKJr  SSKrSrSrS\\S4S jrS r\\4S	 jr	\\4S
 jr
\\4S jr\\4S jrS\\4S jr\\4S jr\\4S jrg)z
Predicates for operators.
    )annotationsNg:0yE>gh㈵>Fc                >   SR                  [        [        5        Uc  [        nUc  [        n[        U [        R
                  5      (       d  [        R                  " U 5      n [        U[        R
                  5      (       d  [        R                  " U5      nU R                  UR                  :w  a  gU(       a  SnU R                   HJ  n[        U5      U:  d  M  [        R                  " U5      nXh-  n[        R                  " SU-  5      U -  n   O   UR                   H^  n[        U5      U:  d  M  [        R                  " U5      nXh-  n[        R                  " S[        R                  " U5      -  5      U-  n  O   Ub  XeS'   [        R                  " XX4S9$ )Na  Test if two arrays are equal.

    The final comparison is implemented using Numpy.allclose. See its
    documentation for additional information on tolerance parameters.

    If ignore_phase is True both matrices will be multiplied by
    exp(-1j * theta) where `theta` is the first nphase for a
    first non-zero matrix element `|a| * exp(1j * theta)`.

    Args:
        mat1 (matrix_like): a matrix
        mat2 (matrix_like): a matrix
        ignore_phase (bool): ignore complex-phase differences between
            matrices [Default: False]
        rtol (double): the relative tolerance parameter [Default {}].
        atol (double): the absolute tolerance parameter [Default {}].
        props (dict | None): if not ``None`` and ``ignore_phase`` is ``True``
            returns the phase difference between the two matrices under
            ``props['phase_difference']``

    Returns:
        bool: True if the matrices are equal or False otherwise.
    Fr                phase_differencertolatol)formatRTOL_DEFAULTATOL_DEFAULT
isinstancenpndarrayarrayshapeflatabsangleexpallclose)	mat1mat2ignore_phaser   r	   propsr   eltr   s	            b/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/quantum_info/operators/predicates.pymatrix_equalr      sG   , 	l	 ||dBJJ''xx~dBJJ''xx~zzTZZ 99C3x$ ) vvcEk*T1  99C3x$ ) vvcBHHSM12T9  (8$%;;t88    c                ~    [         R                  " U 5      n U R                  S:w  a  gU R                  nUS   US   :H  $ )z$Test if an array is a square matrix.   Fr      )r   r   ndimr   )matr   s     r   is_square_matrixr$   X   s9    
((3-C
xx1}IIE8uQxr   c                    Uc  [         nUc  [        n[        R                  " U 5      n U R                  S:w  a  g[        R
                  " U [        R                  " [        R                  " U 5      5      XS9$ )z%Test if an array is a diagonal matrixr    Fr   )r   r   r   r   r"   r   diagdiagonalr#   r   r	   s      r   is_diagonal_matrixr)   a   sV    ||
((3-C
xx1};;sBGGBKK$45DLLr   c                    Uc  [         nUc  [        n[        R                  " U 5      nUR                  S:w  a  g[        R
                  " X3R                  XS9$ )z&Test if an array is a symmetric matrixr    Fr   )r   r   r   r   r"   r   T)opr   r	   r#   s       r   is_symmetric_matrixr-   m   sF    ||
((2,C
xx1};;sEE88r   c                    Uc  [         nUc  [        n[        R                  " U 5      n U R                  S:w  a  g[        R
                  " U [        R                  " U R                  5      XS9$ )z&Test if an array is a Hermitian matrixr    Fr   )r   r   r   r   r"   r   conjr+   r(   s      r   is_hermitian_matrixr0   y   sP    ||
((3-C
xx1};;sBGGCEENAAr   c                    Uc  [         nUc  [        n[        XUS9(       d  g[        R                  R                  U 5      nU H  nXB* :  d  M    g   g)z)Test if a matrix is positive semidefiniter   FT)r   r   r0   r   linalgeigvalsh)r#   r   r	   valsvs        r   is_positive_semidefinite_matrixr6      sP    ||sD999c"Du9  r   c                T   Uc  [         nUc  [        n[        R                  " U 5      n U R                  S:w  a  gU(       a5  [        R
                  " U S   5      n[        R                  " SU-  5      U -  n [        R                  " [        U 5      5      n[        R                  " XX#S9$ )z'Test if an array is an identity matrix.r    F)r   r   r   r   )
r   r   r   r   r"   r   r   eyelenr   )r#   r   r   r	   thetaidens         r   is_identity_matrixr<      s    ||
((3-C
xx1} T#ffS5[!C'66#c(D;;st77r   c                    [         R                  " U 5      n [         R                  " U R                  5      R	                  U 5      n [        U SXS9$ )z%Test if an array is a unitary matrix.F)r   r   r	   )r   r   r/   r+   dotr<   r(   s      r   is_unitary_matrixr?      s:    
((3-C
''#%%.

S
!CcDLLr   c                    [         R                  " U 5      n [         R                  " U R                  S   5      n[         R                  " U R
                  5      R                  U 5      n [         R                  " XXS9$ )z Test if an array is an isometry.r!   r   )r   r   r8   r   r/   r+   r>   r   )r#   r   r	   r;   s       r   is_isometryrA      sR    
((3-C66#))A,D
''#%%.

S
!C;;st77r   )__doc__
__future__r   numpyr   r   r   r   r$   r)   r-   r0   r6   r<   r?   rA    r   r   <module>rF      s    #  +0l]a =9@  ".L 	M ".L 	9 #/\ 	B /;   */\ 8( !-< M '\ 8r   