{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

A+Practical+Theory+of+Programming+08

A+Practical+Theory+of+Programming+08 - Data-Stack Theory...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
Data-Stack Theory syntax stack all stacks of items of type X empty a stack containing no items push a function that takes a stack and an item and gives back another stack pop a function that takes a stack and gives back another stack top a function that takes a stack and gives back an item 1/51
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data-Stack Theory axioms empty : stack push : stack X stack pop : stack stack top : stack X empty s1 s2 s3 s4 ↑↑ || | | 2/51
Background image of page 2
Data-Stack Theory axioms empty : stack push : stack X stack pop : stack stack top : stack X push s x empty empty s1 s2 s3 s4 ↑↑ || | 3/51
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data-Stack Theory axioms empty : stack push : stack X stack pop : stack stack top : stack X push s x empty push s x = push t y = s = t x = y empty s1 s2 s3 s4 .......... .......... t u v w .......... 4/51
Background image of page 4
Data-Stack Theory axioms empty : stack push : stack X stack pop : stack stack top : stack X push s x empty push s x = push t y = s = t x = y empty , push stack X : stack empty , push B X : B stack : B empty s1 s2 s3 s4 .......... 5/51
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data-Stack Theory axioms empty : stack push : stack X stack pop : stack stack top : stack X push s x empty push s x = push t y = s = t x = y empty , push stack X : stack empty , push B X : B stack : B P empty s : stack · x : X · Ps P ( push s x ) = s : stack · Ps 6/51
Background image of page 6
Data-Stack Theory axioms empty : stack push : stack X stack pop : stack stack top : stack X push s x empty push s x = push t y = s = t x = y empty , push stack X : stack empty , push B X : B stack : B P empty s : stack · x : X · Ps P ( push s x ) = s : stack · Ps pop ( push s x ) = s top ( push s x ) = x 7/51
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data-Stack Theory implementation stack = [* int ] empty = [ nil ] push = s : stack x : int s + [ x ] ⟩⟩ pop = s : stack if s = empty then empty else s [0;..# s –1] top = s : stack if s = empty then 0 else s (# s –1) 8/51
Background image of page 8
Data-Stack Theory proof Prove that the axioms of the theory are satisfied by the definitions of the implementation. (the axioms of the theory) (the definitions of the implementation) specification implementation 9/51
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data-Stack Theory proof (last axiom): top ( push s x ) = x definition of push = top ( s : stack x : int s + [ x ] ⟩⟩ s x ) = x apply function = top ( s + [ x ]) = x definition of top = s : stack if s = empty then 0 else s (# s –1) ( s + [ x ]) = x apply function = ( if s + [ x ]= empty then 0 else ( s + [ x ]) (#( s + [ x ])–1)) = x definition of empty = ( if s + [ x ]=[ nil ] then 0 else ( s + [ x ]) (#( s + [ x ])–1)) = x simplify the if and the index = ( s + [ x ]) (# s ) = x index the list = x = x reflexive law = T 10/51
Background image of page 10
Data-Stack Theory usage var a , b : stack a := empty . b := push a 2 consistent? yes, we implemented it. complete? no, the boolean expressions pop empty = empty top empty = 0 are unclassified. Proof: implement twice.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}