Ë
    7^(hâB  ã                   ó�   — d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZmZ d„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdddœd„Zy)z,Functions returning normal forms of matricesé    )Údefaultdicté   )ÚDomainMatrix)ÚDMDomainErrorÚDMShapeError)Úsymmetric_residue)ÚQQÚZZc                 ór   — t        | «      }t        j                  || j                  | j                  «      }|S )aI  
    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      ú^/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/polys/matrices/normalforms.pyÚsmith_normal_formr      s/   € ô$ ˜QÓ€DÜ
×
Ñ
˜D !§(¡(¨A¯G©GÓ
4€CØ€Jó    c                 óÀ  — | j                   }| j                  }|j                  }| j                  «       } t	        |d   «      D ])  }t	        |d   «      D ]  }||k(  rŒ	| |   |   |k(  rŒ  y Œ+ t        |d   |d   «      }t	        d|«      D ]O  }| |dz
     |dz
     |k(  r| |   |   |k7  sŒ  y|j                  | |   |   | |dz
     |dz
     «      d   }||k7  sŒO y y)z8
    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Ø�AŠvØØ�Q‘4˜‘7˜d“?Úñ		ðô ��a‘˜% ™(Ó#€EÜ�1�e‹_ò ˆØˆQˆq‰S‰6�!�A‘#‰;˜$ÒØ�‰t�A‰w˜$‹Ùà—
‘
˜1˜Q™4 ™7 A a¨¡c¡F¨1¨Q©3¡KÓ0°Ñ3ˆAØ�D‹yÙðð r   c                 ó¢   — t        t        | «      «      D ]8  }| |   |   }||z  || |   |   z  z   | |   |<   ||z  || |   |   z  z   | |   |<   Œ: y ©N©r   Úlen©	r   r   r   ÚaÚbÚcÚdÚkÚes	            r   Úadd_columnsr,   E   sj   € ô ”3�q“6‹]ò "ˆØˆa‰D�‰GˆØ�A‘#˜˜!˜A™$˜q™'™	‘/ˆˆ!‰ˆQ‰Ø�A‘#˜˜!˜A™$˜q™'™	‘/ˆˆ!‰ˆQŠñ"r   c                 óp   — | j                   }| j                  }| j                  «       } t        | ||d¬«      S )a3  
    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   s2   € ð �X‰X€FØ�G‰G€EØ	�	‰	‹€AÜ  6°¸UÔCÐCr   c                 ó  — | j                   }| j                  x\  }}}| j                  «       } t        | ||d¬«      \  }}}t	        j
                  |||«      j                  «       }t	        ||||f¬«      }t	        ||||f¬«      }|||fS )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˜v¨d°D¨\Ô:€AÜ�Q˜v¨d°D¨\Ô:€AØ��1ˆ9Ðr   c           
      ó 	  ‡ ‡‡‡‡ ‡!‡"‡#‡$‡%— ‰j                   sd‰› �}t        |«      ‚|\  Š"Š ‰j                  Š%‰j                  Š!ˆ!ˆ%fd„}d|v r‰rd |‰"«       |‰ «      fS y‰r |‰"«      Š# |‰ «      Š$d„ Šˆˆˆˆ ˆ"ˆ#ˆ%fd„}ˆ ˆˆˆ ˆ$ˆ%fd„}t	        ‰"«      D �cg c]  }‰ |   d   ‰%k7  sŒ|‘Œ }	}|	r9|	d   ‰%k7  r1‰ |	d      ‰ d   c‰ d<   ‰ |	d   <   ‰r„‰#|	d      ‰#d   c‰#d<   ‰#|	d   <   nlt	        ‰ «      D �
cg c]  }
‰ d   |
   ‰%k7  sŒ|
