Algebraic Specifications

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

Formal Specifications
Chapter 7. Binary Search Trees
Stacks, Queues, and Linked Lists
Linear Lists – Array Representation
Chapter ElevenModern Programming Languages1 A Fourth Look At ML.
A Fourth Look At ML Chapter ElevenModern Programming Languages, 2nd ed.1.
5/10/20151 GC16/3011 Functional Programming Lecture 13 Example Programs 1. Evaluating arithmetic expressions 2. lists as functions.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Katz Formal Specifications Larch 1 Algebraic Specification and Larch Formal Specifications of Complex Systems Shmuel Katz The Technion.
©Ian Sommerville 2000Software Engineering, 6/e, Chapter 91 Formal Specification l Techniques for the unambiguous specification of software.
Chapter 4 Linked Lists Anshuman Razdan Div of Computing Studies
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 10 Slide 1 Formal Specification.
PPL Pairs, lists and data abstraction. Data Abstraction? An interface: separate implementation from usage Think of the Map interface in Java: we know.
PPL Pairs, lists and data abstraction. Compound Data Until now: atomic, unrelated entities Now: organized into structures Why? – Better conceptual level.
©Ian Sommerville 2000Software Engineering, 6th edition. Chapter 9 Slide 1 Formal Specification l Techniques for the unambiguous specification of software.
Attribute Grammars Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 17.
October 18, Algorithms and Data Structures Lecture V Simonas Šaltenis Nykredit Center for Database Research Aalborg University
1 Chapter 3 Data Representation Part 1. 2 Goals Introduce the different ways in which data may be represented Concepts –Abstract data types –Formula-based,
©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification.
CM0551 Exam Prep. What are an algorithm’s time and space complexity? (2 marks) Answer: The growth rate of the algorithm’s time requirement and the computer.
1 Section 10.3 Abstract Data Types as Algebras An abstract data type (ADT) is an algebra in which the carriers (i.e., the data sets) and the operations.
WXGE6103 Software Engineering Process and Practice Formal Specification.
COSC 1030 Lecture 9 Binary Trees. Topics Basic Concept and Terminology Applications of Binary Tree Complete Tree Representation Traversing Binary Trees.
Lecture – Searching a Tree Neil Ghani University of Strathclyde.
Ceg860 (Prasad)LADT1 Specification and Implementation of Abstract Data Types Algebraic Techniques.
SWEN 5130Requirements Engineering Algebraic Specification Slide 1 Algebraic Specification u Specifying abstract types in terms of relationships between.
Formal Methods in Software Engineering Credit Hours: 3+0 By: Qaisar Javaid Assistant Professor.
©Ian Sommerville 2000Software Engineering, Chapter 10 Slide 1 Chapter 10 Formal Specification.
114 3/30/98 CSE 143 Collection ADTs [Chapter 4] /30/98 Collection ADTs  Many standard ADTs are for collections  Data structures that manage groups.
(c) University of Washington20c-1 CSC 143 Binary Search Trees.
Laurea Triennale in Informatica – Corso di Ingegneria del Software I – A.A. 2006/2007 Andrea Polini IX. System Models (III)
1 Recursive Data Structures CS 270 Math Foundations of CS Jeremy Johnson.
IS301 – Software Engineering V:
Formal Specification.
Conditional Expressions
Types CSCE 314 Spring 2016.
Sorted Linked List Same objective as a linked list, but it should be sorted Sorting can be custom according to the type of nodes Offers speedups over non-sorted.
ML: a quasi-functional language with strong typing
Representing Sets (2.3.3) Huffman Encoding Trees (2.3.4)
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
LinkedIntList(int n) Write a constructor for LinkedIntList that accepts an int n parameter and makes a list of the number from 0 to n new LinkedIntList(3)
Binary Search one reason that we care about sorting is that it is much faster to search a sorted list compared to sorting an unsorted list the classic.
COP4020 Programming Languages
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Chapter 27 Formal Specification.
Lesson Objectives Aims
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Cs212: Data Structures Computer Science Department Lab 7: Stacks.
Discrete Maths 11. Recursion Objective
searching Concept: Linear search Binary search
Queues: Implemented using Arrays
File System Regions Files Documents.
Stacks: Implemented using Linked Lists
PROGRAMMING IN HASKELL
CSCE 314: Programming Languages Dr. Dylan Shell
Haskell Types, Classes, and Functions, Currying, and Polymorphism
Binary Search Trees Chapter 9 2/22/2019 B.Ramamurthy.
Data Mutation Primitive and compound data mutators set! for names
Stacks with Dynamic Memory
Binary Search Trees Chapter 9 2/24/2019 B.Ramamurthy.
Pointers & Dynamic Data Structures
CSC 143 Java Trees.
CSC 143 Binary Search Trees.
More examples of invariants
Algebraic Specification Software Specification Lecture 34
Building Java Programs
Queues: Implemented using Linked Lists
More Scheme CS 331.
Presentation transcript:

