edu.buffalo.fs7.mathlib
Class BinaryOp

java.lang.Object
  |
  +--edu.buffalo.fs7.mathlib.MathObject
        |
        +--edu.buffalo.fs7.mathlib.Operator
              |
              +--edu.buffalo.fs7.mathlib.BinaryOp
All Implemented Interfaces:
java.lang.Cloneable

public class BinaryOp
extends Operator

This class represents a binary operator of the form '+', '-', '*' or '/'. It has all the specialized routines for different arguments build in. For fast quantum simulations it has static functions specialized in applying gates to qubits given as ket vectors. In contrast to the normal operations, the specialized gate methods do not copy the argument, but the result is written into the argument object.

The binary operator is identified by the Tokenizer class and executed by the Parse class.

See Also:
Tokenizer, Parse, Braket

Field Summary
protected  char data
          identifies the operator
 
Fields inherited from class edu.buffalo.fs7.mathlib.MathObject
mathlib
 
Constructor Summary
BinaryOp(char c)
          creates a binary operator according to the char given.
 
Method Summary
 MathObject apply(Complex s1, Complex s2)
          Complex-Complex operations (+,-,*,/)
 MathObject apply(Complex s1, Matrix m2)
          complex-matrix operations (*)
 MathObject apply(Complex s1, Vect v2)
          Complex-Vector operations (*)
 MathObject apply(Gate g1, Vect v2)
          gate-vector operations (*)
 MathObject apply(MathObject s1, MathObject s2)
          this is the generic apply method.
 MathObject apply(Matrix m1, Complex s2)
          matrix-complex operations (*,/)
 MathObject apply(Matrix m1, Matrix m2)
          matrix-matrix operations (+,-,*,#)
 MathObject apply(Matrix m1, Vect v2)
          matrix-vector operations (*)
 MathObject apply(Vect v1, Vect v2)
          Vector-Vector operation (+,-,*,#)
static void implicitApply(Gate g1, Braket v2, Matrix error)
          this method dispatches gate operation to specialized methods.
static void implicitApply2x2(Gate g1, Braket v2, Matrix error)
          this method applies a general unitary 2x2 matrix onto the corresponding subspace as specified by the Gate argument to the ket given by v2.
static void implicitApply2x2a(Gate g1, Braket v2)
          this method is a optimized version to apply a unitary 2x2 matrix with zeros of the counter diagonal onto the corresponding subspace as specified by the Gate argument to the ket given by v2.
static void implicitApply2x2b(Gate g1, Braket v2)
          this method is a optimized version to apply a unitary 2x2 matrix with zero diagonal onto the corresponding subspace as specified by the Gate argument to the ket given by v2.
static void implicitApplyNxN(Gate g1, Braket v2)
          this method applies a general unitary NxN matrix onto the corresponding subspace as specified by the Gate argument to the ket given by v2.
static void implicitApplyNxNo(Gate g1, Braket v2)
          this method is an optimized method for applying a general unitary NxN matrix onto the corresponding subspace as specified by the Gate argument to the ket given by v2.
static int pow(int base, int exp)
          integer power funtion base^exp
 boolean precedence(BinaryOp b)
          decides whether the current operator precedes the operator given as a parameter.
 java.lang.String toString()
          returns the string representation of the binary operator
 
Methods inherited from class edu.buffalo.fs7.mathlib.MathObject
clone, toParseableString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

data

protected char data
identifies the operator
Constructor Detail

BinaryOp

public BinaryOp(char c)
creates a binary operator according to the char given. Valid input values: +,-,*,\
Method Detail

apply

public MathObject apply(MathObject s1,
                        MathObject s2)
this is the generic apply method. It dispatches the computation request according to the type of the given arguments. Usually, the compiler is able to bind type specific methods at compile time, but since at compile time it is not clear, which argument type Parse might parse, this cannot be done.
Parameters:
s1 - left hand side argument
s2 - right hand side argument
Returns:
resulting MathObject

apply

public MathObject apply(Complex s1,
                        Complex s2)
Complex-Complex operations (+,-,*,/)

apply

public MathObject apply(Complex s1,
                        Vect v2)
Complex-Vector operations (*)

apply

public MathObject apply(Vect v1,
                        Vect v2)
Vector-Vector operation (+,-,*,#)

apply

public MathObject apply(Matrix m1,
                        Matrix m2)
matrix-matrix operations (+,-,*,#)

apply

public MathObject apply(Complex s1,
                        Matrix m2)
complex-matrix operations (*)

apply

public MathObject apply(Matrix m1,
                        Complex s2)
matrix-complex operations (*,/)

apply

public MathObject apply(Matrix m1,
                        Vect v2)
matrix-vector operations (*)

pow

public static int pow(int base,
                      int exp)
integer power funtion base^exp
Parameters:
base -  
exp -  
Returns:
value as int

apply

public MathObject apply(Gate g1,
                        Vect v2)
gate-vector operations (*)

implicitApply

public static void implicitApply(Gate g1,
                                 Braket v2,
                                 Matrix error)
this method dispatches gate operation to specialized methods. It is a specialized method used in the quantum simulation and is not used during a normal parse process. The parameter error can be a 2x2 matrix with which the gate is modified in oder to simulate operational errors.
Parameters:
g1 - gate to be applied
v2 - ket vector
error - 2x2 matrix or null
See Also:
Measurement.partialMeasurement(Braket, int), implicitApply2x2(Gate, Braket, Matrix), implicitApply2x2a(Gate, Braket), implicitApply2x2b(Gate, Braket), implicitApplyNxN(Gate, Braket), implicitApplyNxNo(Gate, Braket)

implicitApply2x2

public static void implicitApply2x2(Gate g1,
                                    Braket v2,
                                    Matrix error)
this method applies a general unitary 2x2 matrix onto the corresponding subspace as specified by the Gate argument to the ket given by v2. The parameter error is a 2x2 matrix with which the gate gets modified.
See Also:
implicitApply2x2a(Gate, Braket)

implicitApply2x2a

public static void implicitApply2x2a(Gate g1,
                                     Braket v2)
this method is a optimized version to apply a unitary 2x2 matrix with zeros of the counter diagonal onto the corresponding subspace as specified by the Gate argument to the ket given by v2.
See Also:
implicitApply2x2(Gate, Braket, Matrix), implicitApply2x2b(Gate, Braket)

implicitApply2x2b

public static void implicitApply2x2b(Gate g1,
                                     Braket v2)
this method is a optimized version to apply a unitary 2x2 matrix with zero diagonal onto the corresponding subspace as specified by the Gate argument to the ket given by v2.
See Also:
implicitApply2x2(Gate, Braket, Matrix), implicitApply2x2a(Gate, Braket)

implicitApplyNxN

public static void implicitApplyNxN(Gate g1,
                                    Braket v2)
this method applies a general unitary NxN matrix onto the corresponding subspace as specified by the Gate argument to the ket given by v2.
See Also:
implicitApply2x2(Gate, Braket, Matrix), implicitApplyNxNo(Gate, Braket)

implicitApplyNxNo

public static void implicitApplyNxNo(Gate g1,
                                     Braket v2)
this method is an optimized method for applying a general unitary NxN matrix onto the corresponding subspace as specified by the Gate argument to the ket given by v2. It should perform better for N > 4 than the general version.
See Also:
implicitApply2x2(Gate, Braket, Matrix), implicitApplyNxN(Gate, Braket)

precedence

public boolean precedence(BinaryOp b)
decides whether the current operator precedes the operator given as a parameter.
Parameters:
b - a binary operator to compare with

toString

public java.lang.String toString()
returns the string representation of the binary operator
Overrides:
toString in class MathObject
Following copied from class: edu.buffalo.fs7.mathlib.MathObject
See Also:
MathObject.toParseableString()