+
    
þÎjË€  ã                   óÎ   € ^ RI Ht ^ RIHt ^ RIHt ^ RIHtHt ^RI	H
t
HtHtHtHtHtHt ]R8w  d   R.t]! R4      tR.t]! R.R	7       ! R
 R4      4       t^ RIHt ^ RIHt R# )é    )ÚGROUND_TYPES)Úimport_module)Údoctest_depends_on)ÚZZÚQQ)ÚDMBadInputErrorÚDMDomainErrorÚDMNonSquareMatrixErrorÚDMNonInvertibleMatrixErrorÚDMRankErrorÚDMShapeErrorÚDMValueErrorÚflintÚ*ÚDFM©Úground_typesc                   ó
  a € ] tR t^Et o RtRtRtRtR t]	R 4       t
R t]	R 4       t]	R	 4       t]	R
 4       t]R 4       tR tR tR t]	R 4       tR tR tR tR tR tR t]	R 4       t]	R 4       tR tR t]	R 4       tR t ]	R 4       t!R t"]	R 4       t#R t$R  t%R! t&R" t'R# t(R$ t)R% t*R& t+R' t,R( t-R) t.R* t/R+ t0R, t1R- t2R. t3]	R/ 4       t4]	R0 4       t5]	R1 4       t6]	R2 4       t7R3 t8R4 t9R5 t:R6 t;R7 t<R8 t=R9 t>R: t?R; t@R< tAR= tB]C! R>R?7      R@ 4       tD]C! R>R?7      RA 4       tE]C! R>R?7      RB 4       tFRC tGRD tH]C! R>R?7      RE 4       tIRF tJRG tKRORI ltLRJ tMRPRK ltN]C! R>R?7      RQRL l4       tO]C! R>R?7      RQRM l4       tPRNtQV tRRH# )Rr   a¾  
Dense FLINT matrix. This class is a wrapper for matrices from python-flint.

>>> from sympy.polys.domains import ZZ
>>> from sympy.polys.matrices.dfm import DFM
>>> dfm = DFM([[ZZ(1), ZZ(2)], [ZZ(3), ZZ(4)]], (2, 2), ZZ)
>>> dfm
[[1, 2], [3, 4]]
>>> dfm.rep
[1, 2]
[3, 4]
>>> type(dfm.rep)  # doctest: +SKIP
<class 'flint._flint.fmpz_mat'>

Usually, the DFM class is not instantiated directly, but is created as the
internal representation of :class:`~.DomainMatrix`. When
`SYMPY_GROUND_TYPES` is set to `flint` and `python-flint` is installed, the
:class:`DFM` class is used automatically as the internal representation of
:class:`~.DomainMatrix` in dense format if the domain is supported by
python-flint.

>>> from sympy.polys.matrices.domainmatrix import DM
>>> dM = DM([[1, 2], [3, 4]], ZZ)
>>> dM.rep
[[1, 2], [3, 4]]

A :class:`~.DomainMatrix` can be converted to :class:`DFM` by calling the
:meth:`to_dfm` method:

>>> dM.to_dfm()
[[1, 2], [3, 4]]

ÚdenseTFc                ó¼   € V P                  V4      p^ V9  d    V! V4      pMV! V!  pV P	                  WRV4      #   \        \        3 d    \        RT 24      hi ; i)úConstruct from a nested list.z"Input should be a list of list of )Ú_get_flint_funcÚ
ValueErrorÚ	TypeErrorr   Ú_new)ÚclsÚrowslistÚshapeÚdomainÚ	flint_matÚreps   &&&&  ÚO/opt/data/home/.local/lib/python3.14/site-packages/sympy/polys/matrices/_dfm.pyÚ__new__ÚDFM.__new__m   sq   € à×'Ñ'¨Ó/ˆ	à�EŒ>ðUÙ Ó)‘ñ ˜UÑ#ˆCà�x‰x˜ FÓ+Ð+øô ¤	Ð*ô UÜ%Ð(JÈ6È(Ð&SÓTÐTðUús	   š; » Ac                ó˜   € V P                  WV4       \        P                  V 4      pWn        V;Vn        w  Vn        Vn        W4n        V# )z)Internal constructor from a flint matrix.)Ú_checkÚobjectr#   r!   r   ÚrowsÚcolsr   )r   r!   r   r   Úobjs   &&&& r"   r   ÚDFM._new{   sD   € ð 	�
‰
�3˜vÔ&Ü�n‰n˜SÓ!ˆØŒØ).Ð.ˆŒ	Ñ&�C”H˜cœhØŒ
Øˆ
ó    c                óN   € V P                  WP                  V P                  4      # )z>Create a new DFM with the same shape and domain but a new rep.)r   r   r   )Úselfr!   s   &&r"   Ú_new_repÚDFM._new_rep…   s   € à�y‰y˜Ÿj™j¨$¯+©+Ó6Ð6r,   c                ó:  € VP                  4       VP                  4       3pWB8w  d   \        R 4      hV\        8X  d,   \	        V\
        P                  4      '       g   \        R4      hV\        8X  d,   \	        V\
        P                  4      '       g   \        R4      hVP                  '       d<   \	        V\
        P                  \
        P                  34      '       g   \        R4      hV\        \        39  d    VP                  '       g   \        R4      hR# R# )z(Shape of rep does not match shape of DFMzRep is not a flint.fmpz_matzRep is not a flint.fmpq_matz1Rep is not a flint.fmpz_mod_mat or flint.nmod_matú#Only ZZ and QQ are supported by DFMN)ÚnrowsÚncolsr   r   Ú
