001: package JSci.maths.categories;
002:
003: import JSci.maths.*;
004: import JSci.maths.matrices.AbstractComplexMatrix;
005: import JSci.maths.matrices.ComplexMatrix;
006: import JSci.maths.matrices.ComplexDiagonalMatrix;
007: import JSci.maths.vectors.AbstractComplexVector;
008: import JSci.maths.algebras.*;
009: import JSci.maths.fields.*;
010: import JSci.maths.groups.AbelianGroup;
011:
012: /**
013: * The Hilb class encapsulates the category <b>Hilb</b>.
014: * @version 1.0
015: * @author Mark Hale
016: */
017: public class Hilb extends Object implements Category {
018: /**
019: * Constructs a <b>Hilb</b> category.
020: */
021: public Hilb() {
022: }
023:
024: /**
025: * Returns the identity morphism for an object.
026: * @param a a HilbertSpace.
027: */
028: public Category.Morphism identity(Object a) {
029: return new LinearMap(ComplexDiagonalMatrix
030: .identity(((HilbertSpace) a).dimension()));
031: }
032:
033: /**
034: * Returns the cardinality of an object.
035: * @param a a HilbertSpace.
036: */
037: public Object cardinality(Object a) {
038: return new MathInteger(((HilbertSpace) a).dimension());
039: }
040:
041: /**
042: * Returns a hom-set.
043: * @param a a HilbertSpace.
044: * @param b a HilbertSpace.
045: * @return a HilbertSpace.
046: */
047: public Category.HomSet hom(Object a, Object b) {
048: return new OperatorSpace((HilbertSpace) a, (HilbertSpace) b);
049: }
050:
051: public class OperatorSpace extends HilbertSpace implements
052: Category.HomSet {
053: private final int rows, cols;
054:
055: public OperatorSpace(HilbertSpace a, HilbertSpace b) {
056: super (a.dimension() * b.dimension());
057: rows = b.dimension();
058: cols = a.dimension();
059: }
060:
061: /**
062: * Returns an element of this hom-set.
063: */
064: public VectorSpace.Member getVector(Complex array[][]) {
065: return new LinearMap(array);
066: }
067: }
068:
069: public class LinearMap implements BanachSpace.Member,
070: Category.Morphism {
071: private AbstractComplexMatrix matrix;
072:
073: public LinearMap(Complex array[][]) {
074: matrix = new ComplexMatrix(array);
075: }
076:
077: public LinearMap(AbstractComplexMatrix m) {
078: matrix = m;
079: }
080:
081: public Object domain() {
082: return new HilbertSpace(matrix.columns());
083: }
084:
085: public Object codomain() {
086: return new HilbertSpace(matrix.rows());
087: }
088:
089: public Object map(Object v) {
090: return matrix.multiply((AbstractComplexVector) v);
091: }
092:
093: public Category.Morphism compose(Category.Morphism m) {
094: if (m instanceof LinearMap) {
095: LinearMap lm = (LinearMap) m;
096: if (matrix.columns() == lm.matrix.rows())
097: return new LinearMap(lm.matrix.multiply(matrix));
098: else
099: throw new UndefinedCompositionException();
100: } else
101: throw new IllegalArgumentException(
102: "Morphism is not a LinearMap.");
103: }
104:
105: public double norm() {
106: return matrix.frobeniusNorm();
107: }
108:
109: public int dimension() {
110: return matrix.rows() * matrix.columns();
111: }
112:
113: public Object getSet() {
114: return matrix.getSet();
115: }
116:
117: public AbelianGroup.Member add(final AbelianGroup.Member m) {
118: if (m instanceof LinearMap)
119: return new LinearMap(matrix.add(((LinearMap) m).matrix));
120: else
121: throw new IllegalArgumentException(
122: "Member class not recognised by this method.");
123: }
124:
125: public AbelianGroup.Member negate() {
126: return new LinearMap((AbstractComplexMatrix) matrix
127: .negate());
128: }
129:
130: public AbelianGroup.Member subtract(final AbelianGroup.Member m) {
131: if (m instanceof LinearMap)
132: return new LinearMap(matrix
133: .subtract(((LinearMap) m).matrix));
134: else
135: throw new IllegalArgumentException(
136: "Member class not recognised by this method.");
137: }
138:
139: public Module.Member scalarMultiply(Ring.Member z) {
140: if (z instanceof Complex)
141: return new LinearMap(matrix.scalarMultiply((Complex) z));
142: else
143: throw new IllegalArgumentException(
144: "Member class not recognised by this method.");
145: }
146:
147: public VectorSpace.Member scalarDivide(Field.Member z) {
148: if (z instanceof Complex)
149: return new LinearMap(matrix.scalarMultiply((Complex) z));
150: else
151: throw new IllegalArgumentException(
152: "Member class not recognised by this method.");
153: }
154: }
155: }
|