This document illustrates the content of the
IBM's basics of quantum information course
with Scala
code.
This section deals with probabilistic information and quantum information.
The main difference between probabilistic information and quantum information is that the former involves non-negative real numbers and the latter involves complex numbers.
Real
is a type
alias for Double
.
Complex
is a case class
.
re
is the real part of a complex number,im
is the imaginary part of a complex number.
Scalar
is a trait
that specifies a type class for type parameter S
as Scalar[S]
.
A type class specification declares, and default defines common members of its type parameter.
realScalar
is a given
that implements type class Scalar
by substituting type argument Real
for type
parameter S
as Scalar[Real]
.
A type class implementation defines the declared members of its type class specification.
isValidScalar
is true
if and only if a real number is positive or zero.
Not using the absolute value function for the scalar norm of a real number is justified by the fact that a real number is required to be positive or zero.
scalarNorm
does not use the absolute value function because the real number is positive or zero.
complexScalar
defines two extra members, r
resp. i
to construct real resp imaginary complex numbers.
NormedVector
is a trait
that specifies a generic value class with parameter S
, required to be a Scalar
, as
NormedVector[S: Scalar]
.
A value class declares, and default defines common members for values that are instances of it.
When constructing such an instance, all declared members need to be defined.
seq
is the sequence of scalars of a normed vector.
norm
is the Manhattan, L1-norm for vectors of non-negative real numbers resp. the square of the
Euclidean, L2-norm for vectors of complex numbers.
Not using the square root function for the norm of vectors of complex numbers is justified by the fact that this norm
is required to be equal to 1.0
.
and
NormedColumnVector
and NormedRowVector
differ in the way they implement toString
.
NormedColumnVectorSpace
is a trait
that specifies a generic value class with parameter S
, required to be a
Scalar
, as NormedColumnVectorSpace[S: Scalar]
.
dim
, the dimension of the normed column vector space is the only declared member, all other ones are defined.
normedColumnVector
constructs normed column vectors.
They are required to have norm equal to 1.0
.
normedRowVector
constructs normed row vectors.
They are required to have norm equal to 1.0
.
indices
and δ
are auxiliary members that are used to define basis (normed) vectors.
basisColumnVector
constructs basis (normed) column vectors.
basisRowVector
constructs basis (normed) row vectors.
basisColumnVectors
consists of all (normed) basis column vectors
isBasisColumnVector
checks if a normed column vector is a basis (normed) column vector.
linearCombination
constructs linear combinations of normed column vectors.
They are required to have norm equal to 1.0
.
o
defines the inner product of a normed row vector and a normed column vector.
asLinearBasisVectorCombination
defines a normed column vector ncv
as a linear combination of basis column vectors
with coefficients basisRowVector(i) o ncv
for all indices i
in 0 to dim - 1
.
ProbabilisticStateVector.scala
ProbabilisticStateVector
is a type
alias for NormedColumnVector[Real]
.
Note: in IBM's basics of quantum information course probabilistic state vectors are called probability vectors.
QuantumStateVector
is a type
alias for NormedColumnVector[Complex]
.
ProbabilisticStateVectorSpace.scala
ProbabilisticStateVectorSpace
is a type
alias for NormedColumnVectorSpace[Real]
.
QuantumStateVectorSpace
is a type
alias for NormedColumnVectorSpace[Complex]
.
ProbabilisticStateVectorExamples.scala
QuantumStateVectorExamples.scala
ProbabilisticStateVectorSpaceSuite.scala
QuantumStateVectorSpaceSuite.scala
sbt:qc> test
qc.scalar.ProbabilisticStateVectorSpaceSuite:
+ norm == 1.0 0.005s
+ probabilisticStateVector == linearBasisVectorCombination 0.0s
qc.scalar.QuantumStateVectorSpaceSuite:
+ norm == 1.0 0.005s
+ quantumStateVector == linearBasisVectorCombination 0.0s
[info] Passed: Total 4, Failed 0, Errors 0, Passed 4
[success]