code: def purity(state, indices, check_state=False, c_dtype="complex128"):
      r"""Computes the purity of a density matrix.
  
      .. math::
          \gamma = \text{Tr}(\rho^2)
  
      where :math:`\rho` is the density matrix. The purity of a normalized quantum state satisfies
      :math:`\frac{1}{d} \leq \gamma \leq 1`, where :math:`d` is the dimension of the Hilbert space.
      A pure state has a purity of 1.
  
      It is possible to compute the purity of a sub-system from a given state. To find the purity of
      the overall state, include all wires in the ``indices`` argument.
  
      Args:
          state (tensor_like): Density matrix of shape ``(2**N, 2**N)`` or ``(batch_dim, 2**N, 2**N)``
          indices (list(int)): List of indices in the considered subsystem.
          check_state (bool): If ``True``, the function will check the state validity (shape and norm).
          c_dtype (str): Complex floating point precision type.
  
      Returns:
          float: Purity of the considered subsystem.
  
      **Example**
  
      >>> x = [[1/2, 0, 0, 1/2], [0, 0, 0, 0], [0, 0, 0, 0], [1/2, 0, 0, 1/2]]
      >>> purity(x, [0, 1])
      1.0
      >>> purity(x, [0])
      0.5
  
      >>> x = [[1/2, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 1/2]]
      >>> purity(x, [0, 1])
      0.5
  
      .. seealso:: :func:`pennylane.qinfo.transforms.purity`
      """
      # Cast as a c_dtype array
      state = cast(state, dtype=c_dtype)
  
      density_matrix = reduce_dm(state, indices, check_state)
      return _compute_purity(density_matrix)
  
imports: import itertools
  import functools
  from string import ascii_letters
  from autoray import numpy
  from numpy import float64
  import pennylane
  from .None import single_dispatch
  from .multi_dispatch import diag, dot, scatter_element_add, einsum, get_interface
  from .utils import is_abstract, allclose, cast, convert_like, cast_like
  from .matrix_manipulation import _permute_dense_matrix
label_desc: Use image node_id 8 for calling a global function with example usage: purity(state, indices, check_state, c_dtype) and returns: _compute_purity