Intro to computer science module 2

391 views

Published on

Revision uploaded March 14, 2014

This is module 2 of an introductory course that will introduce computer science and software engineering to the novice, and it is also a course that will teach even veteran computer scientists some new concepts, or explain concepts they thought they understood well. Concepts are introduced with hands on experience using object-oriented pseudo code (which can very easily be translated to C#, Java, C++, etc.) and functional programming pseudo code (which can easily be translated into F#, Erlang, Python, Haskell, etc.)

Published in: Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
391
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
21
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Intro to computer science module 2

  1. 1. Foundations of Computer Science and Software Engineering module 2/30 WALID S. SABA
  2. 2. Foundations of Computer Science and Software Engineering ALBERT EINSTIEN TO THE TEACHER
  3. 3. Foundations of Computer Science and Software Engineering TO THE STUDENT SOCRATES
  4. 4. Foundations of Computer Science and Software Engineering About this Course This is an introductory course that will introduce computer science and software engineering to the novice, and it is also a course that will teach even veteran computer scientists some new concepts, or explain concepts they thought they understood well. Concepts are introduced with hands on experience using object-oriented pseudo code (which can very easily be translated to C#, Java, C++, etc.) and functional programming pseudo code (which can easily be translated into F#, Erlang, Python, Haskell, etc.) About the Author Walid Saba has 20 years of experience in information technology, where he worked at such places as the American Institutes for Research, AT&T Bell Labs, Metlife, Nortel Networks, IBM and Cognos. He has also spent 7 years in academia where he has taught computer science at Carelton University, the New Jersey Institute of Technology, the University of Windsor, and the American University of Beirut. He has published over 30 technical articles, including an award wining paper that he recieved at KI-2008 in Germany. Walid holds a PhD in Computer Science which he obtained from Carleton University in1999
  5. 5. MODULE 2 (1 hour) MATHEMATICAL PRILIMENARIES – LOGIC Foundations of Computer Science and Software Engineering
  6. 6. Introduction to Computer Science – Preliminaries
  7. 7. Introduction to Computer Science – Preliminaries
  8. 8. Introduction to Computer Science – Preliminaries
  9. 9. Introduction to Computer Science – Preliminaries Huh?
  10. 10. Propositional Logic Introduction to Computer Science – Preliminaries Logic is a system of reasoning to systematically determine the soundness (or validity) of an argument
  11. 11. Propositional Logic Introduction to Computer Science – Preliminaries The simplest logical system is that of “propositional logic” – which is roughly equivalent to what is also known in computer science and computer engineering as “Boolean algebra” Logic is a system of reasoning to systematically determine the soundness (or validity) of an argument
  12. 12. Propositional Logic Introduction to Computer Science – Preliminaries Logic is a system of reasoning to systematically determine the soundness (or validity) of an argument The simplest logical system is that of “propositional logic” – which is roughly equivalent to what is also known in computer science and computer engineering as “Boolean algebra” Sentences (or declarative statements) that express or declare some proposition, are assigned the value True or False
  13. 13. Propositional Logic Introduction to Computer Science – Preliminaries Sentences (or declarative statements) that express or declare some proposition, are assigned the value True or False
  14. 14. Propositional Logic Introduction to Computer Science – Preliminaries Sentences (or declarative statements) that express or declare some proposition, are assigned the value True or False Examples of sentences that can be assigned True or False:
  15. 15. Propositional Logic Introduction to Computer Science – Preliminaries Sentences (or declarative statements) that express or declare some proposition, are assigned the value True or False Examples of sentences that can be assigned True or False:
  16. 16. Propositional Logic Introduction to Computer Science – Preliminaries Sentences (or declarative statements) that express or declare some proposition, are assigned the value True or False Examples of sentences that can be assigned True or False:
  17. 17. Propositional Logic Introduction to Computer Science – Preliminaries Sentences (or declarative statements) that express or declare some proposition, are assigned the value True or False Examples of sentences that can be assigned True or False:
  18. 18. Propositional Logic Introduction to Computer Science – Preliminaries Simple sentences (that are assigned a truth value such as True or False) can be combined into compound statements (that are also be assigned a truth value)
  19. 19. Propositional Logic Introduction to Computer Science – Preliminaries Simple sentences (that are assigned a truth value such as True or False) can be combined into compound statements (that are also be assigned a truth value) Everyone in France Speaks Chinese The moon is made of cheese Introduction to Computer Science – Preliminaries
  20. 20. Propositional Logic Introduction to Computer Science – Preliminaries Simple sentences (that are assigned a truth value such as True or False) can be combined into compound statements (that are also be assigned a truth value) Everyone in France Speaks Chinese AND The moon is made of cheese Introduction to Computer Science – Preliminaries
  21. 21. Propositional Logic Introduction to Computer Science – Preliminaries Simple sentences (that are assigned a truth value such as True or False) can be combined into compound statements (that are also be assigned a truth value) Everyone in France Speaks Chinese The moon is made of cheese Introduction to Computer Science – Preliminaries
  22. 22. Propositional Logic Introduction to Computer Science – Preliminaries Simple sentences (that are assigned a truth value such as True or False) can be combined into compound statements (that are also be assigned a truth value) Everyone in France Speaks Chinese OR The moon is made of cheese Introduction to Computer Science – Preliminaries
  23. 23. Propositional Logic Introduction to Computer Science – Preliminaries Simple sentences (that are assigned a truth value such as True or False) can be combined into compound statements (that are also be assigned a truth value) If Everyone in France Speaks Chinese Then The moon is made of cheese Introduction to Computer Science – Preliminaries
  24. 24. Propositional Logic Introduction to Computer Science – Preliminaries Simple sentences (that are assigned a truth value such as True or False) can be combined into compound statements (that are also be assigned a truth value) If Everyone in France Speaks Chinese Then The moon is made of cheese Introduction to Computer Science – Preliminaries
  25. 25. Propositional Logic Introduction to Computer Science – Preliminaries Simple sentences (that are assigned a truth value such as True or False) can be combined into compound statements (that are also be assigned a truth value) It is NOT True that Everyone in France Speaks Chinese Introduction to Computer Science – Preliminaries
  26. 26. Propositional Logic Introduction to Computer Science – Preliminaries If we have two propositions (sentences, or declarative statements), p and q, then we can say: Introduction to Computer Science – Preliminaries
  27. 27. Propositional Logic Introduction to Computer Science – Preliminaries If we have two propositions (sentences, or declarative statements), p and q, then we can say: Introduction to Computer Science – Preliminaries
  28. 28. Propositional Logic Introduction to Computer Science – Preliminaries If we have two propositions (sentences, or declarative statements), p and q, then we can say: Introduction to Computer Science – Preliminaries
  29. 29. Propositional Logic Introduction to Computer Science – Preliminaries If we have two propositions (sentences, or declarative statements), p and q, then we can say: Introduction to Computer Science – Preliminaries
  30. 30. Propositional Logic Introduction to Computer Science – Preliminaries If we have two propositions (sentences, or declarative statements), p and q, then we can say: Introduction to Computer Science – Preliminaries
  31. 31. Propositional Logic Introduction to Computer Science – Preliminaries According to the above, we can make an infinite number of sentences, such as Introduction to Computer Science – Preliminaries
  32. 32. Propositional Logic Introduction to Computer Science – Preliminaries But if we know the truth values of two simple sentences, how do we determine the truth value of a compound sentence? T T F F T F T F T F F F T T F F T F T F T T T F T T F F T F T F T F F T T F T T p and q is true when both are true, and false otherwise p or q is true when either one is true, otherwise it is false if p then q is false only when p is true and q is false not p is false when p is true & true when p is false Introduction to Computer Science – Preliminaries
  33. 33. Propositional Logic Introduction to Computer Science – Preliminaries iff (if and only if), or as it is also called bi-directional if or equivalence Introduction to Computer Science – Preliminaries
  34. 34. Equivalence Introduction to Computer Science – Preliminaries Two formulas P and Q are equivalent iff (if and only if) they have the same truth value for every truth value assignment of their symbols. We write Introduction to Computer Science – Preliminaries
  35. 35. Equivalence Introduction to Computer Science – Preliminaries Two formulas P and Q are equivalent iff (if and only if) they have the same truth value for every truth value assignment of their symbols. We write EXAMPLE Introduction to Computer Science – Preliminaries
  36. 36. Equivalence Introduction to Computer Science – Preliminaries All possible truth value assignments of P and Q Two formulas P and Q are equivalent iff (if and only if) they have the same truth value for every truth value assignment of their symbols. We write EXAMPLE Introduction to Computer Science – Preliminaries
  37. 37. Equivalence Introduction to Computer Science – Preliminaries All possible truth value assignments of P and Q Two formulas P and Q are equivalent iff (if and only if) they have the same truth value for every truth value assignment of their symbols. We write EXAMPLE Introduction to Computer Science – Preliminaries
  38. 38. Equivalence Introduction to Computer Science – Preliminaries All possible truth value assignments of P and Q Two formulas P and Q are equivalent iff (if and only if) they have the same truth value for every truth value assignment of their symbols. We write EXAMPLE Introduction to Computer Science – Preliminaries
  39. 39. Equivalence Introduction to Computer Science – Preliminaries All possible truth value assignments of P and Q These two statements have the same truth value for every truth value assignment of P and Q, and thus they are equivalent Two formulas P and Q are equivalent iff (if and only if) they have the same truth value for every truth value assignment of their symbols. We write EXAMPLE Introduction to Computer Science – Preliminaries
  40. 40. Introduction to Computer Science – Preliminaries Validity A formula is valid if it is true for every possible truth assignment of its symbols. Or, a formula is valid if it cannot be made false for any truth assignment Introduction to Computer Science – Preliminaries
  41. 41. Introduction to Computer Science – Preliminaries Validity A formula is valid if it is true for every possible truth assignment of its symbols. Or, a formula is valid if it cannot be made false for any truth assignment AS A TRIVIAL EXAMPLE is a formula that is always true – cannot be false! Introduction to Computer Science – Preliminaries
  42. 42. Introduction to Computer Science – Preliminaries Validity A formula is valid if it is true for every possible truth assignment of its symbols. Or, a formula is valid if it cannot be made false for any truth assignment AS A TRIVIAL EXAMPLE is a formula that is always true – cannot be false! Let us try something more interesting. Is the following a valid formula? Introduction to Computer Science – Preliminaries
  43. 43. Introduction to Computer Science – Preliminaries Validity A formula is valid if it is true for every possible truth assignment of its symbols. Or, a formula is valid if it cannot be made false for any truth assignment AS A TRIVIAL EXAMPLE is a formula that is always true – cannot be false! Let us try something more interesting. Is the following a valid formula? It seems like this is a sound (valid) statement, since the formula states the following: Introduction to Computer Science – Preliminaries
  44. 44. Introduction to Computer Science – Preliminaries Validity A formula is valid if it is true for every possible truth assignment of its symbols. Or, a formula is valid if it cannot be made false for any truth assignment AS A TRIVIAL EXAMPLE is a formula that is always true – cannot be false! Let us try something more interesting. Is the following a valid formula? It seems like this is a sound (valid) statement, since the formula states the following: saying it is not true that both p and q are true Introduction to Computer Science – Preliminaries
  45. 45. Introduction to Computer Science – Preliminaries Validity A formula is valid if it is true for every possible truth assignment of its symbols. Or, a formula is valid if it cannot be made false for any truth assignment AS A TRIVIAL EXAMPLE is a formula that is always true – cannot be false! Let us try something more interesting. Is the following a valid formula? It seems like this is a sound (valid) statement, since the formula states the following: saying it is not true that both p and q are true is exactly like saying Introduction to Computer Science – Preliminaries
  46. 46. Introduction to Computer Science – Preliminaries AS A TRIVIAL EXAMPLE is a formula that is always true – cannot be false! Let us try something more interesting. Is the following a valid formula? It seems like this is a sound (valid) statement, since the formula states the following: saying it is not true that both p and q are true is exactly like saying either p is false or q is false Validity A formula is valid if it is true for every possible truth assignment of its symbols. Or, a formula is valid if it cannot be made false for any truth assignment Introduction to Computer Science – Preliminaries
  47. 47. Introduction to Computer Science – Preliminaries Validity A formula is valid if it is true for every possible truth assignment of its symbols. Or, a formula is valid if it cannot be made false for any truth assignment AS A TRIVIAL EXAMPLE is a formula that is always true – cannot be false! Let us try something more interesting. Is the following a valid formula? It seems like this is a sound (valid) statement, since the formula states the following: saying it is not true that both p and q are true is exactly like saying either p is false or q is false Which seems reasonable Introduction to Computer Science – Preliminaries
  48. 48. Introduction to Computer Science – Preliminaries Validity While it sounds reasonable to claim that is a valid statement, we need to systematically check if this statement is true for every truth assignment of p and q Introduction to Computer Science – Preliminaries
  49. 49. Introduction to Computer Science – Preliminaries Validity While it sounds reasonable to claim that is a valid statement, we need to systematically check if this statement is true for every truth assignment of p and q Introduction to Computer Science – Preliminaries
  50. 50. Introduction to Computer Science – Preliminaries Validity While it sounds reasonable to claim that is a valid statement, we need to systematically check if this statement is true for every truth assignment of p and q Introduction to Computer Science – Preliminaries
  51. 51. Introduction to Computer Science – Preliminaries Validity While it sounds reasonable to claim that is a valid statement, we need to systematically check if this statement is true for every truth assignment of p and q Introduction to Computer Science – Preliminaries
  52. 52. Introduction to Computer Science – Preliminaries Validity While it sounds reasonable to claim that is a valid statement, we need to systematically check if this statement is true for every truth assignment of p and q Introduction to Computer Science – Preliminaries
  53. 53. Introduction to Computer Science – Preliminaries Validity While it sounds reasonable to claim that is a valid statement, we need to systematically check if this statement is true for every truth assignment of p and q This statement is valid since it cannot be made false, or since it is true for every possible truth assignment of p and q Introduction to Computer Science – Preliminaries
  54. 54. Introduction to Computer Science – Preliminaries Satisfiability A formula is satisfiable if there is at least one possible truth assignment that will make it true – otherwise, we say the formula is unsatisfiable AS A TRIVIAL EXAMPLE is a formula that is satisfiable since it can be made true when p is true or when q is false Introduction to Computer Science – Preliminaries
  55. 55. Introduction to Computer Science – Preliminaries Satisfiability A formula is satisfiable if there is at least one possible truth assignment that will make it true – otherwise, we say the formula is unsatisfiable AS A TRIVIAL EXAMPLE is a formula that is satisfiable since it can be made true when p is true or when q is false Now, is the formula satisfiable? Introduction to Computer Science – Preliminaries
  56. 56. Introduction to Computer Science – Preliminaries Satisfiability A formula is satisfiable if there is at least one possible truth assignment that will make it true – otherwise, we say the formula is unsatisfiable AS A TRIVIAL EXAMPLE is a formula that is satisfiable since it can be made true when p is true or when q is false Now, is the formula satisfiable? Are there truth values for r, p and q that will make it true? Introduction to Computer Science – Preliminaries
  57. 57. Introduction to Computer Science – Preliminaries Satisfiability A formula is satisfiable if there is at least one possible truth assignment that will make it true – otherwise, we say the formula is unsatisfiable AS A TRIVIAL EXAMPLE is a formula that is satisfiable since it can be made true when p is true or when q is false Now, is the formula satisfiable? Are there truth values for r, p and q that will make it true? If it can be made true, in how many ways? Introduction to Computer Science – Preliminaries
  58. 58. Introduction to Computer Science – Preliminaries Satisfiability Introduction to Computer Science – Preliminaries
  59. 59. Introduction to Computer Science – Preliminaries Satisfiability This statement can be made true ... Introduction to Computer Science – Preliminaries
  60. 60. Introduction to Computer Science – Preliminaries Satisfiability If we have the following: Introduction to Computer Science – Preliminaries
  61. 61. Introduction to Computer Science – Preliminaries Satisfiability Which means we have the following: Introduction to Computer Science – Preliminaries
  62. 62. Introduction to Computer Science – Preliminaries Satisfiability The OR statement can be made true in three ways Introduction to Computer Science – Preliminaries
  63. 63. Introduction to Computer Science – Preliminaries Satisfiability So we have 3 possible ways to make our formula true (so it satisfiable in 3 ways) Introduction to Computer Science – Preliminaries
  64. 64. Introduction to Computer Science – Preliminaries Satisfiability So we have 3 possible ways to make our formula true (so it satisfiable in 3 ways) An alternative to this process is to make the entire truth table and select at the end the rows for which the last formula comes out to be true. For a formula with 3 symbols this might not be too much, but what if we had 6 or 10 symbols? Introduction to Computer Science – Preliminaries
  65. 65. Introduction to Computer Science – Preliminaries Satisfiability So we have 3 possible ways to make our formula true (so it satisfiable in 3 ways) Try it out! Plug the different truth values of the three combinations we arrived at to see if the original formula comes out to be true! Introduction to Computer Science – Preliminaries
  66. 66. Applications of Propositional Logic Introduction to Computer Science – Preliminaries DIGITAL REPRESENTATION OF DECIMAL DIGITS Every digit is displayed by turning some variables ON (true) and some variables OFF (false)
  67. 67. Applications of Propositional Logic Introduction to Computer Science – Preliminaries DIGITAL REPRESENTATION OF DECIMAL DIGITS Every digit is displayed by turning some variables ON (true) and some variables OFF (false)
  68. 68. Applications of Propositional Logic Introduction to Computer Science – Preliminaries DIGITAL REPRESENTATION OF DECIMAL DIGITS ? Every digit is displayed by turning some variables ON (true) and some variables OFF (false)
  69. 69. Limitations of Propositional Logic Introduction to Computer Science – Preliminaries Consider the following declarative sentences:
  70. 70. Limitations of Propositional Logic Introduction to Computer Science – Preliminaries Consider the following declarative sentences: Assuming that p and q are true (that is, assuming we agreed that p and q are true), then r should follow from p and q. In other words this statement should be a valid (always true)
  71. 71. Limitations of Propositional Logic Introduction to Computer Science – Preliminaries Consider the following declarative sentences: Assuming that p and q are true (that is, assuming we agreed that p and q are true), then r should follow from p and q. In other words this statement should be a valid (always true) But this statement is not valid – it is not true for all possible truth values of p, q and r
  72. 72. Limitations of Propositional Logic Introduction to Computer Science – Preliminaries Consider the following declarative sentences: Assuming that p and q are true (that is, assuming we agreed that p and q are true), then r should follow from p and q. In other words this statement should be a valid (always true) But this statement is not valid – it is not true for all possible truth values of p, q and r WHAT WENT WRONG?
  73. 73. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries It turns out that certain valid inferences cannot be made in propositional logic, and a more powerful logic is needed
  74. 74. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries It turns out that certain valid inferences cannot be made in propositional logic, and a more powerful logic is needed First-Order Logic (FOL), or the Predicate Calculus, as it is also called, introduces predicates, quantifiers and variables
  75. 75. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries It turns out that certain valid inferences cannot be made in propositional logic, and a more powerful logic is needed First-Order Logic (FOL), or the Predicate Calculus, as it is also called, introduces predicates, quantifiers and variables
  76. 76. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries Variables introduced by quantifiers have scope
  77. 77. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries Variables introduced by quantifiers have scope This is the scope of the variable x
  78. 78. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries Variables introduced by quantifiers have scope This is the scope of the variable x This is the scope of the variable y
  79. 79. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries Variables introduced by quantifiers have scope This is the scope of the variable x This is the scope of the variable y Note that the scope of y is within the scope of x
  80. 80. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries Variables introduced by quantifiers have scope This is the scope of the variable x This is the scope of the variable y Note that the scope of y is within the scope of x Later in the course we will see that the notion of introducing and defining variables in a certain scope in programming languages is exactly the same as that in first- order logic
  81. 81. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries Example predicates Is true if the square of x is y
  82. 82. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries Example predicates Is true if the square of x is y Is true if x is positive
  83. 83. First-Order Logic (FOL) Introduction to Computer Science – Preliminaries Example predicates Is true if the square of x is y Is true if x is positive For any x and for any y, if y is the square of x, then y is positive
  84. 84. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Inference Rules in Logic: Modus Ponens (MP) An important rule of inference in propositional logic is called modus ponens, which can be described as follows:
  85. 85. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries An important rule of inference in propositional logic is called modus ponens, which can be described as follows: The rule says: if p implies q, and we can establish p, therefore we can conclude q. Inference Rules in Logic: Modus Ponens (MP)
  86. 86. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries The modus ponens inference rule states the following: if p implies q, and p, then q Inference Rules in Logic: Modus Ponens (MP)
  87. 87. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries The modus ponens inference rule states the following: if p implies q, and p, then q The modus ponens inference rule is a valid inference rule, since it is true for all possible truth value assignments of p and q Inference Rules in Logic: Modus Ponens (MP)
  88. 88. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries The modus ponens inference rule states the following: if p implies q, and p, then q The modus ponens inference rule is a valid inference rule, since it is true for all possible truth value assignments of p and q Inference Rules in Logic: Modus Ponens (MP)
  89. 89. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries The modus ponens inference rule states the following: if p implies q, and p, then q The modus ponens inference rule is a valid inference rule, since it is true for all possible truth value assignments of p and q Inference Rules in Logic: Modus Ponens (MP)
  90. 90. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries The modus ponens inference rule states the following: if p implies q, and p, then q The modus ponens inference rule is a valid inference rule, since it is true for all possible truth value assignments of p and q Inference Rules in Logic: Modus Ponens (MP)
  91. 91. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries The modus ponens inference rule states the following: if p implies q, and p, then q The modus ponens inference rule is a valid inference rule, since it is true for all possible truth value assignments of p and q Inference Rules in Logic: Modus Ponens (MP)
  92. 92. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Other Inference Rules Other basic but important inference rules include the following:
  93. 93. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Other Inference Rules Other basic but important inference rules include the following: If p is true, and q is true, then we can infer (p and q)
  94. 94. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Other Inference Rules Other basic but important inference rules include the following: If (p and q) is true, the we can infer p and we can infer q If p is true, and q is true, then we can infer (p and q)
  95. 95. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Other Inference Rules Other basic but important inference rules include the following: If (p and q) is true, the we can infer p and we can infer q (elimination) if (not p or q) is true, and we know p is true, then q must be true If p is true, and q is true, then we can infer (p and q)
  96. 96. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Inferences in FOL Let us now re-consider this argument and use first order logic to make this inference:
  97. 97. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Inferences in FOL Let us now re-consider this argument and use first order logic to make this inference: Let us introduce these predicates: True if x is a mathematician True if x is clever
  98. 98. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Inferences in FOL
  99. 99. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Inferences in FOL 1.
  100. 100. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Inferences in FOL 1. 2.
  101. 101. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Inferences in FOL 1. 2. 3.
  102. 102. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Inferences in FOL 1. 2. 3. 4.
  103. 103. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning Let us see how we can use FOL in data and information representation and reasoning Suppose we want to represent the blocks world depicted graphically below, where the goal is stack all the blocks from A (at the top) to E (at the bottom) and where the rule that we should follow is that a block cannot be placed on top of another block unless it precedes it alphabetically
  104. 104. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning Representing the domain – predicates to describe the domain
  105. 105. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning Representing the domain – predicates to describe the domain
  106. 106. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning If block x is not stacked, and block x precedes y, and block y is free, then block x can be placed on top of block y Representing the domain – rules of movement
  107. 107. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning Representing the domain – domain knowledge If block x precedes y, and block y precedes z, then block x precedes block y
  108. 108. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning Representing the domain – describing the state of affairs
  109. 109. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning Representing the domain – describing the state of affairs
  110. 110. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning Representing the domain – describing the state of affairs
  111. 111. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries Using FOL in Representation and Reasoning Representing the domain – describing the state of affairs
  112. 112. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries FOL in Computing Science FOL can be used to define sets and relations As an example, let us define the predicate even 0 is even (or, that 0 is even is true!) Any number is even if the one preceding it is not
  113. 113. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries FOL in Computing Science Let us test this definition
  114. 114. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries FOL in Computing Science Let us test this definition
  115. 115. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries FOL in Computing Science Let us test this definition Check using the above definition of even if even(5) comes out to be true or false
  116. 116. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries FOL in Computing Science Let us test this definition Later in the course you will see how we can write a simple function/program to test whether some input number is an even number of not
  117. 117. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries FOL in Computing Science Sets, which are unordered collections of objects, can be defined using predicates in FOL The sets A and B have the same objects. A is defined intensionally, i.e., using logical formulas, and B is defined extensionally, i.e., by actually enumerating the actual objects
  118. 118. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries FOL in Computing Science Sets, which are unordered collections of objects, can be defined using predicates in FOL The sets A and B have the same objects. A is defined intensionally, i.e., using logical formulas, and B is defined extensionally, i.e., by actually enumerating the actual objects Define the set that would contain the elements {3, 7, 9, 11} without listing the elements but using the predicate even
  119. 119. Introduction to Computer Science – PreliminariesIntroduction to Computer Science – Preliminaries FOL in Computing Science Sets, which are unordered collections of objects, can be defined using predicates in FOL The sets A and B have the same objects. A is defined intensionally, i.e., using logical formulas, and B is defined extensionally, i.e., by actually enumerating the actual objects Sets, relations (between sets) and functions will be the subject of the next module!
  120. 120. Introduction to Computer Science END OF MODULE 2 MATHEMATICAL PRILIMENARIES – SETS, RELATIONS AND FUNCTIONS Next module

×