o
    ohT                     @  s  d Z ddlmZ dg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 d/d0 d0eedZ*G d1d2 d2eeedZ+G d3d4 d4eeedZ,G d5d6 d6eeedZ-G d7d8 d8eeedZ.G d9d: d:eeedZ/G d;d< d<eeedZ0G d=d> d>eedZ1G d?d@ d@eeedZ2G dAdB dBeedZ3G dCdD dDeedZ4dKdEdFZ5dGdH Z6dIdJ Z7e8  dS )Lz>Options manager for :class:`~.Poly` and public API functions.     )annotationsOptions)Basicsympify)GeneratorsErrorOptionError	FlagError)numbered_symbolstopological_sortpublic)has_dupsis_sequenceNc                   @  sv   e Zd ZU dZdZded< dZg Zded< g Zded< g Z	ded	< g Z
ded
< edd Zedd Zedd ZdS )Optionz%Base class for all kinds of options. Nz
str | NoneoptionF	list[str]requiresexcludesafterbeforec                 C     d S N clsr   r   k/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/sympy/polys/polyoptions.pydefault      zOption.defaultc                 C  r   r   r   )r   r   r   r   r   
preprocess!   r   zOption.preprocessc                 C  r   r   r   r   optionsr   r   r   postprocess%   r   zOption.postprocess)__name__
__module____qualname____doc__r   __annotations__is_Flagr   r   r   r   classmethodr   r   r    r   r   r   r   r      s   
 

r   c                   @     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)   *       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 )N)TFz/'%s' must have a boolean value assigned, got %s)boolr   r   )r   valuer   r   r   r   3   s   zBooleanOption.preprocessN)r!   r"   r#   r$   r'   r   r   r   r   r   r+   0   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 w r   )r   KeyErrorr   )selfr   r   r   getter?   s
   z#OptionType.__init__.<locals>.getter)propertysetattrr   r   __options__)r   argskwargsr1   r   r   r   __init__>   s   zOptionType.__init__N)r!   r"   r#   r$   r7   r   r   r   r   r.   ;   s    r.   c                      sx   e Zd ZU dZdZi Zded< 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

    Nzdict[str, type[Option]]r4   Fc                   s8  t  |r|ddrtd|rt |}||d< |di } fdd}|| t |D ] }|v r;||= q1 D ]}j| }	||	jv rP||=  nq?q1||  D ]1}j| }	|	jD ]}
|
d u rutd||
f qd|	jD ]}|d urtd||f qyqZj	D ]
}j| 
 qd S )	Ngensr   z1both '*gens' and keyword argument 'gens' supplieddefaultsc              	     s   |   D ]9\}}zj| }W n ty   td| w t|tr2 d u s*| vr2r2td| |d ur=|||< qd S )N'%s' is not a valid option('%s' flag is not allowed in this context)itemsr4   r/   r   
issubclassr)   r   )r5   r   r-   r   flagsr0   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')dictr7   getr   popkeysr4   r   r   	__order__r    )r0   r8   r5   r?   r@   r9   rA   keyr   r   require_optionexclude_optionr   r>   r   r7   ~   sH   






zOptions.__init__c                   s   | j du rLg t }}| j D ]#\ }|  | fdd|jD  | fdd|jD  qzt|t	|f| _ W dS  t
yK   tdw dS )z*Resolve the order of options' processing. Nc                 3  s    | ]}| fV  qd S r   r   .0_namenamer   r   	<genexpr>       z3Options._init_dependencies_order.<locals>.<genexpr>c                 3  s    | ]} |fV  qd S r   r   rJ   rM   r   r   rO      rP   z/cycle detected in sympy.polys options framework)rF   setr4   r<   appendupdater   r   r
   list
ValueErrorRuntimeError)r   verticesedgesr   r   rM   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. )rB   __new__	__class__r<   )r0   updatesobjr   r-   r   r   r   clone   s   

