Logics in Computer Science (Cosc3141)
Logics in Computer Science (Cosc3141)
CHAPTER ONE
INTRODUCTION
1.1. Introduction
The aim of logic in computer science is to develop languages to model the situations we
encounter as computer science professionals, in such a way that we can reason about them
formally. Reasoning about situations means constructing arguments about them; we want to do
this formally, so that the arguments are valid and can be defended rigorously, or executed on a
machine.
Computer Science has utilized many subfields of Logic in areas such as program verification,
semantics of programming languages, automated theorem proving, and logic
programming. From the very beginning, education in Computer Science supports the idea of
strict separation between syntax and semantics (of programming languages). Also, recursive
definitions, equations and programs are a familiar thing to a Computer Science student.
Propositional logic is central to the design of computer hardware because hardware is usually
designed with components having two voltage levels that are arbitrarily assigned the symbols 0
and 1. Circuits are described by idealized elements called logic gates; for example, an and-gate
produces the voltage level associated with 1 if and only if both its input terminals are held at this
same voltage level.
Propositional logic is widely used in software, too. The reason is that any program is a finite
entity. Mathematicians may consider the natural numbers to be infinite (0, 1, 2, ...), but a word of
a computer’s memory can only store numbers in a finite range. By using an atomic proposition
for each bit of a program’s state, the meaning of a computation can be expressed as a (very large)
formula. Algorithms have been developed to study properties of computations by evaluating
properties of formulas in propositional logic.
1.2. Statements/Propositions
In order to make arguments difficult, we need to develop a language in which we can express
sentences in such a way that brings out their logical structure. The language we begin with is the
language of propositional logic. It is based on propositions, or declarative sentences which one
can, in principle, argue as being true or false.
A sentence which can be said to be true or false (but not both) is said to be a proposition (or
statement). The words True and False, denoted by T and F respectively, are called truth values.
Consider the following examples:
a. Four is less than Ten.
b. Addis Ababa is the capital of Ethiopia.
c. He is very talented.
d. There are life forms on other planets in the universe.
Sentence (a) is a statement because it is True. Sentence (b) is a statement because it is true.
Sentence (c) is neither true nor false because “he” is not specified; therefore (c) is not a
statement. Sentence (d) is a statement because it is either true or false; we do not have to be able
to decide which.
Propositional logic explores simple grammatical connections, like and, or and not, between the
simplest "atomic/indecomposable propositions". In English, simple statements are combined with
connecting words like ‘and’ to make more interesting compound statements. The truth value of a
compound statement depends on the truth values of its components and which connecting words are
used. If we combine the two true statements, “Elephants are big,” and, “Baseballs are round,” we
would consider the resulting statement, “Elephants are big and baseballs are round,” to be true.
Given two or more propositions, you can use connectives to join the sentences to form compound
statement. The fundamental connectives in logic are: not, or, and, if ... then, and if and only if.
To find the truth-value of a statement which is combined by using connectives, you need rules which
give the truth value of the compound statement. You also need symbols for connectives and notations
for propositions. You usually represent propositions by small letters such as p, q, r, s, t, and so on.
Now, let p and q are two different propositions.
We assign certain distinct symbols p, q, r, or sometimes p1, p2, p3, to each of these atomic sentences
and we can then code up more complex sentences in a compositional way. For example, given the
atomic sentences:
p:‘I won the lottery last week.’
q:‘I purchased a lottery ticket.’
r:‘I won last week’s sweepstakes.’
a) ¬ p represents: I did not win the lottery last week,’ or equivalently It is not true that I won
the lottery last week.
b) p ∧r represents: Last week I won the lottery and the sweepstakes.
c) p ∨q represents: I won the lottery last week, or I purchased a lottery ticket.
d) p → q represents: If I won the lottery last week, then I purchased a lottery ticket.
e) p ↔ q represents: I won the lottery last week if and only if I purchased a lottery ticket.
Now we will see to the rules that govern us in communicating through logic by using truth tables for
each of the logical operators.
Negation is a unary connective, it is applied to a single statement and does not connect two
statements.
Let p be a proposition.
When two propositions p and q are joined with the connective "or"(denoted by p ∨q), the
proposition formed is a logical disjunction. p and q are called the disjuncts of the expression. p
∨ q is false, if and only if both p and q are false.
To determine the truth value of p ∨q, we have to know the truth value of the components p and q.
As mentioned earlier, if we have two propositions to be combined, there are four possibilities of
combinations of the truth values of component propositions.
The truth table for disjunction is given as follows.
p q p ∨q
T T T
T F T
F T T
F F F
When two propositions p and q are joined with the connective "implies"(denoted by p → q) the
proposition formed is a logical implication. It conveys the meaning that the truth of p implies or
leads to the truth of q. In the implication p → q, p stands for the antecedent statement and q stands
for the consequent statement.
p → q is false, if and only if p is true and q is false.
p q p→q
T T T
T F F
F T T
F F T
To understand its definition, let’s suppose your friend remarks, “If I pass my economics test,
then I’ll go to the movie Friday.” If your friend passes the test and goes to the movie, the remark
was true. If your friend passes the test but doesn’t go to the movie, the remark was false. If your
friend doesn’t pass the test, then whether he or she goes to the movie or not, you could not claim
that the remark was false. You would probably want to give the benefit of the doubt and say that
the statement was true. By convention p → q is considered true if p is false, regardless of the
truth value of q.
When two propositions p and q are joined with the connective "bi-implication" (denoted by p ↔
q) the proposition formed is a logical bi-implication. Unlike conjunction, disjunction, and
implication, the bi-implication connective is not really a fundamental connective but a
convenient shortcut. The expression p ↔ q stands for (p → q) ∧ (q → p).
p ↔ q is false, if and only if p and q have different truth values.
The truth table for bi–implication is given as follows.
p q p↔q
T T T
T F F
F T F
F F T
The following table summarizes the truth values for all of the above logical connectives. This
information is critical to an understanding of logical reasoning.
Because of the richness of the English language, words that have different shades of meaning are
however represented by the same logical connective. The following table shows the common
English words associated with various logical connectives.
p is necessary and
sufficient for q.
not p Negation ¬p
It is false that p ...
It is not true that p ...
Suppose that p → q is true. Then, according to the truth table for implication, the consequent, q,
can be true even though the antecedent, p, is false. So while the truth of p leads to (implies) the
truth of q, the truth of q does not imply the truth of p. The phrase “q is a necessary condition for
p” to describe p → q simply means that if p is true, then q is necessarily true, as well. “p only if
q” describes the same thing, that p implies q.
For example:
The statement, “Fire is a necessary condition for smoke,” can be restated, “If there is smoke, then
there is fire.” The antecedent is “there is smoke,” and the consequent is “there is fire.”
Exercise!
Name the antecedent and consequent in each of the following statements. (Hint: Rewrite each
statement in if-then form.)
a. If the rain continues, then the river will flood.
b. A sufficient condition for network failure is that the central switch goes down.
c. The avocados are ripe only if they are dark and soft.
d. A good diet is a necessary condition for a healthy cat.
Expressing the negation of a statement must be done with care, especially for a compound
statement. The following table gives some examples.
So far, you have defined statements and logical connectives (or logical operators) and you have
seen the rules that go with the logical connectives. Now you are going to give a name for
statements formed from two or more component propositions by using logical operators. A
statement formed by joining two or more statements by a connective (or connectives) is called a
compound statement.
For example:
(¬ p ∨q) ∧ (q → p)
The truth table for the above compound statement is the following.
p q ¬p ¬p∨q q→p (¬ p ∨ q) ∧ (q → p)
T T F T T T
T F F F T F
F T T T F F
F F T T T T
Some compound propositions have the same truth values for each assignment of the truth values
of component propositions. Such pairs of compound propositions are called equivalent
propositions. We use the symbol “≡” in-between the two propositions to mean they are
equivalent.
For the logical connectives discussed so far, the following properties hold true.