code: def remove_ids(mul):
      """Remove Identities from a MatMul
  
      This is a modified version of sympy.strategies.rm_id.
      This is necesssary because MatMul may contain both MatrixExprs and Exprs
      as args.
  
      See Also
      ========
  
      sympy.strategies.rm_id
      """
      # Separate Exprs from MatrixExprs in args
      factor, mmul = mul.as_coeff_mmul()
      # Apply standard rm_id for MatMuls
      result = rm_id(lambda x: x.is_Identity is True)(mmul)
      if result != mmul:
          return newmul(factor, *result.args)  # Recombine and return
      else:
          return mul
  
imports: from sympy.assumptions.ask import ask, Q
  from sympy.assumptions.refine import handlers_dict
  from sympy.core import Basic, sympify, S
  from sympy.core.mul import mul, Mul
  from sympy.core.numbers import Number, Integer
  from sympy.core.symbol import Dummy
  from sympy.functions import adjoint
  from sympy.strategies import rm_id, unpack, typed, flatten, exhaust, do_one, new
  from sympy.matrices.exceptions import NonInvertibleMatrixError
  from sympy.matrices.matrixbase import MatrixBase
  from sympy.utilities.exceptions import sympy_deprecation_warning
  from sympy.matrices.expressions._shape import validate_matmul_integer
  from .inverse import Inverse
  from .matexpr import MatrixExpr
  from .matpow import MatPow
  from .transpose import transpose
  from .permutation import PermutationMatrix
  from .special import ZeroMatrix, Identity, GenericIdentity, OneMatrix
label_desc: Use image node_id 4 for calling a global function with example usage: remove_ids(mul) and returns: newmul, mul