1 / 133

Sets and predicates

Sets and predicates. Programming Fundamentals 9 Feliks Klu ź niak. Logic and daily life (a digression). Logic and daily life (a digression) “Requirement: Native Speaker of Mandarin & Hindi.”. Logic and daily life (a digression) “Requirement: Native Speaker of Mandarin & Hindi.”

moral
Download Presentation

Sets and predicates

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sets and predicates Programming Fundamentals 9 Feliks Kluźniak

  2. Logic and daily life (a digression) Sets and Predicates

  3. Logic and daily life (a digression) “Requirement: Native Speaker of Mandarin & Hindi.” Sets and Predicates

  4. Logic and daily life (a digression) “Requirement: Native Speaker of Mandarin & Hindi.” There is a huge difference between “and” and “or”. Sets and Predicates

  5. Logic and daily life (a digression) “No bikes allowed.” Sets and Predicates

  6. Logic and daily life (a digression) “No bikes allowed.” This is at least ambiguous. Negation normally binds very strongly, so one can read this as “(No bikes) allowed.” Sets and Predicates

  7. Logic and daily life (a digression) “No bikes allowed.” This is at least ambiguous. Negation normally binds very strongly, so one can read this as “(No bikes) allowed.” In other words, “You don’t have to ride a bike.” . Sets and Predicates

  8. Logic and daily life (a digression) “No bikes allowed.” This is at least ambiguous. Negation normally binds very strongly, so one can read this as “(No bikes) allowed.” In other words, “You don’t have to ride a bike.” . Compare this with “Bikes not allowed.” Just one letter more, but what a difference!

  9. Sentential Calculus (a.k.a. Propositional Logic) Sets and Predicates

  10. Sentential Calculus (a.k.a. Propositional Logic) We use variables such as p, q, r to denote sentences (a.k.a. propositions) that are either unequivocally true or unequivocally false. Sets and Predicates

  11. Sentential Calculus (a.k.a. Propositional Logic) We use variables such as p, q, r to denote sentences (a.k.a. propositions) that are either unequivocally true or unequivocally false. Examples: ”The earth is flat.” ”France is a republic.” ”7 < 8” Sets and Predicates

  12. Sentential Calculus (a.k.a. Propositional Logic) We use variables such as p, q, r to denote sentences (a.k.a. propositions) that are either unequivocally true or unequivocally false. We introduce operations that are defined by ”truth tables”. Sets and Predicates

  13. Sentential Calculus (a.k.a. Propositional Logic) We use variables such as p, q, r to denote sentences (a.k.a. propositions) that are either unequivocally true or unequivocally false. We introduce operations that are defined by ”truth tables”. Negation: p not p true false false true Sets and Predicates

  14. Sentential Calculus (a.k.a. Propositional Logic) Conjunction:p q p and q false false false false true false true false false true true true Sets and Predicates

  15. Sentential Calculus (a.k.a. Propositional Logic) Conjunction:p q p and q false false false false true false true false false true true true This captures quite well the common meaning of the word ”and”. Sets and Predicates

  16. Sentential Calculus (a.k.a. Propositional Logic) Disjunction:p q p or q false false false false true true true false true true true true Sets and Predicates

  17. Sentential Calculus (a.k.a. Propositional Logic) Disjunction:p q p or q false false false false true true true false true true true true Notice that ” ’The earth is not flat’ or ’France is a republic’ ” is also true. So this is close, but not identical to the common meaning of the word ”or” (i.e., it’s not ”either - or”). Sets and Predicates

  18. Sentential Calculus (a.k.a. Propositional Logic) Implication:p q p implies q false false true false true true true false false true true true Sets and Predicates

  19. Sentential Calculus (a.k.a. Propositional Logic) Implication:p q p implies q false false true false true true true false false true true true Notice that ” ’The earth is flat’ implies ’France is a republic’ ” is also true. So this is not very close to the common meaning of the word ”implies”. Sets and Predicates

  20. Sentential Calculus (a.k.a. Propositional Logic) Implication:p q p implies q false false true false true true true false false true true true Implication could also have been defined as follows: p implies q = (not p) or q p not p q not p or q false truefalsetrue false truetruetrue true falsefalsefalse true falsetruetrue

  21. Sentential Calculus (a.k.a. Propositional Logic) Given such operations we can formulate a number of laws, which can be verified by means of case analysis on truth tables. Sets and Predicates

  22. Sentential Calculus (a.k.a. Propositional Logic) Given such operations we can formulate a number of laws, which can be verified by means of case analysis on truth tables. The law of the excluded middle: p or not p Sets and Predicates

  23. Sentential Calculus (a.k.a. Propositional Logic) Given such operations we can formulate a number of laws, which can be verified by means of case analysis on truth tables. The law of the excluded middle: p or not p De Morgan’s laws: not ( p and q ) = (not p) or (not q) not ( p or q ) = (not p) and (not q) etc. Exercise: verify these three laws. Sets and Predicates

  24. Sentential Calculus (a.k.a. Propositional Logic) Given such operations we can formulate a number of laws, which can be verified by means of case analysis on truth tables. We can also formulate inference rules that allow us to formally derive true sentences from other true sentences. Sets and Predicates

  25. Sentential Calculus (a.k.a. Propositional Logic) Given such operations we can formulate a number of laws, which can be verified by means of case analysis on truth tables. We can also formulate inference rulesthat allow us to formally derive true sentences from other true sentences. For example, here is the rule called modus ponens: p , p implies q q Sets and Predicates

  26. Sentential Calculus (a.k.a. Propositional Logic) Given such operations we can formulate a number of laws, which can be verified by means of case analysis on truth tables. We can also formulate inference rulesthat allow us to formally derive true sentences from other true sentences. For example, here is the rule called modus ponens: p , p implies q q If we know that p is true, and that p implies q , then we know that q is true. This captures the everyday meaning of ”implication” quite well.

  27. Sentential Calculus (a.k.a. Propositional Logic) Another example: ((p implies q) and (q implies p)) implies (p = q) p q p implies q q implies p p = q false false truetruetrue false true true false false true false false true false true true truetruetrue Sets and Predicates

  28. Sentential Calculus (a.k.a. Propositional Logic) Another example: ((p implies q) and (q implies p)) implies (p = q) and since we have also (p = q) implies ((p implies q) and (q implies p)) Exercise: verify this! Sets and Predicates

  29. Sentential Calculus (a.k.a. Propositional Logic) Another example: ((p implies q) and (q implies p))implies (p = q) and since we have also (p = q) implies ((p implies q) and (q implies p)) it follows that (p = q) = ((p implies q) and (q implies p)) Sets and Predicates

  30. Sentential Calculus (a.k.a. Propositional Logic) Another example: ((p implies q) and (q implies p))implies (p = q) and since we have also (p = q) implies ((p implies q) and (q implies p)) it follows that (p = q) = ((p implies q) and (q implies p)) This need not be verified by a truth table, as it is just an application of the first rule above, which has already been verified! Sets and Predicates

  31. Predicate calculus (aka. first-order logic) Instead of sentences that are unequivocally true or false, we consider statements (technically known as predicates) that may contain free variables ranging over some domain. Sets and Predicates

  32. Predicate calculus (aka. first-order logic) Instead of sentences that are unequivocally true or false, we consider statements (technically known as predicates) that may contain free variables ranging over some domain. Example: ”The average grade of x is B.” Here, x is a variable. The reason for calling it a free variable will become clear at the end of this lecture. Sets and Predicates

  33. Predicate calculus (aka. first-order logic) Instead of sentences that are unequivocally true or false, we consider statements (technically known as predicates) that may contain free variables ranging over some domain. Example: ”The average grade of x is B.” Whether or not the statement is true depends on what we substitute for x . For example, ”The average grade of John is B.” may be false, while ”The average grade of Mary is B.” may be true. Sets and Predicates

  34. Predicate calculus (aka. first-order logic) Instead of sentences that are unequivocally true or false, we consider statements (technically known as predicates) that may contain free variables ranging over some domain. Example: ”The average grade of x is B.” The domain is just some set. In this case we would expect it to be some set of students: the students in this class, all the students at UTD etc. Sets and Predicates

  35. Predicate calculus (aka. first-order logic) Instead of sentences that are unequivocally true or false, we consider statements (technically known as predicates) that may contain free variables ranging over some domain. Example: ”The average grade of x is B.” The domain is just some set. In this case we would expect it to be some set of students: the students in this class, all the students at UTD etc. Given a domain D, we can always find a subset (possibly empty) of D for which the statement is true: for example, the set of students in this class whose average grade is B. Sets and Predicates

  36. Predicate calculus (aka. first-order logic) Example: ”The average grade of x is B.” The domain is just some set. In this case we would expect it to be some set of students: the students in this class, all the students at UTD etc. Given a domain D, we can always find a subset (possibly empty) of D for which the statement is true: for example, the set of students in this class whose average grade is B. We say that the predicate describes (or characterizes) this set. Sets and Predicates

  37. Predicate calculus (aka. first-order logic) Example: ”The average grade of x is B.” The domain is just some set. In this case we would expect it to be some set of students: the students in this class, all the students at UTD etc. Given a domain D, we can always find a subset (possibly empty) of D for which the statement is true: for example, the set of students in this class whose average grade is B. We say that the predicate describes (or characterizes) this set. It is convenient to say that each element of the set is also described by the predicate, or satisfies the predicate. Sets and Predicates

  38. Predicate calculus (aka. first-order logic) Example: ”x < y” Here we have two variables. If the domain of each variable is the set of integers, then the predicate is satisfied by all pairs of integers such that the first is smaller than the other: 1 and 2, 1 and 11, 245 and 999 etc. y x < y x Sets and Predicates

  39. Predicate calculus (aka. first-order logic) Example: ”x < y” Here we have two variables. If the domain of each variable is the set of integers, then the predicate is satisfied by all pairs of integers such that the first is smaller than the other: 1 and 2, 1 and 11, 245 and 999 etc. We define the domain of the predicate as the Cartesian product of the domains of the variables on which its value depends: in this case, the set of all pairs of integers. Sets and Predicates

  40. Predicate calculus (aka. first-order logic) It is convenient to give the predicate a name, and explicitly show the variables on which its value depends: B_student( x ) : ”The grade average of x is B.” LT( x, y ) : x < y . Sets and Predicates

  41. Predicate calculus (aka. first-order logic) It is convenient to give the predicate a name, and explicitly show the variables on which its value depends: B_student( x ) : ”The grade average of x is B.” LT( x, y ) : x < y . We can then write things down succintly: B_student( John ) = false LT( 1, 11 ) = true Sets and Predicates

  42. Predicate calculus (aka. first-order logic) We can define operations on predicates, similar to the ones we have in sentential calculus. If we ground all the free variables of a predicate, i.e., give them specific values from their domains, then the predicate becomes a proposition. Sets and Predicates

  43. Predicate calculus (aka. first-order logic) We can define operations on predicates, similar to the ones we have in sentential calculus. If we ground all the free variables of a predicate, i.e., give them specific values from their domains, then the predicate becomes a proposition. Example: x < y - a predicate with two free variables Sets and Predicates

  44. Predicate calculus (aka. first-order logic) We can define operations on predicates, similar to the ones we have in sentential calculus. If we ground all the free variables of a predicate, i.e., give them specific values from their domains, then the predicate becomes a proposition. Example: x < y - a predicate with two free variables x < 17 - a predicate with one free variable Sets and Predicates

  45. Predicate calculus (aka. first-order logic) We can define operations on predicates, similar to the ones we have in sentential calculus. If we ground all the free variables of a predicate, i.e., give them specific values from their domains, then the predicate becomes a proposition. Example: x < y - a predicate with two free variables x < 17 - a predicate with one free variable 5 < y - a predicate with one free variable Sets and Predicates

  46. Predicate calculus (aka. first-order logic) We can define operations on predicates, similar to the ones we have in sentential calculus. If we ground all the free variables of a predicate, i.e., give them specific values from their domains, then the predicate becomes a proposition. Example: x < y - a predicate with two free variables x < 17 - a predicate with one free variable 5 < y - a predicate with one free variable 5 < 17 - a predicate with no free variables is a proposition Sets and Predicates

  47. Predicate calculus (aka. first-order logic) We can define operations on predicates, similar to the ones we have in sentential calculus. If we ground all the free variables of a predicate, i.e., give them specific values from their domains, then the predicate becomes a proposition. Example: x < y - a predicate with two free variables x < 17 - a predicate with one free variable 5 < y - a predicate with one free variable 5 < 17 - a predicate with no free variables is a proposition 17 < 3 - another grounding of the original predicate Sets and Predicates

  48. Predicate calculus (aka. first-order logic) We can define operations on predicates, similar to the ones we have in sentential calculus. If we ground all the free variables of a predicate, i.e., give them specific values from their domains, then the predicate becomes a proposition. We can then apply the standard operators of propositional logic. Example: 5 < 17 and not 17 < 3 . Sets and Predicates

  49. Predicate calculus (aka. first-order logic) We can define operations on predicates, similar to the ones we have in sentential calculus. If we ground all the free variables of a predicate, i.e., give them specific values from their domains, then the predicate becomes a proposition. We can then apply the standard operators of propositional logic. Example: 5 < 17 and not 17 < 3 . We can also apply the operators directly to the predicates, knowing that the entire formula becomes a proposition when we ground the variables. Example:x < y and not y < z . Sets and Predicates

  50. Predicate calculus (aka. first-order logic) Example:x < y and not y < z . In general, propositions that we obtain from a predicate with free variables can be true or false, depending on how we ground the variables. Example:5 < 17 and not 17 < 20 is false, but 5 < 17 and not 17 < 3 is true . Sets and Predicates

More Related