isinstancer   Úfmpz_matÚRuntimeErrorr   Úfmpq_matÚis_FFÚfmpz_mod_matÚnmod_matÚNotImplementedError)r   r!   r   r   Úrepshapes   &&&& r"   r&   Ú
DFM._check‰   sÈ   € à—I‘I“K §¡£Ð-ˆØÔÜ!Ð"LÓMÐMØ”RŒ<¤
¨3´·±× ?Ò ?ÜÐ<Ó=Ð=Ø”rŒ\¤*¨S´%·.±.×"AÒ"AÜÐ<Ó=Ð=Ø�\�\ˆ\¤*¨S´5×3EÑ3EÄuÇ~Á~Ð2V×"WÒ"WÜÐRÓSÐSØœB¤˜8Ô#¨F¯L¯L¨LÜ%Ð&KÓLÐLñ -9Ñ#r,   c                óp   € V\         \        39   ;'       g!    VP                  ;'       d    VP                  # )z4Return True if the given domain is supported by DFM.)r   r   r9   Ú	_is_flint)r   r   s   &&r"   Ú_supports_domainÚDFM._supports_domain—   s-   € ð œ"œb˜Ñ!×FÐF V§\¡\×%FÐ%F°f×6FÑ6FÐFr,   c                óŽ  aaa€ V\         8X  d   \        P                  # V\        8X  d   \        P                  # VP
                  '       dq   VP                  4       o\        VP                  \        P                  4      '       d   \        P                  oVV3R lpV# \        P                  S4      oV3R lpV# \        R4      h)z3Return the flint matrix class for the given domain.c                  ó¦   <€ \        V 4      ^8X  d7   \        V ^ ,          \        P                  4      '       d   S! V ^ ,          4      # S! . V OSN5!  # )é   )Úlenr5   r   r;   )ÚeÚ_clsÚcs   *€€r"   Ú_funcÚ"DFM._get_flint_func.<locals>._func§   s@   ø€ Ü˜1“v ”{¤z°!°Aµ$¼¿¹×'GÒ'GÙ# A a¥D›zÐ)á#˜{ Q˜{¨›{Ð*r,   c                  ó6   <€ \         P                  ! . V OSN5!  # ©N)r   r:   )rG   Úms   *€r"   Ú<lambda>Ú%DFM._get_flint_func.<locals>.<lambda>®   s   ø€ ¤5×#5Ò#5Ð#<°qÐ#<¸!Ô#<r,   r2   )r   r   r6   r   r8   r9   Úcharacteristicr5   ÚoneÚnmodr;   Úfmpz_mod_ctxr<   )r   r   rJ   rH   rI   rN   s   && @@@r"   r   ÚDFM._get_flint_funcœ   s�   ú€ ð ”RŒ<Ü—>‘>Ð!Ø”rŒ\Ü—>‘>Ð!Ø�\�\ˆ\Ø×%Ñ%Ó'ˆAÜ˜&Ÿ*™*¤e§j¡j×1Ò1Ü—~‘~�ö+ð ˆLô ×&Ñ& qÓ)�Ü<�ØˆLä%Ð&KÓLÐLr,   c                ó8   € V P                  V P                  4      # )z5Callable to create a flint matrix of the same domain.)r   r   ©r.   s   &r"   rJ   Ú	DFM._func³   s   € ð ×#Ñ# D§K¡KÓ0Ð0r,   c                ó4   € \        V P                  4       4      # )zReturn ``str(self)``.)ÚstrÚto_ddmrW   s   &r"   Ú__str__ÚDFM.__str__¸   s   € ä�4—;‘;“=Ó!Ð!r,   c                óH   € R\        V P                  4       4      R,           2# )zReturn ``repr(self)``.r   :é   NN)Úreprr[   rW   s   &r"   Ú__repr__ÚDFM.__repr__¼   s    € à”T˜$Ÿ+™+›-Ó(¨Õ,Ð-Ð.Ð.r,   c                ó®   € \        V\        4      '       g   \        # V P                  VP                  8H  ;'       d    V P                  VP                  8H  # )zReturn ``self == other``.)r5   r   ÚNotImplementedr   r!   ©r.   Úothers   &&r"   Ú__eq__Ú
