You are on page 1of 9

Chapter 1: Propositions and Predicates

19

The given premises are:


(i)
(ii)
(iii)
(iv)

p
Q

R
P

Q
R
S 1\ T

The conclusion is S.
1. P
2. P

Premise (i v)
Premise (i)
Modus ponens RIJ,
3. Q
Premise (ii)
4. Q ~ R
Modus ponens RIJ,
5. R
Premise (iii)
6. R ~ S 1\ T
Modus ponens RIJ,
7. 5 1\ T
Simplification Rl~
8. S
Thus the argument is valid.

1.4

PREDICATE CALCULUS

Consider two propositions 'Ram is a student', and 'Sam is a student'. As


propositions, there is no relation between them, but we know they have
something in common. Both Ram and Sam share the property of being a
student. We can replace the t\VO propositions by a single statement 'x is a
student'. By replacing x by Ram or Sam (or any other name), we get many
propositions. The common feature expressed by 'is a student' is called a
predicate. In predicate calculus we deal with sentences involving predicates.
Statements involving predicates occur in mathematics and programming
languages. For example. '2x + 3y = 4,:', 'IF (D. GE. 0.0) GO TO 20' are
statements in mathematics and FORTRAN. respectively, involving predicates.
Some logical deductions are possible only by 'separating' the predicates.

1.4.1

PREDICATES

A part of a declarative sentence describing the properties of an object or


relation among objects is called a predicate. For example, 'is a student' is a
predicate.
Sentences involving predicateSCfe~-cribing the property of objects are
denoted by P(x), where P denotes the predicate and x is a variable denoting
any object. For example. P(x) can denote 'x is a student'. In this sentence, x
is a variable and P denotes the predicate 'is a student'.
The sentence 'x is the father of y' also involves a predicate 'is the father
of. Here the predicate describes the relation between two persons. We can
write this sentence as F(x, y), Similarly, 2x + 3y = 4z can be described by
Sex, y, ,:).

http://engineeringbooks.net

20

Theory of Computer Science

Note: Although P(x) involving a predicate looks like a proposition, it is not


a proposition. As P(x) involves a variable x, we cannot assign a truth value
to P(x). However, if we replace x by an individual object, we get a
proposition. For example, if we replace x by Ram in P(x), we get the
proposition 'Ram is a student'. (We can denote this proposition by P(Ram).)
If we replace x by 'A cat', then also we get a proposition (whose truth value is
F). Similarly, S(2, 0, 1) is the proposition 2 . 2 + 3 . 0 = 4 . 1 (whose truth
value is T). Also, S(l, 1, 1) is the proposition 2 . 1 + 3 . 1 = 4 . 1 (whose
truth value is F).
The following definition is regarding the possible 'values' which can be
assigned to variables.

Definition 1.13 For a declarative sentence involving a predicate, the


universe of discourse, or simply the universe, is the set of all possible values
which can be assigned to variables.
For example, the universe of discourse for P(x): 'x is a student', can be
taken as the set of all human names; the universe of discourse for (n): 'n is
an even integer', can be taken as the set of all integers (or the set of all real
numbers).
Note: In most examples. the universe of discourse is not specified but can be
easily given.
Remark We have seen that by giving values to variables, we can get
propositions from declarative sentences involving predicates. Some sentences
involving variables can also be assigned truth values. For example, consider
'There exists x such that .~ = 5', and 'For all x, .~ = (_x)2,. Both these
sentences can be assigned truth values (T in both cases). 'There exists' and
'For all' quantify the variables.

Universal and Existential Quantifiers


The phrase 'for all' (denoted by V) is called the universal quantifier. Using
this symbol, we can write 'For all x, x 2 = (_x)2, as Vx Q(x), where Q(x) is
'x 2

= (_x)2 ..

The phrase 'there exists' (denoted by 3) is called the existential quantifier.


