001: package JSci.physics.quantum;
002:
003: import JSci.maths.Complex;
004: import JSci.maths.vectors.MathVector;
005: import JSci.maths.vectors.AbstractComplexVector;
006: import JSci.maths.vectors.ComplexVector;
007: import JSci.maths.matrices.ComplexSquareMatrix;
008: import JSci.maths.DimensionException;
009: import JSci.maths.vectors.VectorDimensionException;
010: import JSci.maths.groups.AbelianGroup;
011: import JSci.maths.algebras.Module;
012: import JSci.maths.fields.Ring;
013:
014: /**
015: * The KetVector class provides an object for encapsulating Dirac ket vectors.
016: * @version 1.5
017: * @author Mark Hale
018: */
019: public final class KetVector extends MathVector {
020: private AbstractComplexVector representation;
021:
022: /**
023: * Constructs a ket vector given a vector representation.
024: * @param rep a vector representation
025: */
026: public KetVector(AbstractComplexVector rep) {
027: super (rep.dimension());
028: representation = rep;
029: }
030:
031: /**
032: * Compares two ket vectors for equality.
033: * @param a a ket vector
034: */
035: public boolean equals(Object a) {
036: return representation.equals(((KetVector) a).representation);
037: }
038:
039: /**
040: * Returns a comma delimited string representing the value of this ket vector.
041: */
042: public String toString() {
043: return representation.toString();
044: }
045:
046: /**
047: * Returns a hashcode for this ket vector.
048: */
049: public int hashCode() {
050: return representation.hashCode();
051: }
052:
053: /**
054: * Map this ket vector to a bra vector.
055: */
056: public BraVector toBraVector() {
057: return new BraVector(representation.conjugate());
058: }
059:
060: /**
061: * Returns the representation.
062: */
063: public AbstractComplexVector getRepresentation() {
064: return representation;
065: }
066:
067: /**
068: * Returns the norm.
069: */
070: public double norm() {
071: return representation.norm();
072: }
073:
074: public Object getSet() {
075: return representation.getSet();
076: }
077:
078: //============
079: // OPERATIONS
080: //============
081:
082: /**
083: * Returns the negative of this vector.
084: */
085: public AbelianGroup.Member negate() {
086: return representation.negate();
087: }
088:
089: // ADDITION
090:
091: /**
092: * Returns the addition of this vector and another.
093: */
094: public AbelianGroup.Member add(AbelianGroup.Member v) {
095: if (v instanceof KetVector)
096: return add((KetVector) v);
097: else
098: throw new IllegalArgumentException(
099: "Vector class not recognised by this method.");
100: }
101:
102: /**
103: * Returns the addition of this vector and another.
104: * @param v a ket vector
105: * @exception VectorDimensionException If the vectors are different sizes.
106: */
107: public KetVector add(KetVector v) {
108: return new KetVector(representation.add(v.representation));
109: }
110:
111: // SUBTRACTION
112:
113: /**
114: * Returns the subtraction of this vector by another.
115: */
116: public AbelianGroup.Member subtract(AbelianGroup.Member v) {
117: if (v instanceof KetVector)
118: return subtract((KetVector) v);
119: else
120: throw new IllegalArgumentException(
121: "Vector class not recognised by this method.");
122: }
123:
124: /**
125: * Returns the subtraction of this vector by another.
126: * @param v a ket vector
127: * @exception VectorDimensionException If the vectors are different sizes.
128: */
129: public KetVector subtract(KetVector v) {
130: return new KetVector(representation.subtract(v.representation));
131: }
132:
133: // MULTIPLICATION
134:
135: /**
136: * Returns the multiplication of this ket vector by a scalar.
137: */
138: public Module.Member scalarMultiply(Ring.Member x) {
139: return representation.scalarMultiply(x);
140: }
141:
142: /**
143: * Returns the multiplication of this ket vector and a bra vector.
144: * @param bra a bra vector
145: * @exception VectorDimensionException If the vectors have different dimensions.
146: */
147: public Operator multiply(BraVector bra) {
148: final int ketDim = dimension();
149: if (ketDim == bra.dimension()) {
150: AbstractComplexVector braRep = bra.getRepresentation();
151: Complex array[][] = new Complex[ketDim][ketDim];
152: for (int j, i = 0; i < ketDim; i++) {
153: array[i][0] = representation.getComponent(i).multiply(
154: braRep.getComponent(0));
155: for (j = 1; j < ketDim; j++)
156: array[i][j] = representation.getComponent(i)
157: .multiply(braRep.getComponent(j));
158: }
159: return new Operator(new ComplexSquareMatrix(array));
160: } else
161: throw new VectorDimensionException(
162: "Vectors have different dimensions.");
163: }
164: }
|