1 / 16

Lab 1 Requirements

Lab 1 Requirements. Local operations (at least Heapify and Sift_Root_Down) provide specs—they don't need to be formal, but you must have appropriate parameter modes, requires, and ensures Heapify must be recursive and use the algorithm discussed in class

Télécharger la présentation

Lab 1 Requirements

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab 1 Requirements • Local operations (at least Heapify and Sift_Root_Down) • provide specs—they don't need to be formal, but you must have appropriate parameter modes, requires, and ensures • Heapify must be recursive and use the algorithm discussed in class • Follow the Resolve/C++ disciplinehttp://www.cse.ohio-state.edu/sce/now/321/labs/writeups/lab_grading_hints.html • Make sure you look at and implement the specs of Sorting_Machine_Kernel • Follow the convention and correspondence • Comment your code

  2. (We were not drunk when we made it up. Seriously!) A Day of Revelations • What’s the difference between implementing an extension and a kernel? • What are convention and correspondence? What are they for? Why do we bother? • What about the rule that kernel operations cannot call other kernel operations?

  3. Extension Usually layered over a kernel Does not access representation directly Kernel Defines representation Directly accesses representation Extension vs. Kernel Op_Ext Op_1 Op_2 Rep Op_3 Op_4 Kernel Extension

  4. The Correspondence • Consider the implementation of Sorting_Machine_Kernel with Heapsort • What’s the math model of Sorting_Machine? • What’s the representation? • What’s the math model of the representation?

  5. self.contents self.inserting Math Model of Sorting_Machine Sorting_Machine_Type is modeled by ( inserting: boolean contents: multiset of Item )

  6. self.inserting_rep self.queue self.array self.heap_size self.array.lb self.array.ub self.array.table Representation Math Model Rep is modeled by ( inserting_rep: boolean queue: string of Item array: ARRAY_MODEL heap_size: integer ) math subtype ARRAY_MODEL is ( lb: integer ub: integer table: INDEXED_TABLE ) constraint … math subtype INDEXED_TABLE is finite set of ( i: integer x: Item ) constraint …

  7. abstract state space ? (true, {1, 2, 3}) concrete state space (true, <2, 1, 3>, (1, 0, {}), 0) Correspondence Continued… Sorting_Machine_Type is modeled by ( inserting: boolean contents: multiset of Item ) Rep is modeled by ( inserting_rep: boolean queue: string of Item array: ARRAY_MODEL heap_size: integer )

  8. Correspondence Continued… • Given the Sorting_Machine m with value m = (true, {1, 2, 3}), what’s the corresponding value for the representation? How do you know? • Conversely, given the representation (true, <2, 1, 3>, (1, 0, {}), 0), what Sorting_Machine value does it represent? How do you know?

  9. Correspondence Continued… • The correspondence provides the mapping between the abstract value (the sorting machine) and the concrete value (the representation)

  10. Sorting_Machine with Heapsort: Correspondence self.inserting = self.inserting_rep and ifself.inserting thenself.contents = elements (self.queue) elsefor all x: Item (x is inself.contents iff there exists i: integer (self.array.lb <= i and i <= self.heap_size and (i,x) is inself.array.table))

  11. The Convention • What Sorting Machine is represented by • (true, <2, 1, 3>, (1, 0, {}), 5) • (true, <2, 1, 3>, (1, 2, {(1, 7), (2, 8)}), 3) • (false, <>, (1, 2, {(1, 7), (2, 8)}), 3)? • Is the following a correct implementation of Size? What would you need to know to answer this question? { return self[heap_size]; }

  12. Convention Continued… • The convention states any implementation-wide assumptions the implementer makes • It restricts the space of possible representation values • It allows us to reason about the correctness of each operation independently of the others

  13. abstract state space (true, {1, 2, 3}) correspondence convention concrete state space (true, <2, 1, 3>, (1, 0, {}), 0) (true, <2, 1, 3>, (1, 0, {}), 5) Convention Continued… Sorting_Machine_Type is modeled by ( inserting: boolean contents: multiset of Item ) Rep is modeled by ( inserting_rep: boolean queue: string of Item array: ARRAY_MODEL heap_size: integer )

  14. Sorting_Machine with Heapsort: Convention if self.inserting_rep then self.heap_size = 0 and self.array = (1, 0, empty_set) else self.array.lb = 1 and 0 <= self.heap_size and self.heap_size <= self.array.ub and SUB_TREE_IS_ORDERED ( self.array, 1, self.heap_size) and self.queue = empty_string

  15. Convention: One More Thing • In implementing a kernel component, the implementer assumes that the convention holds at the beginning of each kernel operation • It is the responsibility of the implementer to ensure that the convention holds at the end of each kernel operation

  16. Convention Continued… • What happens if in the middle of a kernel operation (where the convention may not hold) we call another kernel operation?

More Related