/* Research Project: Graphical Database for Category Theory J. Bradbury, Dr. R. Rosebrugh, I. Rutherford M. Graves, J. Tweedle Mount Allison University 2001 Updated: May 8th, 2003 File: Sum.java Description: This class contains the algorithms to test a category for sums. It is used only by the SumFrame class. */ public class Sum { private Category cat; private IniSettings ini; private int editoption; private int obj; private int alpha[]; private int beta[]; private int numsums; private String output; private String type; private boolean supress_output; private boolean endopassed; public static final int NOT_AN_OBJECT = 0; public static final int INVALID_FIRST_DOMAIN = -1; public static final int INVALID_FIRST_PATH = -2; public static final int INVALID_SECOND_DOMAIN = -3; public static final int INVALID_SECOND_PATH = -4; public static final int SUM = -5; public static final int NOT_SUM = -6; public Sum(Category newCat, String newType) { cat = newCat; ini = cat.ini; output = ""; type = newType; numsums = 0; supress_output = false; endopassed = false; alpha = new int [ini.getMAXWORD()]; beta = new int [ini.getMAXWORD()]; } //---------------- //sum (product) METHODS //---------------- public boolean is_sum(int sumobj, int alpha[], int beta[], int maxloop) /* Parameters: sumobj: the object of the sum being tested alpha: first projection of the sum beta: second projection of the sum Local Variables: testobj: is currently being tested for sum property path: keeps track of the current path to testobj from sumobj objects: array of integers storing the number of times each object has been visited in current path id: a path that has a value of -2 and represents the identity arrow gammatree: tree of all arrows from sumobj to testobj gamalbet: tree of gamma alphas with gamma beta subtrees rhotree: tree of all arrows from domain of beta to testobj p, tp: temporary pointers reduced_alpha, reduced_beta : normalized versions of the projections Purpose: To check each object in the category for 1-1 and onto. Design: Returns true if object is a sum, and false if not. */ { int path[] = new int[ini.getMAXWORD()]; int id[] = new int[2]; int reducedAlpha[] = new int[ini.getMAXWORD()]; int reducedBeta[] = new int[ini.getMAXWORD()]; HomTree gamalbet; // all paths from all Paths A to C composed with gamma(C->D) HomTree gammatree;//all paths from C -> D HomTree rhotree;//all paths from B to D (will be bigger than gammalbet) HomTree pathtree; int obj, i, dom; // obj is test object // check each object in the category for (obj=0; obj= 0 && cat.arr[alpha[0]][1] != obj) { output += "First path must have domain of " + cat.obj[obj] + "."; return INVALID_FIRST_DOMAIN; } else { editoption = 2; } } else { output += "Invalid first path."; return INVALID_FIRST_PATH; } } else { output += "Invalid first path."; return INVALID_FIRST_PATH; } } if (editoption == 2) { if ((cat.check_string(betapath))) { beta = cat.copy_path(cat.string_to_path(betapath)); if (cat.check_path(beta)) { if (beta[0] >= 0 && cat.arr[beta[0]][1] != obj) { output += "Second path must have domain of " + cat.obj[obj] + "."; return INVALID_SECOND_DOMAIN; } else { if (is_sum(obj,alpha,beta,ini.getMaxLoop())) { output += cat.obj[obj] + " is a " + type + "."; return SUM; } else { output += cat.obj[obj] + " is not a " + type + "."; return NOT_SUM; } } } else { output += "Invalid second path."; return INVALID_SECOND_PATH; } } else { output += "Invalid second path."; return INVALID_SECOND_PATH; } } return this.getNumSums(); } public int getNumSums() { return numsums; } public void setNumSums(int newNumSums) { numsums = newNumSums; } public String getOutput() { return output; } public void setOutput(String newOutput) { output = newOutput; } public boolean getSupressOutput() { return supress_output; } public void setSupressOutput(boolean newSupressOutput) { supress_output = newSupressOutput; } public boolean getEndoPassed() { return endopassed; } public void setEndoPassed(boolean newEndoPassed) { endopassed = newEndoPassed; } }