Download presentation
Presentation is loading. Please wait.
1
Discrete Math - Module #1 - Logic
2/19/2019 University of Florida Dept. of Computer & Information Science & Engineering COT 3100 Applications of Discrete Structures Dr. Michael P. Frank Slides for a Course Based on the Text Discrete Mathematics & Its Applications (5th Edition) by Kenneth H. Rosen A word about organization: Since different courses have different lengths of lecture periods, and different instructors go at different paces, rather than dividing the material up into fixed-length lectures, we will divide it up into “modules” which correspond to major topic areas and will generally take 1-3 lectures to cover. Within modules, we have smaller “topics”. Within topics are individual slides. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
2
Module #1: The Fundamentals of Logic
Discrete Math - Module #1 - Logic 2/19/2019 Module #1: The Fundamentals of Logic Rosen 5th ed., §§ ~81 slides, ~4 lectures In Spring 2003 I spent 7 fifty-minute lecture periods on this material, but two half-lectures were taken up by team selection and a quiz, so it really only took 6 lectures. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
3
Module #1: Foundations of Logic (§§1.1-1.3, ~3 lectures)
Discrete Math - Module #1 - Logic 2/19/2019 Module #1: Foundations of Logic (§§ , ~3 lectures) Mathematical Logic is a tool for working with elaborate compound statements. It includes: A formal language for expressing them. A concise notation for writing them. A methodology for objectively reasoning about their truth or falsity. It is the foundation for expressing formal proofs in all branches of mathematics. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
4
Foundations of Logic: Overview
Discrete Math - Module #1 - Logic 2/19/2019 Foundations of Logic: Overview Propositional logic (§ ): Basic definitions. (§1.1) Equivalence rules & derivations. (§1.2) Predicate logic (§ ) Predicates. Quantified predicate expressions. Equivalences & derivations. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
5
Propositional Logic (§1.1)
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1 – Propositional Logic Propositional Logic (§1.1) Propositional Logic is the logic of compound statements built from simpler statements using so-called Boolean connectives. Some applications in computer science: Design of digital electronic circuits. Expressing conditions in programs. Queries to databases & search engines. George Boole ( ) We normally attribute propositional logic to George Boole, who first formalized it. Actually the particular formal notation we will present is not precisely Boole’s; he originally spoke of logic in terms of sets, not propositions, and he also used Boolean algebra notation such as AB, A+B, rather than the A /\ B, A \/ B notation we will use. But, he was the first to mathematically formalize these kinds of concepts in preserved writings. Boole’s formalization of logic was developed further by the philosopher Frege. However, even though logic was not formalized as such until the 1800’s, the basic ideas of it go all the way back to the ancient Greeks. Aristotle (ca B.C.) developed a detailed system of logic (though one that was not quite as convenient and powerful as the modern one), and Chrysippus of Soli (ca B.C.) introduced a logic centered around logic AND, inclusive and exclusive OR, NOT, and implication, similarly to Boole’s. Chrysippus’ logic apparently included all of the key rules that Boole’s logic had. However, his original works were unfortunately lost; we only have fragments quoted by other authors. Chrysippus of Soli (ca. 281 B.C. – 205 B.C.) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
6
Definition of a Proposition
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1 – Propositional Logic Definition of a Proposition Definition: A proposition (denoted p, q, r, …) is simply: a statement (i.e., a declarative sentence) with some definite meaning, (not vague or ambiguous) having a truth value that’s either true (T) or false (F) it is never both, neither, or somewhere “in between!” However, you might not know the actual truth value, and, the truth value might depend on the situation or context. Later, we will study probability theory, in which we assign degrees of certainty (“between” T and F) to propositions. But for now: think True/False only! 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
7
Examples of Propositions
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1 – Propositional Logic Examples of Propositions “It is raining.” (In a given situation.) “Beijing is the capital of China.” • “1 + 2 = 3” But, the following are NOT propositions: “Who’s there?” (interrogative, question) “La la la la la.” (meaningless interjection) “Just do it!” (imperative, command) “Yeah, I sorta dunno, whatever...” (vague) “1 + 2” (expression with a non-true/false value) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
8
Operators / Connectives
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Operators / Connectives An operator or connective combines one or more operand expressions into a larger expression. (E.g., “+” in numeric exprs.) Unary operators take 1 operand (e.g., −3); binary operators take 2 operands (eg 3 4). Propositional or Boolean operators operate on propositions (or their truth values) instead of on numbers. Later in the course, we will see that operators can themselves be defined in terms of functions. This slide doesn’t define them that way because we haven’t defined functions yet. But for your reference, when you come back to study this section after learning about functions, in general, an n-ary operator O on any set S (the domain of the operator) is a function O:S^n->S mapping n-tuples of members of S (the operands) to members of S. “S^n” here denotes S with n as a superscript, that is, the nth Cartesian power of S. All this will be defined later when we talk about set theory. For Boolean operators, the set we are dealing with is B={True,False}. A unary Boolean operator U is a function U:B->B, while a binary Boolean operator T is a function T:(B,B)->B. Binary operators are conventionally written in between their operands, while unary operators are usually written in front of their operands. (One exception is the post-increment and post-decrement operators in C/C++/Java, which are written after their operands.) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
9
Some Popular Boolean Operators
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Some Popular Boolean Operators Formal Name Nickname Arity Symbol Negation operator NOT Unary Conjunction operator AND Binary Disjunction operator OR Exclusive-OR operator XOR Implication operator IMPLIES Biconditional operator IFF ↔ 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
10
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.0 – Propositional Logic: Operators The Negation Operator The unary negation operator “¬” (NOT) transforms a prop. into its logical negation. E.g. If p = “I have brown hair.” then ¬p = “I do not have brown hair.” The truth table for NOT: T :≡ True; F :≡ False “:≡” means “is defined as” Operand column Result column 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
11
The Conjunction Operator
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators The Conjunction Operator The binary conjunction operator “” (AND) combines two propositions to form their logical conjunction. E.g. If p=“I will have salad for lunch.” and q=“I will have steak for dinner.”, then pq=“I will have salad for lunch and I will have steak for dinner.” ND Remember: “” points up like an “A”, and it means “ND” 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
12
Conjunction Truth Table
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Conjunction Truth Table Operand columns Note that a conjunction p1 p2 … pn of n propositions will have 2n rows in its truth table. Also: ¬ and operations together are suffi-cient to express any Boolean truth table! Note that AND is commutative and associative, which means that we can write a long conjunction (like in the first bullet on the left) without parenthesizing it. It also doesn’t matter what order the n propositions are in. The fact that an n-operand operator has 2^n rows in its truth table is an easy consequence of the product rule of combinatorics. Here is a proof. Note that for the table to be complete, we must have 1 row for every possible assignment of truth values to the n operands. Thus, there is 1 row for every function f:V->B, where V is the set of operand columns {p,q,…} and B={T,F}. Here, |V|=n and |B|=2. The number of functions from a set of size n to a set of size m is m^n. This is because of the product rule, as we will see in a moment. In this case, m=2 so we get 2^n such functions. In terms of the product rule: There are 2 possible values for p. For each of these, there are 2 possible values for q, since the choice of q is independent of the choice of p. And so on. So there are 2x2x…(n repetitions)…x2 possible rows, thus 2^n. Of course, we haven’t defined the product rule, set cardinality, or functions yet, so don’t worry if the above argument doesn’t quite make sense to you yet. In the second bullet, we would say, {NOT,AND} is a universal set of Boolean operators, but we haven’t even defined sets yet. If you already know what a set is, a universal set of operators over a given domain is a set of operators such that nested expressions involving those operators are sufficient to express any possible operator over that domain. In this case, the domain is B={T,F}. The proof that {NOT,AND} is universal is as follows: OR can be defined by p OR q = NOT(NOT(p) AND NOT(q)) (easily verified; this is one of DeMorgan’s Laws, which we will get to later). Now, armed with OR, AND, and NOT, we can show how to express any Boolean truth table, with any number of columns, as follows. Look for the cases where the last (result) column is T. For each such row in the truth table, include a corresponding term in a disjunctive expression for the whole truth table. The term should be a conjunction of terms, one for each input operand in that row. Each of these terms should be p if the entry in that position is “T”, and NOT(p) if the entry in that position is “F”. So, the entire expression basically says, “the value of the operator is T if and only if the pattern of truth values of the input operands exactly matches one of the rows in the truth table that ends in a ‘T’ result.” Thus, the expression directly encodes the content of the truth table. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
13
The Disjunction Operator
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators The Disjunction Operator The binary disjunction operator “” (OR) combines two propositions to form their logical disjunction. p=“My car has a bad engine.” q=“My car has a bad carburetor.” pq=“Either my car has a bad engine, or my car has a bad carburetor.” OR is also commutative and associative. The animated picture on the right is just a memory device to help you remember that the disjunction operator is symbolized with a downward-pointing wedge, like the blade of an axe, because it “splits” a proposition into two parts, such that you can take either part (or both), if you are trying to decide how to make the whole proposition true. Note that the meaning of disjunction is like the phrase “and/or” which is sometimes used in informal English. “The car has a bad engine and/or a bad carburetor.” After the downward- pointing “axe” of “” splits the wood, you can take 1 piece OR the other, or both. Meaning is like “and/or” in English. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
14
Disjunction Truth Table
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Disjunction Truth Table Note that pq means that p is true, or q is true, or both are true! So, this operation is also called inclusive or, because it includes the possibility that both p and q are true. “¬” and “” together are also universal. Note difference from AND 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
15
Nested Propositional Expressions
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Nested Propositional Expressions Use parentheses to group sub-expressions: “I just saw my old friend, and either he’s grown or I’ve shrunk.” = f (g s) (f g) s would mean something different f g s would be ambiguous By convention, “¬” takes precedence over both “” and “”. ¬s f means (¬s) f , not ¬ (s f) As an exercise, drop the truth tables for f /\ (g \/ s) and (f /\ g) \/ s to see that they’re different, and thus the parentheses are necessary. Precedence conventions such as the one in the second bullet help to reduce the number of parentheses needed in expressions. Note that negation, with its tight binding (high precedence), and with its position to the left of its operand, behaves similarly to a negative sign in arithmetic. There is also a precedence convention that you see sometimes (for example, in the C programming language) that AND takes precedence over OR. However, this convention is not quite universally accepted, not all systems adopt it. Therefore, to be safe, you should always include parentheses whenever you are mixing ANDs and ORs in a single sequence of binary operators. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
16
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.0 – Propositional Logic: Operators A Simple Exercise Let p=“It rained last night”, q=“The sprinklers came on last night,” r=“The lawn was wet this morning.” Translate each of the following into English: ¬p = r ¬p = ¬ r p q = “It didn’t rain last night.” For slides that have interactive exercises, it may be a good idea to stop the class for a minute to allow the students to discuss the problem with their neighbors, then call on someone to answer. This will help keep the students engaged in the lecture activity. “The lawn was wet this morning, and it didn’t rain last night.” “Either the lawn wasn’t wet this morning, or it rained last night, or the sprinklers came on last night.” 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
17
The Exclusive Or Operator
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators The Exclusive Or Operator The binary exclusive-or operator “” (XOR) combines two propositions to form their logical “exclusive or” (exjunction?). p = “I will earn an A in this course,” q = “I will drop this course,” p q = “I will either earn an A in this course, or I will drop it (but not both!)” 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
18
Exclusive-Or Truth Table
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Exclusive-Or Truth Table Note that pq means that p is true, or q is true, but not both! This operation is called exclusive or, because it excludes the possibility that both p and q are true. “¬” and “” together are not universal. A good way to remember the symbol for XOR, a plus sign inside an O, is to think of XOR as adding the bit-values of its inputs (mod 2). E.g., 0+0=0, 1+0=0, 1+1=0 (mod 2). Thus XOR is basically an addition, and we put it inside an “O” to remind ourselves that it is a type of “Or”. XOR together with unary operators do not form a universal set of operators over the Booleans. However, it turns out that they are a universal set for quantum logic! However we do not have time to cover quantum computing in this class, interesting though it is. Note difference from OR. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
19
Natural Language is Ambiguous
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Natural Language is Ambiguous Note that English “or” can be ambiguous regarding the “both” case! “Pat is a singer or Pat is a writer.” - “Pat is a man or Pat is a woman.” - Need context to disambiguate the meaning! For this class, assume “or” means inclusive. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
20
The Implication Operator
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators The Implication Operator antecedent consequent The implication p q states that p implies q. I.e., If p is true, then q is true; but if p is not true, then q could be either true or false. E.g., let p = “You study hard.” q = “You will get a good grade.” p q = “If you study hard, then you will get a good grade.” (else, it could go either way) Note that the definition of “p implies q” says: “If p is true, then q is true, and if p is not true, then q is either true or false.” Well, saying that q is either true or false is not saying anything, since any proposition is, by the very definition of a proposition, either true or false. So, the last part of that sentence (covering the case where p is not true) is not really saying anything. So we may as well say the definition is, “If p is true, then q is true.” Sometimes the antecedent is called the hypothesis and the consequent is called the conclusion. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
21
Implication Truth Table
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Implication Truth Table p q is false only when p is true but q is not true. p q does not say that p causes q! p q does not require that p or q are ever true! E.g. “(1=0) pigs can fly” is TRUE! The only False case! Let’s consider the rows of the truth table, one at a time. In the first row, p is false and q is false. Now, let’s consider the definition of p->q. It says “If p is true, then q is true, but if p is false, then q is either true or false.” Well, in this case, p is false, and q is either true or false (namely false), so the second part of the statement is true. But, of course that part is true, since it is just a tautology that q is either true or false. In other words, and if is always true when its antecedent is false. Similarly, the second row is True. The third row is false, since p is true but q is false, so it is not the case that if p is true then q is true. Finally, in the fourth row, since p is true and q is true, it is the case that if q is true then q is true. Many students have trouble with the implication operator. When we say, “A implies B”, it is just a shorthand for “either not A, or B”. In other words, it is just the statement that it is NOT the case that A is true and B is false. This often seems wrong to students, because when we say “A implies B” in everyday English, we mean that if somehow A were to become true in some way, somehow, the statement B would automatically be thereby made true, as a result. This does not seem to be the case in general when A and B are just two random false statements (such as the example in the last bullet). (However in this case, we might make a convoluted argument that the antecedent really DOES effectively imply the consequent: Note that if 1=0, then if a given pig flies 0 times in his life, then he also flies 1 time, thus he can fly.) In any case, perhaps a more accurate and satisfying English rendering of the true meaning of the logical claim “A implies B”, might be just, “the possibility that A implies B is not contradicted directly by the truth values of A and B”. In other words, “it is not the case that A is true and B is false.” (Since that combination of truth values would directly contradict the hypothesis that A implies B.) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
22
Examples of Implications
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Examples of Implications “If this lecture ever ends, then the sun will rise tomorrow.” True or False? “If Tuesday is a day of the week, then I am a penguin.” True or False? “If 1+1=6, then Bush is president.” True or False? “If the moon is made of green cheese, then I am richer than Bill Gates.” True or False? The first one is true because T->T is True. It doesn’t matter that my lecture ending is not the cause of the sun rising tomorrow. The second one is false for me, because although Tuesday is a day of the week, I am most certainly NOT a penguin. (But, if a penguin were to say this statement, then it would be true for him.) The third one is true, because 1+1 is not equal to 6. F->T is True. The last one is true, because the moon is not made of green cheese. F->F is True. In other words, anything that’s false implies anything at all. p->q if p is false. Why? If p is false, then if p is true, then p is both false and true at the same time, and so truth and falsity are the same thing. So if q is false then q is true. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
23
Why does this seem wrong?
Discrete Math - Module #1 - Logic 2/19/2019 Why does this seem wrong? Consider a sentence like, “If I wear a red shirt tomorrow, then Osama bin Laden will be captured!” In logic, we consider the sentence True so long as either I don’t wear a red shirt, or Osama is caught. But, in normal English conversation, if I were to make this claim, you would think that I was lying. Why this discrepancy between logic & language? 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
24
Resolving the Discrepancy
Discrete Math - Module #1 - Logic 2/19/2019 Resolving the Discrepancy In English, a sentence “if p then q” usually really implicitly means something like, “In all possible situations, if p then q.” That is, “For p to be true and q false is impossible.” Or, “I guarantee that no matter what, if p, then q.” This can be expressed in predicate logic as: “For all situations s, if p is true in situation s, then q is also true in situation s” Formally, we could write: s, P(s) → Q(s) That sentence is logically False in our example, because for me to wear a red shirt and for Osama to stay free is a possible (even if not actual) situation. Natural language and logic then agree with each other. Later, we will learn an extension of propositional logic called predicate logic that allows us to express what we really mean by this english sentence. Basically, “if .. then” sentences in English usually carry the connotation that they are always true, or true in all situations. Therefore, they really have a more complex structure than plain logically implication. When we get to the next section, on predicate logic, we will learn that we need to use an additional logical quantifier called FORALL to properly render such a sentence. So, if I make this claim “If I wear a red shirt the US will attack” you automatically assume that what I really mean is “For all possible courses of events that the world could follow tomorrow, if that course of events has me wearing a red shirt, then it will have the US attacking Iraq.” This sentence is False both intuitively and logically, because we surely agree that it is a possible course of events for tomorrow that I do wear a red shirt but the US does not attack Iraq. In predicate logic, if we define the universe of discourse to be all possible versions of tomorrow t, and we define P(t) = “In tomorrow t, I wear a red shirt”, and Q(t) = “In tomorrow t, the U.S. attacks Iraq,” then the sentence would be rendered logically as “FORALL t, P(t) --> Q(t)”, which is False (agreeing with intuition) so long as there is a possible tomorrow t in which I do wear a red shirt and the US doesn’t attack. If I don’t wear a red shirt, we don’t consider the sentence to have been verified, because it doesn’t prove what would have happened if I had worn the red shirt. Even if I wear a red shirt, and the US does attack, we still don’t believe the sentence because it doesn’t prove that it wasn’t a possibility for the US not to attack. It is important that you keep in mind that in pure logic, when we say “if p then q” or “p implies q” we explicitly do NOT mean that in ALL situations p implies q. For that we would say, FORALL s P(s)->Q(s). Rather, we just mean, “p is false or q is true”. So, the example says “I predict that tomorrow, either I will not be wearing a red shirt, or the US will be attacking Iraq.” I can make this prediction true (obviously) just by not wearing a red shirt. Since you believe that I can do this, you believe that sentence. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
25
English Phrases Meaning p q
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators English Phrases Meaning p q “p implies q” “if p, then q” “if p, q” “when p, q” “whenever p, q” “q if p” “q when p” “q whenever p” “p only if q” “p is sufficient for q” “q is necessary for p” “q follows from p” “q is implied by p” We will see some equivalent logic expressions later. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
26
Converse, Inverse, Contrapositive
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Converse, Inverse, Contrapositive Some terminology, for an implication p q: Its converse is: q p. Its inverse is: ¬p ¬q. Its contrapositive: ¬q ¬ p. One of these three has the same meaning (same truth table) as p q. Can you figure out which? Also, note that the converse and inverse of p->q also have the same meaning as each other. Contrapositive 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
27
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.0 – Propositional Logic: Operators How do we know for sure? Proving the equivalence of p q and its contrapositive using truth tables: 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
28
The biconditional operator
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators The biconditional operator The biconditional p q states that p is true if and only if (IFF) q is true. p = “Bush wins the 2004 election.” q = “Bush will be president for all of 2005.” p q = “If, and only if, Bush wins the 2004 election, Bush will be president for all of 2005.” 2005 I’m still here! 2004 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
29
Biconditional Truth Table
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Biconditional Truth Table p q means that p and q have the same truth value. Note this truth table is the exact opposite of ’s! Thus, p q means ¬(p q) p q does not imply that p and q are true, or that either of them causes the other, or that they have a common cause. Also, p IFF q is equivalent to (p -> q) /\ (q -> p). (“/\” being the AND wedge) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
30
Boolean Operations Summary
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Boolean Operations Summary We have seen 1 unary operator (out of the 4 possible) and 5 binary operators (out of the 16 possible). Their truth tables are below. For fun, try writing down the truth tables for each of the 4 possible unary operators, and each of the 16 possible binary operators. For each one, try to come up with an English description of the operator that conveys its meaning. Also, figure out a way to define it in terms of other operators we already introduced. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
31
Some Alternative Notations
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.0 – Propositional Logic: Operators Some Alternative Notations 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
32
Bits and Bit Operations
Discrete Math - Module #1 - Logic 2/19/2019 Topic #2 – Bits Bits and Bit Operations A bit is a binary (base 2) digit: 0 or 1. Bits may be used to represent truth values. By convention: represents “false”; 1 represents “true”. Boolean algebra is like ordinary algebra except that variables stand for bits, + means “or”, and multiplication means “and”. See module 23 (chapter 10) for more details. John Tukey ( ) Bits can also be defined in terms of sets, if you like, by the convention that the empty set {} represents 0, and the set containing the empty set {{}} represents 1. Or more generally, any two distinct objects can represent the two bit-values or truth-values. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
33
Discrete Math - Module #1 - Logic
2/19/2019 Topic #2 – Bits Bit Strings A Bit string of length n is an ordered sequence (series, tuple) of n0 bits. More on sequences in §3.2. By convention, bit strings are (sometimes) written left to right: e.g. the “first” bit of the bit string “ ” is 1. Watch out! Another common convention is that the rightmost bit is bit #0, the 2nd-rightmost is bit #1, etc. When a bit string represents a base-2 number, by convention, the first (leftmost) bit is the most significant bit. Ex =8+4+1=13. We will talk about strings more generally later in the module on sequences. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
34
Discrete Math - Module #1 - Logic
2/19/2019 Topic #2 – Bits Counting in Binary Did you know that you can count to 1,023 just using two hands? How? Count in binary! Each finger (up/down) represents 1 bit. To increment: Flip the rightmost (low-order) bit. If it changes 1→0, then also flip the next bit to the left, If that bit changes 1→0, then flip the next one, etc. , , , … …, , , This is just a fun exercise to practice with the binary number system. We’ll have more to say about binary (and base-n numbers in general) later in the course. If you demonstrate this technique, you should probably apologize to your audience when you get to 4. The sequence in the last bullet is (in decimal): 0, 1, 2, … (skip a bunch) …, 1021, 1022, The next number, 1024 (or 1K) is 2^10. You would need 11 fingers to show it! 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
35
Discrete Math - Module #1 - Logic
2/19/2019 Topic #2 – Bits Bitwise Operations Boolean operations can be extended to operate on bit strings as well as single bits. E.g.: Bit-wise OR Bit-wise AND Bit-wise XOR The answers are present, but hidden, as white text on a white background. The slide can be done in class as an exercise, with the instructor typing in the students’ answers in the space provided. Then the correct answers can be revealed by selecting the bottom 3 rows and changing their font color unconditionally to black. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
36
Discrete Math - Module #1 - Logic
2/19/2019 End of §1.1 You have learned about: Propositions: What they are. Propositional logic operators’ Symbolic notations. English equivalents. Logical meaning. Truth tables. Atomic vs. compound propositions. Alternative notations. Bits and bit-strings. Next section: §1.2 Propositional equivalences. How to prove them. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
37
Propositional Equivalence (§1.2)
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.1 – Propositional Logic: Equivalences Propositional Equivalence (§1.2) Two syntactically (i.e., textually) different compound propositions may be the semantically identical (i.e., have the same meaning). We call them equivalent. Learn: Various equivalence rules or laws. How to prove equivalences using symbolic derivations. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
38
Tautologies and Contradictions
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.1 – Propositional Logic: Equivalences Tautologies and Contradictions A tautology is a compound proposition that is true no matter what the truth values of its atomic propositions are! Ex. p p [What is its truth table?] A contradiction is a compound proposition that is false no matter what! Ex. p p [Truth table?] Other compound props. are contingencies. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
39
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.1 – Propositional Logic: Equivalences Logical Equivalence Compound proposition p is logically equivalent to compound proposition q, written pq, IFF the compound proposition pq is a tautology. Compound propositions p and q are logically equivalent to each other IFF p and q contain the same truth values as each other in all rows of their truth tables. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
40
Proving Equivalence via Truth Tables
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.1 – Propositional Logic: Equivalences Proving Equivalence via Truth Tables Ex. Prove that pq (p q). F T T T F T T F F T T F T F T T F F F T 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
41
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.1 – Propositional Logic: Equivalences Equivalence Laws These are similar to the arithmetic identities you may have learned in algebra, but for propositional equivalences instead. They provide a pattern or template that can be used to match all or part of a much more complicated proposition and to find an equivalence for it. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
42
Equivalence Laws - Examples
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.1 – Propositional Logic: Equivalences Equivalence Laws - Examples Identity: pT p pF p Domination: pT T pF F Idempotent: pp p pp p Double negation: p p Commutative: pq qp pq qp Associative: (pq)r p(qr) (pq)r p(qr) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
43
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.1 – Propositional Logic: Equivalences More Equivalence Laws Distributive: p(qr) (pq)(pr) p(qr) (pq)(pr) De Morgan’s: (pq) p q (pq) p q Trivial tautology/contradiction: p p T p p F Augustus De Morgan ( ) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
44
Defining Operators via Equivalences
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1.1 – Propositional Logic: Equivalences Defining Operators via Equivalences Using equivalences, we can define operators in terms of other operators. Exclusive or: pq (pq)(pq) pq (pq)(qp) Implies: pq p q Biconditional: pq (pq) (qp) pq (pq) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
45
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.1 – Propositional Logic: Equivalences An Example Problem Check using a symbolic derivation whether (p q) (p r) p q r. (p q) (p r) [Expand definition of ] (p q) (p r) [Expand defn. of ] (p q) ((p r) (p r)) [DeMorgan’s Law] (p q) ((p r) (p r)) cont. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
46
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.1 – Propositional Logic: Equivalences Example Continued... (p q) ((p r) (p r)) [ commutes] (q p) ((p r) (p r)) [ associative] q (p ((p r) (p r))) [distrib. over ] q (((p (p r)) (p (p r))) [assoc.] q (((p p) r) (p (p r))) [trivail taut.] q ((T r) (p (p r))) [domination] q (T (p (p r))) [identity] q (p (p r)) cont. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
47
Discrete Math - Module #1 - Logic
2/19/2019 Topic #1.1 – Propositional Logic: Equivalences End of Long Example q (p (p r)) [DeMorgan’s] q (p (p r)) [Assoc.] q ((p p) r) [Idempotent] q (p r) [Assoc.] (q p) r [Commut.] p q r Q.E.D. (quod erat demonstrandum) (Which was to be shown.) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
48
Review: Propositional Logic (§§1.1-1.2)
Discrete Math - Module #1 - Logic 2/19/2019 Topic #1 – Propositional Logic Review: Propositional Logic (§§ ) Atomic propositions: p, q, r, … Boolean operators: Compound propositions: s : (p q) r Equivalences: pq (p q) Proving equivalences using: Truth tables. Symbolic derivations. p q r … 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
49
Discrete Math - Module #1 - Logic
2/19/2019 Topic #3 – Predicate Logic Predicate Logic (§1.3) Predicate logic is an extension of propositional logic that permits concisely reasoning about whole classes of entities. Propositional logic (recall) treats simple propositions (sentences) as atomic entities. In contrast, predicate logic distinguishes the subject of a sentence from its predicate. Remember these English grammar terms? 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
50
Applications of Predicate Logic
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Applications of Predicate Logic It is the formal notation for writing perfectly clear, concise, and unambiguous mathematical definitions, axioms, and theorems (more on these in module 2) for any branch of mathematics. Predicate logic with function symbols, the “=” operator, and a few proof-building rules is sufficient for defining any conceivable mathematical system, and for proving anything that can be proved within that system! 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
51
Discrete Math - Module #1 - Logic
2/19/2019 Topic #3 – Predicate Logic Other Applications Predicate logic is the foundation of the field of mathematical logic, which culminated in Gödel’s incompleteness theorem, which revealed the ultimate limits of mathematical thought: Given any finitely describable, consistent proof procedure, there will always remain some true statements that will never be proven by that procedure. I.e., we can’t discover all mathematical truths, unless we sometimes resort to making guesses. Kurt Gödel A note on pronunciation: The guy’s name is Austrian. The o with the double dot over it is called an “o umlaut.” It is also sometimes written “oe” in languages without umlauts, thus, “Goedel” is also a correct way to write his name in English. An o umlaut is pronounced something between “uh” and “ur”. So, “Goedel” is pronounced something like “girdle.” One way of saying Godel’s theorem is that there are infinitely many finite mathematical statements that are true, but that are not provable from earlier statements by any finite argument following a fixed set of logical inference rules. Thus, the only way to really expand the scope of mathematics is to make guesses (through intuition or inspiration) about additional statements being true (or equivalently, additional inference rules being valid). When one makes such guesses, since they have not been proven, one should always keep in mind the possibility that they may be false (inconsistent with earlier statements), and thus may eventually be disproven. Thus, in general, we can never really know whether a given mathematical system we are using is really logically self-consistent. (Except for some very simple systems of limited power can be proven to be consistent.) Later, we will see that the mathematical world was badly shaken up when it was discovered that the simple form of set theory that everyone had been using was actually logically inconsistent! To restore consistency, the theory had to be modified, and the new set theory is self-consistent, as far as anyone knows. Goedel was also a close colleague and friend of Albert Einstein, and he discovered (among other things) that Einstein’s theory of General Relativity (the modern theory of gravity) had some theoretical solutions in which time travel into the past was possible! 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
52
Practical Applications of Predicate Logic
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Practical Applications of Predicate Logic It is the basis for clearly expressed formal specifications for any complex system. It is basis for automatic theorem provers and many other Artificial Intelligence systems. E.g. automatic program verification systems. Predicate-logic like statements are supported by some of the more sophisticated database query engines and container class libraries these are types of programming tools. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
53
Subjects and Predicates
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Subjects and Predicates In the sentence “The dog is sleeping”: The phrase “the dog” denotes the subject - the object or entity that the sentence is about. The phrase “is sleeping” denotes the predicate- a property that is true of the subject. In predicate logic, a predicate is modeled as a function P(·) from objects to propositions. P(x) = “x is sleeping” (where x is any object). 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
54
Discrete Math - Module #1 - Logic
2/19/2019 Topic #3 – Predicate Logic More About Predicates Convention: Lowercase variables x, y, z... denote objects/entities; uppercase variables P, Q, R… denote propositional functions (predicates). Keep in mind that the result of applying a predicate P to an object x is the proposition P(x). But the predicate P itself (e.g. P=“is sleeping”) is not a proposition (not a complete sentence). E.g. if P(x) = “x is a prime number”, P(3) is the proposition “3 is a prime number.” 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
55
Propositional Functions
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Propositional Functions Predicate logic generalizes the grammatical notion of a predicate to also include propositional functions of any number of arguments, each of which may take any grammatical role that a noun can take. E.g. let P(x,y,z) = “x gave y the grade z”, then if x=“Mike”, y=“Mary”, z=“A”, then P(x,y,z) = “Mike gave Mary the grade A.” 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
56
Universes of Discourse (U.D.s)
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Universes of Discourse (U.D.s) The power of distinguishing objects from predicates is that it lets you state things about many objects at once. E.g., let P(x)=“x+1>x”. We can then say, “For any number x, P(x) is true” instead of (0+1>0) (1+1>1) (2+1>2) ... The collection of values that a variable x can take is called x’s universe of discourse. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
57
Quantifier Expressions
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Quantifier Expressions Quantifiers provide a notation that allows us to quantify (count) how many objects in the univ. of disc. satisfy a given predicate. “” is the FORLL or universal quantifier. x P(x) means for all x in the u.d., P holds. “” is the XISTS or existential quantifier. x P(x) means there exists an x in the u.d. (that is, 1 or more) such that P(x) is true. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
58
The Universal Quantifier
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic The Universal Quantifier Example: Let the u.d. of x be parking spaces at UF. Let P(x) be the predicate “x is full.” Then the universal quantification of P(x), x P(x), is the proposition: “All parking spaces at UF are full.” i.e., “Every parking space at UF is full.” i.e., “For each parking space at UF, that space is full.” Instructors: You can substitute your favorite overly-crowded destination in place of the University of Florida in this example. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
59
The Existential Quantifier
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic The Existential Quantifier Example: Let the u.d. of x be parking spaces at UF. Let P(x) be the predicate “x is full.” Then the existential quantification of P(x), x P(x), is the proposition: “Some parking space at UF is full.” “There is a parking space at UF that is full.” “At least one parking space at UF is full.” 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
60
Free and Bound Variables
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Free and Bound Variables An expression like P(x) is said to have a free variable x (meaning, x is undefined). A quantifier (either or ) operates on an expression having one or more free variables, and binds one or more of those variables, to produce an expression having one or more bound variables. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
61
Discrete Math - Module #1 - Logic
2/19/2019 Topic #3 – Predicate Logic Example of Binding P(x,y) has 2 free variables, x and y. x P(x,y) has 1 free variable, and one bound variable. [Which is which?] “P(x), where x=3” is another way to bind x. An expression with zero free variables is a bona-fide (actual) proposition. An expression with one or more free variables is still only a predicate: e.g. let Q(y) = x P(x,y) y x 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
62
Nesting of Quantifiers
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Nesting of Quantifiers Example: Let the u.d. of x & y be people. Let L(x,y)=“x likes y” (a predicate w. 2 f.v.’s) Then y L(x,y) = “There is someone whom x likes.” (A predicate w. 1 free variable, x) Then x (y L(x,y)) = “Everyone has someone whom they like.” (A __________ with ___ free variables.) Proposition 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
63
Review: Predicate Logic (§1.3)
Discrete Math - Module #1 - Logic 2/19/2019 Review: Predicate Logic (§1.3) Objects x, y, z, … Predicates P, Q, R, … are functions mapping objects x to propositions P(x). Multi-argument predicates P(x, y). Quantifiers: [x P(x)] :≡ “For all x’s, P(x).” [x P(x)] :≡ “There is an x such that P(x).” Universes of discourse, bound & free vars. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
64
Discrete Math - Module #1 - Logic
2/19/2019 Topic #3 – Predicate Logic Quantifier Exercise If R(x,y)=“x relies upon y,” express the following in unambiguous English: x(y R(x,y))= y(x R(x,y))= x(y R(x,y))= y(x R(x,y))= x(y R(x,y))= Everyone has someone to rely on. There’s a poor overburdened soul whom everyone relies upon (including himself)! There’s some needy person who relies upon everybody (including himself). Everyone has someone who relies upon them. Everyone relies upon everybody, (including themselves)! 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
65
Natural language is ambiguous!
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Natural language is ambiguous! “Everybody likes somebody.” For everybody, there is somebody they like, x y Likes(x,y) or, there is somebody (a popular person) whom everyone likes? y x Likes(x,y) “Somebody likes everybody.” Same problem: Depends on context, emphasis. [Probably more likely.] 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
66
Game Theoretic Semantics
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Game Theoretic Semantics Thinking in terms of a competitive game can help you tell whether a proposition with nested quantifiers is true. The game has two players, both with the same knowledge: Verifier: Wants to demonstrate that the proposition is true. Falsifier: Wants to demonstrate that the proposition is false. The Rules of the Game “Verify or Falsify”: Read the quantifiers from left to right, picking values of variables. When you see “”, the falsifier gets to select the value. When you see “”, the verifier gets to select the value. If the verifier can always win, then the proposition is true. If the falsifier can always win, then it is false. Here is a way of understanding what we mean by nested quantifiers. First, “game theory” is a branch of mathematics dealing with ideal strategies for playing competitive games. It has practical applications in economics, business, international politics, as well as in many areas of computer science such as computer security. In the recent movie “A Beautiful Mind”, John Nash’s work is related to game theory. A semantics for a language is the specification how that language is understood; it gives you the meaning of the language, as opposed to just giving you its grammar. So far, I have given you one way of understanding the semantics of nested quantifiers in predicate logic, through translation to the English phrases “for all…” and “there exists…such that…”. However, if you are still fuzzy on the concept, here is another way to understand it. Think of determining the truth value of a nested quantifier expression as being like playing a game following certain rules. In this game, there are two players, the “verifier” who wants to argue the case that the proposition is true, and the “falsifier” who wants to argue the case that the proposition is false. To play the game, read the nested-quantifier expression from left to right. Every time you read “FORALL x”, the falsifier gets to take a turn, and he gets to pick any value of x in the universe of discourse that he wants to use to demonstrate his case. Every time you read “EXISTS x”, the verifier gets to take a turn, and he gets to pick any value of x in the u.d. that he wants to use to demonstrate his case. Now, we can say, if there is a winning strategy for the verifier (if he can plan a way to play the game that guarantees him a win), then the proposition is true. On the other hand, if there is a winning strategy for the falsifier, then the proposition is false. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
67
Let’s Play, “Verify or Falsify!”
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Let’s Play, “Verify or Falsify!” Let B(x,y) :≡ “x’s birthday is followed within 7 days by y’s birthday.” Suppose I claim that among you: x y B(x,y) Let’s play it in class. Who wins this game? What if I switched the quantifiers, and I claimed that y x B(x,y)? Who wins in that case? Your turn, as falsifier: You pick any x → (so-and-so) y B(so-and-so,y) As an example, let “B(x,y)” be the proposition, “y’s birthday falls within 1 week after x’s birthday.” Then suppose I assert, for the universe of discourse consisting of students in this class, that the predicate FORALL x EXISTS y B(x,y) is true. Now, let’s play the game. I will be the verifier, and you all can play the falsifier. (This example works well in my class because it’s so large; for smaller classes you should change the time interval to 1 month instead.) The first quantifier is the FORALL quantifier. Since I am claiming the part after the FORALL is true for all values of x, I shouldn’t care what value of x is chosen. I’m saying it’s true no matter what value is picked. So, the falsifier gets to pick x, and try his best to prove me wrong. So, who in class wants to offer up their birthday as the value of x here, to see if they can prove me wrong? Just suggest someone, anyone… You? OK, good. What’s your name? OK, (so-and-so). What’s your birth date? (Since we’re supposed to have the same knowledge, you have to tell me.) Now x is picked as so-and-so, and it’s my job to show that the rest of the sentence, EXISTS y B(so-and-so, y) is true. It’s my turn to play since the next quantifier is an EXISTS. EXISTS only claims there is 1 member of the universe of discourse who satisfies the predicate, so I get to pick it. Now, since in this game we’re both supposed to have the same knowledge, but I don’t actually know all your birthdays, you’re going to have to have to help me out here. Who has a birthday within the next 7 days after so-and-so? You? When’s your birthday? OK, I pick you then. Now, all the variables are chosen, and we look at the truth value of the rest of the sentence. Notice it is true. So I win. This does not yet establish that the sentence is true; for that we’d have to tabulate everyone’s birthdays, and show that no matter who you pick for x, I can pick someone for y to make the sentence true. In a class this large, the sentence may actually be true; there may be no 1-week periods that have no birthdays in them. (In a much smaller class, it would most likely be false.) Now, to show that the order of quantifiers matters, let’s switch the quantifiers. Now, I (the verifier) have to go first. In this game, making the first move turns out to be a disadvantage rather than an advantage. Now, no matter who I pick for y, let’s say you – what’s your birthday? You guys can easily pick someone for x to make the sentence false. Thus, the sentence is false. My turn, as verifier: I pick any y → (such-and-such) B(so-and-so,such-and-such) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
68
Still More Conventions
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Still More Conventions Sometimes the universe of discourse is restricted within the quantification, e.g., x>0 P(x) is shorthand for “For all x that are greater than zero, P(x).” =x (x>0 P(x)) x>0 P(x) is shorthand for “There is an x greater than zero such that P(x).” =x (x>0 P(x)) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
69
More to Know About Binding
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic More to Know About Binding x x P(x) - x is not a free variable in x P(x), therefore the x binding isn’t used. (x P(x)) Q(x) - The variable x is outside of the scope of the x quantifier, and is therefore free. Not a complete proposition! (x P(x)) (x Q(x)) – This is legal, because there are 2 different x’s! 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
70
Quantifier Equivalence Laws
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Quantifier Equivalence Laws Definitions of quantifiers: If u.d.=a,b,c,… x P(x) P(a) P(b) P(c) … x P(x) P(a) P(b) P(c) … From those, we can prove the laws: x P(x) x P(x) x P(x) x P(x) Which propositional equivalence laws can be used to prove this? (Chalkboard.) Another way to see why the order of quantifiers matters is to expand out the definitions of FORALL and EXISTS in terms of AND and OR. For example, suppose the universe of discourse just consists of two objects a and b. Now, consider some predicate P(x,y). Then, FORALL x EXISTS y P(x,y) (EXISTS y P(a,y)) /\ (EXISTS y P(b,y)) (P(a,a) \/ P(a,b)) /\ (P(b,a) \/ P(b,b)). In contrast, EXISTS y FORALL x P(x,y) (FORALL x P(x,a)) \/ (FORALL x P(x,b)) (P(a,a) /\ P(b,a)) \/ (P(a,b) /\ P(b,b)). To see that these two are inequivalent, suppose only P(a,a) and P(b,b) are true. Then, the first proposition (with the FORALL first) is true, but, the second proposition (with the EXISTS first) is true. Students can come up with this counterexample in-class as an exercise. DeMorgan's 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
71
Discrete Math - Module #1 - Logic
2/19/2019 Topic #3 – Predicate Logic More Equivalence Laws x y P(x,y) y x P(x,y) x y P(x,y) y x P(x,y) x (P(x) Q(x)) (x P(x)) (x Q(x)) x (P(x) Q(x)) (x P(x)) (x Q(x)) Exercise: See if you can prove these yourself. What propositional equivalences did you use? 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
72
Review: Predicate Logic (§1.3)
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Review: Predicate Logic (§1.3) Objects x, y, z, … Predicates P, Q, R, … are functions mapping objects x to propositions P(x). Multi-argument predicates P(x, y). Quantifiers: (x P(x)) =“For all x’s, P(x).” (x P(x))=“There is an x such that P(x).” These “Review” slides I insert at the point where I am at the beginning of a lecture, just to quickly review what we’ve been covering recently. Instructors should feel free to move these slides around to wherever they are convenient. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
73
More Notational Conventions
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic More Notational Conventions Quantifiers bind as loosely as needed: parenthesize x P(x) Q(x) Consecutive quantifiers of the same type can be combined: x y z P(x,y,z) x,y,z P(x,y,z) or even xyz P(x,y,z) All quantified expressions can be reduced to the canonical alternating form x1x2x3x4… P(x1, x2, x3, x4, …) ( ) 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
74
Defining New Quantifiers
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Defining New Quantifiers As per their name, quantifiers can be used to express that a predicate is true of any given quantity (number) of objects. Define !x P(x) to mean “P(x) is true of exactly one x in the universe of discourse.” !x P(x) x (P(x) y (P(y) y x)) “There is an x such that P(x), where there is no y such that P(y) and y is other than x.” 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
75
Some Number Theory Examples
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Some Number Theory Examples Let u.d. = the natural numbers 0, 1, 2, … “A number x is even, E(x), if and only if it is equal to 2 times some other number.” x (E(x) (y x=2y)) “A number is prime, P(x), iff it’s greater than 1 and it isn’t the product of any two non-unity numbers.” x (P(x) (x>1 yz x=yz y1 z1)) Note we can even use quantifier expressions to define concepts like even-ness and prime-ness. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
76
Goldbach’s Conjecture (unproven)
Discrete Math - Module #1 - Logic 2/19/2019 Topic #3 – Predicate Logic Goldbach’s Conjecture (unproven) Using E(x) and P(x) from previous slide, E(x>2): P(p),P(q): p+q = x or, with more explicit notation: x [x>2 E(x)] → p q P(p) P(q) p+q = x. “Every even number greater than 2 is the sum of two primes.” The notation in the top part may look confusing at first but it is actually unambiguous. After FORALL we must have the name of a variable. The following term has 1 free variable x, so we assume that variable comes after the FORALL. Then, the expression E(x>2) becomes a predicate that restricts the universe of discourse. E() is only a predicate if it contains a free variable; the only free variable within it is x so we translate E(x>2) as E(x) /\ x>2. This then is the predicate that must be true of an item in the universe of discourse in order for the rest of the expression to apply to it. Similarly, P(p) and P(q) translate to both free variables p and q after the EXISTS and to conjoined propositions about p and q. Alternatively, the whole expression could also be written FORALL E(x)>2 EXISTS p+q=x, P(p), P(q). Or of course in many other equivalent forms. Due to Goedel’s theorem, as far as we know right now, it is entirely possible that Goldbach’s conjecture could be perfectly true for the universe of all natural numbers from 0 to infinity, yet, there might be absolutely NO finite-length proof of this conjecture from the basic axioms of number theory. On the other hand, it might have a proof that is finite but extremely long, or even possibly a relatively short one that we just haven’t been lucky enough to discover yet. 2/19/2019 (c) , Michael P. Frank (c) , Michael P. Frank
77
Topic #3 – Predicate Logic
Calculus Example One way of precisely defining the calculus concept of a limit, using quantifiers: 2/19/2019 (c) , Michael P. Frank
78
Topic #3 – Predicate Logic
Deduction Example Definitions: s :≡ Socrates (ancient Greek philosopher); H(x) :≡ “x is human”; M(x) :≡ “x is mortal”. Premises: H(s) Socrates is human. x H(x)M(x) All humans are mortal. 2/19/2019 (c) , Michael P. Frank
79
Deduction Example Continued
Topic #3 – Predicate Logic Deduction Example Continued Some valid conclusions you can draw: H(s)M(s) [Instantiate universal.] If Socrates is human then he is mortal. H(s) M(s) Socrates is inhuman or mortal. H(s) (H(s) M(s)) Socrates is human, and also either inhuman or mortal. (H(s) H(s)) (H(s) M(s)) [Apply distributive law.] F (H(s) M(s)) [Trivial contradiction.] H(s) M(s) [Use identity law.] M(s) Socrates is mortal. 2/19/2019 (c) , Michael P. Frank
80
Topic #3 – Predicate Logic
Another Example Definitions: H(x) :≡ “x is human”; M(x) :≡ “x is mortal”; G(x) :≡ “x is a god” Premises: x H(x) M(x) (“Humans are mortal”) and x G(x) M(x) (“Gods are immortal”). Show that x (H(x) G(x)) (“No human is a god.”) 2/19/2019 (c) , Michael P. Frank
81
The Derivation x H(x)M(x) and x G(x)M(x).
Topic #3 – Predicate Logic The Derivation x H(x)M(x) and x G(x)M(x). x M(x)H(x) [Contrapositive.] x [G(x)M(x)] [M(x)H(x)] x G(x)H(x) [Transitivity of .] x G(x) H(x) [Definition of .] x (G(x) H(x)) [DeMorgan’s law.] x G(x) H(x) [An equivalence law.] 2/19/2019 (c) , Michael P. Frank
82
Bonus Topic: Logic Programming
There are some programming languages that are based entirely on predicate logic! The most famous one is called Prolog. A Prolog program is a set of propositions (“facts”) and (“rules”) in predicate logic. The input to the program is a “query” proposition. Want to know if it is true or false. The Prolog interpreter does some automated deduction to determine whether the query follows from the facts. 2/19/2019 (c) , Michael P. Frank
83
Facts in Prolog A fact in Prolog represents a simple, non-compound proposition in predicate logic. e.g., “John likes Mary” can be written Likes(John,Mary) in predicate logic. can be written likes(john,mary). in Prolog! Lowercase symbols must be used for all constants and predicates, uppercase is reserved for variable names. 2/19/2019 (c) , Michael P. Frank
84
Rules in Prolog A rule in Prolog represents a universally quanitifed proposition of the general form x: [y P(x,y)]→Q(x), where x and y might be compound variables x=(z,w) and P,Q compound propositions. In Prolog, this is written as the rule: q(X) :- p(X,Y). i.e., the , quantifiers are implicit. Example: likable(X) :- likes(Y,X). ← Variables must be capitalized 2/19/2019 (c) , Michael P. Frank
85
Conjunction and Disjunction
Logical conjunction is encoded using multiple comma-separated terms in a rule. Logical disjunction is encoded using multiple rules. E.g., x [(P(x)Q(x))R(x)]→S(x) can be rendered in Prolog as: s(X) :- p(X),q(X) s(X) :- r(X) 2/19/2019 (c) , Michael P. Frank
86
Deduction in Prolog When a query is input to the Prolog interpreter,
it searches its database to determine if the query can be proven true from the available facts. if so, it returns “yes”, if not, “no”. If the query contains any variables, all values that make the query true are printed. 2/19/2019 (c) , Michael P. Frank
87
Simple Prolog Example An example input program:
likes(john,mary). likes(mary,fred). likes(fred,mary). likable(X) :- likes(Y,X). An example query: ? likable(Z) returns: mary fred 2/19/2019 (c) , Michael P. Frank
88
End of §1.3-1.4, Predicate Logic
Topic #3 – Predicate Logic End of § , Predicate Logic From these sections you should have learned: Predicate logic notation & conventions Conversions: predicate logic clear English Meaning of quantifiers, equivalences Simple reasoning with quantifiers Upcoming topics: Introduction to proof-writing. Then: Set theory – a language for talking about collections of objects. 2/19/2019 (c) , Michael P. Frank
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.