
    \h'                     2    S r SSKJr   " S S5      rSS jrg)z3Tools for manipulation of expressions using paths.     )Basicc                   X    \ rS rSrSrSrS rS rS rS\	4S jr
S	 rS
 rSS jrS rSrg)EPath   a  
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                    [        U[        5      (       a  U$ U(       d  [        S5      eUnUS   S:X  a  USS nO[        S5      e/ nUR	                  S5       GH  nUR                  5       nU(       d  [        S5      eSnU H%  nUR                  5       (       d  US;   a  US-  nM%    O   / n/ nU(       a  USU n	XES nU	R	                  S	5       Hb  n
U
R                  5       n
U
(       d  [        S
5      eU
R                  S5      (       a  UR                  U
SS 5        MQ  UR                  U
5        Md     SnUS:X  a  OUR                  S5      (       a   UR                  S5      nUSU / pSU;  a  [        U5      nOUUR	                  SS5       H7  nU(       d  UR                  S5        M  UR                  [        U5      5        M9     [        U6 nXLS-   S nU(       a  [        S5      eUR                  XxU45        GM     [        R                  U 5      nX/l        X?l        U$ ! [         a    [        S5      ef = f)zConstruct new EPath. zempty EPathr   /   Nznon-root EPathzempty selector)_|?r   zempty elementr   *[]zexpected ']', got EOL:   ztrailing characters in selector)
isinstancer   
ValueErrorNotImplementedErrorsplitstripisalnumendswithappend
startswithindexintsliceobject__new__r   r   )clspathr   epathselectorr   cattrstypeselementselementspani_spaneltobjs                   Q/var/www/auris/envauris/lib/python3.13/site-packages/sympy/simplify/epathtools.pyr"   EPath.__new__   s+   dE""K]++7c>8D%&677

3H~~'H !122E99;;!"6QJE	  EE#FU+#F+'~~c2G%mmoG"(99'',,WSb\2W-  3 D3&&s++B$NN3/ #+1Q-4%'"5z#(;;sA#6C#& $D 1 $CH 5	 $7  %d|'A/H$%FGGLL%-.{ (~ nnS!	

9 & B()@AABs   H))H?c                 R    U R                   R                  < SU R                  < S3$ )N())	__class____name__r   )selfs    r1   __repr__EPath.__repr__t   s    >>22DJJ??    c                     UR                   (       a  UR                  5       $ UR                  (       a  UR                  5       $ UR                  $ )z)Sort ``expr.args`` using printing order. )is_Addas_ordered_termsis_Mulas_ordered_factorsargs)r8   exprs     r1   _get_ordered_argsEPath._get_ordered_argsw   s8    ;;((**[[**,,99r;   returnc                 .   ^ [        U4S jU 5       5      $ )z(Check if ``expr`` has any of ``attrs``. c              3   <   >#    U  H  n[        TU5      v   M     g 7fN)hasattr).0attrrB   s     r1   	<genexpr>"EPath._hasattrs.<locals>.<genexpr>   s     95474&&5s   )all)r8   rB   r(   s    ` r1   	_hasattrsEPath._hasattrs   s    95999r;   c                     UR                   R                  5        Vs/ s H  o3R                  PM     nn[        [	        U5      R                  U5      5      $ s  snf )z'Check if ``expr`` is any of ``types``. )r6   mror7   boolsetintersection)r8   rB   r)   r#   _typess        r1   	_hastypesEPath._hastypes   sG    +/>>+=+=+?A+?C<<+?ACK,,U344 Bs   Ac                     U(       d  U(       d  gU(       a  U R                  X5      (       a  gU(       a  U R                  X5      (       a  gg)z3Apply ``_hasattrs`` and ``_hastypes`` to ``expr``. TF)rO   rW   )r8   rB   r(   r)   s       r1   _has
EPath._has   s5    T^^D00T^^D00r;   Nc                 ~   ^ ^^^^ UU 4S jmU=(       d    SU=(       d    0 smmUUU4S jnT" T R                   X5      $ )a  
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                 n  > U (       d  U" U5      $ U S   U SS  pUu  pEn[        U[        5      (       a&  UR                  (       d  TR                  U5      SpOU$ [	        US5      (       a  USpOU$ [        U5      nUb:  [        U[        5      (       a!  [        UR                  [        U5      5      6 n	OU/n	O[        [        U5      5      n	U	 H,  n
 Xz   nTR                  XU5      (       d  M!  T" XU5      Xz'   M.     U(       a  UR                  " U6 $ UR                  U5      $ ! [         a     Md  f = f)Nr   r   T__iter__F)r   r   is_AtomrC   rI   listr    rangeindiceslen
IndexErrorrZ   funcr6   )r$   rB   re   r&   r(   r)   r,   rA   basicrb   r-   arg_applyr8   s               r1   rh   EPath.apply.<locals>._apply   s%   Dz!!%a$qr($%-"ddE**<<&*&<&<T&BDe#T:.."&%KDz#!$.."'c$i)@"A#'&#CI.G A!"g yyU33"(D"9 ! 99d++>>$// & ! !s   D&&
D43D4 c                    > T" U /TQ70 TD6$ rH   rj   )rB   _args_kwargsre   s    r1   <lambda>EPath.apply.<locals>.<lambda>   s    T$::':r;   r   )	r8   rB   re   rA   kwargs_funcrh   rl   rm   s	   ` `   @@@r1   applyEPath.apply   s4    0'	0R V\rw:dkk4//r;   c                 F   ^ ^^ / mUUU 4S jmT" T R                   U5        T$ )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]

c                   > U (       d  T	R                  U5        g U S   U SS  pUu  p4n[        U[        5      (       a  T
R                  U5      nO[	        US5      (       a  UnOg Ub   [        U[
        5      (       a  Xe   nO Xe   /nU H$  nT
R                  XsU5      (       d  M  T" X5        M&     g ! [         a     g f = f)Nr   r   r^   )r   r   r   rC   rI   r    rd   rZ   )r$   rB   r&   r(   r)   r,   rA   rg   _selectresultr8   s           r1   rw   EPath.select.<locals>._select   s    d#!%a$qr($%-"ddE**11$7DT:..D#!$..#z#$(J<D  CyyU33*    * #"#s   B3 3
C ?C rp   )r8   rB   rw   rx   s   ` @@r1   selectEPath.select   s$    0 	+6 	T"r;   rj   )NN)r7   
__module____qualname____firstlineno____doc__	__slots__r"   r9   rC   rS   rO   rW   rZ   rs   rz   __static_attributes__rj   r;   r1   r   r      sB    ( $IUn@: :5
D0L6r;   r   Nc                 n    [        U 5      nUc  U$ Uc  UR                  U5      $ UR                  XX45      $ )a@  
Manipulate parts of an expression selected by a path.

Explanation
===========

This function allows to manipulate large nested expressions in single
line of code, utilizing techniques to those applied in XML processing
standards (e.g. XPath).

If ``func`` is ``None``, :func:`epath` retrieves elements selected by
the ``path``. Otherwise it applies ``func`` to each matching element.

Note that it is more efficient to create an EPath object and use the select
and apply methods of that object, since this will compile the path string
only once.  This function should only be used as a convenient shortcut for
interactive use.

This is the supported syntax:

* select all: ``/*``
      Equivalent of ``for arg in args:``.
* select slice: ``/[0]`` or ``/[1:5]`` or ``/[1:5:2]``
      Supports standard Python's slice syntax.
* select by type: ``/list`` or ``/list|tuple``
      Emulates ``isinstance()``.
* select by attribute: ``/__iter__?``
      Emulates ``hasattr()``.

Parameters
==========

path : str | EPath
    A path as a string or a compiled EPath.
expr : Basic | iterable
    An expression or a container of expressions.
func : callable (optional)
    A callable that will be applied to matching parts.
args : tuple (optional)
    Additional positional arguments to ``func``.
kwargs : dict (optional)
    Additional keyword arguments to ``func``.

Examples
========

>>> 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)

)r   rz   rs   )r$   rB   re   rA   rq   r   s         r1   r%   r%     s=    H 4[F||}}T""||D55r;   )NNNN)r   
sympy.corer   r   r%   rj   r;   r1   <module>r      s    9 L L^K6r;   