Algebraic Specifications

The structure of an algebraic specification SPECIFICATION NAME <Generic Parameters> sort <name> imports <LIST OF SPECIFICATION NAMES> Informal description of the sort and its operations Operation signatures setting out the names and the types of the parameters to the operations defined over the sort. Axioms defining the operations over the sort

List specification LIST ( Elem : [Undefined  Elem]) sort List imports INTEGER Create  List Cons (List, Elem)  List Tail (List)  List Head (List)  Elem Length (List)  Integer

List specification Head (Create) = undefined -- error to evaluate an empty list Head (Cons (L, v)) = if L == Create then v else Head (L) Length (Create) = 0 Length (Cons (L, v)) = Length (L) + 1 Tail (Create) = Create Tail (Cons (L, v)) = if L == Create then Create else Cons (Tail (L), v))

Binary Search Tree Operation Description Create Creates and empty tree Add(Binary_tree, Elem) Adds a node to the binary tree using the usual ordering principles. Left(Binary_tree) Returns the left sub-tree of the top of the tree Data(Binary_tree) Returns the value of the data element at the top of the tree Right(Binary_tree) Returns the right sub-tree of the top of the tree IsEmpty(Binary_tree) Returns true of the tree does not contain any elements Contains(Binary_tree, Elem) Returns true of the tree contains the given element

BINTREE ( Elem: [ Undefined  Elem, . == .  Bool, . < .  Bool] ) sort Binary_tree imports BOOLEAN Defines a binary search tree where the data is of generic type Elem. Build is an additional primitive constructor operation which is introduced to simplify the specification. It builds a tree given the value of a node and the left and right sub-tree.

Create  Binary_tree Add(Binary_tree, Elem)  Binary_tree Left(Binary_tree)  Binary_tree Data(Binary_tree)  Elem Right(Binary_tree)  Binary_tree IsEmpty(Binary_tree)  Boolean Contains(Binary_tree, Elem)  Boolean Build(Binary_tree, Elem, Binary_tree)  Biniary_tree

Add (Create, E) = Build(Create, E, Create) Add (B, E) = if E < Data (B) then Add (Left(B), E) else Add (Right (B), E) Left (Create) = Create Right (Create) = Create Data (Create) = Undefined Left (Build(L, D, R)) = L Right (Build(L, D, R)) = R Data (Build(L, D, R)) = D IsEmpty(Create) = true IsEmpty (Build (L, D, R)) = false Contains (Create, E) = false Contains (Build (L, D, R), E) = if E = D then true else if E < D then Contains (L, E) else Contains (R, E)

Example 1 – Specification of Sort Coord imports INTEGER, BOOLEAN This specification defines a sort called Coord representing a Cartesian coordinate. The operations defined on Coord are X and Y which evaluate the X and Y attributes of an entity of this sort and Eq which compares two entities of sort Coord for equality. Create (integer, integer)  Coord X(Coord)  integer Y(Coord)  integer Eq (Coord, Coord)  Boolean X (Create(x,y)) = x Y(Create(x,y) = y Eq (Create(x1, y1), Create(x2, y2)) = ((x1 == x2) and (y1 == y2))

CURSOR sort Cursor imports INTEGER, COORD, BITMAP A cursor is a representation of a screen position. Defined operations are Create, Position, Translate, Change_Icon and Display. Create (Coordinate, Bitmap)  Cursor Translate(Cursor, Integer, Integer)  Cursor Position(Cursor)  Coord Change_Icon(Cursor, Bitmap)  Cursor Display(Cursor)  Cursor Translate(Create(C, Icon), xd, yd) = Create(COORD.Create(X(C)+xd, Y(C)+yd), Icon) Position(Create(C, Icon)) = C Position(Translate(C, xd, yd)) = COORD.Create(X(C)+xd, Y(C)+yd) Change_Icon(Create(C, Icon), Icon2) = Create(C, Icon2)