FMSE lecture 07
Predicate Logic part II and set theory
Outline
• Free and bound variables in quantifiers
• Replacing free variables
• Scope of quantifiers
• Mixing quantifiers
• Order of quantifiers
• Mathematical data types (Sets)
• Popular sets
• Power set
• Cartesian product and relations
• Domain of a set
• Range of set
3. Free and bound variables contd..
• Predicate expressions, which are generally of the form P(t1, t2,...,tn),
have the symbol P as a node, but now P has n many subtrees, namely
the parse trees of the terms t1, t2,...,tn.
• You can see that variables occur at two different sorts of places.
• First, they appear next to quantifiers ∀ and ∃ in nodes like ∀x and ∃z;
• Such nodes always have one subtree, subsuming their scope to which
the respective quantifier applies.
3. Free and bound variables contd..
• The other sort of occurrence of variables is leaf nodes containing
variables.
• If variables are leaf nodes, then they stand for values that still have to
be made concrete.
• There are two principal such occurrences:
• We have three leaf nodes x. If we walk up the tree beginning at any
one of these x leaves, we run into the quantifier ∀x.
• This means that those occurrences of x are actually bound to ∀x so
they represent, or stand for, any possible value of x.
3. Free and bound variables contd..
• In walking upwards, the only quantifier that the leaf node y runs into
is ∀x but that x has nothing to do with y;
• x and y are different place holders.
• So y is free in this formula.
• This means that its value has to be specified by some additional
information,
• for example
• the contents of a location in memory
Definition 2.6
• Let φ be a formula in predicate logic. An occurrence of x in φ is free in
φ if it is a leaf node in the parse tree of φ such that there is no path
upwards from that node x to a node ∀x or ∃x. Otherwise, that
occurrence of x is called bound.
• For ∀x φ, or ∃x φ, we say that φ – minus any of φ’s sub formulas ∃x
ψ, or ∀x ψ – is the scope of ∀x, respectively ∃x.
• Thus, if x occurs in φ, then it is bound if, and only if, it is in the scope
of some ∃x or some ∀x; otherwise it is free.
• In terms of parse trees, the scope of a quantifier is just its subtree,
minus any subtrees which re-introduce .
3. Free and bound variables contd..
• quantifier for x; e.g. the scope of ∀x in ∀x (P(x) → ∃x Q(x)) is P(x).
• It is quite possible, and common, that a variable is bound and free in a
formula.
• Consider the formula
• (∀x (P(x) ∧ Q(x))) → (¬P(x) ∨ Q(y))
(∀x (P(x) ∧ Q(x))) → (¬P(x) ∨ Q(y))
3. Free and bound variables contd..
• Note, however, that a single leaf either is under the scope of a
quantifier, or it isn’t.
• Hence individual occurrences of variables are either free or bound,
never both at the same time.
4. SUBSTIUTION
• Variables are place holders so we must have some means of replacing
them with more concrete information.
• On the syntactic side, we often need to replace a leaf node x by the
parse tree of an entire term t.
• Recall from the definition of formulas that any replacement of x may
only be a term.
• it could not be a predicate expression, or a more complex formula,
for x serves as a term to a predicate symbol one step higher up in the
parse tree.
4. SUBSTIUTION CONTD..
• In substituting t for x we have to leave untouched the bound leaves x
since they are in the scope of some ∃x or ∀x, i.e. they stand for some
unspecified or all values respectively.
• Definition 2.7: Given a variable x, a term t and a formula φ we define
φ[t/x] to be the formula obtained by replacing each free occurrence
of variable x in φ with t.
• For example
• Let f be a function symbol with two arguments and φ the formula with the
parse tree in Figure 2.1
∀x ((P(x) → Q(x)) ∧ S(x, y)).
(∀x (P(x) ∧ Q(x))) → (¬P(x) ∨ Q(y))
Figure 2.2
4. SUBSTIUTION CONTD..
4. SUBSTIUTION CONTD..
• substitutions can give rise to undesired side effects.
• In performing a substitution φ[t/x], the term t may contain a variable y,
where free occurrences of x in φ are under the scope of ∃y or ∀y in φ.
• By carrying out this substitution φ[t/x], the value y, which might have been
fixed by a concrete context, gets caught in the scope of ∃y or ∀y.
• This binding capture overrides the context specification of the concrete
value of y, for it will now stand for ‘some unspecified’ or ‘all ,’ respectively.
• Such undesired variable captures are to be avoided at all costs
Definition 2.8 substitution contd..
• Given a term t, a variable x and a formula φ, we say that t is free for x
in φ if no free x leaf in φ occurs in the scope of ∀y or ∃y for any
variable y occurring in t.
• For example
• Given the parse tree of φ and the parse tree of t, we can perform the
substitution [t/x] on φ to obtain the formula φ[t/x].
• The latter has a parse tree where all free x leaves of the parse tree of φ are
replaced by the parse tree of t.
• What ‘t is free for x in φ’ means is that the variable leaves of the parse tree of
t won’t become bound if placed into the bigger parse tree of φ[t/x].
4. SUBSTIUTION CONTD..
• For example, if we consider x, t and φ in Figure 2.3, then t is free for x
in φ since the new leaf variables x and y of t are not under the scope
of any quantifiers involving x or y.
(∀x (P(x) ∧ Q(x))) → (¬P(x) ∨ Q(y))
Figure 2.2
• Example
• Consider the φ with parse tree in Figure 2.4
• and let t be f(y, y).
• All two occurrences of x in φ are free.
• The leftmost occurrence of x could be substituted since it is not in the
scope of any quantifier, but substituting the rightmost x leaf
introduces a new variable y in t which becomes bound by ∀y.
Therefore, f(y, y) is not free for x in φ
Figure 2.4
Mixing Quantifiers
• “Every even integer greater than 2 is the sum of two primes.”
• For every even integer n greater than 2, there exist primes p and q such that n
= p + q.
• Let Evens be the set of even integers greater than 2, and let Primes be the set
of primes.
• ∀n ∈ Evens ∃p ∈ Primes ∃q ∈ Primes. n = p + q.
Evens={4,6,8,10,12…..}
Primes={2,3,5,7,11,13,17,19}
N=4, 2+2 true,
6=3+3,true
Order of Quantifiers contd..
There is some number n which is greater than any number m
n= {0,1,2,3…..}, m={0,1,2,3…..}
n=10,
m<n
0<10 true
1<10 true
2<10 true
;;;;;;;;;
10<10 false
Scope of quantifiers
The scope of this quantification is the predicate .
All occurrences of the variable n within this predicate are said to be
bound by that quantification.
m in the quantification remains free.
Scope of quantifiers contd..
• What about this example? Which variable is bound and which
variable is free?
• Draw it parse tree and find the free variables as well as bound
variables
0<6hypothesis true
0<-1 conclusion false
• w=-1 Implication is false
• m={01,2,3….}, n={0,1,2,3…..} 0<6 o<-1 0>m
Substitution for free variables
• • An expression can be substituted for a free variable.
• This is written as P[E/x] x is replaced by P pronounced
as P with E for x.
• For example
• In the predicate x CHESS => x GO
• The substitution of the expression alice for the x variable,
results in alice CHESS => alice GO
Substitution for free variables contd..
• More complex expressions can be substituted for variables.
• For example
Substitution for free variables contd..
• Bound variables are not substituted.
• We can rename bound variables.
• Collection of variables can be substituted as
• Where the list of variables x……y are variables to be substituted
• E……..F the expressions to replace them
What are the results of applying the following
substitutions? (x<y) [y+1/y] (x<y+1) if ⱯxⱯy.(N={0,1,2,3……} .x<=y) is always true
If x=0, y=0
Limit <=50, serve =49,next=50,
0<0+1 true
Serve<limit+1==>serve<limit
If x=2, y=1
1<511<50 False
2<1+1 false
49<5149<50
Ɐ
n.(n n={0,1,2,3….}, serve=10, next 25
n=0, 10+1<4+ 0 true
n=1, 11<4+1V 1<25 true
n=5 11<4+25 V 5<25
N=25 11<4+625 V25<25
Ɐn.(n
Mathematical Data Types
Sets
• Set is a bunch of objects, which are called the elements.
• Order of elements is not significant.
• For example, here are some sets:
• A = {Alex, Tippy, Shells, Shadow} dead pets
• B = {red, blue, yellow} primary colors
• C = {{a,b} , {a,c} , {b,c}} a set of sets
Sets contd..
• The expression e ∈ S asserts that e is an element of set S
• For example
• blue ∈ B
Some popular sets
• Mathematicians have devised special symbols to represent some common sets.
• symbol set elements
• ∅ the empty set none
• Nat (N) nonnegative integers {0, 1, 2, 3,...}
• Nat1 (N1) integers greater than 0 { 1, 2, 3,...}
• Z integers {...,−3,−2,−1, 0, 1, 2, 3,...}
• Q rational numbers 1 , −5 , 16, etc.
2 3
• R real numbers π, e, −9, √2, etc.
• C complex numbers i, , √2 − 2i, etc.
2
Comparing and combining sets
• The expression S ⊆ T indicates that set S is a subset of set T (it could be said that S = T) true
• T={1,3,5,7,9,11}
• S={1,9} S ⊆ T ,S=T
• can we also say T=S
• N ⊆ Z and Q ⊆ R (every rational number is a real number .
• There are two ways to combine sets
• Union of sets
• Intersection of sets
• Example
• Let
• X ::= {1, 2, 3}
• Y ::= {2, 3, 4}
Comparing and combining sets
• Unión of X and Y is :
• X ∪ Y = {1, 2, 3, 4}.
• Intersection of X and Y is:
• X ∩ Y = {2, 3}.
Complement of Set
• for any subset, A, we define A bar to be the set of all elements not in
A
• For example
• Positive real numbers is the set of negative real numbers together
with zero
•R ∪{0} .
+(bar)
= R(bar)
• Let A and B are disjoint sets A ∩ B = ∅
• then we can write set A as :A is a subset of the complement of B.
Power Set
• The set of all the subsets of a set,
• P(A), of A.
• So B ∈P(A) Iff B ⊆ A.
• P({1, 2}) are ∅, {1} , {2} and {1, 2}.
Set Builder Notation
• An important use of predicates is in set builder notation.
• A ::= {n ∈ N | n is a prime and n =4k +1 for some integer k}
• The set A consists of all nonnegative integers n for which the
predicate “n is a prime and n =4k +1 for some integer k” is true. Thus,
the smallest elements of A are: 5, 13, 17, 29, 37, 41, 53, 57, 61, 73,....
• B ::= {x ∈ R | x3 − 3x +1 > 0 }
• C ::={ a + bi ∈ C | a2 +2b2 ≤ 1 }
Proving Set Equalities
• X = Y means that z ∈ X if and only if z ∈ Y , for all elements, z.
• For example
• A ∩ (B ∪ C)=(A ∩ B) ∪ (A ∩ C)
Relations
• Machines/models can be required to maintain information about
relationships on the information contained within them.
• Relation between sets
• If S and T are two sets, then their Cartesian product SxT is the set of all pairs
(s, t) of elements from S and T respectively. This is defined as follows:
Relation notations
• s↦t pronounced s maps to t
• It exactly means the same as (s, t)ordered pair.
• it is a pair whose first element is s and whose second element is t.
• A relation R between sets S and T expresses a relationship
between elements in S and elements in T.
• It is captured as a set of pairs (s, t) with s S and t T representing
those elements which are related.
Relation Example
• PHOTOGRAPHER={anna, bob, chris, dave, elizabeth, francis} and
• CAMERA={canon, kodak ,hasselblad ,minolta, olympus ,pentax}
• The relation owns detailing the ownership relation between
photographers and their cameras can be defined as follows
• Owns={(anna, canon), (bob, canon), (bob, kodak), (chris, hasselblad),
(chris, kodak), (chris, pentax), (dave, pentax), (elizabeth, pentax),
(elizabeth, minolta)}
Relation Example contd..
• Or using the notation map
• Owns={(anna ↦ canon), (bob ↦ canon), (bob ↦ kodak), (chris ↦
hasselblad), (chris ↦ kodak), (chris ↦ pentax), (dave ↦ pentax),
(elizabeth ↦ pentax),(elizabeth ↦ minolta)}
• A relation between S and T is a subset of SxT or an element of P(SxT).
• The notation S⟷T denotes the set of relations between S and T.
Relation Abbreviation
• Hence S ⟷ T is an abbreviation for the set of all substes of SxT
• S⟷T=P(SxT)// an element of power set of SxT
• To specify that R is a relation between S and T we write RS⟷T.
• In this case set S is said to be the source of R and the set T is said to
be the target.
• For example owns PHOTOGRAPHER⟷CAMERA
• Read it as (Photographer owns camera)
Relation Abbreviation contd..
• The statement that (dave, pentax) owns states that dave is related to
pentax in the relation owns.
• dave↦pentax also states that dave is related to pentax.
• owns(dave↦pentax )
• If owns records the cameras that are owned by the photographers,
then this corresponds to the information that dave owns a pentax
camera.
Relations use
• When producing specifications, we are generally interested in
extracting information from the relations our machines/models
maintain,
• To answer particular questions such as:
Relations use contd..
• Owns={(anna, canon), (bob, canon), (bob, kodak), (chris, hasselblad), (chris, kodak),
(chris, pentax), (dave, pentax), (elizabeth, pentax),(elizabeth, minolta)}
• Does Bob own a camera?
• How many cameras does Elizabeth own?
• Who owns a Hasselblad camera? (chris, hasselblad)
• Which cameras are used by both Chris and Dave?
• How many cameras does Anna own?
• Is there anyone that does not have a camera?
• There are constructs for extracting the information required for questions to be
expressed in relations.
Relations use contd..
• Extracting the domain and range of a relation
• Domain restriction: restricting the relation to a particular domain of
interest
• Range restriction: restricting the relation to a particular range of
interest
• Identifying the elements related to some item in a given set.
• Relational inverse the relation the opposite way round
Domain of a Relation
• The domain of a relation R S ↔T is the set of elements of S that R
relates to something in T.
• Items in the source set that are related to something, it is written
dom(R)
• Dom(owns)= {anna,bob, chris, dave, elizabeth}
Range of a Relation
• The range is the set of elements of T that are related to some element
of S. it is written ran(R)
• For example
• Ran(owns)={canon, kodak, hasselblad, minolta, pentax}
Solve
P(Member)={},{fred},{ginger},{harold},{fred,ginger},{fred,harold},{ginger,fred}
{fred,ginger,harold} (2^n)
MemberxMember={fred,ginger},{fred,harold},{ginger,fred}{ginger,Harold},{Harold,fred},
{Harold,ginger},{fred, fred},{ginger,ginger},{Harold,harold} nxn
CARD(MemberxMember)=9
CARD(P(MemberxMember))=2^9
CARD(P(P(MEMBER))=(2^3)
=(2^8)=
Solve contd…
P(Member)={},{fred},{ginger},{harold},{fred,ginger},{fred,harold},{ginger,fred}{fred,ginger,harold}
TO DO list
• Read chapter 2 from the b- method an introduction Steve Schneider
and solve its examples and exercises.
• Read chapter 1 from logic in computer science, related to contents
covered in lecture 4,5, 6 and 7 and solve relevant exercises.
• Quiz 03 will be held in next (8th) lecture.
• Submit individual project proposal on real time systems. Assignments
shall be covered from project.
Any questions?