logic for computer science
play

Logic for Computer Science 13 Modelling processes Wouter Swierstra - PowerPoint PPT Presentation

Logic for Computer Science 13 Modelling processes Wouter Swierstra University of Utrecht 1 Last time Games of no chance 2 This lecture Processes 3 Mid-term Exam The results have been emailed to you directly. I have appointments with


  1. Logic for Computer Science 13 – Modelling processes Wouter Swierstra University of Utrecht 1

  2. Last time Games of no chance 2

  3. This lecture Processes 3

  4. Mid-term Exam The results have been emailed to you directly. I have appointments with students to go through the exams. I’ll try to email the final marks at the end of the week – these final marks will be a bit higher than the mark in the email. 4

  5. 5

  6. But our book is called ‘’Modelling Computing Systems” – these are all fairly ‘static’ mathematical structures. How do we model computing systems? Recap In the lectures until now, we have learned about • propositional logic; • predicate logic; • proofs; • sets, functions and relations; • inductive definitions and proofs by induction. 6

  7. Recap In the lectures until now, we have learned about • propositional logic; • predicate logic; • proofs; • sets, functions and relations; • inductive definitions and proofs by induction. But our book is called ‘’Modelling Computing Systems” – these are all fairly ‘static’ mathematical structures. How do we model computing systems? 6

  8. Like a light switch… Processes Rather than start immediately with complicated computing systems – let’s begin by looking at some (familiar) examples drawn from the real world. 7

  9. Processes Rather than start immediately with complicated computing systems – let’s begin by looking at some (familiar) examples drawn from the real world. Like a light switch… 7

  10. We can see we have two different states our system is in (On or Off); and there are two different actions that transition between these two states ( on and off ). Modelling a light switch A light can be either on or off. There is a switch that can be used to the light on (if it is off); And turn the light off (if it is on). We might visualise this as follows: on On Off off 8

  11. Modelling a light switch A light can be either on or off. There is a switch that can be used to the light on (if it is off); And turn the light off (if it is on). We might visualise this as follows: on On Off off We can see we have two different states our system is in (On or Off); and there are two different actions that transition between these two states ( on and off ). 8

  12. Modelling a vending machine coffee coin 0 1 tea A simple vending machine that can dispense coffee or two for 1 euro can be modelled in this style. There are two possible states: • 0 – no coin inserted; • 1 – a coin has been inserted and a drink may be selected. There can be more than one action between different states! (This machine doesn’t give change and only accepts 1 euro coins.) 9

  13. This example shows that even something as simple as a pocket calculator has a great deal of ‘custom’ notation and natural language explanation. A bit like trying to define propositional logic, without knowing about inductive sets. Isn’t there a better notation? Or more general definition? Modelling a calculator A pocket calculator is a much more complicated ‘machine’ with many more buttons: • C/AC – resets the current calculation; • the digits 1-9 extend the current number (or sometimes start a new number); • the operations +,-, ÷ , and × finalize the current number being entered and start asking for a new number. How can we ever start formally describing such a machine? 10

  14. Modelling a calculator A pocket calculator is a much more complicated ‘machine’ with many more buttons: • C/AC – resets the current calculation; • the digits 1-9 extend the current number (or sometimes start a new number); • the operations +,-, ÷ , and × finalize the current number being entered and start asking for a new number. How can we ever start formally describing such a machine? This example shows that even something as simple as a pocket calculator has a great deal of ‘custom’ notation and natural language explanation. A bit like trying to define propositional logic, without knowing about inductive sets. Isn’t there a better notation? Or more general definition? 10

  15. Labelled transition systems Each of these examples are instances of a labelled transition system – a simple way to model a computational process that can be in different states and shift between these states. More formally, a labelled transition system consists of: • A set States – corresponding to all the possible states of the system (like On or 1); • A set Actions – corresponding to the labels between states; • A relation on States × Actions × States corresponding to the possible transitions from one a state to the next. We usually write s 1 → s 2 when this relation includes ( s 1 , a , s 2 ) —or put − differently we can transition from state s 1 to s 2 by performing the action a . 11

  16. Example: vending machine coffee coin 0 1 tea • States: { 0 , 1 } • Actions: { coin , coffee , tea } • Transitions: { ( 0 , coin , 1 ) , ( 1 , coffee , 0 ) , ( 1 , tea , 0 ) } 12

  17. We can easily extend our transition relation to work over lists of actions, rather than a single action. This is useful to model a sequence of transition steps, rather than a single step, usually w s , where w written s Action • s s – if there are no further actions to be taken, we stay at the state s . aw t if s w t for some state s – if we can take a single step from s to s along a • s s and s a , and continue from s to t by the word w , we can transition from s to t by aw . Notation and short-hands a • We will write s 1 → s 2 when we can transition from s 1 to s 2 by the action a . − a • When we cannot transition from s 1 to s 2 with the action a , we sometimes write s 1 / s 2 → − • When there are no actions that transition from s 1 to s 2 , we will write s 1 → / s 2 . • When there are no transitions from s to any other state, we will write s → / 13

  18. Notation and short-hands a • We will write s 1 → s 2 when we can transition from s 1 to s 2 by the action a . − a • When we cannot transition from s 1 to s 2 with the action a , we sometimes write s 1 / s 2 − → • When there are no actions that transition from s 1 to s 2 , we will write s 1 → / s 2 . • When there are no transitions from s to any other state, we will write s → / We can easily extend our transition relation to work over lists of actions, rather than a single action. This is useful to model a sequence of transition steps, rather than a single step, usually w written s → s ′ , where w ∈ Action ∗ − • s ε → s – if there are no further actions to be taken, we stay at the state s . − aw → s ′ and s ′ a → t for some state s ′ – if we can take a single step from s to s ′ along w • s → t if s − − − a , and continue from s ′ to t by the word w , we can transition from s to t by aw . 13

  19. Wolf-goat-cabbage A man needs to cross a river with a wolf, a goat, and a cabbage. His boat is only large enough to carry himself and one of his three possessions, so he must transport them one at a time. However, if he leaves the wolf and the goat together unattended, then the wolf will eat the goat; similarly, if he leaves the goat and the cabbage together unattended, the goat will eat the cabbage. How can the man get across safely with his possessions? Question How can we solve this puzzle? And more importantly, how can we model this problem as a labelled transition system? 14

  20. The book uses a slightly different notation writing: MGC W When the man, goat and cabbage are on one side of the river, but the wolf has crossed. Wolf-goat-cabbage: states We want to model where the man, wolf, goat and cabbage are. Each can be on one side of the river, but not both at the same time. We can model this by taking P( { M , W , G , C } ) as our set of states. At a given state S , the elements of S have successfully crossed the river. Initially, no one has crossed the river – hence we are at the state ∅ . 15

  21. Wolf-goat-cabbage: states We want to model where the man, wolf, goat and cabbage are. Each can be on one side of the river, but not both at the same time. We can model this by taking P( { M , W , G , C } ) as our set of states. At a given state S , the elements of S have successfully crossed the river. Initially, no one has crossed the river – hence we are at the state ∅ . The book uses a slightly different notation writing: MGC ≀≀≀ W When the man, goat and cabbage are on one side of the river, but the wolf has crossed. 15

  22. The transitions each move the man (and possibly one of his possessions) to the other side of the river. g C For example, MGC W MWG Finally, some states are ‘dangerous’ – when the wolf and goat are unattended on one side of the river or the goat and cabbage are unattended on one side of the river. Actions and transitions There are four possible actions: { m , g , c , w } corresponding to crossing the river with the an empty boat ( m ), the goat ( g ), the cabbage ( c ), or the wolf ( w ). 16

  23. Finally, some states are ‘dangerous’ – when the wolf and goat are unattended on one side of the river or the goat and cabbage are unattended on one side of the river. Actions and transitions There are four possible actions: { m , g , c , w } corresponding to crossing the river with the an empty boat ( m ), the goat ( g ), the cabbage ( c ), or the wolf ( w ). The transitions each move the man (and possibly one of his possessions) to the other side of the river. g For example, MGC ≀≀≀ W → C ≀≀≀ MWG − 16

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend