code: def gradient(scalar_field, doit=True):
      """
      Returns the vector gradient of a scalar field computed wrt the
      base scalars of the given coordinate system.
  
      Parameters
      ==========
  
      scalar_field : SymPy Expr
          The scalar field to compute the gradient of
  
      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, gradient
      >>> R = CoordSys3D('R')
      >>> s1 = R.x*R.y*R.z
      >>> gradient(s1)
      R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
      >>> s2 = 5*R.x**2*R.z
      >>> gradient(s2)
      10*R.x*R.z*R.i + 5*R.x**2*R.k
  
      """
      coord_sys = _get_coord_systems(scalar_field)
  
      if len(coord_sys) == 0:
          return Vector.zero
      elif len(coord_sys) == 1:
          coord_sys = next(iter(coord_sys))
          h1, h2, h3 = coord_sys.lame_coefficients()
          i, j, k = coord_sys.base_vectors()
          x, y, z = coord_sys.base_scalars()
          vx = Derivative(scalar_field, x) / h1
          vy = Derivative(scalar_field, y) / h2
          vz = Derivative(scalar_field, z) / h3
  
          if doit:
              return (vx * i + vy * j + vz * k).doit()
          return vx * i + vy * j + vz * k
      else:
          if isinstance(scalar_field, (Add, VectorAdd)):
              return VectorAdd.fromiter(
                  gradient(i) for i in scalar_field.args
              )
          if isinstance(scalar_field, (Mul, VectorMul)):
              s = _split_mul_args_wrt_coordsys(scalar_field)
              return VectorAdd.fromiter(
                  scalar_field / i * gradient(i) for i in s
              )
          return Gradient(scalar_field)
  
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 5 for calling a global function with example usage: gradient(scalar_field, doit) and returns: Vector, unknown, Gradient, unknown, VectorAdd, VectorAdd