0% found this document useful (0 votes)
87 views

Discrete Structures For Computing

This document provides an overview of propositional and predicate logic concepts. It defines tautologies, contradictions and contingencies using truth tables. Logical equivalences are shown to have the same truth values across all cases. Predicates and quantifiers are introduced to express concepts involving variables and properties. Universal and existential quantifiers are used to specify properties across all or some values in a domain. Logical equivalences can be proven by showing equal truth values regardless of the specific predicates or domains used.

Uploaded by

xhienye
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views

Discrete Structures For Computing

This document provides an overview of propositional and predicate logic concepts. It defines tautologies, contradictions and contingencies using truth tables. Logical equivalences are shown to have the same truth values across all cases. Predicates and quantifiers are introduced to express concepts involving variables and properties. Universal and existential quantifiers are used to specify properties across all or some values in a domain. Logical equivalences can be proven by showing equal truth values regardless of the specific predicates or domains used.

Uploaded by

xhienye
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

DMATH RESEARCH – PAGE 1

Discrete Structures for Computing


Notes 2

------------------------------------------------------------------------
1.2 Propositional Equivalences
------------------------------------------------------------------------

TAUTOLOGY: a proposition that is always true, no matter what truth


values are assigned to the component propositions.

Ex: p \/ ~p

Truth table:
p ~p p \/ ~p
----------------
T F T
F T T

CONTRADICTION: a proposition that is always false, no matter what truth


values are assigned to the component propositions.

Ex: p /\ ~p

Truth table:
p ~p p /\ ~p
----------------
T F F
F T F

CONTINGENCY: a proposition that is neither a tautology nor a contradiction.

Ex: p /\ p

Truth table:
p p /\ p
----------
T T
F F

LOGICALLY EQUIVALENT: the two propositions have the same truth value
in all possible cases.

Another way to say this is that p <-> q is a tautology (i.e.,


"p iff q" is always true).

Notation: p <=> q (or, an equals sign with three horizontal strokes).

How can you tell if two propositions are logically equivalent?

One way is to use a truth table:

Ex: Show that ~(p \/ q) <=> ~p /\ ~q (i.e., ~(p \/ q) and ~p /\ ~q


are logically equivalent, or have the same truth value no matter
what truth values are assigned to p and q.

p q p \/ q ~(p \/ q) ~p ~q ~p /\ ~q
--------------------------------------------------
T T T F F F F
T F T F F T F
F T T F T F F
F F F T T T T

Notice that the two relevant columns have the same values in them.

There is an analogous logical equivalence:


~(p /\ q) <=> ~p \/ ~q.
It can be verified in a similar way.

These two are called DEMORGAN'S LAWS.

Here's another example: show that (p -> q) <=> (~p \/ q) using


a truth table.

<<work it out>>

*** Study Tables 6, 7 and 8 on pp. 24-25: contain a number of logical


DMATH RESEARCH – PAGE 2

equivalences (such as commutativity, associativity) that can be proved


using truth tables.

The drawback of using the truth table approach is that you


need 2^n rows, where n is the number of variables. (Remember
example from last time). Doesn't scale well. For example, if you
have 1000 variables, then truth table has 2^1000 rows, which is more
than 10^300, and it will take even the fastest known computer trillions
of years.

For instance, how would you prove a generalized version of


DeMorgan's laws, which states that for any n,

~(p_1 \/ p_2 \/ ... \/ p_n) <=> (~p_1 /\ ~p_2 /\ ... /\ ~p_n) ?

We'll see techniques later on.

We can use the equivalences already established to prove new ones.

Example: Show ~(p -> q) and p /\ ~q are logically equivalent.

~(p -> q) <=> ~(~p \/ q) since p -> q <=> (~p \/ q) (done above)
<=> ~(~p) /\ ~q) by DeMorgan
<=> p /\ ~q by double negation (cf. Table 6)

Example: Show ~(p \/ (~p /\ q)) and ~p /\ ~q are logically equivalent.

~(p \/ (~p /\ q)) <=> ~p /\ ~(~p /\ q) by DeMorgan


