o
    oho                    @  s  U d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZmZ ddlmZmZmZ dd	l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!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZPmQZQmRZR ddlSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZb ddlcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZm ddlnmoZompZpmqZqmrZrmsZsmtZtmuZu ddlvmwZwmxZxmyZymzZz ddl{m|Z|m}Z}m~Z~mZmZmZmZmZmZmZmZ ddlmZmZ ded< edkrGddlZeefZndZdZG dd de
ZG dd deZG dd deZdd ZG dd  d ee
Zd!d" ZG d#d$ d$e
ZdS )%z1OO layer for several polynomial representations.     )annotations)GROUND_TYPES)sympy_deprecation_warning)oo)CantSympify)PicklableWithSlots_sort_factors)DomainZZQQ)CoercionFailedExactQuotientFailedDomainErrorNotInvertible)!ninfdmp_validate
dup_normal
dmp_normaldup_convertdmp_convertdmp_from_sympy	dup_stripdmp_degree_indmp_degree_listdmp_negative_pdmp_ground_LCdmp_ground_TCdmp_ground_nthdmp_one
dmp_grounddmp_zero
dmp_zero_p	dmp_one_pdmp_ground_pdup_from_dictdmp_from_dictdmp_to_dictdmp_deflate
dmp_inject	dmp_ejectdmp_terms_gcddmp_list_termsdmp_exclude	dup_slicedmp_slice_indmp_permutedmp_to_tuple)dmp_add_grounddmp_sub_grounddmp_mul_grounddmp_quo_grounddmp_exquo_grounddmp_absdmp_negdmp_adddmp_subdmp_muldmp_sqrdmp_powdmp_pdivdmp_premdmp_pquo
dmp_pexquodmp_divdmp_remdmp_quo	dmp_exquodmp_add_muldmp_sub_muldmp_max_normdmp_l1_normdmp_l2_norm_squared)dmp_clear_denomsdmp_integrate_indmp_diff_indmp_eval_in
dup_revertdmp_ground_truncdmp_ground_contentdmp_ground_primitivedmp_ground_monicdmp_composedup_decompose	dup_shift	dmp_shiftdup_transformdmp_lift)
dup_half_gcdex	dup_gcdex
dup_invertdmp_subresultantsdmp_resultantdmp_discriminantdmp_inner_gcddmp_gcddmp_lcm
dmp_cancel)dup_gff_listdmp_norm	dmp_sqf_pdmp_sqf_normdmp_sqf_partdmp_sqf_listdmp_sqf_list_include)dup_cyclotomic_pdmp_irreducible_pdmp_factor_listdmp_factor_list_include)dup_isolate_real_roots_sqfdup_isolate_real_rootsdup_isolate_all_roots_sqfdup_isolate_all_rootsdup_refine_real_rootdup_count_real_rootsdup_count_complex_roots	dup_sturmdup_cauchy_upper_bounddup_cauchy_lower_bounddup_mignotte_sep_bound_squared)UnificationFailedPolynomialErrorztuple[Domain, ...]_flint_domainsflintN c                   @  s^  e Zd ZdZdZdddZedd Zedd	 Z	d
d Z
edd Zedd Zedd Zedd Zedd Zdd Zdd Zedd Zedd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zdd+d,Zdd-d.Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!dd<d=Z"d>d? Z#d@dA Z$ddBdCZ%ddDdEZ&ddFdGZ'ddHdIZ(dJdK Z)dLdM Z*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.ddVdWZ/ddXdYZ0dZd[ Z1d\d] Z2d^d_ Z3d`da Z4dbdc Z5ddde Z6dfdg Z7dhdi Z8djdk Z9dldm Z:dndo Z;dpdq Z<drds Z=dtdu Z>dvdw Z?dxdy Z@dzd{ ZAd|d} ZBd~d ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dddZ\dd Z]dd Z^dd Z_dd Z`dd Zadd Zbdd Zcdd ZdddÄ Zeddń ZfddǄ ZgddɄ Zhdd˄ Ziddd΄ZjddЄ Zkddd҄ZlddԄ ZmdddքZndd؄ Zoddڄ Zpdd܄ Zqddބ Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd ZzdddZ{dddZ|dd Z}dd Z~dd Zdd Zdd Zdd Zdd  ZdddZdd Zdd Zdd	 Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zdd>d?Zdd@dAZdBdC ZdDdE ZddFdGZdHdI ZdJdK ZdLdM ZdNdO ZddPdQZdRdS ZddTdUZddVdWZedXdY ZedZd[ Zed\d] Zed^d_ Zed`da Zedbdc Zeddde Zedfdg Zedhdi Zedjdk Zedldm Zedndo Zdpdq Zdrds Zdtdu Zdvdw Zdxdy Zdzd{ Zd|d} Zd~d Zdd ZÐdd ZĐdd ZŐdd ZƐdd Zǐdd ZȐdd Zɐdd ZʐdddZːdddZ̐dd Z͐dd Zΐdd Zϐdd ZАdd ZdS (  DMP)Dense Multivariate Polynomials over `K`. r}   Nc                 C  s>   |d u rt |\}}nt|tstdt| | |||S )Nzexpected list, got %s)r   
isinstancelistr   typenewclsrepdomlevr}   r}   k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/polys/polyclasses.py__new__   s
   
zDMP.__new__c                 C  s4   t d ur|dkr|tv rt|||S t|||S Nr   )r|   r{   	DUP_Flint_new
DMP_Pythonr   r}   r}   r   r      s   zDMP.newc                 C  s   t dddd |  S )z!Get the representation of ``f``. ay  
        Accessing the ``DMP.rep`` attribute is deprecated. The internal
        representation of ``DMP`` instances can now be ``DUP_Flint`` when the
        ground types are ``flint``. In this case the ``DMP`` instance does not
        have a ``rep`` attribute. Use ``DMP.to_list()`` instead. Using
        ``DMP.to_list()`` also works in previous versions of SymPy.
        z1.13zdmp-rep)deprecated_since_versionactive_deprecations_target)r   to_listfr}   r}   r   r      s
   zDMP.repc                 C  s>   t durt| tr| jdkr| jtv rt| j| j| jS | S )zConvert to DUP_Flint if possible.

        This method should be used when the domain or level is changed and it
        potentially becomes possible to convert from DMP_Python to DUP_Flint.
        Nr   )	r|   r   r   r   r   r{   r   r   _repr   r}   r}   r   to_best   s   zDMP.to_bestc                   s@   t  tsJ t |tr|dksJ  fdd|| d S )Nr   c                   sP   t | tsJ |dkrt fdd| D sJ d S | D ]	}||d  qd S )Nr   c                 3  s    | ]}  |V  qd S N)of_type.0cr   r}   r   	<genexpr>       z;DMP._validate_args.<locals>.validate_rep.<locals>.<genexpr>   )r   r   all)r   r   rr   validate_repr}   r   r      s   z(DMP._validate_args.<locals>.validate_rep)r   r	   intr   r}   r   r   _validate_args   s   zDMP._validate_argsc                 C  s   t |||}| |||S r   )r%   r   r   r   r   r   r}   r}   r   	from_dict   s   zDMP.from_dictc                 C  s   |  t||d|||S )zCCreate an instance of ``cls`` given a list of native coefficients. N)r   r   r   r}   r}   r   	from_list   s   zDMP.from_listc                 C  s   |  t|||||S )zBCreate an instance of ``cls`` given a list of SymPy coefficients. )r   r   r   r}   r}   r   from_sympy_list   s   zDMP.from_sympy_listc                 C  s   | t tt||||S r   )dictr   zip)r   monomscoeffsr   r   r}   r}   r   from_monoms_coeffs      zDMP.from_monoms_coeffsc                 C  s   | j |kr| S | jstdu r| |S t| tr(|tv r!| |S |  |S t| tr=|tv r8| |	 S | |S t
d)z0Convert ``f`` to a ``DMP`` over the new domain. Nzunreachable code)r   r   r|   _convertr   r   r{   to_DMP_Pythonr   to_DUP_FlintRuntimeErrorr   r   r}   r}   r   convert   s   





zDMP.convertc                 C     t r   NotImplementedErrorr   r}   r}   r   r         zDMP._convertc                 C  s   t t|||S r   )r~   r    r   r   r   r}   r}   r   zero      zDMP.zeroc                 C  s   t t||||S r   )r~   r   r   r}   r}   r   one      zDMP.onec                 C  r   r   r   r   r}   r}   r   _one  r   zDMP._onec                 C  s   d| j j|  | jf S )Nz
%s(%s, %s))	__class____name__r   r   r   r}   r}   r   __repr__     zDMP.__repr__c                 C  s   t | jj|  | j| jfS r   )hashr   r   to_tupler   r   r   r}   r}   r   __hash__  s   zDMP.__hash__c                 C  s   |   | j| jfS r   )r   r   r   selfr}   r}   r   __getnewargs__
     zDMP.__getnewargs__c                 C  r   z*Construct a new ground instance of ``f``. r   r   coeffr}   r}   r   
ground_new     zDMP.ground_newc                 C  s\   t |tr| j|jkrtd| |f | j|jkr*| j|j}| |} ||}| |fS z7Unify and return ``DMP`` instances of ``f`` and ``g``. Cannot unify %s with %s)r   r~   r   ry   r   unifyr   r   gr   r}   r}   r   	unify_DMP  s   

zDMP.unify_DMPFc                 C  s   t |  | j| j|dS )AConvert ``f`` to a dict representation with native coefficients. r   )r&   r   r   r   )r   r   r}   r}   r   to_dict     zDMP.to_dictc                 C  s2   | j |d}| D ]\}}| j|||< q
|S )@Convert ``f`` to a dict representation with SymPy coefficients. r   )r   itemsr   to_sympy)r   r   r   kvr}   r}   r   to_sympy_dict!  s   zDMP.to_sympy_dictc                   s    fdd   S )@Convert ``f`` to a list representation with SymPy coefficients. c                   s>   g }| D ]}t |tr|| q| j| q|S r   )r   r   appendr   r   )r   outvalr   sympify_nested_listr}   r   r   ,  s   
z.DMP.to_sympy_list.<locals>.sympify_nested_listr   r   r}   r   r   to_sympy_list*  s   	zDMP.to_sympy_listc                 C  r   AConvert ``f`` to a list representation with native coefficients. r   r   r}   r}   r   r   7  r   zDMP.to_listc                 C  r   zx
        Convert ``f`` to a tuple representation with native coefficients.

        This is needed for hashing.
        r   r   r}   r}   r   r   ;  s   zDMP.to_tuplec                 C     |  | j S )zMake the ground domain a ring. )r   r   get_ringr   r}   r}   r   to_ringC  r   zDMP.to_ringc                 C  r   )z Make the ground domain a field. )r   r   	get_fieldr   r}   r}   r   to_fieldG  r   zDMP.to_fieldc                 C  r   )zMake the ground domain exact. )r   r   	get_exactr   r}   r}   r   to_exactK  r   zDMP.to_exactr   c                 C  s$   | j s|s| ||S | |||S z1Take a continuous subsequence of terms of ``f``. )r   _slice
