§
    OŠtj  ã                   ó€   — d 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 dd„Zdd„Zdd	„Z
dd
„Zdd„Zdddœd„ZdS )z,Functions returning normal forms of matricesé    )ÚZZ)ÚPoly)ÚDomainMatrix)Úsmith_normal_formÚis_smith_normal_formÚsmith_normal_decompÚinvariant_factorsÚhermite_normal_formNc                 ó²   — t          | dd¦  «        }|                      d„ ¦  «        } t          j        | ¦  «        }|p|}|�|                     |¦  «        }|S )zConvert Matrix to DomainMatrixÚringNc                 óX   — t          | t          ¦  «        r|                      ¦   «         n| S ©N)Ú
isinstancer   Úas_expr)Úes    úX/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/matrices/normalforms.pyú<lambda>z_to_domain.<locals>.<lambda>   s!   € ­Z¸½4Ñ-@Ô-@ÐG˜aŸiši™kœk˜kÀa€ ó    )ÚgetattrÚ	applyfuncr   Úfrom_MatrixÚ
convert_to)ÚmÚdomainr   ÚdMs       r   Ú
_to_domainr      s_   € õ �1�f˜dÑ#Ô#€DØ	�ŠÐGÐGÑHÔH€Aå	Ô	! !Ñ	$Ô	$€Bàˆ^�t€FØÐØ�]Š]˜6Ñ"Ô"ˆØ€Ir   c                 ód   — t          | |¦  «        }t          |¦  «                             ¦   «         S )aª  
    Return the Smith Normal Form of a matrix `m` over the ring `domain`.
    This will only work if the ring is a principal ideal domain.

    Examples
    ========

    >>> from sympy import Matrix, ZZ
    >>> from sympy.matrices.normalforms import smith_normal_form
    >>> m = Matrix([[12, 6, 4], [3, 9, 6], [2, 16, 14]])
    >>> print(smith_normal_form(m, domain=ZZ))
    Matrix([[1, 0, 0], [0, 10, 0], [0, 0, 30]])

    )r   Ú_snfÚ	to_Matrix©r   r   r   s      r   r   r      s+   € õ 
�A�vÑ	Ô	€BÝ�‰8Œ8×ÒÑÔÐr   c                 ó@   — t          | |¦  «        }t          |¦  «        S )z8
    Checks that the matrix is in Smith Normal Form
    )r   Ú_is_snfr    s      r   r   r   0   s   € õ 
�A�vÑ	Ô	€BÝ�2‰;Œ;Ðr   c                 ó¾   — t          | |¦  «        }t          |¦  «        \  }}}|                     ¦   «         |                     ¦   «         |                     ¦   «         fS )a§  
    Return the Smith Normal Decomposition of a matrix `m` over the ring
    `domain`. This will only work if the ring is a principal ideal domain.

    Examples
    ========

    >>> from sympy import Matrix, ZZ
    >>> from sympy.matrices.normalforms import smith_normal_decomp
    >>> m = Matrix([[12, 6, 4], [3, 9, 6], [2, 16, 14]])
    >>> a, s, t = smith_normal_decomp(m, domain=ZZ)
    >>> assert a == s * m * t
    )r   Ú_sndr   )r   r   r   ÚaÚsÚts         r   r   r   8   sI   € õ 
�A�vÑ	Ô	€BÝ�2‰hŒh�G€A€qˆ!Ø�;Š;‰=Œ=˜!Ÿ+š+™-œ-¨¯ª©¬Ð6Ð6r   c                 ó  ‡‡‡— t          | |¦  «        Št          ‰¦  «        }t          ˆfd„|D ¦   «         ¦  «        }t          | d¦  «        r3| j        j        r'| j        Šˆfd„Št          ˆfd„|D ¦   «         ¦  «        }|S )a9  
    Return the tuple of abelian invariants for a matrix `m`
    (as in the Smith-Normal form)

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Smith_normal_form#Algorithm
    .. [2] https://web.archive.org/web/20200331143852/https://sierra.nmsu.edu/morandi/notes/SmithNormalForm.pdf

    c              3   óL   •K  — | ]}‰j                              |¦  «        V — Œd S r   )r   Úto_sympy)Ú.0Úfr   s     €r   ú	<genexpr>z$invariant_factors.<locals>.<genexpr>Y   s3   øè è € Ð;Ð;¨a�B”I×&Ò& qÑ)Ô)Ð;Ð;Ð;Ð;Ð;Ð;r   r   c                 ó<   •— t          | ‰j        ‰j        ¬¦  «        S )N)r   )r   Úsymbolsr   )r,   ÚKs    €r   r   z#invariant_factors.<locals>.<lambda>^   s   ø€ ¥ Q¨¬	¸!¼(Ð CÑ CÔ C€ r   c              3   ó.   •K  — | ]} ‰|¦  «        V — Œd S r   © )r+   r,   Úto_polys     €r   r-   z$invariant_factors.<locals>.<genexpr>_   s+   øè è € Ð8Ð8¨1˜G˜G A™JœJÐ8Ð8Ð8Ð8Ð8Ð8r   )r   Ú_invfÚtupleÚhasattrr   Úis_PolynomialRing)r   r   Úfactorsr0   r   r3   s      @@@r   r	   r	   K   sž   øøø€ õ 