DFM.__eq__À   s?   € ä˜%¤×%Ò%Ü!Ð!ð �{‰{˜eŸl™lÑ*×DÐD¨t¯x©x¸5¿9¹9Ñ/DÐDr,   c                ó   € V ! WV4      # )r   © )r   r   r   r   s   &&&&r"   Ú	from_listÚDFM.from_listÉ   s   € ñ �8 FÓ+Ð+r,   c                ó6   € V P                   P                  4       # )zConvert to a nested list.)r!   ÚtolistrW   s   &r"   Úto_listÚDFM.to_listÎ   s   € à�x‰x�‰Ó Ð r,   c                óV   € V P                  V P                  V P                  4      4      # )zReturn a copy of self.)r/   rJ   r!   rW   s   &r"   ÚcopyÚDFM.copyÒ   s   € à�}‰}˜TŸZ™Z¨¯©Ó1Ó2Ð2r,   c                óv   € \         P                  ! V P                  4       V P                  V P                  4      # )zConvert to a DDM.)ÚDDMrk   ro   r   r   rW   s   &r"   r[   Ú
DFM.to_ddmÖ   ó#   € ä�}Š}˜TŸ\™\›^¨T¯Z©Z¸¿¹ÓEÐEr,   c                óv   € \         P                  ! V P                  4       V P                  V P                  4      # )zConvert to a SDM.)ÚSDMrk   ro   r   r   rW   s   &r"   Úto_sdmÚ
DFM.to_sdmÚ   rw   r,   c                ó   € V # )zReturn self.rj   rW   s   &r"   Úto_dfmÚ
DFM.to_dfmÞ   s   € àˆr,   c                ó   € V # )a  
Convert to a :class:`DFM`.

This :class:`DFM` method exists to parallel the :class:`~.DDM` and
:class:`~.SDM` methods. For :class:`DFM` it will always return self.

See Also
========

to_ddm
to_sdm
sympy.polys.matrices.domainmatrix.DomainMatrix.to_dfm_or_ddm
rj   rW   s   &r"   Úto_dfm_or_ddmÚDFM.to_dfm_or_ddmâ   s	   € ð ˆr,   c                ól   € V P                  VP                  4       VP                  VP                  4      # )zConvert from a DDM.)rk   ro   r   r   )r   Úddms   &&r"   Úfrom_ddmÚDFM.from_ddmò   s%   € ð �}‰}˜SŸ[™[›]¨C¯I©I°s·z±zÓBÐBr,   c                ó¸   € V P                  V4      p V! . VOVN5!  pT ! YRT4      #   \         d    \        RT 24      h\         d    \        RT 24      hi ; i)z Inverse of :meth:`to_list_flat`.z'Incorrect number of elements for shape zInput should be a list of )r   r   r   r   )r   Úelementsr   r   Úfuncr!   s   &&&&  r"   Úfrom_list_flatÚDFM.from_list_flat÷   s}   € ð ×"Ñ" 6Ó*ˆð	IÙÐ(˜Ð(˜xÓ(ˆCñ
 �3˜vÓ&Ð&øô	 ô 	UÜ!Ð$KÈEÈ7Ð"SÓTÐTÜô 	IÜ!Ð$>¸v¸hÐ"GÓHÐHð	Iús   “' §!AÁ	Ac                ó6   € V P                   P                  4       # )zConvert to a flat list.)r!   ÚentriesrW   s   &r"   Úto_list_flatÚDFM.to_list_flat  s   € à�x‰x×ÑÓ!Ð!r,   c                ó>   € V P                  4       P                  4       # )z$Convert to a flat list of non-zeros.)r[   Ú
to_flat_nzrW   s   &r"   r�   ÚDFM.to_flat_nz  s   € à�{‰{‹}×'Ñ'Ó)Ð)r,   c                óL   € \         P                  ! WV4      P                  4       # )zInverse of :meth:`to_flat_nz`.)ru   Úfrom_flat_nzr}   )r   r‡   Údatar   s   &&&&r"   r“   ÚDFM.from_flat_nz  s    € ô ×Ò °Ó7×>Ñ>Ó@Ð@r,   c                ó>   € V P                  4       P                  4       # )zConvert to a DOD.)r[   Úto_dodrW   s   &r"   r—   Ú
DFM.to_dod  ó   € à�{‰{‹}×#Ñ#Ó%Ð%r,   c                óL   € \         P                  ! WV4      P                  4       # )zInverse of :meth:`to_dod`.)ru   Úfrom_dodr}   )r   Údodr   r   s   &&&&r"   r›   ÚDFM.from_dod  ó   € ô �|Š|˜C¨Ó/×6Ñ6Ó8Ð8r,   c                ó>   € V P                  4       P                  4       # )zConvert to a DOK.)r[   Úto_dokrW   s   &r"   r    Ú
DFM.to_dok  r™   r,   c                óL   € \         P                  ! WV4      P                  4       # )zInverse of :math:`to_dod`.)ru   Úfrom_dokr}   )r   Údokr   r   s   &&&&r"   r£   ÚDFM.from_dok  rž   r,   c              #  óÊ   "  € V P                   w  rV P                  p\        V4       F5  p\        V4       F#  pW4V3,          pV'       g   K  W4V3,          x € K%  	  K7  	  R# 5i)z/Iterate over the non-zero values of the matrix.N©r   r!   Úrange©r.   rN   Únr!   ÚiÚjÚrepijs   &      r"   Úiter_valuesÚDFM.iter_values"  sP   é € à�z‰z‰ˆØ�h‰hˆÜ�q–ˆAÜ˜1–X�Ø˜q˜D�	�ß‘5Ø ˜d�)”Oó ó ùs   ‚AA#ÁA#c              #  óÀ   "  € V P                   w  rV P                  p\        V4       F0  p\        V4       F  pW4V3,          pV'       g   K  WE3V3x € K   	  K2  	  R# 5i)zBIterate over indices and values of nonzero elements of the matrix.Nr§   r©   s   &      r"   Ú
iter_itemsÚDFM.iter_items,  sQ   é € à�z‰z‰ˆØ�h‰hˆÜ�q–ˆAÜ˜1–X�Ø˜q˜D�	�ß‘5Ø˜6 5˜/Ô)ó ó ùs   ‚AAÁAc                ó”  € WP                   8X  d   V P                  4       # V\        8X  dP   V P                   \        8X  d;   V P	                  \
        P                  V P                  4      V P                  V4      # V P                  V4      '       d.   V P                  4       P                  V4      P                  4       # \        R4      h)zConvert to a new domain.r2   )r   rr   r   r   r   r   r8   r!   r   rA   r[   Ú
convert_tor}   r<   )r.   r   s   &&r"   r´   ÚDFM.convert_to6  s�   € à—[‘[Ô Ø—9‘9“;ÐØ”rŒ\˜dŸk™k¬RÔ/Ø—9‘9œUŸ^™^¨D¯H©HÓ5°t·z±zÀ6ÓJÐJØ×"Ñ" 6×*Ò*à—;‘;“=×+Ñ+¨FÓ3×:Ñ:Ó<Ð<ô &Ð&KÓLÐLr,   c           	     óÞ   € V P                   w  r4V^ 8  d	   W,          pV^ 8  d	   W$,          p V P                  W3,          #   \         d     \        RT RT RT P                    24      hi ; i)zGet the ``(i, j)``-th entry.úInvalid indices (ú, ú) for Matrix of shape ©r   r!   r   Ú
IndexError)r.   r«   r¬   rN   rª   s   &&&  r"   ÚgetitemÚDFM.getitemD  sv   € ð �z‰z‰ˆØˆqŒ5Ø�FˆAØˆqŒ5Ø�FˆAð	]Ø—8‘8˜A˜D•>Ð!øÜô 	]ÜÐ0°°°2°a°SÐ8NÈtÏzÉzÈlÐ[Ó\Ð\ð	]ús   ®A Á*A,c           	     óØ   € V P                   w  rEV^ 8  d	   W,          pV^ 8  d	   W%,          p W0P                  W3&   R#   \         d     \        RT RT RT P                    24      hi ; i)zSet the ``(i, j)``-th entry.r·   r¸   r¹   Nrº   )r.   r«   r¬   ÚvaluerN   rª   s   &&&&  r"   ÚsetitemÚDFM.setitemR  ss   € ð �z‰z‰ˆØˆqŒ5Ø�FˆAØˆqŒ5Ø�FˆAð	]Ø"�H‰H�Q�T‹NøÜô 	]ÜÐ0°°°2°a°SÐ8NÈtÏzÉzÈlÐ[Ó\Ð\ð	]ús	   ®? ¿*A)c           
     óæ   € V P                   pV UUu. uF  qB Uu. uF  qSWE3,          NK  	  upNK  	  ppp\        V4      \        V4      3pV P                  WgV P                  4      # u upi u uppi )z%Extract a submatrix with no checking.)r!   rF   rk   r   )r.   Ú	i_indicesÚ	j_indicesÚMr«   r¬   Úlolr   s   &&&     r"   Ú_extractÚDFM._extract`  se   € ð �H‰HˆÙ5>Ô?±Y° Ó+¡˜A�!�$—�¡Ô+±YˆÑ?Ü�Y“¤ Y£Ð0ˆØ�~‰~˜c¨$¯+©+Ó6Ð6ùò ,ùÓ?s   ’A-šA(¬A-Á(A-c                ó¨  € V P                   w  r4. p. pV FR  pV^ 8  d
   Ws,           pMTp^ Tu;8:  d   V8  g   M \        RV RV P                    24      hVP                  V4       KT  	  V FR  p	V	^ 8  d
   W”,           p
