Lecture slides
Download
Report
Transcript Lecture slides
Conceptual Foundations of
Computing
Lecture 4
Chapter 3 Examinable Content
Study Schedule suggests 3.1 to 3.6 all examinable:
But, course update (http://webfuse.cqu.edu.au/Courses/2008/T2/COIT11118/Updates/) says:
Quiz 1
Quiz 1 is due this week.
See course updates (http://webfuse.cqu.edu.au/Courses/2008/T2/COIT11118/Updates/):
Methods of Proof
We have been studying formal tools to construct a valid argument or proof.
These tools allow us to deduce or infer a conclusion from a set of premises.
If premises are true and argument form is valid, the conclusion will be true.
So, we can deduce new truths from old truths.
Which begs a question: Where do you start?
This week we study some methods of proof applied to elementary number theory.
Along the way we meet the idea of an axiom – a place to start!
Odd and Even Numbers
Definitions:
An integer n is even if and only if, n equals twice some integer.
An integer n is odd if, and only if, n equals twice some integer + 1.
Symbolically, if n is an integer, then
n is even
n is odd
an integer k such that n = 2k.
an integer k such that n = 2k +1.
Exercises
Given our definitions, provide a valid argument to answer the following:
1. Is 0 even?
2. Is -301 odd?
3. If a and b are integers, is 6a • 2b even?
4. If a and b are integers, is 10a + 8b + 1 odd?
5. Is every integer either even or odd?
Prime Numbers
Definition:
An integer n is prime if and only if, n > 1 and for all positive integers r and
s, if n = r • s, then r = 1 or s = 1.
An integer n is composite if and only if, n > 1 and n = r • s for some
positive integers r and s with r ≠ 1 and s ≠ 1.
Symbolically, if n is an integer that is greater than 1, then
n is prime
n is composite
positive integers r and s,
if n = r s then r = 1 or s = 1.
positive integers r and s
such that n = r s and r 1 and s 1.
Proving Existential Statements
x D such that Q(x).
Is true, if and only if: Q(x) is true for at least one x in D.
Two ways to prove this are:
find an x in D that makes Q(x) true
give a set of directions to find such an x
These are constructive methods of proof leading to an example value for x.
Two nonconstructive methods of proof (not leading to an example) are:
show assumption that there is no such x leads to a contradiction
show that x to make Q(x) true follows from an axiom or theorem
Note: A theorem is a statement proved from axioms or other theorems.
Axioms
An axiom is a simple statement that is taken to be true without proof.
Use of axioms started by Euclid: http://en.wikipedia.org/wiki/Euclidean_geometry
Euclidean geometry is based on five axioms , three of which are:
1: Any two points can be joined by a straight line.
2: Any straight line segment can be extended indefinitely in a straight line.
5: Parallel postulate: If two lines intersect a third in such a way that the sum of
the inner angles on one side is less than two right angles, then the two lines
inevitably must intersect each other on that side if extended far enough.
Wikipedia : “geometers tried to prove the fifth postulate from the first four. By 1763
at least 28 different proofs had been published, but all were found to be incorrect.”
Other system of non-Euclidean geometry have used a different set of axioms.
Wikipedia: “Einstein's theory of general relativity shows that the true geometry of
space-time is non-Euclidean geometry.”
That is, gravity bends space: http://en.wikipedia.org/wiki/Gravitational_lense
Disproving Universal Statements
One way to disprove
x D, if P(x) then Q(x).
is to show the negation is true:
x in D such that P(x) and not Q(x).
We only need to find a single x – a counterexample – to prove the negation.
Disproof by Counterexample
To disprove a statement of the form
" x D, if P(x) then Q(x)."
Find a value of x in D for which P(x) is true and Q(x) is false.
Such an x is called a counterexample.
Proving Universal Statements
x D, if P(x) then Q(x).
Method of Exhaustion
Take each possible x in turn and show that the universal statement holds.
If we can determine the few x in D for which P(x) is true, we need only check
that these x all make Q(x) true.
Those x in D for which P(x) is false may be ignored / discarded.
Example:
integers n, if abs(n) 1 then abs(n n) 1.
Integer truth-set of P(x) is -1, 0, 1, which we can be tested exhaustively.
Generalising Generic Particular
Usually, the method of proof by exhaustion of specific values is not feasible.
Instead, we must provide a proof for a general particular value – x.
Method of Generalizing from the Generic Particular
To show that every element of a domain satisfies a certain property,
suppose x is a particular but arbitrarily chosen element of the domain, and
show that x satisfies the property.
We cannot rely on any special property x has over other members of D.
If we use a feature of x then that feature has to apply to every x in D.
The general idea…
Think of a number, any number… follow instructions … and you are left with 7.
In general we might refer to the particular number chosen as x…
Method of Direct Proof
1. Express the statement to be proved in the form
" x D, if P(x) then Q(x)."
2. Start the proof by supposing x is a particular but arbitrarily chosen element of
D for which the hypothesis P(x) is true.
"Suppose x D and P(x)."
3. Show that the conclusion Q(x) is true by using definitions, previously
established results, and the rules for logical inference.
Developing a proof
Most proofs look compact and “elegant”; but, they don’t start like that!
Developing a proof involves lots of false starts, writing down partial ideas, making
lists of things that are known, things that might be useful (similar to program design).
Like a jigsaw, pieces are slotted together to form a rough framework - a “mud-map”
of how to get from start to finish. Slowly, details are filled in.
Often, a road block is found with an approach. Must go back and try again!
Once a correct line of reasoning is found, rewrite proof filling in all the minute details.
Now, critique your proof: Anything overlooked? Anything not fully explained?
Finally , tidy things up: Can you simplify it? Is anything not needed?
Theorem and Proof
Theorem: The sum of any two even integers is even.
Proof:
Suppose m and n are [particular but arbitrarily chosen] even integers. [We
must show that m + n is even.] By definition of even, m = 2r and n = 2s for
some integers r and s. Then
m + n = 2r + 2s
= 2(r + s)
by substitution
by factoring out 2.
Let k = r + s. Note k is an integer because it is a sum of integers. Hence
m + n = 2k
where k is an integer.
It follows by definition of even that m + n is even.
[This is what we needed to show.]
How to write Proofs
1. Copy the statement of the theorem to be proved on your paper.
2. Clearly mark the beginning of your proof with the word “Proof”.
3. Make your proof self-contained.
4. Write your proof in complete sentences.
5. Give a reason for each assertion you make in your proof.
6. Include “little words” that make logic of the argument clear (then, hence, etc).
Two proofs of the same statement will be different:
they will have different structure and notation
they may be written at different intellectual standards
one may be more verbose than another
comments may be added in [] to explain the proof
There is no correct answer for a proof.
Getting Proofs Started
x D, if P(x) then Q(x).
1. Try and write the goal of your proof as a statement in the standard form above.
2. Write your starting point down.
Suppose x is a [particular but arbitrarily chosen] member of D
such that P(x).
3. Write down the conclusion to be shown (at the bottom of the page):
Therefore Q(x).
4. Now you just need to find the correct logical steps to get from the starting
point to the finish.
Disproving an Existential Statement
The negation of an existential statement is a universal statement.
To disprove an existential statement, we must prove a universal statement.
So, again, we must develop proof using a generic particular.
Example
Show that the following is false
There is a positive integer n such that n2 + 3n + 2 is prime.
Equivalent to proving the negation true
For all positive integers n, n2 + 3n + 2 is not prime.
Outline of Proof
Suppose n is any positive integer.
We can factor n2 + 3n + 2 into (n+1)(n+2).
n+1 and n+2 are integers (because they are sums of integers)
n+1 > 1 and n+2 > 1 because n ≥ 1.
Thus n2 + 3n + 2 is a product of two integers each greater than 1.
So n2 + 3n + 2 is not prime.
Section 3.2: Rational Numbers
When you add, subtract or multiply integers you get an integer; but, division?
Dividing one integer by another (non zero) integer gives a rational number.
The result of dividing any number by zero is not defined.
The ‘fraction’ of one integer over another is called a quotient.
A real number r is rational if and only if it can be expressed as a quotient of two
integers with a nonzero denominator.
A real number that is not rational is called irrational.
More formally, if r is a real number, then
r is rational
integers a and b such that r =
a
and b 0.
b
Rational Number Exercises
1. Is 10/3 a rational number?
2. Is –(5/39) a rational number?
3. Is 0.281 a rational number?
4. Is 7 a rational number?
5. Is 0 a rational number?
6. Is 2/0 a rational number?
7. Is 2/0 an irrational number?
8. Is 0.1212121212… a rational number (digits 12 repeat forever)?
9. If m and n are non-zero integers, is (m + n) / m • n a rational number?
Generalising from Generic Particular
Theorem: Every integer is a rational number.
Proof:
Let n be a [particular but arbitrarily chosen] integer.
Then , n • 1 = n, and so n = n / 1 by dividing both sides by 1.
Now n and 1 are both integers and 1 does not equal 0.
Hence, n can be written as a quotient of integers with a nonzero denominator.
So, n is rational.
[This is what was to be shown.]
Rational Number Proofs
Theorem: The sum of any two rational numbers is rational.
Proof:
Suppose r and s are rational numbers. [We must show that r + s is rational.] Then,
by definition of rational, r = a/b and s = c/d for some integers a, b, c, and d with b ≠
0 and d ≠ 0. Thus
r + s = a/b + c/d
by substitution
= (ad + bc)/bd
by basic algebra.
Let p = ad + bc and q = bd. Then p and q are integers because products and sums of
integers are integers and because a, b, c, and d are all integers. Also q ≠ 0 by the
zero product property. Thus
r + s = p/q where p and q are integers and q ≠ 0 .
Therefore r + s is rational by definition of a rational number.
[This is what was to be shown.]
A Corollary
A corollary is a statement whose truth can be immediately deduced from a
theorem that has already been proved.
Corollary: The double of a rational number is a rational.
The double of a number is just its sum with itself.
Since the sum of any two rational numbers is rational (by the theorem), the sum
of a rational number with itself is rational.
Hence the double of a rational number is rational.
Proof:
Suppose r is any rational number. Then 2r = r + r is a sum of two rational
numbers. So, by the theorem, 2r is rational.
Section 3.3: Divisibility
If n and d are integers, then
n is divisible by d if, and only if, n = dk for some integer k.
Alternatively, we can say that
n is a multiple of d
d is a factor of n
d is a divisor of n
d divides n
Symbolically, if n and d are integers,
d|n
an integer k such that n = dk.
The notation d|n is read “d divides n”.
Divisibility Exercises
1. Is 21 divisible by 3?
2. Does 7 | 42?
3. Is 7 a factor of -7?
4. If k is an integer, does k divide 0.
5. Suppose a and b are positive integers and a | b. Is a ≤ b?
6. Which integers divide 1?
7. If a and b are integers, is 3a + 3b divisible by 3?
8. If k and m are integers, is10km divisible by 5?
Most are obvious, but how would you “prove” them?
Nondivisibility
Divisibility can be written formally as an existential statement.
d|n
an integer k such that n = dk.
Negating this we get
Example: Does 4 | 15?
Answer: No, 15/4 = 3.75, which is not an integer.
Caution: The notation a | b stands for “a divides b”, which means there is an
integer k such that b = a • k.
Whereas, a / b stands for the number (a/b) which is the result of dividing a by b
and which may or may not be an integer.
Transitivity of Divisibility
Theorem: For all integers a, b, and c, if a divides b and b divides c, then a divides c.
Proof:
Suppose a, b, and c are [particular but arbitrarily chosen] integers such that a divides b
and b divides c. [We must show that a divides c.] By definition of divisibility,
b = ar and c = bs for some integers r and s.
By substitution
c = bs
= (ar)s
= a(rs)
by basic algebra.
Let k = rs. Then k is an integer since it is the product of integers, and therefore
c = ak
where k is an integer
Thus a divides c by definition of divisibility.
[This is what was to be shown.]
Divisibility by a prime
Theorem: Any integer n > 1 is divisible by a prime number.
Proof: See page 151 of textbook for details.
Approach taken…
Start with a positive integer (generic particular).
If it is a prime then it is divisible by itself, which is a prime, so we are done.
Otherwise it is the product of two smaller positive factors.
If one of these is prime then original number is divisible by a prime.
If not, pick one of factors; it can be written as product of smaller +ve factors.
Examine each of smaller factors, repeating as necessary.
Must eventually find a prime, because must eventually reach a factor of 2 or 3.
Another Divisibility Proof
Is the following statement True or False?
For all integers a and b, if a | b and b | a then a = b.
How would you prove it True or False?
Outline of proof that statement is False – proof by counterexample:
Let a = 2 and b = -2. Then
a | b since 2 | (-2) and b | a since (-2) | 2,
but a ≠ b since 2 ≠ -2.
Therefore, the statement is false.
Unique Factorisation Theorem
Theorem: Given any integer n > 1, there exists a positive integer k, distinct
prime numbers p1 , p2 , … , pk , and positive integers e1 , e2 , … , ek such that
and any other expression of n as a product or prime numbers is identical to this
except perhaps, for the order in which the factors are written.
Proof: See section 10.4 of Textbook (not examinable).
Given any integer n > 1, the standard factored form of n is an expression of
the form
where k is a positive integer; p1 , p2 , … , pk , are prime numbers; e1 , e2 , … , ek
are positive integers; and p1 < p2 < … < pk .
Examples: 18 = 2132
36 = 2232
90 = 213251
Standard Factored Form
Unique Factorisation Theorem also called fundamental theorem of arithmetic.
3300 in standard factored form:
3300 = 2 • 1650
= 2 • 2 • 825
= 2 • 2 • 3 • 275
= 2 • 2 • 3 • 5 • 55
= 2 • 2 • 3 • 5 • 5 • 11
= 22 • 31 • 52 • 111
The standard approach is to work through primes in ascending order. Divide by 2 until
you can’t, then divide by 3 until you can’t, then 5, 7, 11, 13, and so on.
Exercise: Express one of following in standard factored form: 12345, 12346, 12347.
Exercise: Suppose m is an integer such that:
8 • 7 • 6 • 5 • 4 • 3 • 2 • m = 17 • 16 • 15 • 14 • 13 • 12 • 11 • 10
Does 17 | m ?
Integer factorization
Consider the integer: 12345678901234567890 (20 digits)
How long would it take to find prime factors? What about a 200 digit number?
Wikipedia on integer factorization (http://en.wikipedia.org/wiki/Integer_factorization):
“a recent effort which factored a 200-digit number (RSA-200) took eighteen months
and used over half a century of computer time”
“the presumed difficulty of this problem is at the heart of certain algorithms in
cryptography such as RSA”
Wikipedia on RSA (http://en.wikipedia.org/wiki/RSA) :
“in cryptography, RSA is an algorithm for public-key cryptography. It was the first
algorithm known to be suitable for signing as well as encryption, and one of the first
great advances in public key cryptography”
first two steps in RSA algorithm:
Section 3.4: Quotient & Remainder
Division using only integers…
When we divide 11 by 4 we usually calculate the real number answer 3.75.
But what if we only wanted to use integers?
We have to change the format of the result and how we think about it.
The new answer is
“4 goes into 11 twice (2 times) with 3 left over.”
or…
11 = 2 • 4 + 3
The “2” part is called the quotient and the “3” part the remainder.
Note the remainder must always be less than the number we are dividing by.
The ability to stay within the integers for division is a very powerful tool!
Quotient-Remainder Theorem
Theorem: Given any integer n and positive integer d (divisor), there exists unique
integers q (quotient) and r (remainder) such that n = d • q + r and 0 ≤ r < d.
Proof: See section 4.4 of the textbook.
If n is positive the theorem behaves like this
If n is negative the theorem works like this
Div and Mod
The mod, modulo or modulus function has many applications in IT…
Applications of Mod: Hash tables
Wikipedia article (http://en.wikipedia.org/wiki/Hash_table) says:
Applications of Mod: Cryptography
First two steps in using RSA (http://en.wikipedia.org/wiki/RSA) are:
For Bob to send a secure message to Alice :
Article on public/private keys: http://en.wikipedia.org/wiki/Public-key_cryptography
Representation of Integers
Recall:
n is even if there exists q such that n = 2 • q.
n is odd if there exists q such that n = 2 • q + 1.
How does this fit in with the quotient-remainder theorem?
Let n be any integer and let d = 2 then there exists integers q and r such that:
n = 2q + r
and
0 ≤ r < 2.
But the only possible values for r are 0 and 1.
Therefore given any n, there exists an integer q with
n = 2q + 0
or
n = 2q + 1
In the first case n is even in the second n is odd.
Thus n is either even or odd ; there is no third possibility.
Parity Property
The parity of an integer refers to whether the integer is odd or even - 7 has an odd
parity, 42 has an even parity.
Theorem: Any two consecutive integers have opposite parity.
Outline of proof:
Suppose two consecutive integers are given; call them m and m+1. By the parity
property , either m is even or m is odd.
1.(m is even): In this case , m = 2k for some integer k, and so m+1 = 2k + 1, which is
odd. Hence in this case one of m and m+1 is even and the other is odd
2.(m is odd): In this case, m = 2k + 1 for some integer k, and so m+1 = (2k+1) + 1 = 2k
+ 2 = 2(k+1). But k=1 is an integer because it is the sum of two integer. Therefore
m+1 equals twice some integer, and thus m+1 is even. Hence in this case also, one of
m and m+1 is even and the other is odd.
It follows regardless of which case actually occurs for the particular m and m+1 that
are chosen, one of m and m+1 is odd and the other is even.
This is an example of a proof involving a division into cases.
Integers Modulo 4
Show that any integer can be written in one of four forms
n = 4q or
n = 4q + 1
or n = 4q + 2 or
n = 4q + 3
For some integer q.
Solution: Given any integer n, apply the quotient-remainder theorem to n with d = 4.
This implies that there exists an integer quotient q and a remainder r such that
n = 4q + r
and
0 ≤ r < 4.
But the only nonnegative remainders r that are less than 4 are 0, 1, 2, and 3. Hence
n = 4q or
for some integer q.
n = 4q + 1
or n = 4q + 2 or
n = 4q + 3
Where to Start a proof
Theorem: The square of any odd integer has the form 8m + 1 for some integer m.
Proof: See Textbook page 162.
Developing a proofs is a work of art.
This proof is another beautiful piece of work; but, of limited value to IT students.
However, The discussion about how to “get started” is interesting:
You may need to try many different approaches before finding one that works.
There is no ‘formula’ for finding an approach that works!
In this case, thinking of integers in their modulo 4 representation works.
And, from Textbook page 133: “Donald Knuth, one of the pioneers of the science of
computing, has compared constructing a computer program from a set of specifications
to writing a mathematical proof from a set of axioms”
So, as interesting as the proofs are, we are even more interested in the style of thinking
necessary to develop them.
Non-examinable content
1. Section 3.5 - floor and ceiling functions:
• functions produce integers immediately above and below a real number
• a farmer with 2.5 boxes of fruit must use 3 boxes!
• many IT applications
2. Section 3.6 – proof by contradiction and contraposition:
• by contradiction: make supposition and derive contradiction
• by contrapositive: from Week 1 p → q ≡ ~q → ~p
to prove if p then q, derive ~p from ~q
3. Section 3.7 – two classic theorems:
• the square root of 2 is irrational; this really annoyed the Greeks (page 180)!
• there are an infinite number of primes (good for cryptography)!
4. Section 3.8 - algorithms:
• of interest to IT students
• number theory can be used in many useful algorithms
• Example: Euclidean Algorithm to calculate greatest common divisor (GCD)…
Greatest Common Divisor
Greatest common divisor (GCD) is as the name suggests…
GCD of: 21 and 12 is 3
27 and 18 is 9
132 and 48 is ?
21 and 10 is ?
With a > b ≥ 0:
(Textbook page 193)
Hint: 48 = 24 • 3, 132 = 22 • 3 • 11
GCD(a,b) = GCD(b,r) where r = a mod b
GCD(a,0) = a
So:
GCD(924,252) = GCD(252,168)
GCD(252,168) = GCD(168,84)
GCD(168,84) = GCD(84,0)
GCD(84,0) = 84
Hence:
GCD(924,252) = 84
where 168 = 924 mod 252
where 84 = 252 mod 168
where 0 = 168 mod 84
The Euclidean Algorithm implements this approach…
Euclidean Algorithm
Euclidean Algorithm: To calculate greatest common divisor (GCD) of two integers.
[Given two integers A and B with A > B ≥ 0, this algorithm computes GCD(A,B).
Algorithm uses two facts about integers a and b with a > b ≥ 0:
1. GCD(a,b) = GCD(b,r) where r = a mod b
2. GCD(a,0) = a]
Input: A, B [integers with A > B ≥ 0]
Algorithm Body:
a := A, b := B, r := B
[While b ≠ 0, compute r = a mod b and replace a with b and b with r.]
while (b ≠ 0)
r := a mod b
a := b
b := r
end while
[On exit from while loop, b = 0; so, GCD(a,b) = GCD(a,0) = a.]
GCD: = a
Output: GCD [a positive integer]
Greatest Common Divisor application
If the GCD of two integers is 1, they are coprime (e.g., 21 and 10).
Many IT applications for coprime integers, including the RSA algorithm:
First four steps in RSA algorithm (http://en.wikipedia.org/wiki/RSA) are: