Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 1. The Foundations

Similar presentations


Presentation on theme: "Chapter 1. The Foundations"— Presentation transcript:

1 Chapter 1. The Foundations
Cheng-Chia Chen

2 Logic: Sets: Functions : 1. The foundations
The basis of all mathematical reasoning has practical applications to the design of computing machine give the precise meaning of math. statements. Sets: The basis of all mathematical structures. definitions, operations Functions : definitions, classification, operations

3 Foundations of Logic (§§1.1-1.4)
Mathematical Logic is a tool for working with complicated compound statements. It includes: A language(Vocabulary) for expressing them. A concise notation(Syntax) for writing them. A methodology for objectively reasoning about their truth or falsity (Semantics and Axiomatics). It is the foundation for expressing formal proofs in all branches of mathematics.

4 Foundations of Logic: Overview
Propositional logic (§ ): Basic definitions. (§1.1) Equivalence rules & derivations. (§1.2) Predicate logic (§ ) Predicates. Quantified predicate expressions. Equivalences & derivations.

5 Some applications in computer science:
§1.1 Propositional Logic 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.

6 Definition of a Proposition
A proposition (p, q, r, …) is simply a statement (i.e., a declarative sentence) with a definite meaning, having a truth value that’s either true (T) or false (F) (never both, neither, or somewhere in between). (However, you might not know the actual truth value, and it might be situation-dependent.) In probability theory, we assign degrees of certainty to propositions. But for now: think True/False only!

7 Proposition: A statement that is either true or false (,but not both).
Examples Proposition: A statement that is either true or false (,but not both). Example: 1. Taipei is the capital of ROC. 2. Tokyo is the capital of Korea. = = 3. 5. There is no integer x,y,z and n > 2 s.t. xn + yn = zn Fermat’s last theorem 6. “Every even number > 2 is the sum of two prime numbers.” Goldbach’s conjecture (1742) ==> 1. Statement (1)~(6) are propositions, 2. (1),(3) are true; (2),(4) are false. 3. Nobody knew (5) is true or false until 1994, but it must be true or false, hence it is a proposition. (6) open problem.

8 Examples: 1. What time is it? (interrogative)
More Examples Examples: 1. What time is it? (interrogative) 2. Read this carefully! (command) 3. x+1 = 2. 4. x+y = z. 5. 李登輝是中華民國總統 ==> 1. (1) and (2) are not statements 2. (3),(4) are not propositions: neither true nor false! 3. How about (5) ?

9 Propositional variables and propositional constants
In algebra, we use variables to denote an item with unspecified value. e.g. 10 chickens and rabbits in a cage with 16 feet. ==> #rabbits = ? and #chickens=? ==> let x = #rabbits, y = #chickens ==> x + y = 10 /\ 2x + 4y = 16. Likewise, In logic, we can use propositional variable to denote an arbitrary proposition with unspecified truth value. e.g., If it is raining, the ground is wet. since the ground is wet, it is raining now. ==> Let p =def “It is raining”, q =def “the ground is wet” ==> ((p ->q) /\ q) -> p. Propositional constants(literals): only two values: T(true), F(false).

10 Operators / Connectives
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). ternary: p? a:b In C and Java Propositional or Boolean operators operate on propositions or 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.)

11 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

12 Primitive (or atomic) propositions:
Forming Compound propositions from simpler ones using logical connectives Primitive (or atomic) propositions: propositional variables propositional constants P, Q: two known propositions Then the followings are also propositions: 1. “P and Q” : ( P /\ Q) conjunction of P and Q 2. “It is not the case that p”: (~P) negation of P 3. “P or Q” : (P \/ Q) disjunction of P and Q 4. “P implies Q” : ( P  Q) implication P : antecedent, premise, hypotheses; Q: consequence, conclusion equivalent phrase: “P entails Q”, “Q if P”, “P only if Q” 5. “p iff q” (p <->q) equivalence of P and Q

13 Truth conditions for compound propositions
1. P /\ Q is true iff both P and Q are true 2. P \/ Q is true iff either P or Q is true 3. ~P is true iff P is not true (i.e., false) 4. P<->Q is true iff both are true or both are false. 5. PQ is true iff whenever P is true, Q is true ( i.e., it is not the case that P is true but Q is false ) In the propositions, /\, \/, <-> and  are called binary connectives(or operations) and ~ is called unary connective(or operations). Other binary connectives are possible. What about the truth condition for primitive propositions?

14 From natural language statements to formal logic expressions
Today is Friday I have a test today It is not the case that today is Friday Today is not Friday Today is Friday and If today is Friday, then I have a test today. Today is Friday or I have a test today. symbolized logic expr. p q ~p (P ∧ q) (pq) (P ∨ q)

15 Truth conditions for propositions
Problem: when will you say that the sentence: It_is_raining is true ? => The proposition:” It_is_raining” is true if the meaning (or fact) that the proposition is intended to represent occurs(happens, exists) in the situation which the proposition is intended to describe. =>Example: Since it is not raining now(the current situation), the statement It_is_raining is false (in the current situation). But if it were raining now, then I would say that It_is_raining is true. Factors affecting the truth value of a proposition: the situation in which the proposition is used. the meaning of the proposition.

16 The meaning of logical connectives can be
Truth table The meaning of logical connectives can be represented by a truth table.

17 Other usual connectives
Besides /\,\/, and <->, there are also some other connectives which you will study in digital system. xor , nand, nor. Rules: let I(x) denote the truth value of x. I(A  B)=def I(~(A<->B))=1 iff not I(A)=I(B) I(A nand B) =def I(~(A/\B)). I(A nor B) =def I(~( A \/B)).

