a
    khy                    @  s  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 edkrddlZdd ZndZdd 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PolynomialErrorflintNc                 C  s   | j p| jp| jo| jS N)is_ZZis_QQis_FFZ	_is_flintD r   E/var/www/auris/lib/python3.9/site-packages/sympy/polys/polyclasses.py_supported_flint_domain   s    r   c                 C  s   dS NFr   r   r   r   r   r      s    c                   @  sx  e Zd ZU dZdZded< ded< 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/d0Zdd1d2Zd3d4 Zd5d6 Zd7d8 Zd9d: Z d;d< Z!d=d> Z"dd@dAZ#dBdC Z$dDdE Z%ddFdGZ&ddHdIZ'ddJdKZ(ddLdMZ)dNdO Z*dPdQ Z+dRdS Z,dTdU Z-dVdW Z.dXdY Z/ddZd[Z0dd\d]Z1d^d_ Z2d`da Z3dbdc Z4ddde Z5dfdg Z6dhdi Z7djdk Z8dldm Z9dndo Z:dpdq Z;drds Z<dtdu Z=dvdw Z>dxdy Z?dzd{ 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 ZYdd ZZdd Z[dd Z\dddZ]dd Z^dd Z_dd Z`dd Zadd Zbdd ZcddÄ Zdddń ZeddǄ ZfddɄ Zgdd˄ Zhdd̈́ Ziddτ Zjddd҄ZkddԄ ZldddքZmdd؄ ZndddڄZodd܄ Zpddބ Zqdd Zrdd Zsdd Ztdd Zudd Zvdd Zwdd Zxdd Zydd Zzdd Z{dddZ|dddZ}dd Z~dd Zdd Zdd Zdd  Zdd Zd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d0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 Zd:d; Zd<d= Zd>d? Zd@dA ZddBdCZddDdEZdFdG ZdHdI ZddJdKZdLdM ZdNdO ZdPdQ ZdRdS ZddTdUZdVdW ZddXdYZd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 Ze	dpdq Ze	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 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   intlevr	   domNc                 C  s>   |d u rt |\}}nt|ts0tdt| | |||S )Nzexpected list, got %s)r   
isinstancelistr   typenewclsrepr   r   r   r   r   __new__   s
    
zDMP.__new__c                 C  s4   t d ur&|dkr&t|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)Zdeprecated_since_versionZ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:t| j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                   sN   t | tsJ |dkr2t fdd| D sJJ n| D ]}||d  q6d S )Nr   c                 3  s   | ]}  |V  qd S r|   )Z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	   r   r   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   s    zDMP.from_monoms_coeffsc                 C  s   | j |kr| S | jstdu r&| |S t| trRt|rB| |S |  |S n4t| tr~t|rr| |	 S | |S nt
ddS )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  s   t d S r|   NotImplementedErrorr   r   r   r   r      s    zDMP._convertc                 C  s   t t|||S r|   )r   r    r   r   r   r   r   r   zero   s    zDMP.zeroc                 C  s   t t||||S r|   )r   r   r   r   r   r   one   s    zDMP.onec                 C  s   t d S r|   r   r   r   r   r   _one  s    zDMP._onec                 C  s   d| j j|  | jf S )Nz
%s(%s, %s))	__class____name__r   r   r   r   r   r   __repr__  s    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__  s    zDMP.__getnewargs__c                 C  s   t dS )*Construct a new ground instance of ``f``. Nr   r   coeffr   r   r   
ground_new  s    zDMP.ground_newc                 C  s\   t |tr| j|jkr&td| |f | j|jkrT| 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   s    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 ]0}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  s   t dS )AConvert ``f`` to a list representation with native coefficients. Nr   r   r   r   r   r   :  s    zDMP.to_listc                 C  s   t dS )x
        Convert ``f`` to a tuple representation with native coefficients.

        This is needed for hashing.
        Nr   r   r   r   r   r   >  s    zDMP.to_tuplec                 C  s   |  | j S )zMake the ground domain a ring. )r   r   Zget_ringr   r   r   r   to_ringF  s    zDMP.to_ringc                 C  s   |  | j S )z Make the ground domain a field. )r   r   	get_fieldr   r   r   r   to_fieldJ  s    zDMP.to_fieldc                 C  s   |  | j S )zMake the ground domain exact. )r   r   Z	get_exactr   r   r   r   to_exactN  s    zDMP.to_exactr   c                 C  s(   | j s|s| ||S | |||S dS 1Take a continuous subsequence of terms of ``f``. N)r   _slice
_slice_levr   mnjr   r   r   sliceR  s    
z	DMP.slicec                 C  s   t d S r|   r   )r   r   r   r   r   r   r   Y  s    z
DMP._slicec                 C  s   t d S r|   r   r   r   r   r   r   \  s    zDMP._slice_levc                 C  s   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>a  r   zDMP.coeffs.<locals>.<listcomp>ordertermsr   r   r   r   r   r   _  s    z
DMP.coeffsc                 C  s   dd | j |dD S )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   e  r   zDMP.monoms.<locals>.<listcomp>r   r   r   r   r   r   r   c  s    z
DMP.monomsc                 C  s2   | j r"d| jd  }|| jjfgS | j|dS dS )4Returns all non-zero terms from ``f`` in lex order. r   r   r   N)is_zeror   r   r   _terms)r   r   Z
zero_monomr   r   r   r   g  s    z	DMP.termsc                 C  s   t d S r|   r   r   r   r   r   r   o  s    z
DMP._termsc                 C  s,   | j rtd| s| jjgS t|  S dS )z%Returns all coefficients from ``f``. &multivariate polynomials not supportedN)r   rz   r   r   r   r   r   r   r   r   
all_coeffsr  s
    
zDMP.all_coeffsc                   sB   | j rtd|    dk r$dgS  fddt|  D S 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     r   z"DMP.all_monoms.<locals>.<listcomp>N)r   rz   degree	enumerater   r   r   r   r   
all_monoms|  s    zDMP.all_monomsc                   sJ   | j rtd|    dk r,d| jjfgS  fddt|  D S 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     r   z!DMP.all_terms.<locals>.<listcomp>N)r   rz   r   r   r   r  r   r   r   r   r   	all_terms  s    zDMP.all_termsc                 C  s   |    S -Convert algebraic coefficients to rationals. )_liftr   r   r   r   r   lift  s    zDMP.liftc                 C  s   t d S r|   r   r   r   r   r   r    s    z	DMP._liftc                 C  s   t dS )2Reduce degree of `f` by mapping `x_i^m` to `y_i`. Nr   r   r   r   r   deflate  s    zDMP.deflatec                 C  s   t dS ,Inject ground domain generators into ``f``. Nr   r   frontr   r   r   inject  s    z
DMP.injectc                 C  s   t dS 2Eject selected generators into the ground domain. Nr   r   r   r  r   r   r   eject  s    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  s   t d S r|   r   r   r   r   r   r    s    zDMP._excludec                 C  s
   |  |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  s   t d S r|   r   r  r   r   r   r    s    zDMP._permutec                 C  s   t dS )/Remove GCD of terms from the polynomial ``f``. Nr   r   r   r   r   	terms_gcd  s    zDMP.terms_gcdc                 C  s   t dS ))Make all coefficients in ``f`` positive. Nr   r   r   r   r   abs  s    zDMP.absc                 C  s   t dS )"Negate all coefficients in ``f``. Nr   r   r   r   r   neg  s    zDMP.negc                 C  s   |  | j|S z.Add an element of the ground domain to ``f``. )_add_groundr   r   r   r   r   r   r   
