Programming with classical quantum datatypes

Size: px
Start display at page:

Download "Programming with classical quantum datatypes"

Transcription

1 Programming with classical quantum datatypes Robin Cockett & Brett Giles University of Calgary FMCS 2006, Programming with classical quantum datatypes p. 1/49

2 Yet another Quantum Programming Language (QPL)... Linear type system with (classically controlled) datatypes No higher-order constructs... Only built-in types are Qbit and Int. Built-in unitary transformations. A QPL program consists of function definitions and main instructions. Compiles to Quantum Stack Machine (QSM). Quantum assembler calculates density matrix. FMCS 2006, Programming with classical quantum datatypes p. 2/49

3 Semantics... Countably infinite bi-products of completely positive matrices with trace less than or equal to 1. fhilb CPM(fHilb) Mat (CPM(fHilb)) Similar to the semantics of Peter Selinger s QPL. FMCS 2006, Programming with classical quantum datatypes p. 3/49

4 This QPL... Can declare (classically controlled) datatypes (e.g. lists of Quantum bits). Linear variables are unscoped: live from introduction to first use (cannot be used twice). Classical data extracted from linear variables by use command. Classical variables are scoped: live to end of a block (multiple uses permitted). Quantum bits can be measured, Integers have usual arithmetic functions... FMCS 2006, Programming with classical quantum datatypes p. 4/49

5 Example datatype declarations type Bool = { True False } type L i s t a = { N i l Cons ( a, ( L i s t a ) ) } type E i t h e r a b = { L e f t ( a ) Right ( b ) } type Maybe a = { Nothing Just ( a ) } type BinTree a = { Leaf ( a ) Br ( ( BinTree a ), ( BinTree a ) ) } FMCS 2006, Programming with classical quantum datatypes p. 5/49

6 Language constructs continued... Function declaration rotate :: (n : Int,x 1 : Qbit,x 2 : List(Qbit); y 1 : Qbit,y 2 : List(Qbit)) = {statements} Function calls: rotate(n,x,y;x,y); (x,y) = rotate(n,x,y); rotate(n) x y; Had q;not q;not q 1 <=q 2 ;... FMCS 2006, Programming with classical quantum datatypes p. 6/49

7 Example Program: coin flip # Import Prelude. qpl c f l i p : : ( ; b : Bool ) = { q = 0 > ; Had q ; measure q of 0 > => { b = False } 1 > => { b = True } ; } main : : ( ) = { b = c f l i p ( ) ; } FMCS 2006, Programming with classical quantum datatypes p. 7/49

8 Language construct: measurement measure q of 0 {...} 1 {...};... measurement is a control construct... FMCS 2006, Programming with classical quantum datatypes p. 8/49

9 Example Program: Teleport prepare : : ( ; a : Qbit, b : Qbit ) = { a = 0 > ; b = 0 > ; Had a ; Not b <= a } / / C o n t r o l l e d Not t e l e p o r t : : ( x : Qbit ; b : Qbit ) = { ( a, b ) = prepare ( ) ; Not a <= x ; Had x ; measure a of 0 > => { } 1 > => { Not b } ; measure x of 0 > => { } 1 > => {RhoZ b } } FMCS 2006, Programming with classical quantum datatypes p. 9/49

10 Language constructs continued... Loops:... handled by recursion. Pattern matching: case q of nil {...} cons(x,xs) {...}; FMCS 2006, Programming with classical quantum datatypes p. 10/49

11 Example Program: append # Import Prelude. qpl append : : ( x : L i s t ( a ), y : L i s t ( a ) ; z : L i s t ( a ) ) = { case x of N i l => { z = y } Cons ( v, vs ) => { z = Cons ( v, append ( vs, y ) ) } } FMCS 2006, Programming with classical quantum datatypes p. 11/49

12 Language constructs continued... Discarding: discard q 1,...,q n ; implicit discarding of variables on joining of control paths (with warning). Linear assignment is basic: q = expression; q is a linear variable... There is syntactic sugar for classical assignment (see below). FMCS 2006, Programming with classical quantum datatypes p. 12/49

13 Using classical data... Syntactic sugar: use x 1,...,x n in {statements} x := expr;...; x = expr; use x in {...;} use x 1,...,x n ;...; use x 1,...,x n in {...;} FMCS 2006, Programming with classical quantum datatypes p. 13/49

14 Example Program: rotate r o t a t e : : ( n : Int, h : Qbit, z : L i s t ( Qbit ) ; h : Qbit, z : L i s t ( Qbit ) ) = { case z of N i l => { discard n ; z = N i l } Cons ( x, y ) => { use n in { R( n ) x h ; m = n+1 } ; r o t a t e (m) h y ; z = Cons ( x, y ) } } FMCS 2006, Programming with classical quantum datatypes p. 14/49