18 E.g. If p = “I have brown hair.” then ¬p = “I do not have brown hair.”
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.” Truth table for NOT: T :≡ True; F :≡ False “:≡” means “is defined as” Operand column Result column

19 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 pq=“I will have salad for lunch and I will have steak for dinner.” ND Remember: “” points up like an “A”, and it means “ND”

20 Conjunction Truth Table
Notes: Conjunction  can be extended from binary to variable-arity operator The conjunction p1  … 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! Operand columns 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.

21 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.” pq=“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.” Meaning is like “and/or” in English.

22 Disjunction Truth Table
Note that pq 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

23 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.

24 Translate each of the following into English: ¬p = r  ¬p =
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.” “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.” 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.

25 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 for this course, or I will drop it (but not both!)”

26 Exclusive-Or Truth Table
Note that pq 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.

27 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.

28 The Implication Operator
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) in p  q , p is the antecedent and q is the consequent of the implication. 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.”

29 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.)

30 Examples of Implications
“If this lecture 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 ChenShuaBen 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.

31 Why does this seem wrong?
Consider a sentence like, “If I wear a red shirt tomorrow, then the sun will not rise tomorrow.” In logic, we consider the sentence True so long as either I don’t wear a red shirt, or the sun does not rise. But in natural language conversation, if I were to make this claim, you would think I was lying. Why this discrepancy between logic & language?

32 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) This sentence is logically False in our example, because for me to wear a red shirt and the sun to not rise 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.

33 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.

34 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 (logical equivalent; 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

35 How do we know for sure? Proving the equivalence of p  q and its contrapositive using truth tables:

36 The biconditional operator
The biconditional p  q states that p is true if and only if (IFF) q is true. p = “ChenShuaBen wins the 2004 election.” q = “ChenShuaBen will be president for all of 2005.” p  q = “If, and only if, ChenShuaBen wins the 2004 election, ChenShuaBen will be president for all of 2005.”

37 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! p  q means ¬(p  q) p  q does not imply p and q are true, or cause each other. Also, p IFF q is equivalent to (p -> q) /\ (q -> p). (“/\” being the AND wedge)

38 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.

39 Some Alternative Notations

40 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: 0 represents “false”; 1 represents “true”. Boolean algebra is like ordinary algebra except that variables stand for bits, + means “or”, and multiplication means “and”. See chapter 10 for more details. 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.

41 A Bit string of length n is an ordered series or sequence of n0 bits.
Bit Strings A Bit string of length n is an ordered series or sequence of n0 bits. By convention, bit strings are written left to right: e.g. the first bit of “ ” is 1. When a bit string represents a base-2 number, by convention the first bit is the most significant bit. Ex =8+4+1=13. We will talk about strings more generally later in the module on sequences.

42 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.

43 You have learned about: Propositions: What they are.
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.

44 §1.2 Propositional Equivalence
Two syntactically (i.e., textually) different compound propositions may be 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. Analogy: x * (5 + y) and xy + 5x are always equal in algebra. But how about p /\ (q \/ r) and (p/\q) \/ (p /\ r) ?

45 Tautology, contradiction and contingency
Some definitions: Let A be any proposition, then 1. A is a tautology(contradiction) iff A is true (false) no matter what the truth values of the prop. variables inside A are given. 2. If A is neither a tautology nor a contradiction, then A is called a contingency. Contingencies Contradictions (unsatisfiable) Tautologies (valid) The geography of propositions

46 p /\ ~p : a contradiction p, p  ~p, ~p  p : a contingency
Examples: p \/ ~p, p  p : a tautology p /\ ~p : a contradiction p, p  ~p, ~p  p : a contingency

47 Topic #1.1 – Propositional Logic: Equivalences
Logical Equivalence proposition p is logically equivalent to proposition q, written p  q, IFF the compound proposition pq is a tautology. Note:  is a logical symbol (connective) whereas  is a meta logical symbol. 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.

48 I.e., for all propositions A,B and C,
Logical Equivalence A and B are logically equivalent (,A  B) if A <-> B is a tautology Theorem1: Logical equivalence relation is reflexive, symmetric and transitive. I.e., for all propositions A,B and C, 1. A  A 2. A  B implies B A and 3. A  B and B  C imply A  C. Theorem2[substitution theorem]: If A  B and C[X] is a proposition containing X as a subproposition, then C[A] and C[B] are logically equivalent, where C[A] is the result of C with X in C replaced by A. ex: (p∨q)  (q∨p), C[X] =def ~(p ∧ X) => ~(p∧ (p∨q) )~(p∧ (q∨p))

49 Determine tautologies, contradictions and contingencies
Problems: Given a proposition A, how can you determine whether it is a tautology, a contradiction or a contingency? =>Exhausted evaluation! (by using truth table) e.g., A = (p->q) <-> (~p \/q) a tautology ? 1. there are two primitive props: p, q. 2. So there are 4 possible assignments of truth values to p and q. p=0,q=0: p=0,q=1: p=1,q=0: p=1,q=1: 3. Under each assignment, we can evaluate the truth value of A (in bottom up way) by the truth condition rule of connecting connectives.

50 Determine tautologies
p:0 q:0 p->q:1 ~p:1 ~p \/q:1 (pq)<->~p\/q :1 The evaluation tree for (p->q)<-> (~p\/q) The truth table for pq <-> ~p\/q A tautology since all are 1’s 1

51 Determine other properties
1. logical equivalence: A  B iff A<->B is a tautology. So we can apply the procedure for determining tautology to determine if A B. Or A and B have the same truth values in all rows of their truth table. 2. contradiction: A is a contradiction iff ~A is a tautology 3. Satisfiability: A is satisfiable iff ~A is not a tautology. 4. contingence: A is a contingence iff neither A nor ~A is a tautology. 5. logical consequence: B is a logical consequence of A [denoted A |= B] iff AB is a tautology.

52 Proving Equivalence via Truth Tables
Topic #1.1 – Propositional Logic: Equivalences Proving Equivalence via Truth Tables Ex. Prove that pq  (p  q). F T T T F T T F F T T F T F T T F F F T

53 Topic #1.1 – Propositional Logic: Equivalences
Equivalence Laws 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. if x + y = z, => x + (x + y) = x + z.

54 Equivalence Laws - Examples
Topic #1.1 – Propositional Logic: Equivalences Equivalence Laws - Examples Identity: pT  p pF  p Domination: pT  T pF  F Idempotent: pp  p pp  p Double negation: p  p Commutative: pq  qp pq  qp Associative: (pq)r  p(qr) (pq)r  p(qr)

55 Distributive: p(qr)  (pq)(pr) p(qr)  (pq)(pr)
Topic #1.1 – Propositional Logic: Equivalences More Equivalence Laws Distributive: p(qr)  (pq)(pr) p(qr)  (pq)(pr) De Morgan’s: (pq)  p  q (pq)  p  q generalization: ~ (p /\ q /\ r …)  ~p \/ ~q \/ ~r \/ … Trivial tautology/contradiction: p  p  T p  p  F Augustus De Morgan ( )

56 ~(p \/ (~p /\ q)) ~p /\ ~q
One Example: Show that ~(p \/ (~p /\ q)) ~p /\ ~q Proof: 1. By truth table (omitted) 2. ~(p \/ (~p /\ q)  deM ~p /\ ~(~p /\ q)  deM ~p /\ (~(~p) \/ ~q)  DbNeg [+substitution] ~p /\ (p \/ ~q)  Distr (~p /\ p) \/ (~p /\ ~q)  TrivalContradition F \/ (~p /\ ~q)  identity (~p /\ ~q)

57 Defining Operators via Equivalences
Topic #1.1 – Propositional Logic: Equivalences Defining Operators via Equivalences Using equivalences, we can define operators in terms of other operators. Exclusive or: pq  (pq)(pq) pq  (pq)(qp) Implies: pq  p  q Biconditional: pq  (pq)  (qp) pq  (pq) Boolean Algebra uses    as operations Boolean Ring uses   as operations

58 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) [Defn. of ]  (p  q)  ((p  r)  (p  r)) [DeMorgan’s Law + DoubleNeg]  (p  q)  ((p  r)  (p  r))  [associative law] cont.

59 (p  q)  ((p  r)  (p  r))  [ commutes]
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.

60 [DeMorgan’s]  q  (p  (p  r)) [Assoc.]  q  ((p  p)  r)
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.)

