All Downloads are FREE. Search and download functionalities are using the official Maven repository.

JSci.maths.categories.FinSet Maven / Gradle / Ivy

Go to download

JSci is a set of open source Java packages. The aim is to encapsulate scientific methods/principles in the most natural way possible. As such they should greatly aid the development of scientific based software. It offers: abstract math interfaces, linear algebra (support for various matrix and vector types), statistics (including probability distributions), wavelets, newtonian mechanics, chart/graph components (AWT and Swing), MathML DOM implementation, ... Note: some packages, like javax.comm, for the astro and instruments package aren't listed as dependencies (not available).

The newest version!
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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy