Ceg860 (Prasad)LADT1 Specification and Implementation of Abstract Data Types Algebraic Techniques.

Slides:



Advertisements
Similar presentations
Automated Theorem Proving Lecture 1. Program verification is undecidable! Given program P and specification S, does P satisfy S?
Advertisements

Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
Semantics Static semantics Dynamic semantics attribute grammars
Introducing Formal Methods, Module 1, Version 1.1, Oct., Formal Specification and Analytical Verification L 5.
CSE 3341/655; Part 4 55 A functional program: Collection of functions A function just computes and returns a value No side-effects In fact: No program.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
SYMBOLIC MODEL CHECKING: STATES AND BEYOND J.R. Burch E.M. Clarke K.L. McMillan D. L. Dill L. J. Hwang Presented by Rehana Begam.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
ML: a quasi-functional language with strong typing Conventional syntax: - val x = 5; (*user input *) val x = 5: int (*system response*) - fun len lis =
6.001 SICP SICP Sections 5 & 6 – Oct 5, 2001 Quote & symbols Equality Quiz.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
©Ian Sommerville 2000Software Engineering, 6/e, Chapter 91 Formal Specification l Techniques for the unambiguous specification of software.
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
SchemeCOP Introduction to Scheme. SchemeCOP Scheme Meta-language for coding interpreters –“ clean ” semantics Scheme = LISP + ALGOL –simple.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
Recursion. Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example: A list.
Specifications Liskov Chapter 9 SWE 619 Last Updated Fall 2008.
PPL Pairs, lists and data abstraction. Data Abstraction? An interface: separate implementation from usage Think of the Map interface in Java: we know.
M. Khalily Dermany Islamic Azad University.  finite number of element  important in number theory, algebraic geometry, Galois theory, cryptography,
Language Evaluation Criteria
Cs784(Prasad)L34ADT1 Specification and Implementation of Abstract Data Types.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
© Bertrand Meyer and Yishai Feldman Notice Some of the material is taken from Object-Oriented Software Construction, 2nd edition, by Bertrand Meyer (Prentice.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
TECH Computer Science Data Abstraction and Basic Data Structures Improving efficiency by building better  Data Structure Object IN  Abstract Data Type.
CS 330 Programming Languages 11 / 21 / 2006 Instructor: Michael Eckmann.
Recursion: Linear and Tree Recursive Processes and Iteration CMSC Introduction to Computer Programming October 7, 2002.
WXGE6103 Software Engineering Process and Practice Formal Specification.
Cs7100(Prasad)L4-5ADT1 Specification and Implementation of Abstract Data Types.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 330 Programming Languages 11 / 13 / 2008 Instructor: Michael Eckmann.
Ceg860 (Prasad)L7Class1 Classes. ceg860 (Prasad)L7Class2 Class :: Instance (Object) Static structure vs Run-time structure (Analogy -- a statue :: Lincoln.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
2004 Hawaii Inter Conf Comp Sci1 Specifying and Proving Object- Oriented Programs Arthur C. Fleck Computer Science Department University of Iowa.
Fusion Design Overview Object Interaction Graph Visibility Graph Class Descriptions Inheritance Graphs Fusion: Design The overall goal of Design is to.
Faithful mapping of model classes to mathematical structures Ádám Darvas ETH Zürich Switzerland Peter Müller Microsoft Research Redmond, WA, USA SAVCBS.
Ch Ch jcmt CSE 3302 Programming Languages CSE3302 Programming Languages (n-n-n-notes) Summer 2003 Dr. Carter Tiernan.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
Modular Decomposition, Abstraction and Specifications
Functional Programming
Abstract Syntax cs7100 (Prasad) L7AST.
ML: a quasi-functional language with strong typing
Introduction to Scheme
Type Definitions cs776 (prasad) L8tdef.
Closures and Streams cs784(Prasad) L11Clos
Specification and Implementation of Abstract Data Types
Lesson 4 Typed Arithmetic Typed Lambda Calculus
Recursion and Induction
The Metacircular Evaluator
Abstract Syntax Prabhaker Mateti 1.
Data abstraction, revisited
Lecture #9 מבוא מורחב.
Abstract Syntax cs7100 (Prasad) L7AST.
Data Mutation Primitive and compound data mutators set! for names
topics mutable data structures
6.001 SICP Data Mutation Primitive and Compound Data Mutators
Lecture 14: The environment model (cont
Sub-system interfaces
This Lecture Substitution model
6.001 SICP Interpretation Parts of an interpreter
Algebraic Specification Software Specification Lecture 34
To understand recursion, one must first understand recursion.
Lisp.
Abstract Types Defined as Classes of Variables
Presentation transcript:

ceg860 (Prasad)LADT1 Specification and Implementation of Abstract Data Types Algebraic Techniques

ceg860 (Prasad)LADT2 Data Abstraction Clients –Interested in WHAT services a module provides, not HOW they are carried out. So, ignore details irrelevant to the overall behavior, for clarity. Implementors –Reserve the right to change the code, to improve performance. So, ensure that clients do not make unwarranted assumptions.

ceg860 (Prasad)LADT3 Abstraction : Equivalence Relations –Computability Recursive vs Non-recursive –Semantics Behavioral Equivalence –Resource-independent interchangeability Performance aspect irrelevant for “correctness” –E.g., Groups, Fields, Sorting, UNIX, etc –Algorithms Time and Space requirements –Big-Oh (Worst-case Analysis) –NP-hard vs Polynomial-time

ceg860 (Prasad)LADT4 Specification of Data Types Type : Values + Operations Specify Syntax Semantics Signature of Ops Meaning of Ops Model-based Axiomatic( Algebraic ) Description in terms of Give axioms satisfied standard “primitive” data types by the operations

ceg860 (Prasad)LADT5 Syntax of LISP S-expr operations: nil, cons, car, cdr, null signatures: nil: S-expr cons: S-expr  S-expr  S-expr car: S-expr  S-expr cdr: S-expr  S-expr null: S-expr  boolean for every atom a: a : S-expr

ceg860 (Prasad)LADT6 Signature tells us how to form complex terms from primitive operations. Legal nil null(cons(nil,nil)) cons(car(nil),nil) Illegal nil(cons) null(null) cons(nil)

ceg860 (Prasad)LADT7 Formal Spec. of ADTs Characteristics of an “Adequate” Specification –Completeness ( No undefinedness ) –Consistency/Soundness ( No conflicting definitions ) GOAL: Learn to write sound and complete algebraic(axiomatic) specifications of ADTs

ceg860 (Prasad)LADT8 Classification of Operations Observers (“ Queries ”) –generate a value outside the type E.g., null in ADT S-expr Constructors (“ Creators and Commands ”) –required for representing values in the type E.g., nil, cons, atoms a in ADT S-expr Non-constructors (“ Creators and Commands ”) –remaining operations E.g., car, cdr in ADT S-expr

ceg860 (Prasad)LADT9 ADT Table ( symbol table/directory ) empty : Table update : Key x Info x Table  Table lookUp: Key x Table  nfo lookUp(K,empty) = error (Use of variable) (Alternative : Use of Preconditions) lookUp(K,update(Ki, I, T)) = if K = Ki then I else lookUp(K,T) (“last update overrides the others”)

ceg860 (Prasad)LADT10 Implementations –Array-based –LinearList-based –Tree-based Binary Search Trees, AVL Trees, B-Trees etc –HashTable-based These exhibit a common Table behavior, but differ in performance aspects. Correctness of a client program is assured even when the implementation is changed.

ceg860 (Prasad)LADT11 A-list in LISP a : A nil : A-list cons : A x A-list  A-list car : A-list  A cdr : A-list  A-list null : A-list  boolean Observers : null, car Constructors : nil, cons Non-constructors : cdr

ceg860 (Prasad)LADT12 Algebraic Spec Write axioms (equations) that characterize the meaning of all the operations. Describe the meaning of the observers and the non-constructors on all possible constructor patterns. Note the use of typed variables to abbreviate the definition. (“Finite Spec.”)

ceg860 (Prasad)LADT13 for all S, T in S-expr cdr(nil) = error cdr(cons(S,T)) = T car(nil) = error car(cons(S,T)) = S null(nil) = true null(cons(S,T)) = false (To avoid “error”, use preconditions instead.) Other atoms “a” are handled in the same way as “nil”.

ceg860 (Prasad)LADT14 Natural Numbers zero :  succ :   add :  x   iszero :   boolean observers : iszero constructors : zero, succ non-constructors : add Each numbers has a unique representation in terms of its constructors.

ceg860 (Prasad)LADT15 for all I,J in  add(zero,I) = I add(succ(J), I) = succ(add(J,I)) iszero(zero) = true iszero(succ(n)) = false

ceg860 (Prasad)LADT16 A-list Revisted a : A nil : A-list list : A  A-list append : A-list x A-list  A-list null : A-list  boolean values – nil, list(a), append(nil, list(a)),...

ceg860 (Prasad)LADT17 Algebraic Spec constructors –nil, list, append observer isnull(nil) = true isnull(list(a)) = false isnull(append(L1,L2)) = isnull(L1) /\ isnull(L2)

ceg860 (Prasad)LADT18 Problem : Same value has multiple representation in terms of constructors. Solution : Add axioms for constructors. –Identity Rule append(L,nil) = L append(nil,L) = L –Associativity Rule append(append(L1,L2),L3) = append(L1, append(L2,L3))

ceg860 (Prasad)LADT19 Writing ADT Specs Idea: Specify “sufficient” axioms such that syntactically distinct patterns that denote the same value can be proven so. –Completeness Define non-constructors and observers on all possible constructor patterns –Consistency Check for conflicting reductions Note: A term essentially records the detailed history of construction of the value.

ceg860 (Prasad)LADT20 General Strategy for ADT Specs Syntax –Specify signatures and classify operations. Constructors –Write axioms to ensure that two constructor terms that represent the same value can be proven so. E.g., identity, associativity, commutativity rules.

ceg860 (Prasad)LADT21 Non-constructors –Provide axioms to collapse a non-constructor term into a term involving only constructors. Observers –Define the meaning of an observer on all constructor terms, checking for consistency. Implementation of a type An interpretation of the operations of the ADT that satisfies all the axioms.

ceg860 (Prasad)LADT22 Model-based vs Algebraic A model-based specification of a type satisfies the corresponding axiomatic specification. Hence, algebraic spec. is “more abstract” than the model-based spec. Algebraic spec captures the least common- denominator (behavior) of all possible implementations.

ceg860 (Prasad)LADT23 Example car( cons( X, Y) ) = X cdr( cons (X, Y) ) = Y (define ( cons x y) (lambda (m) (cond ((eq? m ’first) x) (eq? m ’second) y) ) )) ; “closure” (define ( car z) (z ’first)) (define ( cdr z) (z ’second))

ceg860 (Prasad)LADT24 Canonical Form for Equality Testing Identity Element Associative Op Commutative Op Idempotent Delete element Collapse tree into linear list ( parenthesis redundant ) Order list elements Remove duplicates

ceg860 (Prasad)LADT25 Ordered Integer Lists null : oil  boolean nil : oil hd : oil  int tl : oil  oil ins : int x oil  oil order : int_list  oil Constructors: nil, ins Non-constructors: tl, order Observers: null, hd

ceg860 (Prasad)LADT26 Problem: –syntactically different, but semantically equivalent constructor terms ins(2,ins(5,nil)) = ins(5,ins(2,nil)) ins(2,ins(2,nil)) = ins(2,nil) –hd should return the smallest element. for all I in int, L in oil, it is not the case that hd(ins(I,L)) = I. This holds iff I is the minimum in ins(I,L). –Similarly for tl.

ceg860 (Prasad)LADT27 Axioms for Constructors Idempotence –for all ordered integer lists L; for all I in int ins(I, ins(I,L)) = ins(I,L) Commutativity –for all ordered integer lists L; for all I, J in int ins(I, ins(J,L)) = ins(J, ins(I,L)) Completeness : Any permutation can be generated by exchanging adjacent elements.

ceg860 (Prasad)LADT28 Axioms for Non-constructors tl(nil) = error tl(ins(I,L)) = ? tl(ins(I,nil)) = nil tl(ins(I,ins(J,L))) = I ins( J, tl(ins(I,L)) ) I > J => ins( I, tl(ins(J,L)) ) I = J => tl( ins( I,L ) ) (cf. constructor axioms for duplicate elimination ) order(nil) =nil order(cons(I,L))=ins(I,order(L))

ceg860 (Prasad)LADT29 Axioms for Observers hd(nil) = error hd(ins(I,nil)) = I hd(ins(I,ins(J,L))) = I hd( ins(I,L) ) I > J => hd( ins(J,L) ) I = J => hd( ins(I,L) ) null(nil) = true null(cons(I,L))= false

ceg860 (Prasad)LADT30 Object-Oriented Software Construction Building software systems as structured collections of (possibly partial) abstract data type implementations. Function categories –Creators ( … x …  –Queries (… x T x …  …) –Commands (… x T x … 