61 Review: Propositional Logic (§§1.1-1.2)
Topic #1 – Propositional Logic Review: Propositional Logic (§§ ) Atomic propositions: p, q, r, … Boolean operators: (~)      Compound propositions: s : (p  q)  r Equivalences: pq  (p  q) Proving equivalences using: Truth tables. Symbolic derivations. p  q  r …

62 1.3 Predicates (述詞) and quantifiers(量詞)
Problems of Propositional logic: Cannot analyze the content of primitive propositions. cannot group similar propositions cannot analyze quantifiers. Ex: Consider the following situations: 1. Family = {f,m,c1,c2,c3 } 2. We are interested in who is whose brother. 3. Suppose In Family, ci is cj’s brother if i ¹ j for i,j =1..3.

63 Inadequacy of propositional logic
Primitive propositions needed: x_is_y’s_brother, x,y Î Family So we need 25 propositions. New approach: Parameterized proposition(Predicate). Use a (predicate) symbol B to symbolize the statement: B(x,y) º x is y ‘s brother. e.g., B(f,c1) : f is c1’s brother, B(c2,c2) : c2 is c2’s brother, ...

64 Benefits of Predicates
Advantage of using predicates: ==> 1. need only 6 (1 predicate and 5 names) symbols. 2. can group related propositions together. (B(x,y) and others, for instance, q(x) º x_isOld. ) 3.The most important : allow representation of quantified statement like: c1_has_a_brother (or, there is an object x which is c1’s brother, $ x B(x, c1)) to be inferred from c2_is_c1’s brother ( B(c2,c1) )

65 1. Each predicate symbol has a fixed arity.
In the expression: B(x,y) B : predicate symbol (or proposition function) x (y) : first (2nd) argument B(x,y) : [atomic] proposition(or formula) #arguments in B(X,Y): the arity of the predicate symbol B. Notes: 1. Each predicate symbol has a fixed arity. 2. B(x,y,c1) and B(x) are meaningless. because used #arguments different from B’s arity.

66 3. The truth value of a proposition p(x1,...,xn)
Predicates (cont’d) 3. The truth value of a proposition p(x1,...,xn) depends on both p and real values of x1,...,xn. Ex1: Let p(x) º “x >3 “. then P(4) º “4 > 3” has truth value T, P(2) º “2 > 3” has truth value F. Ex2: Let Q(x,y) º “x = y +3” then Q(1,2) = “1 = 2 + 3” is false. Q(3,0) = “3 = 0 + 3” is true. Mathematically, we can define (the meaning of) P as a function [P] [P]: Un (n is P’s arity) --> {T,F}with the intention that “P(x1,...,xn)” holds (is true) iff [P]([x1],...,[xn]) = T.

