a
    RG5d,                     @   s`  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d	 Z,d
d Z-dd Z.dd Z/dd Z0dd Z1dd Z2dd Z3dd Z4d,ddZ5d-ddZ6d.dd Z7d/d!d"Z8d0d#d$Z9d1d%d&Z:d'd( Z;d)d* Z<d+S )2z8Square-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                 C   s&   | sdS t t| t| d|| S 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   N)r   r    r   )fK r*   S/var/www/html/django/DPS/env/lib/python3.9/site-packages/sympy/polys/sqfreetools.py	dup_sqf_p!   s    r,   c                 C   s2   t | |rdS tt| t| d||||| S 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'   N)r   r   r!   r   r(   ur)   r*   r*   r+   	dmp_sqf_p7   s    
r/   c                 C   s   |j stddt|jjdd|j }}t| d|dd\}}t||d|j}t||jr\qxq(t	| |j
 ||d  } }q(|| |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_rr*   r*   r+   dup_sqf_normM   s    r=   c           	      C   s   |st | |S |jstdt|jj|d d|j}t|j|j g|d|}d}t	| ||dd\}}t
|||d |j}t|||jrqqPt| ||||d  } }qP|| |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

    r0   r'   r   Tr1   )r=   r3   r&   r   r4   r5   r6   oner7   r   r"   r/   r   )	r(   r.   r)   r9   Fr8   r:   r;   r<   r*   r*   r+   dmp_sqf_normy   s    
r@   c                 C   sN   |j stdt|jj|d d|j}t| ||dd\}}t|||d |jS )zE
    Norm of ``f`` in ``K[X1, ..., Xn]``, often not square-free.
    r0   r'   r   Tr1   )r3   r&   r   r4   r5   r6   r   r"   )r(   r.   r)   r9   r:   r;   r*   r*   r+   dmp_norm   s
    rA   c                 C   s,   t | ||j} t| |j|j}t ||j|S )z3Compute square-free part of ``f`` in ``GF(p)[x]``. )r   r6   r$   r4   )r(   r)   r9   r*   r*   r+   dup_gf_sqf_part   s    rB   c                 C   s   t ddS )z3Compute square-free part of ``f`` in ``GF(p)[X]``. +multivariate polynomials over finite fieldsNNotImplementedErrorr-   r*   r*   r+   dmp_gf_sqf_part   s    rF   c                 C   st   |j rt| |S | s| S |t| |r2t| |} t| t| d||}t| ||}|jrbt	||S t
||d S 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'   N)is_FiniteFieldrB   is_negativer   r   r    r   r   is_Fieldr   r   )r(   r)   gcdsqfr*   r*   r+   dup_sqf_part   s    


rL   c              	   C   s   |st | |S |jr t| ||S t| |r.| S |t| ||rLt| ||} | }t|d D ]}t|t	| d|||||}q\t
| |||}|jrt|||S t|||d S 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'   N)rL   rG   rF   r   rH   r   r   ranger!   r   r   rI   r   r   )r(   r.   r)   rJ   irK   r*   r*   r+   dmp_sqf_part   s    

rO   Fc                 C   sd   t | ||j} t| |j|j|d\}}t|D ]"\}\} }t | |j||f||< q.|||j|fS )z<Compute square-free decomposition of ``f`` in ``GF(p)[x]``. all)r   r6   r#   r4   	enumerateconvert)r(   r)   rQ   coefffactorsrN   kr*   r*   r+   dup_gf_sqf_list	  s
    rW   c                 C   s   t ddS )z<Compute square-free decomposition of ``f`` in ``GF(p)[X]``. rC   NrD   )r(   r.   r)   rQ   r*   r*   r+   dmp_gf_sqf_list  s    rX   c                 C   s
  |j rt| ||dS |jr0t| |}t| |} n.t| |\}} |t| |r^t| |} | }t| dkrr|g fS g d }}t	| d|}t
| ||\}}}	t	|d|}
t|	|
|}|s|||f qt
|||\}}}	|st|dkr|||f |d7 }q||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)])

    rP   r   r'   )rG   rW   rI   r   r   r   rH   r   r   r   r   r   append)r(   r)   rQ   rT   resultrN   r:   r9   pqdr*   r*   r+   dup_sqf_list  s0    



r^   c                 C   sl   t | ||d\}}|rP|d d dkrPt|d d ||}|dfg|dd  S t|g}|dfg| S d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)]

    rP   r   r'   N)r^   r	   r   )r(   r)   rQ   rT   rU   r9   r*   r*   r+   dup_sqf_list_includeS  s    
r_   c                 C   s@  |st | ||dS |jr(t| |||dS |jrHt| ||}t| ||} n4t| ||\}} |t| ||r|t| ||} | }t	| |dkr|g fS g d }}t
| d||}t| |||\}}	}
t
|	d||}t|
|||}t||r||	|f q8t|	|||\}}	}
|s t	||dkr.|||f |d7 }q||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)])

    rP   r   r'   )r^   rG   rX   rI   r   r   r   rH   r   r   r   r   r   r   rY   )r(   r.   r)   rQ   rT   rZ   rN   r:   r9   r[   r\   r]   r*   r*   r+   dmp_sqf_listo  s4    


r`   c                 C   s   |st | ||dS t| |||d\}}|rf|d d dkrft|d d |||}|dfg|dd  S t||}|dfg| S d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)]

    rP   r   r'   N)r_   r`   r
   r   )r(   r.   r)   rQ   rT   rU   r9   r*   r*   r+   dmp_sqf_list_include  s    
ra   c                 C   s   | st dt| |} t| s"g S t| t| |j||}t||}t|D ]6\}\}}t|t||| ||}||d f||< qJt	| ||} t| s|S | dfg| S d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'   N)

ValueErrorr   r   r    r   r>   dup_gff_listrR   r   r   )r(   r)   r9   HrN   r:   rV   r*   r*   r+   rc     s    

rc   c                 C   s   |st | |S t| dS )z
    Compute greatest factorial factorization of ``f`` in ``K[X]``.

    Examples
    ========

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

    N)rc   r%   r-   r*   r*   r+   dmp_gff_list  s    
re   N)F)F)F)F)F)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,   r/   r=   r@   rA   rB   rF   rL   rO   rW   rX   r^   r_   r`   ra   rc   re   r*   r*   r*   r+   <module>   s.   ,0,,2 %


9

<
%