code: def divergence(vect, doit=True):
      """
      Returns the divergence of a vector field computed wrt the base
      scalars of the given coordinate system.
  
      Parameters
      ==========
  
      vector : Vector
          The vector operand
  
      doit : bool
          If True, the result is returned after calling .doit() on
          each component. Else, the returned expression contains
          Derivative instances
  
      Examples
      ========
  
      >>> from sympy.vector import CoordSys3D, divergence
      >>> R = CoordSys3D('R')
      >>> v1 = R.x*R.y*R.z * (R.i+R.j+R.k)
  
      >>> divergence(v1)
      R.x*R.y + R.x*R.z + R.y*R.z
      >>> v2 = 2*R.y*R.z*R.j
      >>> divergence(v2)
      2*R.z
  
      """
      coord_sys = _get_coord_systems(vect)
      if len(coord_sys) == 0:
          return S.Zero
      elif len(coord_sys) == 1:
          if isinstance(vect, (Cross, Curl, Gradient)):
              return Divergence(vect)
          # TODO: is case of many coord systems, this gets a random one:
          coord_sys = next(iter(coord_sys))
          i, j, k = coord_sys.base_vectors()
          x, y, z = coord_sys.base_scalars()
          h1, h2, h3 = coord_sys.lame_coefficients()
          vx = _diff_conditional(vect.dot(i), x, h2, h3) / (
              h1 * h2 * h3
          )
          vy = _diff_conditional(vect.dot(j), y, h3, h1) / (
              h1 * h2 * h3
          )
          vz = _diff_conditional(vect.dot(k), z, h1, h2) / (
              h1 * h2 * h3
          )
          res = vx + vy + vz
          if doit:
              return res.doit()
          return res
      else:
          if isinstance(vect, (Add, VectorAdd)):
              return Add.fromiter(
                  divergence(i, doit=doit) for i in vect.args
              )
          elif isinstance(vect, (Mul, VectorMul)):
              vector = [
                  i
                  for i in vect.args
                  if isinstance(i, (Vector, Cross, Gradient))
              ][0]
              scalar = Mul.fromiter(
                  i
                  for i in vect.args
                  if not isinstance(i, (Vector, Cross, Gradient))
              )
              res = Dot(vector, gradient(scalar)) + scalar * divergence(
                  vector, doit=doit
              )
              if doit:
                  return res.doit()
              return res
          elif isinstance(vect, (Cross, Curl, Gradient)):
              return Divergence(vect)
          else:
              raise Divergence(vect)
  
imports: import collections
  from sympy.core.expr import Expr
  from sympy.core import sympify, S, preorder_traversal
  from sympy.vector.coordsysrect import CoordSys3D
  from sympy.vector.vector import Vector, VectorMul, VectorAdd, Cross, Dot
  from sympy.core.function import Derivative
  from sympy.core.add import Add
  from sympy.core.mul import Mul
label_desc: Use image node_id 4 for calling a global function with example usage: divergence(vect, doit) and returns: S, res, Divergence, res, Add, res, res, Divergence