The sentence 'There exists x such that x 2 = 5' can be written as 3x R(x),
= 5'.
where R(x) is
P(x) in Vx P(x) or in 3x P(x) is called the scope of the quantifier V or 3.

'r

Note: The symbol V can be read as 'for every', 'for any', 'for each',
'for arbitrary'. The symbol 3 can be read as 'for some', for 'at least one'.
When we use quantifiers, we should specify the universe of discourse. If
we change the universe of discourse, the truth value may change. For example,
consider 3x R(x), where R(x) is x 2 = 5. If the universe of discourse is the set
of all integers. then 3x R(x) is false. If the universe of discourse is the set of
all real numbers. then 3x R(x) is true (when x = .J5 ' x 2 = 5).

http://engineeringbooks.net

Chapter 1: Propositions and Predicates

,\;!

21

The logical connectives involving predicates can be used for declarative


sentences involving predicates. The following example illustrates the use of
connectives.
EXAM PLE 1.21
Express the following sentences involving predicates in symbolic form:
1.
2.
3.
4.
5.

All students are clever.


Some students are not successful.
Every clever student is successful.
There are some successful students who are not clever.
Some students are clever and successful.

Solution
As quantifiers are involved. we have to specify the universe of discourse. We
can take the universe of discourse as the set of all students.
Let C(x) denote 'x is clever'.
Let Sex) denote 'x is successful'.
Then the sentence 1 can be written as 'IIx C(x). The sentences 2-5 can be
written as
::Jx (,

Sex~,

::Jx (S(x) /\ ,C(x,

1.4.2

'IIx (cex) :::::} Sex~,

::Jx (C(x) ,

Sex~

WELL-FORMED FORMULAS OF PREDICATE CALCULUS

A well-formed formula (wff) of predicate calculus is a string of variables such


as Xl, x2, . , X/1' connectives. parentheses and quantifiers defined recursively
by the following rules:
(i) PCYl, ... , x,J is a wff. where P is a predicate involving n variables
Xl, X20

. , J.-11'

(ii) If a is a wff. then , a is a wff.


(iii) If a and [3 are wffs, then a v [3, a i\ [3, a :::::} [3, a:::}[3 are also
wffs.
(iv) If a is a wff and x is any v~e; then 'IIx (a), ::Jx (a) are wffs.
(v) A string is a wff if and only if it is obtained by a finite number of
applications of rules (i)-(iv).
Note: A proposition can be viewed as a sentence involving a predicate with 0
Variables. So the propositions are wffs of predicate calculus by rule (i).
We call wffs of predicate calculus as predicate formulas for convenience.
The well-formed formulas introduced in Section 1.1 can be called proposition
formulas (or statement formulas) to distinguish them from predicate formulas.

http://engineeringbooks.net

22

Theory ofComputer Science

DefInition 1.14 Let ex and [3 be two predicate formulas in variables Xb


XII' and let Ube a universe of discourse for ex and [3. Then ex and f3 are
equivalent to each other over U if for every possible assignment of values to
each variable in ex and [3 the resulting statements have the same truth values.
We can write ex = [3 over U.
We say that ex and f3 are equivalent to each other (ex ==

fJ>

if ex == [3 over

U for every universe of discourse U.

Remark In predicate formulas the predicate val;ables mayor may not be


quantified. We can classify the predicate variables in a predicate formula,
depending on whether they are quantified or not. This leads to the following
definitions.
Definition 1.15 If a formula of the form 3x P(x) or "Ix P(x) occurs as part
of a predicate formula ex, then such part is called an x-bound part of ex, and
the occurrence of x is called a bound occurrence of x. An occurrence of x is
free if it is not a bound occurrence. A predicate variable in a is free if its
occurrence is free in any part of a.
In a = (3x l P(XI' x:)) /\ (Vx c Q(x:> X3))' for example, the occurrence of
Xl in 3.1:) P(Xl' xc) is a bound occurrence and that of Xc is free. In VX2 Q(x:> X3),
the occurrence of Xc is a bound occurrence. The occurrence of X3 in ex is
free.
Note: The quantified parts of a predicate formula such as "Ix P(x) or 3x P(x)
are propositions. We can assign values from the universe of discourse only
to the free variables in a predicate f01lliula a.

DefInition 1.16 A predicate formula is valid if for all possible assignments


of values from any universe of discourse to free variables, the resulting
propositions have the truth value T.
Defmition 1.17 A predicate formula is satisfiable if for some assignment of
values to predicate variables the resulting proposition has the truth value T.
DefInition 1.18 A predicate formula is unsatisfiable if for all possible
assignments of values from any universe <5fdiscourse to predicate variables the
resulting propositions have the truth value F.
We note that valid predicate formulas correspond to tautologies among
proposition formulas and the un satisfiable predicate formulas correspond to
contradictions.

http://engineeringbooks.net

CHAPTER 6. FORMAL LANGUAGE THEORY

6.4

109

Regular Languages

We now consider the class of regular languages. Well show that these are
precisely those that can be accepted by an FSA and which can be generated
by a right-linear grammar.
The regular languages are defined as follows.
Definition 13 (Regular Language) Given a finite alphabet :
1. is a regular language.
2. For any string x , {x} is a regular language.
3. If A and B are regular languages, then so is A B.
4. If A and B are regular languages, then so is AB.
5. If A is a regular language, then so is A .
6. Nothing else is a regular language.
Consider each of these operations in turn. First, we have that any string
of symbols from the alphabet can be a specification of a language. Thus, if
the alphabet is = {a, b, c}, then the regular language L can be {a}.6
If L1 = {a} and L2 = {b}, then we can define the regular language which
is the union of L1 and L2 : L3 = L1 L2 , i.e. L3 = {a, b}. In string terms,
this is usually written L3 = (a|b).
We can also concatenate two regular languages, e.g. L3 = L1 L2 , e.g.
L3 = {ab}.
Finally, we have Kleene star, which allows us to repeat some regular
language zero or more times. Thus, if L1 is a regular language, then L2 = L1
is a regular language, e.g. L2 = {a, aa, aaa, . . .}. In string terms: L2 = a .
These operations can, of course, be applied recursively in any order.7 For
example, a(b |c)a refers to the language where all strings are composed of
a single instance of a followed by any number of instances of b or a single c,
followed in turn by any number of instances of a.
We can go in the other direction as well. For example, how might we
describe the language where all strings contain an even number of instances
of a plus any number of the other symbols: ((b|c) a(b|c) a(b|c) ) .
6

Notice that it would work just as well to start form any symbol a here, since we
have recursive concatenation below.
7
In complex examples, we can use parentheses to indicate scope.

CHAPTER 6. FORMAL LANGUAGE THEORY

6.4.1

110

Automata and Regular Languages

It turns out that the set of languages that can be accepted by a finite state
automaton is exactly the regular languages.
Theorem 2 A set of strings is a finite automaton language if and only if it
is a regular language.
We wont prove this rigorously, but we can see the logic of the proof fairly
straightforwardly. There are really only four things that we can do with
a finite automaton, and each of these four correspond to one of the basic
clauses of the definition of a regular language.
First, we have that a single symbol is a legal regular language because we
can have a finite automaton with a start state, a single arc, and a final state.
a

(6.28)

q1

q0

Second, we have concatenation of two regular languages by taking two


automata and connecting them with an arc labeled with .
...

...

FSA 1

FSA 2

(6.29)
We connect all final states of the first automaton with the start state of the
second automaton with -arcs. The final states of the first automaton are
made non-final. The start state of the second automaton is made a non-start
state.
Union is straightforward as well. We simply create a new start state
and then create arcs from that state to the former start states of the two
automata labeled with . We create a new final state as well, with -arcs
from the former final states of the two automata.

FSA 1

q1

q0

FSA 2

(6.30)

CHAPTER 6. FORMAL LANGUAGE THEORY

111

Finally, we can get Kleene star by creating a new start state (which is
also a final state), a new final state, and an -loop between them.

q0

q1

FSA 1

(6.31)

If we can construct an automaton for every step in the construction of a


regular language, it should follow that any regular language can be accepted
by some automaton.8

6.4.2

Right-linear Grammars and Automata

Another equivalence that is of use is that between the regular languages and
right-linear grammars. Right-linear grammars generate precisely the set of
regular languages.
We can show this by pairing the rules of a right-linear grammar with the
arcs of an automaton. First, for every rewrite rule of the form A x B, we
have an arc from state A to state B labeled x. For every rewrite rule of the
form A x, we have an arc from state A to the designated final state, call
it F .
Consider this very simple example of a right-linear grammar.
(6.32) a.
b.
c.
d.

S
A
A
B

aA
aA
aB
b

This generates the language where all strings are composed of two or more
instances of a, followed by exactly one b.
If we follow the construction of the FSA above, we get this:
a
a

(6.33) S
8

a
A

A rigorous proof would require that we go through this in the other direction as well,
from automaton to regular language.

CHAPTER 6. FORMAL LANGUAGE THEORY

112

This FSA accepts the same language generated by the right-linear grammar
in (6.32).
Notice now that if FSAs and right-linear grammars generate the same
set of languages and FSAs generate regular languages, then it follows that
right-linear grammars generate regular languages. Thus we have a three-way
equivalence between regular languages, right-linear grammars, and FSAs.

6.4.3

Closure Properties

Lets now turn to closure properties of the regular languages. By the definition of regular language, it follows that they are closed under the properties
that define them: concatenation, union, Kleene star. They are also closed
under complement. The complement of some regular language L defined over
the alphabet is L = L.
Its rather easy to show this using DFAs. In particular, to construct the
complement of some language L, we create the DFA that generates that
language and then swap the final and non-final states.
Lets consider the DFA in (6.16) on page 102 above. This generates the
language a ba (ba ba ) , where every legal string contains an odd number of
instances of the symbol b, and any number of instances of the symbol a. We
now reverse the final and non-final states so that q0 is both the start state
and the final state.
a

a
b

q0

(6.34)

q1

This now generates the complement language: a (ba ba ) . Every legal string
has an even number of instances of b (including zero), and any number of
instances of a.
With complement so defined, and DeMorgans Law (the set-theoretic version), it follows that the regular languages are closed under intersection as
well. Recall the following equivalences from chapter 3.
(6.35) (X Y ) = X Y
(X Y ) = X Y

113

CHAPTER 6. FORMAL LANGUAGE THEORY

Therefore, since the regular languages are closed under union and under
complement, it follows that they are closed under intersection. Thus if we
want to intersect the languages L1 and L2 , we union their complements, i.e.
L1 L2 = (L1 L2 ) .

6.5

Context-free Languages

In this section, we treat the context-free languages, generated with rules of


the form A , where A is a non-terminal and is a string of terminals
and non-terminals.
From the definition of right-linear grammars and context-free grammars,
it follows that any language that can be described in terms of a right-linear
grammar can be described in terms of a context-free grammar. This is true
trivially since any right-linear grammar is definitionally also a context-free
grammar.
What about in the other direction though? There are languages that can
be described in terms of context-free grammars that cannot be described in
terms of right-linear grammars. Consider, for example, the language an bn :
{, ab, aabb, aaabbb, . . .}. It can be generated by a context-free grammar, but
not by a right-linear grammar. Here is a simple context-free grammar for
this language:
(6.36) S a S b
S
Here are some sample trees produced by this grammar.
(6.37)

S
a

S
b

S
a

b
b

Another language type that cannot be treated with a right-linear grammar is xxR where a string x is followed by its mirror-image xR , including

You might also like