Download presentation

Presentation is loading. Please wait.

Published byKaren Collie Modified about 1 year ago

1
CMPF144 FUNDAMENTALS OF COMPUTING THEORY Module 7: Beyond Classical Logic

2
Module 7CMPF144 Fundamentals of Computing TheorySlide 2 Objectives To present and discuss some example of classical paradoxes. To discuss the importance of recursion and its benefits and weaknesses

3
Module 7CMPF144 Fundamentals of Computing TheorySlide 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.

4
Module 7CMPF144 Fundamentals of Computing TheorySlide 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.

5
Module 7CMPF144 Fundamentals of Computing TheorySlide 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 themselves Question: Does the barber shave himself?

6
Module 7CMPF144 Fundamentals of Computing TheorySlide 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.

7
Module 7CMPF144 Fundamentals of Computing TheorySlide 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.

8
Module 7CMPF144 Fundamentals of Computing TheorySlide 8 Recursion Recursion is a theme that is found and explored: in language and literature in music in mathematics in art and in computing

9
Module 7CMPF144 Fundamentals of Computing TheorySlide 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.

10
Module 7CMPF144 Fundamentals of Computing TheorySlide 10 Recursion (Paradox) Paradox can be an example of recursion Example: The Epimenides paradox Epimenides 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.

11
Module 7CMPF144 Fundamentals of Computing TheorySlide 11 Recursion (Paradox)

12
Module 7CMPF144 Fundamentals of Computing TheorySlide 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.

13
Module 7CMPF144 Fundamentals of Computing TheorySlide 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?

14
Module 7CMPF144 Fundamentals of Computing TheorySlide 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."

15
Module 7CMPF144 Fundamentals of Computing TheorySlide 15 Recursion (Paradox) These are the example of axioms : a) = 2 b) Distance between 1 and 2 to be exactly the one between 2 and 3

16
Module 7CMPF144 Fundamentals of Computing TheorySlide 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.

17
Module 7CMPF144 Fundamentals of Computing TheorySlide 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 case 2. And a simpler version of the problem that might approach the base case.

18
Module 7CMPF144 Fundamentals of Computing TheorySlide 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 * 1 Or, 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.

19
Module 7CMPF144 Fundamentals of Computing TheorySlide 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) * ….

20
Module 7CMPF144 Fundamentals of Computing TheorySlide 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); }

21
Module 7CMPF144 Fundamentals of Computing TheorySlide 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

22
Module 7CMPF144 Fundamentals of Computing TheorySlide 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.

23
Module 7CMPF144 Fundamentals of Computing TheorySlide 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 4 3 or power (5,5) means 5 5

24
Module 7CMPF144 Fundamentals of Computing TheorySlide 24 The END

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google