67 Set representations of truth-functions
Ex: [B]: Family2 -->{T,F} s.t. [b](x,y) = T iff x =[ci], y=[cj], i ¹ j. p(x) º “x >3 “ , So [P]: N --> {T,F } s.t. [P](x) = T iff x > 3. Q(x,y) º “x = y +3” , so [Q] : N2 --> {T,F} with [Q](x,y) = T iff x = y +3. Note: P partition N into two sets, one with members mapped to T and one mapped to F. So, instead of represent P as a truth function, we equivalently represent P as the set {x | P(x) = T } = {4,5,6,...} P(x) = T. {1,2,3} {4,5,...} P(x) = F N Similarly, we can represent Q as {(x,y) | x = y + 3 }

68 constant, function, variables and terms
In the statement: “y > min(x, 3)” --- (s1) x,y are called variables, 3 is a constant, min is a function symbol with arity 2 “min(3,2)” behaves more like x, 3 than “x >y”. So if let P(x,y) º “x > y”, then s1 can be represented as P(y, min(x,3)) we call any expression that can be put on the argument position of an atomic proposition a term Obviously, constants and variables are terms; moreover,if f is a function of arity n, and t1,...tn are n terms, then so is f(t1,...,tn).

69 Quantifiers and universe of discourse
Consider the sentence: p(x) = “x > 0”. 1. as stated before, p(x) is true or false depending on the value of x. 2. p(1), p(2),... : true; p(0) , p(-1),...: false Universe of Discourse (U,論域): The set of objects (domain) from which all variables are allowed to have values. Ex: consider the sentence: s2: ”all numbers are greater than 0”. (for-all x “x > 0” ) or (" x p(x) ) U = N+={1,2,3,...} => s2 is true. U = Z={...,-1,0,1,...}=> s2 is false.

70 Universal and existential quantifications
A: any statement (or called formula) e.g., A = p(x,y) /\ q(x,f(3)),... x: any variable, Then 1. ("x A) is a new formula called the universal quantification of A, 2. ("x A) means: “A(x) is true for all values of x in the universe of discourse.” 3. ($x A) is a new formula called the existential quantification of A, 4. ($x A) means: “A(x) is true for some value of x in the universe of discourse.”

71 Quantifier Expressions
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.

72 The Universal Quantifier 
Topic #3 – Predicate Logic The Universal Quantifier  Example: Let the u.d. of x be parking spaces at the school. 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 the school are full.” i.e., “Every parking space at the school is full.” i.e., “For each parking space at the school, that space is full.” Instructors: You can substitute your favorite overly-crowded destination in place of the University of Florida in this example.

73 The Existential Quantifier 
Topic #3 – Predicate Logic The Existential Quantifier  Example: Let the u.d. of x be parking spaces at the school. 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 the school is full.” “There is a parking space at school that is full.” “At least one parking space at the school is full.”

74 Translation of NL statements into logical ones
Translate the following sentences into logical expressions: 1. Every body likes Chang 2. Everybody loves somebody. 3. There is somebody loved by every one. 4. Nobody likes everybody. 5.There is somebody Chang don’t like. 6. there is somebody no one likes. 7.there is exactly one person everybody likes. 8 Chang likes exactly two persons 9. Everyone likes himself. 10. There is someone who likes no one who does not like himself.

75 Natural language is ambiguous!
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.]

76 Occurrences of variables Free/Bound Variables
Some Terminology Occurrences of variables Free/Bound Variables

77 Occurrences of variables in a formula
A = p(f(x), c) \/ q(x,y) A contains 2 variables x, y, where x occurs twice and y occurs once.

78 Free and Bound Variables
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. ex: x p(x,y).

79 P(x,y) has 2 free variables, x and y.
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 proposition. An expression with one or more free variables is still only a predicate: x P(x,y) Note: we use expression and formula interchangeably as logical expressions are usually called formulas.

80 Nesting of Quantifiers
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 proposition with 0 free variables.)

81 Formalization of free variables
A: a formula (or expression) fv(A) = the set of all free variables in A is defined as follows: If A is atomic => fv(A) is the set of all variables in A fv(~A) = fv(A) fv(A/\B)=fv(A\/B)=fv(A->B)=fv(A<->B)= fv(A) U fv(B). fv(x A) = fv($xA) = fv(A)\ {x}.

82 Formalization of bound variables
bd(A): the set of bound variables in A is defined as follows; 1. If A is atomic => bd(A) = {} 2. bd(~A) = bd(A) 3. bd(A/\B) = d(A\/B) = bd(AB) =bd(A<->B) = bd(A) U bd(B). 4. bd( ∀x A) = bd(A) if x ∉ fv(A) bd(A) U {x} if x ∈ fv(A). Example A = ($ x p(x,y)) \/ q(x) => fv(A) = {x,y}; bd(A) = {x} x occurs twice in A, one occurs free and the other occurs bound. Def: A is a sentence iff fv(A) = {} Note: A is a proposition if A is a sentence

83 The meaning quantifications
A game-theoretic approach help you determine whether a proposition with nested quantifiers is true or false 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. Note: if the input expression is a proposition (ie., no free variables), then either the verifier or the falsifier wins.

84 Let’s Play, “Verify or Falsify!”
Topic #3 – Predicate Logic Let’s Play, “Verify or Falsify!” Let B(x,y) :≡ “x is less than y” where x and y are natural numbers . Suppose I claim that among you: x y B(x,y) Your turn, as falsifier: You pick any value, say, c for x. y B(c,y) My turn, as verifier: I pick (c+1) as the value for y B(c, c+1) : I(Verifier) always win! What if we switched the quantifiers, and claimed that y x B(x,y)? Who wins in that case? 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.

85 Still More Conventions
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))

86 More to Know About Binding
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 proposition! (x P(x))  (x Q(x)) – This is legal, because there are 2 different x’s!

