K i4!DdZddlmZgdZddlmZddlmZGddZGdd eZ Gd d eZ Gd d eZ GddeZ GddeZ e Ze Ze Ze eZe eZe eZeeeeeedZddZGddZdZy)z#Definitions of monomial orderings. ) annotations)lexgrlexgrevlexilexigrlexigrevlex)Symbol)iterablecVeZdZUdZdZded<dZded<dZdZd Z d Z d Z d Z d Z y) MonomialOrderz#Base class for monomial orderings. Nz str | Nonealiasz bool | None is_globalFc4|jjdzS)Nz()) __class____name__selfs [/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/polys/orderings.py__repr__zMonomialOrder.__repr__s~~&&--c|jSN)rrs r__str__zMonomialOrder.__str__s zzrctr)NotImplementedErrorrmonomials r__call__zMonomialOrder.__call__s!!rc4|j|jk(Sr)rrothers r__eq__zMonomialOrder.__eq__s~~00rc,t|jSr)hashrrs r__hash__zMonomialOrder.__hash__sDNN##rc||k( Srr!s r__ne__zMonomialOrder.__ne__ sEM""r)r __module__ __qualname____doc__r__annotations__r is_defaultrrrr#r&r)r(rrr r s<-E:!I{!J."1$#rr c"eZdZdZdZdZdZdZy)LexOrderz"Lexicographic order of monomials. rTc|Srr(rs rrzLexOrder.__call__*srN)rr*r+r,rrr.rr(rrr0r0#s, EIJrr0ceZdZdZdZdZdZy)GradedLexOrderz)Graded lexicographic order of monomials. rTct||fSr)sumrs rrzGradedLexOrder.__call__3sH x((rNrr*r+r,rrrr(rrr3r3-s3 EI)rr3ceZdZdZdZdZdZy)ReversedGradedLexOrderz2Reversed graded lexicographic order of monomials. rTc ht|tt|Dcgc]}| c}fScc}wr)r5tuplereversed)rrms rrzReversedGradedLexOrder.__call__<s+H uX8.Dar.D%EFGG.Ds /Nr6r(rrr8r86s< EIHrr8cDeZdZdZdZdZdZdZdZdZ e dZ y ) ProductOrderab A product order built from other monomial orders. Given (not necessarily total) orders O1, O2, ..., On, their product order P is defined as M1 > M2 iff there exists i such that O1(M1) = O2(M2), ..., Oi(M1) = Oi(M2), O{i+1}(M1) > O{i+1}(M2). Product orders are typically built from monomial orders on different sets of variables. ProductOrder is constructed by passing a list of pairs [(O1, L1), (O2, L2), ...] where Oi are MonomialOrders and Li are callables. Upon comparison, the Li are passed the total monomial, and should filter out the part of the monomial to pass to Oi. Examples ======== We can use a lexicographic order on x_1, x_2 and also on y_1, y_2, y_3, and their product on {x_i, y_i} as follows: >>> from sympy.polys.orderings import lex, grlex, ProductOrder >>> P = ProductOrder( ... (lex, lambda m: m[:2]), # lex order on x_1 and x_2 of monomial ... (grlex, lambda m: m[2:]) # grlex on y_1, y_2, y_3 ... ) >>> P((2, 1, 1, 0, 0)) > P((1, 10, 0, 2, 0)) True Here the exponent `2` of `x_1` in the first monomial (`x_1^2 x_2 y_1`) is bigger than the exponent `1` of `x_1` in the second monomial (`x_1 x_2^10 y_2^2`), so the first monomial is greater in the product ordering. >>> P((2, 1, 1, 0, 0)) < P((2, 1, 0, 2, 0)) True Here the exponents of `x_1` and `x_2` agree, so the grlex order on `y_1, y_2, y_3` is used to decide the ordering. In this case the monomial `y_2^2` is ordered larger than `y_1`, since for the grlex order the degree of the monomial is most important. c||_yr)args)rr@s r__init__zProductOrder.__init__ks  rc@tfd|jDS)Nc3@K|]\}}||ywrr().0Olamdars r z(ProductOrder.__call__..osDJQQuX'Ds)r:r@rs `rrzProductOrder.__call__nsD$))DDDrc|jDcgc]}t|d}}|jjdzdj |zdzScc}wNr(z, ))r@reprrrjoinrxcontentss rrzProductOrder.__repr__qsN(, 21D1J22~~&&,tyy/BBSHH3Ac|jDcgc]}t|d}}|jjdzdj |zdzScc}wrI)r@strrrrMrNs rrzProductOrder.__str__usN'+yy1!C!I11~~&&,tyy/BBSHH2rQcVt|tsy|j|jk(SNF) isinstancer>r@r!s rr#zProductOrder.__eq__ys"%.yyEJJ&&rcDt|j|jfSr)r%rr@rs rr&zProductOrder.__hash__~sT^^TYY/00rcxtd|jDrytd|jDryy)Nc3>K|]\}}|jduyw)TNrrDo_s rrGz)ProductOrder.is_global..s9tq!q{{d"9Tc3>K|]\}}|jduyw)FNrZr[s rrGz)ProductOrder.is_global..s:1q{{e#:r^F)allr@rs rrzProductOrder.is_globals/ 9tyy9 9 : : :rN) rr*r+r,rArrrr#r&propertyrr(rrr>r>?s=)VEII' 1rr>c>eZdZdZdZdZdZedZdZ dZ y) InverseOrdera! The "inverse" of another monomial order. If O is any monomial order, we can construct another monomial order iO such that `A >_{iO} B` if and only if `B >_O A`. This is useful for constructing local orders. Note that many algorithms only work with *global* orders. For example, in the inverse lexicographic order on a single variable `x`, high powers of `x` count as small: >>> from sympy.polys.orderings import lex, InverseOrder >>> ilex = InverseOrder(lex) >>> ilex((5,)) < ilex((0,)) True c||_yrrE)rrEs rrAzInverseOrder.__init__s rc2dt|jzS)Ni)rSrErs rrzInverseOrder.__str__sS[  rc<fd|j|S)NcHt|rtfd|DS| S)Nc3.K|] }|ywrr()rDrOinvs rrGz5InverseOrder.__call__..inv..s/SV/s)r r:)lrks rrkz"InverseOrder.__call__..invs"{/Q///2Irre)rrrks @rrzInverseOrder.__call__s 466(#$$rch|jjdury|jjduryy)NTF)rErrs rrzInverseOrder.is_globals/ 66  t # 66  u $rcXt|txr|j|jk(Sr)rVrcrEr!s rr#zInverseOrder.__eq__s!%.D577dff3DDrcDt|j|jfSr)r%rrErs rr&zInverseOrder.__hash__sT^^TVV,--rN) rr*r+r,rArrrarr#r&r(rrrcrcs5$!%E.rrcNctttr tttr ttdr fd}|SSt dz#t $rt dzwxYw)an Return a function defining admissible order on monomials. The result of a call to :func:`monomial_key` is a function which should be used as a key to :func:`sorted` built-in function, to provide order in a set of monomials of the same length. Currently supported monomial orderings are: 1. lex - lexicographic order (default) 2. grlex - graded lexicographic order 3. grevlex - reversed graded lexicographic order 4. ilex, igrlex, igrevlex - the corresponding inverse orders If the ``order`` input argument is not a string but has ``__call__`` attribute, then it will pass through with an assumption that the callable object defines an admissible order on monomials. If the ``gens`` input argument contains a list of generators, the resulting key function can be used to sort SymPy ``Expr`` objects. zEsupported monomial orderings are 'lex', 'grlex' and 'grevlex', got %rrcJ|jjSr)as_poly degree_list)exprgensorders r_orderzmonomial_key.._orders"\T\\40<<>??rzFmonomial ordering specification must be a string or a callable, got %s)rrVr rS _monomial_keyKeyError ValueErrorhasattr)rvrurws`` r monomial_keyr|s. }% E % n!%(Euj!   @M adiijj ndgllm m ns A&&A>c"eZdZdZdZdZdZy) _ItemGetterz/Helper class to return a subsequence of values.c$t||_yrr:seq)rrs rrAz_ItemGetter.__init__s :rc@tfd|jDS)Nc3(K|] }| ywrr()rDidxr<s rrGz'_ItemGetter.__call__..s0QsV0r)rr<s `rrz_ItemGetter.__call__s0txx000rcVt|tsy|j|jk(SrU)rVr~rr!s rr#z_ItemGetter.__eq__s"%-xx599$$rN)rr*r+r,rArr#r(rrr~r~s91%rr~c i t|D] \}}| |< g}|D]3}|d}|dd} fd}|jt|||f5t|S)ad Build a monomial order on ``gens``. ``arg`` should be a tuple of iterables. The first element of each iterable should be a string or monomial order (will be passed to monomial_key), the others should be subsets of the generators. This function will build the corresponding product order. For example, build a product of two grlex orders: >>> from sympy.polys.orderings import build_product_order >>> from sympy.abc import x, y, z, t >>> O = build_product_order((("grlex", x, y), ("grlex", z, t)), [x, y, z, t]) >>> O((1, 2, 3, 4)) ((3, (1, 2)), (7, (3, 4))) rNc,tfd|DS)Nc3(K|] }| ywrr()rDggens2idxs rrGz:build_product_order..makelambda..s8qx{8r)r~)varrs r makelambdaz'build_product_order..makelambdas8C88 8r) enumerateappendr|r>) argrurgrrvrtnamerrrs @rbuild_product_orderrs~&H$1  E<Aw12h 9 l4(*S/:; <  r)NN)r, __future__r__all__ sympy.corer sympy.utilities.iterablesr r r0r3r8r>rcrrrrrr rxr|r~rr(rrrs)" C.##2})])H]HH=HT,.=,.\j "C e        )kV % % r