_slice_levr   mnjr}   r}   r   sliceO  s   
z	DMP.slicec                 C  r   r   r   )r   r   r   r}   r}   r   r   V  r   z
DMP._slicec                 C  r   r   r   r   r}   r}   r   r   Y  r   zDMP._slice_levc                 C     dd | j |dD S )z;Returns all non-zero coefficients from ``f`` in lex order. c                 S  s   g | ]\}}|qS r}   r}   )r   _r   r}   r}   r   
<listcomp>^      zDMP.coeffs.<locals>.<listcomp>ordertermsr   r   r}   r}   r   r   \     z
DMP.coeffsc                 C  r   )z8Returns all non-zero monomials from ``f`` in lex order. c                 S  s   g | ]\}}|qS r}   r}   )r   r   r   r}   r}   r   r   b  r   zDMP.monoms.<locals>.<listcomp>r   r   r  r}   r}   r   r   `  r  z
DMP.monomsc                 C  s.   | j rd| jd  }|| jjfgS | j|dS )4Returns all non-zero terms from ``f`` in lex order. r   r   r   )is_zeror   r   r   _terms)r   r   
zero_monomr}   r}   r   r   d  s   z	DMP.termsc                 C  r   r   r   r  r}   r}   r   r  l  r   z
DMP._termsc                 C  s(   | j rtd| s| jjgS t|  S )z%Returns all coefficients from ``f``. &multivariate polynomials not supported)r   rz   r   r   r   r   r   r}   r}   r   
all_coeffso  s
   
zDMP.all_coeffsc                   s>   | j rtd|    dk rdgS  fddt|  D S )z"Returns all monomials from ``f``. r  r   r  c                   s   g | ]	\}} | fqS r}   r}   r   ir   r   r}   r   r     s    z"DMP.all_monoms.<locals>.<listcomp>)r   rz   degree	enumerater   r   r}   r  r   
all_monomsy  s   zDMP.all_monomsc                   sF   | j rtd|    dk rd| jjfgS  fddt|  D S )z Returns all terms from a ``f``. r  r   r  c                   s   g | ]\}} | f|fqS r}   r}   r
  r  r}   r   r         z!DMP.all_terms.<locals>.<listcomp>)r   rz   r  r   r   r  r   r   r}   r  r   	all_terms  s   zDMP.all_termsc                 C     |    S z-Convert algebraic coefficients to rationals. )_liftr   r   r}   r}   r   lift     zDMP.liftc                 C  r   r   r   r   r}   r}   r   r    r   z	DMP._liftc                 C  r   2Reduce degree of `f` by mapping `x_i^m` to `y_i`. r   r   r}   r}   r   deflate  r   zDMP.deflatec                 C  r   ,Inject ground domain generators into ``f``. r   r   frontr}   r}   r   inject  r   z
DMP.injectc                 C  r   2Eject selected generators into the ground domain. r   r   r   r  r}   r}   r   eject  r   z	DMP.ejectc                 C  s   |   \}}|| fS )ap  
        Remove useless generators from ``f``.

        Returns the removed generators and the new excluded ``f``.

        Examples
        ========

        >>> from sympy.polys.polyclasses import DMP
        >>> from sympy.polys.domains import ZZ

        >>> DMP([[[ZZ(1)]], [[ZZ(1)], [ZZ(2)]]], ZZ).exclude()
        ([2], DMP_Python([[1], [1, 2]], ZZ))

        )_excluder   r   JFr}   r}   r   exclude  s   zDMP.excludec                 C  r   r   r   r   r}   r}   r   r#    r   zDMP._excludec                 C  
   |  |S )a  
        Returns a polynomial in `K[x_{P(1)}, ..., x_{P(n)}]`.

        Examples
        ========

        >>> from sympy.polys.polyclasses import DMP
        >>> from sympy.polys.domains import ZZ

        >>> DMP([[[ZZ(2)], [ZZ(1), ZZ(0)]], [[]]], ZZ).permute([1, 0, 2])
        DMP_Python([[[2], []], [[1, 0], []]], ZZ)

        >>> DMP([[[ZZ(2)], [ZZ(1), ZZ(0)]], [[]]], ZZ).permute([1, 2, 0])
        DMP_Python([[[1], []], [[2, 0], []]], ZZ)

        )_permuter   Pr}   r}   r   permute  s   
zDMP.permutec                 C  r   r   r   r*  r}   r}   r   r)    r   zDMP._permutec                 C  r   z/Remove GCD of terms from the polynomial ``f``. r   r   r}   r}   r   	terms_gcd  r   zDMP.terms_gcdc                 C  r   z)Make all coefficients in ``f`` positive. r   r   r}   r}   r   abs  r   zDMP.absc                 C  r   "Negate all coefficients in ``f``. r   r   r}   r}   r   neg  r   zDMP.negc                 C     |  | j|S z.Add an element of the ground domain to ``f``. )_add_groundr   r   r   r   r}   r}   r   
add_ground  r   zDMP.add_groundc                 C  r4  z5Subtract an element of the ground domain from ``f``. )_sub_groundr   r   r7  r}   r}   r   
sub_ground  r   zDMP.sub_groundc                 C  r4  z5Multiply ``f`` by a an element of the ground domain. )_mul_groundr   r   r7  r}   r}   r   
mul_ground  r   zDMP.mul_groundc                 C  r4  z8Quotient of ``f`` by a an element of the ground domain. )_quo_groundr   r   r7  r}   r}   r   
quo_ground  r   zDMP.quo_groundc                 C  r4  z>Exact quotient of ``f`` by a an element of the ground domain. )_exquo_groundr   r   r7  r}   r}   r   exquo_ground  r   zDMP.exquo_groundc                 C     |  |\}}||S z2Add two multivariate polynomials ``f`` and ``g``. )r   _addr   r   r&  Gr}   r}   r   add     
zDMP.addc                 C  rE  z7Subtract two multivariate polynomials ``f`` and ``g``. )r   _subrH  r}   r}   r   sub  rK  zDMP.subc                 C  rE  z7Multiply two multivariate polynomials ``f`` and ``g``. )r   _mulrH  r}   r}   r   mul  rK  zDMP.mulc                 C     |   S (Square a multivariate polynomial ``f``. )_sqrr   r}   r}   r   sqr     zDMP.sqrc                 C  $   t |tstdt| | |S )+Raise ``f`` to a non-negative power ``n``. ``int`` expected, got %s)r   r   	TypeErrorr   _powr   r   r}   r}   r   pow  s   

zDMP.powc                 C  rE  /Polynomial pseudo-division of ``f`` and ``g``. )r   _pdivrH  r}   r}   r   pdiv	  rK  zDMP.pdivc                 C  rE  0Polynomial pseudo-remainder of ``f`` and ``g``. )r   _premrH  r}   r}   r   prem  rK  zDMP.premc                 C  rE  /Polynomial pseudo-quotient of ``f`` and ``g``. )r   _pquorH  r}   r}   r   pquo  rK  zDMP.pquoc                 C  rE  5Polynomial exact pseudo-quotient of ``f`` and ``g``. )r   _pexquorH  r}   r}   r   pexquo  rK  z
DMP.pexquoc                 C  rE  z7Polynomial division with remainder of ``f`` and ``g``. )r   _divrH  r}   r}   r   div  rK  zDMP.divc                 C  rE  z2Computes polynomial remainder of ``f`` and ``g``. )r   _remrH  r}   r}   r   rem"  rK  zDMP.remc                 C  rE  z1Computes polynomial quotient of ``f`` and ``g``. )r   _quorH  r}   r}   r   quo'  rK  zDMP.quoc                 C  rE  z7Computes polynomial exact quotient of ``f`` and ``g``. )r   _exquorH  r}   r}   r   exquo,  rK  z	DMP.exquoc                 C  r   r   r   r7  r}   r}   r   r6  1  r   zDMP._add_groundc                 C  r   r   r   r7  r}   r}   r   r:  4  r   zDMP._sub_groundc                 C  r   r   r   r7  r}   r}   r   r=  7  r   zDMP._mul_groundc                 C  r   r   r   r7  r}   r}   r   r@  :  r   zDMP._quo_groundc                 C  r   r   r   r7  r}   r}   r   rC  =  r   zDMP._exquo_groundc                 C  r   r   r   r   r   r}   r}   r   rG  @  r   zDMP._addc                 C  r   r   r   r{  r}   r}   r   rM  C  r   zDMP._subc                 C  r   r   r   r{  r}   r}   r   rP  F  r   zDMP._mulc                 C  r   r   r   r   r}   r}   r   rU  I  r   zDMP._sqrc                 C  r   r   r   r]  r}   r}   r   r\  L  r   zDMP._powc                 C  r   r   r   r{  r}   r}   r   ra  O  r   z	DMP._pdivc                 C  r   r   r   r{  r}   r}   r   re  R  r   z	DMP._premc                 C  r   r   r   r{  r}   r}   r   ri  U  r   z	DMP._pquoc                 C  r   r   r   r{  r}   r}   r   rm  X  r   zDMP._pexquoc                 C  r   r   r   r{  r}   r}   r   rp  [  r   zDMP._divc                 C  r   r   r   r{  r}   r}   r   rs  ^  r   zDMP._remc                 C  r   r   r   r{  r}   r}   r   rv  a  r   zDMP._quoc                 C  r   r   r   r{  r}   r}   r   ry  d  r   z
DMP._exquoc                 C  rX  )0Returns the leading degree of ``f`` in ``x_j``. rZ  )r   r   r[  r   _degreer   r   r}   r}   r   r  g  s   

z
DMP.degreec                 C  r   r   r   r~  r}   r}   r   r}  n  r   zDMP._degreec                 C  r   z$Returns a list of degrees of ``f``. r   r   r}   r}   r   degree_listq  r   zDMP.degree_listc                 C  r   #Returns the total degree of ``f``. r   r   r}   r}   r   total_degreeu  r   zDMP.total_degreec           	      C  s   |   }i }|t|  d d k}|  D ]7}t|d }||k r'|| }nd}|r7|d ||d |f < qt|d }||  |7  < |d |t|< qt|| jt	| | j
S )z&Return homogeneous polynomial of ``f``r   r   )r  lenr   sumr   tupler~   r   r   r   r   )	r   stdresult
new_symboltermdr  lr}   r}   r   
homogenizey  s   
zDMP.homogenizec                 C  sD   | j rt S |  }t|d }|D ]}t|}||kr dS q|S )z(Returns the homogeneous order of ``f``. r   N)r  r   r   r  )r   r   tdegmonom_tdegr}   r}   r   homogeneous_order  s   zDMP.homogeneous_orderc                 C  r   z*Returns the leading coefficient of ``f``. r   r   r}   r}   r   LC  r   zDMP.LCc                 C  r   +Returns the trailing coefficient of ``f``. r   r   r}   r}   r   TC  r   zDMP.TCc                 G  s$   t dd |D r| |S td)+Returns the ``n``-th coefficient of ``f``. c                 s  s    | ]}t |tV  qd S r   )r   r   )r   r   r}   r}   r   r     r   zDMP.nth.<locals>.<genexpr>za sequence of integers expected)r   _nthr[  r   Nr}   r}   r   nth  s   
zDMP.nthc                 C  r   r   r   r  r}   r}   r   r    r   zDMP._nthc                 C  r   zReturns maximum norm of ``f``. r   r   r}   r}   r   max_norm  r   zDMP.max_normc                 C  r   zReturns l1 norm of ``f``. r   r   r}   r}   r   l1_norm  r   zDMP.l1_normc                 C  r   z!Return squared l2 norm of ``f``. r   r   r}   r}   r   l2_norm_squared  r   zDMP.l2_norm_squaredc                 C  r   z0Clear denominators, but keep the ground domain. r   r   r}   r}   r   clear_denoms  r   zDMP.clear_denomsr   c                 C  @   t |tstdt| t |tstdt| | ||S )EComputes the ``m``-th order indefinite integral of ``f`` in ``x_j``. rZ  )r   r   r[  r   
_integrater   r   r   r}   r}   r   	integrate  
   

zDMP.integratec                 C  r   r   r   r  r}   r}   r   r    r   zDMP._integratec                 C  r  )<Computes the ``m``-th order derivative of ``f`` in ``x_j``. rZ  )r   r   r[  r   _diffr  r}   r}   r   diff  r  zDMP.diffc                 C  r   r   r   r  r}   r}   r   r    r   z	DMP._diffc                 C  sZ   t |tstdt| d|  kr| jksn td| | jr(| ||S | |S )z5Evaluates ``f`` at the given point ``a`` in ``x_j``. rZ  r   zinvalid variable index %s)r   r   r[  r   r   
ValueError	_eval_lev_evalr   ar   r}   r}   r   eval  s   

zDMP.evalc                 C  r   r   r   r   r  r}   r}   r   r    r   z	DMP._evalc                 C  r   r   r   r  r}   r}   r   r    r   zDMP._eval_levc                 C  &   |  |\}}|jrtd||S )2Half extended Euclidean algorithm, if univariate. univariate polynomial expected)r   r   r  _half_gcdexrH  r}   r}   r   
half_gcdex     
zDMP.half_gcdexc                 C  r   r   r   r{  r}   r}   r   r    r   zDMP._half_gcdexc                 C  s6   |  |\}}|jrtd|jjstd||S )-Extended Euclidean algorithm, if univariate. r  zground domain must be a field)r   r   r  r   is_Fieldr   _gcdexrH  r}   r}   r   gcdex  s   
z	DMP.gcdexc                 C  r   r   r   r{  r}   r}   r   r    r   z
DMP._gcdexc                 C  r  )(Invert ``f`` modulo ``g``, if possible. r  )r   r   r  _invertrH  r}   r}   r   invert  r  z
DMP.invertc                 C  r   r   r   r{  r}   r}   r   r    r   zDMP._invertc                 C  s   | j rtd| |S )"Compute ``f**(-1)`` mod ``x**n``. r  )r   r  _revertr]  r}   r}   r   revert  s   
z
DMP.revertc                 C  r   r   r   r]  r}   r}   r   r    r   zDMP._revertc                 C  rE  7Computes subresultant PRS sequence of ``f`` and ``g``. )r   _subresultantsrH  r}   r}   r   subresultants  rK  zDMP.subresultantsc                 C  r   r   r   r{  r}   r}   r   r     r   zDMP._subresultantsc                 C  &   |  |\}}|r||S ||S )/Computes resultant of ``f`` and ``g`` via PRS. )r   _resultant_includePRS
_resultant)r   r   
includePRSr&  rI  r}   r}   r   	resultant#  s   

zDMP.resultantc                 C  r   r   r   )r   r   r  r}   r}   r   r  +  r   zDMP._resultantc                 C  r    Computes discriminant of ``f``. r   r   r}   r}   r   discriminant.  r   zDMP.discriminantc                 C  rE  z4Returns GCD of ``f`` and ``g`` and their cofactors. )r   
_cofactorsrH  r}   r}   r   	cofactors2  rK  zDMP.cofactorsc                 C  r   r   r   r{  r}   r}   r   r  7  r   zDMP._cofactorsc                 C  rE  z+Returns polynomial GCD of ``f`` and ``g``. )r   _gcdrH  r}   r}   r   gcd:  rK  zDMP.gcdc                 C  r   r   r   r{  r}   r}   r   r  ?  r   zDMP._gcdc                 C  rE  +Returns polynomial LCM of ``f`` and ``g``. )r   _lcmrH  r}   r}   r   lcmB  rK  zDMP.lcmc                 C  r   r   r   r{  r}   r}   r   r  G  r   zDMP._lcmTc                 C  r  6Cancel common factors in a rational function ``f/g``. )r   _cancel_include_cancel)r   r   includer&  rI  r}   r}   r   cancelJ  s   

z
DMP.cancelc                 C  r   r   r   r{  r}   r}   r   r  S  r   zDMP._cancelc                 C  r   r   r   r{  r}   r}   r   r  V  r   zDMP._cancel_includec                 C  r4  z&Reduce ``f`` modulo a constant ``p``. )_truncr   r   r   pr}   r}   r   truncY  r   z	DMP.truncc                 C  r   r   r   r  r}   r}   r   r  ]  r   z
DMP._truncc                 C  r   z'Divides all coefficients by ``LC(f)``. r   r   r}   r}   r   monic`  r   z	DMP.monicc                 C  r   z(Returns GCD of polynomial coefficients. r   r   r}   r}   r   contentd  r   zDMP.contentc                 C  r   z/Returns content and a primitive form of ``f``. r   r   r}   r}   r   	primitiveh  r   zDMP.primitivec                 C  rE  z4Computes functional composition of ``f`` and ``g``. )r   _composerH  r}   r}   r   composel  rK  zDMP.composec                 C  r   r   r   r{  r}   r}   r   r  q  r   zDMP._composec                 C     | j rtd|  S ),Computes functional decomposition of ``f``. r  )r   r  
_decomposer   r}   r}   r   	decomposet     zDMP.decomposec                 C  r   r   r   r   r}   r}   r   r  {  r   zDMP._decomposec                 C  s    | j rtd| | j|S )/Efficiently compute Taylor shift ``f(x + a)``. r  )r   r  _shiftr   r   r  r}   r}   r   shift~  s   z	DMP.shiftc                   s    fdd|D }  |S )/Efficiently compute Taylor shift ``f(X + A)``. c                      g | ]} j |qS r}   )r   r   )r   air   r}   r   r         z"DMP.shift_list.<locals>.<listcomp>)_shift_listr  r}   r   r   
shift_list     
zDMP.shift_listc                 C  r   r   r   r  r}   r}   r   r    r   z
DMP._shiftc                 C  sD   | j rtd||\}}| |\}}||\}}|||S )5Evaluate functional transformation ``q**n * f(p/q)``.r  )r   r  r   
_transform)r   r  qr+  Qr&  r}   r}   r   	transform  s   zDMP.transformc                 C  r   r   r   r   r  r  r}   r}   r   r     r   zDMP._transformc                 C  r  )&Computes the Sturm sequence of ``f``. r  )r   r  _sturmr   r}   r}   r   sturm  r  z	DMP.sturmc                 C  r   r   r   r   r}   r}   r   r    r   z
DMP._sturmc                 C  r  )7Computes the Cauchy upper bound on the roots of ``f``. r  )r   r  _cauchy_upper_boundr   r}   r}   r   cauchy_upper_bound  r  zDMP.cauchy_upper_boundc                 C  r   r   r   r   r}   r}   r   r	    r   zDMP._cauchy_upper_boundc                 C  r  )?Computes the Cauchy lower bound on the nonzero roots of ``f``. r  )r   r  _cauchy_lower_boundr   r}   r}   r   cauchy_lower_bound  r  zDMP.cauchy_lower_boundc                 C  r   r   r   r   r}   r}   r   r    r   zDMP._cauchy_lower_boundc                 C  r  )BComputes the squared Mignotte bound on root separations of ``f``. r  )r   r  _mignotte_sep_bound_squaredr   r}   r}   r   mignotte_sep_bound_squared  r  zDMP.mignotte_sep_bound_squaredc                 C  r   r   r   r   r}   r}   r   r    r   zDMP._mignotte_sep_bound_squaredc                 C  r  )4Computes greatest factorial factorization of ``f``. r  )r   r  	_gff_listr   r}   r}   r   gff_list  r  zDMP.gff_listc                 C  r   r   r   r   r}   r}   r   r    r   zDMP._gff_listc                 C  r   zComputes ``Norm(f)``.r   r   r}   r}   r   norm  r   zDMP.normc                 C  r   z$Computes square-free norm of ``f``. r   r   r}   r}   r   sqf_norm  r   zDMP.sqf_normc                 C  r   z$Computes square-free part of ``f``. r   r   r}   r}   r   sqf_part  r   zDMP.sqf_partc                 C  r   0Returns a list of square-free factors of ``f``. r   r   r   r}   r}   r   sqf_list  r   zDMP.sqf_listc                 C  r   r  r   r  r}   r}   r   sqf_list_include  r   zDMP.sqf_list_includec                 C  r   0Returns a list of irreducible factors of ``f``. r   r   r}   r}   r   factor_list  r   zDMP.factor_listc                 C  r   r  r   r   r}   r}   r   factor_list_include  r   zDMP.factor_list_includec                 C  sn   | j rtd|r|r| j||||dS |r!|s!| j||||dS |s.|r.| j||||dS | j||||dS )z0Compute isolating intervals for roots of ``f``. z1Cannot isolate roots of a multivariate polynomialepsinfsupfast)r   rz   _isolate_all_roots_sqf_isolate_all_roots_isolate_real_roots_sqf_isolate_real_roots)r   r   r$  r%  r&  r'  sqfr}   r}   r   	intervals  s   zDMP.intervalsc                 C  r   r   r   r   r$  r%  r&  r'  r}   r}   r   r)    r   zDMP._isolate_all_rootsc                 C  r   r   r   r.  r}   r}   r   r(    r   zDMP._isolate_all_roots_sqfc                 C  r   r   r   r.  r}   r}   r   r+    r   zDMP._isolate_real_rootsc                 C  r   r   r   r.  r}   r}   r   r*     r   zDMP._isolate_real_roots_sqfc                 C  s"   | j rtd| j|||||dS )zu
        Refine an isolating interval to the given precision.

        ``eps`` should be a rational number.

        z1Cannot refine a root of a multivariate polynomialr$  stepsr'  )r   rz   _refine_real_rootr   r  tr$  r0  r'  r}   r}   r   refine_root  s
   zDMP.refine_rootc                 C  r   r   r   r2  r}   r}   r   r1    r   zDMP._refine_real_rootc                 C  r   )<Return the number of real roots of ``f`` in ``[inf, sup]``. r   r   r%  r&  r}   r}   r   count_real_roots  r   zDMP.count_real_rootsc                 C  r   )?Return the number of complex roots of ``f`` in ``[inf, sup]``. r   r6  r}   r}   r   count_complex_roots  r   zDMP.count_complex_rootsc                 C  r   z0Returns ``True`` if ``f`` is a zero polynomial. r   r   r}   r}   r   r       zDMP.is_zeroc                 C  r   z0Returns ``True`` if ``f`` is a unit polynomial. r   r   r}   r}   r   is_one   r;  z