add_ground  s    zDMP.add_groundc                 C  s   |  | j|S z5Subtract an element of the ground domain from ``f``. )_sub_groundr   r   r$  r   r   r   
sub_ground  s    zDMP.sub_groundc                 C  s   |  | j|S z5Multiply ``f`` by a an element of the ground domain. )_mul_groundr   r   r$  r   r   r   
mul_ground  s    zDMP.mul_groundc                 C  s   |  | j|S z8Quotient of ``f`` by a an element of the ground domain. )_quo_groundr   r   r$  r   r   r   
quo_ground  s    zDMP.quo_groundc                 C  s   |  | j|S z>Exact quotient of ``f`` by a an element of the ground domain. )_exquo_groundr   r   r$  r   r   r   exquo_ground  s    zDMP.exquo_groundc                 C  s   |  |\}}||S z2Add two multivariate polynomials ``f`` and ``g``. )r   _addr   r   r  Gr   r   r   add  s    zDMP.addc                 C  s   |  |\}}||S z7Subtract two multivariate polynomials ``f`` and ``g``. )r   _subr4  r   r   r   sub  s    zDMP.subc                 C  s   |  |\}}||S z7Multiply two multivariate polynomials ``f`` and ``g``. )r   _mulr4  r   r   r   mul  s    zDMP.mulc                 C  s   |   S (Square a multivariate polynomial ``f``. )_sqrr   r   r   r   sqr  s    zDMP.sqrc                 C  s$   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  s   |  |\}}||S /Polynomial pseudo-division of ``f`` and ``g``. )r   _pdivr4  r   r   r   pdiv  s    zDMP.pdivc                 C  s   |  |\}}||S 0Polynomial pseudo-remainder of ``f`` and ``g``. )r   _premr4  r   r   r   prem  s    zDMP.premc                 C  s   |  |\}}||S /Polynomial pseudo-quotient of ``f`` and ``g``. )r   _pquor4  r   r   r   pquo  s    zDMP.pquoc                 C  s   |  |\}}||S 5Polynomial exact pseudo-quotient of ``f`` and ``g``. )r   _pexquor4  r   r   r   pexquo  s    z
DMP.pexquoc                 C  s   |  |\}}||S 7Polynomial division with remainder of ``f`` and ``g``. )r   _divr4  r   r   r   div   s    zDMP.divc                 C  s   |  |\}}||S z2Computes polynomial remainder of ``f`` and ``g``. )r   _remr4  r   r   r   rem%  s    zDMP.remc                 C  s   |  |\}}||S z1Computes polynomial quotient of ``f`` and ``g``. )r   _quor4  r   r   r   quo*  s    zDMP.quoc                 C  s   |  |\}}||S z7Computes polynomial exact quotient of ``f`` and ``g``. )r   _exquor4  r   r   r   exquo/  s    z	DMP.exquoc                 C  s   t d S r|   r   r$  r   r   r   r#  4  s    zDMP._add_groundc                 C  s   t d S r|   r   r$  r   r   r   r'  7  s    zDMP._sub_groundc                 C  s   t d S r|   r   r$  r   r   r   r*  :  s    zDMP._mul_groundc                 C  s   t d S r|   r   r$  r   r   r   r-  =  s    zDMP._quo_groundc                 C  s   t d S r|   r   r$  r   r   r   r0  @  s    zDMP._exquo_groundc                 C  s   t d S r|   r   r   r   r   r   r   r3  C  s    zDMP._addc                 C  s   t d S r|   r   rd  r   r   r   r8  F  s    zDMP._subc                 C  s   t d S r|   r   rd  r   r   r   r;  I  s    zDMP._mulc                 C  s   t d S r|   r   r   r   r   r   r?  L  s    zDMP._sqrc                 C  s   t d S r|   r   rE  r   r   r   rD  O  s    zDMP._powc                 C  s   t d S r|   r   rd  r   r   r   rI  R  s    z	DMP._pdivc                 C  s   t d S r|   r   rd  r   r   r   rM  U  s    z	DMP._premc                 C  s   t d S r|   r   rd  r   r   r   rQ  X  s    z	DMP._pquoc                 C  s   t d S r|   r   rd  r   r   r   rU  [  s    zDMP._pexquoc                 C  s   t d S r|   r   rd  r   r   r   rY  ^  s    zDMP._divc                 C  s   t d S r|   r   rd  r   r   r   r\  a  s    zDMP._remc                 C  s   t d S r|   r   rd  r   r   r   r_  d  s    zDMP._quoc                 C  s   t d S r|   r   rd  r   r   r   rb  g  s    z
DMP._exquoc                 C  s$   t |tstdt| | |S )0Returns the leading degree of ``f`` in ``x_j``. rB  )r   r   rC  r   _degreer   r   r   r   r   r   j  s    
z
DMP.degreec                 C  s   t d S r|   r   rg  r   r   r   rf  q  s    zDMP._degreec                 C  s   t dS )$Returns a list of degrees of ``f``. Nr   r   r   r   r   degree_listt  s    zDMP.degree_listc                 C  s   t dS )#Returns the total degree of ``f``. Nr   r   r   r   r   total_degreex  s    zDMP.total_degreec           	      C  s   |   }i }|t|  d d k}|  D ]n}t|d }||k rN|| }nd}|rn|d ||d |f < q,t|d }||  |7  < |d |t|< q,t|| jt	| | j
S )z&Return homogeneous polynomial of ``f``r   r   )rk  lenr   sumr   tupler   r   r   r   r   )	r   stdresultZ
new_symbolZtermdr   lr   r   r   
homogenize|  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   rm  )r   r   ZtdegmonomZ_tdegr   r   r   homogeneous_order  s    zDMP.homogeneous_orderc                 C  s   t dS )*Returns the leading coefficient of ``f``. Nr   r   r   r   r   LC  s    zDMP.LCc                 C  s   t dS )+Returns the trailing coefficient of ``f``. Nr   r   r   r   r   TC  s    zDMP.TCc                 G  s(   t dd |D r| |S tddS )+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 expectedN)r   _nthrC  r   Nr   r   r   nth  s    
zDMP.nthc                 C  s   t d S r|   r   r~  r   r   r   r}    s    zDMP._nthc                 C  s   t dS )Returns maximum norm of ``f``. Nr   r   r   r   r   max_norm  s    zDMP.max_normc                 C  s   t dS )Returns l1 norm of ``f``. Nr   r   r   r   r   l1_norm  s    zDMP.l1_normc                 C  s   t dS )!Return squared l2 norm of ``f``. Nr   r   r   r   r   l2_norm_squared  s    zDMP.l2_norm_squaredc                 C  s   t dS 0Clear denominators, but keep the ground domain. Nr   r   r   r   r   clear_denoms  s    zDMP.clear_denomsr   c                 C  s@   t |tstdt| t |ts4tdt| | ||S )EComputes the ``m``-th order indefinite integral of ``f`` in ``x_j``. rB  )r   r   rC  r   
_integrater   r   r   r   r   r   	integrate  s
    

zDMP.integratec                 C  s   t d S r|   r   r  r   r   r   r    s    zDMP._integratec                 C  s@   t |tstdt| t |ts4tdt| | ||S )<Computes the ``m``-th order derivative of ``f`` in ``x_j``. rB  )r   r   rC  r   _diffr  r   r   r   diff  s
    

zDMP.diffc                 C  s   t d S r|   r   r  r   r   r   r    s    z	DMP._diffc                 C  s`   t |tstdt| n$d|  kr2| jks@n td| | jrR| ||S | |S dS )z5Evaluates ``f`` at the given point ``a`` in ``x_j``. rB  r   zinvalid variable index %sN)r   r   rC  r   r   
ValueError	_eval_lev_evalr   ar   r   r   r   eval  s    
zDMP.evalc                 C  s   t d S r|   r   r   r  r   r   r   r    s    z	DMP._evalc                 C  s   t d S r|   r   r  r   r   r   r    s    zDMP._eval_levc                 C  s&   |  |\}}|jrtd||S )2Half extended Euclidean algorithm, if univariate. univariate polynomial expected)r   r   r  _half_gcdexr4  r   r   r   
half_gcdex  s    zDMP.half_gcdexc                 C  s   t d S r|   r   rd  r   r   r   r    s    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   _gcdexr4  r   r   r   gcdex  s    z	DMP.gcdexc                 C  s   t d S r|   r   rd  r   r   r   r    s    z
DMP._gcdexc                 C  s&   |  |\}}|jrtd||S )(Invert ``f`` modulo ``g``, if possible. r  )r   r   r  _invertr4  r   r   r   invert  s    z
DMP.invertc                 C  s   t d S r|   r   rd  r   r   r   r    s    zDMP._invertc                 C  s   | j rtd| |S )"Compute ``f**(-1)`` mod ``x**n``. r  )r   r  _revertrE  r   r   r   revert  s    z
DMP.revertc                 C  s   t d S r|   r   rE  r   r   r   r    s    zDMP._revertc                 C  s   |  |\}}||S 7Computes subresultant PRS sequence of ``f`` and ``g``. )r   _subresultantsr4  r   r   r   subresultants  s    zDMP.subresultantsc                 C  s   t d S r|   r   rd  r   r   r   r  #  s    zDMP._subresultantsc                 C  s*   |  |\}}|r||S ||S dS )/Computes resultant of ``f`` and ``g`` via PRS. N)r   _resultant_includePRS
_resultant)r   r   
includePRSr  r5  r   r   r   	resultant&  s    
zDMP.resultantc                 C  s   t d S r|   r   )r   r   r  r   r   r   r  .  s    zDMP._resultantc                 C  s   t dS ) Computes discriminant of ``f``. Nr   r   r   r   r   discriminant1  s    zDMP.discriminantc                 C  s   |  |\}}||S z4Returns GCD of ``f`` and ``g`` and their cofactors. )r   
_cofactorsr4  r   r   r   	cofactors5  s    zDMP.cofactorsc                 C  s   t d S r|   r   rd  r   r   r   r  :  s    zDMP._cofactorsc                 C  s   |  |\}}||S z+Returns polynomial GCD of ``f`` and ``g``. )r   _gcdr4  r   r   r   gcd=  s    zDMP.gcdc                 C  s   t d S r|   r   rd  r   r   r   r  B  s    zDMP._gcdc                 C  s   |  |\}}||S +Returns polynomial LCM of ``f`` and ``g``. )r   _lcmr4  r   r   r   lcmE  s    zDMP.lcmc                 C  s   t d S r|   r   rd  r   r   r   r  J  s    zDMP._lcmTc                 C  s*   |  |\}}|r||S ||S dS )6Cancel common factors in a rational function ``f/g``. N)r   _cancel_include_cancel)r   r   includer  r5  r   r   r   cancelM  s    
z
DMP.cancelc                 C  s   t d S r|   r   rd  r   r   r   r  V  s    zDMP._cancelc                 C  s   t d S r|   r   rd  r   r   r   r  Y  s    zDMP._cancel_includec                 C  s   |  | j|S z&Reduce ``f`` modulo a constant ``p``. )_truncr   r   r   pr   r   r   trunc\  s    z	DMP.truncc                 C  s   t d S r|   r   r  r   r   r   r  `  s    z
DMP._truncc                 C  s   t dS )'Divides all coefficients by ``LC(f)``. Nr   r   r   r   r   monicc  s    z	DMP.monicc                 C  s   t dS )(Returns GCD of polynomial coefficients. Nr   r   r   r   r   contentg  s    zDMP.contentc                 C  s   t dS )/Returns content and a primitive form of ``f``. Nr   r   r   r   r   	primitivek  s    zDMP.primitivec                 C  s   |  |\}}||S z4Computes functional composition of ``f`` and ``g``. )r   _composer4  r   r   r   composeo  s    zDMP.composec                 C  s   t d S r|   r   rd  r   r   r   r  t  s    zDMP._composec                 C  s   | j rtd|  S ),Computes functional decomposition of ``f``. r  )r   r  
_decomposer   r   r   r   	decomposew  s    zDMP.decomposec                 C  s   t d S r|   r   r   r   r   r   r  ~  s    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                   s   g | ]} j |qS r   )r   r   )r   Zair   r   r   r     r   z"DMP.shift_list.<locals>.<listcomp>)_shift_listr  r   r   r   
shift_list  s    zDMP.shift_listc                 C  s   t d S r|   r   r  r   r   r   r    s    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  s   t d S r|   r   r   r  r  r   r   r   r    s    zDMP._transformc                 C  s   | j rtd|  S )&Computes the Sturm sequence of ``f``. r  )r   r  _sturmr   r   r   r   sturm  s    z	DMP.sturmc                 C  s   t d S r|   r   r   r   r   r   r    s    z
DMP._sturmc                 C  s   | j rtd|  S )7Computes the Cauchy upper bound on the roots of ``f``. r  )r   r  _cauchy_upper_boundr   r   r   r   cauchy_upper_bound  s    zDMP.cauchy_upper_boundc                 C  s   t d S r|   r   r   r   r   r   r    s    zDMP._cauchy_upper_boundc                 C  s   | j rtd|  S )?Computes the Cauchy lower bound on the nonzero roots of ``f``. r  )r   r  _cauchy_lower_boundr   r   r   r   cauchy_lower_bound  s    zDMP.cauchy_lower_boundc                 C  s   t d S r|   r   r   r   r   r   r    s    zDMP._cauchy_lower_boundc                 C  s   | j rtd|  S )BComputes the squared Mignotte bound on root separations of ``f``. r  )r   r  _mignotte_sep_bound_squaredr   r   r   r   mignotte_sep_bound_squared  s    zDMP.mignotte_sep_bound_squaredc                 C  s   t d S r|   r   r   r   r   r   r    s    zDMP._mignotte_sep_bound_squaredc                 C  s   | j rtd|  S )4Computes greatest factorial factorization of ``f``. r  )r   r  	_gff_listr   r   r   r   gff_list  s    zDMP.gff_listc                 C  s   t d S r|   r   r   r   r   r   r    s    zDMP._gff_listc                 C  s   t dS Computes ``Norm(f)``.Nr   r   r   r   r   norm  s    zDMP.normc                 C  s   t dS $Computes square-free norm of ``f``. Nr   r   r   r   r   sqf_norm  s    zDMP.sqf_normc                 C  s   t dS )$Computes square-free part of ``f``. Nr   r   r   r   r   sqf_part  s    zDMP.sqf_partc                 C  s   t dS 0Returns a list of square-free factors of ``f``. Nr   r   r   r   r   r   sqf_list  s    zDMP.sqf_listc                 C  s   t dS r  r   r  r   r   r   sqf_list_include  s    zDMP.sqf_list_includec                 C  s   t dS 0Returns a list of irreducible factors of ``f``. Nr   r   r   r   r   factor_list  s    zDMP.factor_listc                 C  s   t dS r  r   r   r   r   r   factor_list_include  s    zDMP.factor_list_includec                 C  sr   | j rtd|r(|r(| j||||dS |rB|sB| j||||dS |s\|r\| j||||dS | j||||dS dS )z0Compute isolating intervals for roots of ``f``. z1Cannot isolate roots of a multivariate polynomialepsinfsupfastN)r   rz   _isolate_all_roots_sqf_isolate_all_roots_isolate_real_roots_sqf_isolate_real_roots)r   r   r  r  r   r  Zsqfr   r   r   	intervals  s    zDMP.intervalsc                 C  s   t d S r|   r   r   r  r  r   r  r   r   r   r    s    zDMP._isolate_all_rootsc                 C  s   t d S r|   r   r  r   r   r   r    s    zDMP._isolate_all_roots_sqfc                 C  s   t d S r|   r   r  r   r   r   r     s    zDMP._isolate_real_rootsc                 C  s   t d S r|   r   r  r   r   r   r    s    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   ro  tr  r	  r  r   r   r   refine_root  s
    zDMP.refine_rootc                 C  s   t d S r|   r   r  r   r   r   r
    s    zDMP._refine_real_rootc                 C  s   t dS )<Return the number of real roots of ``f`` in ``[inf, sup]``. Nr   r   r  r   r   r   r   count_real_roots  s    zDMP.count_real_rootsc                 C  s   t dS )?Return the number of complex roots of ``f`` in ``[inf, sup]``. Nr   r  r   r   r   count_complex_roots  s    zDMP.count_complex_rootsc                 C  s   t dS )0Returns ``True`` if ``f`` is a zero polynomial. Nr   r   r   r   r   r     s    zDMP.is_zeroc                 C  s   t dS )0Returns ``True`` if ``f`` is a unit polynomial. Nr   r   r   r   r   is_one#  s    z