MT	p
^ T
u;8:  d   V8  g   M \        RV	 RV P                    24      hVP                  V
4       KT  	  V P                  WV4      # )zExtract a submatrix.zInvalid row index z for Matrix of shape zInvalid column index )r   r»   ÚappendrÇ   )r.   r   ÚcolslistrN   rª   Únew_rowsÚnew_colsr«   Úi_posr¬   Új_poss   &&&        r"   ÚextractÚDFM.extracth  sÔ   € ð
 �z‰z‰ˆàˆØˆãˆAØ�1ŒuØ�‘à�Ø˜–> –>Ü Ð#5°a°SÐ8MÈdÏjÉjÈ\Ð!ZÓ[Ð[Ø�O‰O˜EÖ"ñ ó ˆAØ�1ŒuØ�‘à�Ø˜–> –>Ü Ð#8¸¸Ð;PÐQU×Q[ÑQ[ÐP\Ð!]Ó^Ð^Ø�O‰O˜EÖ"ñ ð �}‰}˜XÓ0Ð0r,   c                óˆ   € V P                   w  r4\        V4      V,          p\        V4      V,          pV P                  WV4      # )zSlice a DFM.)r   r¨   rÇ   )r.   ÚrowsliceÚcolslicerN   rª   rÃ   rÄ   s   &&&    r"   Úextract_sliceÚDFM.extract_slice†  s:   € ð �z‰z‰ˆÜ˜!“H˜XÕ&ˆ	Ü˜!“H˜XÕ&ˆ	Ø�}‰}˜YÓ2Ð2r,   c                ó:   € V P                  V P                  ) 4      # ©zNegate a DFM matrix.©r/   r!   rW   s   &r"   ÚnegÚDFM.negŽ  s   € à�}‰}˜dŸh™h˜YÓ'Ð'r,   c                óZ   € V P                  V P                  VP                  ,           4      # )zAdd two DFM matrices.rÙ   re   s   &&r"   ÚaddÚDFM.add’  ó   € à�}‰}˜TŸX™X¨¯	©	Õ1Ó2Ð2r,   c                óZ   € V P                  V P                  VP                  ,
          4      # )zSubtract two DFM matrices.rÙ   re   s   &&r"   ÚsubÚDFM.sub–  rß   r,   c                óF   € V P                  V P                  V,          4      # )z1Multiply a DFM matrix from the right by a scalar.rÙ   re   s   &&r"   ÚmulÚDFM.mulš  s   € à�}‰}˜TŸX™X¨Õ-Ó.Ð.r,   c                óD   € V P                  WP                  ,          4      # )z0Multiply a DFM matrix from the left by a scalar.rÙ   re   s   &&r"   ÚrmulÚDFM.rmulž  s   € à�}‰}˜U§X¡XÕ-Ó.Ð.r,   c                óx   € V P                  4       P                  VP                  4       4      P                  4       # )z/Elementwise multiplication of two DFM matrices.)r[   Úmul_elementwiser}   re   s   &&r"   rê   ÚDFM.mul_elementwise¢  s*   € ð �{‰{‹}×,Ñ,¨U¯\©\«^Ó<×CÑCÓEÐEr,   c                ó    € V P                   VP                  3pV P                  V P                  VP                  ,          W P                  4      # )zMultiply two DFM matrices.)r(   r)   r   r!   r   )r.   rf   r   s   && r"   ÚmatmulÚ