<=> ~p /\ (~(~p) \/ ~q) by DeMorgan
<=> ~p /\ (p \/ ~q) by double negation
<=> (~p /\ p) \/ (~p /\ ~q) by distributive law (Table 6)
<=> F \/ (~p /\ ~q) by negation law (Table 6)
<=> (~p /\ ~q) \/ F by commutativity (Table 6)
<=> ~p /\ ~q by identity (Table 6)

Example: Show that (p /\ q) -> (p \/ q) is a tautology.


How do you show something is a tautology? One way is with a truth
table - show that the column is all T's. Another way is to show
that the proposition is logically equivalent to T:

(p /\ q) -> (p \/ q) <=> ~(p /\ q) \/ (p \/ q) by previous example


<=> (~p \/ ~q) \/ (p \/ q) by DeMorgan
<=> (~p \/ p) \/ (q \/ ~q) by assoc. & comm. (regroup)
<=> (~p \/ p) \/ T by negation
<=> T by domination (Table 6)

------------------------------------------------------------------------
1.3 Predicates and Quantifiers
------------------------------------------------------------------------

Propositional logic cannot express certain important concepts, such as

* Every computer in the university network is working.


* One of the computers in the university network has crashed.

To express such concepts, we need PREDICATE LOGIC (a.k.a., PREDICATE


CALCULUS). New concepts are
* predicates
* quantifiers

We will be dealing with statements that have two parts, a variable


and a predicate.
PREDICATE: a property that the variable might (or might not) satisfy.

Example: "x is greater than 3". x is the variable, "greater than 3"
is the predicate.

Notation: P(x), where x is the variable and P is the predicate.


Together, they form a PROPOSITIONAL FUNCTION. When a value has been
assigned to x, the result is a proposition which has a truth value.

Example: Suppose P(x) is "x > 3".


Then P(4) is true (since 4 > 3) and P(2) is false (since it is not
the case that 2 > 3).

Example: Suppose Q(x,y) is "x = y + 3". (Notice that we have


DMATH RESEARCH – PAGE 3

two variables, x and y.) Then Q(1,2) is false (since it is not


the case that 1 = 2 + 3) and Q(3,0) is true (since 3 = 0 + 3).

A propositional function can have any number of variables:


P(x_1, x_2, ..., x_n). Sometimes called an n-PLACE PREDICATE
or n-ARY PREDICATE.

CS APPLICATION: Predicates are used in program verification.

Example: Here's a program to swap (programming) variables x and y:

temp := x
x := y
y := temp

Suppose x = a and y = b before this program runs.


We want to show that after the program runs, x = b and y = a.

Let P(x,y) be the predicate "x = a and y = b".


Let Q(x,y) be the predicate "x = b and y = a".

We can annotate the program like this:

x = a and y = b (i.e. P(x,y) is true) (precondition)


temp := x
x = a, temp = a, y = b
x := y
x = b, temp = a, y = b
y := temp
x = b, temp = a, y = a (i.e., Q(x,y) is true) (postcondition)

Sometimes we want to consider the value of a predicate for lots of


different values of the variable, not just one specific value.
To specify a range of values of the variable(s), we use QUANTIFIERS.

UNIVERSAL QUANTIFIER: For all x in the domain.


*** Domain needs to be specified!

Use of the universal quantifier: For all x (in the domain), P(x).
Notation is AxP(x) (really A should be upside-down A).

AxP(x) is true if P(x) is true for every x in the domain.


AxP(x) is false if P(x) is false for at least one x in the domain.

Example: Suppose P(x) is "x + 1 > x" and the domain is the real numbers.
What is the truth value of AxP(x)?
Since x + 1 > x is true for all real numbers, AxP(x) is true.

Example: Suppose Q(x) is "x < 2" and the domain is the real numbers.
What is the truth value of AxQ(x)?
Since there exists a real number that is >= 2, AxQ(x) is false.

EXISTENTIAL QUANTIFIER: There exists an x in the domain.


*** Domain needs to be specified!

Use of the existential quantifier: There exists x (in the domain), P(x).
Notation is ExP(x) (really E should be backwards E).

ExP(x) is true if P(x) is true for at least one x in the domain.


ExP(x) is false if P(x) is false for every x in the domain.

