code: def DihedralGroup(n):
      r"""
      Generates the dihedral group `D_n` as a permutation group.
  
      Explanation
      ===========
  
      The dihedral group `D_n` is the group of symmetries of the regular
      ``n``-gon. The generators taken are the ``n``-cycle ``a = (0 1 2 ... n-1)``
      (a rotation of the ``n``-gon) and ``b = (0 n-1)(1 n-2)...``
      (a reflection of the ``n``-gon) in cycle rotation. It is easy to see that
      these satisfy ``a**n = b**2 = 1`` and ``bab = ~a`` so they indeed generate
      `D_n` (See [1]). After the group is generated, some of its basic properties
      are set.
  
      Examples
      ========
  
      >>> from sympy.combinatorics.named_groups import DihedralGroup
      >>> G = DihedralGroup(5)
      >>> G.is_group
      True
      >>> a = list(G.generate_dimino())
      >>> [perm.cyclic_form for perm in a]
      [[], [[0, 1, 2, 3, 4]], [[0, 2, 4, 1, 3]],
      [[0, 3, 1, 4, 2]], [[0, 4, 3, 2, 1]], [[0, 4], [1, 3]],
      [[1, 4], [2, 3]], [[0, 1], [2, 4]], [[0, 2], [3, 4]],
      [[0, 3], [1, 2]]]
  
      See Also
      ========
  
      SymmetricGroup, CyclicGroup, AlternatingGroup
  
      References
      ==========
  
      .. [1] https://en.wikipedia.org/wiki/Dihedral_group
  
      """
      # small cases are special
      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 is a power of 2, group is nilpotent
      if n & (n - 1) == 0:
          G._is_nilpotent = True
      else:
          G._is_nilpotent = False
      G._is_dihedral = True
      G._is_abelian = False
      G._is_solvable = True
      G._degree = n
      G._is_transitive = True
      G._order = 2 * n
      return G
  
file_path: sympy/sympy/combinatorics/named_groups.py
imports: from sympy.combinatorics.group_constructs import DirectProduct
  from sympy.combinatorics.perm_groups import PermutationGroup
  from sympy.combinatorics.permutations import Permutation
label_desc: Use image node_id 5 for calling a global function with example usage: DihedralGroup(n) and returns: G, PermutationGroup, PermutationGroup