DMP.is_onec                 C  s   t dS >Returns ``True`` if ``f`` is an element of the ground domain. Nr   r   r   r   r   	is_ground(  s    zDMP.is_groundc                 C  s   t dS )7Returns ``True`` if ``f`` is a square-free polynomial. Nr   r   r   r   r   is_sqf-  s    z
DMP.is_sqfc                 C  s   t dS )=Returns ``True`` if the leading coefficient of ``f`` is one. Nr   r   r   r   r   is_monic2  s    zDMP.is_monicc                 C  s   t dS )AReturns ``True`` if the GCD of the coefficients of ``f`` is one. Nr   r   r   r   r   is_primitive7  s    zDMP.is_primitivec                 C  s   t dS ):Returns ``True`` if ``f`` is linear in all its variables. Nr   r   r   r   r   	is_linear<  s    zDMP.is_linearc                 C  s   t dS )=Returns ``True`` if ``f`` is quadratic in all its variables. Nr   r   r   r   r   is_quadraticA  s    zDMP.is_quadraticc                 C  s   t dS )8Returns ``True`` if ``f`` is zero or has only one term. Nr   r   r   r   r   is_monomialF  s    zDMP.is_monomialc                 C  s   t dS 7Returns ``True`` if ``f`` is a homogeneous polynomial. Nr   r   r   r   r   is_homogeneousK  s    zDMP.is_homogeneousc                 C  s   t dS ):Returns ``True`` if ``f`` has no factors over its domain. Nr   r   r   r   r   is_irreducibleP  s    zDMP.is_irreduciblec                 C  s   t dS )6Returns ``True`` if ``f`` is a cyclotomic polynomial. Nr   r   r   r   r   is_cyclotomicU  s    zDMP.is_cyclotomicc                 C  s   |   S r|   )r  r   r   r   r   __abs__Z  s    zDMP.__abs__c                 C  s   |   S r|   r!  r   r   r   r   __neg__]  s    zDMP.__neg__c                 C  s<   t |tr| |S z| |W S  ty6   t Y S 0 d S r|   )r   r   r6  r%  r   NotImplementedrd  r   r   r   __add__`  s    

zDMP.__add__c                 C  s
   |  |S r|   r0  rd  r   r   r   __radd__i  s    zDMP.__radd__c                 C  s<   t |tr| |S z| |W S  ty6   t Y S 0 d S r|   )r   r   r9  r(  r   r/  rd  r   r   r   __sub__l  s    

zDMP.__sub__c                 C  s   |   |S r|   r1  rd  r   r   r   __rsub__u  s    zDMP.__rsub__c                 C  s<   t |tr| |S z| |W S  ty6   t Y S 0 d S r|   )r   r   r<  r+  r   r/  rd  r   r   r   __mul__x  s    

zDMP.__mul__c                 C  s
   |  |S r|   r5  rd  r   r   r   __rmul__  s    zDMP.__rmul__c                 C  s<   t |tr| |S z| |W S  ty6   t Y S 0 d S r|   )r   r   rc  r+  r   r/  rd  r   r   r   __truediv__  s    

zDMP.__truediv__c                 C  sF   t |tr|| S z|  || W S  ty@   t Y S 0 d S r|   )r   r   rc  r   r+  r   r/  rd  r   r   r   __rtruediv__  s    

zDMP.__rtruediv__c                 C  s
   |  |S r|   rF  rE  r   r   r   __pow__  s    zDMP.__pow__c                 C  s
   |  |S r|   rZ  rd  r   r   r   
__divmod__  s    zDMP.__divmod__c                 C  s
   |  |S r|   r]  rd  r   r   r   __mod__  s    zDMP.__mod__c                 C  s<   t |tr| |S z| |W S  ty6   t Y S 0 d S r|   )r   r   r`  r.  rC  r/  rd  r   r   r   __floordiv__  s    

