To turn our De Bruijn circuits into functions on density matrices, we need libraries for complex numbers and matrices. We begin with our complex number library, a modified version of the Coquelicot “Complex” library (Boldo et al., 2015).
5.4.1
Complex Numbers
Coquelicot defines its complex numbers as simply pairs of Coq reals.
Definition C := R * R.
The Coq real number library isaxiomatic:0, 1, +,∗ and other terms and operations are defined using the Coq keyword Parameter, which treats them as inhabitants of the given type without requiring them to be further specified. The basic properties of addition and multiplication are then given in terms of axioms, which have no proof. An injection is then established from the integers to the reals.
This representation has advantages and disadvantages. Its main disadvantage is that it is impossible to compute with Coq’s reals, since its basic operations are non- computational. For example, though we can prove that 1+1=2, we cannotsimplify 1+1to2. This is a common difficulty with representations of real numbers, including
those of the Mathematical Components (Mahboubi et al., 2016) and C-CORN (Cruz- Filipe et al., 2004) libraries. On the other hand, a major advantage of extending Coq’s reals is that it gives us access to Coq’s automation techniques, includingfield, which converts field expressions into a normal form to check equality, and fourier which applies the Fourier-Motzkin algorithm (Fourier, 1826; Motzkin, 1936) to decide real (in)equalities. The Coq standard library also provides the powerful lra (linear real arithmetic) tactic which subsumesfieldandfourier. We define our own tactics that extend this automation to complex numbers, which we discuss in Chapter 9.
Our additions to Coquelicot are relatively modest. We show that for any complex number c, c∗¯c is a real number, which is important for multiplying a matrix by its adjoint, along with a few related lemmas about the complex conjugate. We also prove a number of lemmas about taking square roots, which are important for reasoning about states with Hadamard matrices applied.
Since certain quantum algorithms apply phase shift gates, which correspond to the matrix
(10 e0iθ)
for some real number θ, we define eiθ using Euler’s formula:
Definition Cexp (θ : R) : C := cos θ + i * sin θ
We also use this to prove the special case of Euler’s identity, which we write as
Cexp PI= −1. Note that we cannot define the general case of complex exponentiation as a function, since xy can have multiple solutions for x, y∈C.
Our modified version of Coquelicot’s complex number library is available in the
Qwire Github repository (https://github.com/inQWIRE/QWIRE) as Complex.v. This file also removes all of Coquelicot’s dependencies, including the SSReflect and Mathematical Components libraries.
5.4.2
The Matrix Library
The denotational semantics of Qwire is implemented using a matrix library cre- ated specifically for this purpose. Matrices are simply functions from pairs of natural numbers to complex numbers.4
Definition Matrix (m n : N) := N → N → C.
The argumentsm and n, which are the dimensions of the matrix, are not mentioned on the right hand of the equals sign, but they are used to define certain operations on matrices, such as the Kronecker product and matrix multiplication, which depend on these dimensions. They are also useful as an informal annotation that aids the programmer, in the vein ofphantom types(Leijen and Meijer, 1999). We say a matrix is well-formed when it is zero-valued outside of its domain.
Definition WF_Matrix {m n} (M : Matrix m n) : P :=
∀ i j, i ≥ m ∨ j ≥ n → M i j = 0.
The library is designed to facilitate reasoning about and computing with matri- ces. Treating matrices as functions allows us to easily express otherwise complicated matrix operations. Consider the definitions of Kronecker product (⊗) and adjoint (†), where x∗ is the complex conjugate of x:
Definition kron {m n o p} (A : Matrix m n) (B : Matrix o p) : Matrix (m*n) (o*p) :=
fun x y ⇒ A (x / o) (y / p) * B (x mod o) (y mod p). Infix "⊗" := kron (at level 40, left associativity). Definition adjoint {m n} (A : Matrix m n) : Matrix n m :=
fun x y ⇒ (A y x)∗.
Notation "A †" := (conj_transpose A) (at level 0).
These definitions allow us to easily prove properties of matrices, like that the adjoint is involutive, by calling basic automation tactics:
Lemma adjoint_involutive : ∀ {m n} (A : Matrix m n), A†† = A. Proof. intros. mlra. Qed.
5.4.3
Density Matrices
We aren’t just interested in matrices broadly, but in the specific density matrices and unitary matrices discussed in Chapter 2. We start with some preliminary definitions. A unitary matrix is a well-formed, n×n matrix A such that A†×A is the identity matrix 'I_n.
Definition is_unitary {n} (A : Matrix n n) := WF_Matrix A ∧ A† × A = 'I_n.
A pure state of a quantum system is one that corresponds to a unit vector ∣ϕ⟩. We can specify a well-formed unit vector as
Definition Pure_State_Vector {n} (ϕ : Matrix n 1): P := WF_Matrix n 1 ϕ ∧ ϕ† × ϕ = 'I_1.
and use this definition to define pure states:
Definition Pure_State {n} (ρ : Matrix n n) : P :=
∃ ϕ, Pure_State_Vector ϕ ∧ ρ = ϕ × ϕ†.
A density matrix, or mixed state, is a linear combination of pure states represent- ing the probability of each pure state.
Inductive Mixed_State {n} (ρ : Matrix n n) : P := | Pure_S : ∀ ρ, Pure_State ρ → Mixed_State ρ
Mixed_State ρ1 →
Mixed_State ρ2 →
Mixed_State (p .* ρ1 .+ (1-p) .* ρ2).
Note that every mixed state is also well formed, since scaling and addition preserve well-formedness.
A superoperator is a function on square matrices that takes mixed states to mixed states.
Definition Superoperator m n := Matrix m m → Matrix n n. Definition WF_Superoperator m n (f : Superoperator m n) :=
∀ (ρ : Matrix m m), Mixed_State ρ → Mixed_State (f ρ).
Anym×n matrix A can be lifted to a superoperator from n tom by multiplying an input matrix by A and its adjoint:
Definition super {m n} (A : Matrix m n) : Superoperator n m :=
fun ρ ⇒ A × ρ × A†.
Of course, not every matrix so lifted will produce awell-formed superoperator that preserves mixed states. We will address which matrices have this property, along with broader questions about well-formed quantum structures, in Chapter 6.