Create Presentation
Download Presentation

Download Presentation

Chapter 1. The Foundations: Logic and Proofs

Download Presentation
## Chapter 1. The Foundations: Logic and Proofs

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -

**Chapter 1. The Foundations: Logic and Proofs**Cheng-Chia Chen**1. The foundations : logic and proofs**• Logic and proofs: • The basis of all mathematical reasoning • has practical applications to the design of computing machine • give the precise meaning of math. statements.**Foundations of Logic (§§1.1-1.4)**Mathematical Logicis 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.**Foundations of Logic: Overview**• Propositional logic (§1.1-1.2): • Basic definitions. (§1.1) • Equivalence rules & derivations. (§1.2) • Predicate logic (§1.3-1.4) • Predicates. • Quantified predicate expressions. • Equivalences & derivations.**§1.1 Propositional Logic**Propositional Logic is the logic of compound statements built from simpler statements using so-called Booleanconnectives. Some applications in computer science: • Design of digital electronic circuits. • Expressing conditions in programs. • Queries to databases & search engines. George Boole(1815-1864)**Proposition**• Proposition: A statement that is either true or false (,but not both) • even if we do not know it is true or false now. • Example: 1. Taipei is the capital of ROC. 2. Tokyo is the capital of Korea. 3. 1+1 = 2. 4. 2+2 = 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.**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) ?**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).**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.**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**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. PQ 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?**Natural language statement**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 I have a test today 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 (P ∧ q) (pq) (P ∨ q) From natural language statements to formal logic expressions**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.**Truth table**• The meaning of logical connectives can also be • represented by a truth table.**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)).**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 “” and “” takes precedence over “”. • ¬s f means (¬s) f , not ¬ (s f)**The Implication Operator**• The implicationp 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.**The onlyFalsecase!**Implication Truth Table • p q is falseonly whenp is true but q is not true. • p q does not saythat pcausesq! • p q does not requirethat p or qare ever true! • E.g.“(1=0) pigs can fly” is TRUE!**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.”Trueor False?**“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. English Phrases Meaning p q**Converse, Inverse, Contrapositive**Some terminology, for an implication p q: • Its converseis: q p. • Its inverse is: ¬p ¬q. • Its contrapositive: ¬q ¬p. • Which of the above three has the same meaning (logical equivalent; same truth table) as p q ? • Ans: ¬q ¬p.**How do we know for sure?**Proving the equivalence of p q and its contrapositive using truth tables:**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.**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.**Bit Strings**• A Bit string of length n is an ordered series or sequence of n0 bits. • By convention, bit strings are written left to right: e.g. the first bit of “1001101010” is 1. • When a bit string represents a base-2 number, by convention the first bit is the most significant bit. Ex. 11012=8+4+1=13.**Topic #2 – Bits**Bitwise Operations • Boolean operations can be extended to operate on bit strings as well as single bits. • E.g.:01 1011 011011 0001 110111 1011 Bit-wise OR01 0001 Bit-wise AND10 1010 Bit-wise XOR**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. End of §1.1**§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) ?**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**Examples:**• p \/ ~p, p p : a tautology • p /\ ~p : a contradiction • p, p ~p, ~p p : a contingency**Topic #1.1 – Propositional Logic: Equivalences**Logical Equivalence • proposition A is logically equivalent to proposition B, written A B, IFFthe compound proposition AB is a tautology. Note:1. is a logical symbol (connective) whereas is a meta logical symbol. 2. The textbook uses instead of . • Propositions A and Bare logically equivalent to each other iff A and Bcontain the same truth values as each other in all rows of their truth tables.**Logical Equivalence**• 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))**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.**(pq)<->~p\/q :1**• p->q:1 ~p \/q:1 ~p:1 q:0 p:0 The evaluation tree for (p->q)<-> (~p\/q) 1 1 1 1 1 0 0 0 1 0 1 1 The truth table for pq <-> ~p\/q Determine tautologies A tautology since all are 1’s**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 AB is a tautology.**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**Topic #1.1 – Propositional Logic: Equivalences**Equivalence Laws • In algebra, we make use of equality reasoning to replace equal by equal: • Ex: • Given the know equality: x + y = z, • we have x + (x + y) = x + z. • Thanks to substitution theorem, we can do also equality reasoning for logical expressions. Ex: • since p \/ p p, • q /\ ( p \/ p) q \/ p**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) Note. The textbook uses instead of .**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 • generalization: • ~ (p /\ q /\ r …) ~p \/ ~q \/ ~r \/ … • Trivial tautology/contradiction:p p Tp p F AugustusDe Morgan(1806-1871)**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)**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) • Boolean Algebra uses as operations • Boolean Ring uses T as operations**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)[definition of ] • (p q) (pr)[Defn. of ] • (p q) ((p r) (p r)) [DeMorgan’s Law + DoubleNeg] (p q) ((p r) (p r))[ commutes] • (q p) ((p r) (p r))**Topic #1.1 – Propositional Logic: Equivalences**Example Continued... • (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))) [trival taut.] q ((T r) (p (p r))) [domination] q (T (p (p r)))[identity] q (p (p r)) cont.**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.)**Topic #1 – Propositional Logic**Review: Propositional Logic (§§1.1-1.2) • Atomic propositions: p, q, r, … • Boolean operators: (~) • Compound propositions: (p q) r • Equivalences:pq (p q) • Proving equivalences using: • Truth tables. • Symbolic derivations. p q r …**Logical puzzles**Knight or knave: • Two kinds of inhabitants lived in an island • Knights : always tell the truth • Knaves : always lie. • Dialog of two people A and B lived in the island: • A : “You are a knight”, • B: “ We are opposite types” • Question: What are the kinds of A and B ?**Solution:**• Formalization : • Let p = “ A is a knight” ; ~p “A is a knave” • Let q = “B is a knight” ; ~q “B is a knave” • Observed facts: • 1. since A says q, we have • p q (1) /\ ~p ~q (2) • 2. since B says R where • R is (p /\ ~q) \/ ( ~p /\ q) ) (5) , we have • q R (3) /\ ~q ~R (4). • Analysis: • p true =(1)=> q true =(3)=> R true • =(5)=> R false (a contradiction!) • P false =(2)=>q false =(4)=> ~R => ~p /\ ~q. (consistent). • Conclusion: Both are knaves!!**Muddy Children puzzle ( reasoning about knowledge)**• Two children Son and Daughter getting dirty mud on their foreheads. • Father says to them: “At lest one of you has a muddy forehead.” (1) • F2S: Do you know whether you have a muddy forehead? • S : No, • Then, F2D: Do you know whether you have a muddy forehead? • D: Yes. • Problem: Why did S and D answer No and Yes, respectively?