GitLab Repo:
https://gitlab.com/EngineersBox/qcompjs
GitHub Repo (pushed from GitLab):
https://github.com/EngineersBox/qcompjs
JavaScript Version: ECMAscript 6
Dependancies: Math.js
| Constant | Matrix Representation | Description | Code Representation |
|---|---|---|---|
| one | 2-dimensional Hilbert space vector representation of qubit value of 1 | const one = [0,1]; |
|
| zero | 2-dimensional Hilbert space vector representation of qubit value of 0 | const zero = [1,0]; |
|
| posi | Complex number with positive complex value of 1 | const posi = math.complex("0+1i"); |
|
| negi | Complex number with negative complex value of 1 | const negi = math.complex("0-1i"); |
| Function | Matrix Representation | Description | Usage |
|---|---|---|---|
| QC(args) | None | Instantiate a new quantum register with values as arguments. |
const qc = new QC("|01101>");or const qc = new QC("01101");
|
| log() | None | Display arguments in console |
log("Example");
Result: Example
|
| #.getValues() | None | Return a formatted string of this.values of a QC instantiation |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.getValues(); Result: [[0,1],[1,0],[1,0],[0,1]]
|
| format.evalBraKet(args) | None | Return an array of matrix-vector formatted 1's and 0's given via arguments |
format.evalBraKet("|1001>");
Result: [[0,1],[1,0],[1,0],[0,1]]
|
| format.convetResultToString(args) | None | Return a format retainted string of the argument |
format.convetResultToString([[0,1],[1,0]]);
Result: [[0,1],[1,0]]
|
| #.X(args) | Return Pauli-X matrix multiplied by vectors in this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.X([0,1]]); Result: [[1,0],[0,1],[1,0],[0,1]]
|
|
| #.Y(args) | Return Pauli-Y matrix multiplied by vectors in this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.Y([0,1]]); Result: [[1+0i, 0+0i],[0+0i, -1+0i],[1,0],[0,1]]
|
|
| #.Z(args) | Return Pauli-Z matrix multiplied by vectors in this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.Z([0,1]]); Result: [[0,-1],[1,0],[1,0],[0,1]]
|
|
| #.S(args) | Rotate bits in this.values specified by argument list by 90 degrees on the z-axis |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.S([0,1]]); Result: [[0,1+0i],[1,0+0i],[1,0],[0,1]]
|
|
| #.Sdagger(args) | Conjugate transpose of the S gate |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.Sdagger([0,1]]); Result: [[0+0i,-1+0i],[1+0i,0+0i],[1,0],[0,1]]
|
|
| #.sqrtx(args) | Return square root of x matrix multiplied by vectors in this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.sqrtx([0,1]]); Result: [[-0.5+0i,0.5+0i],[0.5+0i, -0.5+0i],[1,0],[0,1]]
|
|
| #.phase(theta, args) | Return a phase rotation by theta radians to this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.phase(math.pi/3,[0,1]); Result: [[0,2.849653908226361],[1,0],[1,0],[0,1]]
|
|
| #.T(args) | Return a rotation by π⁄4 radians to this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.T([0,1]); Result: [[0,2.1932800507380152],[1,0],[1,0],[0,1]]
|
|
| #.Tdagger(args) | Conjugate transpose of the T gate |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.Tdagger([0,1]); Result: [[0,0.45593812776599624+0i],[1,0+0i],[1,0],[0,1]]
|
|
| #.H(args) | Return a superposition given via qubit state to this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.H([0,1]); Result: [[0.7071067811865475,-0.7071067811865475],[0.7071067811865475,0.7071067811865475],[1,0],[0,1]]
|
|
| #.swap(firstBit, secondBit) | Swap the values of the bits denoted by indexes in arguments as firstBit and secondBit |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.swap(0,1); Result: [[1,0],[0,1],[1,0],[0,1]]
|
|
| #.cnot(controlBits, targetBits) | Apply a Pauli-X gate to the targetBits if and only if the controlBits are 1's |
//this.values = [[0,1],[0,1],[1,0],[0,1]]
qc.cnot([0,1],[2,3]); Result: [[0,1],[0,1],[0,1],[1,0]]
|
|
| #.cswap(controlBits, targetBits) | Swap the values of the targetBits (targetBits must be of length 2) if and only if the controlBits are 1's |
//this.values = [[0,1],[0,1],[1,0],[0,1]]
qc.cwap([0,1],[2,3]); Result: [[0,1],[0,1],[0,1],[1,0]]
|
|
| #.rx(theta, args) | Return a rotation on the x-axis by theta radians to this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.rx(math.pi/5,[0,1]); Result: [[-0.3090169943749474+0i, 0.9510565162951535,+0i],[0.9510565162951535+0i,-0.3090169943749474+0i],[1,0],[0,1]]
|
|
| #.ry(theta, args) | Return a rotation on the y-axis by theta radians to this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.ry(math.pi/5,[0,1]); Result: [[0.5+0i,0.8660254037844387+0i],[0.8660254037844387+0i, -0.5+0i],[1,0],[0,1]]
|
|
| #.rz(theta, args) | Return a rotation on the z-axis by theta radians to this.values specified by argument array |
//this.values = [[0,1],[1,0],[1,0],[0,1]]
qc.rz(math.pi/5,[0,1]); Result: [[0+0i, 0.9510565162951535+0.3090169943749474i],[0.9510565162951535-0.3090169943749474i,0+0i],[1,0],[0,1]]
|