class_docstr: 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.
class_docstr_tok: ["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","."]
docstr: 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)
docstr_tok: ["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",")"]
code: def apply(self, expr, func, args=None, kwargs=None):
      """
      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)
  
      """
  
      def _apply(path, expr, func):
          if not path:
              return func(expr)
          else:
              selector, path = path[0], path[1:]
              attrs, types, span = selector
  
              if isinstance(expr, Basic):
                  if not expr.is_Atom:
                      args, basic = self._get_ordered_args(expr), True
                  else:
                      return expr
              elif hasattr(expr, "__iter__"):
                  args, basic = expr, False
              else:
                  return expr
  
              args = list(args)
  
              if span is not None:
                  if isinstance(span, slice):
                      indices = range(*span.indices(len(args)))
                  else:
                      indices = [span]
              else:
                  indices = range(len(args))
  
              for i in indices:
                  try:
                      arg = args[i]
                  except IndexError:
                      continue
  
                  if self._has(arg, attrs, types):
                      args[i] = _apply(path, arg, func)
  
              if basic:
                  return expr.func(*args)
              else:
                  return expr.__class__(args)
  
      _args, _kwargs = args or (), kwargs or {}
      _func = lambda expr: func(expr, *_args, **_kwargs)
  
      return _apply(self._epath, expr, _func)
  
file_path: sympy/sympy/simplify/epathtools.py
imports: from sympy.core import Basic
label_desc: Use image node_id 7 for calling the EPath obj's underlying member method code with example usage: obj.apply(expr, func, args, kwargs) and returns: _apply, func, expr, expr, expr, expr