Set Theory Introduction We introduce the use of Set Theory in - - PDF document
Set Theory Introduction We introduce the use of Set Theory in - - PDF document
Set Theory Introduction We introduce the use of Set Theory in specifying computer systems We introduce: Z schemas for defining states and events/relationships between states. Some basic set notation. is (not) an element
Introduction
We introduce the use of Set Theory in
specifying computer systems
We introduce:
- Z schemas for defining states and
events/relationships between states.
Some basic set notation.
- “is (not) an element of”,
- “Set Union”,
- “Set Difference”
System Lifecycle
- Requirements analysis
- System Specification
- Design
- Implementation
- Testing and Integration
- Support and Enhancement
Abstraction?!
Geographical Representation 1932 Abstract Representation 1933
Maps from London Underground , Idea from Woodcock and Davies
Scenario
Your software company has been
approached to design and build a software system to manage the book loans in a library.
Exercise: Library system
We want to describe a system to track the
borrowing of books from a library.
Identify three elements of a real library system
that you will want to retain in your description.
Identify six elements of a real library system that
you will want to abstract away.
What kind of things should your specification
describe?
Informal Library System
Library a set stock a set members A rule is_on_loan_to Acquire(book b) b is not already in the set stock Add b to the set stock Join(person p) p is not already in the set members Add p to the set members Dispose(book b) Leave(person p)
STATE EVENTS
Return(book b ,person p) Library a set stock a set members A rule is_on_loan_to Borrow(book b, person p) b is not already on loan to anyone Add b is on loan to p
Borrowing and returning books
Library a set stock a set Members A link is_on_loan_to Dispose(book b) Remove b from the set stock b is not in the set stock b is in the set stock Acquire(book b) Add b to the set stock
Towards a Formal Description:
stock b∉
stock b∈
Acquire(book b) Library a set stock a set Members A link is_on_loan_to
Add b to the set stock
{ }
b Books s Book \ = ′
After the event stock is what stock was before the event with b added
Changing State 1: Acquire
stock b∉
} { ' b stock stock ∪ =
Dispose(book b) stock b∈ Library a set stock a set members A link is_on_loan_to
Remove b from the set stock
{ }
b stock stock \ ' =
After the event stock is what stock was before the event with b removed
Changing State 2: Dispose
Exercise: Complete Join and
Leave.
Library a set stock a set members A link is_on_loan_to Join(person p) p is not already in the set Members
Add p to the set Members
Leave(person p) p is in the set Members
Remove p from the set Members
Return(book b ,person p)
Toward a Formal Description:
Borrowing and returning
Library a set stock a set members A link is_on_loan_to Borrow(book b, person p) b is not already on loan to anyone Add b is on loan to p
Question: What is “is_on_loan_to”?
Summary
Software life cycle Specification Sets a is an element of A
:
a is not an element of A : The Union of two sets A and B : The set difference of two sets A and B:
A a∈
A a∉
B A∪
B A \
Sets: Basics
Sets: Basics
In this lecture we introduce:
- The basic concept of a set
- Notations for denoting sets
- Set enumeration
- Set comprehension
- Basic set operations
- Union, intersection, set difference
- Use of Venn Diagrams
[Haggarty chapter 3]
and [Currie chapter 3]
Sets: Basic Concept, Notation and Constructions
What is a set?
set g r
- u
p f a m i l y ensemble b u n c h class g a t h e r i n g collection h e r d
We could have sets of……………? Some examples of sets of “numbers”…
[c.f. Haggerty p36]
N = The set of Natural Numbers
{ 1,2,3,…}
Z = The set of Integers
{ …-3,-2,-1,0,1,2,3,…}
Q = The set of Rational Numbers { p/q : p,q integers, not(q= 0) } R = The set of Real Numbers
all decimals?
Notation
“A set is a collection of objects called elements”
[Haggarty p34]
“A set is a collection of distinct objects called
elements or members” [Currie p20]
} prime" is x |" N {x ∈
} even" is x |" N {x ∈
{1,2,3,4} {Anne of Cleves, Anne Boleyn} {2,4,6,8,…} {2,4,6,8,…,2n,…} {2,3,5,7,11,…} The set of wives of Henry VIII called Anne The set of all natural numbers that are even The set of all natural numbers that are prime
A(x)} | W {x ∈
W: set of wives of Henry A(x): x is called Anne
Exercise:
Enumerate the following sets using set brackets as
- n the previous slide. You may need to use dots
E.g.
- 0,1,2,3}
{-3,-2,-1, 10} x | Z {x
2
= < ∈
B(x)} | A {x ∈
integer} another double is x | Z {x ∈
} r" " letter e contain th not does x | year the
- f
months {x ∈
5} x and x | Z {x < < ∈ 1} x | Z {x
2 =
∈
Venn Diagrams
A convenient way of visualising/illustrating sets is the
use of Venn Diagrams using circles to represent sets and shading to illustrate/distinguish areas of interest.
A Venn Diagram illustrating a set A with…
A y A x ∉ ∈ and A y x
A Venn Diagram illustrating …
sets two
- f
Union The B A ∪ A B B A ∪
Basic Operations on Sets
A B
B A ∪
A B
B A \
A A B
B A ∩
A B
A B \
A B B x
- r
A x B A x ∈ ∈ ∪ ∈ if
- nly
and if B x a A x B A x ∈ ∈ ∩ ∈ nd if
- nly
and if B x a A x B A x ∉ ∈ ∈ nd if
- nly
and if \
Subset
A B
B A ⊆
Examples
{ } { }
7 , 6 , 5 , 4 , 3 , 2 , 1 4 , 3 , 2 ⊆
{ }
N 7 , 6 , 5 , 4 , 3 , 2 , 1 ⊆
{ }
Months July June, May, ⊆ B A A ∪ ⊆ A B A ⊆ ∩
B A B A ⊆ denoted is "
- f
subset a is "
Set A is a subset of set B if every element of A is an element of B
1.
Union
2.
Intersection
3.
Subset
4.
Member of
5.
Set difference
U n i
- n
I n t e r s e c t i
- n
S u b s e t M e m b e r
- f
S e t d i f f e r e n c e
0% 0% 0% 0% 0%
? in used being is symbol What B A∩
1.
Union
2.
Intersection
3.
Subset
4.
Member of
5.
Set difference
U n i
- n
I n t e r s e c t i
- n
S u b s e t M e m b e r
- f
S e t d i f f e r e n c e
0% 0% 0% 0% 0%
? in used being is symbol What B A ⊆
1.
Union
2.
Intersection
3.
Subset
4.
Member of
5.
Set difference
U n i
- n
I n t e r s e c t i
- n
S u b s e t M e m b e r
- f
S e t d i f f e r e n c e
0% 0% 0% 0% 0%
? in used being is symbol What B a∈
Use of a Sequence of Venn diagrams
) \ ( ) \ ( ) ( \ show To C A B A C B A ∩ = ∪
A B C
C B ∪ ( )
C B A ∪ \
B A \
C A \
( ) ( )
C A B A \ \ ∩
The shaded areas for and are the same. Thus
) \ ( ) \ ( ) ( \ C A B A C B A ∩ = ∪ ) ( \ C B A ∪ ) \ ( ) \ ( C A B A ∩
Venn Diagram Exercise
? ) ( ) ( that it true Is C B A C B A ∩ ∪ = ∩ ∪
? ) \ ( ) \ ( ) ( \ that it true Is C A B A C B A ∪ = ∩ ? ) ( ) ( that it true Is C B A C B A ∪ ∩ ⊆ ∪ ∩
1.
Yes
2.
No
3.
Don’t know
Y e s N
- D
- n
’ t k n
- w
0% 0% 0%
? ) \ ( ) \ ( ) ( \ that it true Is C A B A C B A ∪ = ∩
1.
Yes
2.
No
3.
Don’t know
Y e s N
- D
- n
’ t k n
- w
0% 0% 0%
? ) ( ) ( that it true Is C B A C B A ∩ ∪ = ∩ ∪
1.
Yes
2.
No
3.
Don’t know
Y e s N
- D
- n
’ t k n
- w
0% 0% 0%
? ) ( ) ( that it true Is C B A C B A ∪ ∩ ⊆ ∪ ∩
Size of set
Notation: # A denotes the number of
elements in the set A.
E.g.
1 2 3 N
- n
e
- f
t h e a b
- v
e
0% 0% 0% 0%
- 1. 1
- 2. 2
- 3. 3
4.
None of the above
A B
Membership tables 1
( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )
form... in tabular this do can We cases. eight all for check this to need We . and and , deduce may then we and , if example For . and
- f
ship member s ' for ies possibilit various the g considerin by this do can We versa.
- vice
and
- f
member a also is it then
- f
element an is whenever that show must we show To : Example C B A x C B x C A B A x C A x B A x C x B x A x C A, B x C A B A C B A x C A B A C B A ∪ ∩ ∉ ∪ ∈ ∩ ∪ ∩ ∉ ∩ ∉ ∩ ∉ ∉ ∈ ∉ ∩ ∪ ∩ ∪ ∩ ∩ ∪ ∩ = ∪ ∩
Membership tables 2
. if and if under 1 place we table In the SET x SET x SET ∉ ∈ A B C C B ∪
( )
C B A ∪ ∩ B A∩ C A∩
( ) ( )
C A B A ∩ ∪ ∩
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Membership tables: Observation
A B C C B ∪
( )
C B A ∪ ∩ B A∩ C A∩
( ) ( )
C A B A ∩ ∪ ∩
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
A B C
Each row in the membership table corresponds to precisely one “zone” in the Venn Diagram. The “1”s under a Set Expression will indicate the “zones” that correspond to that set
Membership tables: Observation continued
A B C C B ∪
( )
C B A ∪ ∩ B A∩ C A∩
( ) ( )
C A B A ∩ ∪ ∩
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
A B C
Membership tables: Exercise
Which of the following are true?
) ( \ ) ?( ) \ ( ) \ ( ) \ ?( ) \ ( C B C A C B A C B C A C B A ∩ ∩ = ∩ ∪ = ∪
Summary
The basic concept of a set Notations for denoting sets
Set Enumeration Set Comprehension
Basic set operations:
Union, intersection, set difference
Use of Venn diagrams Use of membership tables
{ }
4 , 3 , 2 , 1
{ }
even" is " | N x x∈
{ }
prime" is " | N x x∈ B A ∩
{Anne Boleyn, Anne of Cleves}
A B C
( )
1 1 1 1 1 1 1 1 1 B A B B A B A ∪ ∩ ∪