a
    RG5dU                     @   s  d Z dgZddlmZmZ ddlmZ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 ddlmZmZ dd	lZdd	lZG d
d dZG dd deZG dd deZG dd deZeG dd deZG dd deedZ G dd deedZ!G dd deedZ"G dd deedZ#G dd deedZ$G dd deedZ%G d d! d!eedZ&G d"d# d#eedZ'G d$d% d%eedZ(G d&d' d'eedZ)G d(d) d)eedZ*G d*d+ d+eedZ+G d,d- d-eedZ,G d.d/ d/eedZ-G d0d1 d1eedZ.G d2d3 d3eeedZ/G d4d5 d5eeedZ0G d6d7 d7eeedZ1G d8d9 d9eeedZ2G d:d; d;eeedZ3G d<d= d=eeedZ4G d>d? d?eedZ5G d@dA dAeeedZ6G dBdC dCeedZ7G dDdE dEeedZ8dLdFdGZ9dHdI Z:dJdK Z;e<  d	S )Mz>Options manager for :class:`~.Poly` and public API functions. Options    )DictType)ListOptional)Basicsympify)GeneratorsErrorOptionError	FlagError)numbered_symbolstopological_sortpublic)has_dupsis_sequenceNc                   @   sL   e Zd ZdZdZdZg Zg Zg Zg Z	e
dd Ze
dd Ze
dd	 ZdS )
Optionz%Base class for all kinds of options. NFc                 C   s   d S N clsr   r   S/var/www/html/django/DPS/env/lib/python3.9/site-packages/sympy/polys/polyoptions.pydefault   s    zOption.defaultc                 C   s   d S r   r   )r   optionr   r   r   
preprocess#   s    zOption.preprocessc                 C   s   d S r   r   r   optionsr   r   r   postprocess'   s    zOption.postprocess)__name__
__module____qualname____doc__r   is_Flagrequiresexcludesafterbeforeclassmethodr   r   r   r   r   r   r   r      s   

r   c                   @   s   e Zd ZdZdZdS )Flagz#Base class for all kinds of flags. TN)r   r   r   r    r!   r   r   r   r   r'   ,   s   r'   c                   @   s   e Zd ZdZedd ZdS )BooleanOptionzAAn option that must have a boolean value or equivalent assigned. c                 C   s&   |dv rt |S td| j|f d S )N)TFz/'%s' must have a boolean value assigned, got %s)boolr
   r   )r   valuer   r   r   r   5   s    zBooleanOption.preprocessN)r   r   r   r    r&   r   r   r   r   r   r(   2   s   r(   c                   @   s   e Zd ZdZdd ZdS )
OptionTypez7Base type for all options that does registers options. c                    s.   t  fdd}tt j|  tj j< d S )Nc                    s,   z|  j  W S  ty&      Y S 0 d S r   )r   KeyErrorr   )selfr   r   r   getterA   s    z#OptionType.__init__.<locals>.getter)propertysetattrr   r   __options__)r   argskwargsr.   r   r   r   __init__@   s    zOptionType.__init__N)r   r   r   r    r4   r   r   r   r   r+   =   s   r+   c                       sn   e Zd ZdZdZi ZdddZedd Zi fdd	Z	 fd
dZ
edd Zedd Zedd Z  ZS )r   aB  
    Options manager for polynomial manipulation module.

    Examples
    ========

    >>> from sympy.polys.polyoptions import Options
    >>> from sympy.polys.polyoptions import build_options

    >>> from sympy.abc import x, y, z

    >>> Options((x, y, z), {'domain': 'ZZ'})
    {'auto': False, 'domain': ZZ, 'gens': (x, y, z)}

    >>> build_options((x, y, z), {'domain': 'ZZ'})
    {'auto': False, 'domain': ZZ, 'gens': (x, y, z)}

    **Options**

    * Expand --- boolean option
    * Gens --- option
    * Wrt --- option
    * Sort --- option
    * Order --- option
    * Field --- boolean option
    * Greedy --- boolean option
    * Domain --- option
    * Split --- boolean option
    * Gaussian --- boolean option
    * Extension --- option
    * Modulus --- option
    * Symmetric --- boolean option
    * Strict --- boolean option

    **Flags**

    * Auto --- boolean flag
    * Frac --- boolean flag
    * Formal --- boolean flag
    * Polys --- boolean flag
    * Include --- boolean flag
    * All --- boolean flag
    * Gen --- flag
    * Series --- boolean flag

    NFc                    sD  t  |r$|ddr$tdn|r8t |}||d< |di } fdd}|| t | D ]D\}}|v r||= qh D ]"}	j|	 }