zOptions.clonec                   s(   || j v r|| |< d S t || d S r   )r4   super__setattr__)r0   attrr-   r[   r   r   r`      s   
zOptions.__setattr__c                 C  sF   i }|   D ]\}}|d ur |dkr | j| }t|ts |||< q|S )Nr8   )r<   r4   r=   r)   )r0   r5   r   r-   r   r   r   r   r5      s   

zOptions.argsc                 C  s4   i }| j  D ]\}}t|tst| |||< q|S r   r4   r<   r=   r)   getattr)r0   r   r   r   r   r   r   r         
zOptions.optionsc                 C  s4   i }| j  D ]\}}t|trt| |||< q|S r   rc   )r0   r?   r   r   r   r   r   r?      re   zOptions.flagsNF)r!   r"   r#   r$   rF   r4   r%   r7   r'   rY   r^   r`   r2   r5   r   r?   __classcell__r   r   rb   r   r   J   s   
 /
8


	c                   @  s:   e Zd ZU dZdZg Zded< g Zded< edd Z	dS )	Expandz8``expand`` option to polynomial manipulation functions. expandr   r   r   c                 C     dS NTr   r   r   r   r   r     r   zExpand.defaultN)
r!   r"   r#   r$   r   r   r%   r   r'   r   r   r   r   r   rh      s   
 rh   )	metaclassc                   @  F   e Zd ZU dZdZg Zded< g Zded< edd Z	edd	 Z
d
S )Gensz6``gens`` option to polynomial manipulation functions. r8   r   r   r   c                 C  rj   )Nr   r   r   r   r   r   r     r   zGens.defaultc                 C  s   t |tr	|f}nt|dkrt|d r|d }|dkr#d}t|S t|r/tdt| 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rK   genr   r   r   rO   !  s    z"Gens.preprocess.<locals>.<genexpr>znon-commutative generators: %s)	
isinstancer   lenr   r   r   stranytuple)r   r8   r   r   r   r     s   
zGens.preprocessNr!   r"   r#   r$   r   r   r%   r   r'   r   r   r   r   r   r   rn   
     
 
rn   c                   @  sD   e Zd ZU dZdZg Zded< g Zded< e	dZ
edd Zd	S )
Wrtz5``wrt`` option to polynomial manipulation functions. wrtr   r   r   z\s*,\s*|\s+c                 C  sp   t |tr
t|gS t |tr(| }|drtd|s g S t| j|S t	|dr4tt
t|S td)N,zBad input: missing parameter.__getitem__z!invalid argument for 'wrt' option)rs   r   ru   stripendswithr   rT   	_re_splitsplithasattrmap)r   r{   r   r   r   r   1  s   




zWrt.preprocessN)r!   r"   r#   r$   r   r   r%   r   recompiler   r'   r   r   r   r   r   rz   '  s   
 
rz   c                   @  rm   )Sortz6``sort`` option to polynomial manipulation functions. sortr   r   r   c                 C  s   g S r   r   r   r   r   r   r   J  r   zSort.defaultc                 C  s>   t |trdd |dD S t|drttt|S td)Nc                 S  s   g | ]}|  qS r   )r~   rq   r   r   r   
<listcomp>Q  s    z#Sort.preprocess.<locals>.<listcomp>>r}   z"invalid argument for 'sort' option)rs   ru   r   r   rT   r   r   )r   r   r   r   r   r   N  s
   