DFM.matmul§  s6   € à—‘˜EŸJ™JÐ'ˆØ�y‰y˜Ÿ™ E§I¡IÕ-¨u·k±kÓBÐBr,   c                ó"   € V P                  4       # rØ   )rÚ   rW   s   &r"   Ú__neg__ÚDFM.__neg__°  s   € à�x‰x‹zÐr,   c                óP   € V P                  V4      pV P                  V! V!  W4      # )zReturn a zero DFM matrix.)r   r   )r   r   r   rˆ   s   &&& r"   ÚzerosÚ	DFM.zeros´  s)   € ð ×"Ñ" 6Ó*ˆØ�x‰x™˜e™ eÓ4Ð4r,   c                óJ   € \         P                  ! W4      P                  4       # )zReturn a one DFM matrix.)ru   Úonesr}   )r   r   r   s   &&&r"   rö   ÚDFM.ones¾  s   € ô �xŠx˜Ó&×-Ñ-Ó/Ð/r,   c                óJ   € \         P                  ! W4      P                  4       # )z%Return the identity matrix of size n.)ru   Úeyer}   )r   rª   r   s   &&&r"   rù   ÚDFM.eyeÄ  s   € ô �wŠw�qÓ!×(Ñ(Ó*Ð*r,   c                óJ   € \         P                  ! W4      P                  4       # )zReturn a diagonal matrix.)ru   Údiagr}   )r   r‡   r   s   &&&r"   rü   ÚDFM.diagÊ  s   € ô �xŠx˜Ó)×0Ñ0Ó2Ð2r,   c                ó\   € V P                  4       P                  W4      P                  4       # )z/Apply a function to each entry of a DFM matrix.)r[   Ú	applyfuncr}   )r.   rˆ   r   s   &&&r"   rÿ   ÚDFM.applyfuncÏ  s"   € à�{‰{‹}×&Ñ& tÓ4×;Ñ;Ó=Ð=r,   c                ó˜   € V P                  V P                  P                  4       V P                  V P                  3V P
                  4      # )zTranspose a DFM matrix.)r   r!   Ú	transposer)   r(   r   rW   s   &r"   r  ÚDFM.transposeÓ  s3   € à�y‰y˜Ÿ™×+Ñ+Ó-°·	±	¸4¿9¹9Ð/EÀtÇ{Á{ÓSÐSr,   c                óž   € V P                  4       P                  ! V Uu. uF  q"P                  4       NK  	  up!  P                  4       # u upi )zHorizontally stack matrices.)r[   Úhstackr}   ©r.   ÚothersÚos   &* r"   r  Ú
DFM.hstack×  ó8   € à�{‰{‹}×#Ò#¹&Ó%A¹&°Q§h¡h¦j¹&Ñ%AÑB×IÑIÓKÐKùÒ%Aó   ŸA
c                óž   € V P                  4       P                  ! V Uu. uF  q"P                  4       NK  	  up!  P                  4       # u upi )zVertically stack matrices.)r[   Úvstackr}   r  s   &* r"   r  Ú
DFM.vstackÛ  r
  r  c                ó–   € V P                   pV P                  w  r#\        \        W#4      4       Uu. uF  qAWD3,          NK  	  up# u upi )z$Return the diagonal of a DFM matrix.)r!   r   r¨   Úmin)r.   rÅ   rN   rª   r«   s   &    r"   ÚdiagonalÚDFM.diagonalß  s?   € à�H‰HˆØ�z‰z‰ˆÜ!&¤s¨1£yÔ!1Ó2Ñ!1˜A�!�$—�Ñ!1Ñ2Ð2ùÒ2s   ±Ac                óÈ   € V P                   p\        V P                  4       F<  p\        \        W P                  4      4       F  pWV3,          '       g   K    R# 	  K>  	  R# )z2Return ``True`` if the matrix is upper triangular.FT)r!   r¨   r(   r  r)   ©r.   rÅ   r«   r¬   s   &   r"   Úis_upperÚDFM.is_upperå  sI   € à�H‰HˆÜ�t—y‘yÖ!ˆAÜœ3˜q§)¡)Ó,Ö-�Ø˜�T—7–7Û ó .ñ "ñ r,   c                óÆ   € V P                   p\        V P                  4       F;  p\        V^,           V P                  4       F  pWV3,          '       g   K    R# 	  K=  	  R# )z2Return ``True`` if the matrix is lower triangular.FT©r!   r¨   r(   r)   r  s   &   r"   Úis_lowerÚDFM.is_lowerî  sJ   € à�H‰HˆÜ�t—y‘yÖ!ˆAÜ˜1˜q�5 $§)¡)Ö,�Ø˜�T—7–7Û ó -ñ "ñ r,   c                óR   € V P                  4       ;'       d    V P                  4       # )z*Return ``True`` if the matrix is diagonal.)r  r  rW   s   &r"   Úis_diagonalÚDFM.is_diagonal÷  s   € à�}‰}‹×2Ð2 4§=¡=£?Ð2r,   c                ó¶   € V P                   p\        V P                  4       F3  p\        V P                  4       F  pWV3,          '       g   K    R# 	  K5  	  R# )z1Return ``True`` if the matrix is the zero matrix.FTr  r  s   &   r"   Úis_zero_matrixÚDFM.is_zero_matrixû  sD   € à�H‰HˆÜ�t—y‘yÖ!ˆAÜ˜4Ÿ9™9Ö%�Ø˜�T—7–7Û ó &ñ "ñ r,   c                ó>   € V P                  4       P                  4       # )z5Return the number of non-zero elements in the matrix.)r[   ÚnnzrW   s   &r"   r"  ÚDFM.nnz  ó   € à�{‰{‹}× Ñ Ó"Ð"r,   c                ó>   € V P                  4       P                  4       # )z7Return the strongly connected components of the matrix.)r[   ÚsccrW   s   &r"   r&  ÚDFM.scc  r$  r,   r   r   c                ó6   € V P                   P                  4       # )a£  
Compute the determinant of the matrix using FLINT.

Examples
========

>>> from sympy import Matrix
>>> M = Matrix([[1, 2], [3, 4]])
>>> dfm = M.to_DM().to_dfm()
>>> dfm
[[1, 2], [3, 4]]
>>> dfm.det()
-2

Notes
=====

Calls the ``.det()`` method of the underlying FLINT matrix.

For :ref:`ZZ` or :ref:`QQ` this calls ``fmpz_mat_det`` or
``fmpq_mat_det`` respectively.

At the time of writing the implementation of ``fmpz_mat_det`` uses one
of several algorithms depending on the size of the matrix and bit size
of the entries. The algorithms used are:

- Cofactor for very small (up to 4x4) matrices.
- Bareiss for small (up to 25x25) matrices.
- Modular algorithms for larger matrices (up to 60x60) or for larger
  matrices with large bit sizes.
- Modular "accelerated" for larger matrices (60x60 upwards) if the bit
  size is smaller than the dimensions of the matrix.

The implementation of ``fmpq_mat_det`` clears denominators from each
row (not the whole matrix) and then calls ``fmpz_mat_det`` and divides
by the product of the denominators.

See Also
========

sympy.polys.matrices.domainmatrix.DomainMatrix.det
    Higher level interface to compute the determinant of a matrix.
)r!   ÚdetrW   s   &r"   r)  ÚDFM.det  s   € ðb �x‰x�|‰|‹~Ðr,   c                óf   € V P                   P                  4       P                  4       RRR1,          # )a;  
Compute the characteristic polynomial of the matrix using FLINT.

