CS311 -- Discrete Structures ----Spring 2002
Note: Lecture notes will not exactly follow the lecture. They may include more
material.
Note on notation: Because of the limitations of html (and my knowledge of it),
I will use the following notation in these notes:
- "V" for or
- "&" for and
- " ¬" for not
- "->" for implies
Lecture and Other Notes 1/9/02
In this class we will study the discrete math needed for future classes in
Computer Science and also for programming and problem solving.
What is "discrete math"? Discrete math deals with objects (counting things, graphs,
trees, whole numbers) instead of real numbers. There won't be any epsilons or
deltas in this class. Another goal of the class is to help you become
mathematically mature so that mathematical reasoning will be comfortable in future
classes.
Some topics we will cover:
- Logic -- Chapter 2
- Proof Techniques -- Chapter 2, and instructor's notes
- Combinatorics (counting) -- Chapter 1
- Sets -- Chapter 3
- Proof by induction -- Chapter 4
- Euclid's algorithm -- Chapter 4
- Functions -- Chapter 5
- Relations -- Chapter 5
- Graphs (basics) -- if we have time -- Chapter 11
- Trees (basics) -- if we have time -- Chapter 11
- Recurrence relations (basics) -- if we have time -- Chapter 7
Why do we care about these topics? Computer researchers and programmers have
to be good problem solvers. Most of us are probably in computer science because
we love solving problems or programming. The topics in this class are the mathematical basis
for a lot of the problem-solving and analysis we have to do as computer scientists.
A note on the book. The book is very deep. We will not cover every section.
You will be responsible only for the material covered in class unless otherwise
indicated by the instructor.
Our first topic will be logic and proof techniques.
Logic
You are probably familiar with boolean logic from CS160. Boolean logic deals with
boolean variables; variables that can hold the values true or false
which we often write as 1 or 0. You should be familiar with
- the logical operations and, or, exclusive or, and not, with
- truth tables, and with
- the basic laws of logic.
In this class we will be studying logic from a more mathematical perspective as
a basis for learning how to write good proofs. You may wonder why we care so
much about logic and proofs. In order to reach the correct conclusions when you
think, you need to think logically. This is especially important for programmers.
A computer program is like a translation of a problem from real life into computer
code. To get a complicated program right you need to think logically. You may
never prove anything again after you leave school, but the kind of thinking you
had to do in order to get good grades on your proofs will help you whenever you
have to solve problems in the future.
Logic is usually studied in philosophy departments. It is a science of reasoning.
Boolean logic uses some of the mechanics of logic without the content. In this
class we will be studying logic from a more classical perspective. Where a boolean
variable had the value 0 or 1, a logical "variable" in this class will represent
a statement.
Definition: An proposition is a declarative sentence that is either true or false.
Note: in the book the author uses the term statement instead of proposition.
Examples:
- "Class meets on Mondays."    is a proposition that is true.
- "Class meets on Tuesdays."    is a proposition that is false.
- "Go Vols!"    is not a proposition.
- "The number x is an integer."    is not a proposition because since we do not know what the value of x is the statement does not have a truth value.
We will use letters to represent propositions. Here letters can represent the values
true and false (possibly written as 1 or 0)
or a statement that is true or false (a proposition).
A proposition (or statement) that does not contain logical operators is
called a primitive statement.
If you combine primitive statements with logical
operators ( & , V, ¬ and some we will introduce later) then you have a
compound statement.
For example:
Let p represent the proposition "CS311 meets on Mondays."
Let q represent the proposition "CS311 is a physics class."
Then we can use p and q to form a compound statement: p & q
which means "CS311 meets on Mondays and CS311 is a physics class".
The letters "p" and "q" in this example represent the propositions given above
and also have truth values associated with them.
Since p represents "CS311 meets on Mondays", p is true.
Since q represents "CS311 is a physics class", q is false
So p & q is true & false which is false
In the example above we went from logic to English back to logic. We can also
start with an English statement and write it in logic.
For example consider the statement: "UT is in Knoxville and Knoxville is not in the north".
We want to write this as a logical expression letting variables stand for the English
propositions so that we can use the mechanics of logic to decide whether the statement
is true or not.
Of course this statement is so simple we don't need to do this, but
we can imagine more complicated statements where we would need to.
So let p denote the proposition "UT is in Knoxville." and q the proposition "Knoxville is
in the north." We could include the "not" in the proposition, but it is clearer if
we don't (because we won't have to deal with double negatives).
Then the statement "UT is in Knoxville and Knoxville is not in the north" is: p & ¬ q
Is this true or false? p is true and q is false so
| p & ¬ q= | T & ¬ F |
| = T & T |
| = T |
What about: "UT is in Knoxville and Knoxville is in the north". This would be p & q
which is false since q is false.
What about: "UT is not in Knoxville or Knoxville is not in the north."
This is:
| ¬ p V ¬ q= | ¬ T V ¬ F |
| = F V T |
| = T |
Note that in evaluating an expression like ¬ p V ¬ q I am assuming you use (know)
the truth tables for ¬ and & and V.
Practice Problems: Translating from English to logical expressions.
Write the English statements below as logical statements by defining your propositions
and using letters to denote them. Then say whether each statement is true or false.
- Steve Spurrier is not a Vol. (don't include the negative in the proposition)
- My dog is in the back yard or he is in the river.
- My dog does not like to play frisbee & he likes to play ball.
- My dog is black and lean and loves to swim.
Note sometimes we say things that are difficult to translate into logic (math) because
they are ambiguous (they can be taken more than one way).
Example:
My ideal wife has blonde hair and blue eyes or lots of money.
If we let
      p = "my wife has blonde hair"
      q = "my wife has blue eyes"
      r = "my wife has lots of money"
Then this statement, as written, is: p & q V r.
But is it -- (p & q) V r? "My ideal wife has both blonde hair and blue eyes or lots of money."
Or -- p & (q V r)? "My ideal wife has blonde hair and either blue eyes or lots of money."
Why does it matter? Because (p & q) V r is not equivalent to p & (q V r).
The statement "My ideal wife has blonde hair and blue eyes or lots of money." is ambiguous.
There is no way to tell which interpretation is meant.
How do we know that (p & q) V r is not equivalent to p & (q V r)?
In general how to we decide whether two expressions are equivalent or not?
Equivalence
Definition 1: Two logical statements s1 and s2 are equivalent if and only if they have the
same truth values for all possible truth values of the logical variables.
We write "s1 <=> s2" to mean "s1 is equivalent to s2".
Method for testing whether two logical statements are equivalent: see if their
truth tables agree for every possible value of the variables.
Example: Consider ¬(p & q) versus ¬ p & ¬ q
| p | q | ¬(p & q) | ¬ p & ¬ q |
| 0 | 0 |     1 | 1 |
| 0 | 1 | 1 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 |
These two logical expressions are not equivalent. However, now
consider ¬ (p & q) versus ¬ p V & not q
| p | q | ¬(p & q) | ¬ p V ¬ q |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
These two logical expressions are equivalent: ¬ (p & q) <=> ¬ p V ¬ q.
Whenever two logical expressions are logically equivalent we can
use them interchangeably. These Logical Laws are summarized in
the book in a chart on page 59. Some examples:
- ¬ ¬ p <=> p    Law of Double Negation
- ¬(p & q) <=> ¬ p V ¬ q     DeMorgan's Law
- ¬(p V q) <=> ¬ p & ¬ q     DeMorgan's Law
- p V q <=> q V p Commutative Law
- p & q <=> q & p Commutative Law
- (p V q) V r<=> p V (q V r) Associative Law
- (p & q) & r<=> p & (q & r) Associative Law
There is another method for testing whether two logical expressions
are equivalent: use the laws of logic to simplify them.
Definition:A logical expression is a tautology if it
is true for all possible values of the logical variables. In other
words, every row of the truth table will have the value "true" or "1".
Example: p V &p is a tautology. Here is the truth table:
| p | ¬ p | p V ¬ p |
0 | 1 | 1 |
1 | 0 | 1 |
In the book a tautology is denoted by T0.
Thus we can write: p & ¬ p <=> T0.
Definition:A logical expression is a contradiction if
it is false for all possible values of the variables.
In the book a contradiction is denoted by F0.
Some more laws of logic (from page 59):
- p V F0 <=> p   &nsbp Identity Law
- p & T0 <=> p   &nsbp Identity Law
- p V T0 <=> T0   &nsbp Domination Law
- p & F0 <=> F0   &nsbp Domination Law
- p & ¬ p <=> F0     Inverse Law
- p V ¬ p <=> T0     Inverse Law
You will need to learn these laws. They are useful for simplifying
logical expressions, both here when we are doing proofs and also in
designing boolean circuits.
Problem: Show that ¬ (r & q) V q is a tautology using
the laws of logic to simplify.
| ¬ (r & q) V q | Given |
| (¬ r V ¬ q) V q | DeMorgan's Law |
| ¬ r V (¬ q V q) | Associative Law |
| ¬ r V (T0) | Inverse Law |
| T0 | Domination Law |
Since in each step we replaced an expression by an equivalent
expression, we know that the original expression is equivalent
to T0 and therefore is a tautology.
While the foregoing is probably familiar from classes on digital
systems design, there is another logical operator you may never
have heard of: ->.
Definition: The implies operator, written "->" has
the following truth table:
In English when we write "p->q" we read it as "If p then q."
Examples:
- "If today is Wednesday then CS311 meets."
This is "p->q" where p = "Today is Wednesday" and "q = CS311 meets".
Both p and q are True. In the truth table this corresponds
to the last line and we see that 1->1= 1. So this statement is true.
-
This seems like it should be false and it is. This is equivalent
to "p->q" where p = "Today is Wednesday" and q = "Today is Thursday".
Since this lecture was given on a Wednesday, p was true and q false.
In the truth table for -> we see 1->0 is 0. Therefore this statement
is false.
- "If Elvis is alive then 2 = 5"
This statement is p->q where p is false (I assume Elvis is dead) and
q is false. It is nonsensical, but is defined by the truth table
to be true (0->0 = 1). Think of it as a "don't care". Whenever we
don't care (the first part is false) then we let the whole statement
be true.
The statement "if p then q" can also be read as "p only if q". You
can think of "if p then q" as meaning "whenever p is true then
q must be true." When p is not true we don't care about q.
Later we will talk about how to prove an "if-then" statement.
Since such a statement is true in every case except when p is true
and q is false, you can assume that p is true and then prove q is true.
In this lecture we (more or less) covered sections 2.1-2.2.