§
    º³Ùgô  ã                   ó6   — d Z ddlZddlmZ dd„Zdd„Zdd„ZdS )z
Tools to create LaTeX arrays.
é    N)ÚMissingOptionalLibraryErroré   TFc                 ó4  — ddl }t          j        | |¬¦  «                             ¦   «         } |                     | d¬¦  «        }t          ||j        j        j        ¦  «        r|j	        dk    r| 
                    ¦   «         }t          ||j        j        j        ¦  «        rt          ||¦  «        }|                     |d¬¦  «        }|s|S t          ||j        j        ¦  «        rd|› d	�}|d
k    rd}|dk    rd}|s|                     d¦  «        sd|› �}|S )aï  Convert a complex number to latex code suitable for a ket expression

    Args:
        raw_value (complex): Value to convert.
        decimals (int): Number of decimal places to round to (default 15).
        coefficient (bool): Whether the number is to be used as a coefficient
                            of a ket.
        first_term (bool): If a coefficient, whether this number is the first
                           coefficient in the expression.
    Returns:
        str: latex code
    r   N©ÚdecimalsF)Úrationalé2   )Ú	full_precú(ú)Ú1Ú z-1ú-ú+)ÚsympyÚnpÚaroundÚitemÚ	nsimplifyÚ
isinstanceÚcoreÚnumbersÚRationalÚdenominatorÚevalfÚFloatÚroundÚlatexÚAddÚ
startswith)Ú	raw_valuer   Ú
first_termÚcoefficientr   ÚvalueÚelements          úP/granary/edev/quantum/lib/python3.11/site-packages/qiskit/visualization/array.pyÚ_num_to_latexr'      s-  € ð €L€L€Lå”	˜)¨hÐ7Ñ7Ô7×<Ò<Ñ>Ô>€IØ�OŠO˜I°ˆOÑ6Ô6€Eå�%˜œÔ+Ô4Ñ5Ô5ð ¸%Ô:KÈbÒ:PÐ:Pà—’‘”ˆå�%˜œÔ+Ô1Ñ2Ô2ð 'Ý�e˜XÑ&Ô&ˆà�kŠk˜%¨5ˆkÑ1Ô1€Gàð Øˆå�%˜œœÑ(Ô(ð !à �g�.�.�.ˆà�#‚~€~Øˆà�$‚€Øˆàð  ˜g×0Ò0°Ñ5Ô5ð  Ø�g�-�-ˆà€Nó    é
   r   ©é   r+   c                 óN  ‡‡
— t          |¦  «        dk     rt          d¦  «        ‚d|› d�}|dz  }ˆfd„Š
ˆ
fd„}|\  }}| j        dk    r| || g|¦  «        z  }nÅt          | ¦  «        |k    r£| || d|d	z  …         |¦  «        z  }|| j        d         k    r|d
| j        d         z  z  }n8|d	z  }|d	z  t          j        |d	¦  «        z   dz
  }	|d
|z  z  }|dz  }|d
|	z  z  }|dd…         dz   }| || | d	z  dz   d…         |¦  «        z  }n| || |¦  «        z  }|dz  }|S )až  Latex representation of a complex numpy array (with maximum dimension 2)

    Args:
        matrix (ndarray): The matrix to be converted to latex, must have dimension 2.
        decimals (int): For numbers not close to integers, the number of decimal places
                         to round to.
        prefix (str): Latex string to be prepended to the latex, intended for labels.
        max_size (list(```int```)): Indexable containing two integers: Maximum width and maximum
                          height of output Latex matrix (including dots characters). If the
                          width and/or height of matrix exceeds the maximum, the centre values
                          will be replaced with dots. Maximum width or height must be greater
                          than 3.

    Returns:
        str: Latex representation of the matrix

    Raises:
        ValueError: If minimum value in max_size < 3
    é   z=Smallest value in max_size must be greater than or equal to 3ú
z\begin{bmatrix}
c                 ó\   •— d}| D ]}t          |‰¬¦  «        }||dz   z  }Œ|d d…         }|S )Nr   r   z & éþÿÿÿ)r'   )ÚelementsÚ	el_stringÚelÚ
num_stringr   s       €r&   Ú_elements_to_latexz,_matrix_to_latex.<locals>._elements_to_latex]   sO   ø€ ð ˆ	Øð 	,ð 	,ˆBÝ& r°HÐ=Ñ=Ô=ˆJØ˜ eÑ+Ñ+ˆIˆIØ˜c˜r˜c”Nˆ	ØÐr(   c                 óÚ   •— d}| D ]d}t          |¦  «        |k    r| ‰|¦  «        z  }n;| ‰|d |dz  …         ¦  «        z  }|dz  }| ‰|| dz  dz   d …         ¦  «        z  }|dz  }Œe|S )Nr   é   z& \cdots & é   z \\
 )Úlen)ÚrowsÚ	max_widthÚ
