1 package JSci.maths.categories; 2 3 import JSci.maths.*; 4 5 10 public final class Simplicial extends Object implements Category { 11 public final Bifunctor ADDITION=new Addition(); 12 15 public Simplicial() {} 16 19 public Category.Morphism identity(Object a) { 20 Preorder p=(Preorder)a; 21 Integer id[]=new Integer [p.ordinal()]; 22 for(int i=0;i<id.length;i++) 23 id[i]=new Integer (i); 24 return new IncreasingMap(p,id); 25 } 26 29 public Object cardinality(Object a) { 30 return new MathInteger(((Preorder)a).ordinal()); 31 } 32 35 public Category.HomSet hom(Object a,Object b) { 36 return new FunctionSet((Preorder)a,(Preorder)b); 37 } 38 public Object terminal() { 39 return new Preorder(1); 40 } 41 public class FunctionSet implements Category.HomSet { 42 private final Preorder from,to; 43 public FunctionSet(Preorder a,Preorder b) { 44 from=a; 45 to=b; 46 } 47 public int cardinality() { 48 return (int)ExtraMath.binomial(from.ordinal()+to.ordinal()-1,from.ordinal()); 49 } 50 } 51 public class IncreasingMap implements Functor { 52 protected final Preorder from,to; 53 protected final Integer out[]; 54 public IncreasingMap(Preorder toObj,Integer toImg[]) { 55 from=new Preorder(toImg.length); 56 to=toObj; 57 out=toImg; 58 } 59 public Object domain() { 60 return from; 61 } 62 public Object codomain() { 63 return to; 64 } 65 public Object map(Object o) { 66 return out[((Integer )o).intValue()]; 67 } 68 public Category.Morphism map(Category.Morphism m) { 69 return ((Preorder.RelationSet)to.hom(map(m.domain()),map(m.codomain()))).morphism; 70 } 71 public Category.Morphism compose(Category.Morphism m) { 72 return compose((Functor)m); 73 } 74 public Functor compose(Functor f) { 75 if(f instanceof IncreasingMap) { 76 IncreasingMap im=(IncreasingMap)f; 77 if(to.equals(im.from)) { 78 Integer outImg[]=new Integer [out.length]; 79 for(int i=0;i<outImg.length;i++) 80 outImg[i]=(Integer )im.map(out[i]); 81 return new IncreasingMap(im.to,outImg); 82 } else 83 throw new UndefinedCompositionException(); 84 } else 85 throw new IllegalArgumentException ("Morphism is not an IncreasingMap."); 86 } 87 } 88 public final class FaceMap extends IncreasingMap { 89 private final int skip; 90 public FaceMap(Preorder toObj,int i) { 91 super(toObj,new Integer [toObj.ordinal()-1]); 92 skip=i; 93 for(i=0;i<skip;i++) 94 out[i]=new Integer (i); 95 for(;i<out.length;i++) 96 out[i]=new Integer (i+1); 97 } 98 } 99 public final class DegeneracyMap extends IncreasingMap { 100 private final int repeat; 101 public DegeneracyMap(Preorder toObj,int i) { 102 super(toObj,new Integer [toObj.ordinal()+1]); 103 repeat=i; 104 for(i=0;i<=repeat;i++) 105 out[i]=new Integer (i); 106 for(;i<out.length;i++) 107 out[i]=new Integer (i-1); 108 } 109 } 110 public final class Addition implements Bifunctor { 111 public Addition() {} 112 public Object map(Object a,Object b) { 113 return new Preorder(((Preorder)a).ordinal()+((Preorder)b).ordinal()); 114 } 115 public Category.Morphism map(Category.Morphism m, Category.Morphism n) { 116 IncreasingMap im=(IncreasingMap)m; 117 IncreasingMap in=(IncreasingMap)n; 118 Preorder to=new Preorder(im.to.ordinal()+in.to.ordinal()); 119 Integer toObj[]=new Integer [im.out.length+in.out.length]; 120 int i; 121 for(i=0;i<im.out.length;i++) 122 toObj[i]=im.out[i]; 123 for(;i<toObj.length;i++) 124 toObj[i]=in.out[i]; 125 return new IncreasingMap(to,toObj); 126 } 127 } 128 } 129 130 | Popular Tags |