87 Quantifier Equivalence Laws
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.

88 x y P(x,y)  y x P(x,y) x y P(x,y)  y x P(x,y)
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?

89 Review: Predicate Logic (§1.3)
Topic #3 – Predicate Logic Review: Predicate Logic (§1.3) Object variables :x, y, z, … Object contstants: a,b,c,… function symbols: f(-), father(-), min(-,-),… 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.

90 More Notational Conventions
Topic #3 – Predicate Logic More Notational Conventions Quantifiers bind as loosely as needed: parenthesize x P(x)  Q(x) 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 x1x2x3x4… P(x1, x2, x3, x4, …)

91 Defining New Quantifiers
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.”

92 Some Number Theory Examples
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 two non-unity numbers.” x (P(x)  (x>1  yz x=yz  y1  z1)) Note we can even use quantifier expressions to define concepts like even-ness and prime-ness.

93 Goldbach’s Conjecture (unproven)
“Every even number greater than 2 is the sum of two primes.” x [x>2  E(x)] → p q P(p)  P(q)  p+q = x. 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.

94 Topic #3 – Predicate Logic
Calculus Example One way of precisely defining the calculus concept of a limit, using quantifiers:

95 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. Set theory – a language for talking about collections of objects.

96 a set is a collection of objects.
1.4 Sets Basic structure upon which all other (discrete and continuous ) structures are built. a set is a collection of objects. an object is anything of interest, maybe itself a set. Definition 1. A set is a collection of objects. The objects in a set are called the elements or members of the set. If x is a member of a set S, we say S contains x. notation: x ÎS vs x Ï S Ex: In 1,2,3,4,5, the collection of 1,3 5 is a set.

97 the set of all positive odd integer < 10 = ?
Set description How to describe a set:? 1. List all its member. the set of all positive odd integer < 10 = ? The set all decimal digits = ? the set of all upper case English letters = ? The set of all nonnegative integers = ? 2. Set builder notation: P(x) : a property (or a statement or a proposition) about objects. e.g., P(x) = “ x > 0 and x is odd” then {x | P(x) } is the set of objects satisfying property P. P(3) is true => 3 Î {x | P(x)} P(2) is false => 2 Ï {x | P(x)}

98 The same set may have many different descriptions.
Conventions N =def {x | x is a natural numbers } = { 0,1,2,3,...} N+ =def {1,2,3,...} Z =def {...,-3,-2,-1,0,1,2,3,...} R =def the set of real numbers. Problem: The same set may have many different descriptions. {x | 0 < x <10 /\ x is odd } {1,3,5,7,9}, {5,3,1,9,7} {9,7,1,3,5}.

99 Two sets S1, S2 are equal iff they have the same elements
Set predicates Definition 2. Two sets S1, S2 are equal iff they have the same elements S1 = S2 iff "x (x Î S1 <-> x Î S2) Ex: {1,3,5} = {1,5,3} = {1,1,3,3, 5} Graphical representation of sets: Venn Diagrams: rectangle: Universal set: U circles: sets points: particular elements point x inside circle S => x Î S point x outside S => x Ï S.

100 Set predicates (cont’d)
Null set ={} = Æ =def the collection of no objects. Def 3’: [empty set] for-all x x Ï Æ. Def 3. [subset] A Í B iff all elements of A are elements of B. A Í B  for-all x (x Î A ⇒ x Î B)). Def 3’’: A Ì B =def A Í B /\ A ¹ B. Exercise : Show that: 1. For all set A (Æ Í A) 2. (A Í B /\ B Í A)  (A = B) 3. A Í Æ ⇒ A = Æ Diagram representation of the set inclusion relationship.

101 Size or cardinality of a set
Def. 4: | A | = the size(cardinality) of A = # of distinct elements of A. Ex: |{1,3,3,5}| = ? |{}| = ? | the set of binary digits } | = ? |N| = ? ; |Z| = ? ; | {2i | i ∈ N} = ? |R| = ? Def. 5. A set A is finite iff |A| is a natural number ; o/w it is infinite. Two sets are of the same size (cardinality) iff there is a 1-1 & onto mapping between them.

102 Def. A set A is said to be denumerable iff |A| = |N|.
countability of sets Def. A set A is said to be denumerable iff |A| = |N|. A set is countable iff either |A| = n for some n in N or |A| = |N|. Exercise: Show that 1. |N| = |Z | = | Q | = |{4,5,6,...}| 2. |R| = | (-1, 1) | = |(0,1)| 3. |(0,1)| is uncountable By exercise 1,2,3, R is not countable. Q and Z is countable.

103 The power set Def 6. If A is a set, then the collection of all subsets of A is also a set, called the power set of A and is denoted as P(A) or 2A. Ex: P({0,1,2}) = ? P({}) = ? |P({1,2,..., n})| = ? Elements in a set are not ordered. But sometimes we need to distinguish between (1,3,4) and (3,4,1) --> ordered n-tuples

104 Any ordered 2-tuple is called a pair.
Cartesian Products Def. 7 [n-tuple] If a1,a2,...,an (n > 0) are n objects, then “(a1,a2,...,an)” is a new object, called an (ordered) n-tuple [ with ai as its ith element. ] Any ordered 2-tuple is called a pair. (a1,a2,...,am) = (b1,b2,...,bn) means (1) m = n and (2) ai = bi for all 1 ≤ i ≤ m.