DMP.is_onec                 C  r   >Returns ``True`` if ``f`` is an element of the ground domain. r   r   r}   r}   r   	is_ground%  r;  zDMP.is_groundc                 C  r   z7Returns ``True`` if ``f`` is a square-free polynomial. r   r   r}   r}   r   is_sqf*  r;  z
DMP.is_sqfc                 C  r   z=Returns ``True`` if the leading coefficient of ``f`` is one. r   r   r}   r}   r   is_monic/  r;  zDMP.is_monicc                 C  r   zAReturns ``True`` if the GCD of the coefficients of ``f`` is one. r   r   r}   r}   r   is_primitive4  r;  zDMP.is_primitivec                 C  r   ):Returns ``True`` if ``f`` is linear in all its variables. r   r   r}   r}   r   	is_linear9  r;  zDMP.is_linearc                 C  r   )=Returns ``True`` if ``f`` is quadratic in all its variables. r   r   r}   r}   r   is_quadratic>  r;  zDMP.is_quadraticc                 C  r   8Returns ``True`` if ``f`` is zero or has only one term. r   r   r}   r}   r   is_monomialC  r;  zDMP.is_monomialc                 C  r   7Returns ``True`` if ``f`` is a homogeneous polynomial. r   r   r}   r}   r   is_homogeneousH  r;  zDMP.is_homogeneousc                 C  r   z:Returns ``True`` if ``f`` has no factors over its domain. r   r   r}   r}   r   is_irreducibleM  r;  zDMP.is_irreduciblec                 C  r   6Returns ``True`` if ``f`` is a cyclotomic polynomial. r   r   r}   r}   r   is_cyclotomicR  r;  zDMP.is_cyclotomicc                 C  rR  r   )r0  r   r}   r}   r   __abs__W     zDMP.__abs__c                 C  rR  r   r3  r   r}   r}   r   __neg__Z  rW  zDMP.__neg__c                 C  8   t |tr
| |S z| |W S  ty   t Y S w r   )r   r~   rJ  r8  r   NotImplementedr{  r}   r}   r   __add__]     

zDMP.__add__c                 C  r(  r   r\  r{  r}   r}   r   __radd__f     
zDMP.__radd__c                 C  rZ  r   )r   r~   rN  r;  r   r[  r{  r}   r}   r   __sub__i  r]  zDMP.__sub__c                 C     |   |S r   r^  r{  r}   r}   r   __rsub__r     zDMP.__rsub__c                 C  rZ  r   )r   r~   rQ  r>  r   r[  r{  r}   r}   r   __mul__u  r]  zDMP.__mul__c                 C  r(  r   re  r{  r}   r}   r   __rmul__~  r`  zDMP.__rmul__c                 C  rZ  r   )r   r~   rz  r>  r   r[  r{  r}   r}   r   __truediv__  r]  zDMP.__truediv__c                 C  sB   t |tr
|| S z|  || W S  ty    t Y S w r   )r   r~   rz  r   r>  r   r[  r{  r}   r}   r   __rtruediv__  s   

zDMP.__rtruediv__c                 C  r(  r   r^  r]  r}   r}   r   __pow__  r`  zDMP.__pow__c                 C  r(  r   rq  r{  r}   r}   r   
__divmod__  r`  zDMP.__divmod__c                 C  r(  r   rt  r{  r}   r}   r   __mod__  r`  zDMP.__mod__c                 C  rZ  r   )r   r~   rw  rA  r[  r[  r{  r}   r}   r   __floordiv__  r]  zDMP.__floordiv__c                 C  sL   | |u rdS t |tstS z	| |\}}W n
 ty    Y dS w ||S )NTF)r   r~   r[  r   ry   
_strict_eqrH  r}   r}   r   __eq__  s   

