edu.buffalo.fs7.mathlib
Class Braket

java.lang.Object
  |
  +--edu.buffalo.fs7.mathlib.MathObject
        |
        +--edu.buffalo.fs7.mathlib.Argument
              |
              +--edu.buffalo.fs7.mathlib.Vect
                    |
                    +--edu.buffalo.fs7.mathlib.Braket
All Implemented Interfaces:
java.lang.Cloneable

public class Braket
extends Vect

Class representing a mathematical bra or ket object as introduced by the Dirac notation. The basis chosen for this object is the canonical z-axis basis.

It is derived from the class Vect and is the most important object for quantum computations.

The components of the braket are not created before they are actually needed in a computation.

See Also:
Complex.times_(Complex)., BinaryOp

Field Summary
protected  boolean bra
          holds whether the braket is a bra or a ket.
 int n
          holds the number of qubits.
 
Fields inherited from class edu.buffalo.fs7.mathlib.Vect
data, dimension, transpose
 
Fields inherited from class edu.buffalo.fs7.mathlib.MathObject
mathlib
 
Constructor Summary
Braket(int n)
          constructs an empty ket vector with n qubits and dimension 2^n.
Braket(int state, int n)
          constructs a basis ket.
Braket(MathObject o)
          clone constructor
 
Method Summary
 java.lang.Object clone()
          clone method
 boolean equals(MathObject o)
          equality predicate.
static java.lang.String getBasisString(int basisState, int n, boolean bra)
          static method to obtain the string representation of a basis braket.
 boolean isBra()
           
static Braket parseBraket(java.lang.String str)
          parses a braket object from a given string.
static Braket parseBraket(Vect v)
          creates a braket object from a Vect object.
 java.lang.String toParseableString()
          returns a parsable string representation of the braket.
 java.lang.String toString()
          This method expands the braket in its basis states.
 java.lang.String toString(int length)
          This method expands the braket in its basis states.
 void transpose()
          transposes the braket. bra -> ket", ket -> bra".
 
Methods inherited from class edu.buffalo.fs7.mathlib.Vect
conjugate, getElement, negative, parseVector
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

n

public int n
holds the number of qubits. The dimension is given by 2^n.

bra

protected boolean bra
holds whether the braket is a bra or a ket.
Constructor Detail

Braket

public Braket(MathObject o)
clone constructor
See Also:
Vect.Vect(MathObject)

Braket

public Braket(int n)
constructs an empty ket vector with n qubits and dimension 2^n.
Parameters:
n - number of qubits

Braket

public Braket(int state,
              int n)
constructs a basis ket.
Parameters:
state - 0<= state < 2^n
n - number of qubits
Method Detail

clone

public java.lang.Object clone()
clone method
Overrides:
clone in class Vect
Following copied from class: edu.buffalo.fs7.mathlib.Vect
See Also:
Vect.Vect(MathObject)

isBra

public boolean isBra()

parseBraket

public static Braket parseBraket(Vect v)
                          throws java.lang.IllegalArgumentException
creates a braket object from a Vect object. The transpose property of the vector determines whether the parsed object becomes a bra (transpose = false) or a ket (transpose = true). Throws an IllegalArgumentException if the operation fails.
Parameters:
v - a vect object
Returns:
a braket object

parseBraket

public static Braket parseBraket(java.lang.String str)
                          throws java.lang.NumberFormatException,
                                 java.lang.IllegalArgumentException
parses a braket object from a given string. Possible notations are: |001001> or <101000| (binary) |+> or <-| (only for one qubit brakets!) Throws NumberFormatException or IllegalArgumentException if the operation fails.
Parameters:
str - string to parse
Returns:
the braket object

transpose

public void transpose()
transposes the braket. bra -> ket", ket -> bra". Where " denotes the complex conjugate. In order to transform a bra to a ket, a transpose() operation followed by a conjugate() operation must be performed.
Overrides:
transpose in class Vect
See Also:
Vect.conjugate()

equals

public boolean equals(MathObject o)
equality predicate.
Overrides:
equals in class Vect
Returns:
true if o equals this braket

getBasisString

public static java.lang.String getBasisString(int basisState,
                                              int n,
                                              boolean bra)
static method to obtain the string representation of a basis braket.
Parameters:
basisState - the number of the basisState (0 <= basisState < 2^n)
n - the number of qubits (the length of the binary representation)
bra - determines whether the state is given as bra or ket
Returns:
the string representation of a certain basis state in binary braket notation.
See Also:
toString()

toString

public java.lang.String toString()
This method expands the braket in its basis states. The chosen basis is the canonical z-axis basis.
Overrides:
toString in class Vect
Returns:
the string representation of this braket object
See Also:
toString(int), getBasisString(int,int,boolean)

toString

public java.lang.String toString(int length)
This method expands the braket in its basis states. The chosen basis is the canonical z-axis basis. In contrast to the normal toString() method, this method limits its output to the number given as an argument. This is useful since the string representation grows exponentially with the number of qubits!
Parameters:
length - length of the string after which it is truncated
Returns:
the string representation of this braket object
See Also:
toString()

toParseableString

public java.lang.String toParseableString()
returns a parsable string representation of the braket.
Overrides:
toParseableString in class Vect
Following copied from class: edu.buffalo.fs7.mathlib.Vect
Returns:
parsable string representation of ths vector object.