zDMP.__floordiv__c                 C  sP   | |u rdS t |tstS z| |\}}W n ty@   Y dS 0 ||S d S )NTF)r   r   r/  r   ry   
_strict_eqr4  r   r   r   __eq__  s    
z
DMP.__eq__c                 C  s   t d S r|   r   rd  r   r   r   rA    s    zDMP._strict_eqc                 C  s   |s| |kS |  |S d S r|   )rA  r   r   strictr   r   r   eq  s    zDMP.eqc                 C  s   | j ||d S )N)rD  )rE  rC  r   r   r   ne  s    zDMP.nec                 C  s   |  |\}}| | k S r|   r   r   r4  r   r   r   __lt__  s    z
DMP.__lt__c                 C  s   |  |\}}| | kS r|   rG  r4  r   r   r   __le__  s    z
DMP.__le__c                 C  s   |  |\}}| | kS r|   rG  r4  r   r   r   __gt__  s    z
DMP.__gt__c                 C  s   |  |\}}| | kS r|   rG  r4  r   r   r   __ge__  s    z
DMP.__ge__c                 C  s   | j  S r|   )r   r   r   r   r   __bool__  s    zDMP.__bool__)N)F)F)r   )N)N)N)N)F)F)r   )r   r   )r   r   )r   )F)F)T)F)F)FNNNFF)NNF)NN)NN)F)F)r   
__module____qualname____doc__	__slots____annotations__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  r  r!  r%  r(  r+  r.  r1  r6  r9  r<  r@  rF  rJ  rN  rR  rV  rZ  r]  r`  rc  r#  r'  r*  r-  r0  r3  r8  r;  r?  rD  rI  rM  rQ  rU  rY  r\  r_  rb  r   rf  ri  rk  rt  rv  rx  rz  r  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  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  r2  r3  r4  r5  r7  r8  r9  r;  r=  r?  r@  rB  rA  rE  rF  rH  rI  rJ  rK  rL  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o6| j|jko6| j|jkS r   )r   r   r   r   rd  r   r   r   rA    s    zDMP_Python._strict_eqc                 C  s   |  || j| jS ).Create a DMP out of the given representation. )r   r   r   r   r   r   r   r   per  s    zDMP_Python.perc                 C  s   |  t|| j| j| jS r   )r   r   r   r   r   r   r   r   r     s    zDMP_Python.ground_newc                 C  s   |  | j| jS r|   )r   r   r   r   r   r   r   r     s    zDMP_Python._onec                   s   t |trj|jkr&td|f j|jkrJjjjj|jfS jj|j  tjj }t|j|j } fdd} |||fS dS )z7Unify representations of two multivariate polynomials. r   c                   s    |  S r|   )r   r   r   r   r   r   r   rX     s    zDMP_Python.unify.<locals>.perN)	r   r   r   ry   r   rX  r   r   r   r   r   r  r5  rX  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     s    zDMP_Python.to_DUP_Flintc                 C  s
   t | jS r   )r   r   r   r   r   r   r   	  s    zDMP_Python.to_listc                 C  s   t | j| jS zBConvert ``f`` to a tuple representation with native coefficients. )r0   r   r   r   r   r   r   r     s    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     s    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     s    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     s    zDMP_Python._termsc                 C  s&   t | j| j| j}| || jj| jS r  )rX   r   r   r   r   r   r   r   r   r   r  #  s    zDMP_Python._liftc                 C  s$   t | j| j| j\}}|| |fS )r  )r'   r   r   r   rX  r  r   r   r   r	  (  s    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  rb  )r)   r   r   r   rl  symbols)r   r   r  r  r   r   r   r  3  s    zDMP_Python.ejectc                 C  s,   t | j| j| j\}}}|| || j|fS )&Remove useless generators from ``f``. )r,   r   r   r   r   )r   r  r  ur   r   r   r  9  s    zDMP_Python._excludec                 C  s   |  t| j|| j| jS )6Returns a polynomial in `K[x_{P(1)}, ..., x_{P(n)}]`. )rX  r/   r   r   r   r  r   r   r   r  ?  s    zDMP_Python._permutec                 C  s$   t | j| j| j\}}|| |fS r  )r*   r   r   r   rX  r  r   r   r   r  C  s    zDMP_Python.terms_gcdc                 C  s   |  t| j|| j| jS r"  )rX  r1   r   r   r   r$  r   r   r   r#  H  s    zDMP_Python._add_groundc                 C  s   |  t| j|| j| jS r&  )rX  r2   r   r   r   r$  r   r   r   r'  L  s    zDMP_Python._sub_groundc                 C  s   |  t| j|| j| jS r)  )rX  r3   r   r   r   r$  r   r   r   r*  P  s    zDMP_Python._mul_groundc                 C  s   |  t| j|| j| jS r,  )rX  r4   r   r   r   r$  r   r   r   r-  T  s    zDMP_Python._quo_groundc                 C  s   |  t| j|| j| jS r/  )rX  r5   r   r   r   r$  r   r   r   r0  X  s    zDMP_Python._exquo_groundc                 C  s   |  t| j| j| jS r  )rX  r6   r   r   r   r   r   r   r   r  \  s    zDMP_Python.absc                 C  s   |  t| j| j| jS r   )rX  r7   r   r   r   r   r   r   r   r!  `  s    zDMP_Python.negc                 C  s   |  t| j|j| j| jS r2  )rX  r8   r   r   r   rd  r   r   r   r3  d  s    zDMP_Python._addc                 C  s   |  t| j|j| j| jS r7  )rX  r9   r   r   r   rd  r   r   r   r8  h  s    zDMP_Python._subc                 C  s   |  t| j|j| j| jS r:  )rX  r:   r   r   r   rd  r   r   r   r;  l  s    zDMP_Python._mulc                 C  s   |  t| j| j| jS r=  )rX  r;   r   r   r   r   r   r   r   r@  p  s    zDMP_Python.sqrc                 C  s   |  t| j|| j| jS rA  )rX  r<   r   r   r   rE  r   r   r   rD  t  s    zDMP_Python._powc                 C  s.   t | j|j| j| j\}}| || |fS rG  )r=   r   r   r   rX  r   r   r  r   r   r   r   rI  x  s    zDMP_Python._pdivc                 C  s   |  t| j|j| j| jS rK  )rX  r>   r   r   r   rd  r   r   r   rM  }  s    zDMP_Python._premc                 C  s   |  t| j|j| j| jS rO  )rX  r?   r   r   r   rd  r   r   r   rQ    s    zDMP_Python._pquoc                 C  s   |  t| j|j| j| jS rS  )rX  r@   r   r   r   rd  r   r   r   rU    s    zDMP_Python._pexquoc                 C  s.   t | j|j| j| j\}}| || |fS rW  )rA   r   r   r   rX  rk  r   r   r   rY    s    zDMP_Python._divc                 C  s   |  t| j|j| j| jS r[  )rX  rB   r   r   r   rd  r   r   r   r\    s    zDMP_Python._remc                 C  s   |  t| j|j| j| jS r^  )rX  rC   r   r   r   rd  r   r   r   r_    s    zDMP_Python._quoc                 C  s   |  t| j|j| j| jS ra  )rX  rD   r   r   r   rd  r   r   r   rb    s    zDMP_Python._exquor   c                 C  s   t | j|| jS )re  )r   r   r   rg  r   r   r   rf    s    zDMP_Python._degreec                 C  s   t | j| jS rh  )r   r   r   r   r   r   r   ri    s    zDMP_Python.degree_listc                 C  s   t dd |  D S )rj  c                 s  s   | ]}t |V  qd S r|   rm  )r   r   r   r   r   r     r   z*DMP_Python.total_degree.<locals>.<genexpr>)maxr   r   r   r   r   rk    s    zDMP_Python.total_degreec                 C  s   t | j| j| jS rw  )r   r   r   r   r   r   r   r   rx    s    zDMP_Python.LCc                 C  s   t | j| j| jS ry  )r   r   r   r   r   r   r   r   rz    s    zDMP_Python.TCc                 C  s   t | j|| j| jS r{  )r   r   r   r   r~  r   r   r   r}    s    zDMP_Python._nthc                 C  s   t | j| j| jS r  )rG   r   r   r   r   r   r   r   r    s    zDMP_Python.max_normc                 C  s   t | j| j| jS r  )rH   r   r   r   r   r   r   r   r    s    zDMP_Python.l1_normc                 C  s   t | j| j| jS r  )rI   r   r   r   r   r   r   r   r    s    zDMP_Python.l2_norm_squaredc                 C  s$   t | j| j| j\}}|| |fS )r  )rJ   r   r   r   rX  )r   r   r  r   r   r   r    s    zDMP_Python.clear_denomsr   c                 C  s   |  t| j||| j| jS )r  )rX  rK   r   r   r   r  r   r   r   r    s    zDMP_Python._integratec                 C  s   |  t| j||| j| jS )r  )rX  rL   r   r   r   r  r   r   r   r    s    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   rX  r   r   ro  hr   r   r   r    s    zDMP_Python._half_gcdexc                 C  s4   t | j|j| j\}}}| || || |fS )r  )rZ   r   r   rX  )r   r   ro  r  rw  r   r   r   r    s    zDMP_Python._gcdexc                 C  s   t | j|j| j}| |S )r  )r[   r   r   rX  )r   r   ro  r   r   r   r    s    zDMP_Python._invertc                 C  s   |  t| j|| jS r  )rX  rN   r   r   rE  r   r   r   r    s    zDMP_Python._revertc                 C  s&   t | j|j| j| j}tt| j|S r  )r\   r   r   r   r   maprX  r   r   Rr   r   r   r    s    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   ry  rX  r   r   resr{  r   r   r   r    s    z DMP_Python._resultant_includePRSc                 C  s6   t | j|j| j| j}| jr2| || j| jd }|S ru  )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   rX  )r   r   rw  Zcffcfgr   r   r   r    s    zDMP_Python._cofactorsc                 C  s   |  t| j|j| j| jS r  )rX  r`   r   r   r   rd  r   r   r   r    s    zDMP_Python._gcdc                 C  s   |  t| j|j| j| jS r  )rX  ra   r   r   r   rd  r   r   r   r    s    zDMP_Python._lcmc                 C  s:   t | j|j| j| jdd\}}}}||| || |fS )r  Fr  rb   r   r   r   rX  r   r   cFcGr  r5  r   r   r   r    s    "zDMP_Python._cancelc                 C  s2   t | j|j| j| jdd\}}| || |fS )r  Tr  r  r4  r   r   r   r    s    zDMP_Python._cancel_includec                 C  s   |  t| j|| j| jS r  )rX  rO   r   r   r   r  r   r   r   r    s    zDMP_Python._truncc                 C  s   |  t| j| j| jS r  )rX  rR   r   r   r   r   r   r   r   r    s    zDMP_Python.monicc                 C  s   t | j| j| jS r  )rP   r   r   r   r   r   r   r   r    s    zDMP_Python.contentc                 C  s$   t | j| j| j\}}|| |fS r  )rQ   r   r   r   rX  )r   contr  r   r   r   r  !  s    zDMP_Python.primitivec                 C  s   |  t| j|j| j| jS r  )rX  rS   r   r   r   rd  r   r   r   r  &  s    zDMP_Python._composec                 C  s   t t| jt| j| jS )r  )r   ry  rX  rT   r   r   r   r   r   r   r  *  s    zDMP_Python._decomposec                 C  s   |  t| j|| jS r  )rX  rU   r   r   r  r   r   r   r  .  s    zDMP_Python._shiftc                 C  s   |  t| j|| j| jS )r  )rX  rV   r   r   r   r  r   r   r   r  2  s    zDMP_Python._shift_listc                 C  s   |  t| j|j|j| jS r  )rX  rW   r   r   r  r   r   r   r  6  s    zDMP_Python._transformc                 C  s   t t| jt| j| jS )r  )r   ry  rX  ru   r   r   r   r   r   r   r  :  s    zDMP_Python._sturmc                 C  s   t | j| jS r  )rv   r   r   r   r   r   r   r  >  s    zDMP_Python._cauchy_upper_boundc                 C  s   t | j| jS r  )rw   r   r   r   r   r   r   r  B  s    zDMP_Python._cauchy_lower_boundc                 C  s   t | j| jS r  )rx   r   r   r   r   r   r   r  F  s    z&DMP_Python._mignotte_sep_bound_squaredc                   s    fddt  j jD S )r  c                   s   g | ]\}}  ||fqS r   rX  r   r   r   r   r   r   r   L  r   z(DMP_Python._gff_list.<locals>.<listcomp>)rc   r   r   r   r   r   r   r  J  s    zDMP_Python._gff_listc                 C  s&   t | j| j| j}| || jj| jS )r  )rd   r   r   r   r   ra  r   r   r   r  N  s    zDMP_Python.normc                 C  s8   t | j| j| j\}}}|| || || jj| jfS )r  )rf   r   r   r   rX  r   )r   ro  r   r   r   r   r   r  S  s    zDMP_Python.sqf_normc                 C  s   |  t| j| j| jS r  )rX  rg   r   r   r   r   r   r   r   r  X  s    zDMP_Python.sqf_partc                   s.   t  j j j|\}}| fdd|D fS )r  c                   s   g | ]\}}  ||fqS 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  \  s    zDMP_Python.sqf_listc                   s&   t  j j j|} fdd|D S )r  c                   s   g | ]\}}  ||fqS r   r  r  r   r   r   r   d  r   z/DMP_Python.sqf_list_include.<locals>.<listcomp>)ri   r   r   r   r   r   r  r   r   r   r  a  s    zDMP_Python.sqf_list_includec                   s,   t  j j j\}}| fdd|D fS )r  c                   s   g | ]\}}  ||fqS r   r  r  r   r   r   r   i  r   z*DMP_Python.factor_list.<locals>.<listcomp>)rl   r   r   r   )r   r   r  r   r   r   r  f  s    zDMP_Python.factor_listc                   s$   t  j j j} fdd|D S )r  c                   s   g | ]\}}  ||fqS r   r  r  r   r   r   r   n  r   z2DMP_Python.factor_list_include.<locals>.<listcomp>)rm   r   r   r   r   r  r   r   r   r  k  s    zDMP_Python.factor_list_includec                 C  s   t | j| j||||dS Nr  )ro   r   r   r  r   r   r   r  p  s    zDMP_Python._isolate_real_rootsc                 C  s   t | j| j||||dS r  )rn   r   r   r  r   r   r   r  s  s    z"DMP_Python._isolate_real_roots_sqfc                 C  s   t | j| j||||dS r  )rq   r   r   r  r   r   r   r  v  s    zDMP_Python._isolate_all_rootsc                 C  s   t | j| j||||dS r  )rp   r   r   r  r   r   r   r  y  s    z!DMP_Python._isolate_all_roots_sqfc              	   C  s   t | j||| j|||dS )Nr  )rr   r   r   r  r   r   r   r
  |  s    zDMP_Python._refine_real_rootc                 C  s   t | j| j||dS r  r  r   )rs   r   r   r  r   r   r   r    s    zDMP_Python.count_real_rootsc                 C  s   t | j| j||dS r  r  )rt   r   r   r  r   r   r   r    s    zDMP_Python.count_complex_rootsc                 C  s   t | j| jS r  )r!   r   r   r   r   r   r   r     s    zDMP_Python.is_zeroc                 C  s   t | j| j| jS r  )r"   r   r   r   r   r   r   r   r    s    zDMP_Python.is_onec                 C  s   t | jd| jS r  )r#   r   r   r   r   r   r   r    s    zDMP_Python.is_groundc                 C  s   t | j| j| jS )r  )re   r   r   r   r   r   r   r   r    s    zDMP_Python.is_sqfc                 C  s   | j t| j| j| j S r  )r   r  r   r   r   r   r   r   r   r    s    zDMP_Python.is_monicc                 C  s   | j t| j| j| j S r  )r   r  rP   r   r   r   r   r   r   r    s    zDMP_Python.is_primitivec                 C  s$   t dd t| j| j| j D S )r  c                 s  s   | ]}t |d kV  qdS )r   Nrm  r   ru  r   r   r   r     r   z'DMP_Python.is_linear.<locals>.<genexpr>r   r&   r   r   r   keysr   r   r   r   r     s    zDMP_Python.is_linearc                 C  s$   t dd t| j| j| j D S )r!  c                 s  s   | ]}t |d kV  qdS )   Nrm  r  r   r   r   r     r   z*DMP_Python.is_quadratic.<locals>.<genexpr>r  r   r   r   r   r"    s    zDMP_Python.is_quadraticc                 C  s   t |  dkS )r#  r   )rl  r   r   r   r   r   r$    s    zDMP_Python.is_monomialc                 C  s   |   duS r%  )rv  r   r   r   r   r'    s    zDMP_Python.is_homogeneousc                 C  s   t | j| j| jS )r(  )rk   r   r   r   r   r   r   r   r)    s    zDMP_Python.is_irreduciblec                 C  s   | j st| j| jS dS dS r*  FN)r   rj   r   r   r   r   r   r   r+    s    zDMP_Python.is_cyclotomic)N)F)F)r   )r   r   )r   r   )F)F)NN)NN)rr   rM  rN  rO  rP  rR  r   rA  rX  r   r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r#  r'  r*  r-  r0  r  r!  r3  r8  r;  r@  rD  rI  rM  rQ  rU  rY  r\  r_  rb  rf  ri  rk  rx  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r
  r  r  rS  r   r  r  r  r  r  r   r"  r$  r'  r)  r+  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__  s    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     s    zDUP_Flint.to_listc                 C  s*   t |sJ |dksJ | |}||S r   )r   _get_flint_poly_cls)r   r   r   r   Z	flint_clsr   r   r   r    s    
zDUP_Flint._flint_polyc                 C  s4   |j rtjS |jrtjS |jr$|jS td| d S )N%Domain %s is not supported with flint)r}   r{   	fmpz_polyr~   	fmpq_polyr   Z	_poly_ctxr   )r   r   r   r   r   r    s    zDUP_Flint._get_flint_poly_clsc                   s   |j rt|tjsJ tj}nf|jr<t|tjs4J tj}nH|jrxt|tjtjfsXJ |	 t
|  fdd}ntd| t| }||_||_||_|S )z,Create a DMP from the given representation. c                   s
    | S r|   r   )eZ_DUP_Flint__clsr   r   r   <lambda>  r   z$DUP_Flint.from_rep.<locals>.<lambda>r  )r}   r   r{   r  r~   r  r   Z	nmod_polyZfmpz_mod_polyZcharacteristicr   r   rT  r   r   r   r  )r   r   r   r  rU  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   rd  r   r   r   rA    s    zDUP_Flint._strict_eqc                 C  s   |  | |g| jS rY  r  r  r   r   r   r   r   r   
  s    zDUP_Flint.ground_newc                 C  s   |  | jjS r|   )r   r   r   r   r   r   r   r     s    zDUP_Flint._onec                 C  s   t dS )z*Unify representations of two polynomials. N)r   rd  r   r   r   r     s    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     s    zDUP_Flint.to_DMP_Pythonc                 C  s   t |  S r^  )rn  r   r   r   r   r   r     s    zDUP_Flint.to_tuplec                 C  sd   |t kr&| jtkr&| t| j|S t|rJt| jrJ|  	|
 S td| j d| dS )r_  zDUP_Flint: Cannot convert z to N)r   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   '  s    zDUP_Flint._slicec                 C  s   t dS r   r   r   r   r   r   r   ,  s    zDUP_Flint._slice_levNc                 C  sL   |du s|j dkr8dd t| j D }|ddd S |  j|dS dS )r   Nlexc                 S  s   g | ]\}}|r|f|fqS r   r   )r   r   r   r   r   r   r   4  r   z$DUP_Flint._terms.<locals>.<listcomp>r  r   )aliasr  r   r   r   r   )r   r   r   r   r   r   r   1  s    zDUP_Flint._termsc                 C  s   t dS )r  Nr   r   r   r   r   r  ?  s    zDUP_Flint._liftc                 C  s0   | j rd| fS | j \}}|f| || jfS )r  )r   )r   r   Z	deflationr  r   )r   r   r   r   r   r   r	  D  s    zDUP_Flint.deflateFc                 C  s   t dS r
  r   r  r   r   r   r  Q  s    zDUP_Flint.injectc                 C  s   t dS r  r   r  r   r   r   r  V  s    zDUP_Flint.ejectc                 C  s   t dS )rd  Nr   r   r   r   r   r  [  s    zDUP_Flint._excludec                 C  s   t dS )rf  Nr   r  r   r   r   r  `  s    zDUP_Flint._permutec                 C  s   |    \}}|| fS rg  )r   r  r   r  r   r   r   r  e  s    zDUP_Flint.terms_gcdc                 C  s   |  | j| | jS r"  r  r   r   r$  r   r   r   r#  k  s    zDUP_Flint._add_groundc                 C  s   |  | j| | jS r&  r  r$  r   r   r   r'  o  s    zDUP_Flint._sub_groundc                 C  s   |  | j| | jS r)  r  r$  r   r   r   r*  s  s    zDUP_Flint._mul_groundc                 C  s   |  | j| | jS r,  r  r$  r   r   r   r-  w  s    zDUP_Flint._quo_groundc                 C  s,   t | j|\}}|rt| || || jS )z<Exact quotient of ``f`` by an element of the ground domain. )divmodr   r   r  r   )r   r   r  r   r   r   r   r0  {  s    