‘Œ }	}
|	rF|	d   ‰%k7  r>‰ D ]  }||	d      |d   c|d<   ||	d   <   Œ ‰r‰$D ]  }||	d      |d   c|d<   ||	d   <   Œ t        ˆ ˆ%fd„t	        d	‰ «      D «       «      st        ˆ ˆ%fd
„t	        d	‰"«      D «       «      rN |«         |«        t        ˆ ˆ%fd„t	        d	‰ «      D «       «      rŒ.t        ˆ ˆ%fd
„t	        d	‰"«      D «       «      rŒNˆfd„}‰ d   d   dk7  rh‰j                  ‰ d   d   «      }‰j                  rd	‰ d   d   z  }|‰j                  k7  r+‰ d   dxx   |z  cc<   ‰r‰#d   D �cg c]  }||z  ‘Œ	 c}‰#d<   d	|v rd}nÅ‰ d	d D �cg c]  }|d	d ‘Œ	 }}t        |‰‰"d	z
  ‰ d	z
  f‰¬«      }‰r•|\  }}}d	gdg‰"d	z
  z  z   g|D �cg c]  }dg|z   ‘Œ
 c}z   }d	gdg‰ d	z
  z  z   g|D �cg c]  }dg|z   ‘Œ
 c}z   }t        t        |‰#|‰$|g«      «      \  Š#}Š$}|‰#z  Š#‰$|z  Š$‰#j                  «       Š#‰$j                  «       Š$n|}‰ d   d   �r$‰ d   d   g}|j                  |«       t	        t        |«      d	z
  «      D ]ï  }||   ||d	z      }}|rÝ‰j                  ||«      d	   ‰%k7  rÅ‰r‰j                  ||«      \  }}}n‰j!                  ||«      }‰j                  ||«      d   }‰rr‰j                  ||«      d   } ‰‰#||d	z   d	dd	«       t#        ‰$||d	z   d	dd	«        ‰‰#||d	z   d	| dd	«       t#        ‰$||d	z   d	d| d	«        ‰‰#||d	z   dd	dd«       ||z  ||d	z   <   |||<   Œï n@ n>‰r0‰"d	kD  r‰#d	d ‰#d   gz   Š#‰ d	kD  r‰$D �cg c]  }|d	d |d   gz   ‘Œ c}Š$|‰ d   d   fz   }‰rt%        |«      ‰#‰$fS t%        |«      S c c}w c c}
