1 package JSci.maths.groups; 2 3 10 public final class DihedralGroup extends FiniteGroup { 11 14 private final int n; 15 18 private final Member ONE; 19 23 public DihedralGroup(int n) { 24 super(2*n); 25 this.n = n; 26 ONE = new Member(0, false); 27 } 28 31 public boolean equals(Object o) { 32 return (o instanceof DihedralGroup) && (((DihedralGroup)o).order == order); 33 } 34 public int hashCode() { 35 return order; 36 } 37 public String toString() { 38 return "D_"+n; 39 } 40 43 public Group.Member[] getElements() { 44 Group.Member elements[] = new Group.Member[order]; 45 for(int i=0; i<n; i++) { 46 elements[i] = new Member(i, false); 47 elements[i+n] = new Member(i, true); 48 } 49 return elements; 50 } 51 54 public Monoid.Member identity() { 55 return ONE; 56 } 57 61 public boolean isIdentity(Monoid.Member a) { 62 return a.equals(ONE); 63 } 64 69 public boolean isInverse(Group.Member a, Group.Member b) { 70 return (a instanceof Member) && (b instanceof Member) && a.compose(b).equals(ONE); 71 } 72 class Member implements Group.Member { 73 74 private final int rotate; 75 private final boolean reflect; 76 77 public Member(int theta, boolean flip) { 78 rotate = (theta<0) ? theta%n+n : theta%n; 79 reflect = flip; 80 } 81 84 public boolean equals(Object o) { 85 return (o instanceof Member) && (rotate == ((Member)o).rotate) && (reflect == ((Member)o).reflect); 86 } 87 public int hashCode() { 88 return 2*rotate + (reflect ? 1 : 0); 89 } 90 public Object getSet() { 91 return DihedralGroup.this; 92 } 93 97 public Semigroup.Member compose(Semigroup.Member g) { 98 if(reflect) 99 return new Member(rotate-((Member)g).rotate, !((Member)g).reflect); 100 else 101 return new Member(rotate+((Member)g).rotate, ((Member)g).reflect); 102 } 103 106 public Group.Member inverse() { 107 return new Member(-rotate, !reflect); 108 } 109 } 110 } 111 112 | Popular Tags |