CSC 530 Lecture Notes Week 10 Algebraic Semantics CSC530-S02-L10 - - PDF document

csc 530 lecture notes week 10 algebraic semantics
SMART_READER_LITE
LIVE PREVIEW

CSC 530 Lecture Notes Week 10 Algebraic Semantics CSC530-S02-L10 - - PDF document

CSC530-S02-L10 Slide 1 CSC 530 Lecture Notes Week 10 Algebraic Semantics CSC530-S02-L10 Slide 2 I. A grand vision. A. Algebraic semantics intended to have a wide scope. B. In is grandest form, its a unifying the- oretical framework for:


slide-1
SLIDE 1

CSC530-S02-L10 Slide 1

CSC 530 Lecture Notes Week 10 Algebraic Semantics

slide-2
SLIDE 2

CSC530-S02-L10 Slide 2

  • I. A grand vision.
  • A. Algebraic semantics intended to have a

wide scope.

  • B. In is grandest form, it’s a unifying the-
  • retical framework for:
slide-3
SLIDE 3

CSC530-S02-L10 Slide 3

Grand vision, cont’d

  • 1. Programming languages, including for-

mal semantics and compilers.

  • 2. Software engineering, including object-
  • riented development, formal specifica-

tion, formal testing, and verification.

  • 3. Theoretical foundations of computabil-

ity.

  • 4. High-level computer architecture.
slide-4
SLIDE 4

CSC530-S02-L10 Slide 4

Grand vision, cont’d

  • C. Joseph Goguen is of sufficient intellect

to pull it off.

slide-5
SLIDE 5

CSC530-S02-L10 Slide 5

  • II. How papers present the grand vision.
  • A. Paper 34 presents a broad, early over-

view.

  • B. Paper 35 discusses algebraic theory

applied to object-oriented formal spec- ification and verification.

slide-6
SLIDE 6

CSC530-S02-L10 Slide 6

Papers, cont’d

  • C. Paper 36 describes practical algebraic

programming in OBJ.

  • D. Paper 37 focus on how an algebraic

approach solves well-known problems in programming langs.

slide-7
SLIDE 7

CSC530-S02-L10 Slide 7

Papers, cont’d

  • E. Paper 38 outlines how an algebraic

model of computation can be used to design hardware.

  • F. Paper 39 is the OBJ3 language refer-

ence manual.

slide-8
SLIDE 8

CSC530-S02-L10 Slide 8

Papers, cont’d

  • G. Paper 40 describes the Maude lan-

guage, a popular successor to OBJ.

  • H. Paper 41 is an overview of the OBJ

family of languages; lots of links.

slide-9
SLIDE 9

CSC530-S02-L10 Slide 9

  • III. A mind-altering experience.
  • A. An algebraic PL has the following

unique properties:

  • 1. It’s fully declarative.
  • 2. An algebraic program and its speci-

fication are identical.

  • 3. An algebraic PL and its formal

semantics are identical.

  • 4. Operational execution, semantic

evaluation, and formal verification use the same mechanism.

slide-10
SLIDE 10

CSC530-S02-L10 Slide 10

  • IV. A stack ADT as an initial example.
  • bj STACK is sort Stack .

protecting NAT .

  • p push : Stack Nat -> Stack .
  • p pop : Stack -> Stack .
  • p top : Stack -> Nat .
  • p emptyStack : -> Stack .
  • p emptyElem : -> Nat .

var S : Stack . var E : Nat . eq pop(emptyStack) = emptyStack . eq pop(push(S, E)) = S . eq top(emptyStack) = emptyElem . eq top(push(S, E)) = E . endo

slide-11
SLIDE 11

CSC530-S02-L10 Slide 11

slide-12
SLIDE 12

CSC530-S02-L10 Slide 12

  • V. Executing algebraically-defined ADTs.
  • A. Execution performed using term

re writing, a.k.a, reduction.

  • B. A program is a term, which is simply

an application functions to arguments.

  • C. To perform reduction, equations used

as pattern matching rules.

  • D. Consider the following program:
slide-13
SLIDE 13

CSC530-S02-L10 Slide 13

Executing, cont’d

in Stack

  • bj MAIN is

*** "Protecting" imports. protecting STACK . protecting INT . *** "Op" declares functions.

  • p main : -> Stack .

*** A parameterlesss op is a *** single-assignment variable.

  • p s1 : -> Stack .
  • p s2 : -> Stack .
  • p i : -> Int .
slide-14
SLIDE 14

CSC530-S02-L10 Slide 14

