data invariants abstraction and refinement practice
play

Data Invariants, Abstraction and Refinement Practice Curtis Millar - PowerPoint PPT Presentation

Exercise 2 Specification and Refinement Editor Example Administrivia Software System Design and Implementation Data Invariants, Abstraction and Refinement Practice Curtis Millar CSE, UNSW (and Data61) 24 June 2020 1 Exercise 2


  1. Exercise 2 Specification and Refinement Editor Example Administrivia Software System Design and Implementation Data Invariants, Abstraction and Refinement Practice Curtis Millar CSE, UNSW (and Data61) 24 June 2020 1

  2. Exercise 2 Specification and Refinement Editor Example Administrivia Sort Properties sortFn xs == sortFn (reverse xs) 1 2

  3. Exercise 2 Specification and Refinement Editor Example Administrivia Sort Properties sortFn xs == sortFn (reverse xs) 1 x ‘elem‘ sortFn (xs ++ [x] ++ ys) 2 3

  4. Exercise 2 Specification and Refinement Editor Example Administrivia Sort Properties sortFn xs == sortFn (reverse xs) 1 x ‘elem‘ sortFn (xs ++ [x] ++ ys) 2 isSorted (sortFn xs) 3 4

  5. Exercise 2 Specification and Refinement Editor Example Administrivia Sort Properties sortFn xs == sortFn (reverse xs) 1 x ‘elem‘ sortFn (xs ++ [x] ++ ys) 2 isSorted (sortFn xs) 3 length xs == length (sortFn xs) 4 5

  6. Exercise 2 Specification and Refinement Editor Example Administrivia Sort Properties sortFn xs == sortFn (reverse xs) 1 x ‘elem‘ sortFn (xs ++ [x] ++ ys) 2 isSorted (sortFn xs) 3 length xs == length (sortFn xs) 4 sortFn xs == insertionSort xs 5 6

  7. Exercise 2 Specification and Refinement Editor Example Administrivia Dodgy Sort Satisfy only (2) and (4) 1 7

  8. Exercise 2 Specification and Refinement Editor Example Administrivia Dodgy Sort Satisfy only (2) and (4) 1 Satisfy only (1), (2), and (3) 2 8

  9. Exercise 2 Specification and Refinement Editor Example Administrivia Dodgy Sort Satisfy only (2) and (4) 1 Satisfy only (1), (2), and (3) 2 Satisfy only (1), (3), and (4) 3 9

  10. Exercise 2 Specification and Refinement Editor Example Administrivia Dodgy Sort Satisfy only (2) and (4) 1 Satisfy only (1), (2), and (3) 2 Satisfy only (1), (3), and (4) 3 Satisfy only (1), (2), (3), and (4) 4 10

  11. Exercise 2 Specification and Refinement Editor Example Administrivia Fractal Art Let’s take a look at the gallery 11

  12. Exercise 2 Specification and Refinement Editor Example Administrivia Fractal Art Let’s take a look at the gallery Assess your peers 12

  13. Exercise 2 Specification and Refinement Editor Example Administrivia Fractal Art Let’s take a look at the gallery Assess your peers Is the function which generates the image a recursive function? 1 13

  14. Exercise 2 Specification and Refinement Editor Example Administrivia Fractal Art Let’s take a look at the gallery Assess your peers Is the function which generates the image a recursive function? 1 Is the picture function given parameters that influence at least two aspects of the 2 image other than recursion depth, size, and colour? 14

  15. Exercise 2 Specification and Refinement Editor Example Administrivia Fractal Art Let’s take a look at the gallery Assess your peers Is the function which generates the image a recursive function? 1 Is the picture function given parameters that influence at least two aspects of the 2 image other than recursion depth, size, and colour? Is it a real attempt to generate a nice image? 3 15

  16. Exercise 2 Specification and Refinement Editor Example Administrivia Fractal Art Let’s take a look at the gallery Assess your peers Is the function which generates the image a recursive function? 1 Is the picture function given parameters that influence at least two aspects of the 2 image other than recursion depth, size, and colour? Is it a real attempt to generate a nice image? 3 Online form to review peers art & implementation on course website soon. 16

  17. Exercise 2 Specification and Refinement Editor Example Administrivia Data Invariants Data invariants are statements that must always be true of a data structure. We generally represent these invariants as a wellformedness predicate , a function that tests whether a value is well-formed. 17

  18. Exercise 2 Specification and Refinement Editor Example Administrivia Data Invariants Data invariants are statements that must always be true of a data structure. We generally represent these invariants as a wellformedness predicate , a function that tests whether a value is well-formed. Data invaraints must be shown to be true for all constructors of a data type. The output of any constructor must satisfy the wellformedness predicate. constructor :: .. -> X 18

  19. Exercise 2 Specification and Refinement Editor Example Administrivia Data Invariants Data invariants are statements that must always be true of a data structure. We generally represent these invariants as a wellformedness predicate , a function that tests whether a value is well-formed. Data invaraints must be shown to be true for all constructors of a data type. The output of any constructor must satisfy the wellformedness predicate. constructor :: .. -> X Data invaraints must also be shown to be true for all functions that transform the value of a data type. The output of these functions must satisfy the wellformedness predicate only if the input does. fn :: .. -> X -> X 19

  20. Exercise 2 Specification and Refinement Editor Example Administrivia Abstract Data Types ADTs allow us to encapsulate the implementation of a data type by restricting access to which functions can be used construct, query, or transform a value from outside the module in which it is defined. 20

  21. Exercise 2 Specification and Refinement Editor Example Administrivia Abstract Data Types ADTs allow us to encapsulate the implementation of a data type by restricting access to which functions can be used construct, query, or transform a value from outside the module in which it is defined. The ability to restrict access to certain implementation details is generally dependant on the language. 21

  22. Exercise 2 Specification and Refinement Editor Example Administrivia Abstract Data Types ADTs allow us to encapsulate the implementation of a data type by restricting access to which functions can be used construct, query, or transform a value from outside the module in which it is defined. The ability to restrict access to certain implementation details is generally dependant on the language. If all the externally visible functions maintain the data invariants then no external code can construct a value that ever violates them. 22

  23. Exercise 2 Specification and Refinement Editor Example Administrivia Refinement A relation from an implementation to an abstract model or an abstract specification . 23

  24. Exercise 2 Specification and Refinement Editor Example Administrivia Refinement A relation from an implementation to an abstract model or an abstract specification . If an implementation refines a model or specification, it exhibits all of the same behavior but may have additional behaviour or detail. 24

  25. Exercise 2 Specification and Refinement Editor Example Administrivia Refinement A relation from an implementation to an abstract model or an abstract specification . If an implementation refines a model or specification, it exhibits all of the same behavior but may have additional behaviour or detail. A refinement is the opposite of an abstraction, which removes detail. 25

  26. Exercise 2 Specification and Refinement Editor Example Administrivia Refinement A relation from an implementation to an abstract model or an abstract specification . If an implementation refines a model or specification, it exhibits all of the same behavior but may have additional behaviour or detail. A refinement is the opposite of an abstraction, which removes detail. In this course, the model and implementaion will present an indistingushable interface with different implementation details. 26

  27. Exercise 2 Specification and Refinement Editor Example Administrivia Data Refinement We can demonstrate a refinement relation between two data types if we can show that the interfaces are the same and they exhibit the same behavior. This is a data refinement . 27

  28. Exercise 2 Specification and Refinement Editor Example Administrivia Data Refinement We can demonstrate a refinement relation between two data types if we can show that the interfaces are the same and they exhibit the same behavior. This is a data refinement . We choose which data type will be the abstract model which is the definition or specification . 28

  29. Exercise 2 Specification and Refinement Editor Example Administrivia Data Refinement We can demonstrate a refinement relation between two data types if we can show that the interfaces are the same and they exhibit the same behavior. This is a data refinement . We choose which data type will be the abstract model which is the definition or specification . The other data type then becomes our implementation , i.e. the data type that we will actually use in the final system. 29

  30. Exercise 2 Specification and Refinement Editor Example Administrivia Data Refinement We can demonstrate a refinement relation between two data types if we can show that the interfaces are the same and they exhibit the same behavior. This is a data refinement . We choose which data type will be the abstract model which is the definition or specification . The other data type then becomes our implementation , i.e. the data type that we will actually use in the final system. We must show that the implementation is a refinement of the model or specification. 30

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