zDUP_Flint._exquo_groundc                 C  s   |     S rh  )r   r  r   r   r   r   r   r    s    zDUP_Flint.absc                 C  s   |  | j | jS ri  r  r   r   r   r   r!    s    zDUP_Flint.negc                 C  s   |  | j|j | jS r2  r  rd  r   r   r   r3    s    zDUP_Flint._addc                 C  s   |  | j|j | jS r7  r  rd  r   r   r   r8    s    zDUP_Flint._subc                 C  s   |  | j|j | jS r:  r  rd  r   r   r   r;    s    zDUP_Flint._mulc                 C  s   |  | jd | jS )r>  r  r  r   r   r   r   r@    s    zDUP_Flint.sqrc                 C  s   |  | j| | jS rj  r  rE  r   r   r   rD    s    zDUP_Flint._powc                 C  sN   |   |   d }t| | | j |j\}}| || j| || jfS )rH  r   )r   r  rx  r   r  r   r   r   rr  r  r   r   r   r   rI    s    zDUP_Flint._pdivc                 C  s:   |   |   d }| | | j |j }| || jS )rL  r   r   rx  r   r  r   )r   r   rr  r  r   r   r   rM    s    zDUP_Flint._premc                 C  s:   |   |   d }| | | j |j }| || jS )rP  r   r  )r   r   rr  r   r   r   r   rQ    s    zDUP_Flint._pquoc                 C  sN   |   |   d }t| | | j |j\}}|r@t| || || jS )rT  r   )r   r  rx  r   r   r  r   r  r   r   r   rU    s
    