105 Def. 8: [Cartesian product]
A x B =def {(a,b) | a ∈ A and b ∈ B } A1 x A2 x ...x An =def {(a1,...,an) | ai ∈ Ai for all 1 ≤ i ≤ n}. Ex: A = {1,2}, B = {a,b,c} , C = {0,1} 1. A x B = ? ; 2. B x A = ? 3. A x {} = ? ; 4. A x B x C = ? problem: 1. when will A x B = B x A ? 2. |A x B | = ?

106 The diagonalization principle (D.P.)
R: a binary relation on a set A. D (the diagonal set for R ) =def { x | x Î A and (x,x) Ï R}. For each x Î A, let Ra (the raw of a) = { b Î A | (a,b) Î R}. Then D ≠ Ra for all a Î A. Example: Let A = {a,b,c,d,e,f} and R = Ra ={b,d} Rb={b,c} Rc={c} Rd={b,c,e,f} Re={e,f} Rf={a,c,d,e} D = {a,d,f}. D¹Rx since for each xÎA, xÎD iff (x,x)ÏR iff xÏRx.

107 Generalization of the diagonalization principle
A, B : two sets with a bijection f: A B. R :a relation from B to A (i.e., a subset of BxA). For all x ∈ A, let Rf(x) ≡ { y | y ∈ A ∧ (f(x),y) ∈ R } ⊆ A, and D ≡ { x | x ∈ A ∧ (f(x),x) ∉ R } ⊆ A. Then D ≠ Rf(x) for all x ∈ A. Pf: Analogous to the previous one. Notes: 1. C = {Rf(x) | x ∈ A} = { Ry | y ∈ B} ⊆ 2A is a set of subsets of A. 2. C ≠ 2A (∵ D ∈ 2A but D ∉ C ).

108 Generalization of the diagonalization principle
f:A B ; R: BxA Rfa ={b,d} Rfb={b,c} Rfc={c} Rfd={b,c,e,f} Rfe={e,f} Rff={a,c,d,e} D = {a,d,f}. D¹Rfx since for each f(x)ÎB, xÎD iff (f(x),x)ÏR iff xÏRf(x).

109 (2) Assume |A| = |2A|, i.e., there is a bijection f: A -> 2A.
Show that |A| ≠ |2A| Pf: (1) The case that A is finite is trivial since |2A| = 2|A| > |A| and there is no bijection b/t two finite sets with different sizes. (2) Assume |A| = |2A|, i.e., there is a bijection f: A -> 2A. Let R = {(x, y) ∈ 2A x A| x contains y } = {(f(x),y) | x, y ∈ A and f(x) contains y}. ==> Rf(x) = { y ∈ A | f(x) contains y} = f(x) and the diagonal set D = {x ∈ A | x Ï f(x) }. ==> (*) D is a subset of A and (**) By D.P. D ≠ Rf(x) = f(x) for all x ∈ A. ==> D is not a subset of A (∵ f is onto to 2A), a contradiction to (*).

110 Application of the diagonalization principle
Theorem: The set 2N is uncountable. pf: 1. direct from |A| ¹ |2A| with A = N. 2. another proof: suppose 2N is denumerable. Then there is a bijection f: N -> 2N. let 2N = {S0,S1,S2,...} where Si = f(i). Now the diagonal set D = { k | k Ï Sk }. By diagonalization principle, D ¹ Sk for any k, but D is a subset of N, by assumption D must equal to Sk for some k. a contradiction!

111 Program you are asked to design
The Halting Problem L : any of your favorite programming languages (C, C++, Java, BASIC, etc. ) Problem: write an L-program HALT(P,X), which takes another L-program P(-) and string X as input, and HALT(P,X) returns true if P(X) halts and returns false if P(X) does not halt. Program you are asked to design P(X) Halt ? yes true no false Pr(x:String) { ….. } P “It’s a test …” X HALT(P,X)

112 Halt(P,X) does not exist
where the proof is derived: Problem1 : What about the truth value of the sentence: L: L is false Problem 2 : Let S = {X | X X}. Does S belong to S or not ? The analysis: S  S => S  S; S  S => S  S. Conclusion: 1. S is not a set!! 2. If a language is too powerful, it may produce expressions that is meaningless or can not be realized. Question: If HALT(P,X) can be programmed, will it incur any absurd result like the case of S? Ans: yes!!

113 H(P) : a program that HALT(-,-) cannot predicate
Pr(x:String) { ….. } P P(P) Halt ? yes true no false HALT(P,X) Loop END P P Notes: 1. H uses HALT(-,-) as a subroutine. 2. H(P) Halts iff HALT(P,P) returns false iff P(P) does not halt. 3. H(H) halts iff HALT(H,H) returns false iff H(H) does not halt.  HALT is not a correct implementation!

114 union, intersection,difference , complement, Definition.
1.5 Set operations union, intersection,difference , complement, Definition. 1. AÈ B = {x | x ∈ A or x ∈ B } 2. AÇ B = {x | x ∈ A and x ∈ B } 3. If A Ç B = {} => call A and B disjoint. 4. A - B = {x | x ∈ A but x ∉ B } 5. ~ A = U - A Venn diagram representations Ex: U = {1,..,10}, A = { 1,2,3,5,8} B = {2,4,6,8,10} => AÈ B , AÇ B , A - B , ~ A = ?

115 Domination law: U ? ? = A; {} ?? = {} Idempotent law: A ? A = A ;
Set identities Identity laws: A ? ? = A Domination law: U ? ? = A; {} ?? = {} Idempotent law: A ? A = A ; complementation: ~~A = A commutative : A ? B = B ? A Associative: A ? (B ? C) = (A ? B ) ? C Distributive: A ? (B ? C) = ? DeMoregan laws: ~(AUB) = ?; ~(A ⋂ B)=?

