Exploring Sets in Math & Formal Specification: A Deep Dive into Set Theory & Z Notation, Slides of Software Development Methodologies

An introduction to sets, a fundamental concept in mathematics and important for understanding formal specification and design in software engineering. The basics of set theory, including set membership, extension, comprehension, power sets, and cartesian products. It also introduces the z notation, a formal specification language based on set theory, and explains how sets are used in z specifications.

Typology: Slides

2011/2012

Uploaded on 07/09/2012

chand
chand 🇮🇳

4.4

(7)

31 documents

1 / 21

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter No. 5
Sets
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15

Partial preview of the text

Download Exploring Sets in Math & Formal Specification: A Deep Dive into Set Theory & Z Notation and more Slides Software Development Methodologies in PDF only on Docsity!

Chapter No. 5

Sets

Introduction

  • Mathematical objects are often seen as collections of other objects e.g. - A square is a collection of points in a plane - A function is a collection of pairs
  • These collections are called sets
  • Their theory is a fundamental part of mathematics
  • As mathematics forms the basis of modern software engineering
  • Hence we should not be surprised to find that sets are important to our understanding of formal specification and design

Introduction

  • At the end of the chapter, we will introduce

a system of types based upon maximal sets, a system used throughout the rest of the book.

  • It will help us to ensure that expressions

and variables are used consistently in a specification

Definition of a Set:

A set is a well-defined an un-ordered collection of distinct objects docsity.com

Membership and Extension

The following are all examples of sets

  • The four oceans of the world

Oceans == {Atlantic, Arctic, Indian, Pacific}

  • The individuals who have been appointed to the

post of secretary-general of the United Nations Secretaries == {Trygve Lie,.. ., Koffi Annan}

  • The passwords that may be generated using eight

lower-case letters

  • The prime numbers

Primes == {2, 3, 5, 7,... }

Membership and Extension

Example 5.4 : If we define

s == { 2 , 2 , 5 , 5 , 3} and t == { 2 , 3, 5} then s = t

Example 5.5 : If we let Rockallers be the set

of people who live and work on Rockall, which is a small uninhabited island in the Atlantic Ocean, then

Rockallers = 

Set Comprehension

  • Given any non-empty set s, we can define a

new set by considering only those elements of s that satisfy some property p.

  • This method of definition is called set

comprehension. We write {x : s | p  x} = {x : s | p}

It denotes the set of all elements x in s that

satisfy predicate p

Set Comprehension

It we are interested in expression formed from the values satisfying the predicate p, and not in the values themselves, then { x : s | p  e} denotes the set of all expressions e such that x is drawn from s and satisfies p.

Example 5.9 (Example 5.8) To investigate the crime, the authorities require a set of addresses to visit. { x : Person | x drives a red car  address (x)}

Set Comprehension

Example 5.10 : Without the information that a red car was involved, the authorities would be left with the following set of addresses: { x : Person  address (x)}

It is to be noted that above expression can be written as { x : Person | true  address (x)}

In general

{ x : s  e} = { x : s | true  e}

Set Comprehension

Example 5.12 :

There is nothing special about the names chosen for the driver and his or her accomplice. The set in Example 5.11 could equally well have been written as

{v : Person; w : Person | v is associated with w 

v drives a red car  w reads the Daily Mail  v}

Power Sets

Definition :

If a is a set, then the set of all subsets of a is called the power set of a, and written ¡a. For example, if a is the set {x, y} then  a = { , {x}, {y}, {x, y} }

  • This new set has four elements: the empty set, the set a itself, and the two other subsets of a.

Note :

  • In general, if a set a has n elements, then the power set  a has 2n

Cartesian Product

  • In a formal description of a software system, we may wish to associate objects of different kinds: names; numbers; various forms of composite data.
  • We may also wish to associate two or more objects of the same kind, respecting order and multiplicity.
  • To support this structuring of information, the Z notation includes Cartesian products.
  • These are sets of tuples: ordered lists of elements, one drawn from each of the component sets

Cartesian Product

  • If a and b are sets, then the Cartesian product a  b consists of all tuples of the form (x, y), where x is an element of a and y is an element of b. a  b = {(x, y) | x : a  y : b }
  • A tuple with exactly two elements is called an ordered pair
  • A tuple with exactly n elements, where n is greater than 2, is called an n-tuple.

Cartesian Product

Then the set of possible solutions is given by the Cartesian product: Guests  Rooms  Weapons

And a typical guess would be

(Colonel Mustard, Library, Revolver)

It was Colonel Mustard, in the library, with the revolver.

Cartesian Product

If guess is an element of:

Guests  Rooms  Weapons, then guess.1 is the name of the murderer guess.2 is the suggested location guess.3 is the weapon used

If guess is the tuple

(Colonel Mustard, Library, Revolver) above results

Colonel Mustard, Library, and Revolver, respectively.

Example 5.18 : If there are 6 guests, 9 rooms, and 6 weapons in Cluedo. Then there are 6  9  6 = 324 elements in the above set