Example: Suppose Q(x) is "x < 2" and the domain is the real numbers.
What is the truth value of ExQ(x)?
Since there exists a real number that is less than 2, ExQ(x) is true.

Example: Suppose R(x) is "x > x + 1" and the domain is the real numbers.
What is the truth value of ExR(x)?
Since there is *no* real number that is larger than 1 plus itself,
ExR(x) is false.

Precedence of Quantifiers and Binding of Variables:


--------------------------------------------------
Precedence of A and E is higher than all the other logical operators.

Example: AxP(x) \/ Q(x) is the disjunction of AxP(x) and Q(x)


DMATH RESEARCH – PAGE 4

and is not the universal quantification of P(X) \/ Q(x).

When a quantifier is used on a variable, the variable is BOUND.


If a variable is not bound or set to a particular value, it is FREE.

To produce a proposition, all the variables must either be


bound or set to a specific value.

Example: Ex(x + y = 1)
x is bound, y is free.

Example: Ex(P(x) /\ Q(x)) \/ AxR(x)


All the variables are bound.

In this example, SCOPE of Ex is (P(x) /\ Q(x)), and SCOPE of Ax is R(x).

Logical Equivalences Involving Quantifiers


------------------------------------------
Statements involving predicates and quantifiers are LOGICALLY
EQUIVALENT if and only if they are the same truth value no matter
which predicates and which domains are used.

Example: Ax(P(x) /\ Q(x)) and AxP(x) /\ AxQ(x) are logically equivalent.


How can we prove this? Remember, we cannot rely on any particulars
of the predicates P and Q, nor of the domain from which x is taken.

Proof method: We will show that if Ax(P(x) /\ Q(x)) is true,


then so is AxP(x) /\ AxQ(x), and vice versa.

Suppose Ax(P(x) /\ Q(x)) is true.