row_stringÚrr5   s       €r&   Ú_rows_to_latexz(_matrix_to_latex.<locals>._rows_to_latexg   s¯   ø€ ð ˆ
Øð 	%ð 	%ˆAÝ�1‰vŒv˜Ò"Ð"ØÐ0Ð0°Ñ3Ô3Ñ3�
�
àÐ0Ð0°Ð3C°YÀ!±^Ð3CÔ1DÑEÔEÑE�
Ø˜nÑ,�
ØÐ0Ð0°°I°:À±?ÀQÑ3FÐ3HÐ3HÔ1IÑJÔJÑJ�
Ø˜*Ñ$ˆJˆJØÐr(   r8   Nr7   z	\vdots & z	\ddots & r0   z\\
 z\end{bmatrix}
)ÚminÚ
ValueErrorÚndimr9   Úshaper   Úmod)Úmatrixr   ÚprefixÚmax_sizeÚ
out_stringr>   r;   Ú
max_heightÚ	pre_vdotsÚ
post_vdotsr5   s    `        @r&   Ú_matrix_to_latexrK   C   s¿  øø€ õ( ˆ8�}„}�qÒÐÝÐ\Ñ]Ô]Ð]à �f���€JØÐ&Ñ&€Jðð ð ð ð ðð ð ð ð ð %Ñ€IˆzØ„{�aÒÐØ�n�n f X¨yÑ9Ô9Ñ9ˆ
ˆ
å	ˆV‰Œ�zÒ	!Ð	!ð 	�n�n VÐ,=¨j¸A©oÐ,=Ô%>À	ÑJÔJÑJˆ
à˜œ QœÒ'Ð'Ø˜,¨¬°a¬Ñ8Ñ8ˆJˆJð " Q™ˆIØ" a™­"¬&°¸AÑ*>Ô*>Ñ>ÀÑBˆJØ˜,¨Ñ2Ñ2ˆJØ˜,Ñ&ˆJØ˜,¨Ñ3Ñ3ˆJà   ”_ yÑ0ˆ
Ø�n�n V¨Z¨K¸1Ñ,<¸qÑ,@Ð,BÐ,BÔ%CÀYÑOÔOÑOˆ
ˆ
ð 	�n�n V¨YÑ7Ô7Ñ7ˆ
ØÐ$Ñ$€JØÐr(   r+   c                 ó˜  — 	 t          j        | ¦  «        } | d         dz   }n"# t          $ r}t          d¦  «        |‚d}~ww xY w| j        dk    rt	          d¦  «        ‚t          |t          ¦  «        r||f}t          | |||¬¦  «        }|du r|S 	 dd	lm	} n%# t          $ r}t          d
dd¬¦  «        |‚d}~ww xY w |d|› d�¦  «        S )a  Latex representation of a complex numpy array (with dimension 1 or 2)

    Args:
        array (ndarray): The array to be converted to latex, must have dimension 1 or 2 and
                         contain only numerical data.
        precision (int): For numbers not close to integers or common terms, the number of
                         decimal places to round to.
        prefix (str): Latex string to be prepended to the latex, intended for labels.
        source (bool): If ``False``, will return IPython.display.Latex object. If display is
                       ``True``, will instead return the LaTeX source string.
        max_size (list(int) or int): The maximum size of the output Latex array.

            * If list(``int``), then the 0th element of the list specifies the maximum
              width (including dots characters) and the 1st specifies the maximum height
              (also inc. dots characters).
            * If a single ``int`` then this value sets the maximum width _and_ maximum
              height.

    Returns:
        str or IPython.display.Latex: If ``source`` is ``True``, a ``str`` of the LaTeX
            representation of the array, else an ``IPython.display.Latex`` representation of
            the array.

    Raises:
        TypeError: If array can not be interpreted as a numerical numpy array.
        ValueError: If the dimension of array is not 1 or 2.
        MissingOptionalLibraryError: If ``source`` is ``False`` and ``IPython.display.Latex`` cannot be
                     imported.
    r   r8   z}array_to_latex can only convert numpy arrays containing numerical data,
        or types that can be converted to such arraysNr7   zBarray_to_latex can only convert numpy ndarrays of dimension 1 or 2)r   rE   rF   T)ÚLatexÚIPythonÚarray_to_latexzpip install ipython)ÚlibnameÚnameÚpip_installz$$)r   ÚasarrayÚ	TypeErrorrA   r@   r   ÚintrK   ÚIPython.displayrM   ÚImportErrorr   )	ÚarrayÚ	precisionrE   ÚsourcerF   Ú_ÚerrÚoutstrrM   s	            r&   rO   rO   ’   s5  € ð<Ý”
˜5Ñ!Ô!ˆØ�!ŒH�q‰LˆˆøÝð ð ð Ýð9ñ
ô 
ð ð	øøøøðøøøð „z�A‚~€~ÝÐ]Ñ^Ô^Ð^å�(�CÑ Ô ð (Ø˜hÐ'ˆå˜e¨iÀÐQYÐZÑZÔZ€Fà�€~€~ØˆðØ)Ð)Ð)Ð)Ð)Ð)Ð)øÝð ð ð Ý)ØØ!Ø-ð
ñ 
ô 
ð ð		øøøøðøøøð ˆ5��f���Ñ!Ô!Ð!s*   ‚" ¢
A¬<¼AÂB Â
B:Â"B5Â5B:)r   TF)r)   r   r*   )r)   r   Fr+   )Ú__doc__Únumpyr   Úqiskit.exceptionsr   r'   rK   rO   © r(   r&   ú<module>rb      s{   ððð ð Ð Ð Ð à 9Ð 9Ð 9Ð 9Ð 9Ð 9ð+ð +ð +ð +ð\Lð Lð Lð Lð^:"ð :"ð :"ð :"ð :"ð :"r(   