def DihedralGroup(n):
 if (n == 1):
  return PermutationGroup([Permutation([1, 0])])
 if (n == 2):
  return PermutationGroup([Permutation([1, 0, 3, 2]), Permutation([2, 3, 0, 1]), Permutation([3, 2, 1, 0])])
 a = list(range(1, n))
 a.append(0)
 gen1 = _af_new(a)
 a = list(range(n))
 a.reverse()
 gen2 = _af_new(a)
 G = PermutationGroup([gen1, gen2])
 if ((n & (n - 1)) == 0):
  G._is_nilpotent = True
 else:
  G._is_nilpotent = False
 G._is_abelian = False
 G._is_solvable = True
 G._degree = n
 G._is_transitive = True
 G._order = (2 * n)
 return G

def DihedralGroup ( n ) : if ( n == 1 ) : return PermutationGroup ( [ Permutation ( [ 1 , 0 ] ) ] ) if ( n == 2 ) : return PermutationGroup ( [ Permutation ( [ 1 , 0 , 3 , 2 ] ) , Permutation ( [ 2 , 3 , 0 , 1 ] ) , Permutation ( [ 3 , 2 , 1 , 0 ] ) ] ) a = list ( range ( 1 , n ) ) a . append ( 0 ) gen1 = _af_new ( a ) a = list ( range ( n ) ) a . reverse ( ) gen2 = _af_new ( a ) G = PermutationGroup ( [ gen1 , gen2 ] ) if ( ( n & ( n - 1 ) ) == 0 ) : G . _is_nilpotent = True else : G . _is_nilpotent = False G . _is_abelian = False G . _is_solvable = True G . _degree = n G . _is_transitive = True G . _order = ( 2 * n ) return G
generates the dihedral group d_n as a permutation group .