Consider an arbitrary value a in the domain.
Then P(a) /\ Q(a) is true.
In other words, P(a) is true and Q(a) is true.
Since a was chosen arbitrarily, we can deduce that
P(a) is true for every element a in the domain, i.e., AxP(x) is true and
Q(a) is true for every element a in the domain, i.e., AxQ(x) is true.
Thus AxP(x /\ AxQ(x) is true.

Now the other direction. Suppose AxP(x) /\ AxQ(x) is true.


Consider an arbitrary value a in the domain.
Then P(a) /\ Q(a) is true.
In other words, P(a) is true and Q(a) is true.
Thus for every value a in the domain, P(a) and Q(a) are both true,
i.e., Ax(P(x) /\ Q(x)).

QED (end of proof)

Negating Quantified Expressions - VERY IMPORTANT TO GET RIGHT!


-------------------------------

Consider the statement "Every student in the class has taken Math 151."
What is the negation of this?
(a) "No student in the class has taken Math 151" or
(b) "There is a student in the class that has not taken Math 151" ?

In general,
AxP(x) : for all x, P(x) is true
When this is negated : it is not the case that for all x, P(x) is true.
I.e., there exists an x such that P(x) is not true.
I.e.,
Ex~P(x).

So in the example, the answer is (b).

Similarly, consider the statment "At least one student in the class
has taken Math 152". What is the negation of this?
It is "No student in the class has taken Math 152".

In general,
ExP(x) : there exists an x such that P(x) is true
When this is negated : it is not the case that there exists an x
such that P(x) is true.
I.e., for all x, P(x) is false.
I.e.,
Ax~P(x).
DMATH RESEARCH – PAGE 5

*** So you swap the quantifier and negate the predicate.


Called DeMorgan's laws for quantifiers.

CS APPLICATION: Logic Programming

There is a programming language called Prolog (Programming in Logic),


developed by people studying artificial intelligence.

A Prolog program is given a series of facts and some rules for reasoning
about those facts. Then it can answer queries relating to those facts.
For instance:

input facts:
instructor(chan,math273)
instructor(patel,ee222)
instructor(grossman,cs301)
enrolled(kevin,math273)
enrolled(juana,ee222)
enrolled(Juana,cs301)
enrolled(kiko,math273)
enrolled(kiko,cs301)

input rule: (comma means conjunction)


teaches(P,S) :- instructor(P,C), enrolled(S,C)

Then we can enter the query


?enrolled(kevin,math273)
which will give the output
yes

We can also enter the query (X is a variable)


?enrolled(X,math273)
which will give the output
kevin
kiko

And the query


?teaches(X,juana)
will output
patel
grossman

------------------------------------------------------------------------
1.4 Nested Quantifiers
------------------------------------------------------------------------
We can build even more complex logical statements by nesting
quantifiers. For the next few examples, assume the domain is the
real numbers.

Example: Ax Ey (x + y = 0)
For every x, there exists y such that x + y is zero.
(Namely, -x.)

Example: Ax Ay (x + y = y + x)
The commutative law of addition.

Example: Ax Ay ((x > 0) /\ (y < 0) -> (x*y < 0))


For all x and y, if x is positive and y is negative, then their
product is negative.

The order in which the quantifiers appear is important.


Consider two variables.

* Ax Ay P(x,y) is the same as Ay Ax P(x,y).


Both mean that P(x,y) is true for every pair x and y

* Ax Ey P(x,y)
Means that for every x, there is a y for which P(x,y) is true

* Ex Ay P(x,y)
Means that there exists an x such that for every y, P(x,y) is true

*** note that Ax Ey P(x,y) is NOT the same as Ex Ay P(x,y)

* Ex Ey P(x,y) is the same as Ey Ex P(x,y)


Both mean that there exists a pair x and y such that P(x,y) is true
DMATH RESEARCH – PAGE 6

An example illustrating the difference of the order of quantifiers:


Suppose Q(x,y) is "x + y = 0".

* Ax Ay Q(x,y) : for all x and y, their sum is 0.


This is false (a counter-example is x = 3 and y = 4).

* Ax Ey Q(x,y) : for all x, there is a y such that there sum is 0.


True (let y = -x).

* Ex Ay Q(x,y) : There exists an x such that for all y, their sum is 0.


This is false: each real number is just one additive inverse.

* Ex Ey Q(x,y) : There exists an x and a y such that their sum is 0.


True. For instance, let x = 3 and y = -3.

It is very important to be clear about your quantifiers and their


order, when trying to make precise statements.

Negating Nested Quantifiers:


---------------------------
Start with Ax Ey (x*y = 1) and negate it.
Then "simplify" so that no quantifier has a negation in front of it.

~(Ax Ey (x*y = 1)) <=> Ex ~Ey (x*y = 1) by DeMorgan for quantifiers


<=> Ex Ay ~(x*y = 1) by DeMorgan for quantifiers
<=> Ex Ay (x*y != 1) definition of not equals

I.e., swap the quantifier and negate what comes after it.

------------------------------------------------------------------------
1.5 Rules of Inference
------------------------------------------------------------------------
In order to prove mathematical statements, we have to give valid
arguments for them. I.e., we start with statements we already know
are true, and then deduce new true statements, until finally we reach
our desired conclusion. To deduce new true statements from statements
we already know are true, we use RULES OF INFERENCE.

Example: Suppose we know these two facts:


(1) If you know the root password, then you can change your grade.
(2) You know the root password.

What can we infer from these two facts?


(3) You can change your grade.

More abstractly, if p -> q is true and p is true, then q is true.

Why is this valid?


Because ((p -> q) /\ p) -> q is a tautology (can check with truth
table that all rows are true).

Notation:

p
p -> q
------
.
. . q

Called MODUS PONENS.

Table 1 on p. 66 lists the most important rules of inference.

* p and p -> q implies q modus ponens

* ~q and p -> q implies ~p modens tollens

* p -> q and q -> r implies p -> r hypothetical syllogism

* p \/ q and ~p implies q disjunctive syllogism

* p implies p \/ q addition

* p /\ q implies p simplification
DMATH RESEARCH – PAGE 7

* p and q implies p /\ q conjunction

* p \/ q and ~p \/ r implies q \/ r resolution

Example:

Suppose we know these facts about a program:


(a) "x is not equal to 5 and x is greater than y"
(b) "y is prime only if x = 5" *** ONLY IF: if y is prime then x = 5 ***
(c) "if y is not prime then z is odd"
(d) "if z is odd then z < x"

Can we conclude that z < x?

Translate into logic:


p is "x = 5"
q is "x > y"
r is "y is prime"
s is "z is odd"
t is "z < x"

Hypotheses are:
(a) ~p /\ q
(b) r -> p
(c) ~r -> s
(d) s -> t

Now apply the rules of inference to try to show that t is true.

Step
1. ~p /\ q hypothesis (a)
2. ~p simplification using step 1
3. r -> p hypothesis (b)
4. ~r modus tollens using steps 2 and 3
5. ~r -> s hypothesis (c)
6. s modus ponens using steps 4 and 5
7. s -> t hypothesis (d)
8. t modus ponens using steps 6 and 7

So t is true, i.e., z < x.

CS APPLICATION: Using resolution to automate theorem proving and


in Prolog.

Resolution is the rule of inference that says the following is a


tautology:

((p \/ q) /\ (~p \/ r)) -> (q \/ r)

(Intuition: p is either true or false. If p is true, than r has to be


true. If p is false, then q has to be true.)

These applications (automatic theorem proving and Prolog) use ONLY


Resolution in their reasoning.
So all hypotheses and the conclusion must be represented as
CLAUSES (disjunction of variables or negated variables).
Notice that the resolution rule says that the conjunction of two
clauses implies a third clause.

Claim: Any statement of propositional logic can be converted into


an equivalent statement that is the conjunction of some number of clauses.

Fallacies
---------
Watch out for making these mistakes:

(a) assuming that if p -> q is true and q is true, then p must be true.
This is not necessarily true.

Example: Suppose we know that "if it rains then the roof leaks"
and also we know that the roof is leaking. Do not assume that
it is raining!! It could be that the roof leaks all the time,
even when it is not raining.

(b) assuming that if p -> q is true and p is false, then q must be


false. This is also not necessarily true.
DMATH RESEARCH – PAGE 8

Example: Suppose we know that "if it rains then the roof leaks"
and also we know that it is not raining. Do not assume that the
roof is not leaking! It could be that the roof leaks all the time,
even when it is not raining.

Rules of Inference for Quantified Statements


--------------------------------------------
Often these are "unspoken" rules that are used in mathematical reasoning,
i.e., they are used without being explicitly mentioned.

* If AxP(x) is true, then we can conclude that P(c) is true for


any specific element c in the domain of x
Called Universal Instantiation.

* If P(c) is true for an arbitrary c in the domain, then we can conclude that
AxP(x) is true.
*** WARNING! Cannot make any assumptions about c other than it is
in the domain! Making additional (unwarranted) assumptions about
c and then concluding AxP(x) is a common mistake in proofs.
For instance, suppose you prove something making use of the fact
that c is an even integer - you cannot conclude that the fact is
true of all integers.
Called Universal generalization.

* If ExP(x) is true, then we can conclude that P(c) is true for some
element c of the domain.
*** WARNING! Cannot make any assumptions about c other than that it is
in the domain! Another source of errors. For instance, if the
domain is the integers, and you need to do something with c,
you cannot assume that c is even.
Called Existential Instantiation.

* If P(c) is true for some particular element c in the domain,


then we can conclude that ExP(x) is true.
Called Existential Generalization.

These 4 rules can be combined with the previous rules for propositional
logic.

Example: Universal Modus Ponens:

1. Ax(P(x) -> Q(x)) hypothesis


2. P(a) for some a in the domain hypothesis
3. P(a) -> Q(a) universal instantiation
4. Q(a) modus ponens using steps 2 and 3

We can shorten this to have the rule

* Ax(P(x) -> Q(x)) and P(a) implies Q(a)

Example of its usage:

Assume that "For all positive integers n, if n > 4, then n^2 < 2^n"
is true. Then show that 100^2 < 2^100.

Let P(n) be "n > 4".


Let Q(n) be "n^2 < 2^n".
The hypothesis is An(P(n) -> Q(n)), where the domain is all positive ints
The desired conclusion is Q(100).

1. An(P(n) -> Q(n)) hypothesis


2. P(100) since 100 > 4
3. Q(100) by Universal Modus Ponens.

Similarly, we have the rule Universal Modus Tollens:

* Ax(P(x) -> Q(x)) and ~Q(a) implies ~P(a)

You might also like