z
DMP.__eq__c                 C  r   r   r   r{  r}   r}   r   rq    r   zDMP._strict_eqc                 C  s   |s| |kS |  |S r   )rq  r   r   strictr}   r}   r   eq  s   
zDMP.eqc                 C  s   | j ||d S )N)rt  )ru  rs  r}   r}   r   ne     zDMP.nec                 C  s   |  |\}}| | k S r   r   r   rH  r}   r}   r   __lt__     z
DMP.__lt__c                 C  s   |  |\}}| | kS r   rx  rH  r}   r}   r   __le__  rz  z
DMP.__le__c                 C  s   |  |\}}| | kS r   rx  rH  r}   r}   r   __gt__  rz  z
DMP.__gt__c                 C  s   |  |\}}| | kS r   rx  rH  r}   r}   r   __ge__  rz  z
DMP.__ge__c                 C     | j  S r   )r  r   r}   r}   r   __bool__  rW  zDMP.__bool__r   Fr  r   r   T)FNNNFF)NNFNN)r   
__module____qualname____doc__	__slots__r   classmethodr   propertyr   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.  r0  r3  r8  r;  r>  rA  rD  rJ  rN  rQ  rV  r^  rb  rf  rj  rn  rq  rt  rw  rz  r6  r:  r=  r@  rC  rG  rM  rP  rU  r\  ra  re  ri  rm  rp  rs  rv  ry  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  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*  r4  r1  r7  r9  r  r=  r@  rB  rD  rF  rH  rJ  rM  rP  rR  rU  rV  rY  r\  r_  ra  rc  re  rg  rh  ri  rk  rm  ro  rp  rr  rq  ru  rv  ry  r{  r|  r}  r  r}   r}   r}   r   r~      s   	








	


		
							r~   c                   @  s  e Zd ZdZdZedd Zdd Zdd Zd	d
 Z	dd Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdddZdd Zd d! Zdd#d$Zdd%d&Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"d?d@ Z#dAdB Z$dCdD Z%dEdF Z&dGdH Z'dIdJ Z(dKdL Z)dMdN Z*dOdP Z+dQdR Z,dSdT Z-ddVdWZ.dXdY Z/dZd[ Z0d\d] Z1d^d_ Z2d`da Z3dbdc Z4ddde Z5dfdg Z6dhdi Z7ddkdlZ8ddmdnZ9dodp Z:dqdr Z;dsdt Z<dudv Z=dwdx Z>dydz Z?d{d| Z@d}d~ ZAdd ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdddZZdddZ[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd ZbdddZcdddĄZdeeddƄ ZfeeddȄ Zgeeddʄ Zheedd̄ Zieedd΄ ZjeeddЄ Zkeedd҄ ZleeddԄ Zmeeddք Zneedd؄ Zoeeddڄ Zpeedd܄ ZqdS )r   r   )r   r   r   c                 C  s    t | }||_||_||_|S r   )objectr   r   r   r   )r   r   r   r   objr}   r}   r   r     s
   
zDMP_Python._newc                 C  s8   t | t |kr
dS | j|jko| j|jko| j|jkS NF)r   r   r   r   r{  r}   r}   r   rq    s   $zDMP_Python._strict_eqc                 C     |  || j| jS ).Create a DMP out of the given representation. )r   r   r   r   r   r}   r}   r   per  r   zDMP_Python.perc                 C  s   |  t|| j| j| jS r   )r   r   r   r   r   r}   r}   r   r     r   zDMP_Python.ground_newc                 C     |  | j| jS r   )r   r   r   r   r}   r}   r   r     rw  zDMP_Python._onec                   s   t |trj|jkrtd|f j|jkr%jjjj|jfS jj|j tjj }t|j|j } fdd} |||fS )z7Unify representations of two multivariate polynomials. r   c                   s    |  S r   )r   r   r   r   r   r}   r   r       zDMP_Python.unify.<locals>.per)	r   r~   r   ry   r   r  r   r   r   r   r   r&  rI  r  r}   r  r   r     s   zDMP_Python.unifyc                 C  s   t | j| j| jS )z)Convert ``f`` to a Flint representation. )r   r   r   r   r   r   r}   r}   r   r        zDMP_Python.to_DUP_Flintc                 C  
   t | jS r   )r   r   r   r}   r}   r   r        
zDMP_Python.to_listc                 C     t | j| jS zBConvert ``f`` to a tuple representation with native coefficients. )r0   r   r   r   r}   r}   r   r   
     zDMP_Python.to_tuplec                 C  s    |  t| j| j| j||| jS )$Convert the ground domain of ``f``. )r   r   r   r   r   r   r}   r}   r   r         zDMP_Python._convertc                 C  s$   t | j||| j}| || j| jS r   )r-   r   r   r   r   )r   r   r   r   r}   r}   r   r        zDMP_Python._slicec                 C  s*   t | j|||| j| j}| || j| jS r   )r.   r   r   r   r   )r   r   r   r   r   r}   r}   r   r     s   zDMP_Python._slice_levNc                 C  s   t | j| j| j|dS )r  r   )r+   r   r   r   r  r}   r}   r   r    r  zDMP_Python._termsc                 C  &   t | j| j| j}| || jj| jS r  )rX   r   r   r   r   r   r   r}   r}   r   r        zDMP_Python._liftc                 C  $   t | j| j| j\}}|| |fS r  )r'   r   r   r   r  r$  r}   r}   r   r  %     zDMP_Python.deflateFc                 C  s,   t | j| j| j|d\}}| || jj|S )r  r  )r(   r   r   r   r   )r   r  r&  r   r}   r}   r   r  *  s   zDMP_Python.injectc                 C  s.   t | j| j||d}| ||| jt|j S )r   r  )r)   r   r   r   r  symbols)r   r   r  r&  r}   r}   r   r"  0  s   zDMP_Python.ejectc                 C  s,   t | j| j| j\}}}|| || j|fS z&Remove useless generators from ``f``. )r,   r   r   r   r   )r   r%  r&  ur}   r}   r   r#  6  s   zDMP_Python._excludec                 C     |  t| j|| j| jS z6Returns a polynomial in `K[x_{P(1)}, ..., x_{P(n)}]`. )r  r/   r   r   r   r*  r}   r}   r   r)  <  r   zDMP_Python._permutec                 C  r  r-  )r*   r   r   r   r  r$  r}   r}   r   r.  @  r  zDMP_Python.terms_gcdc                 C  r  r5  )r  r1   r   r   r   r7  r}   r}   r   r6  E  r   zDMP_Python._add_groundc                 C  r  r9  )r  r2   r   r   r   r7  r}   r}   r   r:  I  r   zDMP_Python._sub_groundc                 C  r  r<  )r  r3   r   r   r   r7  r}   r}   r   r=  M  r   zDMP_Python._mul_groundc                 C  r  r?  )r  r4   r   r   r   r7  r}   r}   r   r@  Q  r   zDMP_Python._quo_groundc                 C  r  rB  )r  r5   r   r   r   r7  r}   r}   r   rC  U  r   zDMP_Python._exquo_groundc                 C     |  t| j| j| jS r/  )r  r6   r   r   r   r   r}   r}   r   r0  Y  r   zDMP_Python.absc                 C  r  r1  )r  r7   r   r   r   r   r}   r}   r   r3  ]  r   zDMP_Python.negc                 C     |  t| j|j| j| jS rF  )r  r8   r   r   r   r{  r}   r}   r   rG  a     zDMP_Python._addc                 C  r  rL  )r  r9   r   r   r   r{  r}   r}   r   rM  e  r  zDMP_Python._subc                 C  r  rO  )r  r:   r   r   r   r{  r}   r}   r   rP  i  r  zDMP_Python._mulc                 C  r  rS  )r  r;   r   r   r   r   r}   r}   r   rV  m  r   zDMP_Python.sqrc                 C  r  rY  )r  r<   r   r   r   r]  r}   r}   r   r\  q  r   zDMP_Python._powc                 C  .   t | j|j| j| j\}}| || |fS r_  )r=   r   r   r   r  r   r   r  r   r}   r}   r   ra  u     zDMP_Python._pdivc                 C  r  rc  )r  r>   r   r   r   r{  r}   r}   r   re  z  r  zDMP_Python._premc                 C  r  rg  )r  r?   r   r   r   r{  r}   r}   r   ri  ~  r  zDMP_Python._pquoc                 C  r  rk  )r  r@   r   r   r   r{  r}   r}   r   rm    r  zDMP_Python._pexquoc                 C  r  ro  )rA   r   r   r   r  r  r}   r}   r   rp    r  zDMP_Python._divc                 C  r  rr  )r  rB   r   r   r   r{  r}   r}   r   rs    r  zDMP_Python._remc                 C  r  ru  )r  rC   r   r   r   r{  r}   r}   r   rv    r  zDMP_Python._quoc                 C  r  rx  )r  rD   r   r   r   r{  r}   r}   r   ry    r  zDMP_Python._exquor   c                 C  s   t | j|| jS )r|  )r   r   r   r~  r}   r}   r   r}    r   zDMP_Python._degreec                 C  r  r  )r   r   r   r   r}   r}   r   r    r  zDMP_Python.degree_listc                 C  s   t dd |  D S )r  c                 s  s    | ]}t |V  qd S r   r  )r   r   r}   r}   r   r     s    z*DMP_Python.total_degree.<locals>.<genexpr>)maxr   r   r}   r}   r   r    r  zDMP_Python.total_degreec                 C     t | j| j| jS r  )r   r   r   r   r   r}   r}   r   r    r   zDMP_Python.LCc                 C  r  r  )r   r   r   r   r   r}   r}   r   r    r   zDMP_Python.TCc                 C  s   t | j|| j| jS r  )r   r   r   r   r  r}   r}   r   r    r  zDMP_Python._nthc                 C  r  r  )rG   r   r   r   r   r}   r}   r   r    r   zDMP_Python.max_normc                 C  r  r  )rH   r   r   r   r   r}   r}   r   r    r   zDMP_Python.l1_normc                 C  r  r  )rI   r   r   r   r   r}   r}   r   r    r   zDMP_Python.l2_norm_squaredc                 C  r  r  )rJ   r   r   r   r  )r   r   r&  r}   r}   r   r    r  zDMP_Python.clear_denomsr   c                 C     |  t| j||| j| jS )r  )r  rK   r   r   r   r  r}   r}   r   r    r  zDMP_Python._integratec                 C  r  )r  )r  rL   r   r   r   r  r}   r}   r   r    r  zDMP_Python._diffc                 C  s   t | j| j|d| j| jS r   )rM   r   r   r   r   r  r}   r}   r   r    s   zDMP_Python._evalc                 C  s4   t | j| j||| j| j}| || j| jd S Nr   )rM   r   r   r   r   r   )r   r  r   r   r}   r}   r   r    s   zDMP_Python._eval_levc                 C  s*   t | j|j| j\}}| || |fS )r  )rY   r   r   r  r   r   r  hr}   r}   r   r    s   zDMP_Python._half_gcdexc                 C  s4   t | j|j| j\}}}| || || |fS )r  )rZ   r   r   r  )r   r   r  r3  r  r}   r}   r   r    s   zDMP_Python._gcdexc                 C  s   t | j|j| j}| |S )r  )r[   r   r   r  )r   r   r  r}   r}   r   r    r  zDMP_Python._invertc                 C     |  t| j|| jS r  )r  rN   r   r   r]  r}   r}   r   r    r  zDMP_Python._revertc                 C  s&   t | j|j| j| j}tt| j|S r  )r\   r   r   r   r   mapr  r   r   Rr}   r}   r   r       zDMP_Python._subresultantsc                 C  sN   t | j|j| j| jdd\}}| jr| || j| jd }|tt| j|fS )r  T)r  r   )r]   r   r   r   r   r   r  r  r   r   resr  r}   r}   r   r    s   z DMP_Python._resultant_includePRSc                 C  s6   t | j|j| j| j}| jr| || j| jd }|S r  )r]   r   r   r   r   )r   r   r  r}   r}   r   r    s   zDMP_Python._resultantc                 C  s2   t | j| j| j}| jr| || j| jd }|S )r  r   )r^   r   r   r   r   )r   r  r}   r}   r   r    s   zDMP_Python.discriminantc                 C  s8   t | j|j| j| j\}}}| || || |fS r  )r_   r   r   r   r  )r   r   r  cffcfgr}   r}   r   r    s   zDMP_Python._cofactorsc                 C  r  r  )r  r`   r   r   r   r{  r}   r}   r   r     r  zDMP_Python._gcdc                 C  r  r  )r  ra   r   r   r   r{  r}   r}   r   r    r  zDMP_Python._lcmc                 C  s:   t | j|j| j| jdd\}}}}||| || |fS )r  Fr  rb   r   r   r   r  r   r   cFcGr&  rI  r}   r}   r   r    s   "zDMP_Python._cancelc                 C  s2   t | j|j| j| jdd\}}| || |fS )r  Tr  r  rH  r}   r}   r   r    s   zDMP_Python._cancel_includec                 C  r  r  )r  rO   r   r   r   r  r}   r}   r   r    r   zDMP_Python._truncc                 C  r  r  )r  rR   r   r   r   r   r}   r}   r   r    r   zDMP_Python.monicc                 C  r  r  )rP   r   r   r   r   r}   r}   r   r    r   zDMP_Python.contentc                 C  r  r  )rQ   r   r   r   r  )r   contr&  r}   r}   r   r    r  zDMP_Python.primitivec                 C  r  r  )r  rS   r   r   r   r{  r}   r}   r   r  #  r  zDMP_Python._composec                 C     t t| jt| j| jS )r  )r   r  r  rT   r   r   r   r}   r}   r   r  '  r   zDMP_Python._decomposec                 C  r  r  )r  rU   r   r   r  r}   r}   r   r  +  r  zDMP_Python._shiftc                 C  r  )r  )r  rV   r   r   r   r  r}   r}   r   r  /  r   zDMP_Python._shift_listc                 C  s   |  t| j|j|j| jS r  )r  rW   r   r   r  r}   r}   r   r   3  r  zDMP_Python._transformc                 C  r  )r  )r   r  r  ru   r   r   r   r}   r}   r   r  7  r   zDMP_Python._sturmc                 C  r  r  )rv   r   r   r   r}   r}   r   r	  ;  r  zDMP_Python._cauchy_upper_boundc                 C  r  r  )rw   r   r   r   r}   r}   r   r  ?  r  zDMP_Python._cauchy_lower_boundc                 C  r  r  )rx   r   r   r   r}   r}   r   r  C  r  z&DMP_Python._mignotte_sep_bound_squaredc                   s    fddt  j jD S )r  c                      g | ]\}}  ||fqS r}   r  r   r   r   r   r}   r   r   I  r  z(DMP_Python._gff_list.<locals>.<listcomp>)rc   r   r   r   r}   r   r   r  G  r  zDMP_Python._gff_listc                 C  r  r  )rd   r   r   r   r   r  r}   r}   r   r  K  r  zDMP_Python.normc                 C  s8   t | j| j| j\}}}|| || || jj| jfS r  )rf   r   r   r   r  r   )r   r  r   r   r}   r}   r   r  P  s    zDMP_Python.sqf_normc                 C  r  r  )r  rg   r   r   r   r   r}   r}   r   r  U  r   zDMP_Python.sqf_partc                   s.   t  j j j|\}}| fdd|D fS )r  c                   r  r}   r  r  r   r}   r   r   \  r  z'DMP_Python.sqf_list.<locals>.<listcomp>)rh   r   r   r   r   r   r   factorsr}   r   r   r  Y  s   zDMP_Python.sqf_listc                   s&   t  j j j|} fdd|D S )r  c                   r  r}   r  r  r   r}   r   r   a  r  z/DMP_Python.sqf_list_include.<locals>.<listcomp>)ri   r   r   r   r   r   r  r}   r   r   r  ^     zDMP_Python.sqf_list_includec                   s,   t  j j j\}}| fdd|D fS )r   c                   r  r}   r  r  r   r}   r   r   f  r  z*DMP_Python.factor_list.<locals>.<listcomp>)rl   r   r   r   )r   r   r  r}   r   r   r!  c  s   zDMP_Python.factor_listc                   s$   t  j j j} fdd|D S )r   c                   r  r}   r  r  r   r}   r   r   k  r  z2DMP_Python.factor_list_include.<locals>.<listcomp>)rm   r   r   r   r   r  r}   r   r   r"  h  r  zDMP_Python.factor_list_includec                 C     t | j| j||||dS Nr#  )ro   r   r   r.  r}   r}   r   r+  m  r   zDMP_Python._isolate_real_rootsc                 C  r  r  )rn   r   r   r.  r}   r}   r   r*  p  r   z"DMP_Python._isolate_real_roots_sqfc                 C  r  r  )rq   r   r   r.  r}   r}   r   r)  s  r   zDMP_Python._isolate_all_rootsc                 C  r  r  )rp   r   r   r.  r}   r}   r   r(  v  r   z!DMP_Python._isolate_all_roots_sqfc              	   C  s   t | j||| j|||dS )Nr/  )rr   r   r   r2  r}   r}   r   r1  y     zDMP_Python._refine_real_rootc                 C     t | j| j||dS r5  r%  r&  )rs   r   r   r6  r}   r}   r   r7  |  r  zDMP_Python.count_real_rootsc                 C  r  r8  r  )rt   r   r   r6  r}   r}   r   r9    r  zDMP_Python.count_complex_rootsc                 C  r  r:  )r!   r   r   r   r}   r}   r   r       zDMP_Python.is_zeroc                 C  r  r<  )r"   r   r   r   r   r}   r}   r   r=       zDMP_Python.is_onec                 C  s   t | jd| jS )r?  N)r#   r   r   r   r}   r}   r   r@       zDMP_Python.is_groundc                 C  r  rA  )re   r   r   r   r   r}   r}   r   rB    r  zDMP_Python.is_sqfc                 C     | j t| j| j| j S rC  )r   r=  r   r   r   r   r}   r}   r   rD       zDMP_Python.is_monicc                 C  r  rE  )r   r=  rP   r   r   r   r}   r}   r   rF    r  zDMP_Python.is_primitivec                 C  $   t dd t| j| j| j D S )rG  c                 s      | ]	}t |d kV  qdS )r   Nr  r   r  r}   r}   r   r         z'DMP_Python.is_linear.<locals>.<genexpr>r   r&   r   r   r   keysr   r}   r}   r   rH       $zDMP_Python.is_linearc                 C  r  )rI  c                 s  r  )   Nr  r  r}   r}   r   r     r  z*DMP_Python.is_quadratic.<locals>.<genexpr>r  r   r}   r}   r   rJ    r  zDMP_Python.is_quadraticc                 C  s   t |  dkS )rL  r   )r  r   r   r}   r}   r   rM    r  zDMP_Python.is_monomialc                 C  s   |   duS )rO  N)r  r   r}   r}   r   rP       zDMP_Python.is_homogeneousc                 C  r  rQ  )rk   r   r   r   r   r}   r}   r   rR    r  zDMP_Python.is_irreduciblec                 C  s   | j s
