Download - Modeling Quantum Computing in Haskell
Modeling Quantum Computing in Haskell
Amr Sabry
صبرى عمروIndiana University
August 28, 2003 Haskell Workshop2 of 31
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
August 28, 2003 Haskell Workshop3 of 31
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.
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.
August 28, 2003 Haskell Workshop4 of 31
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
August 28, 2003 Haskell Workshop5 of 31
Outline
Quantum data
Operations/Functions
I/O or Measurement
Example --- Wave/Particle Duality
Conclusions and Related Work
Quantum Data
August 28, 2003 Haskell Workshop7 of 31
Bits and Qubits
orTrue
FalseqFT = True
False
11
Examples of qubits
True
False
01qF =
True
False
10qT =
August 28, 2003 Haskell Workshop8 of 31
Generalize
Given a type a with constructors C1, C2, …, Cn
Quantum values of type QV a
C1 1
… …
C2
Cn
2
n
August 28, 2003 Haskell Workshop9 of 31
Examples
August 28, 2003 Haskell Workshop10 of 31
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:
q2 = True
False 1
2True
Falseq1 = 1
2
q1 &* q2 = (False,False) 1 * 1
(False,True) 1 * 2
(True,False) 2 * 1
(True,True) 2 * 2
August 28, 2003 Haskell Workshop11 of 31
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.ENTANGLED.
Functions / Operations
August 28, 2003 Haskell Workshop13 of 31
Two Simple Operations
What is hadamard qF ?
August 28, 2003 Haskell Workshop14 of 31
Controlled-Not (cnot)
c x
notv 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
What is cnot (qFT,qF) ?
cnot(qFT,qF) = the pair p2
((False,False),(False,False)) 1
((False, True),(False, True)) 1
((True, False),(True, True)) 1
((True, True),(True, False)) 1
cnotM =
August 28, 2003 Haskell Workshop15 of 31
Our First Circuit
not
hadamardqF
qF
Measurement
August 28, 2003 Haskell Workshop17 of 31
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?
August 28, 2003 Haskell Workshop18 of 31
Collapse
MUST return (True,True,True) or (False,False,False)
Not allowed to produce (True,False,True) or any other mixed values
August 28, 2003 Haskell Workshop19 of 31
Observing Pairs
Given a pair of type QV (a,b) we can make three observations:
1. Observe the state of the pair itself
2. Observe the left component only
3. Observe the right component only
August 28, 2003 Haskell Workshop20 of 31
Observing Pairs
August 28, 2003 Haskell Workshop21 of 31
The EPR Paradox
Entangled particles
Light-years apart
observeLeft must affect the right particle
Faster than light communication?Multiple universes?Signals back from the future?Hidden local state?
Spooky action at a distance. HOW?
August 28, 2003 Haskell Workshop22 of 31
Spooky Action at a Distance ) Side-effects
Wave/Particle Duality
August 28, 2003 Haskell Workshop24 of 31
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.
August 28, 2003 Haskell Workshop25 of 31
Virtual Values & Adaptors
(False,False,False)
(True,True,True) 1
1
A quantum value with entangled subvalues
A virtual value to operate on the third and first components
Pointer to the real value
Adaptor
(a,b,c)(c,a)
b
August 28, 2003 Haskell Workshop26 of 31
Apply cnot to our virtual value
cnotM = ((False,False),(False,False)) 1
((False, True),(False, True)) 1
((True, False),(True, True)) 1
((True, True),(True, False)) 1
((a,b,c),(x,b,z)) cnotM((c,a),(z,x))
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 =
August 28, 2003 Haskell Workshop27 of 31
Example
Conclusions and Related Work
August 28, 2003 Haskell Workshop29 of 31
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
August 28, 2003 Haskell Workshop30 of 31
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!
August 28, 2003 Haskell Workshop31 of 31
And of course …
Jerzy Karczmarczuk
August 28, 2003 Haskell Workshop32 of 31
BBC World on SAS flight
It is a bizarre place … … normal laws of physics break … … the fastest machine today will seem like
an abacus …
August 28, 2003 Haskell Workshop33 of 31
Computer Science
Physics
Hardware
Assembly, C, etc
Functional Programming, lambda calculus, etc
August 28, 2003 Haskell Workshop34 of 31
Matrix Representation
August 28, 2003 Haskell Workshop35 of 31
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
August 28, 2003 Haskell Workshop36 of 31
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
August 28, 2003 Haskell Workshop37 of 31
Bits and Qubits
August 28, 2003 Haskell Workshop38 of 31
Generalize
August 28, 2003 Haskell Workshop39 of 31
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:
August 28, 2003 Haskell Workshop40 of 31
Virtual Values & Adaptors
Quantum value with entangled subvalues
Adaptor
Virtual Value
1
2
August 28, 2003 Haskell Workshop41 of 31
Applying Operations to Virtual Values
Input
Function
Output
Promote the function
August 28, 2003 Haskell Workshop42 of 31
Examples
August 28, 2003 Haskell Workshop43 of 31
Observing Pairs (I)
August 28, 2003 Haskell Workshop44 of 31
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