zDUP_Flint._pexquoc                 C  s`   | j jr6t| j|j\}}| || j | || j fS |  | \}}| | fS dS )rX  N)r   r  r  r   r  r   rY  r   rk  r   r   r   rY    s
    zDUP_Flint._divc                 C  s   |  | j|j | jS r[  r  rd  r   r   r   r\    s    zDUP_Flint._remc                 C  s   |  | j|j | jS r^  r  rd  r   r   r   r_    s    zDUP_Flint._quoc                 C  s    |  |\}}|rt| ||S ra  )rY  r   rk  r   r   r   rb    s    
zDUP_Flint._exquoc                 C  s   | j  }|dkrt}|S )re  r  )r   r   r   )r   r   rr  r   r   r   rf    s    
zDUP_Flint._degreec                 C  s
   |   fS rl  rf  r   r   r   r   ri    s    zDUP_Flint.degree_listc                 C  s   |   S )rj  r  r   r   r   r   rk    s    zDUP_Flint.total_degreec                 C  s   | j | j   S ro  r   r   r   r   r   r   rx    s    zDUP_Flint.LCc                 C  s
   | j d S )ry  r   r   r   r   r   r   rz    s    zDUP_Flint.TCc                 C  s   |\}| j | S rq  r  )r   r  r   r   r   r   r}    s    zDUP_Flint._nthc                 C  s   |    S rr  )r   r  r   r   r   r   r    s    zDUP_Flint.max_normc                 C  s   |    S rs  )r   r  r   r   r   r   r    s    zDUP_Flint.l1_normc                 C  s   |    S rt  )r   r  r   r   r   r   r    s    zDUP_Flint.l2_norm_squaredc                 C  sV   | j }|jr8| j }| | | j | j }||fS |jsD|jrN|j	| fS t
dS r  )r   r~   r   denomr  r  numerr}   is_FiniteFieldr   r   )r   r{  r  r  r   r   r   r    s    

zDUP_Flint.clear_denomsr   c                 C  sX   |dksJ | j jr>| j}t|D ]}| }q"| || j S |  j||d S dS )r  r   )r   r   N)	r   r  r   rangeZ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    s    zDUP_Flint._evalc                 C  s   t d S r|   r   r  r   r   r   r    s    zDUP_Flint._eval_levc                 C  s&   |   |  \}}| | fS )z#Half extended Euclidean algorithm. )r   r  r   rv  r   r   r   r  #  s    zDUP_Flint._half_gcdexc                 C  s<   | j |j \}}}| || j| || j| || jfS )zExtended Euclidean algorithm. )r   xgcdr  r   )r   r   rw  ro  r  r   r   r   r  (  s    zDUP_Flint._gcdexc                 C  s^   | j }|jrD| j|j\}}}|d| d kr8td| ||S |  |  S dS )r  r   r   zero divisorN)	r   r  r   r  r   r  r   r  r   )r   r   r{  r  ZF_invr   r   r   r   r  -  s    zDUP_Flint._invertc                 C  s   |   | S rx  )r   r  r   rE  r   r   r   r  <  s    zDUP_Flint._revertc                 C  s    |   |  }dd |D S )r  c                 S  s   g | ]}|  qS r   r   r   r   r   r   r   r   F  r   z,DUP_Flint._subresultants.<locals>.<listcomp>)r   r  rz  r   r   r   r  B  s    zDUP_Flint._subresultantsc                 C  s(   |   |  \}}|dd |D fS )r  c                 S  s   g | ]}|  qS r   r  r  r   r   r   r   L  r   z3DUP_Flint._resultant_includePRS.<locals>.<listcomp>)r   r  r|  r   r   r   r  H  s    zDUP_Flint._resultant_includePRSc                 C  s   |   |  S )z'Computes resultant of ``f`` and ``g``. )r   r  rd  r   r   r   r  N  s    zDUP_Flint._resultantc                 C  s   |    S )r  )r   r  r   r   r   r   r  S  s    zDUP_Flint.discriminantc                 C  s    |  |}|| |||fS r  )r  rc  )r   r   rw  r   r   r   r  X  s    
zDUP_Flint._cofactorsc                 C  s   |  | j|j| jS r  )r  r   r  r   rd  r   r   r   r  ]  s    zDUP_Flint._gcdc                 C  sV   | r|s|  | jjS | || |}|jjr>| }n| dk rR|	 }|S )r  r   )
r   r   r   r;  rb  r  r  r  rx  r!  )r   r   rs  r   r   r   r  a  s    
zDUP_Flint._lcmc                 C  sH  | j |j ksJ | j }|js,|js,|js,J |jrb| |}| ||| }}|j|j||fS |jr|  \}}| \}}n|j|  }}|j| }}||}|| ||  }}||}	||	||	 }}|	 dk }
|	 dk }|
r|r|
 |
  }}n.|
r&| |
  }}n|r<| |
  }}||||fS )r  r   )r   r}   r~   r  r  rc  r   r  r  rx  r!  )r   r   r{  rw  r  r5  r  r  ZcHHZf_negZg_negr   r   r   r  p  s2    


zDUP_Flint._cancelc                 C  s&   |  |\}}}}||||fS )r  )r  r*  r  r   r   r   r    s    zDUP_Flint._cancel_includec                 C  s   |   | S r  )r   r  r   r  r   r   r   r    s    zDUP_Flint._truncc                 C  s   |  |  S r  )r0  rx  r   r   r   r   r    s    zDUP_Flint.monicc                 C  s   |    S r  )r   r  r   r   r   r   r    s    zDUP_Flint.contentc                 C  s,   |   }| jr| jj| fS | |}||fS r  )r  r   r   r   r0  )r   r  Zprimr   r   r   r    s
    
zDUP_Flint.primitivec                 C  s   |  | |j| jS r  r  rd  r   r   r   r    s    zDUP_Flint._composec                 C  s   dd |    D S )r  c                 S  s   g | ]}|  qS r   r  r  r   r   r   r     r   z(DUP_Flint._decompose.<locals>.<listcomp>)r   r  r   r   r   r   r    s    zDUP_Flint._decomposec                 C  s&   |  || jjg}| | || jS r  )r  r   r   r  r   )r   r  Zx_plus_ar   r   r   r    s    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  s   dd |    D S )r  c                 S  s   g | ]}|  qS r   r  r  r   r   r   r     r   z$DUP_Flint._sturm.<locals>.<listcomp>)r   r  r   r   r   r   r    s    zDUP_Flint._sturmc                 C  s   |    S r  )r   r  r   r   r   r   r    s    zDUP_Flint._cauchy_upper_boundc                 C  s   |    S r  )r   r  r   r   r   r   r    s    zDUP_Flint._cauchy_lower_boundc                 C  s   |    S r  )r   r  r   r   r   r   r    s    z%DUP_Flint._mignotte_sep_bound_squaredc                 C  s   |   }dd | D S )r  c                 S  s   g | ]\}}|  |fqS r   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  s   t dS r  r   r   r   r   r   r    s    zDUP_Flint.normc                 C  s   t dS r  r   r   r   r   r   r    s    zDUP_Flint.sqf_normc                 C  s   |  | |  S r  )rb  r  r  r   r   r   r   r    s    zDUP_Flint.sqf_partc                 C  s&   |   j|d\}}|dd |D fS )r  r   c                 S  s   g | ]\}}|  |fqS r   r  r  r   r   r   r     r   z&DUP_Flint.sqf_list.<locals>.<listcomp>)r   r  r  r   r   r   r    s    zDUP_Flint.sqf_listc                 C  s   |   j|d}dd |D S )r  r  c                 S  s   g | ]\}}|  |fqS 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s j jr2 j \}} fdd|D }np j jr j \}} fdd|D }g }|D ].\}}| \}}|||  }|||f qbntd j   	|}||fS )r  c                   s"   g | ]\}}  | j|fqS r   r  r   r  r   r   r   r     r   z)DUP_Flint.factor_list.<locals>.<listcomp>c                   s"   g | ]\}}  | j|fqS r   r  r  r   r   r   r     r   r  )
r   r}   r   r   factorr~   r  r   r   r   )r   r   r  Zfactors_monicr   r   rr  r   r   r   r    s    
zDUP_Flint.factor_listc                 C  s   |    }dd |D S )r  c                 S  s   g | ]\}}|  |fqS 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  s   g | ]\}}|  |fqS 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   r   	  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   |   ||||S r|   )r   r  r  r   r   r   r  #	  s    zDUP_Flint._isolate_real_rootsc                 C  s   |   ||||S r|   )r   r  r  r   r   r   r  &	  s    z!DUP_Flint._isolate_real_roots_sqfc                 C  s   |   ||||S r|   )r   r  r  r   r   r   r  )	  s    zDUP_Flint._isolate_all_rootsc                 C  s   |   ||||S r|   )r   r  r  r   r   r   r  /	  s    z DUP_Flint._isolate_all_roots_sqfc                 C  s   |   |||||S r|   )r   r
  r  r   r   r   r
  2	  s    zDUP_Flint._refine_real_rootc                 C  s   |   j||dS r  )r   r  r  r   r   r   r  5	  s    zDUP_Flint.count_real_rootsc                 C  s   |   j||dS r  )r   r  r  r   r   r   r  9	  s    zDUP_Flint.count_complex_rootsc                 C  s   | j  S r  r  r   r   r   r   r   =	  s    zDUP_Flint.is_zeroc                 C  s   | j | jjkS r  )r   r   r   r   r   r   r   r  B	  s    zDUP_Flint.is_onec                 C  s   | j  dkS )r  r   r  r   r   r   r   r  G	  s    zDUP_Flint.is_groundc                 C  s   | j  dkS )r  r   r  r   r   r   r   r   L	  s    zDUP_Flint.is_linearc                 C  s   | j  dkS )r!  r  r  r   r   r   r   r"  Q	  s    zDUP_Flint.is_quadraticc                   s2   | j    dk p0t fddt  D  S )r#  r   c                 3  s   | ]} | V  qd S r|   r   r|  frr   r   r   Z	  r   z(DUP_Flint.is_monomial.<locals>.<genexpr>)r   r   anyr  r   r   r  r   r$  V	  s    zDUP_Flint.is_monomialc                 C  s   |   | jjkS r  )rx  r   r   r   r   r   r   r  \	  s    zDUP_Flint.is_monicc                 C  s
   |   jS r  )r   r  r   r   r   r   r  a	  s    zDUP_Flint.is_primitivec                 C  s
   |   jS )r&  )r   r'  r   r   r   r   r'  f	  s    zDUP_Flint.is_homogeneousc                 C  s   | j | j  }| dkS )r  r   )r   r  r  r   rd  r   r   r   r  k	  s    zDUP_Flint.is_sqfc                 C  sB   | j  \}}t|dkrdS t|dkr:|d d dkS dS dS )r(  r   Tr   FN)r   r  rl  )r   r   r  r   r   r   r)  q	  s    zDUP_Flint.is_irreduciblec                 C  sJ   | j jr,z| t} W n ty*   Y dS 0 | j jrBt| j S dS dS r  )	r   r~   r   r
   r   r}   boolr   r+  r   r   r   r   r+  |	  s    zDUP_Flint.is_cyclotomic)N)F)F)r   )r   r   )r   r   )F)F)NN)NN)vr   rM  rN  rO  r   rP  r  rR  r   r   r  r  r  rA  r   r   r   r   r   r   r   r   r   r  r	  r  r  r  r  r  r#  r'  r*  r-  r0  r  r!  r3  r8  r;  r@  rD  rI  rM  rQ  rU  rY  r\  r_  rb  rf  ri  rk  rx  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  r
  r  r  rS  r   r  r  r   r"  r$  r  r  r'  r  r)  r+  r   r   r   r   r     s  












'















r   c                 C  s   t t| ||t|||||S r|   )DMFr   numdenr   r   r   r   r   init_normal_DMF	  s    r  c                   @  s  e Zd ZdZdZdZddZed[ddZdd	 Zed\d
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__	  s    zDMF.__init__c                 C  s:   |  |||\}}}t| }||_||_||_||_|S r|   )r  rT  r   r  r  r   r   )r   r   r   r   r  r  rU  r   r   r   r   	  s    
zDMF.newc                 C  s   |  || j| jS r|   )r   r   r   )r   r   r   r   r   r   	  s    zDMF.ground_newc                 C  s(  t |tr|\}}|d urHt |tr0t|||}t |trvt|||}n.t|\}}t|\}}||krn|}ntdt||rtdt||rt||}n$t	|||rt
|||}t
|||}nZ|}|d urt |trt|||}nt |tst|||}nt|\}}t||}|||fS )Nzinconsistent number of levelszfraction denominator)r   rn  r   r%   r   r  r!   ZeroDivisionErrorr   r   r7   r   r   r   )r   r   r   r   r  r  Znum_levZden_levr   r   r   r  	  s8    







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   	  s    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rP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 dS )z0Unify a multivariate fraction and a polynomial. r   TFc                   sB   |r|s| | S |d }|r.t | || \} }j| |f |S ru  rb   r   r   r  r  r  killr   r   r   r   r   rX  	  s    zDMF.poly_unify.<locals>.perN)r   r   r   ry   r   rX  r  r  r   r   r   r   r   r   r  r5  rX  r   r  r   
poly_unify	  s    zDMF.poly_unifyc                   s   t |trj|jkr&td|f j|jkrV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 dS )z5Unify representations of two multivariate fractions. r   TFc                   sB   |r|s| | S |d }|r.t | || \} }j| |f |S ru  r  r  r  r   r   rX  
  s    zDMF.frac_unify.<locals>.perN)
r   r  r   ry   r   rX  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  r  r   r   r   r   r   rX  
  s    zDMF.perc                 C  s(   | j }|r|s|S |d8 }t|| j|S )rV  r   )r   r   r   )r   r   r  r   r   r   r   half_per,
  s    zDMF.half_perc                 C  s   |  d||S r   r   r   r   r   r   r   8
  s    zDMF.zeroc                 C  s   |  d||S ru  r  r   r   r   r   r   <
  s    zDMF.onec                 C  s   |  | jS )z Returns the numerator of ``f``. )r  r  r   r   r   r   r  @
  s    z	DMF.numerc                 C  s   |  | jS )z"Returns the denominator of ``f``. )r  r  r   r   r   r   r  D
  s    z	DMF.denomc                 C  s   |  | j| jS )z4Remove common factors from ``f.num`` and ``f.den``. )rX  r  r  r   r   r   r   r  H
  s    z
DMF.cancelc                 C  s    | j t| j| j| j| jddS )r   Fr  )rX  r7   r  r   r   r  r   r   r   r   r!  L
  s    zDMF.negc                 C  s   | |  | S r"  )r   r$  r   r   r   r%  P
  s    zDMF.add_groundc                 C  s   t |tr:| |\}}}\}}}t|||||| }}	nV| |\}}}}
}|
| \}}\}}tt||||t||||||}t||||}	|||	S )z0Add two multivariate fractions ``f`` and ``g``. )r   r   r  rE   r  r8   r:   r   r   r   r   rX  F_numF_denr5  r  r  r  ZG_numZG_denr   r   r   r6  T
  s    
zDMF.addc                 C  s   t |tr:| |\}}}\}}}t|||||| }}	nV| |\}}}}
}|
| \}}\}}tt||||t||||||}t||||}	|||	S )z5Subtract two multivariate fractions ``f`` and ``g``. )r   r   r  rF   r  r9   r:   r  r   r   r   r9  c
  s    
zDMF.subc                 C  s   t |tr8| |\}}}\}}}t||||| }}	nB| |\}}}}
}|
| \}}\}}t||||}t||||}	|||	S )z5Multiply two multivariate fractions ``f`` and ``g``. r   r   r  r:   r  r  r   r   r   r<  r
  s    
zDMF.mulc                 C  sr   t |tr^| j| j }}|dk r2|||   }}}| jt||| j| jt||| j| jddS tdt	| dS )rA  r   Fr  rB  N)
r   r   r  r  rX  r<   r   r   rC  r   )r   r   r  r  r   r   r   rF  
  s    
zDMF.powc                 C  s   t |tr8| |\}}}\}}}|t|||| }}	nB| |\}}}}
}|
| \}}\}}t||||}t||||}	|||	S )z0Computes quotient of fractions ``f`` and ``g``. r  r  r   r   r   r`  
  s    
