K i'0dZddlmZGddZddZy)z3Tools for manipulation of expressions using paths. )BasiccLeZdZdZdZdZdZdZdefdZ dZ d Z d d Z d Z y )EPatha3 Manipulate expressions using paths. EPath grammar in EBNF notation:: literal ::= /[A-Za-z_][A-Za-z_0-9]*/ number ::= /-?\d+/ type ::= literal attribute ::= literal "?" all ::= "*" slice ::= "[" number? (":" number? (":" number?)?)? "]" range ::= all | slice query ::= (type | attribute) ("|" (type | attribute))* selector ::= range | query range? path ::= "/" selector ("/" selector)* See the docstring of the epath() function. )_path_epathc t|tr|S|s td|}|ddk(r|dd}n tdg}|j dD]v}|j }|s tdd}|D]}|j s|dvr|dz }ng}g}|rt|d|} ||d}| j d D]V} | j } | s td | jd r|j| dd F|j| Xd} |d k(rn|jdr~ |jd} |d| g} } d| vr t| } nM| j ddD]0}|s| jd| jt|2t| } || dzd}|r td|j||| fytj|}||_||_|S#t$r tdwxYw)zConstruct new EPath. z empty EPathr/Nznon-root EPathzempty selector)_|?r z empty elementr *[]zexpected ']', got EOL:ztrailing characters in selector) isinstancer ValueErrorNotImplementedErrorsplitstripisalnumendswithappend startswithindexintsliceobject__new__rr)clspathrepathselectorrcattrstypeselementselementspani_spaneltobjs _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/simplify/epathtools.pyr!z EPath.__new__s@ dE "K]+ + 7c>8D%&67 7 3= /H~~'H !122E 99;!"6QJE   EE#FU+#EF+'~~c2 .G%mmoG"(99'', WSb\2 W- .D3&&s+B$NN3/#+1Q-4E%'"5z#(;;sA#66C#& $ D 1 $ CH 5 6 %d|'A/H$%FGG LL%- .{= /~nnS!   9&B()@AABs 'G--HcN|jjd|jdS)N()) __class____name__r)selfs r0__repr__zEPath.__repr__ts>>22DJJ??c|jr|jS|jr|jS|jS)z)Sort ``expr.args`` using printing order. )is_Addas_ordered_termsis_Mulas_ordered_factorsargs)r6exprs r0_get_ordered_argszEPath._get_ordered_argsws8 ;;((* * [[**, ,99 r8returnc,tfd|DS)z(Check if ``expr`` has any of ``attrs``. c36K|]}t|ywN)hasattr).0attrr?s r0 z"EPath._hasattrs..s9474&9s)all)r6r?r's ` r0 _hasattrszEPath._hasattrss95999r8c|jjDcgc]}|j}}tt |j |Scc}w)z'Check if ``expr`` is any of ``types``. )r4mror5boolset intersection)r6r?r(r"_typess r0 _hastypeszEPath._hastypessF+/>>+=+=+?AC3<<AACK,,U344BsAcb|s|sy|r|j||ry|r|j||ryy)z3Apply ``_hasattrs`` and ``_hastypes`` to ``expr``. TF)rJrQ)r6r?r'r(s r0_hasz EPath._hass3 T^^D%0 T^^D%0r8Nchfd|xsd|xsicfd}j||S)aj Modify parts of an expression selected by a path. Examples ======== >>> from sympy.simplify.epathtools import EPath >>> from sympy import sin, cos, E >>> from sympy.abc import x, y, z, t >>> path = EPath("/*/[0]/Symbol") >>> expr = [((x, 1), 2), ((3, y), z)] >>> path.apply(expr, lambda expr: expr**2) [((x**2, 1), 2), ((3, y**2), z)] >>> path = EPath("/*/*/Symbol") >>> expr = t + sin(x + 1) + cos(x + y + E) >>> path.apply(expr, lambda expr: 2*expr) t + sin(2*x + 1) + cos(2*x + 2*y + E) c,|s||S|d|dd}}|\}}}t|tr"|js j|d}}n|St |dr|d}}n|St |}|5t|t r!t|jt|} n|g} ntt|} | D])} || } j| ||s || ||| <+|r|j|S|j|S#t$rYYwxYw)Nrr T__iter__F)rris_Atomr@rElistrrangeindiceslen IndexErrorrSfuncr4)r#r?r]r%r'r(r+r>basicrZr,arg_applyr6s r0r`zEPath.apply.._applys0Dz!!%a$qr($%-"uddE*<<&*&<&>$//&! !s=D DDc|giSrDra)r?_args_kwargsr]s r0zEPath.apply..sT$::':r8r) r6r?r]r>kwargs_funcr`rcrds ` ` @@@r0applyz EPath.applys60' 0RV\rw:dkk4//r8cDgfdj|S)a  Retrieve parts of an expression selected by a path. Examples ======== >>> from sympy.simplify.epathtools import EPath >>> from sympy import sin, cos, E >>> from sympy.abc import x, y, z, t >>> path = EPath("/*/[0]/Symbol") >>> expr = [((x, 1), 2), ((3, y), z)] >>> path.select(expr) [x, y] >>> path = EPath("/*/*/Symbol") >>> expr = t + sin(x + 1) + cos(x + y + E) >>> path.select(expr) [x, x, y] cV|s j|y|d|dd}}|\}}}t|tr j|}nt |dr|}ny|t|t r||}n ||g}|D]} j|||s||!y#t $rYywxYw)Nrr rV)rrrr@rErr\rS) r#r?r%r'r(r+r>r__selectresultr6s r0rlzEPath.select.._selects d#!%a$qr($%-"uddE*11$7DT:.D#!$.#Dz#$(J>> from sympy.simplify.epathtools import epath >>> from sympy import sin, cos, E >>> from sympy.abc import x, y, z, t >>> path = "/*/[0]/Symbol" >>> expr = [((x, 1), 2), ((3, y), z)] >>> epath(path, expr) [x, y] >>> epath(path, expr, lambda expr: expr**2) [((x**2, 1), 2), ((3, y**2), z)] >>> path = "/*/*/Symbol" >>> expr = t + sin(x + 1) + cos(x + y + E) >>> epath(path, expr) [x, x, y] >>> epath(path, expr, lambda expr: 2*expr) t + sin(2*x + 1) + cos(2*x + 2*y + E) )rrnri)r#r?r]r>rgrs r0r$r$sAH4[F |  |}}T""||D$f55r8)NNNN)rq sympy.corerrr$rar8r0rus9LL^K6r8