- URL: https://github.com/MikeMcl/decimal.js/
- Description: The decimal.js library. This is used to perform more accurate floating point operations.
- Implements:
Decimal
- Description: This implements basic math functions like complex numbers and complex matrices.
- Source Tree:
Complex(real, imaginary)
- Type:
Object
- Description: This implements complex numbers and complex number operations.
- Arguments:
real
- Either a JavaScript floating point number or a
Decimal
object. This represents the real component of the complex number.
- Either a JavaScript floating point number or a
imaginary
- Either a JavaScript floating point number or a
Decimal
object. This represents the imaginary component of the complex number.
- Either a JavaScript floating point number or a
Complex.Real
- Type:
Property
- Description: A
Decimal
object that represents the real component of the complex number.
- Type:
Complex.Imaginary
- Type:
Property
- Description: A
Decimal
object that represents the imaginary component of the complex number.
- Type:
Complex.Sub(comp)
Complex.Add(comp)
Complex.Mult(comp)
Complex.Inverse()
Complex.Negate()
Complex.Div(comp)
Complex.Abs()
Complex.toString()
- Type:
Method
- Description: Creates a string representation of the current
Complex
. - Returns: A new
String
which holds a representation of the currentComplex
.
- Type:
Complex.Sqr()
Complex.Clone()
- Type:
Method
- Description: Creates a clone of the current
Complex
. - Returns: A new
Complex
which is a clone of the currentComplex
.
- Type:
- Type:
Matrix(width, height, opt = true)
- Type:
Object
- Description: A
Object
that represents a matrix in memory. ThisObject
also implements operations on matrices. - Arguments:
width
- An
Int
that represents thewidth
of theMatrix
.
- An
height
- An
Int
that represents theheight
of theMatrix
.
- An
opt
- A
Boolean
that enables theMatrix
to be stored differently depending on thewidth
andheight
. This speeds upMatrix
operations andStateVector
operations.
- A
Matrix.Width
- Type:
Property
- Description: An
Int
that represents thewidth
of theMatrix
.
- Type:
Matrix.Height
- Type:
Property
- Description: An
Int
that represents theheight
of theMatrix
.
- Type:
Matrix.Rotated
- Type:
Property
- Description: A
Boolean
that represents whether theMatrix
representation has been flipped in memory for optimization reasons.
- Type:
Matrix.Vals
- Type:
Property
- Description: A representation of the
Matrix
in memory.
- Type:
Matrix.Set(i, j, v)
Matrix.Get(i, j)
Matrix.Mult(mat)
Matrix.Rotate90()
Matrix.CounterRotate90()
Matrix.VerticleFlatten()
Matrix.toString()
- Type:
Method
- Description: Creates a
String
that represents theMatrix
. - Returns: A
String
that represents theMatrix
.
- Type:
Matrix.FlatFromArr(arr, horiz = false)
- Type:
Method
- Description: Creates either a vector or a vector flipped on its side from an
Array
ofComplex
objects. - Arguments:
arr
- A one dimensional
Array
ofComplex
objects.
- A one dimensional
horiz
- A
Boolean
which if set tofalse
creates a vector and if set totrue
creates a vector that is flipped on its side.
- A
- Returns: A vector or a vector flipped on its side from an
Array
ofComplex
objects. Both in aMatrix
Object
.
- Type:
Matrix.From2dArr(arr2d)
- Type:
Method
- Description: Creates a new
Matrix
Object
from a two dimensionalArray
ofComplex
objects. Still implemented for compatibility reasons. UseMatrix.From2dComplexArr(arr2d)
instead. - Arguments:
arr2d
- A two dimensional
Array
ofComplex
objects.
- A two dimensional
- Returns: A new
Matrix
that is functionally equivalent to the input two dimensionalArray
.
- Type:
Matrix.From2dRealArr(arr2d)
- Type:
Method
- Description: Creates a new
Matrix
Object
from a two dimensionalArray
of JavaScriptFloat
objects. - Arguments:
arr2d
- A two dimensional
Array
of JavaScriptFloat
objects.
- A two dimensional
- Returns: A new
Matrix
that is filled withComplex
objects with theReal
component set to the inputarr2d
.
- Type:
Matrix.From2dComplexArr(arr2d)
- Type:
Method
- Description: Creates a new
Matrix
Object
from a two dimensionalArray
ofComplex
objects. - Arguments:
arr2d
- A two dimensional
Array
ofComplex
objects.
- A two dimensional
- Returns: A new
Matrix
that is functionally equivalent to the input two dimensionalArray
.
- Type:
Matrix.Scalar(a)
- Type:
Method
- Description: Multiplies every element of the matrix by the argument
a
. - Arguments:
a
- A
Complex
that will be multiplied every element of theMatrix
.
- A
- Returns: A new
Matrix
where every element has been multiplied bya
.
- Type:
- Type:
- Description: A module that allows the demo to estimate how many qubits the host computer can process in a reasonable amount of time.
- Source Tree:
PerformanceEval()
- Type:
Method
- Description: provides an estimate of how many qubits a host computer can work with in a reasonable amount of time.
- Type:
- Description: A module that provides an interpreting service to interpret the quantum programming language.
- Source Tree:
qEvaluator
- Type:
Object
- Description: A
Object
that provides the quantum language interpreter.qEvaluator.sim
- Type:
Property
- Description: An instance of the
QVM
Object
to actually preform the simulation of the quantum operations.
- Type:
qEvaluator.measureObj
- Type:
Property
- Description: An
Array
which represents the measured state vector. If no measurement operation has been performed, this will remainUndefined
.
- Type:
qEvaluator.readLine(x)
- Type:
Method
- Description: A method to feed a line of data into the language interpreter.
- Arguments:
x
- A
String
that represents a line of a quantum program.
- A
- Type:
- Type:
- Description: A module that contains all quantum gate definitions in matrix form. All the gates are contained in the
Object
qGates
.
- Description: Implements the actual quantum computer simulator.
- Source Tree:
StateVector(nBit)
- Type:
Object
- Description: A
Object
that stores a quantum state for a quantum computer withnBit
number of bits. - Arguments:
nBit
- A JavaScript
Int
that stores the number of bits represented by the state vector.
- A JavaScript
StateVector.UnitVec
- Type:
Property
- Description: A
Matrix
that hold the vector that represents the state of the quantum computer.
- Type:
StateVector.SetBinUnitVector(states)
StateVector.ZeroBinUnitVector()
StateVector.Flatten()
- Type:
Method
- Description: Creates a one dimensional
Array
ofComplex
objects that represents theUnitVec
. - Returns: A one dimensional
Array
ofComplex
objects that represents theUnitVec
.
- Type:
StateVector.GetProbDist()
- Type:
Method
- Description: Calculates the probabilities of each possible state of the quantum computer.
- Returns: A new one dimensional
Array
ofDecimal
objects that represents all the possible probabilities of each state.
- Type:
- Type:
QVM(nBit)
- Type:
Object
- Description: A simple
Object
which allows quantum computations. - Arguments:
nBit
- A JavaScript
Int
that represents the amount of qubits in the simulated quantum computer.
- A JavaScript
QVM.Gates
- Type:
Property
- Description: An
Array
ofqGates
objects which represent all the quantum operations in order.
- Type:
QVM.qBitSels
- Type:
Property
- Description: An
Array
ofInt
Array
that represents the qubits to be operated on. The length ofQVM.qBitSels
should matchQVM.Gates
.
- Type:
QVM.State
- Type:
Property
- Description: An
StateVector
that represents the current state of the quantum computer simulator.
- Type:
QVM.Reset()
- Type:
Method
- Description: Resets
QVM.State
by callingQVM.State.ZeroBinUnitVector()
.
- Type:
QVM.Run(trackStates = true)
- Type:
Method
- Description: Runs the simulation of the quantum computer.
- Arguments:
trackStates
- A
Boolean
that if set totrue
will log every intermediateStateVector
.
- A
- Result: An
Array
of intermediateStateVector
.
- Type:
QVM.MeasureBits(selBits)
- Type:
Method
- Description: Calculates the probabilities of each possible state of the quantum computer when measured.
- Arguments:
selBits
- An
Array
of JavaScriptInt
that represents the qubits that are measured.
- An
- Type:
- Type:
-
Description: A module that implements algorithms for processing multiple qubits that are entangled.
-
Source Tree:
-
incArr(len)
-
baseArrToN(baseArr, base = 2)
- Type:
Method
- Description: From an
Array
of JavaScriptInt
converts from basebase
to N. - Arguments:
baseArr
- An
Array
ofInt
which represents the value of the places.
- An
base
- A JavaScript
Int
that represents the base of thebaseArr
- A JavaScript
- Returns: A JavaScript
Int
that is the base 10 representation ofbaseArr
in the basebase
.
- Type:
-
nToBaseArr(n, base = 2)
- Type:
Method
- Description: Converts a JavaScript
Int
n
to a base array with the basebase
. - Arguments:
n
- A JavaScript
Int
to convert into basebase
.
- A JavaScript
base
- The base to use for the conversion.
- Returns: An
Array
of JavaScriptInt
that represent the numbern
in the basebase
.
- Type:
-
padRight0(bitArr, n)
- Type:
Method
- Description: Appends 0s to
bitArr
. - Arguments:
bitArr
- The
Array
to append to.
- The
n
- A JavaScript
Int
that represents the number of 0s to append to the array.
- A JavaScript
- Returns: The original
Array
withn
extra 0s appended to it.
- Type:
-
xorArrs(arr1, arr2)
- Type:
Method
- Description: Creates a new
Array
that holds every element ofarr1
XORed witharr2
. - Arguments:
arr1
- A bit
Array
to be XORed.
- A bit
- `arr2
- A bit
Array
to be XORed.
- A bit
- Returns: A new
Array
with every element ofarr1
XORed witharr2
.
- Type:
-
removeFromArray(original, remove)
- Type:
Method
- Description: Creates a new
Array
that holds every element oforiginal
that is not inremove
. - Arguments:
original
- A generic
Array
.
- A generic
remove
- A generic
Array
.
- A generic
- Returns: A new
Array
that holds every element oforiginal
that is not inremove
.
- Type:
-
orBitSelArray(arr, bitSel)
- Type:
Method
- Description: ORs all
arr[bitSel]
. - Arguments:
arr
- A binary
Array
to OR.
- A binary
bitSel
- A JavaScript
Int
Array
that contains the indexes to OR.
- A JavaScript
- Returns: The indexes,
bitSel
ofArray
arr
ORed.
- Type:
-
orArray(arr)
-
Type:
Method
-
Description: ORs all the elements of
arr
-
Arguments:
arr
- A binary
Array
to OR.
- A binary
-
Returns: All the elements of
arr
ORed. -
mapArr(orig, map, preserve = false)
- Type:
Method
- Description: Returns a new
Array
oforig[map]
. - Arguments:
orig
- The
Array
that will be used as the source.
- The
map
- A JavaScript
Array
that is anArray
of indexes to return fromorig
- A JavaScript
- Returns: A new
Array
oforig[map]
.
- Type:
-
generateGroupMap(len, selBits)
- Type:
Method
- Description: An algorithm that creates a map of quantum states to perform single qubit operations on a pair of two or more entangled qubits.
- Arguments:
len
- A JavaScript
Int
that represents the length of theStateVector
.
- A JavaScript
selBits
- A JavaScript
Array
ofInt
that represents the index of the qubits that should be operated on.
- A JavaScript
- Returns: A map of quantum states to perform single qubit operations on a pair of two or more entangled qubits.
- Type:
-
applyGroupMap(map, vec)
- Type:
Method
- Description: Applies the result of
generateGroupMap(len, selBits)
to aStateVector
. - Arguments:
map
- A group map generated by
generateGroupMap(len, selBits)
- A group map generated by
vec
- A
StateVector
to apply the group map to.
- A
- Returns: Groups of pairs of qubit
StateVectors
to be operated on.
- Type:
-
removeGroupMap(map, pairs)
- Type:
Method
- Description: After performing the operation, the pairs must be ‘glued back together’ or combined back into a
StateVector
. Meaning that:removeGroupMap(map, applyGroupMap(map, vec)) == vec
. - Arguments:
map
- A group map generated by
generateGroupMap(len, selBits)
.
- A group map generated by
pairs
- An
Array
of pairs generated byapplyGroupMap(map, vec)
.
- An
- Returns: Reverses the result of
applyGroupMap(map, vec)
.
- Type:
-
generateCombinationMap(len, selBits)
-
Type:
Method
-
Description: Generates a map to combine probabilities of a
StateVector
to create the illusion of measuring individual qubits. Used for theM
command (read the Readme). -
Arguments:
-
len
- A JavaScript
Int
that represents the length of theStateVector
.
- A JavaScript
-
selBits
- A JavaScript
Array
ofInt
that represents the index of the qubits that should be operated on.
- A JavaScript
-
-
Returns: A map to combine probabilities of a
StateVector
.
-
-
ApplyCombinationMap(map, arr, pad = true)
- Type:
Method
- Description: Applies a map generated by
generateCombinationMap(len, selBits)
to probability vector. - Arguments:
map
- A group map generated by
generateCombinationMap(len, selBits)
.
- A group map generated by
arr
- A probability vector to apply the group map to.
pad
- A
Boolean
that if set totrue
will preserve the original probability vector length.
- A
- Returns a probability map as if the quantum computer only measured the qubits defined in
generateCombinationMap(len, selBits)
asselBits
.
- Type:
-
-
The QVM project contains:
827
lines of JavaScript.