16
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++ discipline http://www.cse.ohio-state.edu/sce/now/321/labs/writeups/lab_gradi ng_hints.html Make sure you look at and implement the specs of Sorting_Machine_Kernel Follow the convention and correspondence Comment your code

Lab 1 Requirements

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

Page 1: 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 Follow the Resolve/C++ discipline

http://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

Page 2: Lab 1 Requirements

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?

(We were not drunk when we made it up. Seriously!)

Page 3: Lab 1 Requirements

Extension vs. Kernel Extension

Usually layered over a kernel

Does not access representation directly

Kernel Defines

representation Directly accesses

representation KernelExtension

RepOp_

1 Op_2

Op_4 Op_3

Op_Ext

Page 4: Lab 1 Requirements

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?

Page 5: Lab 1 Requirements

Math Model of Sorting_Machine

Sorting_Machine_Type is modeled by ( inserting: boolean contents: multiset of Item ) self.contents

self.inserting

Page 6: Lab 1 Requirements

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 …

self.inserting_repself.queu

e self.arrayself.heap_size

self.array.table

self.array.lbself.array.ub

Page 7: Lab 1 Requirements

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 )

?

abstract state space

concrete state space

(true, {1, 2, 3})

(true, <2, 1, 3>, (1, 0, {}), 0)

Page 8: Lab 1 Requirements

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?

Page 9: Lab 1 Requirements

Correspondence Continued…

The correspondence provides the mapping between the abstract value (the sorting machine) and the concrete value (the representation)

Page 10: Lab 1 Requirements

Sorting_Machine with Heapsort: Correspondence

self.inserting = self.inserting_rep andif self.insertingthen self.contents = elements (self.queue)else for all x: Item (x is in self.contents iff there exists i: integer (self.array.lb <= i and i <= self.heap_size and (i,x) is in self.array.table))

Page 11: Lab 1 Requirements

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]; }

Page 12: Lab 1 Requirements

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

Page 13: Lab 1 Requirements

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 )

abstract state space

concrete state space

(true, <2, 1, 3>, (1, 0, {}), 5)

convention

(true, {1, 2, 3})correspondence

(true, <2, 1, 3>, (1, 0, {}), 0)

Page 14: Lab 1 Requirements

Sorting_Machine with Heapsort: Conventionif self.inserting_repthen 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

Page 15: Lab 1 Requirements

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

Page 16: Lab 1 Requirements

Convention Continued…

What happens if in the middle of a kernel operation (where the convention may not hold) we call another kernel operation?