+
    i                         R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt	H
tHtHtHt RR ltRR ltRR lt
RR	 ltRR
 ltRRRR/R ltR# )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                    \        V RR4      pV P                  R 4      p \        P                  ! V 4      pT;'       g    TpVe   VP	                  V4      pV# )zConvert Matrix to DomainMatrixringNc                 R    \        V \        4      '       d   V P                  4       # T # N)
isinstancer   as_expr)es   &X/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/matrices/normalforms.py<lambda>_to_domain.<locals>.<lambda>   s    Z4-@-@aiikGaG    )getattr	applyfuncr   from_Matrix
convert_to)mdomainr   dMs   &&  r   
_to_domainr      sU     1fd#D	GHA		!	!!	$B^^tF]]6"Ir   c                J    \        W4      p\        V4      P                  4       # )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	B8r   c                .    \        W4      p\        V4      # )z0
Checks that the matrix is in Smith Normal Form
)r   _is_snfr    s   && r   r   r   0   s     
A	B2;r   c                    \        W4      p\        V4      w  r4pVP                  4       VP                  4       VP                  4       3# )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   s:     
A	B2hGA!;;=!++-66r   c                  aaa \        W4      o\        S4      p\        ;QJ d    . V3R lV 4       F  NK  	  5M! V3R lV 4       4      p\        V R4      '       da   V P                  P
                  '       dE   V P                  oV3R lo\        ;QJ d    . V3R lV 4       F  NK  	  5M! V3R lV 4       4      pV# )a  
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   Z   <"   T F   pSP                   P                  V4      x  K"  	  R # 5ir   )r   to_sympy).0fr   s   & r   	<genexpr>$invariant_factors.<locals>.<genexpr>Y   s#     ;7aBII&&q))7s   (+r   c                 H   < \        V SP                  SP                  R 7      # ))r   )r   symbolsr   )r,   Ks   &r   r   #invariant_factors.<locals>.<lambda>^   s    Q		!(( Cr   c              3   4   <"   T F  pS! V4      x  K  	  R # 5ir    )r+   r,   to_polys   & r   r-   r.   _   s     81GAJJs   )r   _invftuplehasattrr   is_PolynomialRing)r   r   factorsr1   r   r5   s   && @@@r   r   r   K   s     
A	BBiGe;7;ee;7;;Gq&66###ACGe88ee888GNr   D
check_rankFc                   Ve1   \         P                  ! V4      '       g   \        \        V4      4      p\        V P                  WR7      P                  4       # )aw  
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.)

)r;   r<   )r   of_typeint_hnf_repr   )Ar;   r<   s   &$$r   r	   r	   c   s=    n 	}RZZ]]s1vJ!3==??r   r   )__doc__sympy.polys.domains.integerringr   sympy.polys.polytoolsr   sympy.polys.matricesr    sympy.polys.matrices.normalformsr   r   r   r"   r   r$   r   r6   r	   r@   r   r4   r   r   <module>rH      sJ    2 . & -  &7&09@ 9@ 9@r   