package jsci.maths.categories;

import jsci.maths.*;

/**
* The FinSet class encapsulates the category FinSet.
* @version 1.0
* @author Mark Hale
*/
public class FinSet extends Object implements Category {
        /**
        * Constructs a FinSet category.
        */
        public FinSet() {}
        /**
        * Returns the identity morphism for an object.
        */
        public Category.Morphism identity(Object a) {
                return new IdentityFunction((MathSet)a);
        }
        /**
        * Returns the cardinality of an object.
        */
        public Object cardinality(Object a) {
                return new MathInteger(((MathSet)a).cardinality());
        }
        /**
        * Returns a hom-set.
        */
        public Category.HomSet hom(Object a,Object b) {
                return new FunctionSet((MathSet)a,(MathSet)b);
        }
        public class FunctionSet implements MathSet, Category.HomSet {
                private final MathSet from,to;
                private final int size;
                public FunctionSet(MathSet a,MathSet b) {
                        from=a;
                        to=b;
                        size=ExtraMath.pow(b.cardinality(),a.cardinality());
                }
                /**
                * Returns an element of this hom-set.
                */
                public Function getElement(Object in[],Object out[]) {
                        return new Function(from,to,in,out);
                }
                public int cardinality() {
                        return size;
                }
                public MathSet union(MathSet set) {
                        return set.union(this);
                }
                public MathSet intersect(MathSet set) {
                        return set.intersect(this);
                }
        }
        public class Function implements Category.Morphism {
                private final MathSet from,to;
                private final Object in[],out[];
                public Function(MathSet a,MathSet b,Object inObjs[],Object outObjs[]) {
                        from=a;
                        to=b;
                        in=inObjs;
                        out=outObjs;
                }
                public Object domain() {
                        return from;
                }
                public Object codomain() {
                        return to;
                }
                public Object map(Object o) {
                        for(int i=0;i 

Ads help maintain this website.