zSort.preprocessNrx   r   r   r   r   r   B  ry   r   c                   @  rm   )Orderz7``order`` option to polynomial manipulation functions. orderr   r   r   c                 C  s
   t jjjS r   )sympypolys	orderingslexr   r   r   r   r   `  s   
zOrder.defaultc                 C  s   t jj|S r   )r   r   r   monomial_key)r   r   r   r   r   r   d  s   zOrder.preprocessNrx   r   r   r   r   r   X  ry   r   c                   @  *   e Zd ZU dZdZg Zded< g dZdS )Fieldz7``field`` option to polynomial manipulation functions. fieldr   r   )domainr   gaussianNr!   r"   r#   r$   r   r   r%   r   r   r   r   r   r   i  
   
 r   c                   @  r   )Greedyz8``greedy`` option to polynomial manipulation functions. greedyr   r   r   r   r   	extensionmodulus	symmetricNr   r   r   r   r   r   r  r   r   c                   @  s6   e Zd ZU dZdZedd Zg Zded< g dZ	dS )		Compositez;``composite`` option to polynomial manipulation functions. 	compositec                 C  r   r   r   r   r   r   r   r     r   zComposite.defaultr   r   r   N)
r!   r"   r#   r$   r   r'   r   r   r%   r   r   r   r   r   r   {  s   
 
r   c                   @  s   e Zd ZU dZdZg Zded< 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   )r   r   r   r   r   r8   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rS|dv r"tjjjS |dv r+tjjj	S |dkr4tjjj
S |dkr=tjjjS |dkrFtjjjS | j|}|d uri| \}}}|d u r`tjjjS tjjt|S | j|}|d ur| \}}}|d u rtjjjS tjjt|S | j|}|d urt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rtjjjj| S tjjjj| S | j|}|d ur2| \}}ttt|d}|dv r*tjjjj| S tjjj	j| S | j |}|d urSttt| d d}tjjj	j!| S t"d
| )N	to_domain)ZZZ)QQQZZ_IQQ_IEXro   r|   )RRRz-expected a valid domain specification, got %s)#rs   r   r   domainsr   r   r   ru   r   r   r   r   r   _re_realfieldmatchgroupsr   	RealFieldint_re_complexfieldCCComplexField_re_finitefieldFF_re_polynomialrT   r   r   r   	poly_ring_re_fraction
frac_field_re_algebraicalgebraic_fieldr   )r   r   r_precgroundr8   r   r   r   r     sr   











zDomain.preprocessc                 C  sz   d|v rd|v r|d j rt|d jt|d @ rtdd|vs&|d s9d|v r7|d tjjjkr;tdd S d S d S )Nr8   r   z/ground domain and generators interfere togetherz>you have to provide generators because EX domain was requested)is_CompositerQ   symbolsr   r   r   r   r   r   r   r   r   r      s   zDomain.postprocessN)r!   r"   r#   r$   r   r   r%   r   r   r   r   r   r   r   r   r   r   r'   r   r    r   r   r   r   r     s    
 






Vr   c                   @  6   e Zd ZU dZdZg Zded< g dZedd Z	dS )	Splitz7``split`` option to polynomial manipulation functions. r   r   r   )r   r   r   r   r   r   r   c                 C  s   d|v rt dd S )Nr   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   r        
 r   c                   @  r   )	Gaussianz:``gaussian`` option to polynomial manipulation functions. r   r   r   )r   r   r   r   r   r   r   c                 C  s8   d|v r|d du rt jjj|d< t| d S d S d S )Nr   Tr   )r   r   r   r   	Extensionr    r   r   r   r   r      s   zGaussian.postprocessNr   r   r   r   r   r   
  r   r   c                   @  B   e Zd ZU dZdZg Zded< g dZedd Z	edd	 Z
d
S )r   z;``extension`` option to polynomial manipulation functions. r   r   r   )r   r   r   r   r   r   c                 C  sL   |dkrt |S |dkrtdt|ds|h}|S |s d }|S t|}|S )Nro   r   z.'False' is an invalid argument for 'extension'__iter__)r,   r   r   rQ   )r   r   r   r   r   r   #  s   
zExtension.preprocessc                 C  s8   d|v r|d durt jjjj|d  |d< d S d S d S )Nr   Tr   )r   r   r   r   r   r   r   r   r   r    4  s
   
zExtension.postprocessNr!   r"   r#   r$   r   r   r%   r   r'   r   r    r   r   r   r   r     s   
 
