Commits

Duncan McBain  committed f5e3cdf

javadoc for QubitRegister

  • Participants
  • Parent commits 7119754

Comments (0)

Files changed (1)

File QubitRegister.java

 public class QubitRegister implements Cloneable
-{	
+{
+	/** Complex array representing probability amplitudes of the register.
+	  */
 	protected Complex[] m;
-	
+
 	/** Basic constructor.
-		@param in in is the Complex array assigned to m.
-	*/
+	  * @param in the Complex array assigned to m.
+	  */
 	public QubitRegister(Complex[] in)
 	{
 		this.m = in;
 		this.normalise();
 	}
-	
+
 	/** Basic constructor.
-		@param length length is the length of the Complex array assigned to m.
-	*/
+	  * @param length the length of the Complex array assigned to m.
+	  */
 	protected QubitRegister(int length)
 	{
 		this.m = new Complex[length];
 	}
 
 	/** Basic constructor.
-		@param in in is the array of Qubits that compose the register.
-	*/
+	  * @param in in is the array of Qubits that compose the register.
+	  */
 	public QubitRegister(Qubit[] in)
 	{
 		this.m = new Complex[(int) Math.pow(2,in.length)];
 		tProduct(in);
 	}
-	
-	/** Returns probability of element i. */
+
+	/** Returns probability of element i.
+	  * @return double representing probability of i.
+	  */
 	public double probability(int i)
 	{
 		return this.m[i].norm();
 	}
-	
-	/** Scales entire Qubit Register by complex value a. */
+
+	/** Scales entire Qubit Register by complex value a. <code>this</code> is not modified.
+	  * @param a the complex which this register will be multiplied by.
+	  * @return this scaled by a.
+	  */
 	public QubitRegister scale(Complex a)
 	{
 		QubitRegister rtn = new QubitRegister(this.getLength());
 		return rtn;
 	}
 	
-	/** Returns the element i of the register. */
+	/** Returns the element i of the register.
+	  * @param i the position of the desired element.
+	  * @return ith element of <code>this</code>.
+	  */
 	public Complex getElement(int i)
 	{
 		return this.m[i];
 	}
 	
-	/** Returns the length of the state vector represented by the Register. */
+	/** Returns the length of the state vector represented by the Register.
+	  * @return this.m.length.
+	  */
 	public int getLength()
 	{
 		return this.m.length;
 	}
 	
-	/** Assigns value @param a to the element of the register in position @param i. */
+	/** Assigns value a to the element of the register in position i.
+	  * @param i the position to be altered.
+	  * @param a the new value for position i.
+	  */
 	public void setElement(int i, Complex a)
 	{
 		this.m[i] = a.clone();
 	}
 	
-	/** Collapses wavefunction of the register and sets it to the most probable state. */
+	/** Collapses wavefunction of the register and sets it to the most probable state.
+	  * @return the base state the register was observed in.
+	  */
 	public int observe()
 	{
 		double rand = Math.random(), sum = 0;
 		return index;
 	}
 
-	/** Creates state vector of the Qubit Register by forming the tensor product of the Qubit array r.*/
+	/** Creates state vector of the Qubit Register by forming the tensor product of the Qubit array r.
+	  * Used in the constructor.
+	  * @param r Qubit array representing the values of the base states.
+	  */
 	public void tProduct(Qubit[] r)
 	{
 		int p = r.length;
 				this.setElement(i,this.getElement(i).multiply(r[j].getElement((int) (i * Math.pow(2,-p+1+j) % 2))));
 	}
 	
-	/** Passes this through a using matrix multiplication. 
-		@param a The gate through which this is passed.
-	*/
+	/** Passes this through a using matrix multiplication.
+	  * @param a the gate through which this is passed.
+	  * @return new QubitRegister equal to this*a.
+	  */
 	public QubitRegister multiply(Gate a) throws MultiplyMatrixException
 	{
 		if(this.getLength() != a.getColumns())
 		return rtn;
 	}
 	
-	/** Returns an exact clone of the current instance of this. */
+	/** Returns an exact clone of the current instance of this.
+	  * @return exact clone of this.
+	  */
 	public QubitRegister clone()
 	{
 		Complex[] cloned = new Complex[this.m.length];
 		return new QubitRegister(cloned);
 	}
 
+	/** Changes probability amplitudes of <code>this</code> such that the sum of their squares equals 1.*/
 	public void normalise()
 	{
 		double total = 0;
 			this.setElement(i,this.getElement(i).scale(total));
 	}
 
-	/** Returns the outer product of the Qubit Registers this and a. */
+	/** Returns the outer product of the Qubit Registers this and a.
+	  * @param a the QR that will form a gate with this.
+	  * @return outer product of <code>this</code> and a.
+	  */
 	public Gate outerProduct(QubitRegister a)
 	{
 		int q = a.getLength();
 		return ret;
 	}
 	
-	/** Returns the printable form of this. */
+	/** Returns the printable form of this.
+	  * @return multi-line string of probability amplitudes of <code>this</code>.*/
 	public String toString()
 	{
 		String s = "";