�A�vÑ	Ô	€BÝ�B‰iŒi€GÝÐ;Ð;Ð;Ð;°7Ð;Ñ;Ô;Ñ;Ô;€Gåˆq�&ÑÔð 9ØŒ6Ô#ð 	9Ø”ˆAØCÐCÐCÐCˆGÝÐ8Ð8Ð8Ð8°Ð8Ñ8Ô8Ñ8Ô8ˆGØ€Nr   F©ÚDÚ
check_rankc                ó¸   — |�0t          j        |¦  «        st          t          |¦  «        ¦  «        }t          | j        ||¬¦  «                             ¦   «         S )a  
    Compute the Hermite Normal Form of a Matrix *A* of integers.

    Examples
    ========

    >>> from sympy import Matrix
    >>> from sympy.matrices.normalforms import hermite_normal_form
    >>> m = Matrix([[12, 6, 4], [3, 9, 6], [2, 16, 14]])
    >>> print(hermite_normal_form(m))
    Matrix([[10, 0, 2], [0, 15, 3], [0, 0, 2]])

    Parameters
    ==========

    A : $m \times n$ ``Matrix`` of integers.

    D : int, optional
        Let $W$ be the HNF of *A*. If known in advance, a positive integer *D*
        being any multiple of $\det(W)$ may be provided. In this case, if *A*
        also has rank $m$, then we may use an alternative algorithm that works
        mod *D* in order to prevent coefficient explosion.

    check_rank : boolean, optional (default=False)
        The basic assumption is that, if you pass a value for *D*, then
        you already believe that *A* has rank $m$, so we do not waste time
        checking it for you. If you do want this to be checked (and the
        ordinary, non-modulo *D* algorithm to be used if the check fails), then
        set *check_rank* to ``True``.

    Returns
    =======

    ``Matrix``
        The HNF of matrix *A*.

    Raises
    ======

    DMDomainError
        If the domain of the matrix is not :ref:`ZZ`.

    DMShapeError
        If the mod *D* algorithm is used but the matrix has more rows than
        columns.

    References
    ==========

    .. [1] Cohen, H. *A Course in Computational Algebraic Number Theory.*
       (See Algorithms 2.4.5 and 2.4.8.)

    Nr9   )r   Úof_typeÚintÚ_hnfÚ_repr   )ÚAr:   r;   s      r   r
   r
   c   sJ   € ðn 	€}�RœZ¨™]œ]€}Ý�s�1‰vŒv‰JŒJˆÝ�”˜!¨
Ð3Ñ3Ô3×=Ò=Ñ?Ô?Ð?r   r   )Ú__doc__Úsympy.polys.domains.integerringr   Úsympy.polys.polytoolsr   Úsympy.polys.matricesr   Ú sympy.polys.matrices.normalformsr   r   r   r"   r   r$   r	   r4   r
   r?   r   r2   r   r   ú<module>rG      s  ðØ 2Ð 2à .Ð .Ð .Ð .Ð .Ð .Ø &Ð &Ð &Ð &Ð &Ð &Ø -Ð -Ð -Ð -Ð -Ð -ðð ð ð ð ð ð ð ð ð ð ð ð ð ðð ð ð ð ð  ð  ð  ð&ð ð ð ð7ð 7ð 7ð 7ð&ð ð ð ð0 !%°ð 9@ð 9@ð 9@ð 9@ð 9@ð 9@ð 9@r   