<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Formal Quantum Software Engineering Introducing the Formal Methods of Software Engineering to Quantum Computing</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Carmelo R. Cartiere</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>Nextsense Srl, Division of Quantitative Physics and Systems Engineering Via della Rotonda 36</institution>
          ,
          <addr-line>00186 Rome, RM</addr-line>
          ,
          <country country="IT">Italy</country>
        </aff>
      </contrib-group>
      <fpage>60</fpage>
      <lpage>65</lpage>
      <abstract>
        <p>Quantum computing (QC) represents the future of computing systems, but the tools for reasoning about the quantum model of computation, in which the laws obeyed are those on the quantum mechanical scale, are still a mix of linear algebra and Dirac notation; two subjects more suitable for physicists, rather than computer scientists and software engineers. On this ground, we believe it is possible to provide a more intuitive approach to thinking and writing about quantum computing systems, in order to simplify the design of quantum algorithms and the development of quantum software. In this paper, we move the first step in such direction, introducing a specification language as the tool to represent the operations of a quantum computer via axiomatic definitions, by adopting the same symbolisms and reasoning principles used by formal methods in software engineering. We name this approach formal quantum software engineering (F-QSE). This work assumes familiarity with the basic principles of quantum mechanics (QM), with the use of Zed (Z) which is a formal language of software engineering (SE), and with the notation and techniques of first-order logic (FOL) and functional programming (FP).</p>
      </abstract>
      <kwd-group>
        <kwd>eol&gt;Formal Methods</kwd>
        <kwd>Functional Programming</kwd>
        <kwd>Quantum Engineering</kwd>
        <kwd>Zed</kwd>
      </kwd-group>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>1 The probability for an observable to collapse into any of its states is the squared modulus of the states’ corresponding probability amplitudes, which are
complex numbers that weight each eigenvector and such that it is |c0|2 + ... + |cn|2 = 1.</p>
    </sec>
    <sec id="sec-2">
      <title>1.1 Formalizing the Observable</title>
      <p>
        By the third postulate of QM, an observable that has a finite number of quantum states can be
represented via a Hermitian matrix 2 . As such, the three requirements that it must have can be
described, with a sound formalism, by adopting strongly typed data and first-order logic [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ]; i.e.:
      </p>
      <sec id="sec-2-1">
        <title>1. it must be a complex square matrix of order n:</title>
      </sec>
      <sec id="sec-2-2">
        <title>2. it must be equivalent to its own conjugate transpose:</title>
        <p>3. for every eigenvector (or, column) of the matrix the eigenvalue must be a real number; and
such that it is the element on the main diagonal of the matrix:</p>
        <p>
          In Z, all three requirements can be summarized with the following axiomatic definition satisfying
the principle of soundness promoted by FM [
          <xref ref-type="bibr" rid="ref3">3</xref>
          ]:
1.2
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>The Observable Operators</title>
      <p>After having introduced the new type , it is now possible to define the observable operators.
They are elementary quantum gates that perform unitary transformations Uf (i.e., reversible
computations) and that, applied to an observable, make it possible to write quantum programs.</p>
      <p>In the following paragraphs, we introduce the axiomatic definition of the most common quantum
gates, establishing the basic tools to design quantum programs in Z.</p>
      <p>Identity gate.</p>
      <p>It is the simplest, single qubit, quantum operator, that maps the input to the output unchanged. It is
required by any operation where the same qubits that are passed as arguments must be returned:</p>
      <sec id="sec-3-1">
        <title>Pauli-X (or, Bit Flip) gate.</title>
        <p>It is the quantum equivalent of the classical NOT gate:
2 But if the Hilbert space ℋ is infinite-dimensional, the observable is described by a symmetric operator, which is represented as a map  between two
domains of basis’ states  and  ∗ dense in ℋ, such that ∀x: D, y: D∗∃ :  ↦  ∗ • ⟨  (x), y ⟩ = ⟨ x,  (y) ⟩. This is a bijective function (injective-surjective), in
the sense that it cannot map two distinct states of the domain  onto the same state of the co-domain  ∗, thus preserving its unitary quality. However,
because an infinite-dimensional space is unbounded also the operator is unbounded; therefore, it does not have a largest eigenvalue, leaving us with the
conclusion that it might not be defined everywhere and, as such, classifying it as a partial bijective function, which implies graph inclusion:  ≤  ∗.
Phase Shift gate.</p>
        <p>It represents a family of gates, that rotate the basis state |1⟩ of any arbitrary angle  :</p>
      </sec>
      <sec id="sec-3-2">
        <title>Pauli-Z (or,  Phase Shift) gate.</title>
        <p>It is a special case of the Phase Shift gate, that rotates the basis state |1⟩ a  angle:</p>
      </sec>
      <sec id="sec-3-3">
        <title>Hadamard gate.</title>
        <p>It is perhaps the most useful quantum operator because it maps any basis state to one qubit with
