public class Element { public static int ALTS = 6; //max number of alternative expressions to store final int myNumber; final int conjCount; Element dual; //this field is used only if this Element is in a SelfDualModLattice Element [] conjugates; Term myTerm; //the defining term Term [] altTerms; //holds other expressions of the element int altsUsed; //number of alternative expressions available final ModLattice myLattice; public Element(ModLattice myLattice, char variable) //Any character except the lowercase v, the exponent symbol, //zero, and one may be a variable. { myNumber = myLattice.elementCount; conjCount = myLattice.auto; conjugates = new Element[conjCount]; myTerm = new Term(variable); altTerms = new Term[ALTS]; this.myLattice = myLattice; myLattice.elements[myLattice.elementCount++] = this; //When an element is created, it automatically installs itself in the lattice's element list. //System.out.println("Element made: " + myLattice.elementCount); } public Element(ModLattice myLattice, char operator, Element operand1, Element operand2) { myNumber = myLattice.elementCount; conjCount = myLattice.auto; conjugates = new Element[conjCount]; myTerm = new Term(operator, operand1, operand2); altTerms = new Term[ALTS]; this.myLattice = myLattice; myLattice.elements[myLattice.elementCount++] = this; //When an element is created, it automatically installs itself in the lattice's element list. //System.out.println("Element made: " + myLattice.elementCount); } public Element(ModLattice myLattice, Term aTerm) { myNumber = myLattice.elementCount; conjCount = myLattice.auto; conjugates = new Element[conjCount]; myTerm = aTerm; altTerms = new Term[ALTS]; this.myLattice = myLattice; myLattice.elements[myLattice.elementCount++] = this; //When an element is created, it automatically installs itself in the lattice's element list. //System.out.println("Element made: " + myLattice.elementCount); } Element(int number, int count, ModLattice myLattice) /* This constructor is intended to be used only for loading a lattice from a file. */ { myNumber = number; conjCount = count; conjugates = new Element[count]; altTerms = new Term[ALTS]; this.myLattice = myLattice; } public String toString() { return myTerm.toString(); } public String fullName() { String s1, s2; if (myTerm.op == 'v') { s1 = (myTerm.arg1.myTerm.op == '^') ? ("(" + myTerm.arg1.fullName() + ")") : myTerm.arg1.fullName(); s2 = (myTerm.arg2.myTerm.op == '^') ? ("(" + myTerm.arg2.fullName() + ")") : myTerm.arg2.fullName(); return s1 + " v " + s2; } else if (myTerm.op == '^') { s1 = (myTerm.arg1.myTerm.op == 'v') ? ("(" + myTerm.arg1.fullName() + ")") : myTerm.arg1.fullName(); s2 = (myTerm.arg2.myTerm.op == 'v') ? ("(" + myTerm.arg2.fullName() + ")") : myTerm.arg2.fullName(); return s1 + " ^ " + s2; } else return (new Character(myTerm.op)).toString(); } public void addAlt(char operator, Element operand1, Element operand2) { addAlt(new Term(operator, operand1, operand2)); } public void addAlt(Term aTerm) { if (altsUsed < ALTS) { for (int i = 0; i < altsUsed; i++) if (aTerm.equals(altTerms[i])) return; //don't want duplicates if (aTerm.equals(myTerm)) return; altTerms[altsUsed++] = aTerm; } } } //class Element