Examples
========

>>> from sympy import Matrix
>>> M = Matrix([[1, 2], [3, 4]])
>>> dfm = M.to_DM().to_dfm()  # need ground types = 'flint'
>>> dfm
[[1, 2], [3, 4]]
>>> dfm.charpoly()
[1, -5, -2]

Notes
=====

Calls the ``.charpoly()`` method of the underlying FLINT matrix.

For :ref:`ZZ` or :ref:`QQ` this calls ``fmpz_mat_charpoly`` or
``fmpq_mat_charpoly`` respectively.

At the time of writing the implementation of ``fmpq_mat_charpoly``
clears a denominator from the whole matrix and then calls
``fmpz_mat_charpoly``. The coefficients of the characteristic
polynomial are then multiplied by powers of the denominator.

The ``fmpz_mat_charpoly`` method uses a modular algorithm with CRT
reconstruction. The modular algorithm uses ``nmod_mat_charpoly`` which
uses Berkowitz for small matrices and non-prime moduli or otherwise
the Danilevsky method.

See Also
========

sympy.polys.matrices.domainmatrix.DomainMatrix.charpoly
    Higher level interface to compute the characteristic polynomial of
    a matrix.
Néÿÿÿÿ)r!   ÚcharpolyÚcoeffsrW   s   &r"   r-  ÚDFM.charpoly?  s*   € ðT �x‰x× Ñ Ó"×)Ñ)Ó+©D¨b¨DÕ1Ð1r,   c                óx  € V P                   pV P                  w  r#W#8w  d   \        R4      hV\        8X  d   \	        RV,          4      hV\
        8X  g   VP                  '       d+    V P                  V P                  P                  4       4      # \        RV,          4      h  \         d    \        R4      hi ; i)aü  
Compute the inverse of a matrix using FLINT.

Examples
========

>>> from sympy import Matrix, QQ
>>> M = Matrix([[1, 2], [3, 4]])
>>> dfm = M.to_DM().to_dfm().convert_to(QQ)
>>> dfm
[[1, 2], [3, 4]]
>>> dfm.inv()
[[-2, 1], [3/2, -1/2]]
>>> dfm.matmul(dfm.inv())
[[1, 0], [0, 1]]

Notes
=====

Calls the ``.inv()`` method of the underlying FLINT matrix.

For now this will raise an error if the domain is :ref:`ZZ` but will
use the FLINT method for :ref:`QQ`.

The FLINT methods for :ref:`ZZ` and :ref:`QQ` are ``fmpz_mat_inv`` and
``fmpq_mat_inv`` respectively. The ``fmpz_mat_inv`` method computes an
inverse with denominator. This is implemented by calling
``fmpz_mat_solve`` (see notes in :meth:`lu_solve` about the algorithm).

The ``fmpq_mat_inv`` method clears denominators from each row and then
multiplies those into the rhs identity matrix before calling
``fmpz_mat_solve``.

See Also
========

sympy.polys.matrices.domainmatrix.DomainMatrix.inv
    Higher level method for computing the inverse of a matrix.