balanced superposition, and vice-versa:</p>
      </sec>
      <sec id="sec-3-4">
        <title>C-Not gate</title>
        <p>The Controlled Not gate is the most popular 2-qubits operator, because it puts two qubits in a
separable state, with a tensor product pairing the first qubit with the result of an addition modulo-2
between both. As such, it is used to entangle two qubits or disentangle the EPR pair:</p>
        <p>Similarly to what happens in any conventional computation, a quantum computation is just a
sequence of gates applied in a particular order: each gate takes an input and, after having performed
its operation on that input, returns an output. However, in QC, the single use of an operator
simultaneously applies to all basis states [9].</p>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>2 A Practical Example of F-QSE: Programming the Deutsch Algorithm from</title>
    </sec>
    <sec id="sec-5">
      <title>Specifications</title>
      <p>
        The Deutsch algorithm, foundation model of QC [7, 8], proves if a quantum oracle function, i.e. a
black-box that performs a unitary transformation Uf on a qubit, is constant (always maximizing the
same state) or balanced (returning each state half of the time). It exploits the quantum entanglement
principle [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ], and requires the use of two quantum operators: a Hadamard gate, for preparing two
qubits in balanced superposition, and a C-Not gate, for entangling the two qubits.
      </p>
      <p>In Dirac notation, it is represented as a ket taking a pair of qubits, prepared from two different
basis states ( and  ), and mapping them to an entangled pair where the second qubit performs as the
register storing the state (solution) that will be set on the first qubit by the quantum oracle. The
measurement of the first qubit shall, therefore, make it collapse into the state that is held by the
second qubit, to which it is entangled:</p>
      <p>With the Z notation, the algorithm can be described through axiomatic definitions; either by
writing the constraining predicate from the conventional Dirac representation (which is sound but
doesn’t add much in a SE perspective):</p>
      <p>or from the quantum circuit by taking advantage of the axiomatic definitions of the observable
operators, such as:
rather then:</p>
      <p>Indeed, with the last two definitions, by describing the algorithm through a sequence of formal
operators we offer a guidance for coding it, by directly following the stepwise logic represented.</p>
      <p>
        Of course, the coding part can be done in any quantum programming language. For our case, in
