CH # 1 (Logic and Proofs)
CH # 1 (Logic and Proofs)
Chapter # 1
Logic and Proofs
By:
Muhammad Imran
Assistant Prof. of Computer Science
Govt. Millat Graduate College Mumtazabad, Multan
3. What is the shortest path between two cities using transportation system?
4. How can I encrypt a message so that no unintended recipient can read it?
6. How can a list of integers be sorted so that the integers are in increasing
order.
Propositional Logic
Propositional Equivalnces
Conditional Statements
Logical Equivalences
Propositional Logic
A proposition is a declarative sentence (that is, a sentence that declares a fact) that is
either true or false, but not both.
More Examples:
3. X+4>9
This is not a proposition because it is true for certain values of x and false for certain values of x
This is not a proposition because truth or falsity of this proposition depends on the reference of
pronoun she. This can be converted into proposition by the following way:
Notations
We use letters to denote propositional variables (or statement variables), that is,
variables that represent propositions, just as letters are used to denote numerical
variables. The conventional letters used for propositional variables are p, q, r, s, . . . . The
truth value of a proposition is true, denoted by T or 1, if it is a true proposition, and the
truth value of a proposition is false, denoted by F or 0, if it is a false proposition.
The area of logic that deals with propositions is called the propositional calculus or
propositional logic. It was first developed systematically by the Greek philosopher
Aristotle more than 2300 years ago. Many mathematical statements are constructed by
combining one or more propositions. New propositions, called compound propositions,
are formed from existing propositions using logical operators.
Compound Propositions:
Not or Negation of a Proposition
Let p be a proposition. The negation of p, denoted by¬p (also denoted by p), is the statement
―It is not the case that p.‖ The proposition ¬p is read ―not p.‖ The truth value of the negation of p, ¬p, is the
opposite of the truth value of p.
Examples:
the truth table for the negation of a proposition p. This table has a row for each of
the two possible truth values of a proposition p. Each row shows the truth value of
¬p corresponding to the truth value of p for this row.
The negation of a proposition can also be considered the result of the operation of
the negation operator on a proposition. The negation operator constructs a new
proposition from a single existing proposition.We will now introduce the logical
operators that are used to form new propositions from two or more existing
propositions. These logical operators are also called
connectives.
Conjunction (AND):
Let p and q be propositions. The conjunction of p and q, denoted by p ∧ q, is the proposition
―p and q.‖ The conjunction p ∧ q is true when both p and q are true and is false otherwise.
Examples:
2. Find the conjunction of the propositions p and q where p is the proposition ―Rebecca‘s PC has
more than 16 GB free hard disk space‖ and q is the proposition ―The processor in Rebecca‘s
PC runs faster than 1 GHz.‖
Solution: The conjunction of these propositions, p ∧ q, is the proposition ―Rebecca‘s PC has
more than 16 GB free hard disk space, and the processor in Rebecca‘s PC runs faster than 1
GHz.‖ This conjunction can be expressed more simply as ―Rebecca‘s PC has more than 16 GB
free hard disk space, and its processor runs faster than 1 GHz.‖ For this conjunction to be true,
both conditions given must be true. It is false, when one or both of these conditions are false.
Disjunction (OR)
Let p and q be propositions. The disjunction of p and q, denoted by p ∨ q, is the proposition
―p or q.‖ The disjunction p ∨ q is false when both p and q are false and is true otherwise.
Truth Table of OR
Exclusive OR
Let p and q be propositions. The exclusive or of p and q, denoted by p ⊕ q, is the proposition
that is true when exactly one of p and q is true and is false otherwise.
Example:
The use of the connective or in a disjunction corresponds to one of the two ways the word
or is used in English, namely, as an inclusive or. A disjunction is true when at least one of
the two propositions is true. For instance, the inclusive or is being used in the statement
―Students who have taken calculus or computer science can take this class.‖
Here, we mean that students who have taken both calculus and computer science can take the
class, as well as the students who have taken only one of the two subjects. On the other hand,
we are using the exclusive or when we say ―Students who have taken calculus or computer
science, but not both, can enroll in this class.‖
Here, we mean that students who have taken both calculus and a computer science course
cannot take the class. Only those who have taken exactly one of the two courses can take the
class. Similarly, when a menu at a restaurant states, ―Soup or salad comes with an entrée,‖
the restaurant almost always means that customers can have either soup or salad, but not
both.
Hence, this is an exclusive, rather than an inclusive, or.
Let p and q be propositions. The conditional statement p → q is the proposition ―if p, then
q.‖ The conditional statement p → q is false when p is true and q is false, and true otherwise.
In the conditional statement p → q, p is called the hypothesis (or antecedent or premise)
and q is called the conclusion (or consequence).
Because conditional statements play such an essential role in mathematical reasoning, a
variety of terminology is used to express p → q. You will encounter most if not all of the
following ways to express this conditional statement:
―if p, then q‖ ―p implies q‖
―if p, q‖ ―p only if q‖
―p is sufficient for q‖ ―a sufficient condition for q is p‖
―q if p‖ ―q whenever p‖
―q when p‖ ―q is necessary for p‖
―a necessary condition for p is q‖ ―q follows from p‖
Example 1:
If the politician is elected, voters would expect this politician to lower taxes. Furthermore, if the
politician is not elected, then voters will not have any expectation that this person will lower
taxes, although the person may have sufficient influence to cause those in power to lower taxes.
It is only when the politician is elected but does not lower taxes that voters can say that the
politician has broken the campaign pledge. This last scenario corresponds to the case when p
is true but q is false in p → q.
Example 2
Let p be the statement ―Maria learns discrete mathematics‖ and q the statement ―Maria will
find a good job.‖ Express the statement p → q as a statement in English.
Solution: From the definition of conditional statements, we see that when p is the statement
―Maria learns discrete mathematics‖ and q is the statement ―Maria will find a good job,‖ p → q
represents the statement
―If Maria learns discrete mathematics, then she will find a good job.‖
There are many other ways to express this conditional statement in English. Among the most
natural of these are:
―Maria will find a good job when she learns discrete mathematics.‖
―For Maria to get a good job, it is sufficient for her to learn discrete mathematics.‖
and
―Maria will find a good job unless she does not learn discrete mathematics.‖
Note that the way we have defined conditional statements is more general than the meaning
attached to such statements in the English language. For instance, the conditional statement in
Example 7 and the statement
―If it is sunny, then we will go to the beach.‖
are statements used in normal language where there is a relationship between the hypothesis
and the conclusion. Further, the first of these statements is true unless Maria learns discrete
mathematics, but she does not get a good job, and the second is true unless it is indeed sunny,
but we do not go to the beach. On the other hand, the statement ―If Juan has a smartphone, then 2 + 3 = 5‖
is true from the definition of a conditional statement, because its conclusion is true. (The truth
value of the hypothesis does not matter then.) The conditional statement
―If Juan has a smartphone, then 2 + 3 = 6‖
is true if Juan does not have a smartphone, even though 2 + 3 = 6 is false. We would not use
these last two conditional statements in natural language (except perhaps in sarcasm), because
there is no relationship between the hypothesis and the conclusion in either statement. In mathematical
reasoning, we consider conditional statements of a more general sort than we use in
English. The mathematical concept of a conditional statement is independent of a cause-andeffect
relationship between hypothesis and conclusion. Our definition of a conditional statement
specifies its truth values; it is not based on English usage. Propositional language is an artificial
language; we only parallel English usage to make it easy to use and remember.
The if-then construction used in many programming languages is different from that used
in logic. Most programming languages contain statements such as if p then S, where p is a
proposition and S is a program segment (one or more statements to be executed).When execution
of a program encounters such a statement, S is executed if p is true, but S is not executed if p
is false, as illustrated in Example 3.
The truth table for p ↔ q is shown in the following table. Note that the statement p ↔ q is true when both
the conditional statements p → q and q → p are true and is false otherwise. That is why we use the words ―if
and only if‖ to express this logical connective and why it is symbolically written by combining the
symbols→and←. There are some other common ways to express p ↔ q:
―p is necessary and sufficient for q‖
―if p then q, and conversely‖
―p iff q.‖
The last way of expressing the biconditional statement p ↔ q uses the abbreviation ―iff‖ for
―if and only if.‖ Note that p ↔ q has exactly the same truth value as (p → q) ∧ (q → p).
EXAMPLE: Let p be the statement ―You can take the flight,‖ and let q be the statement ―You buy a ticket.‖
Then p ↔ q is the statement
―You can take the flight if and only if you buy a ticket.‖
This statement is true if p and q are either both true or both false, that is, if you buy a ticket and
can take the flight or if you do not buy a ticket and you cannot take the flight. It is false when
p and q have opposite truth values, that is, when you do not buy a ticket, but you can take the
flight (such as when you get a free trip) and when you buy a ticket but you cannot take the flight
(such as when the airline bumps you).
the converse, q → p, nor the inverse, ¬p →¬q, has the same truth value as p → q for all
possible truth values of p and q. Note that when p is true and q is false, the original conditional
statement is false, but the converse and the inverse are both true.
When two compound propositions always have the same truth value we call them equivalent,
so that a conditional statement and its contrapositive are equivalent. The converse and
the inverse of a conditional statement are also equivalent, as the reader can verify, but neither is
equivalent to the original conditional statement. (We will study equivalent propositions in Section
1.3.) Take note that one of the most common logical errors is to assume that the converse
or the inverse of a conditional statement is equivalent to this conditional statement.
We illustrate the use of conditional statements in the following example
EXAMPLE 9 What are the contrapositive, the converse, and the inverse of the conditional statement
―The home team wins whenever it is raining?‖
Solution: Because ―q whenever p‖ is one of the ways to express the conditional statement
p → q, the original statement can be rewritten as
―If it is raining, then the home team wins.‖
Consequently, the contrapositive of this conditional statement is
―If the home team does not win, then it is not raining.‖
The converse is
―If the home team wins, then it is raining.‖
The inverse is
―If it is not raining, then the home team does not win.‖
Only the contrapositive is equivalent to the original statement.
Finally, it is an accepted rule that the conditional and biconditional operators → and ↔
have lower precedence than the conjunction and disjunction operators, ∧ and ∨. Consequently,
p ∨ q → r is the same as (p ∨ q) → r. We will use parentheses when the order of the conditional
operator and biconditional operator is at issue, although the conditional operator has
precedence over the biconditional operator. Table 8 displays the precedence levels of the logical
operators, ¬, ∧, ∨,→, and↔.
Computer bit operations correspond to the logical connectives. By replacing true by a one
and false by a zero in the truth tables for the operators ∧, ∨, and ⊕, the tables shown in Table 9
for the corresponding bit operations are obtained.We will also use the notation OR, AND, and
XOR for the operators ∨,∧, and ⊕, as is done in various programming languages.
Bit String
A bit string is a sequence of zero or more bits. The length of this string is the number of bits in the string.
EXAMPLE: 101010011 is a bit string of length nine.
Solution: The bitwise OR, bitwise AND, and bitwise XOR of these strings are obtained by taking
the OR, AND, and XOR of the corresponding bits, respectively. This gives us
01 1011 0110
11 0001 1101
-----------------
11 1011 1111 bitwise OR
01 0001 0100 bitwise AND
10 1010 1011 bitwise XOR
Assignment No. 1
Logic has many important applications to mathematics, computer science, and numerous other
disciplines. Statements in mathematics and the sciences and in natural language often are imprecise
or ambiguous. To make such statements precise, they can be translated into the language
of logic. For example, logic is used in the specification of software and hardware, because these
specifications need to be precise before development begins. Furthermore, propositional logic
and its rules can be used to design computer circuits, to construct computer programs, to verify
the correctness of programs, and to build expert systems. Logic can be used to analyze and
solve many familiar puzzles. Software systems based on the rules of logic have been developed
for constructing some, but not all, types of proofs automatically.We will discuss some of these
applications of propositional logic in this section.
A compound proposition that is always true, no matter what the truth values of the propositional variables that
occur in it, is called a tautology. A compound proposition that is always false is called a contradiction. A
compound proposition that is neither a tautology nor a contradiction is called a contingency.
Prepared By: Muhammad Imran
Assistant Prof. of Computer Science, Govt. Millat Degree College, Multan.
18 DISCRETE STRUCTURES
We can construct examples of tautologies and contradictions using just one propositional variable.
Example: Consider the truth tables of p ∨¬p and p ∧¬p, shown in Table 1. Because p ∨¬p is always true, it
is a tautology. Because p ∧¬p is always false, it is a contradiction.
Logical Equivalences
Remark: The symbol ≡ is not a logical connective, and p ≡ q is not a compound proposition
but rather is the statement that p ↔ q is a tautology. The symbol⇔is sometimes used instead
of ≡ to denote logical equivalence.
EXAMPLE 4: Show that p ∨ (q ∧ r) and (p ∨ q) ∧ (p ∨ r) are logically equivalent. This is the distributive
law of disjunction over conjunction.
Laws of Logic
We also display some useful equivalences for compound propositions involving conditional
statements and biconditional statements in Tables 7 and 8, respectively.
Solution:
The logical equivalences in Table 6, as well as any others that have been established (such as
those shown in Tables 7 and 8), can be used to construct additional logical equivalences. The
reason for this is that a proposition in a compound proposition can be replaced by a compound
proposition that is logically equivalent to it without changing the truth value of the original
compound proposition.
Example : Show that ¬(p ∨ (¬p ∧ q)) and ¬p ∧¬q are logically equivalent by developing a series of
logical equivalences.
Solution:We will use one of the equivalences in Table 6 at a time, starting with¬(p ∨ (¬p ∧ q))
and ending with ¬p ∧¬q. (Note: we could also easily establish this equivalence using a truth
table.)We have the following equivalences.
Example:
Answer:
Do yourself
Question: Construct a combinatorial circuit using inverters, OR gates, and AND gates that
produces the output (p ∧¬r) ∨ (¬q ∧ r) from input bits p, q, and r.
Solution:
Question: Construct a combinatorial circuit using inverters, OR gates, and AND gates that produces the output
((¬p ∨¬r)∧¬q) ∨ (¬p ∧ (q ∨ r)) from input bits p, q, and r.
Solution:
Equivalent Circuits
In the above example we have constructed the circuit from boolean expression. We have
already seen that we can simplify the boolean expression by using different laws of logic.
E.g Identity Law, Idempotent law etc.
So in the above example both the truth tables will be same. Hence if truth tables are same
the both circuits will also be equivalent after simplification.
Example
To show that both the circuits are equivalent we can use truth table or laws of logic.
Now we will use laws of logic to show that both are equivalent.
whereMATH3 is one of the computers connected to the university network. Likewise, we cannot
use the rules of propositional logic to conclude from the statement
In this section we will introduce a more powerful type of logic called predicate logic. We will
see how predicate logic can be used to express the meaning of a wide range of statements in
mathematics and computer science in ways that permit us to reason and explore relationships
between objects. To understand predicate logic, we first need to introduce the concept of a
predicate. Afterward, we will introduce the notion of quantifiers, which enable us to reason with
statements that assert that a certain property holds for all objects of a certain type and with
statements that assert the existence of an object with a particular property.
Predicates
Statements involving variables, such as
―x > 3,‖ ―x = y + 3,‖ ―x + y = z,‖
and
―computer x is under attack by an intruder,‖
and
―computer x is functioning properly,‖
The statement ―x is greater than 3‖ has two parts. The first part, the variable x, is the subject
of the statement. The second part—the predicate(property of a subject or Expression that
contains variables), ―is greater than 3‖—refers to a property that
the subject of the statement can have. We can denote the statement ―x is greater than 3‖ by P(x),
where P denotes the predicate ―is greater than 3‖ and x is the variable. The statement P(x) is
also said to be the value of the propositional function P at x. Once a value has been assigned
to the variable x, the statement P(x) becomes a proposition and has a truth value. Consider
Examples 1 and 2. A Predicate P(x) is a sentence that contains a finite number of variables
and becomes a proposition when specific values are substituted for the variable
We can also have statements that involve more than one variable. For instance, consider the
statement ―x = y + 3.‖ We can denote this statement by Q(x, y), where x and y are variables
and Q is the predicate. When values are assigned to the variables x and y, the statement Q(x, y)
has a truth value.
Similarly,we can letR(x, y, z) denote the statement`‗x + y = z.‖When values are assigned
to the variables x, y, and z, this statement has a truth value.
Quantifiers
Quantifiers are the words that refer to quantities such as all, some, many, none, and few
are used in quantifications. When the variables in a propositional function are assigned
values, the resulting statement becomes a proposition with a certain truth value.
However, there is another important way, called quantification, to create a proposition
from a propositional function. Quantification expresses the extent to which a predicate is
true over a range of elements. We will focus on two types of quantification here:
universal quantification, which tells us that a predicate is true for every element under
consideration, and existential quantification.
Example:
―All students are hardworking‖
Let P(x) denote ―X is hardworking‖
Then the above statement can be written as:
∀xP(x)
Example1: Let P(x) be the statement ―x + 1 > x.‖ What is the truth value of the
quantification ∀xP(x),
where the domain consists of all real numbers?
Example 2 : Let Q(x) be the statement ―x < 2.‖ What is the truth value of the
quantification ∀xQ(x), where the domain consists of all real numbers?
Solution: Q(x) is not true for every real number x, because, for instance, Q(3) is false.
That is,x = 3 is a counterexample for the statement ∀xQ(x). Thus
∀xQ(x)
is false.
Example 3: Suppose that P(x) is ―x2 > 0.‖ To show that the statement ∀xP(x) is false
where the universe of discourse consists of all integers, we give a counterexample. We
see that x = 0 is a counterexample because x2 = 0 when x = 0, so that x2 is not greater than
0 when x = 0.
Example 4: What is the truth value of ∀xP(x), where P(x) is the statement ―x2 < 10‖ and
the domain consists of the positive integers not exceeding 4?
Solution: The statement ∀xP(x) is the same as the conjunction
P(1) ∧ P(2) ∧ P(3) ∧ P(4),
because the domain consists of the integers 1, 2, 3, and 4. Because P(4), which is the
statement
―42 < 10,‖ is false, it follows that ∀xP(x) is false.
A domain must always be specified when a statement ∃xP(x) is used. Furthermore, the
meaning of ∃xP(x) changes when the domain changes. Without specifying the domain,
the statement ∃xP(x) has no meaning.
Besides the phrase “there exists,” we can also express existential quantification in many
other ways, such as by using the words “for some,” “for at least one,” or “there is.”
The existential quantification ∃xP(x) is read as:
―There is an x such that P(x),‖
―There is at least one x such that P(x),‖
or
―For some xP(x).‖
Example 1: Let P(x) denote the statement ―x > 3.‖ What is the truth value of the
quantification ∃xP(x),
where the domain consists of all real numbers?
Solution: Because ―x > 3‖ is sometimes true—for instance, when x = 4—the existential
quantification of P(x), which is ∃xP(x), is true.
Observe that the statement ∃xP(x) is false if and only if there is no element x in the
domain for which P(x) is true.
Example 2: Let Q(x) denote the statement ―x = x + 1.‖What is the truth value of the
quantification ∃xQ(x), where the domain consists of all real numbers?
Solution: Because Q(x) is false for every real number x, the existential quantification of
Q(x), which is ∃xQ(x), is false.
Example 3: What is the truth value of ∃xP(x), where P(x) is the statement ―x2 > 10‖ and
the universe of
discourse consists of the positive integers not exceeding 4?
Solution: Because the domain is {1, 2, 3, 4}, the proposition ∃xP(x) is the same as the
disjunction
P(1) ∨ P(2) ∨ P(3) ∨ P(4).
Because P(4), which is the statement ―42 > 10,‖ is true, it follows that ∃xP(x) is true.
element x in the domain for which P(x) is false. This holds if and only if there is an
element x in the domain for which ¬P(x) is true.
Finally, note that there is an element x in the domain for which ¬P(x) is true if and only
if ∃x ¬P(x) is true. Putting these steps together, we can conclude that ¬∀xP(x) is true if
and only if ∃x ¬P(x) is true. It follows that ¬∀xP(x) and ∃x ¬P(x) are logically
equivalent.
Suppose we wish to negate an existential quantification. For instance, consider the
proposition
―There is a student in this class who has taken a course in calculus.‖ This is the existential
Quantification
∃xQ(x),
where Q(x) is the statement ―x has taken a course in calculus.‖ The negation of this
statement
is the proposition ―It is not the case that there is a student in this class who has taken a
course in calculus.‖ This is equivalent to ―Every student in this class has not taken
calculus,‖ which is just the universal quantification of the negation of the original
propositional function, or, phrased in the language of quantifiers,
∀x ¬Q(x).
This example illustrates the equivalence
¬∃xQ(x) ≡ ∀x ¬Q(x).
Example: What are the negations of the statements ∀x(x2 > x) and ∃x(x2 = 2)?
Solution: The negation of ∀x(x2 > x) is the statement ¬∀x(x2 > x), which is equivalent
to ∃x¬(x2 > x). This can be rewritten as ∃x(x2 ≤ x). The negation of ∃x(x2 = 2) is the
statement ¬∃x(x2 = 2), which is equivalent to ∀x¬(x2 = 2). This can be rewritten as
∀x(x2 _= 2). The truth values of these statements depend on the domain.
We can always use a truth table to show that an argument form is valid.We do this by
showing that whenever the premises are true, the conclusion must also be true. However,
this can be a tedious approach. For example, when an argument form involves 10
different propositional variables, to use a truth table to show this argument form is valid
requires 210 = 1024 different rows. Fortunately, we do not have to resort to truth tables.
Prepared By: Muhammad Imran
Assistant Prof. of Computer Science, Govt. Millat Degree College, Multan.
45 DISCRETE STRUCTURES
Instead, we can first establish the validity of some relatively simple argument forms,
called rules of inference. These rules of inference can be used as building blocks to
construct more complicated valid argument forms.
We will now introduce the most important rules of inference in propositional logic.
Argument
An argument is a sequence of statements. All the statements are called
Premises or assumptions or hypothesis. The final statement is called conclusion. The
symbol read as therefore and is normally placed just before the conclusion.
Valid Arguments
Example
Invalid Arguments