def DirectProduct(*groups):
 degrees = []
 gens_count = []
 total_degree = 0
 total_gens = 0
 for group in groups:
  current_deg = group.degree
  current_num_gens = len(group.generators)
  degrees.append(current_deg)
  total_degree += current_deg
  gens_count.append(current_num_gens)
  total_gens += current_num_gens
 array_gens = []
 for i in range(total_gens):
  array_gens.append(list(range(total_degree)))
 current_gen = 0
 current_deg = 0
 for i in range(len(gens_count)):
  for j in range(current_gen, (current_gen + gens_count[i])):
   gen = groups[i].generators[(j - current_gen)].array_form
   array_gens[j][current_deg:(current_deg + degrees[i])] = [(x + current_deg) for x in gen]
  current_gen += gens_count[i]
  current_deg += degrees[i]
 perm_gens = list(uniq([_af_new(list(a)) for a in array_gens]))
 return PermutationGroup(perm_gens, dups=False)

def DirectProduct ( * groups ) : degrees = [ ] gens_count = [ ] total_degree = 0 total_gens = 0 for group in groups : current_deg = group . degree current_num_gens = len ( group . generators ) degrees . append ( current_deg ) total_degree += current_deg gens_count . append ( current_num_gens ) total_gens += current_num_gens array_gens = [ ] for i in range ( total_gens ) : array_gens . append ( list ( range ( total_degree ) ) ) current_gen = 0 current_deg = 0 for i in range ( len ( gens_count ) ) : for j in range ( current_gen , ( current_gen + gens_count [ i ] ) ) : gen = groups [ i ] . generators [ ( j - current_gen ) ] . array_form array_gens [ j ] [ current_deg : ( current_deg + degrees [ i ] ) ] = [ ( x + current_deg ) for x in gen ] current_gen += gens_count [ i ] current_deg += degrees [ i ] perm_gens = list ( uniq ( [ _af_new ( list ( a ) ) for a in array_gens ] ) ) return PermutationGroup ( perm_gens , dups = False )
returns the direct product of several groups as a permutation group .