#NEWLINE# def dihedral( n ) : #NEWLINE# #INDENT# "\n    Generates the dihedral group of order 2n, Dn.\n\n    The result is given as a subgroup of Sn, except for the special cases n=1\n    (the group S2) and n=2 (the Klein 4-group) where that's not possible\n    and embeddings in S2 and S4 respectively are given.\n\n    Examples\n    ========\n\n    >>> from sympy.combinatorics.permutations import Permutation\n    >>> Permutation.print_cyclic = True\n    >>> from sympy.combinatorics.generators import dihedral\n    >>> list(dihedral(3))\n    [(2), (0 2), (0 1 2), (1 2), (0 2 1), (2)(0 1)]\n\n    See Also\n    ========\n    cyclic\n    " #NEWLINE# if ( n == 1 ) : #NEWLINE# #INDENT# ( yield Permutation ( [ 0 , 1 ] ) ) #NEWLINE# ( yield Permutation ( [ 1 , 0 ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( n == 2 ) : #NEWLINE# #INDENT# ( yield Permutation ( [ 0 , 1 , 2 , 3 ] ) ) #NEWLINE# ( yield Permutation ( [ 1 , 0 , 3 , 2 ] ) ) #NEWLINE# ( yield Permutation ( [ 2 , 3 , 0 , 1 ] ) ) #NEWLINE# ( yield Permutation ( [ 3 , 2 , 1 , 0 ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# gen = list ( range ( n ) ) #NEWLINE# for i in range ( n ) : #NEWLINE# #INDENT# ( yield Permutation ( gen ) ) #NEWLINE# ( yield Permutation ( i [ : : ( - 1 ) ] ) ) #NEWLINE# gen = rotate_left ( gen , 1 )