+
    iˀ                         ^ 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   &&&&  W/var/www/html/photoedit/myenv/lib/python3.14/site-packages/sympy/polys/matrices/_dfm.py__new__DFM.__new__m   sq    ''/	E>U) U#CxxF++ 	* U%(J6(&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     	

3v&nnS!)..	&CHch

    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    yyjj$++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    IIK-!"LMMR<
3 ? ?<==r\*S%.."A"A<==\\\*S53E3Eu~~2V"W"WRSSB8#FLLL%&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FV\\%F%Ff6F6F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@    1v{z!A$'G'G#AaDz)#{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&**ejj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     ##DKK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?    %%%!! {{ell*DDtxx599/DDr,   c                    V ! WV4      # )r    )r   r   r   r   s   &&&&r"   	from_listDFM.from_list   s     8F++r,   c                6    V P                   P                  4       # )zConvert to a nested list.)r!   tolistrW   s   &r"   to_listDFM.to_list   s    xx  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    }}TZZ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\\^TZZ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[[]CIIszz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
 3v&&	  	U!$KE7"STT 	I!$>vh"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    xx!!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     zzhhqA1XqD	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     zzhhqA1XqD	565/)  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    [[ 99;r\dkkR/99U^^DHH5tzz6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     zzq5FAq5FA	]88AD>! 	]02aS8Ntzzl[\\	]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     zzq5FAq5FA	]"HHQTN 	]02aS8Ntzzl[\\	]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     HH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    
 zzA1u>> #5aS8Mdjj\!Z[[OOE"  A1u>> #8;PQUQ[Q[P\!]^^OOE"  }}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:     zz!HX&	!HX&	}}Y22r,   c                :    V P                  V P                  ) 4      # zNegate a DFM matrix.r/   r!   rW   s   &r"   negDFM.neg  s    }}dhhY''r,   c                Z    V P                  V P                  VP                  ,           4      # )zAdd two DFM matrices.r   re   s   &&r"   addDFM.add      }}TXX		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    }}TXX-..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    }}UXX-..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    EJJ'yyEII-ukkBBr,   c                "    V P                  4       # r   )r   rW   s   &r"   __neg__DFM.__neg__  s    xxz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*xx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     xx&--//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     wwq!((**r,   c                J    \         P                  ! W4      P                  4       # )zReturn a diagonal matrix.)ru   diagr}   )r   r   r   s   &&&r"   r   DFM.diag  s     xx)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    yy++-		499/Et{{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&Qhhj&%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?    HHzz!&s1y!12!1A!$!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    HHtyy!A3q)),-T77  . " 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    HHtyy!A1q5$)),T77  - " 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24==?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    HHtyy!A499%T77  & " 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 xx||~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 xx  "))+DbD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 KKzz6()LMM7 81 <=="WM}}TXX\\^44 &&Ka&OPP % M01K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    kkm&&(exxz188: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/    {{}!xxz188:%%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   \ {{cjj($++szz Z[[
 {{### 84;; FGGzzyy6QPQSTVWXYYF	 6;;=))#**,7>>@@	Q((..)C yy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  rrV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     ;;"488VT2D!XX]]_
azzIIaQ5IIaQ5IIaQ5IIaT[[9	  &*[[]%7%7%9"eLLNLLNLLNLLNQz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zz|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zz|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    zz!}}Q[[)E!--,@@@Qx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{    	  smeaABB zz88==?aMNN xx||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YY"MNNiiei$}}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YY"MNNT7c"		!ii3T[[A|r,   rj   rM   )FgGz?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 .)2V W-FQ .FQP-
&  W-H6 .H6T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,   