Executing, cont’d

*** Equations declare what *** the program does. eq s1 = pop(push(push(push( emptyStack, 1), 2), 3)) . eq i = top(push(push(push( emptyStack, 1), 2), 3)) + 1 . eq s2 = push(push(s1, i), 5) . eq main = pop(s2) . endo

slide-15
SLIDE 15

CSC530-S02-L10 Slide 15

Executing, cont’d

*** The following executes program main. reduce main . *** The result of execution is the stack *** push(push(push(emptyStack,1),2),4).

slide-16
SLIDE 16

CSC530-S02-L10 Slide 16

  • VI. Additional examples.
  • A. An ML-like list ADT.
  • B. A set-like ADT.
  • C. A binary search tree.
  • D. A parameterized list.
  • E. A bubble sorter.
  • F. A simple PL, called "Fun", similar to

SIL and Tennent 13.2.

slide-17
SLIDE 17

CSC530-S02-L10 Slide 17

  • VII. Algebraic program proofs.
  • A. Section 4 of paper 35 describes how

term rewriting is used for proof.

  • B. Hence, proofs about programs use the

same term rewriting technique as used for program execution.

  • C. Here’s an example.
slide-18
SLIDE 18

CSC530-S02-L10 Slide 18

Proofs, cont’d

  • bj NAT is sort Nat .
  • p 0 : -> Nat .
  • p s_ : Nat -> Nat [prec 1] .
  • p _+_ : Nat Nat -> Nat [assoc comm prec 3] .

vars M N : Nat . eq M + 0 = M . eq M + s N = s(M + N).

  • p _*_ : Nat Nat -> Nat [prec 2] .

eq M * 0 = 0 . eq M * s N = M * N + M . endo

  • bj VARS is protecting NAT .
  • ps m n : -> Nat .

endo ***> first show two lemmas, 0*n=0 and sm*n=m*n+n ***> base for first lemma reduce 0 * 0 == 0 . ***> induction step for first lemma

  • bj HYP1 is using VARS .

eq 0 * n = 0 . endo reduce 0 * s n == 0 . *** thus we can assert

slide-19
SLIDE 19

CSC530-S02-L10 Slide 19

  • bj LEMMA1 is protecting NAT .

vars N : Nat . eq 0 * N = 0 . endo ***> base for second lemma reduce in VARS + LEMMA1 : s n * 0 == n * 0 + 0 . ***> induction step for second lemma

  • bj HYP2 is using VARS .

eq s m * n = m * n + n . endo reduce s m * s n == (m * s n)+ s n . *** so we can assert

  • bj LEMMA2 is protecting NAT .

vars M N : Nat . eq s M * N = M * N + N . endo

  • bj SUM is protecting NAT .
  • p sum : Nat -> Nat .

var N : Nat . eq sum(0) = 0 . eq sum(s N) = s N + sum(N) . endo ***> show sum(n)+sum(n)=n*sn ***> base case reduce in SUM + LEMMA1 : sum(0) + sum(0) == 0 * s 0 .

slide-20
SLIDE 20

CSC530-S02-L10 Slide 20

***> induction step

  • bj HYP is using SUM + VARS .

eq sum(n) + sum(n) = n * s n . endo reduce in HYP + LEMMA2 : sum(s n) + sum(s n) == s n * s s n .

slide-21
SLIDE 21

CSC530-S02-L10 Slide 21

Proofs, cont’d

  • D. Here’s an OBJ structural induction

proof, as in paper 35.

slide-22
SLIDE 22

CSC530-S02-L10 Slide 22

Proofs, cont’d

in list th FN is sort S .

  • p f : S -> S .

endth

  • bj MAP[F :: FN] is protecting LIST[F] .
  • p map : List -> List .

var X : S . var L : List . eq map(nil) = nil . eq map(X L) = f(X) map(L) . endo in map

  • bj FNS is protecting INT .
  • ps (sq_)(dbl_)(_*3) : Int -> Int .

var N : Int . eq sq N = N * N . eq dbl N = N + N . eq N *3 = N * 3 . endo reduce in MAP[(sq_).FNS] : map(0 nil 1 -2 3) . ***> should be: 0 1 4 9 reduce in MAP[(dbl_).FNS] : map(0 1 -2 3) . ***> should be: 0 2 -4 6 reduce in MAP[(_*3).FNS] : map(0 1 -2 nil 3) . ***> should be: 0 3 -6 9

slide-23
SLIDE 23

CSC530-S02-L10 Slide 23