116 Prove set equality 1. Show that ~(A È B) = ~A Ç ~B by show that 1. ~(A È B) Í ~A Ç~B 2. ~A Ç~B Í ~(A È B) pf: (By definition and logic reasonng) Let x be any element in ~(A È B) ... 2. show (1) by using set builder and logical equivalence. 3. Show distributive law by using membership table. 4. show ~(AÈ (BÇ C)) = (~C Ç~B) È ~A by set identities. Note the similarity between logical equivalence and set identities.

117 Generalized set operations
Def. 6 A1,A2,...An: n sets B = {A1,A2,...An } 1. A1È A2È An = ÈB = È{i=1,..n} Ai =def ? 2. A1Ç A2Ç An = ÇB = Ç {i=1,..n} Ai=def ? quiz: if B = {} => ÈB = ?; ÇB = ? Venn diagram representation of A1È A2È A3 and A1Ç A2Ç A3 . Example: A = {0,2,4,6,8}, B = {0,1,2,3,4}, C={0,3,6,9} => A1È A2È A3 = ? A1Ç A2Ç A3 = ?

118 Set representation (in computer)
Unordered list or array union, intersection, ~: time consuming. Bit string: U = {a1,...,an} is the universal set. A: any subset of U A can be represented by the string: s(A) = x1 x2 x3....xn where xi = 1 if a1 ∈ A and 0 o/w. fast set operations suitable only if U is not large. constant size representation.

119 Def. 1 [functions] A, B: two sets
1. a function f from A to B is a set of pairs (x, y) ∈ AxB s.t., for each x ∈ A there is at most one y ∈ B s.t. (x,y) ∈ f. 2. if (x,y) ∈ f, we write f(x) = y. 3. f :A B means f is a function from A to B. Def. 2. If f:A  B then 1. A: the domain of f; 2. B: the codomain of f if f(a)=b => 3. b is the image of a a is the preimage of b 5. range(f) = ? preimage(f) = ? 7. f is total iff ?

120 Def 4. f: A x B; S: a subset of A, T: a subset of B 1. f(S) =def ?
Types of functions Def f: A x B; S: a subset of A, T: a subset of B 1. f(S) =def ? 2. f-1(T) =def ? Def. [1-1, onto, injection, surjection, bijection] f: A -> B. f is 1-1 (a injection) iff ? f is onto (surjective, a surjection) iff ? f is 1-1 & onto <=> f is bijective (a bijection, 1-1 correspondence) Exercise:Show that if there are onto mappings from A to B and from B to A, then |A|=|B|.

121 Properties of functions
If there is an onto mapping from A to B, then there is a 1-1 mapping from B to A. If there is a 1-1 mapping from A to B then there is an onto mapping from B to A. The onto (≥ ) and the 1-1(≤ ) relations between sets are all preorders (i.e., refexive and transitive ) and are converse to each other. If there is a onto mapping from A to B and a onto mapping from B to A, then there is a 1-1 and onto mapping from A to B. pf: (1) Let f:AB an onto. For each b ∈ B, let g(b) = {x ∈ A | f(x) = b} ≠ ∅ ⇒ the function h:BAdefined by h(b) = any x ∈ g(b) is 1-1. (2,3) Similar to (1). (4) is hard (as an exercise?).

122 F:A B is a real valued function iff A and B are subsets of R.
Real valued functions F:A B is a real valued function iff A and B are subsets of R. f1,f2: real valued functions => 1. f1+f2 (x) = ? 2. f1• f2 (x) = f1(x) x f2(x). 3. f is increasing iff ? 4. f is strictly increasing iff ?

123 operations on functions
A, B, C: any sets ; f: A B; g: B  C, then 1. [identity function] idA : A A s.t. idA(x) = x for all x in A. 2. [composition of g and f] gf: A  C s.t. gf(x) = g(f(x)) for x in A. 3. [inverse] If f is a bijection, then f-1: B  A s.t. f-1(y) = x iff f(x) = y for y in B. Graphical representations

124 Properties of operations on functions
f: A  B. g: B C; h: C D, then 1. idA f = f = f idB 2. f(gh) = (fg) h --- assoc. 3. (fg)-1 = g-1 f-1 If f: A  A is a bijection then 4. f f-1 = f-1 f= idA . Sequence: finite A-sequence: a: [n] (or [1,n]) A w A-sequence: a : N (or N+)  A. B indexed A-sequence : f:BA.

125 The growth of functions
Summation rules S ai =def a1 + a2+...an+ (...) a + (a+d) + (a+2d)+... = ? a + ar +arr = ? The growth of functions: If f is a positive valued function, then what do the following terms mean? O(f) means ? o(f) means ? W(f) means ? w(f) means ? Q(f) means ? useful in the analysis of the efficiency of computer algorithms.

126 Problem, algorithm and Complexity
A problem is a general question: description of parameters [input] description of solution[output] An algorithm is a step by step procedure to solve a problem. a recipe a computer program We want the most efficient algorithm fastest (mostly) most economical with memory (sometimes) expressed as a function of problem size

127 Example: Traveling Salesman Problem
Parameters: Set of cities Inter-city distances c b d a 3 5 6 9 10

128 Solution: The shortest tour passing all cities
Solution [output] Solution: The shortest tour passing all cities Example: a,b,d,c,a has length 27 c b d a 3 5 6 9 10

129 What is appropriate measure of problem size?
m nodes? m(m+1)/2 distances? Use an encoding of the problem alphabet of symbols: a,b,c,d,0-9, |. strings: abcd||10|5|9|6|9|3. Measures Problem Size: length of encoding. Time Complexity: how long an algorithm takes, as function of problem size.