||
jv r||=  qhqqh||  D ]b}	j|	 }
|
j	D ]"}|d u rtd|	|f q|
jD ]"}|d urtd|	|f qqj
D ]}	j|	  q(d S )	Ngensr   z1both '*gens' and keyword argument 'gens' supplieddefaultsc              	      s   |   D ]v\}}zj| }W n ty<   td| Y n0 t|trh d u sX| vrhrhtd| |d ur|||< qd S )N'%s' is not a valid option('%s' flag is not allowed in this context)itemsr1   r,   r
   
issubclassr'   r   )r2   r   r*   r   flagsr-   strictr   r   preprocess_options   s    
z,Options.__init__.<locals>.preprocess_optionsz.'%s' option is only allowed together with '%s'z-'%s' option is not allowed together with '%s')dictr4   getr
   popr9   keysr1   r#   r"   	__order__r   )r-   r5   r2   r<   r=   r6   r>   keyr*   r   r   Zrequire_optionZexclude_optionr   r;   r   r4      s<    






zOptions.__init__c                 C   s   | j du rg t  }}| j D ]F\}}|| |jD ]}|||f q8|jD ]}|||f qRq zt|t	|f| _ W n t
y   tdY n0 dS )z*Resolve the order of options' processing. Nz/cycle detected in sympy.polys options framework)rC   setr1   r9   appendr$   addr%   r   list
ValueErrorRuntimeError)r   verticesedgesnamer   _namer   r   r   _init_dependencies_order   s    



z Options._init_dependencies_orderc                 C   sD   t | j}|  D ]\}}|||< q| D ]\}}|||< q.|S )z-Clone ``self`` and update specified options. )r?   __new__	__class__r9   )r-   updatesobjr   r*   r   r   r   clone   s    

zOptions.clonec                    s&   || j v r|| |< nt || d S r   )r1   super__setattr__)r-   attrr*   rQ   r   r   rV      s    

zOptions.__setattr__c                 C   sF   i }|   D ]4\}}|d ur|dkr| j| }t|ts|||< q|S )Nr5   )r9   r1   r:   r'   )r-   r2   r   r*   r   r   r   r   r2      s    


zOptions.argsc                 C   s4   i }| j  D ] \}}t|tst| |||< q|S r   r1   r9   r:   r'   getattr)r-   r   r   r   r   r   r   r      s
    
zOptions.optionsc                 C   s4   i }| j  D ] \}}t|trt| |||< q|S r   rY   )r-   r<   r   r   r   r   r   r<      s
    
zOptions.flags)NF)r   r   r   r    rC   r1   r4   r&   rO   rT   rV   r/   r2   r   r<   __classcell__r   r   rX   r   r   L   s   /
8


	c                   @   s(   e Zd ZdZdZg Zg Zedd ZdS )Expandz8``expand`` option to polynomial manipulation functions. expandc                 C   s   dS NTr   r   r   r   r   r   	  s    zExpand.defaultN)	r   r   r   r    r   r"   r#   r&   r   r   r   r   r   r\     s   r\   )	metaclassc                   @   s4   e Zd ZdZdZg Zg Zedd Zedd Z	dS )Gensz6``gens`` option to polynomial manipulation functions. r5   c                 C   s   dS )Nr   r   r   r   r   r   r     s    zGens.defaultc                 C   s   t |tr|f}n t|dkr2t|d r2|d }|dkr@d}n<t|rZtdt| n"tdd |D r|tdt| t|S )	N   r   r   r   zduplicated generators: %sc                 s   s   | ]}|j d u V  qdS )FN)is_commutative.0genr   r   r   	<genexpr>%      z"Gens.preprocess.<locals>.<genexpr>znon-commutative generators: %s)	
