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.AbstractComplexSquareMatrix;
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 BraVector class provides an object for encapsulating Dirac bra vectors.
016: * @version 1.5
017: * @author Mark Hale
018: */
019: public final class BraVector extends MathVector {
020: private AbstractComplexVector representation;
021:
022: /**
023: * Constructs a bra vector given a vector representation.
024: * @param rep a vector representation
025: */
026: public BraVector(AbstractComplexVector rep) {
027: super (rep.dimension());
028: representation = rep;
029: }
030:
031: /**
032: * Compares two bra vectors for equality.
033: * @param a a bra vector
034: */
035: public boolean equals(Object a) {
036: return representation.equals(((BraVector) a).representation);
037: }
038:
039: /**
040: * Returns a comma delimited string representing the value of this bra vector.
041: */
042: public String toString() {
043: return representation.toString();
044: }
045:
046: /**
047: * Returns a hashcode for this bra vector.
048: */
049: public int hashCode() {
050: return representation.hashCode();
051: }
052:
053: /**
054: * Map this bra vector to a ket vector.
055: */
056: public KetVector toKetVector() {
057: return new KetVector(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 BraVector)
096: return add((BraVector) 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 bra vector
105: * @exception VectorDimensionException If the vectors are different sizes.
106: */
107: public BraVector add(BraVector v) {
108: return new BraVector(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 BraVector)
118: return subtract((BraVector) 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 bra vector
127: * @exception VectorDimensionException If the vectors are different sizes.
128: */
129: public BraVector subtract(BraVector v) {
130: return new BraVector(representation.subtract(v.representation));
131: }
132:
133: // MULTIPLICATION
134:
135: /**
136: * Returns the multiplication of this bra 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 bra vector and a ket vector.
144: * @param ket a ket vector
145: * @exception VectorDimensionException If the vectors have different dimensions.
146: */
147: public Complex multiply(KetVector ket) {
148: final int braDim = dimension();
149: if (braDim == ket.dimension()) {
150: AbstractComplexVector ketRep = ket.getRepresentation();
151: Complex answer = representation.getComponent(0).multiply(
152: ketRep.getComponent(0));
153: for (int i = 1; i < braDim; i++)
154: answer = answer.add(representation.getComponent(i)
155: .multiply(ketRep.getComponent(i)));
156: return answer;
157: } else
158: throw new VectorDimensionException(
159: "Vectors have different dimensions.");
160: }
161:
162: /**
163: * Returns the multiplication of this bra vector and an operator.
164: * @param op an operator
165: * @exception DimensionException If the operator and vector have different dimensions.
166: */
167: public BraVector multiply(Operator op) {
168: final int braDim = dimension();
169: if (braDim == op.dimension()) {
170: AbstractComplexSquareMatrix opRep = op.getRepresentation();
171: Complex tmp, array[] = new Complex[braDim];
172: for (int j, i = 0; i < braDim; i++) {
173: tmp = representation.getComponent(0).multiply(
174: opRep.getElement(0, i));
175: for (j = 1; j < braDim; j++)
176: tmp = tmp.add(representation.getComponent(j)
177: .multiply(opRep.getElement(j, i)));
178: array[i] = tmp;
179: }
180: return new BraVector(new ComplexVector(array));
181: } else
182: throw new DimensionException(
183: "Operator and vector have different dimensions.");
184: }
185: }
|