
    Ed                     D   d Z ddlmZmZ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  G d d          Z ed	 ed
d	          d          Z e            Ze                    d e
ddgddgg                     e                    d e
ddgddgg                     e                    d e
ddgddgg                     e                    d e
ddgddgg                     e                    d e
ddgddgg                     e                    d e
ddgddgg                     e                    d e
de gedgg                     e                    d e
ddgdd
gg                     e                    d e
ddgdegg                     e                    d e
ddgd eeez  dz            gg                     e                    de e
ddgdd
gg          z             e                    d e
ddgdd
gg                     e                    d e
g dg dg dg dg                     e                    d e e
ddgdd
gg          z             e                    d! e
edgde gg                     d"S )#z7A cache for storing small matrices in multiple formats.    )IRationalpi)Pow)exp)Matrix)to_sympyto_numpyto_scipy_sparsec                   >    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
S )MatrixCachea  A cache for small matrices in different formats.

    This class takes small matrices in the standard ``sympy.Matrix`` format,
    and then converts these to both ``numpy.matrix`` and
    ``scipy.sparse.csr_matrix`` matrices. These matrices are then stored for
    future recovery.
    complexc                 "    i | _         || _        d S N)_cachedtype)selfr   s     Alib/python3.11/site-packages/sympy/physics/quantum/matrixcache.py__init__zMatrixCache.__init__   s    


    c                     	 |                      ||           n# t          $ r Y nw xY w	 |                     ||           n# t          $ r Y nw xY w	 |                     ||           dS # t          $ r Y dS w xY w)zCache a matrix by its name.

        Parameters
        ----------
        name : str
            A descriptive name for the matrix, like "identity2".
        m : list of lists
            The raw matrix data as a SymPy Matrix.
        N)_sympy_matrixImportError_numpy_matrix_scipy_sparse_matrixr   namems      r   cache_matrixzMatrixCache.cache_matrix   s    	tQ'''' 	 	 	D		tQ'''' 	 	 	D		%%dA..... 	 	 	DD	s/    
&&A 
AAA* *
A87A8c                 n    | j                             ||f          }||S t          d|d|d          )a  Get a cached matrix by name and format.

        Parameters
        ----------
        name : str
            A descriptive name for the matrix, like "identity2".
        format : str
            The format desired ('sympy', 'numpy', 'scipy.sparse')
        NzMatrix with name z and format z is not available.)r   getNotImplementedErrorr   r   formatr   s       r   
get_matrixzMatrixCache.get_matrix1   sO     KOOT6N++ 	H!!TT666
 
 	
r   c                     || j         ||f<   d S r   )r   r#   s       r   _store_matrixzMatrixCache._store_matrixC   s    &'T6N###r   c                 N    |                      |dt          |                     d S )Nsympy)r'   r	   r   s      r   r   zMatrixCache._sympy_matrixF   s&    4(1++66666r   c                 `    t          || j                  }|                     |d|           d S )Nr   numpy)r
   r   r'   r   s      r   r   zMatrixCache._numpy_matrixI   s4    Qdj)))4!,,,,,r   c                 `    t          || j                  }|                     |d|           d S )Nr+   zscipy.sparse)r   r   r'   r   s      r   r   z MatrixCache._scipy_sparse_matrixM   s6     ATZ000433333r   N)r   )__name__
__module____qualname____doc__r   r   r%   r'   r   r   r    r   r   r   r      s              .
 
 
$( ( (7 7 7- - -4 4 4 4 4r   r      F)evaluateeye2   op11op00op10op01XYZST   HHsqrt2SWAP)r7   r   r   r   )r   r   r7   r   )r   r7   r   r   )r   r   r   r7   ZXZYN)r1   sympy.core.numbersr   r   r   sympy.core.powerr   &sympy.functions.elementary.exponentialr   sympy.matrices.denser   !sympy.physics.quantum.matrixutilsr	   r
   r   r   	sqrt2_invmatrix_cacher   r2   r   r   <module>rN      s   = = 0 0 0 0 0 0 0 0 0 0             6 6 6 6 6 6 ' ' ' ' ' '         
D4 D4 D4 D4 D4 D4 D4 D4N C88B??U333	 {}}   &&&1a&1a&)9":": ; ; ;   &&&1a&1a&)9":": ; ; ;   &&&1a&1a&)9":": ; ; ;   &&&1a&1a&)9":": ; ; ;   &&&1a&1a&)9":": ; ; ;   #vv1v1v&677 8 8 8   #vvA2wA&788 9 9 9   #vv1v2w&788 9 9 9   #vv1v1v&677 8 8 8   #vv1v33qtAv;;/?&@AA B B B   #y!Q!R0A)B)BB C C C   (FFQFQG+<$=$= > > >   
FFLLL,,,lllKLLN N N   $	&&1a&1b'1B*C*C C D D D   $AQB'8 9 9 : : : : :r   