t| j| jS dS )rT  F)r   rj   r   r   r   r}   r}   r   rU    s   zDMP_Python.is_cyclotomicr   r  r  r  r  )rr   r  r  r  r  r  r   rq  r  r   r   r   r   r   r   r   r   r   r  r  r  r  r"  r#  r)  r.  r6  r:  r=  r@  rC  r0  r3  rG  rM  rP  rV  r\  ra  re  ri  rm  rp  rs  rv  ry  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  r  r!  r"  r+  r*  r)  r(  r1  r7  r9  r  r  r=  r@  rB  rD  rF  rH  rJ  rM  rP  rR  rU  r}   r}   r}   r   r     s    





















r   c                   @  s  e Zd ZdZdZdZdd Zedd Zdd	 Z	ed
d Z
edd Zedd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zd d! Zdd#d$Zd%d& Zd'd( Zdd*d+Zdd,d-Zd.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Z d:d; Z!d<d= Z"d>d? Z#d@dA Z$dBdC Z%dDdE Z&dFdG Z'dHdI Z(dJdK Z)dLdM Z*dNdO Z+dPdQ Z,dRdS Z-dTdU Z.dVdW Z/dXdY Z0dZd[ Z1dd\d]Z2d^d_ Z3d`da Z4dbdc Z5ddde Z6dfdg Z7dhdi Z8djdk Z9dldm Z:dndo Z;ddqdrZ<ddsdtZ=dudv Z>dwdx Z?dydz Z@d{d| ZAd}d~ ZBdd ZCdd ZDdd ZEdd ZFdd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dddZ]dddZ^dd Z_dd Z`dd Zadd Zbdd Zcdd ZdddĄ ZeddƄ ZfdddȄZgdddʄZheidd̄ Zjeidd΄ ZkeiddЄ Zleidd҄ ZmeiddԄ Zneiddք Zoeidd؄ Zpeiddڄ Zqeidd܄ Zreiddބ Zseidd Zteidd Zud"S )r   r   r   )r   r   _clsc                 C  s   | j |  | j| jffS r   )r   r   r   r   r   r}   r}   r   
__reduce__  r   zDUP_Flint.__reduce__c                 C  s$   |  |d d d ||}| ||S N)_flint_polyfrom_repr   r}   r}   r   r     s   zDUP_Flint._newc                 C  s   | j  ddd S )r   Nr  )r   r   r   r}   r}   r   r     r  zDUP_Flint.to_listc                 C  s*   |t v sJ |dksJ | |}||S r   )r{   _get_flint_poly_cls)r   r   r   r   	flint_clsr}   r}   r   r    s   
zDUP_Flint._flint_polyc                 C  s$   |j rtjS |jrtjS td| )N%Domain %s is not supported with flint)is_ZZr|   	fmpz_polyis_QQ	fmpq_polyr   )r   r   r}   r}   r   r    s
   zDUP_Flint._get_flint_poly_clsc                 C  sh   |j rt|tjsJ tj}n|jrt|tjsJ tj}ntd| t| }||_	||_
