Lecture slides
Download
Report
Transcript Lecture slides
Conceptual Foundations of
Computing
Lecture 2
Something thought about?
In formal logic we model
“If it is raining then there are clouds in the sky.”
as
p→q
p: It is raining.
q: There are clouds in the sky.
We are modelling a statement of the form:
“If p is True then it must be the case that q is True.”
However, consider:
r→p
r: It is Wednesday
p: It is raining.
Since today is Monday, r → p is True. So, is it True to say that:
“If it is Wednesday then it must be the case that it is raining.”
What’s going on here?
Material implication
In formal logic we model
“If it is raining then there must be clouds in the sky.”
as
p→q
However, p → q does not fully capture this statement.
• p → q is a poor model of this statement
• p → q is related to the statement above, but weaker
Last week we saw that:
• p→q
~p ˅ q
~(p ˄ ~q)
“p is False or q is True”
“It is not the case that p is True and q is False.”
p → q makes a statement about the current , “actual”, “material” values of p and q.
So, r → p says:
“It is not the case that it is Wednesday and not raining.”
This statement is True.
Material implication
Should we worry that p → q is a weak model for:
“If p is True then it must be the case that q is True.”
We want to use p → q in valid arguments.
p → q “if p is True then q is True”
p
“p is True”
q
“therefore q is True”
Fortunately, we can do this with confidence.
Notice the Truth table for “material implication” above.
If we know that p → q is True and p is True, what does that tell us about q?
Wikipedia on “material implication”: http://en.wikipedia.org/wiki/Material_implication
Material implication is a weak, abstract, but adequate model of “if p then q”.
This is probably the most challenging concept in the whole course.
Arguments
An argument is a sequence of statements ending in a conclusion
If Socrates is a man, then Socrates is mortal.
Socrates is a man.
Therefore Socrates is mortal.
This argument has the following abstract form (structure)
If p then q.
p
Therefore q.
Where p and q are variables (place holders ) for statements. The form of this
argument is valid regardless of the statements for p and q.
All statements or “statement forms” other than last are called premises. Last
statement form is called the conclusion.
Definition of an argument
The symbol
, for “therefore”, is normally placed before the conclusion.
If p then q
p
q
premise
premise
conclusion
To say that an argument form is valid means that if the substituted statements
result in valid premises, then the conclusion is also true. Here the two premises
are:
If p then q
p
The truth of the conclusion is said to be inferred from or deduced from the truth of
the premises.
If statements substituted for p and q make premises true, conclusion is true.
Testing an Argument Form
1. Identify the premises and conclusions.
2. Construct a truth table showing the truth values of all the premises and the
conclusion.
3. If the truth table contains a row in which all premises are true and the
conclusion is false, then the argument form is invalid.
If every case where all premises are true the conclusion is true, then the
argument form is valid.
(We do not need to worry about any line in truth table with a false premise.)
Invalid Argument Form
Use truth table to show the following argument form is invalid.
pq ~r
q p r
pr
Valid Argument Form
Use truth table to show following argument form is valid.
p (q r )
~r
pr
Only rows with all true premises are important: called critical rows
A better way?
Using truth tables to test the validity of an argument is a bit slow and
laborious.
It would be painful for a long, complex argument?
And, it is a significant departure from informal methods of presenting an
argument.
We need something equally reliable, but more convenient.
The method we use involves a fixed number of valid argument forms
called inference rules that enable us to infer (deduce) a new truth (the
conclusion) from a set of given truths (the premises).
Syllogism
A number of our inference rules take two premises to produce one
conclusion. An argument form consisting of two premises and a conclusion
is called a syllogism.
First premise is called major premise.
Second premise is called minor premise.
Two most famous syllogisms:
modus ponens - Latin for “method of affirming”
modus tollens - Latin for “method of denying”
Modus Ponens
pq
p
q
Modus Tollens
pq
~q
~ p
Exercise: Use truth table below to test validity of argument form.
Example modus tollens argument
If Zeus is human, then Zeus is mortal.
Zeus is not mortal.
Therefore Zeus is not human.
Informal reasoning:
If Zeus were human then he would be mortal.
But, Zeus is not mortal.
Therefore, Zeus cannot be human.
Or…
If Zeus were human, then he would be mortal.
But he is not mortal. A contradiction!
Hence, Zeus cannot be human.
Modus ponens and modus tollens…
From last week, we saw that:
p→q
So:
p→q
~q
~p
~q → ~p (contrapositive)
by modus tollens
is equivalent to:
p→q
~q → ~p (contrapositive)
~q
~p
by modus ponens
So, modus tollens is an application of contrapositive + modus ponens.
Rules of Inference
Modus ponens and modus tollens are rules of inference (valid argument forms).
An inference rule is used to generate a conclusion from a set of premises.
Premises are either given, or derived from given premises using rules of
inference.
Rules of inference apply with any substituted statements forms.
Premises: p → q (a), p (b)
p→q
p
q
Premises: r ˄ s → t (a), r ˄ s (b)
by premise (a)
by premise (p)
by modus ponens
There are nine rules of inference!
r˄s→t
r˄s
t
by premise (a)
by premise (b)
by modus ponens
Generalization
p
pq
q
pq
If you know that a particular statement is true, then you know that a logical
or of that statement with another statement is also true.
Premises: p ˅ q → r (a), p (b)
(1)
p
p˅q
(2) p ˅ q → r
p˅q
r
Target conclusion: r
by premise (b)
by generalisation
by premise (a)
by (1)
by modus ponens
In a formal argument, we document each application of an inference rule.
Note: This inference rule has only one premise.
Specialization
pq
p
pq
q
If you know that a logical and statement is true, then both of the component
statements must be true.
Premises: p → q (a), p ˄ r (b)
(1) p ˄ r
p
(2) p → q
p
q
by premise (b)
by specialisation
by premise(a)
by (1)
by modus ponens
Target conclusion: q
Conjunction
p
q
pq
If you know that two statements are true, a statement that they are both
true is also true.
Premises: p ˄ q → r (a), p (b), q (c)
(1)
(2)
p
q
p˄q
p˄q→r
p˄q
r
by premise (b)
by premise (c)
by conjunction
by premise (a)
by (1)
by modus ponens
Target conclusion: r
Elimination
pq
pq
~q
~p
p
q
If there are two possibilities and one can be ruled out, then the other must
be the case.
From last week: p → q
~p ˅ q
So:
p˅q
~p → q
And:
p˅q
~q → p
So, elimination is equivalent to another application of modus ponens.
Transitivity
pq
qr
pr
Given that, if a statement is true a second statement is true, and if that
second statement is true a third statement is true, you can conclude that if
the first statement is true the third statement will be true.
Premises: p → q (a), q → r (b), p (c)
(1) p → q
q→r
p→r
(2) p → r
p
r
by premise (a)
by premise (b)
by transitivity
by (1)
by premise (c)
by modus ponens
Target conclusion: r
Proof by division into cases
pq
p r
q r
r
If you know one of two statements is true. If you can deduce the same third
statement from either statement, that third statement must be true.
Premises: p → r (a), q → r (b), p v q (c)
pvq
p→r
q→r
r
Target conclusion: r
by premise (c)
by premise (a)
by premise (b)
by division into cases
Note: This inference rule has three premises.
Contradiction Rule
~ pc
p
If you can show that the supposition that statement p is false leads to a
contradiction, then you can conclude that p is true.
Contradiction Rule
~ pc
p
Textbook does not show presentation. Normally, something like this…
Premises: p → q (a), p (b)
(1) ~q
(1a) p → q
~q
~p
(1b) p
~p
p ˄ ~p
~q → c
q
Target conclusion: q
by supposition
by premise (a)
by supposition
by modus tollens
by premise (b)
by (1a)
by conjunction – contradiction!
by contradiction
Summary of Rules of Inference
Exercise: Complete solution
Deduce conclusion from premises. (Textbook exercise 41, page 43)
Premises:
a. ~p ˅ q → r
b. s ˅ ~q
c. ~t
d. p → t
e. ~p ˄ r → ~s
Conclusion:
~q
Solution:
(1) p → t
~t
~p
(2) ~p
~p ˅ q
(3) ~p ˅ q → r
~p ˅ q
r
(4) ~p
r
~p ˄ r
(5) ?
(6) s ˅ ~q
~s
~q
by premise (d)
by premise (e)
by modus tollens
by (1)
by generalisation
by premise (a)
by (2)
by modus ponens
by (1)
by (3)
by conjunction
by premise (b)
by (5)
by elimination
Digital Logic Circuits
An important application of the formal system of logic we’ve been studying
is digital logic circuits…
Simple Switching Circuits
Switch and Bulb Logic
Which logic tables do these correspond to?
Logic Gates
Basic building
blocks
corresponding to
logic operators.
Boolean Expressions for Circuits
Black Boxes
P
Q
R
The logic of a black box
can be fully defined by an
input/output table.
S Output Signal
Build a logic block for each row of the table with a 1 in the output column
and then use a multiple or gate to connect them to a single output.
Simplifying Circuits
Two digital logic circuits are
equivalent if, and only if,
their input/output tables are
identical.
NAND and NOR Gates
NAND (not and) gate is an AND gate followed by a NOT gate
NOR (not or) gate is an OR gate followed by a NOT gate
P|Q ≡ ~(PΛQ)
Sheffer stroke
P↓Q ≡ ~(P V Q)
Peirce arrow
Rewriting Expressions
It can be shown that any Boolean expression can be rewritten solely using
Sheffer strokes or solely rewritten using Pierce arrows.
This makes the development of printed circuits easier, since you can use lots
of nand gates in a chip and join them together as you need.
~ P ~ ( P P)
P|P
P Q ~ (~ ( P Q))
~ (~ P ~ Q)
~ (( P | P ) (Q | Q))
( P | P) | (Q | Q)
Number Systems and Addition Circuits
The cheapest digital circuits use 2 voltage values, corresponding to 1 and 0.
So, Integers are represented in a computer in a binary form.
Let’s look at how numbers are represented in binary form, and how basic
arithmetic (addition and subtraction) is performed on these representations
using digital circuits.
Decimal System
Based on the number 10.
Works because of the most important number: 0.
Uses position to represent value. Hence the need for 0!
Developed because people have 10 digits on their hands.
There is nothing special about 10.
Binary System
Base 2 is a perfectly valid way to represent integers.
Exercise: What is the integer represented by 110112 ?
Binary to Decimal
1101012 1 2 1 2 0 2 1 2 0 2 1 2
5
4
32 16 4 1
5310
3
2
1
0
Decimal to Binary
Keep removing the largest possible power of 2 from what you have left.
20910 128 a smaller number
=128+64+a smaller number
=128+64+16+1
=1128+1 64+0 32+116+0 8+0 4+0 2 11
1 27 1 26 0 25 1 24 0 23 0 22 0 21 1 20
110100012
Binary Addition
Exercise: Spot the error in the following addition.
Binary Subtraction
Subtraction done using the “borrow one, pay one back system”.
Circuits for Addition
When adding two binary digits we need to deal with 4 cases.
The carry bit (number of 2s) is an and: c = p ˄ q
The sum bit (numbers of 1s) is an xor: s = (p ˅ q) ˄ ~(p ˄ q)
Notice that xor includes an and, thus : s = (p ˅ q) ˄ ~c
So, we can use output from digital circuit for “c” in circuit for “s”.
Half Adder
This circuit adds two binary digits.
Full Adder
This circuit adds three binary digits.
Exercise: Can C1 and C2 both be 1?
Parallel Adder
This circuit adds two 3-bit numbers.
Similar circuits can add numbers with more bits.
PQR
+_______
STU
WXYZ
Representing integers in a computer
In a computer, we must represent +ve and –ve integers in a fixed number
of bits; normally 16, 32 or 64. We could use normal binary representation
of the number with one bit used for the sign.
Using 8 bits to illustrate this idea:
:
00000011
represents
00000010
represents
00000001
represents
00000000
represents
10000000
represents
10000001
represents
10000010
represents
10000011
represents
:
+310
+210
+110
+010
-010
-110
-210
-310
Unfortunately, this system has two representations for 0 (+0 and -0).
Two’s Complement
A system with only one representation of 0 and simple addition and
subtraction uses a two’s complement representation of–ve integers.
To obtain the two’s complement of an integer:
(1) take binary representation
(2) flip bits (1s to 0s, 0s to 1s)
(3) add 1
Example 1310:
0001101
1110010
1110011
If will flip bits and add one again, we get back to binary representation:
two’s complement of 1310:
1110011
flip bits:
0001100
add one:
0001101
Exercise: If we represent -8 as two’s complement of 8, what does binary
addition of 8 and -8 produce?
Note: By switching sign of a number, a subtraction becomes an addition:
a – b = a + (-b)
Example of subtraction: a + (-b)
Consider the example :
39 + (-25)
Truncate leading 1.
Note: This is the simple case 1 ≤ b ≤ a ≤ 127. See Textbook for other cases.
Hexadecimal Notation
See Textbook for
conversion between the
hexadecimal, decimal and
binary representation of a
number.