CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 7: Beyond Classical Logic.
-
Upload
karen-collie -
Category
Documents
-
view
222 -
download
3
Transcript of CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 7: Beyond Classical Logic.
CMPF144FUNDAMENTALS OF COMPUTING THEORY
Module 7: Beyond Classical Logic
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 2
Objectives
To present and discuss some example of classical paradoxes. To discuss the importance of recursion and its benefits and weaknesses
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 3
Paradox
Logical Paradox:
A paradox is generally a puzzling conclusion we seem to be driven towards by our reasoning, but which is highly counterintuitive, nevertheless.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 4
Paradox
A paradox is an apparently true statement that seems to lead to a logical self-contradiction, or to a situation that contradicts common intuition.
The identification of a paradox based on seemingly simple and reasonable concepts has often led to significant advances in science, philosophy and mathematics.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 5
The Barber Shop
In a certain village there is a man who is a barber. The barber shave all and only those men in the village who do not shave themselvesQuestion:
Does the barber shave himself?
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 6
Think!!!
Any man in this village is shaved by the barber if and only if he is not shaved by himself. Therefore in particular the barber shaves himself if and only if he does not. We are in trouble if we say the barber shaves himself and we are in trouble if we say he does not.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 7
Others…
There are many other paradoxes that can be discussed.
Epimenides paradox:
A Cretan says "All Cretans are liars".
Basically, the reason for this paradoxes is what we called a self-referral or circular-referral.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 8
Recursion
Recursion is a theme that is found and explored:
in language and literature
in music
in mathematics
in art
and in computing
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 9
Recursion
Recursion means self-referential. Something may be defined in terms of itself. Care must be taken not to create a circular reference which might lead to an endless regression, a paradox.
Recursion is a simple but very powerful concept.
Recursion means an instance (or instances) is derived from an exactly identical instance.
Recursion can go on and on infinitely.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 10
Recursion (Paradox)
Paradox can be an example of recursionExample:
The Epimenides paradoxEpimenides was a Cretan. He made the statement:"All Cretans are liars.“
If we believe this to be true, then Epimenides was lying. If he was lying, then Cretans tell the truth. But if Cretans tell the truth then…We are stuck in a strange loop, a paradox.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 11
Recursion (Paradox)
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 12
Recursion (Paradox)
Dutch artist, M.C. Escher, constructed optically challenging drawings.
Waterfall (see Figure 1), a lithograph, shows water flowing over the edge of an aqueduct turning a waterwheel in the same aqueduct.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 13
Recursion (Paradox)
Did the right hand draw the left hand first? Or did the left hand draw the right hand that draws the left hand?
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 14
Recursion (Paradox)
Mathematician Kurt Godel, challenged our understanding of number systems by stating his incompleteness theorem:
"All consistent axiomatic formulations of number theory include undecidable propositions."
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 15
Recursion (Paradox)
These are the example of axioms:a) 1 + 1 = 2b) Distance between 1 and 2 to be
exactly the one between 2 and 3
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 16
Recursion
From the definition of recursion, it can often lead to paradox. Such a definition is circular, or endlessly regressive.
In the perspective of the computer programmer, an endless loop.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 17
Recursion
A more precise definition says that recursion never defines something in terms of itself, but always in terms of simpler versions of itself. We try to break a problem into two parts:
1. The simplest case, sometimes called the base case2. And a simpler version of the problem that might approach the base case.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 18
Factorial
"n factorial" n! is the product: n * (n – 1) * (n – 2) … * 1, with 1! factorial defined to be 1, and 0! defined to be 1.
i.e.: 0! = 1 1! = 1
for example: 5! = 5 * 4 * 3 * 2 * 1Or, since 4! = 4 * 3 * 2 * 1 we can say that 5! is equal to 5 * 4!
The simplest version of the problem occurs when n is zero or one.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 19
Factorial
The slightly simpler version of the problem is generalized this way.
n! = n * (n – 1)!
(n – 1) * (n – 2)!
(n – 2) * (n – 3)!
n * (n – 1) * (n – 2) * (n – 3) * ….
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 20
Recursive Function
Let define a function called factorial(n)The definition of recursive function factorial(n) is:
factorial(n){
if(n == 0) then
return 1;else
n * factorial (n-1);}
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 21
Tracing
Example:factorial (5)
5*factorial(4)5*4*factorial(3)5*4*3*factorial(2)5*4*3*2*factorial(1)5*4*3*2*1*factorial(0)5*4*3*2*1*1 = 120
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 22
Recursive
In C or C++, when we say that a function is recursive, we mean that the function calls itself. In order to prevent endlessly regressive function calls, we carefully construct a recursive function such that it terminates when the base case is reached. If the base case is not reached, the function calls itself and sends a slightly simpler version of the problem as the argument.
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 23
Quiz 2
Based on the example, write a recursive function called power(m,n) where m is the base number and n is the power number. I.e power(4, 3) mean 43
or power (5,5) means 55
Module 7 CMPF144 Fundamentals of Computing Theory
Slide 24
The END