
    sg                     R   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j%                  d e
ddgddgg             ej%                  d e
ddgddgg             ej%                  d e
ddgddgg             ej%                  d e
ddgddgg             ej%                  d e
ddgddgg             ej%                  d e
ddgddgg             ej%                  d e
de gedgg             ej%                  d e
ddgdd
gg             ej%                  d e
ddgdegg             ej%                  d e
ddgd eeez  dz        gg             ej%                  de e
ddgdd
gg      z         ej%                  d e
ddgdd
gg             ej%                  d e
g dg dg dg dg             ej%                  d e e
ddgdd
gg      z         ej%                  d! e
edgde gg             y")#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
y	)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.
    c                      i | _         || _        y N)_cachedtype)selfr   s     T/var/www/html/venv/lib/python3.12/site-packages/sympy/physics/quantum/matrixcache.py__init__zMatrixCache.__init__   s    
    c                     	 | j                  ||       	 | j                  ||       	 | j                  ||       y# t        $ r Y 2w xY w# t        $ r Y .w xY w# t        $ r Y y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'	tQ'	%%dA.  		  		  		s1   ; A
 A 	AA
	AA	A%$A%c                 h    | j                   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')
        zMatrix with name z and format z is not available.)r   getNotImplementedErrorr   r   formatr   s       r   
get_matrixzMatrixCache.get_matrix1   s;     KKOOT6N+=H!6
 	
r   c                 &    || j                   ||f<   y r   )r   r"   s       r   _store_matrixzMatrixCache._store_matrixC   s    &'T6N#r   c                 <    | j                  |dt        |             y )Nsympy)r&   r	   r   s      r   r   zMatrixCache._sympy_matrixF   s    4(1+6r   c                 X    t        || j                        }| j                  |d|       y )Nr   numpy)r
   r   r&   r   s      r   r   zMatrixCache._numpy_matrixI   s$    Qdjj)4!,r   c                 X    t        || j                        }| j                  |d|       y )Nr*   zscipy.sparse)r   r   r&   r   s      r   r   z MatrixCache._scipy_sparse_matrixM   s&     ATZZ043r   N)complex)__name__
__module____qualname____doc__r   r   r$   r&   r   r   r    r   r   r   r      s*    .
$(7-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      sf   = 0 0   6 ' 
D4 D4N 8B?U3	 }   &&1a&1a&)9": ;   &&1a&1a&)9": ;   &&1a&1a&)9": ;   &&1a&1a&)9": ;   &&1a&1a&)9": ;   #v1v1v&67 8   #vA2wA&78 9   #v1v2w&78 9   #v1v1v&67 8   #v1v3qtAv;/?&@A B   #y!Q!R0A)BB C   (FQFQG+<$= >   
FL,lKLN   $	&1a&1b'1B*C C D   $AQB'8 9 :r   