001: package JSci.maths.categories;
002:
003: import JSci.maths.*;
004:
005: /**
006: * The Simplicial class encapsulates the simplicial category.
007: * @version 1.0
008: * @author Mark Hale
009: */
010: public final class Simplicial extends Object implements Category {
011: public final Bifunctor ADDITION = new Addition();
012:
013: /**
014: * Constructs a simplicial category.
015: */
016: public Simplicial() {
017: }
018:
019: /**
020: * Returns the identity morphism for an object.
021: */
022: public Category.Morphism identity(Object a) {
023: Preorder p = (Preorder) a;
024: Integer id[] = new Integer[p.ordinal()];
025: for (int i = 0; i < id.length; i++)
026: id[i] = new Integer(i);
027: return new IncreasingMap(p, id);
028: }
029:
030: /**
031: * Returns the cardinality of an object.
032: */
033: public Object cardinality(Object a) {
034: return new MathInteger(((Preorder) a).ordinal());
035: }
036:
037: /**
038: * Returns a hom-set.
039: */
040: public Category.HomSet hom(Object a, Object b) {
041: return new FunctionSet((Preorder) a, (Preorder) b);
042: }
043:
044: public Object terminal() {
045: return new Preorder(1);
046: }
047:
048: public class FunctionSet implements Category.HomSet {
049: private final Preorder from, to;
050:
051: public FunctionSet(Preorder a, Preorder b) {
052: from = a;
053: to = b;
054: }
055:
056: public int cardinality() {
057: return (int) ExtraMath.binomial(from.ordinal()
058: + to.ordinal() - 1, from.ordinal());
059: }
060: }
061:
062: public class IncreasingMap implements Functor {
063: protected final Preorder from, to;
064: protected final Integer out[];
065:
066: public IncreasingMap(Preorder toObj, Integer toImg[]) {
067: from = new Preorder(toImg.length);
068: to = toObj;
069: out = toImg;
070: }
071:
072: public Object domain() {
073: return from;
074: }
075:
076: public Object codomain() {
077: return to;
078: }
079:
080: public Object map(Object o) {
081: return out[((Integer) o).intValue()];
082: }
083:
084: public Category.Morphism map(Category.Morphism m) {
085: return ((Preorder.RelationSet) to.hom(map(m.domain()),
086: map(m.codomain()))).morphism;
087: }
088:
089: public Category.Morphism compose(Category.Morphism m) {
090: return compose((Functor) m);
091: }
092:
093: public Functor compose(Functor f) {
094: if (f instanceof IncreasingMap) {
095: IncreasingMap im = (IncreasingMap) f;
096: if (to.equals(im.from)) {
097: Integer outImg[] = new Integer[out.length];
098: for (int i = 0; i < outImg.length; i++)
099: outImg[i] = (Integer) im.map(out[i]);
100: return new IncreasingMap(im.to, outImg);
101: } else
102: throw new UndefinedCompositionException();
103: } else
104: throw new IllegalArgumentException(
105: "Morphism is not an IncreasingMap.");
106: }
107: }
108:
109: public final class FaceMap extends IncreasingMap {
110: private final int skip;
111:
112: public FaceMap(Preorder toObj, int i) {
113: super (toObj, new Integer[toObj.ordinal() - 1]);
114: skip = i;
115: for (i = 0; i < skip; i++)
116: out[i] = new Integer(i);
117: for (; i < out.length; i++)
118: out[i] = new Integer(i + 1);
119: }
120: }
121:
122: public final class DegeneracyMap extends IncreasingMap {
123: private final int repeat;
124:
125: public DegeneracyMap(Preorder toObj, int i) {
126: super (toObj, new Integer[toObj.ordinal() + 1]);
127: repeat = i;
128: for (i = 0; i <= repeat; i++)
129: out[i] = new Integer(i);
130: for (; i < out.length; i++)
131: out[i] = new Integer(i - 1);
132: }
133: }
134:
135: public final class Addition implements Bifunctor {
136: public Addition() {
137: }
138:
139: public Object map(Object a, Object b) {
140: return new Preorder(((Preorder) a).ordinal()
141: + ((Preorder) b).ordinal());
142: }
143:
144: public Category.Morphism map(Category.Morphism m,
145: Category.Morphism n) {
146: IncreasingMap im = (IncreasingMap) m;
147: IncreasingMap in = (IncreasingMap) n;
148: Preorder to = new Preorder(im.to.ordinal()
149: + in.to.ordinal());
150: Integer toObj[] = new Integer[im.out.length + in.out.length];
151: int i;
152: for (i = 0; i < im.out.length; i++)
153: toObj[i] = im.out[i];
154: for (; i < toObj.length; i++)
155: toObj[i] = in.out[i];
156: return new IncreasingMap(to, toObj);
157: }
158: }
159: }
|