||_|S )z,Create a DMP from the given representation. r  )r  r   r|   r  r  r  r   r  r   r   r   r  )r   r   r   r  r  r}   r}   r   r    s   
zDUP_Flint.from_repc                 C  s,   t | t |kr
dS | j|jko| j|jkS r  )r   r   r   r{  r}   r}   r   rq    s   zDUP_Flint._strict_eqc                 C  s   |  | |g| jS r   r  r  r   r   r}   r}   r   r      r  zDUP_Flint.ground_newc                 C  s   |  | jjS r   )r   r   r   r   r}   r}   r   r     r  zDUP_Flint._onec                 C  r   )z*Unify representations of two polynomials. )r   r{  r}   r}   r   r     r   zDUP_Flint.unifyc                 C  s   t |  | j| jS )z1Convert ``f`` to a Python native representation. )r   r   r   r   r   r   r}   r}   r   r     r  zDUP_Flint.to_DMP_Pythonc                 C  s   t |  S r  )r  r   r   r}   r}   r   r     r  zDUP_Flint.to_tuplec                 C  s`   |t kr| jtkr| t| j|S |tkr%| jt kr%|  |	 S t
d| j d| )r  zDUP_Flint: Cannot convert z to )r   r   r
   r  r|   r  r   r   r   r   r   r   r}   r}   r   r     s
   zDUP_Flint._convertc                 C  s&   | j  || }| | || jS r   )r   r   r  r  r   )r   r   r   r   r}   r}   r   r     r  zDUP_Flint._slicec                 C  r   r   r   r   r}   r}   r   r   "  r;  zDUP_Flint._slice_levNc                 C  sH   |du s	|j dkrdd t| j D }|ddd S |  j|dS )r  Nlexc                 S  s   g | ]\}}|r|f|fqS r}   r}   )r   r   r   r}   r}   r   r   *  r  z$DUP_Flint._terms.<locals>.<listcomp>r  r   )aliasr  r   r   r   r  )r   r   r   r}   r}   r   r  '  s   zDUP_Flint._termsc                 C  r   r  r   r   r}   r}   r   r  5  r;  zDUP_Flint._liftc                 C  s0   | j rd| fS | j \}}|f| || jfS )r  )r   )r  r   	deflationr  r   )r   r   r   r}   r}   r   r  :  s   zDUP_Flint.deflateFc                 C  r   r  r   r  r}   r}   r   r  G  r;  zDUP_Flint.injectc                 C  r   r  r   r!  r}   r}   r   r"  L  r;  zDUP_Flint.ejectc                 C  r   r  r   r   r}   r}   r   r#  Q  r;  zDUP_Flint._excludec                 C  r   r  r   r*  r}   r}   r   r)  V  r;  zDUP_Flint._permutec                 C  s   |    \}}|| fS r-  )r   r.  r   r$  r}   r}   r   r.  [  s   zDUP_Flint.terms_gcdc                 C  s   |  | j| | jS r5  r  r   r   r7  r}   r}   r   r6  a  r  zDUP_Flint._add_groundc                 C  s   |  | j| | jS r9  r  r7  r}   r}   r   r:  e  r  zDUP_Flint._sub_groundc                 C  s   |  | j| | jS r<  r  r7  r}   r}   r   r=  i  r  zDUP_Flint._mul_groundc                 C  s   |  | j| | jS r?  r  r7  r}   r}   r   r@  m  r  zDUP_Flint._quo_groundc                 C  s,   t | j|\}}|rt| || || jS rB  )divmodr   r   r  r   )r   r   r  r   r}   r}   r   rC  q  s   
zDUP_Flint._exquo_groundc                 C  s   |     S r/  )r   r0  r   r   r}   r}   r   r0  x  r   zDUP_Flint.absc                 C  s   |  | j | jS r1  r  r   r}   r}   r   r3  |  r   zDUP_Flint.negc                 C  s   |  | j|j | jS rF  r  r{  r}   r}   r   rG    r  zDUP_Flint._addc                 C  s   |  | j|j | jS rL  r  r{  r}   r}   r   rM    r  zDUP_Flint._subc                 C  s   |  | j|j | jS rO  r  r{  r}   r}   r   rP    r  zDUP_Flint._mulc                 C  s   |  | jd | jS )rT  r  r  r   r}   r}   r   rV    r  zDUP_Flint.sqrc                 C  s   |  | j| | jS r  r  r]  r}   r}   r   r\    r  zDUP_Flint._powc                 C  sN   |   |   d }t| | | j |j\}}| || j| || jfS )r`  r   )r  r  r  r   r  r   r   r   r  r  r   r}   r}   r   ra    s   zDUP_Flint._pdivc                 C  s:   |   |   d }| | | j |j }| || jS )rd  r   r  r  r   r  r   )r   r   r  r  r}   r}   r   re       zDUP_Flint._premc                 C  s:   |   |   d }| | | j |j }| || jS )rh  r   r   )r   r   r  r   r}   r}   r   ri    r  zDUP_Flint._pquoc                 C  sN   |   |   d }t| | | j |j\}}|r t| || || jS )rl  r   )r  r  r  r   r   r  r   r  r}   r}   r   rm    s
   
zDUP_Flint._pexquoc                 C  s\   | j jrt| j|j\}}| || j | || j fS |  | \}}| | fS ro  )r   r  r  r   r  r   rp  r   r  r}   r}   r   rp    s
   zDUP_Flint._divc                 C  s   |  | j|j | jS rr  r  r{  r}   r}   r   rs    r  zDUP_Flint._remc                 C  s   |  | j|j | jS ru  r  r{  r}   r}   r   rv    r  zDUP_Flint._quoc                 C  s    |  |\}}|rt| ||S rx  )rp  r   r  r}   r}   r   ry    s   
zDUP_Flint._exquoc                 C  s   | j  }|dkrt}|S )r|  r  )r   r  r   )r   r   r  r}   r}   r   r}    s   
zDUP_Flint._degreec                 C  s
   |   fS r  r}  r   r}   r}   r   r    r  zDUP_Flint.degree_listc                 C  rR  r  r  r   r}   r}   r   r    rW  zDUP_Flint.total_degreec                 C  s   | j | j   S r  r   r  r   r}   r}   r   r    r   zDUP_Flint.LCc                 C  s
   | j d S )r  r   r   r   r}   r}   r   r    r  zDUP_Flint.TCc                 C  s   |\}| j | S r  r  )r   r  r   r}   r}   r   r    s   
zDUP_Flint._nthc                 C  r  r  )r   r  r   r}   r}   r   r    r  zDUP_Flint.max_normc                 C  r  r  )r   r  r   r}   r}   r   r    r  zDUP_Flint.l1_normc                 C  r  r  )r   r  r   r}   r}   r   r    r  zDUP_Flint.l2_norm_squaredc                 C  s,   | j  }| | | j  | j}||fS r  )r   denomr  r  numerr   )r   r  r  r}   r}   r   r    s   
zDUP_Flint.clear_denomsr   c                 C  sT   |dksJ | j jr| j}t|D ]}| }q| || j S |  j||d S )r  r   )r   r   )	r   r  r   rangeintegralr  r   r  r   r   r   r   r   r  r}   r}   r   r    s   
zDUP_Flint._integratec                 C  s6   |dksJ | j }t|D ]}| }q| || jS )z1Computes the ``m``-th order derivative of ``f``. r   )r   r  
derivativer  r   r	  r}   r}   r   r     s
   
zDUP_Flint._diffc                 C  s   |   |S r   )r   r  r  r}   r}   r   r    r  zDUP_Flint._evalc                 C  r   r   r   r  r}   r}   r   r    r   zDUP_Flint._eval_levc                 C  s&   |   |  \}}| | fS )z#Half extended Euclidean algorithm. )r   r  r   r  r}   r}   r   r    r  zDUP_Flint._half_gcdexc                 C  s<   | j |j \}}}| || j| || j| || jfS )zExtended Euclidean algorithm. )r   xgcdr  r   )r   r   r  r  r3  r}   r}   r   r    s   (zDUP_Flint._gcdexc                 C  sP   | j jr| j|j\}}}|dkrtd| || j S |  |  S )r  r   zero divisor)	r   r  r   r  r   r  r   r  r   )r   r   r  F_invr   r}   r}   r   r    s   zDUP_Flint._invertc                 C     |   | S r  )r   r  r   r]  r}   r}   r   r  #  r   zDUP_Flint._revertc                 C  s    |   |  }dd |D S )r  c                 S     g | ]}|  qS r}   r   r   r   r}   r}   r   r   *  r   z,DUP_Flint._subresultants.<locals>.<listcomp>)r   r  r  r}   r}   r   r  '  s   zDUP_Flint._subresultantsc                 C  s(   |   |  \}}|dd |D fS )r  c                 S  r  r}   r  r  r}   r}   r   r   /  r   z3DUP_Flint._resultant_includePRS.<locals>.<listcomp>)r   r  r  r}   r}   r   r  ,  s   zDUP_Flint._resultant_includePRSc                 C  s   |   |  S )z'Computes resultant of ``f`` and ``g``. )r   r  r{  r}   r}   r   r  1  r   zDUP_Flint._resultantc                 C  r  r  )r   r  r   r}   r}   r   r  5  r  zDUP_Flint.discriminantc                 C  s    |  |}|| |||fS r  )r  rz  )r   r   r  r}   r}   r   r  9  s   
zDUP_Flint._cofactorsc                 C  s   |  | j|j| jS r  )r  r   r  r   r{  r}   r}   r   r  >  r   zDUP_Flint._gcdc                 C  sX   | r|s|  | jjS | || |}|jjr | }|S | dk r*|	 }|S )r  r   )
r   r   r   rP  ry  r  r  r  r  r3  )r   r   r  r}   r}   r   r  B  s   zDUP_Flint._lcmc           
      C  s  | j |j   krttfv sJ  J | j jr#|  \}}| \}}n| j j| }}|j j|}}||}|| || }}||}||||}}|	 dk }|	 dk }	|ri|	ri|
 |
 }}n|rt| |
 }}n
|	r~| |
 }}||||fS )r  r   )r   r
   r   r  r  r   r  r  rz  r  r3  )
r   r   r  r&  r  rI  cHHf_negg_negr}   r}   r   r  Q  s&   $

zDUP_Flint._cancelc                 C  s&   |  |\}}}}||||fS r  )r  r=  r  r}   r}   r   r  p  r  zDUP_Flint._cancel_includec                 C  r  r  )r   r  r   r  r}   r}   r   r  u  r   zDUP_Flint._truncc                 C  s   |  |  S r  )rC  r  r   r}   r}   r   r  y  r  zDUP_Flint.monicc                 C  r  r  )r   r  r   r}   r}   r   r  }  r  zDUP_Flint.contentc                 C  s   |   }| |}||fS r  )r  rC  )r   r  primr}   r}   r   r    s   
zDUP_Flint.primitivec                 C  s   |  | |j| jS r  r  r{  r}   r}   r   r    r  zDUP_Flint._composec                 C     dd |    D S )r  c                 S  r  r}   r  r  r}   r}   r   r     r   z(DUP_Flint._decompose.<locals>.<listcomp>)r   r  r   r}   r}   r   r    r  zDUP_Flint._decomposec                 C  s&   |  || jjg}| | || jS r  )r  r   r   r  r   )r   r  x_plus_ar}   r}   r   r    r  zDUP_Flint._shiftc                 C  s,   |   |  |  }}}||| S r  )r   r  r   )r   r  r  r&  r+  r  r}   r}   r   r     s   zDUP_Flint._transformc                 C  r  )r  c                 S  r  r}   r  r  r}   r}   r   r     r   z$DUP_Flint._sturm.<locals>.<listcomp>)r   r  r   r}   r}   r   r    r  zDUP_Flint._sturmc                 C  r  r  )r   r	  r   r}   r}   r   r	    r  zDUP_Flint._cauchy_upper_boundc                 C  r  r  )r   r  r   r}   r}   r   r    r  zDUP_Flint._cauchy_lower_boundc                 C  r  r  )r   r  r   r}   r}   r   r    r  z%DUP_Flint._mignotte_sep_bound_squaredc                 C  s   |   }dd | D S )r  c                 S     g | ]
\}}|  |fqS r}   r  r  r}   r}   r   r         z'DUP_Flint._gff_list.<locals>.<listcomp>)r   r  )r   r&  r}   r}   r   r    s   zDUP_Flint._gff_listc                 C  r   r  r   r   r}   r}   r   r    r;  zDUP_Flint.normc                 C  r   r  r   r   r}   r}   r   r    r;  zDUP_Flint.sqf_normc                 C  s   |  | |  S r  )ry  r  r  r   r}   r}   r   r    r  zDUP_Flint.sqf_partc                 C  s&   |   j|d\}}|dd |D fS )r  r   c                 S  r  r}   r  r  r}   r}   r   r     r  z&DUP_Flint.sqf_list.<locals>.<listcomp>)r   r  r  r}   r}   r   r    r  zDUP_Flint.sqf_listc                 C  s   |   j|d}dd |D S )r  r  c                 S  r  r}   r  r  r}   r}   r   r     r  z.DUP_Flint.sqf_list_include.<locals>.<listcomp>)r   r  r  r}   r}   r   r    s   zDUP_Flint.sqf_list_includec                   s    j jr j \}} fdd|D }n8 j jrF j \}} fdd|D }g }|D ]\}}| \}}|||  }|||f q-ntd j   |}||fS )r   c                   "   g | ]\}}  | j|fqS r}   r  r   r  r   r}   r   r        " z)DUP_Flint.factor_list.<locals>.<listcomp>c                   r  r}   r  r  r   r}   r   r     r  r  )	r   r  r   factorr  r  r   r   r   )r   r   r  factors_monicr   r   r  r}   r   r   r!    s   
zDUP_Flint.factor_listc                 C  s   |    }dd |D S )r   c                 S  r  r}   r  r  r}   r}   r   r     r  z1DUP_Flint.factor_list_include.<locals>.<listcomp>)r   r"  r  r}   r}   r   r"    s   zDUP_Flint.factor_list_includec                   s8   dd |D }t |dd} fddfdd|D S )z+Sort a list of factors to canonical order. c                 S  r  r}   r   r  r}   r}   r   r     r  z+DUP_Flint._sort_factors.<locals>.<listcomp>T)multiplec                   s      | d d d  jS r  r  )r   r   r}   r   <lambda>  r  z)DUP_Flint._sort_factors.<locals>.<lambda>c                   s   g | ]
\}} ||fqS r}   r}   r  )to_dup_flintr}   r   r     r  )r   r  r}   )r   r#  r   r     s   zDUP_Flint._sort_factorsc                 C     |   ||||S r   )r   r+  r.  r}   r}   r   r+       zDUP_Flint._isolate_real_rootsc                 C  r$  r   )r   r*  r.  r}   r}   r   r*    r%  z!DUP_Flint._isolate_real_roots_sqfc                 C  r$  r   )r   r)  r.  r}   r}   r   r)    r%  zDUP_Flint._isolate_all_rootsc                 C  r$  r   )r   r(  r.  r}   r}   r   r(  	  r%  z DUP_Flint._isolate_all_roots_sqfc                 C  s   |   |||||S r   )r   r1  r2  r}   r}   r   r1  	  s   zDUP_Flint._refine_real_rootc                 C     |   j||dS r  )r   r7  r6  r}   r}   r   r7  	  r   zDUP_Flint.count_real_rootsc                 C  r&  r  )r   r9  r6  r}   r}   r   r9  	  r   zDUP_Flint.count_complex_rootsc                 C  r~  r:  r  r   r}   r}   r   r  	     zDUP_Flint.is_zeroc                 C  s   | j | jjkS r<  )r   r   r   r   r}   r}   r   r=  	  r  zDUP_Flint.is_onec                 C     | j  dkS )r?  r   r  r   r}   r}   r   r@  	  r  zDUP_Flint.is_groundc                 C  r(  )rG  r   r  r   r}   r}   r   rH  	  r  zDUP_Flint.is_linearc                 C  r(  )rI  r  r  r   r}   r}   r   rJ  #	  r  zDUP_Flint.is_quadraticc                 C  
   |   jS rK  )r   rM  r   r}   r}   r   rM  (	     
zDUP_Flint.is_monomialc                 C  s   |   | jjkS rC  )r  r   r   r   r}   r}   r   rD  -	  r  zDUP_Flint.is_monicc                 C  r)  rE  )r   rF  r   r}   r}   r   rF  2	  r*  zDUP_Flint.is_primitivec                 C  r)  rN  )r   rP  r   r}   r}   r   rP  7	  r*  zDUP_Flint.is_homogeneousc                 C  r)  rA  )r   rB  r   r}   r}   r   rB  <	  r*  zDUP_Flint.is_sqfc                 C  r)  rQ  )r   rR  r   r}   r}   r   rR  A	  r*  zDUP_Flint.is_irreduciblec                 C  s    | j jrt| j S |  jS rS  )r   r  boolr   rU  r   r   r}   r}   r   rU  F	  s   
zDUP_Flint.is_cyclotomicr   r  r  r  r  )vr   r  r  r  r   r  r  r  r   r   r  r  r  rq  r   r   r   r   r   r   r   r   r  r  r  r  r"  r#  r)  r.  r6  r:  r=  r@  rC  r0  r3  rG  rM  rP  rV  r\  ra  re  ri  rm  rp  rs  rv  ry  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  r!  r"  r   r+  r*  r)  r(  r1  r7  r9  r  r  r=  r@  rH  rJ  rM  rD  rF  rP  rB  rR  rU  r}   r}   r}   r   r     s   



