w c c}w c c}w c c}w c c}w c c}w )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           	      óŒ   •— t        | «      D ��cg c]"  }t        | «      D �cg c]  }||k(  r‰n‰‘Œ c}‘Œ$ c}}S c c}w c c}}w r"   )r   )Únr   r   Úoner   s      €€r   Úeyez!_smith_normal_decomp.<locals>.eye‹   s8   ø€ ÜEJÈ1ÃX×NÀ´%¸³(Ö;¨Q˜˜Qš‘ DÑ(Ô;ÓNÐNùÒ;ùÓNs   �A ¢;²A »A r   © c                 ó¨   — t        t        | d   «      «      D ]8  }| |   |   }||z  || |   |   z  z   | |   |<   ||z  || |   |   z  z   | |   |<   Œ: y )Nr   r#   r%   s	            r   Úadd_rowsz&_smith_normal_decomp.<locals>.add_rows˜   so   € ô ”s˜1˜Q™4“yÓ!ò 	&ˆAØ�!‘�Q‘ˆAØ˜‘c˜A˜a ™d 1™g™I‘oˆAˆa‰D�‰GØ˜‘c˜A˜a ™d 1™g™I‘oˆAˆa‰D�ŠGñ	&r   c            
      ó¤  •— ‰d   d   } t        d‰«      D ]¸  }‰|   d   ‰k(  rŒ‰
j                  ‰|   d   | «      \  }}|‰k(  r" ‰	‰d|dd| d«       ‰sŒA ‰	‰d|dd| d«       ŒQ‰
j                  | ‰|   d   «      \  }}}‰
j                  ‰|   d   |«      }‰
j                  | |«      } ‰	‰d||||| «       ‰r ‰	‰d||||| «       |} Œº y ©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_columnz*_smith_normal_decomp.<locals>.clear_column    s  ø€ à�!‘�Q‘ˆÜ�q˜$“ò 	ˆAØ�‰t�A‰w˜$ŠØØ—:‘:˜a ™d 1™g uÓ-‰DˆAˆqØ�DŠyÙ˜˜A˜q ! Q¨¨¨AÔ.ÚÙ˜Q  1 a¨¨Q¨B°Õ2à Ÿ,™, u¨a°©d°1©gÓ6‘��1�aØ—l‘l 1 Q¡4¨¡7¨AÓ.�Ø—l‘l 5¨!Ó,�Ù˜˜A˜q ! Q¨¨c¨TÔ2ÙÙ˜Q  1 a¨¨C°#°Ô6Ø‘ñ	r   c            
      ó¼  •— ‰d   d   } t        d‰	«      D ]Ä  }‰d   |   ‰k(  rŒ‰
j                  ‰d   |   | «      \  }}|‰k(  r(t        ‰d|dd| d«       ‰sŒDt        ‰d|dd| d«       ŒW‰
j                  | ‰d   |   «      \  }}}‰
j	                  ‰d   |   |«      }‰
j	                  | |«      }t        ‰d||||| «       ‰rt        ‰d||||| «       |} ŒÆ y rA   )r   r   r,   rB   rC   )rD   r   r)   r   r&   r'   rE   rF   rG   r4   r   r/   r   r6   r   s            €€€€€€r   Ú	clear_rowz'_smith_normal_decomp.<locals>.clear_row´   s  ø€ à�!‘�Q‘ˆÜ�q˜$“ò 	ˆAØ�‰t�A‰w˜$ŠØØ—:‘:˜a ™d 1™g uÓ-‰DˆAˆqØ�DŠyÜ˜A˜q ! Q¨¨A¨2¨qÔ1ÚÜ  1 a¨¨A°¨r°1Õ5à Ÿ,™, u¨a°©d°1©gÓ6‘��1�aØ—l‘l 1 Q¡4¨¡7¨AÓ.�Ø—l‘l 5¨!Ó,�Ü˜A˜q ! Q¨¨3°°Ô5ÙÜ  1 a¨¨A¨s°S°DÔ9Ø‘ñ	r   c              3   ó4   •K  — | ]  }‰d    |   ‰k7  –— Œ y­w©r   Nr=   ©Ú.0r   r   r   s     €€r   ú	<genexpr>z'_smith_normal_decomp.<locals>.<genexpr>Ø   ó   øè ø€ Ò6 1ˆq�‰t�A‰w˜$�Ñ6ùó   ƒr   c              3   ó4   •K  — | ]  }‰|   d    ‰k7  –— Œ y­wrL   r=   rM   s     €€r   rO   z'_smith_normal_decomp.<locals>.<genexpr>Ù   rP   rQ   c                 óN   •— t        | t        | «      t        | d   «      f‰¬«      S )Nr   )r   r   )r   r$   )r   r   s    €r   Úto_domain_matrixz._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   rB   Úgcdr,   Útuple)&r   r   r   r/   Úmsgr<   rH   rJ   r   Úindr   ÚrowrT   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� Q q¡T¨!¡W°£_Š1Ð
5€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ˆÐ9Ù�3�q‘6˜T’>Øò :�Ø&)¨#¨a©&¡k°3°q±6Ð#��A‘˜˜C ™Fšð:áØò >�CØ*-¨c°!©f©+°s¸1±vÐ'�C˜‘F˜C  A¡šKð>ô Ô6¬¨a°«Ô6Ô6ÜÔ6¬¨a°«Ô6Ô6ÙŒÙŒô Ô6¬¨a°«Ô6Õ6ÜÔ6¬¨a°«Ô6Õ6ôIð 	ˆ�tˆA�w�!‚|Ø×!Ñ! ! A¡$ q¡'Ó*ˆØ�?Š?Ø�A�a‘D˜‘G‘ˆAØ�—
‘
Š?Øˆa‰D�‹G�q‰L‹GÙØ-.¨q©TÖ2 T˜˜q›Ò2��!‘àˆE�zØ‰à&'¨¨ eÖ, �q˜˜’uÐ,ˆÐ,Ü" ;°Ø˜a‘x ¨¡Ð*°ô7ˆáØ%(Ñ"ˆD�'˜7Ø�#˜˜˜T !™V™Ñ$Ð%¸gÖ(F°s¨!¨¨s«Ò(FÑFˆBØ�#˜˜˜T !™V™Ñ$Ð%¸gÖ(F°s¨!¨¨s«Ò(FÑFˆBÜ¤Ð$4°q¸"¸aÀ°nÓ EÓF‰LˆAˆr�1�bØ�Q‘ˆAØ�B‘ˆAØ—	‘	“ˆAØ—	‘	“‰AàˆDàˆ�tˆAƒ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  1 q¡5¨!¨Q°°1Ô5Ü  1 a¨!¡e¨Q°°1°aÔ8Ù˜Q  1 q¡5¨!¨e¨V°Q¸Ô:Ü  1 a¨!¡e¨Q°°D°5¸!Ô<Ù˜Q  1 q¡5¨!¨Q°°AÔ6à %™i��q˜‘s‘Ø��q’	áñ)	ñ, Ø�aŠxØ�a�b�E˜Q˜q™T˜F‘N�Ø�aŠxØ34Ö5¨C�S˜˜�W  A¡˜xÓ'Ò5�Ø˜˜1™˜a™˜
Ñ"ˆáÜ�V‹}˜a Ð"Ð"ä�V‹}Ðùòm 6ùò :ùò0 3ùò
 -ùò
 )GùÚ(FùòN 6s6   ÂR-Â*R-Ã8R2Ä	R2É	R7É)R<Ê'SË