z!cannot invert a non-square matrixzfield expected, got %szmatrix is not invertiblez#DFM.inv() is not implemented for %s)r   r   r
   r   r	   r   r9   r/   r!   ÚinvÚZeroDivisionErrorr   r<   )r.   ÚKrN   rª   s   &   r"   r1  ÚDFM.invk  s¢   € ðn �K‰KˆØ�z‰z‰ˆàŒ6Ü(Ð)LÓMÐMà”Œ7ÜÐ 8¸1Õ <Ó=Ð=Ø”"ŒW˜ŸŸ˜ðMØ—}‘} T§X¡X§\¡\£^Ó4Ð4ô &Ð&KÈaÕ&OÓPÐPøô %ô MÜ0Ð1KÓLÐLðMús   Á'(B" Â"B9c                ó†   € V P                  4       P                  4       w  rpVP                  4       VP                  4       V3# )z*Return the LU decomposition of the matrix.)r[   Úlur}   )r.   ÚLÚUÚswapss   &   r"   r6  ÚDFM.lu´  s3   € à—k‘k“m×&Ñ&Ó(‰ˆˆeØ�x‰x‹z˜1Ÿ8™8›: uÐ,Ð,r,   c                ó‚   € V P                  4       P                  4       w  rVP                  4       VP                  4       3# )z*Return the QR decomposition of the matrix.)r[   Úqrr}   )r.   ÚQÚRs   &  r"   r<  ÚDFM.qr¹  s/   € à�{‰{‹}×ÑÓ!‰ˆØ�x‰x‹z˜1Ÿ8™8›:Ð%Ð%r,   c           
     ó°  € V P                   VP                   8X  g(   \        RV P                   : RVP                   : 24      hV P                   P                  '       g   \        RV P                   ,          4      hV P                  w  r#VP                  w  rEW$8w  d   \	        RV: RV: RV: RV: 24      hW53pW#8w  d<   V P                  4       P                  VP                  4       4      P                  4       #  V P                  P                  VP                  4      pT P                  YvT P                   4      #   \         d    \        R4      hi ; i)aè  
Solve a matrix equation using FLINT.

Examples
========

>>> from sympy import Matrix, QQ
>>> M = Matrix([[1, 2], [3, 4]])
>>> dfm = M.to_DM().to_dfm().convert_to(QQ)
>>> dfm
[[1, 2], [3, 4]]
>>> rhs = Matrix([1, 2]).to_DM().to_dfm().convert_to(QQ)
>>> dfm.lu_solve(rhs)
[[0], [1/2]]

Notes
=====

Calls the ``.solve()`` method of the underlying FLINT matrix.

For now this will raise an error if the domain is :ref:`ZZ` but will
use the FLINT method for :ref:`QQ`.

The FLINT methods for :ref:`ZZ` and :ref:`QQ` are ``fmpz_mat_solve``
and ``fmpq_mat_solve`` respectively. The ``fmpq_mat_solve`` method
uses one of two algorithms:

- For small matrices (<25 rows) it clears denominators between the
  matrix and rhs and uses ``fmpz_mat_solve``.
- For larger matrices it uses ``fmpq_mat_solve_dixon`` which is a
  modular approach with CRT reconstruction over :ref:`QQ`.

The ``fmpz_mat_solve`` method uses one of four algorithms:

- For very small (<= 3x3) matrices it uses a Cramer's rule.
- For small (<= 15x15) matrices it uses a fraction-free LU solve.
- Otherwise it uses either Dixon or another multimodular approach.

See Also
========

sympy.polys.matrices.domainmatrix.DomainMatrix.lu_solve
    Higher level interface to solve a matrix equation.
zDomains must match: z != zField expected, got %szMatrix size mismatch: z * z vs z Matrix det == 0; not invertible.)r   r	   Úis_Fieldr   r   r[   Úlu_solver}   r!   Úsolver2  r   r   )r.   ÚrhsrN   rª   r¬   ÚkÚ	sol_shapeÚsols   &&      r"   rB  ÚDFM.lu_solveÉ  s  € ð\ �{‰{˜cŸj™jÔ(ÝÀ$Ç+Ä+ÈsÏzËzÐ ZÓ[Ð[ð
 �{‰{×#×#Ð#ÜÐ 8¸4¿;¹;Õ FÓGÐGà�z‰z‰ˆØ�y‰y‰ˆØŒ6ÝËQÓPQÓSTÒVWÐXÓYÐYØ�Fˆ	ð Œ6Ø—;‘;“=×)Ñ)¨#¯*©*«,Ó7×>Ñ>Ó@Ð@ð	QØ—(‘(—.‘. §¡Ó)ˆCð �y‰y˜¨¯©Ó5Ð5øô !ô 	QÜ,Ð-OÓPÐPð	Qús   Ã=%D> Ä>Ec                ó~  € V P                   \        8X  dÅ   \        V P                  RR4      pVeª   V P                  P	                  4       w  r#rEV P
                  w  rgV P                  W&V3V P                   4      V P                  W6V3V P                   4      V P                  WFV3V P                   4      V P                  WPP
                  V P                   4      3# V P                  4       P	                  4       w  r‰r«VP                  4       pV	P                  4       pV
P                  4       pVP                  4       pW#WE3# )zÐ
Fraction-free LU decomposition of DFM.

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

Uses `python-flint` if possible for a matrix of
integers otherwise uses the DDM method.

See Also
========

sympy.polys.matrices.ddm.DDM.fflu
ÚffluN)	r   r   Úgetattrr!   rJ  r   r   r[   r}   )r.   rJ  ÚPr7  ÚDr8  rN   rª   Úddm_pÚddm_lÚddm_dÚddm_us   &           r"   rJ  ÚDFM.fflu  sù   € ð �;‰;œ"ÔÜ˜4Ÿ8™8 V¨TÓ2ˆDØÒØ!ŸX™XŸ]™]›_‘
��aØ—z‘z‘�à—I‘I˜a Q ¨¯©Ó5Ø—I‘I˜a Q ¨¯©Ó5Ø—I‘I˜a Q ¨¯©Ó5Ø—I‘I˜a§¡¨T¯[©[Ó9ð	ð ð &*§[¡[£]×%7Ñ%7Ó%9Ñ"ˆ�eØ�L‰L‹NˆØ�L‰L‹NˆØ�L‰L‹NˆØ�L‰L‹NˆØ�QˆzÐr,   c                óf   € V P                  4       P                  4       w  rVP                  4       V3# )ú/Return a basis for the nullspace of the matrix.)r[   Ú	nullspacer}   )r.   rƒ   Ú	nonpivotss   &  r"   rU  ÚDFM.nullspace5  s+   € ð& Ÿ™›×0Ñ0Ó2‰ˆØ�z‰z‹|˜YÐ&Ð&r,   Nc                ój   € V P                  4       P                  VR7      w  r#VP                  4       V3# )rT  )Úpivots)rz   Únullspace_from_rrefr}   )r.   rY  ÚsdmrV  s   &&  r"   rZ  ÚDFM.nullspace_from_rrefK  s0   € ð Ÿ™›×:Ñ:À&Ð:ÓI‰ˆØ�z‰z‹|˜YÐ&Ð&r,   c                óZ   € V P                  4       P                  4       P                  4       # )z+Return a particular solution to the system.)r[   Ú
particularr}   rW   s   &r"   r^  ÚDFM.particularQ  s    € à�{‰{‹}×'Ñ'Ó)×0Ñ0Ó2Ð2r,   c                ó  € R pV! V4      pV! V4      pRTu;8  d   ^8  g   M \        R4      hV P                  w  rxV P                  P                  4       V8w  d   \	        R4      hV P                  P                  WW4VR7      # )zACall the fmpz_mat.lll() method but check rank to avoid segfaults.c                 ó®   € \         P                  ! V 4      '       d0   \        V P                  4      \        V P                  4      ,          # \        V 4      # rM   )r   Úof_typeÚfloatÚ	numeratorÚdenominator)Úxs   &r"   Úto_floatÚDFM._lll.<locals>.to_float_  s5   € Ü�zŠz˜!�}Š}Ü˜QŸ[™[Ó)¬E°!·-±-Ó,@Õ@Ð@ä˜Q“x�r,   g      Ð?z delta must be between 0.25 and 1z-Matrix must have full row rank for Flint LLL.)Ú	transformÚdeltaÚetar!   Úgram)r   r   r!   Úrankr   Úlll)	r.   ri  rj  rk  r!   rl  rg  rN   rª   s	   &&&&&&   r"   Ú_lllÚDFM._lllU  s{   € ò	 ñ ˜“ˆÙ�s‹mˆà�eÖ˜aÖÜÐAÓBÐBð �z‰z‰ˆØ�8‰8�=‰=‹?˜aÔÜÐMÓNÐNð �x‰x�|‰| iÀ#ÐUYˆ|ÓZÐZr,   c                óö   € V P                   \        8w  d   \        RV P                   ,          4      hV P                  V P                  8”  d   \        R4      hV P                  VR7      pV P                  V4      # )a§  Compute LLL-reduced basis using FLINT.