isinstancer   lenr   r   r	   stranytuple)r   r5   r   r   r   r     s    
zGens.preprocessN
r   r   r   r    r   r"   r#   r&   r   r   r   r   r   r   r`     s   
r`   c                   @   s2   e Zd ZdZdZg Zg ZedZ	e
dd ZdS )Wrtz5``wrt`` option to polynomial manipulation functions. wrtz\s*,\s*|\s+c                 C   sz   t |trt|gS t |trV| }|dr8td|s@g S dd | j|D S t|drnt	t
t|S tdd S )N,zBad input: missing parameter.c                 S   s   g | ]}|qS r   r   rc   r   r   r   
<listcomp>?  rg   z"Wrt.preprocess.<locals>.<listcomp>__getitem__z!invalid argument for 'wrt' option)rh   r   rj   stripendswithr
   	_re_splitsplithasattrrH   map)r   ro   r   r   r   r   5  s    




zWrt.preprocessN)r   r   r   r    r   r"   r#   recompileru   r&   r   r   r   r   r   rn   +  s   
rn   c                   @   s4   e Zd ZdZdZg Zg Zedd Zedd Z	dS )Sortz6``sort`` option to polynomial manipulation functions. sortc                 C   s   g S r   r   r   r   r   r   r   N  s    zSort.defaultc                 C   sB   t |trdd |dD S t|dr6ttt|S tdd S )Nc                 S   s   g | ]}|  qS r   )rs   rc   r   r   r   rq   U  rg   z#Sort.preprocess.<locals>.<listcomp>>rr   z"invalid argument for 'sort' option)rh   rj   rv   rw   rH   rx   r
   )r   r|   r   r   r   r   R  s
    

zSort.preprocessNrm   r   r   r   r   r{   F  s   
r{   c                   @   s4   e Zd ZdZdZg Zg Zedd Zedd Z	dS )Orderz7``order`` option to polynomial manipulation functions. orderc                 C   s
   t jjjS r   )sympypolys	orderingslexr   r   r   r   r   d  s    zOrder.defaultc                 C   s   t jj|S r   )r   r   r   monomial_key)r   r   r   r   r   r   h  s    zOrder.preprocessNrm   r   r   r   r   r~   \  s   
r~   c                   @   s    e Zd ZdZdZg Zg dZdS )Fieldz7``field`` option to polynomial manipulation functions. field)domainrv   gaussianNr   r   r   r    r   r"   r#   r   r   r   r   r   m  s   r   c                   @   s    e Zd ZdZdZg Zg dZdS )Greedyz8``greedy`` option to polynomial manipulation functions. greedyr   rv   r   	extensionmodulus	symmetricNr   r   r   r   r   r   v  s   r   c                   @   s,   e Zd ZdZdZedd Zg Zg dZdS )	Compositez;``composite`` option to polynomial manipulation functions. 	compositec                 C   s   d S r   r   r   r   r   r   r     s    zComposite.defaultr   N)	r   r   r   r    r   r&   r   r"   r#   r   r   r   r   r     s   
r   c                   @   sz   e Zd ZdZdZg Zg dZdgZe	dZ
e	dZe	dZe	dZe	d	Ze	d
Zedd Zedd ZdS )Domainz8``domain`` option to polynomial manipulation functions. r   )r   r   rv   r   r   r5   z^(R|RR)(_(\d+))?$z^(C|CC)(_(\d+))?$z^(FF|GF)\((\d+)\)$z)^(Z|ZZ|Q|QQ|ZZ_I|QQ_I|R|RR|C|CC)\[(.+)\]$z^(Z|ZZ|Q|QQ)\((.+)\)$z^(Q|QQ)\<(.+)\>$c                 C   s  t |tjjjr|S t|dr&| S t |tr|dv rDtjjjS |dv rVtjjj	S |dkrhtjjj
S |dkrztjjjS |dkrtjjjS | j|}|d ur| \}}}|d u rtjjjS tjjt|S | j|}|d ur| \}}}|d u r
tjjjS tjjt|S | j|}|d urLtjjt| d S | j|}|d ur| \}}ttt|d}|dv rtjjjj| S |dv rtjjj	j| S |d	v rtjjjj| S |dkrtjjj
j| S |dkrtjjjj| S tjjjj| S | j|}|d urt| \}}ttt|d}|dv rdtjjjj| S tjjj	j| S | j |}|d urttt| d d}tjjj	j!| S t"d
| d S )N	to_domain)ZZZ)QQQZZ_IQQ_IEXra   rp   )RRRz-expected a valid domain specification, got %s)#rh   r   r   domainsr   rw   r   rj   r   r   r   r   r   _re_realfieldmatchgroupsr   	RealFieldint_re_complexfieldCCComplexField_re_finitefieldFF_re_polynomialrH   rx   r   rv   Z	poly_ring_re_fractionZ
frac_field_re_algebraicalgebraic_fieldr
   )r   r   r_precZgroundr5   r   r   r   r     sr    



















zDomain.preprocessc                 C   st   d|v r>d|v r>|d j r>t|d jt|d @ r>tdn2d|vsN|d spd|v rp|d tjjjkrptdd S )Nr5   r   z/ground domain and generators interfere togetherz>you have to provide generators because EX domain was requested)is_CompositerE   symbolsr	   r   r   r   r   r   r   r   r   r     s    zDomain.postprocessN)r   r   r   r    r   r"   r#   r$   ry   rz   r   r   r   r   r   r   r&   r   r   r   r   r   r   r     s   






Vr   c                   @   s,   e Zd ZdZdZg Zg dZedd ZdS )Splitz7``split`` option to polynomial manipulation functions. rv   )r   r   r   r   r   r   r   c                 C   s   d|v rt dd S )Nrv   z%'split' option is not implemented yet)NotImplementedErrorr   r   r   r   r     s    zSplit.postprocessN	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g Zg dZedd ZdS )Gaussianz:``gaussian`` option to polynomial manipulation functions. r   )r   r   r   rv   r   r   r   c                 C   s0   d|v r,|d du r,t jjj|d< t| d S )Nr   Tr   )r   r   r   r   	Extensionr   r   r   r   r   r     s    zGaussian.postprocessNr   r   r   r   r   r     s   r   c                   @   s8   e Zd ZdZdZg Zg dZedd Zedd Z	dS )	r   z;``extension`` option to polynomial manipulation functions. r   )r   r   rv   r   r   r   c                 C   sN   |dkrt |S |dkr"tdn(t|ds4|h}n|s>d }nt|}|S d S )Nra   r   z.'False' is an invalid argument for 'extension'__iter__)r)   r
   rw   rE   )r   r   r   r   r   r   '  s    

zExtension.preprocessc                 C   s0   d|v r,|d dur,t jjjj|d  |d< d S )Nr   Tr   )r   r   r   r   r   r   r   r   r   r   8  s    
zExtension.postprocessN
r   r   r   r    r   r"   r#   r&   r   r   r   r   r   r   r     s   
r   c                   @   s8   e Zd ZdZdZg Zg dZedd Zedd Z	dS )	Modulusz9``modulus`` option to polynomial manipulation functions. r   )r   rv   r   r   r   c                 C   s.   t |}|jr|dkrt|S td| d S )Nr   z)'modulus' must a positive integer, got %s)r   
is_Integerr   r
   )r   r   r   r   r   r   G  s    zModulus.preprocessc                 C   s4   d|v r0|d }| dd}tjj|||d< d S )Nr   r   Tr   )r@   r   r   r   r   )r   r   r   r   r   r   r   r   Q  s    zModulus.postprocessNr   r   r   r   r   r   ?  s   
	r   c                   @   s"   e Zd ZdZdZdgZg dZdS )	Symmetricz;``symmetric`` option to polynomial manipulation functions. r   r   )r   r   rv   r   r   Nr   r   r   r   r   r   Y  s   r   c                   @   s    e Zd ZdZdZedd ZdS )Strictz8``strict`` option to polynomial manipulation functions. r=   c                 C   s   dS r^   r   r   r   r   r   r   g  s    zStrict.defaultNr   r   r   r    r   r&   r   r   r   r   r   r   b  s   r   c                   @   s4   e Zd ZdZdZg dZedd Zedd ZdS )	Autoz4``auto`` flag to polynomial manipulation functions. auto)r   r   r   r   c                 C   s   dS r^   r   r   r   r   r   r   s  s    zAuto.defaultc                 C   s$   d|v sd|v r d|vr d|d< d S )Nr   r   r   Fr   r   r   r   r   r   w  s    zAuto.postprocessN)	r   r   r   r    r   r$   r&   r   r   r   r   r   r   r   l  s   
r   c                   @   s    e Zd ZdZdZedd ZdS )Fracz6``auto`` option to polynomial manipulation functions. fracc                 C   s   dS NFr   r   r   r   r   r     s    zFrac.defaultNr   r   r   r   r   r   }  s   r   c                   @   s    e Zd ZdZdZedd ZdS )Formalz6``formal`` flag to polynomial manipulation functions. Zformalc                 C   s   dS r   r   r   r   r   r   r     s    zFormal.defaultNr   r   r   r   r   r     s   r   c                   @   s   e Zd ZdZdZdS )Polysz5``polys`` flag to polynomial manipulation functions. r   N)r   r   r   r    r   r   r   r   r   r     s   r   c                   @   s    e Zd ZdZdZedd ZdS )Includez7``include`` flag to polynomial manipulation functions. includec                 C   s   dS r   r   r   r   r   r   r     s    zInclude.defaultNr   r   r   r   r   r     s   r   c                   @   s    e Zd ZdZdZedd ZdS )Allz3``all`` flag to polynomial manipulation functions. allc                 C   s   dS r   r   r   r   r   r   r     s    zAll.defaultNr   r   r   r   r   r     s   r   c                   @   s,   e Zd ZdZdZedd Zedd ZdS )Genz3``gen`` flag to polynomial manipulation functions. re   c                 C   s   dS )Nr   r   r   r   r   r   r     s    zGen.defaultc                 C   s   t |ttfr|S tdd S )Nz!invalid argument for 'gen' option)rh   r   r   r
   )r   re   r   r   r   r     s    zGen.preprocessN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edd ZdS )Seriesz6``series`` flag to polynomial manipulation functions. seriesc                 C   s   dS r   r   r   r   r   r   r     s    zSeries.defaultNr   r   r   r   r   r     s   r   c                   @   s,   e Zd ZdZdZedd Zedd ZdS )Symbolsz7``symbols`` flag to polynomial manipulation functions. r   c                 C   s   t dddS )Nsra   )start)r   r   r   r   r   r     s    zSymbols.defaultc                 C   s"   t |drt|S td| d S )Nr   z2expected an iterator or iterable container, got %s)rw   iterr
   )r   r   r   r   r   r     s    
zSymbols.preprocessNr   r   r   r   r   r     s   
r   c                   @   s    e Zd ZdZdZedd ZdS )Methodz6``method`` flag to polynomial manipulation functions. methodc                 C   s"   t |tr| S td| d S )Nzexpected a string, got %s)rh   rj   lowerr
   )r   r   r   r   r   r     s    
zMethod.preprocessN)r   r   r   r    r   r&   r   r   r   r   r   r     s   r   c                 C   s@   |du rd|  } }t |dks*d|vs*| r4t| |S |d S dS )z9Construct options from keyword arguments or ... options. Nr   ra   opt)ri   r   )r5   r2   r   r   r   build_options  s
    

r   c              	   C   s^   t |}|  D ]H}z$tj| jr6||vr6td| W q tyV   td| Y q0 qdS )a  
    Allow specified flags to be used in the given context.

    Examples
    ========

    >>> from sympy.polys.polyoptions import allowed_flags
    >>> from sympy.polys.domains import ZZ

    >>> allowed_flags({'domain': ZZ}, [])

    >>> allowed_flags({'domain': ZZ, 'frac': True}, [])
    Traceback (most recent call last):
    ...
    FlagError: 'frac' flag is not allowed in this context

    >>> allowed_flags({'domain': ZZ, 'frac': True}, ['frac'])

    r8   r7   N)rE   rB   r   r1   r!   r   r,   r
   )r2   r<   argr   r   r   allowed_flags  s    r   c                 K   s   d| vrt | } || d< | S )z$Update options with default values. r6   )r?   )r   r6   r   r   r   set_defaults  s    r   )N)=r    __all__typingr   tDictr   r   r   
sympy.corer   r   sympy.polys.polyerrorsr	   r
   r   sympy.utilitiesr   r   r   sympy.utilities.iterablesr   r   sympy.polysr   ry   r   r'   r(   typer+   r?   r   r\   r`   rn   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rO   r   r   r   r   <module>   sZ    5		s!	