r   c                   @  r   )Modulusz9``modulus`` option to polynomial manipulation functions. r   r   r   )r   r   r   r   r   c                 C  s*   t |}|jr|dkrt|S td| )Nr   z)'modulus' must a positive integer, got %s)r   
is_Integerr   r   )r   r   r   r   r   r   C  s   zModulus.preprocessc                 C  s8   d|v r|d }| dd}tjj|||d< d S d S )Nr   r   Tr   )rC   r   r   r   r   )r   r   r   r   r   r   r   r    M  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   r   r   r   N)r!   r"   r#   r$   r   r   r   r   r   r   r   r   U  s
    r   c                   @      e Zd ZdZdZedd ZdS )Strictz8``strict`` option to polynomial manipulation functions. r@   c                 C  rj   rk   r   r   r   r   r   r   c  r   zStrict.defaultNr!   r"   r#   r$   r   r'   r   r   r   r   r   r   ^  
    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  rj   rk   r   r   r   r   r   r   o  r   zAuto.defaultc                 C  s,   d|v sd|v rd|vrd|d< d S d S d S )Nr   r   r   Fr   r   r   r   r   r    s  s   zAuto.postprocessN)	r!   r"   r#   r$   r   r   r'   r   r    r   r   r   r   r   h  s    
r   c                   @  r   )Fracz6``auto`` option to polynomial manipulation functions. fracc                 C  rj   rf   r   r   r   r   r   r   ~  r   zFrac.defaultNr   r   r   r   r   r   y  r   r   c                   @  r   )Formalz6``formal`` flag to polynomial manipulation functions. formalc                 C  rj   rf   r   r   r   r   r   r     r   zFormal.defaultNr   r   r   r   r   r     r   r   c                   @  r(   )Polysz5``polys`` flag to polynomial manipulation functions. r   N)r!   r"   r#   r$   r   r   r   r   r   r     r*   r   c                   @  r   )Includez7``include`` flag to polynomial manipulation functions. includec                 C  rj   rf   r   r   r   r   r   r     r   zInclude.defaultNr   r   r   r   r   r     r   r   c                   @  r   )Allz3``all`` flag to polynomial manipulation functions. allc                 C  rj   rf   r   r   r   r   r   r     r   zAll.defaultNr   r   r   r   r   r     r   r   c                   @  ,   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. rr   c                 C  rj   )Nr   r   r   r   r   r   r     r   zGen.defaultc                 C  s   t |ttfr	|S td)Nz!invalid argument for 'gen' option)rs   r   r   r   )r   rr   r   r   r   r     s   zGen.preprocessNr!   r"   r#   r$   r   r'   r   r   r   r   r   r   r         
r   c                   @  r   )Seriesz6``series`` flag to polynomial manipulation functions. seriesc                 C  rj   rf   r   r   r   r   r   r     r   zSeries.defaultNr   r   r   r   r   r     r   r   c                   @  r   )Symbolsz7``symbols`` flag to polynomial manipulation functions. r   c                 C  s   t dddS )Nsro   )start)r	   r   r   r   r   r     s   zSymbols.defaultc                 C  s   t |dr	t|S td| )Nr   z2expected an iterator or iterable container, got %s)r   iterr   )r   r   r   r   r   r        
zSymbols.preprocessNr   r   r   r   r   r     r   r   c                   @  r   )Methodz6``method`` flag to polynomial manipulation functions. methodc                 C  s   t |tr	| S td| )Nzexpected a string, got %s)rs   ru   lowerr   )r   r   r   r   r   r     r   zMethod.preprocessN)r!   r"   r#   r$   r   r'   r   r   r   r   r   r     r   r   c                 C  s<   |du r	d| } }t |dksd|vs| rt| |S |d S )z9Construct options from keyword arguments or ... options. Nr   ro   opt)rt   r   )r8   r5   r   r   r   build_options  s
   

r   c              	   C  sX   t |}|  D ]!}ztj| jr||vrtd| W q ty)   td| w 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'])

    r;   r:   N)rQ   rE   r   r4   r&   r   r/   r   )r5   r?   argr   r   r   allowed_flags  s   r   c                 K  s   d| vrt | } || d< | S )z$Update options with default values. r9   )rB   )r   r9   r   r   r   set_defaults
  s   r   r   )9r$   
__future__r   __all__
sympy.corer   r   sympy.polys.polyerrorsr   r   r   sympy.utilitiesr	   r
   r   sympy.utilities.iterablesr   r   sympy.polysr   r   r   r)   r+   typer.   rB   r   rh   rn   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   rY   r   r   r   r   <module>   sZ     3		s!	






