Modeling Quantum Computing in Haskell Amr Sabry Indiana
Modeling Quantum Computing in Haskell Amr Sabry ﻋﻤﺮﻭﺻﺒﺮﻯ Indiana University
Our Abstractions are Broken! ¢ CS prides itself on the fact that it is insensitive to the changes in the hardware and its technology ¢ Turing Machines, complexity classes, lambda calculus, etc, were supposed to be “perfect abstractions” ¢ Changes in the model of physics (classical vs. quantum) broke through our abstractions 2 Haskell Workshop August 28, 2003
Turing ‘ 36 Deutsch ‘ 97 Computing is normally done by writing certain symbols on paper. We may suppose this paper is divided into squares like a child’s arithmetic book…. If we regard a symbol as literally printed on a square we may suppose that the square is 0 < x < 1, 0 < y <1. The symbol is defined as a set of points in this square, viz. the set occupied by printers ink. 3 Haskell Workshop Turing hoped that his abstractedpaper-tape model was so simple, so transparent and well defined, that it would not depend on any assumptions about physics that could conceivably be falsified, and therefore that it could become the basis of an abstract theory of computation that was independent of the underlying physics. 'He thought, ' as Feynman once put it, 'that he understood paper. ' But he was mistaken. Real, quantummechanical paper is wildly different from the abstract stuff that the Turing machine uses. The Turing machine is entirely classical, and does not allow for the possibility the paper might have different symbols written on it in different universes, and that those might interfere with one another. August 28, 2003
Challenge to PL Research Quantum physics is affecting hardware design, complexity theory, and propagates all the way to our high level programming languages Develop a new appropriate programming paradigm 4 Haskell Workshop August 28, 2003
Outline ¢ Quantum data ¢ Operations/Functions ¢ I/O or Measurement ¢ Example --- Wave/Particle Duality ¢ Conclusions and Related Work 5 Haskell Workshop August 28, 2003
Quantum Data
Bits and Qubits q. F = Examples of qubits False True q. FT = False 1 0 q. T = True or False True 7 False Haskell Workshop 0 1 1 1 August 28, 2003
Generalize Given a type a with constructors C 1, C 2, …, Cn Quantum values of type QV a C 1 C 2 … Cn 8 1 2 … n Haskell Workshop August 28, 2003
Examples 9 Haskell Workshop August 28, 2003
Pairs ¢ ¢ Pairs of type (QV a, QV b): No surprises … Pairs of type QV (a, b) can be assembled from two quantum values using a tensor product: q 1 = False 1 True 2 q 1 &* q 2 = 10 q 2 = False 1 True 2 (False, False) 1 * 1 (False, True) 1 * 2 (True, False) 2 * 1 (True, True) 2 * 2 Haskell Workshop August 28, 2003
Non Compositionality and Entanglement There is no way to describe the state of the pair p 2 in terms of the state of its two components. The values are ENTANGLED. 11 Haskell Workshop August 28, 2003
Functions / Operations
Two Simple Operations What is hadamard q. F ? 13 Haskell Workshop August 28, 2003
Controlled-Not (cnot) x c v not y cnot(c, v) = (x, y) where x is always the same as c if c is False, y = v if c is True, y = not v cnot. M = ((False, False), (False, False)) 1 ((False, True), (False, True)) 1 What is cnot (q. FT, q. F) ? ((True, False), (True, True)) 1 cnot(q. FT, q. F) = the pair p 2 ((True, True), (True, False)) 1 14 Haskell Workshop August 28, 2003
Our First Circuit q. F hadamard not q. F 15 Haskell Workshop August 28, 2003
Measurement
Probabilities ¢ observe q. FT should produce False with 50% probability and produce True with 50% probability ¢ What happens if we observe a quantum value q. FT more than once? 17 Haskell Workshop August 28, 2003
Collapse ¢ ¢ 18 MUST return (True, True) or (False, False) Not allowed to produce (True, False, True) or any other mixed values Haskell Workshop August 28, 2003
Observing Pairs ¢ Given a pair of type QV (a, b) we can make three observations: 1. Observe the state of the pair itself Observe the left component only Observe the right component only 2. 3. 19 Haskell Workshop August 28, 2003
Observing Pairs 20 Haskell Workshop August 28, 2003
The EPR Paradox Entangled particles Light-years apart observe. Left must affect the right particle 21 Spooky action at a distance. HOW? Faster than light communication? Multiple universes? Signals back from the future? Hidden local state? Haskell Workshop August 28, 2003
Spooky Action at a Distance ) Side-effects 22 Haskell Workshop August 28, 2003
Wave/Particle Duality
Let’s Implement a Simple Example… The individual operations are easy: H is hadamard, V and VT are phase-shifting operations But given a generally entangled triple QV (a, b, c), how can we conveniently apply an operation on the first component, or the second and third, or the first and third, etc given that we cannot decompose the tuple into its three components. 24 Haskell Workshop August 28, 2003
Virtual Values & Adaptors Pointer to the real value Adaptor (False, False) 1 (True, True) 1 (c, a) (a, b, c) b A quantum value with entangled subvalues A virtual value to operate on the third and first components 25 Haskell Workshop August 28, 2003
Apply cnot to our virtual value cnot. M = ((False, False), (False, False)) 1 ((False, True), (False, True)) 1 ((True, False), (True, True)) 1 ((True, True), (True, False)) 1 Promote cnot. M to work on the full quantum value as follows: -Extract the required components using the adaptor, apply cnot -Other components are left unchanged Promoted cnot. M = 26 ((a, b, c), (x, b, z)) Haskell Workshop cnot. M((c, a), (z, x)) August 28, 2003
Example 27 Haskell Workshop August 28, 2003
Conclusions and Related Work
Summary Quantum values are maps from classical values to probability amplitudes (complex numbers) ¢ Functions are matrices ¢ Observation causes collapse (modeled by side-effects) ¢ Programming without destructors ¢ 29 Haskell Workshop August 28, 2003
A Lambda Calculus for QC by André van Tonder ¢ ¢ -calculus with (quantum) constants Uses sequences of terms (history) to make reductions reversible State ´ a superposition of sequences To avoid having history terms entangled with computational terms, functions are linear (cannot discard superpositions) ¢ No observation No datatypes: still talks about qubits and gates Can use pattern-matching on entangled values! 30 Haskell Workshop ¢ ¢ August 28, 2003
And of course … Jerzy Karczmarczuk 31 Haskell Workshop August 28, 2003
BBC World on SAS flight ¢ ¢ ¢ 32 It is a bizarre place … … normal laws of physics break … … the fastest machine today will seem like an abacus … Haskell Workshop August 28, 2003
Computer Science Functional Programming, lambda calculus, etc Assembly, C, etc Hardware Physics 33 Haskell Workshop August 28, 2003
Matrix Representation 34 Haskell Workshop August 28, 2003
Conventions in Physics ¢ Quantum values represented by a vector of probability amplitudes (in some implicit order) ¢ Quantum operations represented by matrices giving for each input constructor its contribution to each output constructor ¢ Applying an operation to a value is multiplication 35 Haskell Workshop August 28, 2003
Potential Rewards ¢ Nature’s programming paradigm might be better than what we have. ¢ Information flow in QM is a mystery (EPR paradox). An executable semantics for QC might help. ¢ There are some appealing connections between quantum computing and functional programming (operations must be pure and reversible, evaluation is different from observation, quantum values cannot be cloned i. e. are linear, etc) ¢ comp. lang. functional discussion about free will and predestination 36 Haskell Workshop August 28, 2003
Bits and Qubits 37 Haskell Workshop August 28, 2003
Generalize 38 Haskell Workshop August 28, 2003
Pairs ¢ ¢ Pairs of type (QV a, QV b): No surprises … Pairs of type QV (a, b) can be assembled from two quantum values using a tensor product: 39 Haskell Workshop August 28, 2003
Virtual Values & Adaptors Virtual Value 1 Adaptor 2 Quantum value with entangled subvalues 40 Haskell Workshop August 28, 2003
Applying Operations to Virtual Values Input Function Promote the function Output 41 Haskell Workshop August 28, 2003
Examples 42 Haskell Workshop August 28, 2003
Observing Pairs (I) 43 Haskell Workshop August 28, 2003
Accessing Substructures ¢ In conventional programming: composable references, façade pattern, … ¢ In quantum computing: virtual registers, shuffle wires, or our proposal of virtual values and adaptors 44 Haskell Workshop August 28, 2003
- Slides: 44