
    Ed,                     @   d Z ddlmZmZmZmZmZmZmZm	Z	m
Z
 ddlmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZmZ ddl m!Z!m"Z"m#Z#m$Z$m%Z% ddl&m'Z'm(Z( ddl)m*Z*m+Z+ d Z,d	 Z-d
 Z.d Z/d Z0d Z1d Z2d Z3d Z4ddZ5ddZ6ddZ7ddZ8ddZ9ddZ:d Z;d Z<dS )z8Square-free decomposition algorithms and related tools.     )	dup_negdmp_negdup_subdmp_subdup_muldup_quodmp_quodup_mul_grounddmp_mul_ground)
	dup_stripdup_LCdmp_ground_LC
dmp_zero_p
dmp_ground
dup_degree
dmp_degree	dmp_raise
dmp_injectdup_convert)	dup_diffdmp_diffdmp_diff_in	dup_shiftdmp_compose	dup_monicdmp_ground_monicdup_primitivedmp_ground_primitive)dup_inner_gcddmp_inner_gcddup_gcddmp_gcddmp_resultant)gf_sqf_listgf_sqf_part)MultivariatePolynomialErrorDomainErrorc           
      f    | sdS t          t          | t          | d|          |                     S )a  
    Return ``True`` if ``f`` is a square-free polynomial in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x = ring("x", ZZ)

    >>> R.dup_sqf_p(x**2 - 2*x + 1)
    False
    >>> R.dup_sqf_p(x**2 - 1)
    True

    T   )r   r!   r   )fKs     7lib/python3.11/site-packages/sympy/polys/sqfreetools.py	dup_sqf_pr-   !   s;       @tga!Q):):A>>????    c                     t          | |          rdS t          t          | t          | d||          ||          |           S )a  
    Return ``True`` if ``f`` is a square-free polynomial in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x,y = ring("x,y", ZZ)

    >>> R.dmp_sqf_p(x**2 + 2*x*y + y**2)
    False
    >>> R.dmp_sqf_p(x**2 + y**2)
    True

    Tr)   )r   r   r"   r   r*   ur+   s      r,   	dmp_sqf_pr2   7   sK      !Q Itga!Q1)=)=q!DDaHHHHr.   c                 @   |j         st          d          dt          |j        j        dd|j                  }}	 t          | d|d          \  }}t          ||d|j                  }t          ||j                  rnt          | |j
         |          |dz   }} `|| |fS )al  
    Square-free norm of ``f`` in ``K[x]``, useful over algebraic domains.

    Returns ``s``, ``f``, ``r``, such that ``g(x) = f(x-sa)`` and ``r(x) = Norm(g(x))``
    is a square-free polynomial over K, where ``a`` is the algebraic extension of ``K``.

    Examples
    ========

    >>> from sympy.polys import ring, QQ
    >>> from sympy import sqrt

    >>> K = QQ.algebraic_field(sqrt(3))
    >>> R, x = ring("x", K)
    >>> _, X = ring("x", QQ)

    >>> s, f, r = R.dup_sqf_norm(x**2 - 2)

    >>> s == 1
    True
    >>> f == x**2 + K([QQ(-2), QQ(0)])*x + 1
    True
    >>> r == X**4 - 10*X**2 + 1
    True

    ground domain must be algebraicr   r)   Tfront)is_Algebraicr'   r   modrepdomr   r#   r-   r   unit)r*   r+   sgh_rs          r,   dup_sqf_normrA   M   s    6 > =;<<<i	1a//qA3!Q...1!Q15))Q 	3Q++QUqA3 a7Nr.   c                    |st          | |          S |j        st          d          t          |j        j        |dz   d|j                  }t          |j        |j         g|d|          }d}	 t          | ||d          \  }}t          |||dz   |j                  }t          |||j                  rnt          | |||          |dz   }} _|| |fS )a  
    Square-free norm of ``f`` in ``K[X]``, useful over algebraic domains.

    Returns ``s``, ``f``, ``r``, such that ``g(x) = f(x-sa)`` and ``r(x) = Norm(g(x))``
    is a square-free polynomial over K, where ``a`` is the algebraic extension of ``K``.

    Examples
    ========

    >>> from sympy.polys import ring, QQ
    >>> from sympy import I

    >>> K = QQ.algebraic_field(I)
    >>> R, x, y = ring("x,y", K)
    >>> _, X, Y = ring("x,y", QQ)

    >>> s, f, r = R.dmp_sqf_norm(x*y + y**2)

    >>> s == 1
    True
    >>> f == x*y + y**2 + K([QQ(-1), QQ(0)])*y
    True
    >>> r == X**2*Y**2 + 2*X*Y**3 + Y**4 + Y**2
    True

    r4   r)   r   Tr5   )rA   r7   r'   r   r8   r9   r:   oner;   r   r#   r2   r   )	r*   r1   r+   r=   Fr<   r>   r?   r@   s	            r,   dmp_sqf_normrE   y   s    6  "Aq!!!> =;<<<!%)QUAqu--A1516'"Aq!,,A	A2!Q...1!QAqu--Q15!! 	2q!Q**AEqA2 a7Nr.   c                     |j         st          d          t          |j        j        |dz   d|j                  }t          | ||d          \  }}t          |||dz   |j                  S )zE
    Norm of ``f`` in ``K[X1, ..., Xn]``, often not square-free.
    r4   r)   r   Tr5   )r7   r'   r   r8   r9   r:   r   r#   )r*   r1   r+   r=   r>   r?   s         r,   dmp_normrG      sn     > =;<<<!%)QUAqu--AaAT***DAqAq1uae,,,r.   c                     t          | ||j                  } t          | |j        |j                  }t          ||j        |          S )z3Compute square-free part of ``f`` in ``GF(p)[x]``. )r   r:   r%   r8   )r*   r+   r=   s      r,   dup_gf_sqf_partrI      s>    Aq!%  AAquae$$Aq!%###r.   c                      t          d          )z3Compute square-free part of ``f`` in ``GF(p)[X]``. +multivariate polynomials over finite fieldsNotImplementedErrorr0   s      r,   dmp_gf_sqf_partrN          
K
L
LLr.   c                 Z   |j         rt          | |          S | s| S |                    t          | |                    rt	          | |          } t          | t          | d|          |          }t          | ||          }|j        rt          ||          S t          ||          d         S )z
    Returns square-free part of a polynomial in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x = ring("x", ZZ)

    >>> R.dup_sqf_part(x**3 - 3*x - 2)
    x**2 - x - 2

    r)   )is_FiniteFieldrI   is_negativer   r   r!   r   r   is_Fieldr   r   )r*   r+   gcdsqfs       r,   dup_sqf_partrV      s     	 %q!$$$ }}VAq\\"" AqMM
!XaA&&
*
*C
!S!

Cz (a   S!$$Q''r.   c                    |st          | |          S |j        rt          | ||          S t          | |          r| S |                    t          | ||                    rt          | ||          } | }t          |dz             D ]%}t          |t          | d|||          ||          }&t          | |||          }|j        rt          |||          S t          |||          d         S )z
    Returns square-free part of a polynomial in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x,y = ring("x,y", ZZ)

    >>> R.dmp_sqf_part(x**3 + 2*x**2*y + x*y**2)
    x**2 + x*y

    r)   )rV   rQ   rN   r   rR   r   r   ranger"   r   r	   rS   r   r   )r*   r1   r+   rT   irU   s         r,   dmp_sqf_partrZ      s
     "Aq!!! (q!Q'''!Q }}]1a++,, Aq!
C1Q3ZZ = =c;q!Q155q!<<
!S!Q

Cz 2Q***#CA..q11r.   Fc                    t          | ||j                  } t          | |j        |j        |          \  }}t	          |          D ]#\  }\  } }t          | |j        |          |f||<   $|                    ||j                  |fS )z<Compute square-free decomposition of ``f`` in ``GF(p)[x]``. all)r   r:   r$   r8   	enumerateconvert)r*   r+   r]   coefffactorsrY   ks          r,   dup_gf_sqf_listrc   	  s    Aq!%  A AE15c:::NE7w'' 3 3	6Aq!!QUA..2

99UAE""G++r.   c                      t          d          )z<Compute square-free decomposition of ``f`` in ``GF(p)[X]``. rK   rL   )r*   r1   r+   r]   s       r,   dmp_gf_sqf_listre     rO   r.   c                    |j         rt          | ||          S |j        r!t          | |          }t	          | |          } nIt          | |          \  }} |                    t          | |                    rt          | |          } | }t          |           dk    r|g fS g d}}t          | d|          }t          | ||          \  }}}		 t          |d|          }
t          |	|
|          }|s|                    ||f           nGt          |||          \  }}}	|st          |          dk    r|                    ||f           |dz  }||fS )as  
    Return square-free decomposition of a polynomial in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x = ring("x", ZZ)

    >>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16

    >>> R.dup_sqf_list(f)
    (2, [(x + 1, 2), (x + 2, 3)])
    >>> R.dup_sqf_list(f, all=True)
    (2, [(1, 1), (x + 1, 2), (x + 2, 3)])

    r\   r   r)   )rQ   rc   rS   r   r   r   rR   r   r   r   r   r   append)r*   r+   r]   r`   resultrY   r>   r=   pqds              r,   dup_sqf_listrl     s   $ 	 .q!----z q!aOO A&&q==1&& 	1AFE!}} byAAFAqAAq!$$GAq!Q1Aq! 	MM1a&!!!1a((1a 	"*Q--!# 	"MM1a&!!!	Q &=r.   c                     t          | ||          \  }}|r?|d         d         dk    r-t          |d         d         ||          }|dfg|dd         z   S t          |g          }|dfg|z   S )a  
    Return square-free decomposition of a polynomial in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x = ring("x", ZZ)

    >>> f = 2*x**5 + 16*x**4 + 50*x**3 + 76*x**2 + 56*x + 16

    >>> R.dup_sqf_list_include(f)
    [(2, 1), (x + 1, 2), (x + 2, 3)]
    >>> R.dup_sqf_list_include(f, all=True)
    [(2, 1), (x + 1, 2), (x + 2, 3)]

    r\   r   r)   N)rl   r
   r   )r*   r+   r]   r`   ra   r=   s         r,   dup_sqf_list_includern   S  s    $ "!QC000NE7 "71:a=A% "71:a=%33Ax'!""+%%ugAx'!!r.   c                    |st          | ||          S |j        rt          | |||          S |j        r#t	          | ||          }t          | ||          } nLt          | ||          \  }} |                    t	          | ||                    rt          | ||          } | }t          | |          dk    r|g fS g d}}t          | d||          }t          | |||          \  }}	}
	 t          |	d||          }t          |
|||          }t          ||          r|                    |	|f           nIt          |	|||          \  }}	}
|st          ||          dk    r|                    ||f           |dz  }||fS )aZ  
    Return square-free decomposition of a polynomial in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x,y = ring("x,y", ZZ)

    >>> f = x**5 + 2*x**4*y + x**3*y**2

    >>> R.dmp_sqf_list(f)
    (1, [(x + y, 2), (x, 3)])
    >>> R.dmp_sqf_list(f, all=True)
    (1, [(1, 1), (x + y, 2), (x, 3)])

    r\   r   r)   )rl   rQ   re   rS   r   r   r   rR   r   r   r   r    r   r   rg   )r*   r1   r+   r]   r`   rh   rY   r>   r=   ri   rj   rk   s               r,   dmp_sqf_listrp   o  s   $  +Aqc**** 1q!QC0000z aA&&Q1%%'1a00q==q!Q//00 	1a  AFE!Q1 byAAFAq!AAq!Q''GAq!Q1a  Aq!Qa 	MM1a&!!!1a++1a 	"*Q""Q& 	"MM1a&!!!	Q &=r.   c                 
   |st          | ||          S t          | |||          \  }}|r@|d         d         dk    r.t          |d         d         |||          }|dfg|dd         z   S t          ||          }|dfg|z   S )ah  
    Return square-free decomposition of a polynomial in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x,y = ring("x,y", ZZ)

    >>> f = x**5 + 2*x**4*y + x**3*y**2

    >>> R.dmp_sqf_list_include(f)
    [(1, 1), (x + y, 2), (x, 3)]
    >>> R.dmp_sqf_list_include(f, all=True)
    [(1, 1), (x + y, 2), (x, 3)]

    r\   r   r)   N)rn   rp   r   r   )r*   r1   r+   r]   r`   ra   r=   s          r,   dmp_sqf_list_includerr     s    $  3#Aqc2222!!Qs333NE7 "71:a=A% "71:a=%A66Ax'!""+%%ua  Ax'!!r.   c           
         | st          d          t          | |          } t          |           sg S t          | t	          | |j        |          |          }t          ||          }t          |          D ]<\  }\  }}t          |t	          | ||           |          |          }||dz   f||<   =t          | ||          } t          |           s|S | dfg|z   S )z
    Compute greatest factorial factorization of ``f`` in ``K[x]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x = ring("x", ZZ)

    >>> R.dup_gff_list(x**5 + 2*x**4 - x**3 - 2*x**2)
    [(x, 1), (x + 2, 4)]

    zDgreatest factorial factorization doesn't exist for a zero polynomialr)   )

ValueErrorr   r   r!   r   rC   dup_gff_listr^   r   r   )r*   r+   r=   HrY   r>   rb   s          r,   ru   ru     s      a_```!QAa==  	AyAE1--q11A"1 	 	IAv19Q1q11155Aq1u:AaDDAq!!}} 	 HF8a<r.   c                 D    |st          | |          S t          |           )z
    Compute greatest factorial factorization of ``f`` in ``K[X]``.

    Examples
    ========

    >>> from sympy.polys import ring, ZZ
    >>> R, x,y = ring("x,y", ZZ)

    )ru   r&   r0   s      r,   dmp_gff_listrx     s*      -Aq!!!)!,,,r.   N)F)=__doc__sympy.polys.densearithr   r   r   r   r   r   r	   r
   r   sympy.polys.densebasicr   r   r   r   r   r   r   r   r   r   sympy.polys.densetoolsr   r   r   r   r   r   r   r   r   sympy.polys.euclidtoolsr   r    r!   r"   r#   sympy.polys.galoistoolsr$   r%   sympy.polys.polyerrorsr&   r'   r-   r2   rA   rE   rG   rI   rN   rV   rZ   rc   re   rl   rn   rp   rr   ru   rx    r.   r,   <module>r      s0   > >$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $                       ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) ) )
                           @ @ @,I I I,) ) )X/ / /d
- 
- 
-$ $ $M M M
( ( (@"2 "2 "2J	, 	, 	, 	,M M M M
6 6 6 6r" " " "89 9 9 9x" " " ">"  "  " J- - - - -r.   