Quantum Basis and State (19) 
In our Quantum Framework, a quantum state is defined with respect to a QuantumBasis. For pure states, the given input can be a list of amplitudes, or an association with keys corresponds to basis elements and values as amplitudes.
Define a 2D quantum basis (computational):
Given the basis dimension n, the basis elements will be indexed by ket with i=0,1,...,n-1
Use a sequence as QuantumBasis[n,m], for n qudits of m-dimensional (overall dimension will be nm). For example, let us define a 2×2×2 dimensional quantum basis (three qubits):
Use a list as QuantumBasis[{n1,n2,...,nm}] for n1×n2×n2×...×nm dimensional Hilbert space of m qudits. For example, define a 3×5 dimensional quantum basis (two qudits):
A basis can also be defined by an association with the basis element names as keys, and corresponding vectors as values.
There are many named-basis built in the quantum framework, {"Computational", "PauliX", "PauliY", "PauliZ","Fourier", "Identity","Schwinger", "Pauli", "Dirac", "Wigner"}:
After a basis object has been defined, it is straightforward to use it to construct quantum states and operators. A quantum state is represented by QuantumState object and a quantum operator is represented by QuantumOperator.
For pure quantum states, a vector with elements as amplitudes, and the corresponding basis should be given in this format: QuantumState[amp_List,QuantumBasis[args]]. With no basis specified, the default basis will be the computational basis whose dimension depends on the amplitude vector.
Define a pure 2-dimensional quantum state (qubit) in the Pauli-X basis:
If the basis is not specified, the default is the computational basis of 2n dimension (n qubits):
If the vector has more than 2 elements, it is interpreted as a n-qubit state (by right-padding of zeros), unless the dimension is specified.
Same amplitude vector, but this time the dimension is specified:
Many named states are available for easy access:
Using associations, one can create a superposition of states, with keys as a list of corresponding indexes, and values as amplitudes. For example, let us create a superposition of 3 qubits (i.e., QuantumBasis[2,3]) as
:
A different way of creating superposition is simple adding two quantum state objects. For example, the previous state can be constructed as follows, too:
Once a built-in basis is specified, amplitudes correspond to the basis elements. For example, let's use Bell basis:
We can also define a state by inputting a density matrix:
For pure states, one can get the corresponding normalized state vector:
Define a generic Bloch vector:
Test if it is a mixed state:
Calculate Von Neumann Entropy:
Purity:
A pure state (by normalizing the vector r):
Purity:
Calculate Bloch Spherical Coordinates
A matrix that is not positive semi-definite (cannot be a density matrix in standard QM, but in ZX-formalism we can have situations like this):
A non positive-semidefinite matrix as state: