package jsci.physics.quantum;
import jsci.maths.Complex;
import jsci.maths.DimensionException;
import jsci.maths.algebras.Module;
import jsci.maths.fields.Ring;
import jsci.maths.groups.AbelianGroup;
import jsci.maths.matrices.ComplexSquareMatrix;
import jsci.maths.vectors.AbstractComplexVector;
import jsci.maths.vectors.ComplexVector;
import jsci.maths.vectors.MathVector;
import jsci.maths.vectors.VectorDimensionException;
/**
* The KetVector class provides an object for encapsulating Dirac ket vectors.
* @version 1.5
* @author Mark Hale
*/
public final class KetVector extends MathVector {
private AbstractComplexVector representation;
/**
* Constructs a ket vector given a vector representation.
* @param rep a vector representation
*/
public KetVector(AbstractComplexVector rep) {
super(rep.dimension());
representation=rep;
}
/**
* Compares two ket vectors for equality.
* @param a a ket vector
*/
public boolean equals(Object a) {
return representation.equals(((KetVector)a).representation);
}
/**
* Returns a comma delimited string representing the value of this ket vector.
*/
public String toString() {
return representation.toString();
}
/**
* Returns a hashcode for this ket vector.
*/
public int hashCode() {
return representation.hashCode();
}
/**
* Map this ket vector to a bra vector.
*/
public BraVector toBraVector() {
return new BraVector(representation.conjugate());
}
/**
* Returns the representation.
*/
public AbstractComplexVector getRepresentation() {
return representation;
}
/**
* Returns the norm.
*/
public double norm() {
return representation.norm();
}
public Object getSet() {
return representation.getSet();
}
//============
// OPERATIONS
//============
/**
* Returns the negative of this vector.
*/
public AbelianGroup.Member negate() {
return representation.negate();
}
// ADDITION
/**
* Returns the addition of this vector and another.
*/
public AbelianGroup.Member add(AbelianGroup.Member v) {
if(v instanceof KetVector)
return add((KetVector)v);
else
throw new IllegalArgumentException("Vector class not recognised by this method.");
}
/**
* Returns the addition of this vector and another.
* @param v a ket vector
* @exception VectorDimensionException If the vectors are different sizes.
*/
public KetVector add(KetVector v) {
return new KetVector(representation.add(v.representation));
}
// SUBTRACTION
/**
* Returns the subtraction of this vector by another.
*/
public AbelianGroup.Member subtract(AbelianGroup.Member v) {
if(v instanceof KetVector)
return subtract((KetVector)v);
else
throw new IllegalArgumentException("Vector class not recognised by this method.");
}
/**
* Returns the subtraction of this vector by another.
* @param v a ket vector
* @exception VectorDimensionException If the vectors are different sizes.
*/
public KetVector subtract(KetVector v) {
return new KetVector(representation.subtract(v.representation));
}
// MULTIPLICATION
/**
* Returns the multiplication of this ket vector by a scalar.
*/
public Module.Member scalarMultiply(Ring.Member x) {
return representation.scalarMultiply(x);
}
/**
* Returns the multiplication of this ket vector and a bra vector.
* @param bra a bra vector
* @exception VectorDimensionException If the vectors have different dimensions.
*/
public Operator multiply(BraVector bra) {
final int ketDim=dimension();
if(ketDim==bra.dimension()) {
AbstractComplexVector braRep=bra.getRepresentation();
Complex array[][]=new Complex[ketDim][ketDim];
for(int j,i=0;i
Ads help maintain this website.