440 likes | 548 Views
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
E N D
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 Haskell Workshop
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. Turing ‘36 Deutsch ‘97 Turing hoped that his abstracted-paper-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, quantum-mechanical 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. Haskell Workshop
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 Haskell Workshop
Outline • Quantum data • Operations/Functions • I/O or Measurement • Example --- Wave/Particle Duality • Conclusions and Related Work Haskell Workshop
qT = qF = 0 1 False False 1 0 True True 1 False 1 True Bits and Qubits Examples of qubits qFT = or False True Haskell Workshop
1 C1 2 C2 … … n Cn Generalize Given a type a with constructors C1, C2, …, Cn Quantum values of type QV a Haskell Workshop
Examples Haskell Workshop
1 q2 = False 1 2 q1 = False True 1 * 1 q1 &* q2 = (False,False) 2 True (False,True) 1 * 2 2 * 1 (True,False) (True,True) 2 * 2 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: Haskell Workshop
Non Compositionality and Entanglement There is no way to describe the state of the pair p2 in terms of the state of its two components. The values are ENTANGLED. Haskell Workshop
What is hadamard qF? Two Simple Operations Haskell Workshop
x c v y not ((False,False),(False,False)) 1 ((False, True),(False, True)) 1 ((True, False),(True, True)) 1 ((True, True),(True, False)) 1 Controlled-Not (cnot) 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 cnotM = What is cnot (qFT,qF) ? cnot(qFT,qF) = the pair p2 Haskell Workshop
qF hadamard not qF Our First Circuit Haskell Workshop
Probabilities • observe qFT should produce False with 50% probability and produce True with 50% probability • What happens if we observe a quantum value qFT more than once? Haskell Workshop
Collapse • MUST return (True,True,True) or (False,False,False) • Not allowed to produce (True,False,True) or any other mixed values Haskell Workshop
Observing Pairs • Given a pair of type QV (a,b) we can make three observations: • Observe the state of the pair itself • Observe the left component only • Observe the right component only Haskell Workshop
Observing Pairs Haskell Workshop
Entangled particles Light-years apart The EPR Paradox observeLeft must affect the right particle Spooky action at a distance. HOW? Faster than light communication? Multiple universes? Signals back from the future? Hidden local state? Haskell Workshop
Spooky Action at a Distance ) Side-effects Haskell Workshop
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. Haskell Workshop
1 (False,False,False) (True,True,True) 1 Virtual Values & Adaptors Pointer to the real value Adaptor (c,a) (a,b,c) b A quantum value with entangled subvalues A virtual value to operate on the third and first components Haskell Workshop
((False,False),(False,False)) 1 ((False, True),(False, True)) 1 ((True, False),(True, True)) 1 ((True, True),(True, False)) 1 Apply cnot to our virtual value cnotM = • Promote cnotM to work on the full quantum value as follows: • Extract the required components using the adaptor, apply cnot • Other components are left unchanged Promoted cnotM = ((a,b,c),(x,b,z)) cnotM((c,a),(z,x)) Haskell Workshop
Example Haskell Workshop
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 Haskell Workshop
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! Haskell Workshop
And of course … Jerzy Karczmarczuk Haskell Workshop
BBC World on SAS flight • It is a bizarre place … • … normal laws of physics break … • … the fastest machine today will seem like an abacus … Haskell Workshop
Computer Science Functional Programming, lambda calculus, etc Assembly, C, etc Hardware Physics Haskell Workshop
Matrix Representation Haskell Workshop
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 Haskell Workshop
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 Haskell Workshop
Bits and Qubits Haskell Workshop
Generalize Haskell Workshop
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: Haskell Workshop
Virtual Values & Adaptors Virtual Value 1 Adaptor 2 Quantum value with entangled subvalues Haskell Workshop
Promote the function Function Applying Operations to Virtual Values Input Output Haskell Workshop
Examples Haskell Workshop
Observing Pairs (I) Haskell Workshop
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 Haskell Workshop