130 Time Complexity What is tractable? A function f(n) is O(g(n)) whenever ∃ c > 0 ∃ n0 > 0 s.t. |f(n)| ≤ c ∙ |g(n)| for all n > n0. A polynomial time algorithm is one whose time complexity is O(p(n)) for some polynomial p(n). An exponential time algorithm is one whose time complexity cannot be bounded by a polynomial (e.g., nlog n ).

131 execution time in microseconds(μs)
Tractability Basic distinction: polynomial time = tractable exponential time = intractable execution time in microseconds(μs) 10 20 30 40 50 60 n .00001s .00002s .00003s .00004s .00005s .00006s n2 .0001s .0004s .0009s .0016s .0025s .0036s n3 .001s .008s .027s .064s .125s .216s n5 .1s 3.2s 24.3s 1.7 m 5.2 m 13.0 m 2n 1.0s 17.9s 12.7d 35.7 y 366c 3n .059 s 58 m 6.5 y 3855 c 2∙108c 1.3∙10 13 c

132 Effect of Speed-ups for different order of functions
Wait for faster hardware! Consider maximum problem size you can solve in an hour. present 100 times faster 1000 times faster n N1 100 N1 1000 N1 n2 N2 10N2 31.6 N2 n3 N3 4.64 N3 10 N3 n5 N4 2.5 N4 3.98 N4 2n N5 N5+6.64 N5+9.97 3n N6 N6+4.19 N6+2.29

133 Asymptotic notations Asymptotic analysis: care only the value of f(n) when n is very large. discard the difference of f and g when limit f/g is a constant. Q((g(n)) = {f(n) | c2,c1 and k > 0 s.t. c2g(n)  f(n)  c1 g(n) for all n > k } O((g(n)) = {f(n) |  c and k > 0 s.t. f(n)  cg(n) for all n > k } W((g(n)) = {f(n) | c and k > 0 s.t. c g(n)  f(n) for all n > k } o((g(n)) = {f(n) | arbitrary small c >0  k > 0 s.t. f(n) < c g(n) for all n >k } w((g(n)) = {f(n) | arbitrary large c >0  k > 0 s.t. c g(n) < f(n) for all n > k }

134 Ex1: Show that f(x) = x2 + 2x+ 1 is O(x2).
Examples Ex1: Show that f(x) = x2 + 2x+ 1 is O(x2). pf: Let c = 4, k = 1, It is easy to check that if x > k, then f(x) = x2 + 2x+ 1 ≤ x2 + 2 x2 + x2 ≤ c x2. Hence by definition, f(x) = O(x2). Ex2: Show that f(x) = x2 + 2x+ 1 is W(x2). pf: Let c = 1, k = 1. Obviously, x2+2x+1 ≥ x2 = cx2 for all x >1=k. Hence f(x) = W(x2).

135 Ex2: Show that f(x) = x2 + 2x+ 1 is Q(x2).
pf: Let c1 = 1,c2=4, k = 1. c1x2 ≤ x2+2x+1 ≤ c2 x2 for all x >1=k. Hence f(x) = Q(x2). Proposition: f = Q(g) iff f = O(g) and f = W(g). pf: (=>:) direct from definition. (<=:) if f = O(g) = Q(g) => ∃ c1, k1 s.t f(x) ≤ c1 g(x) for all x > k1. ∃ c2, k2 s.t f(x) ≥ c2 g(x) for all x > k2. let k = max(k1,k2) => c2 g(x) ≤ f(x) ≤ c1 g(x) for all x > k. Hence f(x) = Q(g).

136 Ex2: Show that f(x) = x2 + 2x+ 1 is not in o(x2).
Example: Ex2: Show that f(x) = x2 + 2x+ 1 is not in o(x2). pf: f(x) = o(x2) means ∀c > 0, ∃ k with f(x) < c g(x) for all x > k. But this does not hold: for c = 1, for all k > 0, we have f(x) ≥ c g(x) for some x > max(1, k). Hence f(x) is not in o(x2). Ex2: Show that f(x) = x2 + 2x+ 1 is in o(x3). pf: for any c > 0, x2 + 2x + 1 < c x3 iff 1/x + 2/x2 + 1/x3 < c Note since 1/x + 2/x2 + 1/x3 is decreasing and its limit is 0, we can always find a k s.t. 1/x + 2/x2 + 1/x3 < c for all x > k. Hence f(x) = o(x3).

137 Using the asymptotic notations
We use f(n) = D(g(n)) to mean f(n) D(g(n)), where D = Q,O,o,W,or w. analogy: O (asymptotic upper bound):  f(n) = O(g(n)) behaves like f(n)  g(n) o (asymptotic upper bound but not tight): < f(n) = o(g(n)) behaves like f(n) < g(n) W (asymptotic lower bound):  f(n) = W(g(n)) behaves like f(n)  g(n) w (asymptotic lower bound but not tight): > f(n) = w(g(n)) behaves like f(n) > g(n) Q (asymptotic tight bound : = f(n) = Q (g(n)) behaves like f(n) = g(n)

138 Let f and g be positive real function. Show that
Exercises Let f and g be positive real function. Show that 1. f = O(g) iff g = W(f) 2. f = o(g) iff g = w(f) 3. f = o(g) iff f = O(g) and f ≠ Q(g) 4. f = w (g) iff f = W(g) and f ≠ Q(g) 5. f = o(g) iff limit n f/g = 0 iff limit n g/f =  iff g = w(f). 6. f= Q(g) iff limit n g/f is bounded 7. f=O(g) iff f=o(g) or f= Q(g) 8. f= W(g) iff f= w (g) or f = Q(g)


Download ppt "Chapter 1. The Foundations"

Similar presentations


Ads by Google