order to match the formal definitions introduced, we worked out an instruction set in Haskell that
leans on Green’s QIO library [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>The Deutsch algorithm can be now, effortlessly, translated into the following QC program:
for which, the required operators are implemented as follows:
---- return a qubit in a given state
qb :: [Char] -&gt; QIO ( Qbit )
qb qstate
| qstate = = "|0&gt;" = mkQ( False )
| qstate = = "|1&gt;" = mkQ( True )
| qstate = = "|+&gt;" || qstate = = "H|0&gt;" = do
qBit &lt;- qb( "|0&gt;" )
applyU( uhad( qBit ) )
return( qBit )
| qstate = = "|-&gt;" || qstate = = "H|1&gt;" = do
qBit &lt;- qb( "|1&gt;" )
applyU( uhad( qBit ) )
return( qBit )
| otherwise = error "qb: wrong argument"
---- apply the Hadamard gate to a qubit
qH :: Qbit -&gt; QIO ()
qH qbit = applyU( uhad( qbit ) )
---- measure a qubit
mq :: Qbit -&gt; QIO ( Bool )
mq qbit = measQ( qbit )
---- apply the C-Not gate to a qubit
qN :: (Bool -&gt; Bool) -&gt; Qbit -&gt; Qbit -&gt; QIO ()
qN f qx qy = applyU( cond (qx) (\ a → if f(a) then unot(qy) else mempty ))
3</p>
    </sec>
    <sec id="sec-6">
      <title>Conclusions and Outlooks</title>
      <p>
        The diffusion of QC cannot be forever relegated within a narrow circle of experts, but many
computer scientists and software engineers entering the field of QC are quickly put off by the existing
conceptual and notational barriers [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ]. This is not only due to the intrinsic difficulty of the subject, but
also because it can only be seen through a dark glass (as the complete knowledge of the state of a
quantum system is forbidden) [10].
      </p>
      <p>
        One of the possible ways to overcome this stasis is to introduce a vocabulary inspired by the
formal tools of SE. In this paper, the main notions of QC take the form of axiomatic definitions in the
Z notation so that they can be used throughout specifications [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. The result is a notational system
that, ideally, can be straightforwardly translated into any quantum programming language.
      </p>
      <p>Hopefully, it can open the doors of QC to a wider audience of players, helping them to beautifully
understand, describe, and finally convert the structure of quantum algorithms into fully working code.</p>
    </sec>
    <sec id="sec-7">
      <title>Acknowledgments</title>
      <p>The author would like to thank you professor emeritus Prof. Giuseppe Moesch, Prof. Ralf Hinze,
and Dr. Wojciech Roga, for the lasting guidance offered during the most intense moments of his life.
[7] D. Deutsch “Quantum Theory, the Church-Turing Principle and the Universal Quantum</p>
      <p>Computer”, Proc. Royal Soc. of London, A400:97-117, 1985
[8] D. Deutsch, R. Jozsa “Rapid Solutions of Problems by Quantum Computation”, Proc. Royal Soc.</p>
      <p>of London, A439:553, 1992
[9] A. Barenco “Quantum Computation: an Introduction”. in “Introduction to Quantum Computation
and Information”, H. Lo, S. Popescu and T. Spiller (Eds.), World Scientific, 1998
[10] A. M. Gross, J. Stallard “Implementing Grover’s Algorithm Using Linear Transformations in
Haskell”, Proceedings of the Eight Symposium on Trends in Functional Programming, 8:XXV,
2007
[11] Mateus P., Sernadas A. (2004) Reasoning About Quantum Systems. In: Alferes J.J., Leite J. (eds)
Logics in Artificial Intelligence. JELIA 2004. Lecture Notes in Computer Science, vol 3229.</p>
      <p>Springer, Berlin, Heidelberg
[12] Simon D. R. “On the Power of Quantum Computation” SIAM J. Comput., 26(5), 1474-1483
(1997)
[13] P. Kaye, R. Laflamme, M. Mosca “An Introduction to Quantum Computing” Oxford University
Press, 2007</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>C. R.</given-names>
            <surname>Cartiere</surname>
          </string-name>
          , “
          <article-title>Quantum Software Engineering: Bringing the Classical Software Engineering into the Quantum Domain”</article-title>
          ,
          <source>Master's Thesis</source>
          , University of Oxford, Department of Computer Science, Software Engineering Programme,
          <year>2013</year>
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>G. W.</given-names>
            <surname>Greenwood</surname>
          </string-name>
          , “
          <article-title>Finding Solutions to NP Problems: Philosophical Difference Between Quantum and Evolutionary Search Algorithms”</article-title>
          , Portland State University, OR, USA,
          <year>2001</year>
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>J.</given-names>
            <surname>Woodcock</surname>
          </string-name>
          , J. Davies, “Using
          <string-name>
            <given-names>Z.</given-names>
            <surname>Specification</surname>
          </string-name>
          , Refinement, and Proof”, Prentice Hall,
          <year>1996</year>
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>A. S.</given-names>
            <surname>Green</surname>
          </string-name>
          , “
          <article-title>The QIO package”, Haskell community's central package archive of open source soft</article-title>
          ., https://hackage.haskell.org/package/QIO,
          <year>v1</year>
          .
          <fpage>3</fpage>
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5]
          <string-name>
            <given-names>P.</given-names>
            <surname>Dirac</surname>
          </string-name>
          <article-title>“The Principles of Quantum Mechanics”</article-title>
          , Oxford University Press, 4th edition,
          <year>1958</year>
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>R.</given-names>
            <surname>Feynman</surname>
          </string-name>
          “Simulating Physics with Computers”,
          <source>Intl. J. Theo. Phys.</source>
          ,
          <volume>21</volume>
          :
          <fpage>467</fpage>
          -
          <lpage>488</lpage>
          ,
          <year>1982</year>
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>