zDMF.quoc                 C  s   | j | j| jddS )z&Computes inverse of a fraction ``f``. Fr  )rX  r  r  )r   checkr   r   r   r  
  s    z
DMF.invertc                 C  s   t | j| jS )z.Returns ``True`` if ``f`` is a zero fraction. r!   r  r   r   r   r   r   r   
  s    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  
  s    z
DMF.is_onec                 C  s   |   S r|   r-  r   r   r   r   r.  
  s    zDMF.__neg__c              
   C  sh   t |ttfr| |S || jv r4| | j|S z| | |W S  tt	t
fyb   t Y S 0 d S r|   )r   r   r  r6  r   r%  r   r  rC  r   r   r/  rd  r   r   r   r0  
  s    

zDMF.__add__c                 C  s
   |  |S r|   r1  rd  r   r   r   r2  
  s    zDMF.__radd__c              
   C  sL   t |ttfr| |S z| | |W S  tttfyF   t Y S 0 d S r|   )	r   r   r  r9  r  rC  r   r   r/  rd  r   r   r   r3  
  s    
zDMF.__sub__c                 C  s   |   |S r|   r1  rd  r   r   r   r4  
  s    zDMF.__rsub__c              
   C  sL   t |ttfr| |S z| | |W S  tttfyF   t Y S 0 d S r|   )	r   r   r  r<  r  rC  r   r   r/  rd  r   r   r   r5  
  s    
zDMF.__mul__c                 C  s
   |  |S r|   r6  rd  r   r   r   r7  
  s    zDMF.__rmul__c                 C  s
   |  |S r|   r:  rE  r   r   r   r;  
  s    zDMF.__pow__c              
   C  sL   t |ttfr| |S z| | |W S  tttfyF   t Y S 0 d S r|   )	r   r   r  r`  r  rC  r   r   r/  rd  r   r   r   r8  
  s    
zDMF.__truediv__c                 C  s   | j dd| S )NF)r  )r  )r   r   r   r   r   r9  
  s    zDMF.__rtruediv__c                 C  s   zxt |trL| |\}}}\}}}| j|jkrvt|| j| joF||kW S n*| |\}}}}}| j|jkrv||kW S W n ty   Y n0 dS r   r   r   r  r   r"   r   r  ry   r   r   r   r  r  r5  r  r   r   r   rB  
  s    
z
DMF.__eq__c                 C  s   zzt |trN| |\}}}\}}}| j|jkrxt|| j| joF||k W S n*| |\}}}}}| j|jkrx||kW S W n ty   Y n0 dS )NTr  r  r   r   r   __ne__
  s    
z
DMF.__ne__c                 C  s   |  |\}}}}}||k S r|   r  r   r   r   r  r5  r   r   r   rH    s    z
DMF.__lt__c                 C  s   |  |\}}}}}||kS r|   r  r  r   r   r   rI    s    z
DMF.__le__c                 C  s   |  |\}}}}}||kS r|   r  r  r   r   r   rJ    s    z
DMF.__gt__c                 C  s   |  |\}}}}}||kS r|   r  r  r   r   r   rK    s    z
DMF.__ge__c                 C  s   t | j| j S r|   r  r   r   r   r   rL    s    zDMF.__bool__)N)N)N)TF)F)T)2r   rM  rN  rO  rP  r  rR  r   r   r  r   r   r  r  rX  r  r   r   r  r  r  r!  r%  r6  r9  r<  rF  r`  rc  r  rS  r   r  r.  r0  r2  r3  r4  r5  r7  r;  r8  r9  rB  r  rH  rI  rJ  rK  rL  r   r   r   r   r  	  sf   
	+






			r  c                 C  s   t t| |t|||S r|   )ANPr   )r   modr   r   r   r   init_normal_ANP  s    