r   c                 C  s   t t| ||t|||||S r   )DMFr   numdenr   r   r}   r}   r   init_normal_DMFO	  s   r0  c                   @  s  e Zd ZdZdZdZddZedZddZdd	 ZedZd
dZ	dd Z
dd Zdd Zdd Zd[ddZd\ddZedd Zedd Zdd Zd d! Zd"d# Zd$d% Zd&d' Zd(d) Zd*d+ Zd,d- Zd.d/ Zd0d1 ZeZd]d2d3Zed4d5 Zed6d7 Z d8d9 Z!d:d; Z"d<d= Z#d>d? Z$d@dA Z%dBdC Z&dDdE Z'dFdG Z(dHdI Z)dJdK Z*dLdM Z+dNdO Z,dPdQ Z-dRdS Z.dTdU Z/dVdW Z0dXdY Z1dS )^r,  z'Dense Multivariate Fractions over `K`. r-  Nc                 C  sB   |  |||\}}}t||||\}}|| _|| _|| _|| _d S r   )_parserb   r.  r/  r   r   )r   r   r   r   r.  r/  r}   r}   r   __init__Y	  s   
zDMF.__init__c                 C  s:   |  |||\}}}t| }||_||_||_||_|S r   )r1  r  r   r.  r/  r   r   )r   r   r   r   r.  r/  r  r}   r}   r   r   b	  s   
zDMF.newc                 C  r  r   )r   r   r   )r   r   r}   r}   r   r   o	  r   zDMF.ground_newc                 C  s$  t |trb|\}}|d ur$t |trt|||}t |tr#t|||}nt|\}}t|\}}||kr7|}ntdt||rDtdt||rOt||}n>t	|||rat
|||}t
|||}n+|}|d urt |trtt|||}nt |tst|||}nt|\}}t||}|||fS )Nzinconsistent number of levelszfraction denominator)r   r  r   r%   r   r  r!   ZeroDivisionErrorr   r   r7   r   r   r   )r   r   r   r   r.  r/  num_levden_levr}   r}   r   r1  r	  s>   








z
DMF._parsec                 C  s   d| j j| j| j| jf S )Nz%s((%s, %s), %s))r   r   r.  r/  r   r   r}   r}   r   r   	  r  zDMF.__repr__c                 C  s.   t | jjt| j| jt| j| j| j| jfS r   )r   r   r   r0   r.  r   r/  r   r   r}   r}   r   r   	  s   zDMF.__hash__c                   s   t |trj|jkrtd|f j|jkr(jjjjjf|jfS jj	|j} t
j|j t
j|j f}t
|j||j }dd|f fdd	}| |||fS )z0Unify a multivariate fraction and a polynomial. r   TFc                   B   |r|s| | S |d }|rt | || \} }j| |f |S r  rb   r   r   r.  r/  r  killr   r   r   r}   r   r  	     zDMF.poly_unify.<locals>.per)r   r~   r   ry   r   r  r.  r/  r   r   r   r   r   r   r&  rI  r  r}   r:  r   
poly_unify	  s   zDMF.poly_unifyc                   s   t |trj|jkrtd|f j|jkr+jjjjjf|j|jffS jj|j} t	j|j t	j|j f}t	|j||j t	|j||j f}dd|f fdd	}| |||fS )z5Unify representations of two multivariate fractions. r   TFc                   r6  r  r7  r8  r:  r}   r   r  	  r;  zDMF.frac_unify.<locals>.per)
r   r,  r   ry   r   r  r.  r/  r   r   r<  r}   r:  r   
frac_unify	  s   
zDMF.frac_unifyTFc                 C  sP   | j | j}}|r|s|| S |d8 }|rt||||\}}| j||f||S )z.Create a DMF out of the given representation. r   )r   r   rb   r   r   )r   r.  r/  r  r9  r   r   r}   r}   r   r  	  s   zDMF.perc                 C  s(   | j }|r|s	|S |d8 }t|| j|S )r  r   )r   r~   r   )r   r   r9  r   r}   r}   r   half_per	  s   zDMF.half_perc                 C     |  d||S r   r   r   r}   r}   r   r   	  r  zDMF.zeroc                 C  r@  r  rA  r   r}   r}   r   r    
  r  zDMF.onec                 C     |  | jS )z Returns the numerator of ``f``. )r?  r.  r   r}   r}   r   r  
  r  z	DMF.numerc                 C  rB  )z"Returns the denominator of ``f``. )r?  r/  r   r}   r}   r   r  
  r  z	DMF.denomc                 C  r  )z4Remove common factors from ``f.num`` and ``f.den``. )r  r.  r/  r   r}   r}   r   r  
  r   z
DMF.cancelc                 C  s    | j t| j| j| j| jddS )r2  Fr  )r  r7   r.  r   r   r/  r   r}   r}   r   r3  
  r  zDMF.negc                 C  s   | |  | S r5  )r   r7  r}   r}   r   r8  
  r  zDMF.add_groundc                 C     t |tr| |\}}}\}}}t||||||}}	n+| |\}}}}
}|
|\}}\}}tt||||t||||||}t||||}	|||	S )z0Add two multivariate fractions ``f`` and ``g``. )r   r~   r=  rE   r>  r8   r:   r   r   r   r   r  F_numF_denrI  r.  r/  r&  G_numG_denr}   r}   r   rJ  
     

zDMF.addc                 C  rD  )z5Subtract two multivariate fractions ``f`` and ``g``. )r   r~   r=  rF   r>  r9   r:   rE  r}   r}   r   rN  '
  rJ  zDMF.subc                 C  s   t |tr| |\}}}\}}}t|||||}}	n!| |\}}}}
}|
|\}}\}}t||||}t||||}	|||	S )z5Multiply two multivariate fractions ``f`` and ``g``. r   r~   r=  r:   r>  rE  r}   r}   r   rQ  6
     

zDMF.mulc                 C  sn   t |tr/| j| j}}|dk r||| }}}| jt||| j| jt||| j| jddS tdt	| )rY  r   FrC  rZ  )
r   r   r.  r/  r  r<   r   r   r[  r   )r   r   r.  r/  r}   r}   r   r^  D
  s   
zDMF.powc                 C  s   t |tr| |\}}}\}}}|t||||}}	n!| |\}}}}
}|
|\}}\}}t||||}t||||}	|||	S )z0Computes quotient of fractions ``f`` and ``g``. rK  rE  r}   r}   r   rw  O
  rL  zDMF.quoc                 C  s   | j | j| jddS )z&Computes inverse of a fraction ``f``. FrC  )r  r/  r.  )r   checkr}   r}   r   r  _
  r  z
DMF.invertc                 C  r  )z.Returns ``True`` if ``f`` is a zero fraction. r!   r.  r   r   r}   r}   r   r  c
  r  zDMF.is_zeroc                 C  s$   t | j| j| jot | j| j| jS )z.Returns ``True`` if ``f`` is a unit fraction. )r"   r.  r   r   r/  r   r}   r}   r   r=  h
  s   z
DMF.is_onec                 C  rR  r   rX  r   r}   r}   r   rY  n
  rW  zDMF.__neg__c              
   C  sd   t |ttfr| |S || jv r| | j|S z	| | |W S  tt	t
