CSC 530 Lecture Notes Week 7 More on Tennent-Style Denotational - - PDF document

csc 530 lecture notes week 7 more on tennent style
SMART_READER_LITE
LIVE PREVIEW

CSC 530 Lecture Notes Week 7 More on Tennent-Style Denotational - - PDF document

CSC530-W02-L7 Slide 1 CSC 530 Lecture Notes Week 7 More on Tennent-Style Denotational Semantics CSC530-W02-L7 Slide 2 I. Tennent Ch 13. A. Well dissect some key definitions. B. Prepare for pervasive use of functions (of functions (of


slide-1
SLIDE 1

CSC530-W02-L7 Slide 1

CSC 530 Lecture Notes Week 7 More on Tennent-Style Denotational Semantics

slide-2
SLIDE 2

CSC530-W02-L7 Slide 2

  • I. Tennent Ch 13.
  • A. We’ll dissect some key definitions.
  • B. Prepare for pervasive use of functions

(of functions (of functions)).

slide-3
SLIDE 3

CSC530-W02-L7 Slide 3

  • II. Assignment statements
  • A. Dissection of assmnt from 13.3:

[[C [[ (( ) (u)) ( s) = command, here "I := E" env = D Ide store = +{unused R L }) G per Tennent top of page 221: "The store transformation denoted by command C in environment u."

slide-4
SLIDE 4

CSC530-W02-L7 Slide 4

Assignment, cont’d where G expands as follows: G = s[d |→ e] = s[u[[I]] |→ [[E]] u s ] = s[(Ide → D) [[I]] |→ [[E]] (Ide → D) (L → (R + {unused}))]

slide-5
SLIDE 5

CSC530-W02-L7 Slide 5

Assignment, cont’d

  • B. What this says is that the meaning of

an assignment statement of the form "I := E" for some identifier "I" and expression "E" is a modified store, where the location of the modification is the memory location bound to "I" in the environment and the value of the modification is the value produced by evaluating E in the environment and pre-modified store.

  • C. Cool, huh?
slide-6
SLIDE 6

CSC530-W02-L7 Slide 6

  • III. Procedures
  • A. Consider:

Code Semantics val n = 100 [[val n = 100]] new x = 0 [[new x = 0]] t = true [[new t = true]] new Pn = (procedure x := x+1) [[val Pn = (proc ...)]] val Pv = (procedure x := x+1) [[val Pv = (proc ...)]] call(Pv) [[Pv]]u s

slide-7
SLIDE 7

CSC530-W02-L7 Slide 7

Procedures, cont’d

  • B. Resulting env and store

Environment: Store: Ide Value x Tag Addr Value n 100,Z 0xff20 x 0xff20, L 1 t 0xff24, L 2 Pn 0xff25, L 3 Pv [[x:=x+1]]uv 4 true 5 [[x:=x+1]]un storage for body of Pv ...

slide-8
SLIDE 8

CSC530-W02-L7 Slide 8

Procedures, cont’d

  • C. Notes
  • 1. Depiction of env resembles lookup

table, depiction of store resembles memory.

  • a. Both depictions are merely sug-

gestions.

  • b. Abstractly, env and store are

unary functions.

slide-9
SLIDE 9

CSC530-W02-L7 Slide 9

Procedures, cont’d

  • 2. Assoc-style lookup denoted

u[[x]]

  • a. This means apply the env func-

tion u to ident "x".

  • b. Think of entire table applied as

function to "x".

slide-10
SLIDE 10

CSC530-W02-L7 Slide 10

Procedures, cont’d

  • 3. Proc values bound to Pn and Pv are

unevaluated lambda bodies, with an attached env.

  • a. Attachment defines language as

statically scoped.

  • b. Note different static env in Pn

versus Pv.

slide-11
SLIDE 11

CSC530-W02-L7 Slide 11

  • IV. Tennent versus Knuth eval
  • A. Consider

var x,y; x := 1; y := x+1;

  • B. Knuth eval walks the parse tree:

program decl ; stmts stmt ; stmt expr := expr expr := expr expr + expr x 1 y x 1

slide-12
SLIDE 12

CSC530-W02-L7 Slide 12

  • C. Comparable Tennent eval:

var x,y; x:=1 y:=x+1 var x,y y:=x+1 expr expr expr x 1 y x 1 M [ [ D[ [ C[ [ E[ [ ] ] ] ] ] ] ] ] ] ] ] ] ] ] x:=1; y:=x+1 ; C[ [ C[ [ x:=1 ; ] ] ] ] ] ] ] ] E[ [ E[ [ E[ [ E[ [ E[ [expr := := + expr expr

slide-13
SLIDE 13

CSC530-W02-L7 Slide 13

  • V. Infinitary program behavior -- loops
  • A. Thus far, not directly considered.
  • B. There are two approaches.
  • 1. "Operational" mathematical

approach.

  • 2. Limit/Fixpoint approach.
slide-14
SLIDE 14

CSC530-W02-L7 Slide 14

  • VI. Fixpoint def of while
  • A. Basic idea

‘‘while E do C’’= if E then { C ; while E do C } Using a bit of notation: [[ while E do C ]] = if [[E]] then begin [[C]] ; [[while E do C]]end where let f = [[ while E do C ]] F(f) = if [[E]] then begin [[C]] ; [[while E do C]] end

slide-15
SLIDE 15

CSC530-W02-L7 Slide 15

While, cont’d

  • B. Question: What’s going on here?

Ans: it’s an equation to be solved for f, i.e., for f = F(f)

  • C. Question: Does this form of equation

have a solution in general? I.e., for a functional F: D→D, does there exist Y: (D→D)→D such that Y(F) = F(Y(F))

slide-16
SLIDE 16

CSC530-W02-L7 Slide 16

While, cont’d Ans: Yes, if we make the following assumptions:

  • 1. Function domains properly defined.
  • 2. All functions are continuous
  • D. Solution is called a fixpoint
slide-17
SLIDE 17

CSC530-W02-L7 Slide 17

While, cont’d

  • E. Question: What does such a fixpoint

look like? Ans:

  • 1. For non-recursive cases, e.g.,

fix( f(x) = 4 ) is 4 fix( f(x) = 8 - x ) is 4

slide-18
SLIDE 18

CSC530-W02-L7 Slide 18

While, cont’d

  • 2. For recursive cases, consider

let f(x) = if x=0 then 1 else if x=1 then f(3) else f(x-2)

  • a. A fixpoint of this is

f(x) =1 if x is is even and x≥0 undefined otherwise

slide-19
SLIDE 19

CSC530-W02-L7 Slide 19

While, cont’d

  • b. But also a fixpoint is

f(x) = 1 if x is even and x≥0 a if x is odd and x>0 b otherwise for any a,b

  • c. The first is the ‘‘least’’ fixpoint.
slide-20
SLIDE 20

CSC530-W02-L7 Slide 20

While, cont’d

  • 3. For while loop, fixpoint function

looks like a limit of successive approximations.

  • a. I.e.,

(while E do C) 0 = ‘‘the worst loop approximation’’ (while E do C) i+1 = if E then C; (while E do C) i

slide-21
SLIDE 21

CSC530-W02-L7 Slide 21

While, cont’d

  • b. More specifically,

(while E do C) 0 = while true do null; (while E do C) 1 = if E then C; while true do null; (while E do C) 2 = if E then C; if E then C ; while true do null; ...

slide-22
SLIDE 22

CSC530-W02-L7 Slide 22

While, cont’d

  • c. In terms of functions,

let f = [[while E do C]] and we want

f = [[E]] → [[C; while E do C]] = [[E]] → ( [[while E do C]]( [[C]])) = [[E]] → f( [[C]])

slide-23
SLIDE 23

CSC530-W02-L7 Slide 23

While, cont’d and now, we want f = F(f)

  • d. That is, we have arrived at

| _, F( | _ ), F(F( | _ )), ..., Fi( | _ ) which approximates f. I.e.,

slide-24
SLIDE 24

CSC530-W02-L7 Slide 24

While, cont’d FixD : (D → D) → D defined as FixD = limi→ Fi( | ) is the ‘‘least’’ solution of f = F(f).