1.33k likes | 1.49k Views
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.”
E N D
Sets and predicates Programming Fundamentals 9 Feliks Kluźniak
Logic and daily life (a digression) Sets and Predicates
Logic and daily life (a digression) “Requirement: Native Speaker of Mandarin & Hindi.” Sets and Predicates
Logic and daily life (a digression) “Requirement: Native Speaker of Mandarin & Hindi.” There is a huge difference between “and” and “or”. Sets and Predicates
Logic and daily life (a digression) “No bikes allowed.” Sets and Predicates
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
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
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!
Sentential Calculus (a.k.a. Propositional Logic) Sets and Predicates
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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