r  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 )yr  z1Dense Algebraic Number Polynomials over a field. )r   _modr   c                   s   t |trnZt|tu r,tt|  d}n:t |trJ fdd|D }n |g}tt| d}t |trrn.t |trtt|  d}ntt| d}| || S )Nr   c                   s   g | ]}  |qS r   )r   )r   r  r   r   r   r   )  r   zANP.__new__.<locals>.<listcomp>)	r   r   r   r   r$   r   r   r   r   r   r   r  r   r   r   r   r   "  s    



zANP.__new__c                   sD   |j |j   kr|ks"n tdt | }||_||_||_ |S )NzInconsistent domain)r   r   superr   r   r  )r   r   r  r   rU  r   r   r   r   7  s    zANP.newc                 C  s   t | j| j| jffS r|   )r  r   r  r   r   r   r   r   r  D  s    zANP.__reduce__c                 C  s
   | j  S r|   r   r   r   r   r   r   r   G  s    zANP.repc                 C  s   |   S r|   )mod_to_listr   r   r   r   r  K  s    zANP.modc                 C  s   | j S r|   r  r   r   r   r   to_DMPO  s    z
ANP.to_DMPc                 C  s   | j S r|   )r  r   r   r   r   
mod_to_DMPR  s    zANP.mod_to_DMPc                 C  s   |  || j| jS r|   )r   r  r   rW  r   r   r   rX  U  s    zANP.perc                 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   X  s    zANP.__repr__c                 C  s    t | jj|  | j | jfS r|   )r   r   r   r   r  r   r   r   r   r   r   [  s    zANP.__hash__c                 C  s0   | j |kr| S | | j|| j||S dS )z.Convert ``f`` to a ``ANP`` over a new domain. N)r   r   r   r   r  r   r   r   r   r   ^  s    
zANP.convertc                   s   t |tr| j|jkr&td| |f | j|jkrJ| j| j| j|j| jfS | j|j t| j| j }t|j|j } | jkr |jkrt| j| j n | jkr| jn|j fdd} |||fS )z0Unify representations of two algebraic numbers. r   c                   s   t |  S r|   r  rZ  r   r  r   r   r  ~  r   zANP.unify.<locals>.<lambda>)	r   r  r  ry   r   rX  r   r   r   r\  r   r  r   r   e  s    
z	ANP.unifyc                 C  sh   t |tr| j|jkr&td| |f | j|jkrT| j|j}| |} ||}| j|j| j| jfS r   )r   r  r  ry   r   r   r   r   r   r   r   r   	unify_ANP  s    

zANP.unify_ANPc                 C  s   t d||S r   r  r   r  r   r   r   r   r     s    zANP.zeroc                 C  s   t d||S ru  r  r  r   r   r   r     s    zANP.onec                 C  s
   | j  S )r   )r   r   r   r   r   r   r     s    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  s
   | j  S r]  r  r   r   r   r   r     s    zANP.to_listc                 C  s
   | j  S )z5Return ``f.mod`` as a list with native coefficients. )r  r   r   r   r   r   r    s    zANP.mod_to_listc                   s    fdd   D S )r   c                   s   g | ]} j |qS r   )r   r   r   r   r   r   r     r   z%ANP.to_sympy_list.<locals>.<listcomp>r   r   r   r   r   r     s    zANP.to_sympy_listc                 C  s
   | j  S )r   )r   r   r   r   r   r   r     s    zANP.to_tuplec                 C  s   t ttt|j|||S r|   )r  r   r   ry  r   r  r   r   r   r     s    zANP.from_listc                 C  s   |  | j|S r"  )rX  r   r%  r$  r   r   r   r%    s    zANP.add_groundc                 C  s   |  | j|S r&  )rX  r   r(  r$  r   r   r   r(    s    zANP.sub_groundc                 C  s   |  | j|S )z3Multiply ``f`` by an element of the ground domain. )rX  r   r+  r$  r   r   r   r+    s    zANP.mul_groundc                 C  s   |  | j|S )z6Quotient of ``f`` by an element of the ground domain. )rX  r   r.  r$  r   r   r   r.    s    zANP.quo_groundc                 C  s   |  | j S r|   )rX  r   r!  r   r   r   r   r!    s    zANP.negc                 C  s&   |  |\}}}}| ||||S r|   )r  r   r6  r   r   r  r5  r  r   r   r   r   r6    s    zANP.addc                 C  s&   |  |\}}}}| ||||S r|   )r  r   r9  r  r   r   r   r9    s    zANP.subc                 C  s,   |  |\}}}}| |||||S r|   )r  r   r<  r]  r  r   r   r   r<    s    zANP.mulc                 C  s^   t |tstdt| | j}| j}|dk r@|||  }}| ||	| j|| j
S )rA  rB  r   )r   r   rC  r   r  r   r  r   rF  r]  r   )r   r   r  r  r   r   r   rF    s    
zANP.powc                 C  s2   |  |\}}}}| ||||||S r|   )r  r   r<  r  r]  r  r   r   r   rc    s    z	ANP.exquoc                 C  s   |  || | j| jfS r|   )rc  r   r  r   rd  r   r   r   rZ    s    zANP.divc                 C  s
   |  |S r|   )rc  rd  r   r   r   r`    s    zANP.quoc                 C  s>   |  |\}}}}||\}}|jr2| ||S tdd S )Nr  )r  r  r  r   r   )r   r   r  r5  r  r   ro  rw  r   r   r   r]    s
    zANP.remc                 C  s
   | j  S ro  )r   rx  r   r   r   r   rx    s    zANP.LCc                 C  s
   | j  S rp  )r   rz  r   r   r   r   rz     s    zANP.TCc                 C  s   | j jS )z6Returns ``True`` if ``f`` is a zero algebraic number. )r   r   r   r   r   r   r     s    zANP.is_zeroc                 C  s   | j jS )z6Returns ``True`` if ``f`` is a unit algebraic number. )r   r  r   r   r   r   r  	  s    z
ANP.is_onec                 C  s   | j jS )r  )r   r  r   r   r   r   r    s    zANP.is_groundc                 C  s   | S r|   r   r   r   r   r   __pos__  s    zANP.__pos__c                 C  s   |   S r|   r-  r   r   r   r   r.    s    zANP.__neg__c                 C  sJ   t |tr| |S z| j|}W n ty:   t Y S 0 | |S d S r|   )r   r  r6  r   r   r   r/  r%  rd  r   r   r   r0    s    


zANP.__add__c                 C  s
   |  |S r|   r1  rd  r   r   r   r2  #  s    zANP.__radd__c                 C  sJ   t |tr| |S z| j|}W n ty:   t Y S 0 | |S d S r|   )r   r  r9  r   r   r   r/  r(  rd  r   r   r   r3  &  s    


zANP.__sub__c                 C  s   |   |S r|   r1  rd  r   r   r   r4  0  s    zANP.__rsub__c                 C  sJ   t |tr| |S z| j|}W n ty:   t Y S 0 | |S d S r|   )r   r  r<  r   r   r   r/  r+  rd  r   r   r   r5  3  s    


zANP.__mul__c                 C  s
   |  |S r|   r6  rd  r   r   r   r7  =  s    zANP.__rmul__c                 C  s
   |  |S r|   r:  rE  r   r   r   r;  @  s    zANP.__pow__c                 C  s
   |  |S r|   r<  rd  r   r   r   r=  C  s    zANP.__divmod__c                 C  s
   |  |S r|   r>  rd  r   r   r   r?  F  s    zANP.__mod__c                 C  sJ   t |tr| |S z| j|}W n ty:   t Y S 0 | |S d S r|   )r   r  r`  r   r   r   r/  r.  rd  r   r   r   r8  I  s    


zANP.__truediv__c                 C  s6   z|  |\}}}}W n ty,   t Y S 0 ||kS r|   r  ry   r/  r   r   r  r5  r   r   r   r   rB  S  s
    
z
ANP.__eq__c                 C  s6   z|  |\}}}}W n ty,   t Y S 0 ||kS r|   r  r  r   r   r   r  Z  s
    
z
ANP.__ne__c                 C  s   |  |\}}}}||k S r|   r  r  r   r   r   rH  a  s    z
ANP.__lt__c                 C  s   |  |\}}}}||kS r|   r  r  r   r   r   rI  e  s    z
ANP.__le__c                 C  s   |  |\}}}}||kS r|   r  r  r   r   r   rJ  i  s    z
ANP.__gt__c                 C  s   |  |\}}}}||kS r|   r  r  r   r   r   rK  m  s    z
ANP.__ge__c                 C  s
   t | jS r|   )r  r   r   r   r   r   rL  q  s    zANP.__bool__)Cr   rM  rN  rO  rP  r   rR  r   r  rS  r   r  r  r  rX  r   r   r   r   r  r   r   r   r   r   r  r   r   r   r%  r(  r+  r.  r!  r6  r9  r<  rF  rc  rZ  r`  r]  rx  rz  r   r  r  r  r.  r0  r2  r3  r4  r5  r7  r;  r=  r?  r8  rB  r  rH  rI  rJ  rK  rL  __classcell__r   r   r  r   r    s   



	
	






r  )rO  
__future__r   Zsympy.external.gmpyr   Zsympy.utilities.exceptionsr   Zsympy.core.numbersr   Zsympy.core.sympifyr   Zsympy.polys.polyutilsr   r   Zsympy.polys.domainsr	   r
   r   Zsympy.polys.polyerrorsr   r   r   r   Z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   Z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   Zsympy.polys.densetoolsrJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   Zsympy.polys.euclidtoolsrY   rZ   r[   r\   r]   r^   r_   r`   ra   rb   Zsympy.polys.sqfreetoolsrc   rd   re   rf   rg   rh   ri   Zsympy.polys.factortoolsrj   rk   rl   rm   Zsympy.polys.rootisolationrn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r   r   r   r   r  r  r  r  r   r   r   r   <module>   s^   lD0
$4

        R   v     I   