Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
CMPUT 272
Formal Systems
Logic in CS
I. E. Leonard
University of Alberta
http://www.cs.ualberta.ca/~isaac/cmput272/f03
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
1
Today
Sets (5.1, 5.2, 5.3)
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
2
Sets (chapter 5)
QuickTi me™ and a TIFF (U ncompressed) decompressor are needed to see this picture.
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
3
Sneak-preview : Sets
What is a set?
A collection of elements:
Order is irrelevant
No repetitions
Can be infinite
Can be empty
Examples:
{Angela, Belinda, Jean}
{0,1,2,3,…}
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
4
Operations on sets
S is a set
Membership:
xS
x is an element of S
Angela{Angela, Belinda, Jean}
Subset:
S1 S
Set S1 is a subset of set S
All elements of S1 are elements of S
{Angela,Belinda} {Angela, Belinda, Jean}
Proper subset S1S
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
5
Operations on sets
S, S1 are sets
Equality:
S = S1
iff they have the same elements
Difference:
S \ S1
is a set of all elements that belong to S but
NOT to S1
{Angela, Belinda, Jean} \ {Angela,Dana} =
{Belinda, Jean}
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
6
Operations on sets
S, S1 are sets
Intersection:
S S1
is a set of all elements that belong to both
{Angela, Belinda, Jean} {Angela,Dana} =
{Angela}
Union:
S S1
is a set of all elements that belong to either
{Angela, Belinda, Jean} {Angela,Dana} =
{Angela,Belinda,Jean,Dana}
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
7
More notation
In mathematics sets are often specified
with a predicate and an enveloping set
as follows:
S={xA | P(x)}
S is the set of all elements of A that satisfy
predicate P
Example:
Q={xR | a,bZ b0 & x=a/b}
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
8
Set Equality
Two sets are equal iff they have the
same elements
Theorem: for any sets A and B, A=B iff
AB & BA
Proof
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
9
Subset and Membership
Book example 5.1.5
2{1,2,3}
{2}{1,2,3}
2{1,2,3}
{2}{1,2,3}
{2}{{1},{2}}
{2}{{1},{2}}
?
?
?
?
?
?
How about set A such that {2} is a
subset of it and A is an element of it?
A={1,2,{1},{2}}
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
10
Universal Set
If we are dealing with sets which are all
subsets of a larger set U then we call it
a universal set U
All of your sets will be subsets of U
When does such a U exist?
Always, for we can set U to the union of all
sets involved
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
11
Complement
So if I am dealing with set A which is a
subset of the universal set U then:
I can define complement of A:
AC=U\A
That is the set of all elements (of U)
that are not in A
Often “of U” is dropped and people say
that AC is the set of everything that is
not in A
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
12
Quick questions
What is the complement of U?
UC = Ø
What set has U as its complement?
ØC=U
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
13
Sets & Predicate Logic
All of the set operations and relations
above can be defined in terms of
Boolean connectives:
AB={x | xA v xB}
AB={x | xA & xB}
A\B={x | xA & not xB}
AC={x | not xA}
A=B iff x (xA xB)
AB iff x (xA xB)
AB iff (x (xA xB)) & not (A=B)
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
14
Questions
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
15
Symmetric Difference
Set C is the symmetric difference of sets
A and B iff every element of C belongs
to A or B but not both
ABC [C=A B a (aC
(aA xor aB))]
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
16
Examples
A={1,2}, B={2,3}
A B={1,3}
A={Clinton,Reagan}, B={Gorbachov,Bregnev}
A B={Clinton,Reagan,Gorbachov,Bregnev}
A={CMPUT272 students}, B={CMPUT272 students}
A B = {}
In general: A A = {}
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
17
Exercise 2
Intersection of two sets is contained in their union:
AB [ (A B) (A B) ]
Proof:
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
18
Exercise 3
Union is commutative
AB [ A B = B A ]
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
19
Exercise 4
Intersection is commutative
AB [ A B = B A ]
Proof: very similar to the one we just
did. Try it yourself.
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
20
Exercise 5
Intersection distributes over union:
ABC [ A (B C) =(A B) (A C) ]
There is an analogy between logical operations v and &
and arithmetic operations:
v feels like +
& feels like *
So A & (B v C) = A & B v A & C
[just like A*(B+C) = A*B + A*C]
How about A+(B*C) --- is it (A+B)*(A+C)?
NO
So what about A v (B & C) = (A v B) & (A v C)?
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
21
The Analogy
The analogy is incomplete:
Arithmetic:
Logic:
A+(B*C) (A+B)*(A+C)
A v B&C = (A v B) & (A v C)
Proof of the latter:
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
22
Exercise 6
In Exercise #5 we proved:
ABC [ A (B C) =(A B) (A C) ]
using the fact that A&(B v C)=A&B v A&C
Given the statement just proved
A v B&C = (A v B) & (A v C)
what can we now prove in terms of sets?
Union distributes over intersection:
ABC [ A (B C) =(A B) (A C) ]
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
23
Proof of Exercise 6
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
24
Questions
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
25
More Identities
See Theorem 5.2.2 in the book
The proofs can often be done using:
the logical definitions of set operations
logical identities we have proven before
I recommend doing some/all of them as
an exercise
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
26
Boolean Algebra
Are these similarities between set
identities and logical identities
incidental?
It turns out that both systems are
examples of a more general construct
called Boolean algebra
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
27
Boolean Algebra
Boolean algebra is a set S together with two operations: +
and * defined on S such that the following identities hold: For
all a,b,c in S
a+b is in S and a*b is in S (closure laws)
a+b=b+a and a*b = b*a (commutative laws)
(a+b)+c=a+(b+c) and (a*b)*c = a*(b*c) (associative laws)
a*(b+c)=a*b+a*c and a+(b*c) = (a+b)*(a+c) (distributive laws)
There exist distinct 0,1 in S:
a+0=a (additive identity)
a*1=a (multiplicative identity)
For each a from S there exists a complement a’ such that:
a+a’=1 (complement laws)
a*a’=0
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
28
Boolean Algebra - Logic - Sets
S
+
*
a+b=b+a
a*b=b*a
(a+b)+c=a+(b+c)
(a*b)*c=a*(b*c)
a*(b+c)=(a*b)+(a*c)
a+(b*c)=(a+b)*(a+c)
0
1
a+0=a
a*1=a
complement (a’)
a+a’=1
a*a’=0
Oct 30, 2003
{true,false}
v
&
avb=bva
a&b=b&a
(avb)vc=av(bvc)
(a&b)&c=a&(b&c)
a&(bvc)=(a&b)v(a&c)
av(b&c)=(avb) & (avc)
false
true
a v false = a
a & true = a
~a
a v ~a = true
a & ~a = false
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
P(U) (i.e., all sets)
ab=ba
ab=ba
(ab)c=a(bc)
(ab)c=a(bc)
a(bc)=(ab)(ac)
a(bc)=(ab)(ac)
Ø
U
aØ=a
aU=a
aC
a aC = U
a aC = Ø
29
Notes
How about numbers with addition and
multiplication? Do they form a Boolean
algebra?
Not quite
Why are these 5 groups of identities
(page 266 in the book) important?
Other standard identities of any Boolean
algebra (including Boolean logic and sets
can be derived from them)
Oct 30, 2003
© Vadim Bulitko : CMPUT 272, Fall 2003, UofA
30