fy1   t Y S w r   )r   r~   r,  rJ  r   r8  r   r?  r[  r   r   r[  r{  r}   r}   r   r\  q
  s   

zDMF.__add__c                 C  r(  r   r^  r{  r}   r}   r   r_  |
  r`  zDMF.__radd__c              
   C  H   t |ttfr| |S z	| | |W S  tttfy#   t Y S w r   )	r   r~   r,  rN  r?  r[  r   r   r[  r{  r}   r}   r   ra  
     
zDMF.__sub__c                 C  rb  r   r^  r{  r}   r}   r   rc  
  rd  zDMF.__rsub__c              
   C  rO  r   )	r   r~   r,  rQ  r?  r[  r   r   r[  r{  r}   r}   r   re  
  rP  zDMF.__mul__c                 C  r(  r   rf  r{  r}   r}   r   rg  
  r`  zDMF.__rmul__c                 C  r(  r   rj  r]  r}   r}   r   rk  
  r`  zDMF.__pow__c              
   C  rO  r   )	r   r~   r,  rw  r?  r[  r   r   r[  r{  r}   r}   r   rh  
  rP  zDMF.__truediv__c                 C  s   | j dd| S )NF)rM  )r  )r   r   r}   r}   r   ri  
  rw  zDMF.__rtruediv__c                 C  s   z?t |tr(| |\}}}\}}}| j|jkr%t|| j| jo#||kW S W dS | |\}}}}}| j|jkr=||kW S W dS  tyI   Y dS w r  r   r~   r=  r   r"   r   r>  ry   r   r   r   rF  rG  rI  r&  r}   r}   r   rr  
  s    


z
DMF.__eq__c                 C  s   z@t |tr)| |\}}}\}}}| j|jkr&t|| j| jo#||k W S W dS | |\}}}}}| j|jkr>||kW S W dS  tyJ   Y dS w )NTrQ  rR  r}   r}   r   __ne__
  s    


z
DMF.__ne__c                 C  s   |  |\}}}}}||k S r   r>  r   r   r   r&  rI  r}   r}   r   ry  
     z
DMF.__lt__c                 C  s   |  |\}}}}}||kS r   rT  rU  r}   r}   r   r{  
  rV  z
DMF.__le__c                 C  s   |  |\}}}}}||kS r   rT  rU  r}   r}   r   r|  
  rV  z
DMF.__gt__c                 C  s   |  |\}}}}}||kS r   rT  rU  r}   r}   r   r}  
  rV  z
DMF.__ge__c                 C  s   t | j| j S r   rN  r   r}   r}   r   r  
  rw  zDMF.__bool__r   )TFr  r  )2r   r  r  r  r  r2  r  r   r   r1  r   r   r=  r>  r  r?  r   r   r  r  r  r3  r8  rJ  rN  rQ  r^  rw  rz  r  r  r  r=  rY  r\  r_  ra  rc  re  rg  rk  rh  ri  rr  rS  ry  r{  r|  r}  r  r}   r}   r}   r   r,  T	  sh    
	+






			r,  c                 C  s   t t| |t|||S r   )ANPr   )r   modr   r}   r}   r   init_normal_ANP
  s   

rY  c                      s  e Zd ZdZdZdd Ze fddZdd Ze	d	d
 Z
e	dd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zedd Zedd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zed-d. Zd/d0 Zd1d2 Zd3d4 Zd5d6 Z d7d8 Z!d9d: Z"d;d< Z#d=d> Z$d?d@ Z%dAdB Z&dCdD Z'dEdF Z(dGdH Z)dIdJ Z*dKdL Z+e	dMdN Z,e	dOdP Z-e	dQdR Z.dSdT Z/dUdV Z0dWdX Z1dYdZ Z2d[d\ Z3d]d^ Z4d_d` Z5dadb Z6dcdd Z7dedf Z8dgdh Z9didj Z:dkdl Z;dmdn Z<dodp Z=dqdr Z>dsdt Z?dudv Z@dwdx ZA  ZBS )yrW  z1Dense Algebraic Number Polynomials over a field. )r   _modr   c                   s   t |trn-t|tu rtt|  d}nt |tr% fdd|D }n |g}tt| d}t |tr9nt |trHtt|  d}ntt| d}| || S )Nr   c                   s   g | ]}  |qS r}   )r   )r   r  r   r}   r   r   
  s    zANP.__new__.<locals>.<listcomp>)	r   r~   r   r   r$   r   r   r   r   r   r   rX  r   r}   r   r   r   
  s   



zANP.__new__c                   sJ   |j |j   kr|kstd tdt | }||_||_||_ |S )NzInconsistent domain)r   r   superr   r   rZ  )r   r   rX  r   r  r   r}   r   r   
  s   zANP.newc                 C  s   t | j| j| jffS r   )rW  r   rX  r   r   r}   r}   r   r    r%  zANP.__reduce__c                 C  
   | j  S r   r   r   r   r}   r}   r   r     r  zANP.repc                 C  rR  r   )mod_to_listr   r}   r}   r   rX    rW  zANP.modc                 C     | j S r   r  r   r}   r}   r   to_DMP     z
ANP.to_DMPc                 C  ra  r   )rZ  r   r}   r}   r   
mod_to_DMP  rc  zANP.mod_to_DMPc                 C  r  r   )r   rZ  r   r  r}   r}   r   r    r   zANP.perc                 C  s"   d| j j| j | j | jf S )Nz%s(%s, %s, %s))r   r   r   r   rZ  r   r   r}   r}   r   r     s   "zANP.__repr__c                 C  s    t | jj|  | j | jfS r   )r   r   r   r   rZ  r   r   r}   r}   r   r     s    zANP.__hash__c                 C  s,   | j |kr| S | | j|| j||S )z.Convert ``f`` to a ``ANP`` over a new domain. )r   r   r   r   rZ  r   r}   r}   r   r   "  s   
zANP.convertc                   s   t |tr| j|jkrtd| |f | j|jkr%| j| j| j|j| jfS | j|j t| j| j }t|j|j } | jkrO |jkrOt| j| j n | jkrX| jn|j fdd} |||fS )z0Unify representations of two algebraic numbers. r   c                   s   t |  S r   rW  r  r   rX  r}   r   r"  B  s    zANP.unify.<locals>.<lambda>)	r   rW  rX  ry   r   r  r   r   r   r  r}   rf  r   r   )  s   
z	ANP.unifyc                 C  sh   t |tr| j|jkrtd| |f | j|jkr*| j|j}| |} ||}| j|j| j| jfS r   )r   rW  rZ  ry   r   r   r   r   r   r}   r}   r   	unify_ANPF  s   

zANP.unify_ANPc                 C     t d||S r   re  r   rX  r   r}   r}   r   r   S  r  zANP.zeroc                 C  rh  r  re  ri  r}   r}   r   r   W  r  zANP.onec                 C  r^  )r   )r   r   r   r}   r}   r   r   [  r  zANP.to_dictc                 C  s6   t | jd| j}| D ]\}}| j|||< q|S )r   r   )r&   r   r   r   r   )r   r   r   r   r}   r}   r   r   _  s   zANP.to_sympy_dictc                 C  r^  r   r_  r   r}   r}   r   r   h  r  zANP.to_listc                 C  r^  )z5Return ``f.mod`` as a list with native coefficients. )rZ  r   r   r}   r}   r   r`  l  r  zANP.mod_to_listc                   s    fdd   D S )r   c                   r  r}   )r   r   r   r   r}   r   r   r  r  z%ANP.to_sympy_list.<locals>.<listcomp>r   r   r}   r   r   r   p  r  zANP.to_sympy_listc                 C  r^  r   )r   r   r   r}   r}   r   r   t  s   
zANP.to_tuplec                 C  s   t ttt|j|||S r   )rW  r   r   r  r   r[  r}   r}   r   r   |  r  zANP.from_listc                 C  r4  r5  )r  r   r8  r7  r}   r}   r   r8    r   zANP.add_groundc                 C  r4  r9  )r  r   r;  r7  r}   r}   r   r;    r   zANP.sub_groundc                 C  r4  )z3Multiply ``f`` by an element of the ground domain. )r  r   r>  r7  r}   r}   r   r>    r   zANP.mul_groundc                 C  r4  )z6Quotient of ``f`` by an element of the ground domain. )r  r   rA  r7  r}   r}   r   rA    r   zANP.quo_groundc                 C  r   r   )r  r   r3  r   r}   r}   r   r3    rw  zANP.negc                 C  &   |  |\}}}}| ||||S r   )rg  r   rJ  r   r   r&  rI  rX  r   r}   r}   r   rJ       zANP.addc                 C  rj  r   )rg  r   rN  rk  r}   r}   r   rN    rl  zANP.subc                 C  s,   |  |\}}}}| |||||S r   )rg  r   rQ  rt  rk  r}   r}   r   rQ    s   zANP.mulc                 C  s^   t |tstdt| | j}| j}|dk r ||| }}| ||	| j|| j
S )rY  rZ  r   )r   r   r[  r   rZ  r   r  r   r^  rt  r   )r   r   rX  r&  r}   r}   r   r^    s   
zANP.powc                 C  s2   |  |\}}}}| ||||||S r   )rg  r   rQ  r  rt  rk  r}   r}   r   rz    s    z	ANP.exquoc                 C  s   |  || | j| jfS r   )rz  r   rZ  r   r{  r}   r}   r   rq    r  zANP.divc                 C  r(  r   )rz  r{  r}   r}   r   rw    r`  zANP.quoc                 C  s:   |  |\}}}}||\}}|jr| ||S td)Nr  )rg  r  r=  r   r   )r   r   r&  rI  rX  r   r  r  r}   r}   r   rt    s
   zANP.remc                 C  r^  r  )r   r  r   r}   r}   r   r    r  zANP.LCc                 C  r^  r  )r   r  r   r}   r}   r   r    r  zANP.TCc                 C     | j jS )z6Returns ``True`` if ``f`` is a zero algebraic number. )r   r  r   r}   r}   r   r    r'  zANP.is_zeroc                 C  rm  )z6Returns ``True`` if ``f`` is a unit algebraic number. )r   r=  r   r}   r}   r   r=    r'  z
ANP.is_onec                 C  rm  r>  )r   r@  r   r}   r}   r   r@    r'  zANP.is_groundc                 C  s   | S r   r}   r   r}   r}   r   __pos__  r   zANP.__pos__c                 C  rR  r   rX  r   r}   r}   r   rY    rW  zANP.__neg__c                 C  F   t |tr
| |S z| j|}W n ty   t Y S w | |S r   )r   rW  rJ  r   r   r   r[  r8  r{  r}   r}   r   r\       


zANP.__add__c                 C  r(  r   r^  r{  r}   r}   r   r_    r`  zANP.__radd__c                 C  ro  r   )r   rW  rN  r   r   r   r[  r;  r{  r}   r}   r   ra    rp  zANP.__sub__c                 C  rb  r   r^  r{  r}   r}   r   rc    rd  zANP.__rsub__c                 C  ro  r   )r   rW  rQ  r   r   r   r[  r>  r{  r}   r}   r   re    rp  zANP.__mul__c                 C  r(  r   rf  r{  r}   r}   r   rg    r`  zANP.__rmul__c                 C  r(  r   rj  r]  r}   r}   r   rk    r`  zANP.__pow__c                 C  r(  r   rl  r{  r}   r}   r   rm    r`  zANP.__divmod__c                 C  r(  r   rn  r{  r}   r}   r   ro  
  r`  zANP.__mod__c                 C  ro  r   )r   rW  rw  r   r   r   r[  rA  r{  r}   r}   r   rh    rp  zANP.__truediv__c                 C  s4   z|  |\}}}}W ||kS  ty   t Y S w r   rg  ry   r[  r   r   r&  rI  r   r}   r}   r   rr       z
ANP.__eq__c                 C  s4   z|  |\}}}}W ||kS  ty   t Y S w r   rq  rr  r}   r}   r   rS    rs  z
ANP.__ne__c                 C  s   |  |\}}}}||k S r   rg  rr  r}   r}   r   ry  %     z
ANP.__lt__c                 C  s   |  |\}}}}||kS r   rt  rr  r}   r}   r   r{  )  ru  z
ANP.__le__c                 C  s   |  |\}}}}||kS r   rt  rr  r}   r}   r   r|  -  ru  z
ANP.__gt__c                 C  s   |  |\}}}}||kS r   rt  rr  r}   r}   r   r}  1  ru  z
ANP.__ge__c                 C  r  r   )r+  r   r   r}   r}   r   r  5  r`  zANP.__bool__)Cr   r  r  r  r  r   r  r   r  r  r   rX  rb  rd  r  r   r   r   r   rg  r   r   r   r   r   r`  r   r   r   r8  r;  r>  rA  r3  rJ  rN  rQ  r^  rz  rq  rw  rt  r  r  r  r=  r@  rn  rY  r\  r_  ra  rc  re  rg  rk  rm  ro  rh  rr  rS  ry  r{  r|  r}  r  __classcell__r}   r}   r]  r   rW  
  s    



	
	






rW  )r  
__future__r   sympy.external.gmpyr   sympy.utilities.exceptionsr   sympy.core.numbersr   sympy.core.sympifyr   sympy.polys.polyutilsr   r   sympy.polys.domainsr	   r
   r   sympy.polys.polyerrorsr   r   r   r   sympy.polys.densebasicr   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/   r0   sympy.polys.densearithr1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   sympy.polys.densetoolsrJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   sympy.polys.euclidtoolsrY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   sympy.polys.sqfreetoolsrc   rd   re   rf   rg   rh   ri   sympy.polys.factortoolsrj   rk   rl   rm   sympy.polys.rootisolationrn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   __annotations__r|   r{   r~   r   r   r0  r,  rY  rW  r}   r}   r}   r   <module>   sb    lD0$
4

        O   v        