code: def decompose_space(H, A):
      
      return OperatorTrace.create(
          OperatorTrace.create(A, over_space=H.operands[-1]),
          over_space=ProductSpace.create(*H.operands[:-1]))
docs: Simplifies OperatorTrace expressions over tensor-product spaces by
      turning it into iterated partial traces.
  
      Args:
          H (ProductSpace): The full space.
          A (Operator):
  
      Returns:
          Operator: Iterative partial trace expression