KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > categories > Hilb


1 package JSci.maths.categories;
2
3 import JSci.maths.*;
4 import JSci.maths.matrices.AbstractComplexMatrix;
5 import JSci.maths.matrices.ComplexMatrix;
6 import JSci.maths.matrices.ComplexDiagonalMatrix;
7 import JSci.maths.vectors.AbstractComplexVector;
8 import JSci.maths.algebras.*;
9 import JSci.maths.fields.*;
10 import JSci.maths.groups.AbelianGroup;
11
12 /**
13 * The Hilb class encapsulates the category <b>Hilb</b>.
14 * @version 1.0
15 * @author Mark Hale
16 */

17 public class Hilb extends Object JavaDoc implements Category {
18         /**
19         * Constructs a <b>Hilb</b> category.
20         */

21         public Hilb() {}
22         /**
23         * Returns the identity morphism for an object.
24         * @param a a HilbertSpace.
25         */

26         public Category.Morphism identity(Object JavaDoc a) {
27                 return new LinearMap(ComplexDiagonalMatrix.identity(((HilbertSpace)a).dimension()));
28         }
29         /**
30         * Returns the cardinality of an object.
31         * @param a a HilbertSpace.
32         */

33         public Object JavaDoc cardinality(Object JavaDoc a) {
34                 return new MathInteger(((HilbertSpace)a).dimension());
35         }
36         /**
37         * Returns a hom-set.
38         * @param a a HilbertSpace.
39         * @param b a HilbertSpace.
40         * @return a HilbertSpace.
41         */

42         public Category.HomSet hom(Object JavaDoc a,Object JavaDoc b) {
43                 return new OperatorSpace((HilbertSpace)a,(HilbertSpace)b);
44         }
45         public class OperatorSpace extends HilbertSpace implements Category.HomSet {
46                 private final int rows,cols;
47                 public OperatorSpace(HilbertSpace a,HilbertSpace b) {
48                         super(a.dimension()*b.dimension());
49                         rows=b.dimension();
50                         cols=a.dimension();
51                 }
52                 /**
53                 * Returns an element of this hom-set.
54                 */

55                 public VectorSpace.Member getVector(Complex array[][]) {
56                         return new LinearMap(array);
57                 }
58         }
59         public class LinearMap implements BanachSpace.Member, Category.Morphism {
60                 private AbstractComplexMatrix matrix;
61                 public LinearMap(Complex array[][]) {
62                         matrix=new ComplexMatrix(array);
63                 }
64                 public LinearMap(AbstractComplexMatrix m) {
65                         matrix=m;
66                 }
67                 public Object JavaDoc domain() {
68                         return new HilbertSpace(matrix.columns());
69                 }
70                 public Object JavaDoc codomain() {
71                         return new HilbertSpace(matrix.rows());
72                 }
73                 public Object JavaDoc map(Object JavaDoc v) {
74                         return matrix.multiply((AbstractComplexVector)v);
75                 }
76                 public Category.Morphism compose(Category.Morphism m) {
77                         if(m instanceof LinearMap) {
78                                 LinearMap lm=(LinearMap)m;
79                                 if(matrix.columns()==lm.matrix.rows())
80                                         return new LinearMap(lm.matrix.multiply(matrix));
81                                 else
82                                         throw new UndefinedCompositionException();
83                         } else
84                                 throw new IllegalArgumentException JavaDoc("Morphism is not a LinearMap.");
85                 }
86                 public double norm() {
87                         return matrix.frobeniusNorm();
88                 }
89                 public int dimension() {
90                         return matrix.rows()*matrix.columns();
91                 }
92         public Object JavaDoc getSet() {
93             return matrix.getSet();
94         }
95                 public AbelianGroup.Member add(final AbelianGroup.Member m) {
96                         if(m instanceof LinearMap)
97                                 return new LinearMap(matrix.add(((LinearMap)m).matrix));
98                         else
99                                 throw new IllegalArgumentException JavaDoc("Member class not recognised by this method.");
100                 }
101                 public AbelianGroup.Member negate() {
102                         return new LinearMap((AbstractComplexMatrix)matrix.negate());
103                 }
104                 public AbelianGroup.Member subtract(final AbelianGroup.Member m) {
105                         if(m instanceof LinearMap)
106                                 return new LinearMap(matrix.subtract(((LinearMap)m).matrix));
107                         else
108                                 throw new IllegalArgumentException JavaDoc("Member class not recognised by this method.");
109                 }
110                 public Module.Member scalarMultiply(Ring.Member z) {
111                         if(z instanceof Complex)
112                                 return new LinearMap(matrix.scalarMultiply((Complex)z));
113                         else
114                                 throw new IllegalArgumentException JavaDoc("Member class not recognised by this method.");
115                 }
116                 public VectorSpace.Member scalarDivide(Field.Member z) {
117                         if(z instanceof Complex)
118                                 return new LinearMap(matrix.scalarMultiply((Complex)z));
119                         else
120                                 throw new IllegalArgumentException JavaDoc("Member class not recognised by this method.");
121                 }
122         }
123 }
124
125
Popular Tags