See :meth:`lll_transform` for more information.

Examples
========

>>> from sympy import Matrix
>>> M = Matrix([[1, 2, 3], [4, 5, 6]])
>>> M.to_DM().to_dfm().lll()
[[2, 1, 0], [-1, 1, 3]]

See Also
========

sympy.polys.matrices.domainmatrix.DomainMatrix.lll
    Higher level interface to compute LLL-reduced basis.
lll_transform
    Compute LLL-reduced basis and transform matrix.
úZZ expected, got %sú,Matrix must not have more rows than columns.)rj  )r   r   r	   r(   r)   r   ro  r/   )r.   rj  r!   s   && r"   rn  ÚDFM.llls  s`   € ð, �;‰;œ"ÔÜÐ 5¸¿¹Õ CÓDÐDØ�Y‰Y˜Ÿ™Ô"ÜÐMÓNÐNà�i‰i˜eˆiÓ$ˆØ�}‰}˜SÓ!Ð!r,   c                óf  € V P                   \        8w  d   \        RV P                   ,          4      hV P                  V P                  8”  d   \        R4      hV P                  RVR7      w  r#V P                  V4      pV P                  W0P                  V P                  3V P                   4      pWE3# )aÔ  Compute LLL-reduced basis and transform using FLINT.

Examples
========

>>> from sympy import Matrix
>>> M = Matrix([[1, 2, 3], [4, 5, 6]]).to_DM().to_dfm()
>>> M_lll, T = M.lll_transform()
>>> M_lll
[[2, 1, 0], [-1, 1, 3]]
>>> T
[[-2, 1], [3, -1]]
>>> T.matmul(M) == M_lll
True

See Also
========

sympy.polys.matrices.domainmatrix.DomainMatrix.lll
    Higher level interface to compute LLL-reduced basis.
lll
    Compute LLL-reduced basis without transform matrix.
rr  rs  T)ri  rj  )	r   r   r	   r(   r)   r   ro  r/   r   )r.   rj  r!   ÚTÚbasisÚT_dfms   &&    r"   Úlll_transformÚDFM.lll_transform‘  sŒ   € ð2 �;‰;œ"ÔÜÐ 5¸¿¹Õ CÓDÐDØ�Y‰Y˜Ÿ™Ô"ÜÐMÓNÐNà—‘ T°�Ó7‰ˆØ—‘˜cÓ"ˆØ—	‘	˜!Ÿi™i¨¯©Ð3°T·[±[ÓAˆØˆ|Ðr,   rj   rM   )Fg®Gáz®ï?gR¸…ëQà?ÚzbasisÚapprox)g      è?)SÚ__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚfmtÚis_DFMÚis_DDMr#   Úclassmethodr   r/   r&   rA   r   ÚpropertyrJ   r\   ra   rg   rk   ro   rr   r[   rz   r}   r€   r„   r‰   r�   r�   r“   r—   r›   r    r£   r®   r±   r´   r¼   rÀ   rÇ   rÐ   rÕ   rÚ   rÝ   rá   rä   rç   rê   rí   rð   ró   rö   rù   rü   rÿ   r  r  r  r  r  r  r  r  r"  r&  r   r)  r-  r1  r6  r<  rB  rJ  rU  rZ  r^  ro  rn  ry  Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r"   r   r   E   sô  ø‡ € ñ ðD €CØ€FØ€Fò,ð ñó ðò7ð ñMó ðMð ñGó ðGð ñMó ðMð, ñ1ó ð1ò"ò/òEð ñ,ó ð,ò!ò3òFòFòòð  ñCó ðCð ñ	'ó ð	'ò"ò*ð ñAó ðAò&ð ñ9ó ð9ò&ð ñ9ó ð9ò$ò*òMò]ò]ò7ò1ò<3ò(ò3ò3ò/ò/òFò
Còð ñ5ó ð5ð ñ0ó ð0ð
 ñ+ó ð+ð
 ñ3ó ð3ò>òTòLòLò3òòò3òò#ò#ñ  WÔ-ñ0ó .ð0ñd  WÔ-ñ)2ó .ð)2ñV  WÔ-ñFQó .ðFQòP-ò
&ñ   WÔ-ñH6ó .ðH6òTòB'ô,'ò3ô[ñ<  WÔ-ó"ó .ð"ñ:  WÔ-ó ó .ö r,   )ru   )ry   N)Úsympy.external.gmpyr   Úsympy.external.importtoolsr   Úsympy.utilities.decoratorr   Úsympy.polys.domainsr   r   Ú
exceptionsr   r	   r
   r   r   r   r   Ú__doctest_skip__r   Ú__all__r   Úsympy.polys.matrices.ddmru   ry   rj   r,   r"   Ú<module>r’     sv   ðõT -Ý 4Ý 8ç &÷÷ ñ ð �7ÔØ�uÐñ 	�gÓ€ð ˆ'€ñ  ' Ô+÷lð ló ,ðlõ` )ß (r,   