
    \h                         S r SSKJr  SSKJr  SSKJr  SSKJr	J
rJrJrJr  SS jrSS jrSS	 jr
SS
 jrSS jrSSS.S jrg)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                     [        U SS5      nU R                  S 5      n [        R                  " U 5      nU=(       d    UnUb  UR	                  U5      nU$ )zConvert Matrix to DomainMatrixringNc                 P    [        U [        5      (       a  U R                  5       $ U $ N)
isinstancer   as_expr)es    R/var/www/auris/envauris/lib/python3.13/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      sS     1fd#D	GHA		!	!!	$B^tF]]6"Ir   c                 J    [        X5      n[        U5      R                  5       $ )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                 .    [        X5      n[        U5      $ )z0
Checks that the matrix is in Smith Normal Form
)r   _is_snfr!   s      r   r   r   0   s     
A	B2;r   c                     [        X5      n[        U5      u  p4nUR                  5       UR                  5       UR                  5       4$ )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                   ^^^ [        X5      m[        T5      n[        U4S jU 5       5      n[        U S5      (       aB  U R                  R
                  (       a'  U R                  mU4S jm[        U4S jU 5       5      nU$ )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   >#    U  H   nTR                   R                  U5      v   M"     g 7fr   )r   to_sympy).0fr   s     r   	<genexpr>$invariant_factors.<locals>.<genexpr>Y   s#     ;7aBII&&q))7s   (+r   c                 B   > [        U TR                  TR                  S9$ )N)r   )r   symbolsr   )r-   Ks    r   r   #invariant_factors.<locals>.<lambda>^   s    Q		!(( Cr   c              3   4   >#    U  H  nT" U5      v   M     g 7fr    )r,   r-   to_polys     r   r.   r/   _   s     81GAJJs   )r   _invftuplehasattrr   is_PolynomialRing)r   r   factorsr2   r   r6   s      @@@r   r	   r	   K   se     
A	BBiG;7;;Gq&66##ACG888GNr   FD
check_rankc                    Ub/  [         R                  " U5      (       d  [        [        U5      5      n[        U R                  XS9R                  5       $ )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   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	   r7   r
   rB   r   r5   r   r   <module>rJ      sA    2 . & -  &7&0 !% 9@r   