ó
    Š*£hâB  ã                   ó’   • S r SSKJr  SSKJr  SSKJrJr  SSKJ	r	  SSK
JrJr  S rS	 rS
 rS rS rS rS rS rS rSSS.S jrg)z,Functions returning normal forms of matricesé    )Údefaultdicté   )ÚDomainMatrix)ÚDMDomainErrorÚDMShapeError)Úsymmetric_residue)ÚQQÚZZc                 ór   • [        U 5      n[        R                  " XR                  U R                  5      nU$ )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 ZZ
>>> from sympy.polys.matrices import DomainMatrix
>>> from sympy.polys.matrices.normalforms import smith_normal_form
>>> m = DomainMatrix([[ZZ(12), ZZ(6), ZZ(4)],
...                   [ZZ(3), ZZ(9), ZZ(6)],
...                   [ZZ(2), ZZ(16), ZZ(14)]], (3, 3), ZZ)
>>> print(smith_normal_form(m).to_Matrix())
Matrix([[1, 0, 0], [0, 10, 0], [0, 0, 30]])

)Úinvariant_factorsr   ÚdiagÚdomainÚshape)ÚmÚinvsÚsmfs      Ú]/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/polys/matrices/normalforms.pyÚsmith_normal_formr      s-   € ô$ ˜QÓ€DÜ
×
Ò
˜D§(¡(¨A¯G©GÓ
4€CØ€Jó    c                 óÌ  • U R                   nU R                  nUR                  nU R                  5       n [	        US   5       H-  n[	        US   5       H  nXE:X  a  M
  X   U   U:X  a  M      g   M/     [        US   US   5      n[	        SU5       HO  nXS-
     US-
     U:X  a  X   U   U:w  a    gM#  UR                  X   U   XS-
     US-
     5      S   nXs:w  d  MO    g   g)z0
Checks that the matrix is in Smith Normal Form
r   r   FT)r   r   ÚzeroÚto_listÚrangeÚminÚdiv)r   r   r   r   ÚiÚjÚupperÚrs           r   Úis_smith_normal_formr    (   sï   € ð �X‰X€FØ�G‰G€EØ�;‰;€DØ	�	‰	‹€Aä�5˜‘8Ž_ˆÜ�u˜Q‘x–ˆAØ‹vÙØ‘4˜‘7˜d•?Úó	 !ñ ô ��a‘˜% ™(Ó#€EÜ�1�eŽ_ˆØˆq‰S‰6�!�A‘#‰;˜$ÓØ‰t�A‰w˜$‹Ùñ ð —
‘
˜1™4 ™7 A¨¡c¡F¨1¨Q©3¡KÓ0°Ñ3ˆAØ�yÙñ ð r   c                 ó˜   • [        [        U 5      5       H2  nX   U   nX8-  X@U   U   -  -   X   U'   XX-  X`U   U   -  -   X   U'   M4     g ©N©r   Úlen©	r   r   r   ÚaÚbÚcÚdÚkÚes	            r   Úadd_columnsr,   E   sW   € ô ”3�q“6Ž]ˆØ‰D�‰GˆØ‘#˜˜A™$˜q™'™	‘/ˆ‰ˆQ‰Ø‘#˜˜A™$˜q™'™	‘/ˆ‰ˆQ‹ò r   c                 óh   • U R                   nU R                  nU R                  5       n [        XUSS9$ )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

F©r   Úfull)r   r   r   Ú_smith_normal_decomp)r   r   r   s      r   r   r   N   s0   € ð �X‰X€FØ�G‰G€EØ	�	‰	‹€AÜ °¸UÑCÐCr   c                 óô   • U R                   nU R                  =u  p#nU R                  5       n [        XUSS9u  pVn[        R
                  " XQU5      R                  5       n[	        XaX"4S9n[	        XqX34S9nX†U4$ )aµ  
Return the Smith-Normal form decomposition of matrix `m`.

Examples
========

>>> from sympy import ZZ
>>> from sympy.polys.matrices import DomainMatrix
>>> from sympy.polys.matrices.normalforms import smith_normal_decomp
>>> m = DomainMatrix([[ZZ(12), ZZ(6), ZZ(4)],
...                   [ZZ(3), ZZ(9), ZZ(6)],
...                   [ZZ(2), ZZ(16), ZZ(14)]], (3, 3), ZZ)
>>> a, s, t = smith_normal_decomp(m)
>>> assert a == s * m * t
Tr.   )r   r   )r   r   r   r0   r   r   Úto_dense)	r   r   ÚrowsÚcolsr   r   ÚsÚtr   s	            r   Úsmith_normal_decompr7   `   s{   € ð  �X‰X€FØŸ™Ð �J€D�Ø	�	‰	‹€Aä% a°uÀ4ÑH�J€DˆQÜ
×
Ò
˜D¨%Ó
0×
9Ñ
9Ó
;€Cä�Q¨d¨\Ñ:€AÜ�Q¨d¨\Ñ:€AØ�1ˆ9Ðr   c           
      ó´
  ^ ^^^^ ^!^"^#^$^%• TR                   (       d  ST 3n[        U5      eUu  m"m TR                  m%TR                  m!U!U%4S jnSU;   a  T(       a  SU" T"5      U" T 5      4$ gT(       a  U" T"5      m#U" T 5      m$S mUUUU U"U#U%4S jnU UUU U$U%4S jn[	        T"5       Vs/ s H  nT U   S   T%:w  d  M  UPM     n	nU	(       a?  U	S   T%:w  a6  T U	S      T S   sT S'   T U	S   '   T(       a  T#U	S      T#S   sT#S'   T#U	S   '   O|[	        T 5       V
s/ s H  n
T S   U
   T%:w  d  M  U
PM     n	n
U	(       aL  U	S   T%:w  aC  T  H  nX¹S      US   sUS'   X¹S   '   M     T(       a  T$ H  nX¹S      US   sUS'   X¹S   '   M     [        U U%4S j[	        S	T 5       5       5      (       d%  [        U U%4S
 j[	        S	T"5       5       5      (       a\  U" 5         U" 5         [        U U%4S j[	        S	T 5       5       5      (       a  M5  [        U U%4S
 j[	        S	T"5       5       5      (       a  M\  U4S jnT S   S   S:w  au  TR                  T S   S   5      nTR                  (       a  S	T S   S   -  nUTR                  :w  a2  T S   S==   U-  ss'   T(       a  T#S    Vs/ s H  oîU-  PM	     snT#S'   S	U;   a  SnOÐT S	S  Vs/ s H  nUS	S PM
     nn[        UTT"S	-
  T S	-
  4TS9nT(       a›  Uu  nnnS	/S/T"S	-
  -  -   /U Vs/ s H	  nS/U-   PM     sn-   nS	/S/T S	-
  -  -   /U Vs/ s H	  nS/U-   PM     sn-   n[        [        UT#UT$U/5      5      u  m#nm$nUT#-  m#T$U-  m$T#R                  5       m#T$R                  5       m$OUnT S   S   (       Ga1  T S   S   /nUR                  U5        [	        [        U5      S	-
  5       Hû  nUU   UUS	-      nnU(       aä  TR                  UU5      S	   T%:w  aË  T(       a  TR                  UU5      u  nnnOTR!                  UU5      nTR                  UU5      S   nT(       am  TR                  UU5      S   nT" T#XˆS	-   S	SWS	5        [#        T$XˆS	-   S	WSS	5        T" T#XˆS	-   S	U* SS	5        [#        T$XˆS	-   S	SU* S	5        T" T#XˆS	-   SS	SS5        UU-  UUS	-   '   UUU'   Mû    OJ   OGT(       a4  T"S	:”  a  T#S	S T#S   /-   m#T S	:”  a  T$ Vs/ s H  o»S	S US   /-   PM     snm$UT S   S   4-   nT(       a  [%        U5      T#T$4$ [%        U5      $ s  snf s  sn
f s  snf s  snf s  snf s  snf s  snf )z×
Return the tuple of abelian invariants for a matrix `m`
(as in the Smith-Normal form). If `full=True` then invertible matrices
``s, t`` such that the product ``s, m, t`` is the Smith Normal Form
are also returned.
zBThe matrix entries must be over a principal ideal domain, but got c           	      ó˜   >• [        U 5       VVs/ s H&  n[        U 5       Vs/ s H  o"U:X  a  TOTPM     snPM(     snn$ s  snf s  snnf r"   )r   )Únr   r   Úoner   s      €€r   ÚeyeÚ!_smith_normal_decomp.<locals>.eye‹   s>   ø€ ÜEJÈ1ÄXÔNÂXÀ´%¸´(Ó;²(¨Q˜Q›‘ DÒ(±(Ô;ÁXÒNÐNùÒ;ùÓNs   �A£A¶AÁAr   © c                 óž   • [        [        U S   5      5       H2  nX   U   nX8-  X@U   U   -  -   X   U'   XX-  X`U   U   -  -   X   U'   M4     g )Nr   r#   r%   s	            r   Úadd_rowsÚ&_smith_normal_decomp.<locals>.add_rows˜   s\   € ô ”s˜1˜Q™4“yÖ!ˆAØ‘�Q‘ˆAØ‘c˜A ™d 1™g™I‘oˆA‰D�‰GØ‘c˜A ™d 1™g™I‘oˆA‰D�‹Gò "r   c            
      ó¸  >• TS   S   n [        ST5       HÁ  nTU   S   T:X  a  M  T
R                  TU   S   U 5      u  p#UT:X  a)  T	" TSUSSU* S5        T(       a  T	" TSUSSU* S5        MX  MZ  T
R                  U TU   S   5      u  pEnT
R                  TU   S   U5      nT
R                  X5      nT	" TSXXWU* 5        T(       a  T	" TSXXWU* 5        Un MÃ     g ©Nr   r   )r   r   ÚgcdexÚexquo)Úpivotr   r)   r   r&   r'   ÚgÚd_0Úd_jr@   r   r/   r   r3   r5   r   s            €€€€€€€r   Úclear_columnÚ*_smith_normal_decomp.<locals>.clear_column    s÷   ø€ à�!‘�Q‘ˆÜ�q˜$–ˆAØ�‰t�A‰w˜$‹ÙØ—:‘:˜a ™d 1™g uÓ-‰DˆAØ�D‹yÙ˜˜A˜q ! Q¨¨¨AÔ.ÞÙ˜Q  1 a¨¨Q¨B°Ö2ñ ð !Ÿ,™, u¨a°©d°1©gÓ6‘��aØ—l‘l 1 Q¡4¨¡7¨AÓ.�Ø—l‘l 5Ó,�Ù˜˜A˜q Q¨c¨TÔ2ÞÙ˜Q  1¨°#°Ô6Ø’ò  r   c            
      óÐ  >• TS   S   n [        ST	5       HÍ  nTS   U   T:X  a  M  T
R                  TS   U   U 5      u  p#UT:X  a/  [        TSUSSU* S5        T(       a  [        TSUSSU* S5        M^  M`  T
R                  U TS   U   5      u  pEnT
R	                  TS   U   U5      nT
R	                  X5      n[        TSXXWU* 5        T(       a  [        TSXXWU* 5        Un MÏ     g rC   )r   r   r,   rD   rE   )rF   r   r)   r   r&   r'   rG   rH   rI   r4   r   r/   r   r6   r   s            €€€€€€r   Ú	clear_rowÚ'_smith_normal_decomp.<locals>.clear_row´   s÷   ø€ à�!‘�Q‘ˆÜ�q˜$–ˆAØ�‰t�A‰w˜$‹ÙØ—:‘:˜a ™d 1™g uÓ-‰DˆAØ�D‹yÜ˜A˜q ! Q¨¨A¨2¨qÔ1ÞÜ  1 a¨¨A°¨r°1Ö5ñ ð !Ÿ,™, u¨a°©d°1©gÓ6‘��aØ—l‘l 1 Q¡4¨¡7¨AÓ.�Ø—l‘l 5Ó,�Ü˜A˜q !¨°°Ô5ÞÜ  1 a¨A°S°DÔ9Ø’ò  r   c              3   ó:   >#   • U  H  nTS    U   T:g  v •  M     g7f©r   Nr>   ©Ú.0r   r   r   s     €€r   Ú	<genexpr>Ú'_smith_normal_decomp.<locals>.<genexpr>Ø   ó   øé € Ð6ª 1ˆq�‰t�A‰w˜$Žªùó   ƒr   c              3   ó:   >#   • U  H  nTU   S    T:g  v •  M     g7frP   r>   rQ   s     €€r   rS   rT   Ù   rU   rV   c                 óH   >• [        U [        U 5      [        U S   5      4TS9$ )Nr   )r   r   )r   r$   )r   r   s    €r   Úto_domain_matrixÚ._smith_normal_decomp.<locals>.to_domain_matrixÝ   s#   ø€ Ü˜A¤c¨!£f¬c°!°A±$«iÐ%8ÀÑHÐHr   Nr.   éÿÿÿÿ)Úis_PIDÚ
ValueErrorr   r;   r   ÚanyÚcanonical_unitÚis_Fieldr0   ÚlistÚmapr   Úextendr$   r   rD   Úgcdr,   Útuple)&r   r   r   r/   Úmsgr<   rJ   rM   r   Úindr   ÚrowrY   r(   Úelemr   r   Úlower_rightÚretÚs_smallÚt_smallÚs2Út2Úresultr&   r'   ÚxÚyr)   ÚalphaÚbetar@   r4   r;   r3   r5   r6   r   s&   `` `                           @@@@@@@r   r0   r0   |   s“  ÿù€ ð �=�=ØRÐSYÐRZÐ[ˆÜ˜‹oÐà�J€Dˆ$Ø�;‰;€DØ
�*‰*€CöOð 	ˆEƒzÞØ‘s˜4“y¡# d£)Ð+Ð+àæÙ�‹IˆÙ�‹Iˆò&÷ó ÷(ò ô* ˜D”kÓ
5’k� Q q¡T¨!¡W°¡_�1‘k€CÐ
5Þ
ˆs�1‰v˜‹~Ø˜C ™F™) Q q¡Tˆˆˆ!‰ˆa��A‘‰iÞØ  A¡™i¨¨1©ˆOˆAˆa‰D�!�C˜‘F‘)øä œ+Ó9š+�Q¨¨1©¨a©°D©�q™+ˆÐ9Þ�3�q‘6˜T“>Û�Ø&)¨a©&¡k°3°q±6Ð#��A‘˜ ™F›ñ æÛ�CØ*-°!©f©+°s¸1±vÐ'�C˜‘F˜C A¡›Kñ ô Õ6¬¨a°¬Ó6×6Ñ6ÜÕ6¬¨a°¬Ó6×6Ñ6ÙŒÙŒô Õ6¬¨a°¬Ó6×6Ó6ÜÕ6¬¨a°¬Ó6×6Ó6õIð 	ˆ�tˆA�w�!ƒ|Ø×!Ñ! ! A¡$ q¡'Ó*ˆØ�?�?Ø�A�a‘D˜‘G‘ˆAØ�—
‘
‹?Øˆa‰D�‹G�q‰L‹GÞØ-.¨qªTÓ2ªT T˜qœ©TÑ2��!‘àˆEƒzØ‰à&'¨¨¡eÓ,¢e �q˜˜“u¡eˆÐ,Ü" ;°Ø˜a‘x ¨¡Ð*°ñ7ˆæØ%(Ñ"ˆD�'˜7Ø�#˜˜˜T !™V™Ñ$Ð%¹gÓ(Fºg°s¨!¨¨s¬¹gÑ(FÑFˆBØ�#˜˜˜T !™V™Ñ$Ð%¹gÓ(Fºg°s¨!¨¨s¬¹gÑ(FÑFˆBÜ¤Ð$4°q¸"¸aÀ°nÓ EÓF‰LˆAˆr�1�bØ�Q‘ˆAØ�B‘ˆAØ—	‘	“ˆAØ—	‘	“‰AàˆDàˆ�tˆA‡w€wØ�A‘$�q‘'�ˆØ�‰�dÔä”s˜6“{ 1‘}Ö%ˆAØ˜!‘9˜f Q q¡S™kˆqˆAÞ�V—Z‘Z  1Ó% aÑ(¨DÓ0ÞØ$Ÿl™l¨1¨aÓ0‘G�A�q™!àŸ
™
 1 aÓ(�AàŸ
™
 1 aÓ(¨Ñ+�ÞØ!Ÿ:™: a¨Ó+¨AÑ.�DÙ˜Q  q¡5¨!¨Q°°1Ô5Ü  1¨!¡e¨Q°°1°aÔ8Ù˜Q  q¡5¨!¨e¨V°Q¸Ô:Ü  1¨!¡e¨Q°°D°5¸!Ô<Ù˜Q  q¡5¨!¨Q°°AÔ6à %™i��q˜‘s‘Ø��q“	áò) &ö, Ø�a‹xØ�a�b�E˜Q˜q™T˜F‘N�Ø�a‹xÙ34Ó5²1¨C˜˜�W  A¡˜xÔ'±1Ñ5�Ø˜˜1™˜a™˜
Ñ"ˆæÜ�V‹}˜a Ð"Ð"ä�V‹}Ðùòm 6ùò :ùò0 3ùò
 -ùò
 )GùÚ(FùòN 6s6   Â-T7ÃT7ÄT<Ä0T<Ê$UËUÌUÌ1UÓ3Uc                 óp   • [         R                  " X5      u  p#nU S:w  a  X-  S:X  a  SnU S:  a  SOSnX#U4$ )aƒ  
This supports the functions that compute Hermite Normal Form.

Explanation
===========

Let x, y be the coefficients returned by the extended Euclidean
Algorithm, so that x*a + y*b = g. In the algorithms for computing HNF,
it is critical that x, y not only satisfy the condition of being small
in magnitude -- namely that |x| <= |b|/g, |y| <- |a|/g -- but also that
y == 0 when a | b.

r   r[   r   )r
   rD   )r&   r'   rq   rr   rG   s        r   Ú_gcdexrv   "  s?   € ô �hŠh�q‹n�G€Aˆ!ØˆAƒv�!‘%˜1“*ØˆØ�a“%‰B˜QˆØ�ˆ7€Nr   c                 óÆ  • U R                   R                  (       d  [        S5      eU R                  u  pU R	                  5       R                  5       n Un[        US-
  SS5       HÍ  nUS:X  a    OÆUS-  n[        US-
  SS5       HK  nX   U   S:w  d  M  [        X   U   X   U   5      u  pgnX   U   U-  X   U   U-  p©[        XXVXz* U	5        MM     X   U   nUS:  a  [        XUSSSS5        U* nUS:X  a  US-  nMœ  [        US-   U5       H  nX   U   U-  n[        XUSU* SS5        M      MÏ     [        R                  " U R                  5       5      SS2US24   $ )a¤  
Compute the Hermite Normal Form of DomainMatrix *A* over :ref:`ZZ`.

Parameters
==========

A : :py:class:`~.DomainMatrix` over domain :ref:`ZZ`.

Returns
=======

:py:class:`~.DomainMatrix`
    The HNF of matrix *A*.

Raises
======

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

References
==========

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

úMatrix must be over domain ZZ.r   r[   r   N)r   Úis_ZZr   r   Úto_ddmÚcopyr   rv   r,   r   Úfrom_repÚto_dfm_or_ddm)ÚAr   r:   r*   r   r   ÚuÚvr)   r   r5   r'   Úqs                r   Ú_hermite_normal_formr‚   7  sz  € ð8 �8‰8�>�>ÜÐ<Ó=Ð=ð �7‰7�D€AØ	�‰‹
�‰Ó€Að 	
€AÜ�1�q‘5˜"˜bÖ!ˆØ�‹6ñ Ø	ˆQ‰ˆô �q˜1‘u˜b "Ö%ˆAØ‰t�A‰w˜!�|ô ! ¡ a¡¨!©$¨q©'Ó2‘��aØ‘t˜A‘w !‘| Q¡T¨!¡W°¡\�1Ü˜A !¨¨2¨qÖ1ñ &ð ‰D�‰Gˆàˆq‹5Ü˜˜a  Q¨¨AÔ.Ø�ˆAð �‹6Ø�‰FŠAô
 ˜1˜q™5 !–_�Ø‘D˜‘G˜q‘L�Ü˜A ! Q¨¨¨A¨qÖ1ó %ñ? "ôH × Ò  §¡Ó!2Ó3²A°q±r°EÑ:Ð:r   c                 óŠ  • U R                   R                  (       d  [        S5      e[        R                  " U5      (       a  US:  a  [        S5      eS n[        [        5      nU R                  u  pEXT:  a  [        S5      eU R                  5       n UnUn[        US-
  SS5       Hú  nUS-  n[        US-
  SS5       HI  n	X   U	   S:w  d  M  [        X   U   X   U	   5      u  p«nX   U   U-  X   U	   U-  píU" XXiX«U* U5        MK     X   U   nUS:X  a	  U=X   U'   n[        X÷5      u  p«n[        U5       H  nX U   U   -  U-  UU   U'   M     X8   U   S:X  a  XsU   U'   [        US-   U5       H#  n	X8   U	   X8   U   -  n[        X9USU* SS5        M%     X|-  nMü     [        X4U4[        5      R                  5       $ )aß  
Perform the mod *D* Hermite Normal Form reduction algorithm on
:py:class:`~.DomainMatrix` *A*.

Explanation
===========

If *A* is an $m \times n$ matrix of rank $m$, having Hermite Normal Form
$W$, and if *D* is any positive integer known in advance to be a multiple
of $\det(W)$, then the HNF of *A* can be computed by an algorithm that
works mod *D* in order to prevent coefficient explosion.

Parameters
==========

A : :py:class:`~.DomainMatrix` over :ref:`ZZ`
    $m \times n$ matrix, having rank $m$.
D : :ref:`ZZ`
    Positive integer, known to be a multiple of the determinant of the
    HNF of *A*.

Returns
=======

:py:class:`~.DomainMatrix`
    The HNF of matrix *A*.

Raises
======

DMDomainError
    If the domain of the matrix is not :ref:`ZZ`, or
    if *D* is given but is not in :ref:`ZZ`.

DMShapeError
    If the matrix has more rows than columns.

References
==========

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

rx   r   z0Modulus D must be positive element of domain ZZ.c                 óÌ   • [        [        U 5      5       HL  nX   U   n	[        XI-  XPU   U   -  -   U-  U5      X   U'   [        Xi-  XpU   U   -  -   U-  U5      X   U'   MN     g r"   )r   r$   r   )
r   ÚRr   r   r&   r'   r(   r)   r*   r+   s
             r   Úadd_columns_mod_RÚ8_hermite_normal_form_modulo_D.<locals>.add_columns_mod_R¶  sq   € ô ”s˜1“v–ˆAØ‘�Q‘ˆAÜ'¨©°°q±T¸!±W±Ñ)<ÀÑ(AÀ1ÓEˆA‰D�‰GÜ'¨©°°q±T¸!±W±Ñ)<ÀÑ(AÀ1ÓEˆA‰D�‹Gò r   z2Matrix must have at least as many columns as rows.r[   r   )r   ry   r   r
   Úof_typer   Údictr   r   r   r   rv   r,   r   r2   )r~   ÚDr†   ÚWr   r:   r*   r…   r   r   r   r€   r)   r   r5   r'   Úiir�   s                     r   Ú_hermite_normal_form_modulo_Dr�   „  sß  € ðZ �8‰8�>�>ÜÐ<Ó=Ð=Ü�:Š:�a�=‰=˜A ›EÜÐNÓOÐOòFô 	”DÓ€Aà�7‰7�D€AØƒuÜÐOÓPÐPØ	�	‰	‹€AØ	€AØ	€AÜ�1�q‘5˜"˜bÖ!ˆØ	ˆQ‰ˆÜ�q˜1‘u˜b "Ö%ˆAØ‰t�A‰w˜!�|Ü  ¡ a¡¨!©$¨q©'Ó2‘��aØ‘t˜A‘w !‘| Q¡T¨!¡W°¡\�1Ù! !¨¨a°Q°B¸Ö:ñ	 &ð
 ‰D�‰GˆØ�‹6ØˆOˆA‰D�‰G�aÜ˜“,‰ˆˆaÜ˜–(ˆBØ˜2™˜q™‘z A‘~ˆAˆb‰E�!‹Hñ à‰4�‰7�a‹<Øˆa‰D�‰GÜ�q˜1‘u˜a–ˆAØ‘�Q‘˜1™4 ™7Ñ"ˆAÜ˜˜a  Q B¨¨1Ö-ñ !ð 	
‰Šñ% "ô& ˜˜q˜6¤2Ó&×/Ñ/Ó1Ð1r   NF)rŠ   Ú
check_rankc                óö   • U R                   R                  (       d  [        S5      eUbF  U(       a4  U R                  [        5      R                  5       U R                  S   :X  a  [        X5      $ [        U 5      $ )a}  
Compute the Hermite Normal Form of :py:class:`~.DomainMatrix` *A* over
:ref:`ZZ`.

Examples
========

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

Parameters
==========

A : $m \times n$ ``DomainMatrix`` over :ref:`ZZ`.

D : :ref:`ZZ`, 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
=======

:py:class:`~.DomainMatrix`
    The HNF of matrix *A*.

Raises
======

DMDomainError
    If the domain of the matrix is not :ref:`ZZ`, or
    if *D* is given but is not in :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.)

rx   r   )	r   ry   r   Ú
convert_tor	   Úrankr   r�   r‚   )r~   rŠ   rŽ   s      r   Úhermite_normal_formr’   Ü  sZ   € ðv �8‰8�>�>ÜÐ<Ó=Ð=Ø�}žj¨A¯L©L¼Ó,<×,AÑ,AÓ,CÀqÇwÁwÈqÁzÓ,QÜ,¨QÓ2Ð2ä# AÓ&Ð&r   )Ú__doc__Úcollectionsr   Údomainmatrixr   Ú
exceptionsr   r   Úsympy.ntheory.modularr   Úsympy.polys.domainsr	   r
   r   r    r,   r   r7   r0   rv   r‚   r�   r’   r>   r   r   Ú<module>r™      sX   ðÙ 2å #å &ß 3Ý 3ß &òò.ò:"òDò$ò8còLò*J;òZU2ðp !%°ö @'r   