15 Example Program: Quantum Fourier Transform q f t : : ( qf : L i s t ( Qbit ) ; qf : L i s t ( Qbit ) ) = { case qf of N i l => { qf = N i l } Cons ( head, t a i l ) => { { Had head ; r o t a t e ( 2 ) head t a i l ; q f t t a i l ; qf = Cons ( head, t a i l ) } } FMCS 2006, Programming with classical quantum datatypes p. 15/49

16 A Quantum stack machine The machine state consists of the quantum stack, a classical stack, and a dump. The quantum stack is represented as a tree, with three types of nodes (Qbit, Datatype, Int) and values at the leaves (zero probability branches are not represented). Operations are done primarily on the top node or top few nodes. Rotation of the tree allows us to bring a node to the top. The dump is used to hold intermediate data during instruction execution. FMCS 2006, Programming with classical quantum datatypes p. 16/49

17 Qbit Nodes A Qbit is represented by a node with four branches, labeled by 00, 01, 10 and 11 (equivalent to the density matrix notation of a Qbit). Note that physically, we only store those branches with non-zero values at the leaves. FMCS 2006, Programming with classical quantum datatypes p. 17/49

18 Int nodes Classical data is represented by a node with an arbitrary (finite) number of branches labeled by classical values (e.g. Int values): FMCS 2006, Programming with classical quantum datatypes p. 18/49

19 Datatype nodes A node with a branch for each constructor which is labeled by the constructor name and the variables the construction binds. FMCS 2006, Programming with classical quantum datatypes p. 19/49

20 Binding... Variables bound along a branch of a node cannot be rotated above their point of binding... so can not be manipulated directly in the Quantum stack. FMCS 2006, Programming with classical quantum datatypes p. 20/49

21 Example program evaluation: coin flip... # Import Prelude. qpl c f l i p : : ( ; q : Qbit, r : Bool ) = { q = 0 > ; Had q ; measure q of 0 > => { q = 0 > ; r = True } 1 > => { q = 1 > ; r = False } ; } main : : ( ) = { ( q, b ) = c f l i p ( ) ; } FMCS 2006, Programming with classical quantum datatypes p. 21/49

22 Empty stack FMCS 2006, Programming with classical quantum datatypes p. 22/49

23 Introduce Qbit 0 FMCS 2006, Programming with classical quantum datatypes p. 23/49

24 Hadamard FMCS 2006, Programming with classical quantum datatypes p. 24/49

25 Measure FMCS 2006, Programming with classical quantum datatypes p. 25/49

26 Left branch FMCS 2006, Programming with classical quantum datatypes p. 26/49

27 Left branch: introduce Qbit 0 FMCS 2006, Programming with classical quantum datatypes p. 27/49

28 Left branch: introduce True FMCS 2006, Programming with classical quantum datatypes p. 28/49

29 Swap to right branch FMCS 2006, Programming with classical quantum datatypes p. 29/49

30 Right branch: introduce Qbit 1 FMCS 2006, Programming with classical quantum datatypes p. 30/49

31 Right branch: introduce False FMCS 2006, Programming with classical quantum datatypes p. 31/49

32 Merge FMCS 2006, Programming with classical quantum datatypes p. 32/49

33 Quantum Stack Machine Instructions QPL programs compile to Quantum Stack Machine (QSM) code. QPL QSM QSM code is run by the QSM-assembler. The design of an efficient yet basic instruction set for this machine has been an issue... FMCS 2006, Programming with classical quantum datatypes p. 33/49

34 QSM Instructions: node construction QLoad x k : creates a node called x with a single branch labeled k on top of the Quantum stack. QCons x cons: creates a node called x with a single branch labeled cons (the specific constructor) on top of the Quantum stack. QMove x: removes the top value of the classical stack and creates, on top of the Quantum stack, a node called x with a single branch labeled by that classical value. QBind z: expects a node with a single branch and binds the variable z down that branch. FMCS 2006, Programming with classical quantum datatypes p. 34/49

35 Construction Transitions (QLoad x k :C,S,Q,D) = (C,S,x:[ k Q],D) (QCons x c:c,s,q,d) = (C,S,x:[c{} Q],D) (QBind z 0 :C,S,x:[c{z 1,...,z n} Q],D) = (C,S,x:[c{z 0,z 1,...,z n} Q[z 0/z 0 ]],D) (QMove x:c,v:s,q,d) = (C,S,x:[ v Q],D) FMCS 2006, Programming with classical quantum datatypes p. 35/49

36 QSM Instructions: node destruction QUnbind x: Expects the stack have a node with a single branch on top with a list of bound variables. The first bound variable is removed and renamed to x to make it free. QDiscard: Discards the top node by merging its classical branches. FMCS 2006, Programming with classical quantum datatypes p. 36/49

37 Destruction Transitions (QDiscard:C,S,x:[ k Q],D) = (C,S,Q,D) (QDiscard:C,S,x:[c{} Q],D) = (C,S,Q,D) (QDiscard:C,S,x:[ v Q],D) = (C,v:S,Q,D) (QUnbind y:c,s,x:[c{z 1,...,z n} Q],D) = (C,S,x:[c{z 2,...,z n} Q[y/z 1]],D) ( k { 0, 1 }) FMCS 2006, Programming with classical quantum datatypes p. 37/49

38 QSM Instructions: stack manipulation QPullup x: Rotates the node labeled x to the top of the Quantum stack. QApply 0 Had: Expects 1 Qbit on top of the Quantum stack and applies the Hadamard transformation to it. QApply 1 Rotate: Parametrizes the Rotate transform by the top element of the classical stack and then applies it to the 2 Qbits on the top of the stack. QName x y: Renames the (visible) node x to y. FMCS 2006, Programming with classical quantum datatypes p. 38/49

39 Manipulation Transitions (QPullup x:c,s,q,d) = (C,S, pull(x,q),d (QApply n t:c,v 1 : :v n :S,Q,D) = (C,v 1 : :v n :S, transform([v 1,...,v n ],t,q),d) (QName x y:c,s,q,d) = (C,S,Q[y/x],D) FMCS 2006, Programming with classical quantum datatypes p. 39/49

40 QSM Instructions: Quantum control; Use; Split; Measure Use label: Expects top of the Quantum stack to be classical. For each branch put this value on the classical stack, perform the computation at label, which is ended by EndQC, and merge the results. Split [Nil label 1,Cons label 2 ]: Expects a datatype node on top of the Quantum stack. Executes the code at label i, which is ended with EndQC, on each branch with a matching label and merges the results. Meas label 1 label 2 : Expects a Qbit node on top of the Quantum stack. Executes the code at label 1, which is ended with EndQC, on the 0 branch and label 2 on the 1 branch and merges the results. FMCS 2006, Programming with classical quantum datatypes p. 40/49

41 Transitions for Quantum Control - Use (Use C U :C,S,x:[ v i Q i ],D) = (EndQC,S, 0, Qc(S, [(x i :v i Q i, C U )], C, 0):D) (EndQC,S,Q, Qc(S, [(x i :v i Q i, C U )] i=j,...,m, C,Q ):D) = (C U,S,x j, Qc(S, [(x i :v i Q i, C U )] i=j+1,...,m, C,Q + Q ):D) (EndQC,S,Q, Qc(S, [], C,Q ):D) = (C,S,Q + Q,D) FMCS 2006, Programming with classical quantum datatypes p. 41/49

42 Transitions for Quantum Control - Split (Split [(c i, C i )]:C,S,x:[c i {V i } Q i ],D) = (EndQC,S, 0, Qc(S, [(x i :c i {V i } Q i, C i )], C, 0):D) (EndQC,S,Q, Qc(S, [(x i :c i {V i } Q i, C i )] i=j,...,m, C,Q ):D) = (C j,s,x j, Qc(S, [(x i :c i {V i } Q i, C i )] i=j+1,...,m, C,Q + Q ):D) (EndQC,S,Q, Qc(S, [], C,Q ):D) = (C,S,Q + Q,D) FMCS 2006, Programming with classical quantum datatypes p. 42/49

43 Transitions for Quantum Control - Measure (Meas C 0 C 1 :C,S,x:[ 0 Q 0, 1 Q 1, Q],D) = (EndQC,S, 0, Qc(S, [(x k : k Q k, C k )] k {0,1}, C, 0):D) (EndQC,S,Q, Qc(S, [(x k : k Q k, C k )] k {0,1}, C,Q ):D) = (C 0,S,x 0, Qc(S, [(x 1 : 1 Q 1, C 1 )], C,Q + Q ):D) (EndQC,S,Q, Qc(S, [(x 1 : 1 Q 1, C 1 )], C,Q ):D) = (C 1,S,x 1, Qc(S, [], C,Q + Q ):D) (EndQC,S,Q, Qc(S, [], C,Q ):D) = (C,S,Q + Q,D) FMCS 2006, Programming with classical quantum datatypes p. 43/49

44 QSM Instructions: classical control Jump label: Jumps to the code at label. CJump label: Pops the top element of the classical stack if it is true jumps to the code at label. Call label: Pushes the return code pointer onto the dump and jumps to the subroutine code. Return: Pops the code label off the dump and continues execution of the code to which it points. FMCS 2006, Programming with classical quantum datatypes p. 44/49

45 Transitions for Classical Control (Jump C J :C,S,Q,D) = (C J,S,Q,D) (CJump C J :C, False:S,Q,D) = (C J,S,Q,D) (CJump C J :C, True:S,Q,D) = (C,S,Q,D) (Call n C C :C,v 1 : :v n :S,Q,D) = (C C, [v 1,...,v n ],Q,R(S, C):D) (Return n,v 1 : :v n :S,Q,R(S, C):D) = (C, [v 1,...,v n ]:S,Q,D) FMCS 2006, Programming with classical quantum datatypes p. 45/49

46 QSM Instructions: classical CGet n: Puts the n th Classical stack value on top of the Classical stack. CApply ADD: Pops the top values off the classical stack, applies the operation and pushes the result back onto the stack. CLoad n: Pushes the constant value n onto the Classical stack. CPop: Pops the top element off the Classical stack. FMCS 2006, Programming with classical quantum datatypes p. 46/49

47 Transitions for Classical Operations (CPop:C,v:S,Q,D) = (C,S,Q,D) (CGet n:c,v 1 : :v n :S,Q,D) = (c,v n :v 1 : :v n :S,Q,D) (CApply op n :C,v 1 : :v n :S,Q,D) = (C, op n (v 1,...,v n ):S,Q,D) (CLoad n :C,S,Q,D) = (C,n:S,Q,D) FMCS 2006, Programming with classical quantum datatypes p. 47/49

48 Recursion The machine stack is actually a stream of stacks, where stacks further down the stream correspond to progressive unfoldings of the recursion. The limit of the stream is the computation. Instructions are lifted by the standard Kliesli lifting to produce a function between streams of Quantum stacks. FMCS 2006, Programming with classical quantum datatypes p. 48/49

49 Conclusion Where are we... State of QPL compiler: Working, generating code! State of quantum stack machine: Working with this instruction set, revising for controlled transforms. State of QPL programs: order finding for Shor s factoring algorithm compiling, and quantum search not done. Where are we going... Expect to complete implementation this fall. Plan to make web runnable version available. Executable compiler and QPL programs will be down-loadable. FMCS 2006, Programming with classical quantum datatypes p. 49/49

THE UNIVERSITY OF CALGARY. Programming with a Quantum Stack. Brett Gordon Giles A THESIS SUBMITTED TO THE FACULTY OF GRADUATE STUDIES

THE UNIVERSITY OF CALGARY. Programming with a Quantum Stack. Brett Gordon Giles A THESIS SUBMITTED TO THE FACULTY OF GRADUATE STUDIES THE UNIVERSITY OF CALGARY Programming with a Quantum Stack by Brett Gordon Giles A THESIS SUBMITTED TO THE FACULTY OF GRADUATE STUDIES IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR THE DEGREE OF MASTER

More information

Programming Language Concepts, CS2104 Lecture 3

Programming Language Concepts, CS2104 Lecture 3 Programming Language Concepts, CS2104 Lecture 3 Statements, Kernel Language, Abstract Machine 31 Aug 2007 CS2104, Lecture 3 1 Reminder of last lecture Programming language definition: syntax, semantics

More information

Roy L. Crole. Operational Semantics Abstract Machines and Correctness. University of Leicester, UK

Roy L. Crole. Operational Semantics Abstract Machines and Correctness. University of Leicester, UK Midlands Graduate School, University of Birmingham, April 2008 1 Operational Semantics Abstract Machines and Correctness Roy L. Crole University of Leicester, UK Midlands Graduate School, University of

More information

Quantum Functional Programming Language & Its Denotational Semantics

Quantum Functional Programming Language & Its Denotational Semantics Quantum Functional Programming Language & Its Denotational Semantics Ichiro Hasuo Dept. Computer Science University of Tokyo Naohiko Hoshino Research Inst. for Math. Sci. Kyoto University Talk based on:

More information

An Introduction to Z3

An Introduction to Z3 An Introduction to Z3 Huixing Fang National Trusted Embedded Software Engineering Technology Research Center April 12, 2017 Outline 1 SMT 2 Z3 Huixing Fang (ECNU) An Introduction to Z3 April 12, 2017 2

More information

Towards a High Level Quantum Programming Language

Towards a High Level Quantum Programming Language Towards a High Level Quantum Programming Language Thorsten Altenkirch University of Nottingham based on joint work with Jonathan Grattage and discussions with V.P. Belavkin Towards ahigh LevelQuantum Programming

More information

4th year Project demo presentation

4th year Project demo presentation 4th year Project demo presentation Colm Ó héigeartaigh CASE4-99387212 coheig-case4@computing.dcu.ie 4th year Project demo presentation p. 1/23 Table of Contents An Introduction to Quantum Computing The

More information

Declarative Computation Model. Conditional. Case statement. Procedure values (2) Procedure values. Sequential declarative computation model

Declarative Computation Model. Conditional. Case statement. Procedure values (2) Procedure values. Sequential declarative computation model Declarative Computation Model Kernel language semantics revisited (VRH.4.5) From kernel to practical language (VRH.6) Exceptions (VRH.7) Carlos Varela RPI October 0, 009 Adapted with permission from: Seif

More information

A High Level Programming Language for Quantum Computing

A High Level Programming Language for Quantum Computing QUARK QUantum Analysis and Realization Kit A High Level Programming Language for Quantum Computing Team In lexicographical order: Name UNI Role Daria Jung djj2115 Verification and Validation Jamis Johnson

More information

Reasoning About Imperative Programs. COS 441 Slides 10b

Reasoning About Imperative Programs. COS 441 Slides 10b Reasoning About Imperative Programs COS 441 Slides 10b Last time Hoare Logic: { P } C { Q } Agenda If P is true in the initial state s. And C in state s evaluates to s. Then Q must be true in s. Program

More information

Models of Computation. by Costas Busch, LSU

Models of Computation. by Costas Busch, LSU Models of Computation by Costas Busch, LSU 1 Computation CPU memory 2 temporary memory input memory CPU output memory Program memory 3 Example: f ( x) x 3 temporary memory input memory Program memory compute

More information

Foundations of Computer Science Lecture 23 Languages: What is Computation?

Foundations of Computer Science Lecture 23 Languages: What is Computation? Foundations of Computer Science Lecture 23 Languages: What is Computation? A Formal Model of a Computing Problem Decision Problems and Languages Describing a Language: Regular Expressions Complexity of

More information

Quantum Effects. Juliana K. Vizzotto 1 Thorsten Altenkirch 2. Amr Sabry January Yale CS Colloquium Page 1

Quantum Effects. Juliana K. Vizzotto 1 Thorsten Altenkirch 2. Amr Sabry January Yale CS Colloquium Page 1 Quantum Effects Juliana K. Vizzotto 1 Thorsten Altenkirch 2 Amr Sabry 3 1 Federal University of Rio Grande do Sul 2 The University of Nottingham 3 Indiana University 2 January 25 Yale CS Colloquium Page

More information

Quantum data and control made easier

Quantum data and control made easier QPL 006 Preliminary Version Quantum data and control made easier Michael Lampis 1, Kyriakos G. Ginis 3 Nikolaos S. Papaspyrou 4 School of Electrical and Computer Engineering National Technical University

More information

Orthogonality and Algebraic Lambda-Calculus

Orthogonality and Algebraic Lambda-Calculus Orthogonality and Algebraic Lambda-Calculus Benoît Valiron March 28, 2010 Abstract Directly encoding lambda-terms on quantum strings while keeping a quantum interpretation is a hard task. As shown by van

More information

Register machines L2 18

Register machines L2 18 Register machines L2 18 Algorithms, informally L2 19 No precise definition of algorithm at the time Hilbert posed the Entscheidungsproblem, just examples. Common features of the examples: finite description

More information

Operational Semantics

Operational Semantics Operational Semantics Semantics and applications to verification Xavier Rival École Normale Supérieure Xavier Rival Operational Semantics 1 / 50 Program of this first lecture Operational semantics Mathematical

More information

THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521

THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521 P. 1 of 7 THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521 December, 2016 Time: 2 hrs. Instructions The exam contains questions totaling 100 points. Answer all questions.

More information

Quantum Recursion and Second Quantisation

Quantum Recursion and Second Quantisation Quantum Recursion and Second Quantisation Mingsheng Ying State Key Laboratory of Computer Science Outline 1. Introduction 2. Recursive Programming 3. Classical Recursion in Quantum Programming 4. Quantum

More information

- Why aren t there more quantum algorithms? - Quantum Programming Languages. By : Amanda Cieslak and Ahmana Tarin

- Why aren t there more quantum algorithms? - Quantum Programming Languages. By : Amanda Cieslak and Ahmana Tarin - Why aren t there more quantum algorithms? - Quantum Programming Languages By : Amanda Cieslak and Ahmana Tarin Why aren t there more quantum algorithms? there are only a few problems for which quantum

More information

Solutions to EoPL3 Exercises

Solutions to EoPL3 Exercises Solutions to EoPL3 Exercises Release 0.1.0 Cheng Lian May 16, 2017 Contents 1 Contents 3 2 Overview 29 i ii Author Cheng Lian Contents 1 2 Contents CHAPTER 1 Contents Chapter 1.

More information

Normalization by Evaluation

Normalization by Evaluation Normalization by Evaluation Andreas Abel Department of Computer Science and Engineering Chalmers and Gothenburg University PhD Seminar in Mathematical Engineering EAFIT University, Medellin, Colombia 9

More information

Quantum Computing Virtual Machine. Author: Alexandru Gheorghiu Scientific advisor: PhD. Lorina Negreanu

Quantum Computing Virtual Machine. Author: Alexandru Gheorghiu Scientific advisor: PhD. Lorina Negreanu Quantum Computing Virtual Machine Author: Alexandru Gheorghiu Scientific advisor: PhD. Lorina Negreanu Quantum Computing Virtual Machine Quantum Computing Computer science + quantum mechanics = quantum

More information

THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521

THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521 P. 1 of 7 THE UNIVERSITY OF CALGARY FACULTY OF SCIENCE FINAL EXAMINATION COMPUTER SCIENCE 521 December, 2014 Time: 2 hrs. Instructions The exam contains questions totaling 100 points. Answer all questions.

More information

Parallelism and Machine Models

Parallelism and Machine Models Parallelism and Machine Models Andrew D Smith University of New Brunswick, Fredericton Faculty of Computer Science Overview Part 1: The Parallel Computation Thesis Part 2: Parallelism of Arithmetic RAMs

More information

Part I: Definitions and Properties

Part I: Definitions and Properties Turing Machines Part I: Definitions and Properties Finite State Automata Deterministic Automata (DFSA) M = {Q, Σ, δ, q 0, F} -- Σ = Symbols -- Q = States -- q 0 = Initial State -- F = Accepting States

More information

Depending on equations

Depending on equations Depending on equations A proof-relevant framework for unification in dependent type theory Jesper Cockx DistriNet KU Leuven 3 September 2017 Unification for dependent types Unification is used for many

More information

Towards a Quantum Programming Language

Towards a Quantum Programming Language The final version of this paper appeared in Math. Struct. in Comp. Science 14(4:527-586, 2004 Towards a Quantum Programming Language P E T E R S E L I N G E R Department of Mathematics and Statistics University

More information

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures

1 Introduction. 2 Recap The Typed λ-calculus λ. 3 Simple Data Structures CS 6110 S18 Lecture 21 Products, Sums, and Other Datatypes 1 Introduction In this lecture, we add constructs to the typed λ-calculus that allow working with more complicated data structures, such as pairs,

More information

Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL. C. Varela; Adapted w. permission from S. Haridi and P. Van Roy 1

Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL. C. Varela; Adapted w. permission from S. Haridi and P. Van Roy 1 Higher-Order Programming: Iterative computation (CTM Section 3.2) Closures, procedural abstraction, genericity, instantiation, embedding (CTM Section 3.6.1) Carlos Varela RPI September 15, 2015 Adapted

More information

Static Program Analysis

Static Program Analysis Static Program Analysis Xiangyu Zhang The slides are compiled from Alex Aiken s Michael D. Ernst s Sorin Lerner s A Scary Outline Type-based analysis Data-flow analysis Abstract interpretation Theorem

More information

System F. Proofs and Types. Bow-Yaw Wang. Academia Sinica. Spring 2012

System F. Proofs and Types. Bow-Yaw Wang. Academia Sinica. Spring 2012 Proofs and Types System F Bow-Yaw Wang Academia Sinica Spring 2012 The Calculus Types in System F are defined as follows. type variables: X, Y,.... if U and V are types, then U V is a type. if V is a type

More information

Simulating and compiling code for the Sequential Quantum Random Access Machine

Simulating and compiling code for the Sequential Quantum Random Access Machine QPL 005 Preliminary Version Simulating and compiling code for the Sequential Quantum Random Access Machine Rajagopal Nagarajan 1,3 Department of Computer Science University of Warwick Coventry CV4 7AL

More information

Quantum Phase Estimation using Multivalued Logic

Quantum Phase Estimation using Multivalued Logic Quantum Phase Estimation using Multivalued Logic Agenda Importance of Quantum Phase Estimation (QPE) QPE using binary logic QPE using MVL Performance Requirements Salient features Conclusion Introduction

More information

Models of Computation, Recall Register Machines. A register machine (sometimes abbreviated to RM) is specified by:

Models of Computation, Recall Register Machines. A register machine (sometimes abbreviated to RM) is specified by: Models of Computation, 2010 1 Definition Recall Register Machines A register machine (sometimes abbreviated M) is specified by: Slide 1 finitely many registers R 0, R 1,..., R n, each capable of storing

More information

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing

CMSC 330: Organization of Programming Languages. Pushdown Automata Parsing CMSC 330: Organization of Programming Languages Pushdown Automata Parsing Chomsky Hierarchy Categorization of various languages and grammars Each is strictly more restrictive than the previous First described

More information

BDD Based Upon Shannon Expansion

BDD Based Upon Shannon Expansion Boolean Function Manipulation OBDD and more BDD Based Upon Shannon Expansion Notations f(x, x 2,, x n ) - n-input function, x i = or f xi=b (x,, x n ) = f(x,,x i-,b,x i+,,x n ), b= or Shannon Expansion

More information

Accumulators. A Trivial Example in Oz. A Trivial Example in Prolog. MergeSort Example. Accumulators. Declarative Programming Techniques

Accumulators. A Trivial Example in Oz. A Trivial Example in Prolog. MergeSort Example. Accumulators. Declarative Programming Techniques Declarative Programming Techniques Accumulators, Difference Lists (VRH 3.4.3-3.4.4) Carlos Varela RPI Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL September 13, 2007 Accumulators Accumulator

More information

COMPUTER SCIENCE TRIPOS

COMPUTER SCIENCE TRIPOS CST.2016.6.1 COMPUTER SCIENCE TRIPOS Part IB Thursday 2 June 2016 1.30 to 4.30 COMPUTER SCIENCE Paper 6 Answer five questions. Submit the answers in five separate bundles, each with its own cover sheet.

More information

Theorem 1.7 [Bayes' Law]: Assume that,,, are mutually disjoint events in the sample space s.t.. Then Pr( )

Theorem 1.7 [Bayes' Law]: Assume that,,, are mutually disjoint events in the sample space s.t.. Then Pr( ) Theorem 1.7 [Bayes' Law]: Assume that,,, are mutually disjoint events in the sample space s.t.. Then Pr Pr = Pr Pr Pr() Pr Pr. We are given three coins and are told that two of the coins are fair and the

More information

THEORY OF COMPILATION

THEORY OF COMPILATION Lecture 04 Syntax analysis: top-down and bottom-up parsing THEORY OF COMPILATION EranYahav 1 You are here Compiler txt Source Lexical Analysis Syntax Analysis Parsing Semantic Analysis Inter. Rep. (IR)

More information

Declarative Programming Techniques

Declarative Programming Techniques Declarative Programming Techniques Accumulators (CTM 3.4.3) Difference Lists (CTM 3.4.4) Carlos Varela RPI Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL December 1, 2015 C. Varela; Adapted

More information

Lecture 11: Data Flow Analysis III

Lecture 11: Data Flow Analysis III CS 515 Programming Language and Compilers I Lecture 11: Data Flow Analysis III (The lectures are based on the slides copyrighted by Keith Cooper and Linda Torczon from Rice University.) Zheng (Eddy) Zhang

More information

A Logic for Formal Verification of Quantum Programs

A Logic for Formal Verification of Quantum Programs A Logic for Formal Verification of Quantum Programs Yoshihiko Kakutani Department of Information Science, University of Tokyo kakutani@is.s.u-tokyo.ac.jp Abstract. This paper provides a Hoare-style logic

More information

Combined Satisfiability Modulo Parametric Theories

Combined Satisfiability Modulo Parametric Theories Intel 07 p.1/39 Combined Satisfiability Modulo Parametric Theories Sava Krstić*, Amit Goel*, Jim Grundy*, and Cesare Tinelli** *Strategic CAD Labs, Intel **The University of Iowa Intel 07 p.2/39 This Talk

More information

Declarative Programming Techniques

Declarative Programming Techniques Declarative Programming Techniques Accumulators and Difference Lists (CTM 3.4.3-3.4.4) Carlos Varela RPI Adapted with permission from: Seif Haridi KTH Peter Van Roy UCL February 12, 2015 C. Varela; Adapted

More information

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65

Undecidable Problems. Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, / 65 Undecidable Problems Z. Sawa (TU Ostrava) Introd. to Theoretical Computer Science May 12, 2018 1/ 65 Algorithmically Solvable Problems Let us assume we have a problem P. If there is an algorithm solving

More information

Multicore Semantics and Programming

Multicore Semantics and Programming Multicore Semantics and Programming Peter Sewell Tim Harris University of Cambridge Oracle October November, 2015 p. 1 These Lectures Part 1: Multicore Semantics: the concurrency of multiprocessors and

More information

Quantum Recursion and Second Quantisation

Quantum Recursion and Second Quantisation Quantum Recursion and Second Quantisation Mingsheng Ying University of Technology Sydney, Australia and Tsinghua University, China Outline 1. Introduction 2. Quantum Case Statement 3. Syntax of Quantum

More information

Automata Theory CS S-12 Turing Machine Modifications

Automata Theory CS S-12 Turing Machine Modifications Automata Theory CS411-2015S-12 Turing Machine Modifications David Galles Department of Computer Science University of San Francisco 12-0: Extending Turing Machines When we added a stack to NFA to get a

More information

A Principled approach to Ornamentation in ML

A Principled approach to Ornamentation in ML 0 0 A Principled approach to Ornamentation in ML THOMAS WILLIAMS, Inria DIDIER RÉMY, Inria Ornaments are a way to describe changes in datatype definitions reorganizing, adding, or dropping some pieces

More information

The L Machines are very high-level, in two senses:

The L Machines are very high-level, in two senses: What is a Computer? State of the machine. CMPSCI 630: Programming Languages An Abstract Machine for Control Spring 2009 (with thanks to Robert Harper) Internal registers, memory, etc. Initial and final

More information

Lecture 17: Language Recognition

Lecture 17: Language Recognition Lecture 17: Language Recognition Finite State Automata Deterministic and Non-Deterministic Finite Automata Regular Expressions Push-Down Automata Turing Machines Modeling Computation When attempting to

More information

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications

NICTA Advanced Course. Theorem Proving Principles, Techniques, Applications NICTA Advanced Course Theorem Proving Principles, Techniques, Applications λ 1 CONTENT Intro & motivation, getting started with Isabelle Foundations & Principles Lambda Calculus Higher Order Logic, natural

More information

CPSC 421: Tutorial #1

CPSC 421: Tutorial #1 CPSC 421: Tutorial #1 October 14, 2016 Set Theory. 1. Let A be an arbitrary set, and let B = {x A : x / x}. That is, B contains all sets in A that do not contain themselves: For all y, ( ) y B if and only

More information

Conservation of Information

Conservation of Information Conservation of Information Amr Sabry (in collaboration with Roshan P. James) School of Informatics and Computing Indiana University May 8, 2012 Amr Sabry (in collaboration with Roshan P. James) (IU SOIC)

More information

EXTRACTING COST RECURRENCES FROM SEQUENTIAL AND PARALLEL FUNCTIONAL PROGRAMS

EXTRACTING COST RECURRENCES FROM SEQUENTIAL AND PARALLEL FUNCTIONAL PROGRAMS Wesleyan University EXTRACTING COST RECURRENCES FROM SEQUENTIAL AND PARALLEL FUNCTIONAL PROGRAMS By Justin Raymond Faculty Advisor: Norman Danner A Dissertation submitted to the Faculty of Wesleyan University

More information

QWIRE Practice: Formal Verification of Quantum Circuits in Coq

QWIRE Practice: Formal Verification of Quantum Circuits in Coq 1 / 29 QWIRE Practice: Formal Verification of Quantum Circuits in Coq Robert Rand, Jennifer Paykin, Steve Zdancewic University of Pennsylvania Quantum Physics and Logic, 2017 2 / 29 QWIRE A high-level

More information

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach

EDA045F: Program Analysis LECTURE 10: TYPES 1. Christoph Reichenbach EDA045F: Program Analysis LECTURE 10: TYPES 1 Christoph Reichenbach In the last lecture... Performance Counters Challenges in Dynamic Performance Analysis Taint Analysis Binary Instrumentation 2 / 44 Types

More information

EXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully

EXAM. CS331 Compiler Design Spring Please read all instructions, including these, carefully EXAM Please read all instructions, including these, carefully There are 7 questions on the exam, with multiple parts. You have 3 hours to work on the exam. The exam is open book, open notes. Please write

More information

Game semantics for quantum stores

Game semantics for quantum stores Replace this file with prentcsmacro.sty for your meeting, or with entcsmacro.sty for your meeting. Both can be found at the ENTCS Macro Home Page. Game semantics for quantum stores Yannick Delbecque a,1,2

More information

Lambda Calculus! Gunnar Gotshalks! LC-1

Lambda Calculus! Gunnar Gotshalks! LC-1 Lambda Calculus! LC-1 λ Calculus History! Developed by Alonzo Church during mid 1930 s! One fundamental goal was to describe what can be computed.! Full definition of λ-calculus is equivalent in power

More information

Lecture 21: Algebraic Computation Models

Lecture 21: Algebraic Computation Models princeton university cos 522: computational complexity Lecture 21: Algebraic Computation Models Lecturer: Sanjeev Arora Scribe:Loukas Georgiadis We think of numerical algorithms root-finding, gaussian

More information

1 Introduction (January 21)

1 Introduction (January 21) CS 97: Concrete Models of Computation Spring Introduction (January ). Deterministic Complexity Consider a monotonically nondecreasing function f : {,,..., n} {, }, where f() = and f(n) =. We call f a step

More information

Trace semantics: towards a unification of parallel paradigms Stephen Brookes. Department of Computer Science Carnegie Mellon University

Trace semantics: towards a unification of parallel paradigms Stephen Brookes. Department of Computer Science Carnegie Mellon University Trace semantics: towards a unification of parallel paradigms Stephen Brookes Department of Computer Science Carnegie Mellon University MFCSIT 2002 1 PARALLEL PARADIGMS State-based Shared-memory global

More information

Lower and Upper Bound Theory

Lower and Upper Bound Theory Lower and Upper Bound Theory Adnan YAZICI Dept. of Computer Engineering Middle East Technical Univ. Ankara - TURKEY 1 Lower and Upper Bound Theory How fast can we sort? Most of the sorting algorithms are

More information

Advanced Cryptography Quantum Algorithms Christophe Petit

Advanced Cryptography Quantum Algorithms Christophe Petit The threat of quantum computers Advanced Cryptography Quantum Algorithms Christophe Petit University of Oxford Christophe Petit -Advanced Cryptography 1 Christophe Petit -Advanced Cryptography 2 The threat

More information

Handout 8: Computation & Hierarchical parsing II. Compute initial state set S 0 Compute initial state set S 0

Handout 8: Computation & Hierarchical parsing II. Compute initial state set S 0 Compute initial state set S 0 Massachusetts Institute of Technology 6.863J/9.611J, Natural Language Processing, Spring, 2001 Department of Electrical Engineering and Computer Science Department of Brain and Cognitive Sciences Handout

More information

MP 5 Program Transition Systems and Linear Temporal Logic

MP 5 Program Transition Systems and Linear Temporal Logic MP 5 Program Transition Systems and Linear Temporal Logic CS 477 Spring 2018 Revision 1.0 Assigned April 10, 2018 Due April 17, 2018, 9:00 PM Extension extend48 hours (penalty 20% of total points possible)

More information

Lecture 22: Quantum computational complexity

Lecture 22: Quantum computational complexity CPSC 519/619: Quantum Computation John Watrous, University of Calgary Lecture 22: Quantum computational complexity April 11, 2006 This will be the last lecture of the course I hope you have enjoyed the

More information

Type Systems for Quantum Computation

Type Systems for Quantum Computation Type Systems for Quantum Computation Bill Zorn Abstract Type systems are useful to programmers for a variety of reasons. In the classical world, they help us to define interfaces between separate pieces

More information

Propositional and Predicate Logic - V

Propositional and Predicate Logic - V Propositional and Predicate Logic - V Petr Gregor KTIML MFF UK WS 2016/2017 Petr Gregor (KTIML MFF UK) Propositional and Predicate Logic - V WS 2016/2017 1 / 21 Formal proof systems Hilbert s calculus

More information

A call-by-name lambda-calculus machine

A call-by-name lambda-calculus machine A call-by-name lambda-calculus machine Jean-Louis Krivine University Paris VII, C.N.R.S. 2 place Jussieu 75251 Paris cedex 05 (krivine@pps.jussieu.fr) Introduction We present, in this paper, a particularly

More information

Single qubit + CNOT gates

Single qubit + CNOT gates Lecture 6 Universal quantum gates Single qubit + CNOT gates Single qubit and CNOT gates together can be used to implement an arbitrary twolevel unitary operation on the state space of n qubits. Suppose

More information

Analyse et Conception Formelle. Lesson 4. Proofs with a proof assistant

Analyse et Conception Formelle. Lesson 4. Proofs with a proof assistant Analyse et Conception Formelle Lesson 4 Proofs with a proof assistant T. Genet (ISTIC/IRISA) ACF-4 1 / 26 Prove logic formulas... to prove programs fun nth:: "nat => a list => a" where "nth 0 (x#_)=x"

More information

A Short Introduction to Hoare Logic

A Short Introduction to Hoare Logic A Short Introduction to Hoare Logic Supratik Chakraborty I.I.T. Bombay June 23, 2008 Supratik Chakraborty (I.I.T. Bombay) A Short Introduction to Hoare Logic June 23, 2008 1 / 34 Motivation Assertion checking

More information

SEMANTICS OF PROGRAMMING LANGUAGES Course Notes MC 308

SEMANTICS OF PROGRAMMING LANGUAGES Course Notes MC 308 University of Leicester SEMANTICS OF PROGRAMMING LANGUAGES Course Notes for MC 308 Dr. R. L. Crole Department of Mathematics and Computer Science Preface These notes are to accompany the module MC 308.

More information

1 The Quantum IO Monad

1 The Quantum IO Monad 1 The Quantum IO Monad Thorsten Altenkirch and Alexander S. Green School of Computer Science, The University of Nottingham Abstract The Quantum IO monad is a purely functional interface to quantum programming

More information

LECTURE NOTES ON QUANTUM COMPUTATION. Cornell University, Physics , CS 483; Spring, 2005 c 2006, N. David Mermin

LECTURE NOTES ON QUANTUM COMPUTATION. Cornell University, Physics , CS 483; Spring, 2005 c 2006, N. David Mermin LECTURE NOTES ON QUANTUM COMPUTATION Cornell University, Physics 481-681, CS 483; Spring, 2005 c 2006, N. David Mermin IV. Searching with a Quantum Computer Last revised 3/30/06 Suppose you know that eactly

More information

The Assignment Axiom (Hoare)

The Assignment Axiom (Hoare) The Assignment Axiom (Hoare) Syntax: V := E Semantics: value of V in final state is value of E in initial state Example: X:=X+ (adds one to the value of the variable X) The Assignment Axiom {Q[E/V ]} V

More information

Theory of Computation

Theory of Computation Theory of Computation (Feodor F. Dragan) Department of Computer Science Kent State University Spring, 2018 Theory of Computation, Feodor F. Dragan, Kent State University 1 Before we go into details, what

More information

Limitations of OCAML records

Limitations of OCAML records Limitations of OCAML records The record types must be declared before they are used; a label e can belong to only one record type (otherwise fun x x.e) would have several incompatible types; we cannot

More information

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ;

1 Trees. Listing 1: Node with two child reference. public class ptwochildnode { protected Object data ; protected ptwochildnode l e f t, r i g h t ; 1 Trees The next major set of data structures belongs to what s called Trees. They are called that, because if you try to visualize the structure, it kind of looks like a tree (root, branches, and leafs).

More information

Functional Programming with F# Overview and Basic Concepts

Functional Programming with F# Overview and Basic Concepts Functional Programming with F# Overview and Basic Concepts Radu Nicolescu Department of Computer Science University of Auckland 27 Sep 2017 1 / 52 1 Background 2 Overview 3 Type System and Type Inference

More information

Types and Programming Languages (15-814), Fall 2018 Assignment 4: Data Representation (Sample Solutions)

Types and Programming Languages (15-814), Fall 2018 Assignment 4: Data Representation (Sample Solutions) Types and Programming Languages (15-814), Fall 2018 Assignment 4: Data Representation (Sample Solutions) Contact: 15-814 Course Staff Due Tuesday, October 16, 2018, 10:30am This assignment is due by 10:30am

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction Code Generation to MIPS David Sinclair Code Generation The generation o machine code depends heavily on: the intermediate representation;and the target processor. We are

More information

Remainders. We learned how to multiply and divide in elementary

Remainders. We learned how to multiply and divide in elementary Remainders We learned how to multiply and divide in elementary school. As adults we perform division mostly by pressing the key on a calculator. This key supplies the quotient. In numerical analysis and

More information

Lecture 12: Core State Machines II

Lecture 12: Core State Machines II Software Design, Modelling and Analysis in UML Lecture 12: Core State Machines II 2015-12-15 12 2015-12-15 main Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universität Freiburg, Germany

More information

Please give details of your answer. A direct answer without explanation is not counted.

Please give details of your answer. A direct answer without explanation is not counted. Please give details of your answer. A direct answer without explanation is not counted. Your answers must be in English. Please carefully read problem statements. During the exam you are not allowed to

More information

Exam 1. March 12th, CS525 - Midterm Exam Solutions

Exam 1. March 12th, CS525 - Midterm Exam Solutions Name CWID Exam 1 March 12th, 2014 CS525 - Midterm Exam s Please leave this empty! 1 2 3 4 5 Sum Things that you are not allowed to use Personal notes Textbook Printed lecture notes Phone The exam is 90

More information

Representing Multidimensional Trees. David Brown, Colin Kern, Alex Lemann, Greg Sandstrom Earlham College

Representing Multidimensional Trees. David Brown, Colin Kern, Alex Lemann, Greg Sandstrom Earlham College Representing Multidimensional Trees David rown, Colin Kern, lex Lemann, Greg andstrom Earlham College 1 Introduction Presentation Layout Dave: n Introduction to Multidimensional Trees and Grammars lex:

More information

Syntax Analysis Part I. Position of a Parser in the Compiler Model. The Parser. Chapter 4

Syntax Analysis Part I. Position of a Parser in the Compiler Model. The Parser. Chapter 4 1 Syntax Analysis Part I Chapter 4 COP5621 Compiler Construction Copyright Robert van ngelen, Flora State University, 2007 Position of a Parser in the Compiler Model 2 Source Program Lexical Analyzer Lexical

More information

Principles of Program Analysis: A Sampler of Approaches

Principles of Program Analysis: A Sampler of Approaches Principles of Program Analysis: A Sampler of Approaches Transparencies based on Chapter 1 of the book: Flemming Nielson, Hanne Riis Nielson and Chris Hankin: Principles of Program Analysis Springer Verlag

More information

COSE312: Compilers. Lecture 17 Intermediate Representation (2)

COSE312: Compilers. Lecture 17 Intermediate Representation (2) COSE312: Compilers Lecture 17 Intermediate Representation (2) Hakjoo Oh 2017 Spring Hakjoo Oh COSE312 2017 Spring, Lecture 17 May 31, 2017 1 / 19 Common Intermediate Representations Three-address code

More information

Extending the Lambda Calculus: An Eager Functional Language

Extending the Lambda Calculus: An Eager Functional Language Syntax of the basic constructs: Extending the Lambda Calculus: An Eager Functional Language canonical forms z cfm ::= intcfm boolcfm funcfm tuplecfm altcfm intcfm ::= 0 1-1... boolcfm ::= boolconst funcfm

More information

Introduction to Computing II (ITI1121) FINAL EXAMINATION

Introduction to Computing II (ITI1121) FINAL EXAMINATION Université d Ottawa Faculté de génie École de science informatique et de génie électrique University of Ottawa Faculty of engineering School of Electrical Engineering and Computer Science Identification

More information

Compute the Fourier transform on the first register to get x {0,1} n x 0.

Compute the Fourier transform on the first register to get x {0,1} n x 0. CS 94 Recursive Fourier Sampling, Simon s Algorithm /5/009 Spring 009 Lecture 3 1 Review Recall that we can write any classical circuit x f(x) as a reversible circuit R f. We can view R f as a unitary

More information

(a) Definition of TMs. First Problem of URMs

(a) Definition of TMs. First Problem of URMs Sec. 4: Turing Machines First Problem of URMs (a) Definition of the Turing Machine. (b) URM computable functions are Turing computable. (c) Undecidability of the Turing Halting Problem That incrementing

More information

Since CFL is closed under intersection with regular languages, we can do

Since CFL is closed under intersection with regular languages, we can do Exercise 7.3.1 Show that the operation cycle preserves context-free languages, where cycle is defined by: cycle(l) = {xy yx L} Informally, cycle(l) allows all strings constructed as follows: take a string

More information

Compiling Techniques

Compiling Techniques Lecture 11: Introduction to 13 November 2015 Table of contents 1 Introduction Overview The Backend The Big Picture 2 Code Shape Overview Introduction Overview The Backend The Big Picture Source code FrontEnd

More information