SÑ0Sc                 óp   — t        j                  | |«      \  }}}| dk7  r|| z  dk(  rd}| dk  rdnd}|||fS )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   rU   r   )r
   rB   )r&   r'   rk   rl   rE   s        r   Ú_gcdexrp   "  sG   € ô �h‰h�q˜!‹n�G€A€qˆ!ØˆA‚v�!�a‘%˜1’*ØˆØ�a’%‰B˜QˆØˆa�ˆ7€Nr   c                 óÀ  — | j                   j                  st        d«      ‚| j                  \  }}| j	                  «       j                  «       } |}t        |dz
  dd«      D ]Ð  }|dk(  r nÉ|dz  }t        |dz
  dd«      D ]R  }| |   |   dk7  sŒt        | |   |   | |   |   «      \  }}}| |   |   |z  | |   |   |z  }
}	t        | |||||
 |	«       ŒT | |   |   }|dk  rt        | ||dddd«       | }|dk(  r|dz  }Œ t        |dz   |«      D ]  }| |   |   |z  }t        | ||d| dd«       Œ! ŒÒ t        j                  | j                  «       «      dd…|d…f   S )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   rU   r   N)r   Úis_ZZr   r   Úto_ddmÚcopyr   rp   r,   r   Úfrom_repÚto_dfm_or_ddm)ÚAr   r:   r*   r   r   ÚuÚvr)   r   r5   r'   Úqs                r   Ú_hermite_normal_formr|   7  s§  € ð8 �8‰8�>Š>ÜÐ<Ó=Ð=ð �7‰7�D€A€qØ	�‰‹
