def det_perm(M):
 args = []
 s = True
 n = M.rows
 try:
  list = M._mat
 except AttributeError:
  list = flatten(M.tolist())
 for perm in generate_bell(n):
  fac = []
  idx = 0
  for j in perm:
   fac.append(list[(idx + j)])
   idx += n
  term = Mul(*fac)
  args.append((term if s else (- term)))
  s = (not s)
 return Add(*args)

def det_perm ( M ) : args = [ ] s = True n = M . rows try : list = M . _mat except AttributeError : list = flatten ( M . tolist ( ) ) for perm in generate_bell ( n ) : fac = [ ] idx = 0 for j in perm : fac . append ( list [ ( idx + j ) ] ) idx += n term = Mul ( * fac ) args . append ( ( term if s else ( - term ) ) ) s = ( not s ) return Add ( * args )
return the det(m) by using permutations to select factors .