�‰Ó€Að 	
€AÜ�1�q‘5˜"˜bÓ!ò !2ˆØ�Š6ñ Ø	ˆQ‰ˆô �q˜1‘u˜b "Ó%ò 	2ˆAØ�‰t�A‰w˜!‹|ô !  1¡ a¡¨!¨A©$¨q©'Ó2‘��1�aØ˜‘t˜A‘w !‘| Q q¡T¨!¡W°¡\�1�Ü˜A˜q ! Q¨¨A¨2¨qÕ1ð	2ð ˆa‰D�‰GˆàˆqŠ5Ü˜˜1˜a  Q¨¨AÔ.Ø�ˆAð �Š6Ø�‰F‰Aô
 ˜1˜q™5 !“_ò 2�Ø�a‘D˜‘G˜q‘L�Ü˜A˜q ! Q¨¨¨A¨qÕ1ñ2ð?!2ôH × Ñ  §¡Ó!2Ó3²A°q±r°EÑ:Ð:r   c                 óŒ  — | j                   j                  st        d«      ‚t        j                  |«      r|dk  rt        d«      ‚d„ }t        t        «      }| j                  \  }}||k  rt        d«      ‚| j                  «       } |}|}t        |dz
  dd«      D �]  }|dz  }t        |dz
  dd«      D ]P  }	| |   |	   dk7  sŒt        | |   |   | |   |	   «      \  }
}}| |   |   |z  | |   |	   |z  }} || |||	|
|| |«       ŒR | |   |   }|dk(  r
|x| |   |<   }t        ||«      \  }
}}t        |«      D ]  }|
| |   |   z  |z  ||   |<   Œ ||   |   dk(  r|||   |<   t        |dz   |«      D ]%  }	||   |	   ||   |   z  }t        ||	|d| dd«       Œ' ||z  }�Œ t        |||ft        «      j                  «       S )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.)

    rr   r   z0Modulus D must be positive element of domain ZZ.c                 óÖ   — t        t        | «      «      D ]R  }| |   |   }	t        ||	z  || |   |   z  z   |z  |«      | |   |<   t        ||	z  || |   |   z  z   |z  |«      | |   |<   ŒT y r"   )r   r$   r   )
r   ÚRr   r   r&   r'   r(   r)   r*   r+   s
             r   Úadd_columns_mod_Rz8_hermite_normal_form_modulo_D.<locals>.add_columns_mod_R¶  s†   € ô ”s˜1“v“ò 	FˆAØ�!‘�Q‘ˆAÜ'¨¨Q©°°Q°q±T¸!±W±Ñ)<ÀÑ(AÀ1ÓEˆAˆa‰D�‰GÜ'¨¨Q©°°Q°q±T¸!±W±Ñ)<ÀÑ(AÀ1ÓEˆAˆa‰D�ŠGñ	Fr   z2Matrix must have at least as many columns as rows.rU   r   )r   rs   r   r
   Úof_typer   Údictr   r   r   r   rp   r,   r   r2   )rx   ÚDr€   ÚWr   r:   r*   r   r   r   ry   rz   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€qØˆ1‚uÜÐOÓPÐPØ	�	‰	‹€AØ	€AØ	€AÜ�1�q‘5˜"˜bÓ!ó ˆØ	ˆQ‰ˆÜ�q˜1‘u˜b "Ó%ò 	;ˆAØ�‰t�A‰w˜!‹|Ü   1¡ a¡¨!¨A©$¨q©'Ó2‘��1�aØ˜‘t˜A‘w !‘| Q q¡T¨!¡W°¡\�1�Ù! ! Q¨¨1¨a°°Q°B¸Õ:ð		;ð
 ˆa‰D�‰GˆØ�Š6ØˆOˆAˆa‰D�‰G�aÜ˜˜A“,‰ˆˆ1ˆaÜ˜“(ò 	&ˆBØ˜˜2™˜q™‘z A‘~ˆAˆb‰E�!ŠHð	&àˆQ‰4�‰7�aŠ<ØˆAˆa‰D�‰GÜ�q˜1‘u˜a“ò 	.ˆAØ�!‘�Q‘˜1˜Q™4 ™7Ñ"ˆAÜ˜˜1˜a  Q B¨¨1Õ-ð	.ð 	
ˆa‰Šð%ô& ˜˜A˜q˜6¤2Ó&×/Ñ/Ó1Ð1r   NF)rƒ   Ú
check_rankc                óà   — | j                   j                  st        d«      ‚|�A|r3| j                  t        «      j                  «       | j                  d   k(  rt        | |«      S t        | «      S )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.)

    rr   r   )	r   rs   r   Ú
convert_tor	   Úrankr   r†   r|   )rx   rƒ   r‡   s      r   Úhermite_normal_formr‹   Ü  s\   € ð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   rp   r|   r†   r‹   r=   r   r   ú<module>r’      sX   ðÙ 2å #å &ß 3Ý 3ß &òò.ò:"òDò$ò8còLò*J;òZU2ðp !%°õ @'r   