Propositional Logic Propositional Logic
Total Page:16
File Type:pdf, Size:1020Kb
9/9/2020 CS4350: Logic in computer Science Propositional Logic 1 Propositional Logic • In Propositional Logic (a.k.a Propositional Calculus or Sentential Logic), the primitive objects are called propositions • Definition: A proposition is a statement that is either true or false, but not both. • We usually denote a proposition by a letter: p, q, r, s, …, called propositional variables. 2 1 9/9/2020 Logic as a Language • Syntax: – Symbols: What symbols are eligible – Grammars: how well-formed sentences (formulas) are formed • Semantics: – Meaning of symbols – Truthiness of formulas • Proof Procedures – How to prove theorems (true formulas if the premises are true) from the given premises. 3 Propositional Logic: Syntax Two types of symbols: • Propositional variables: p, q, r, … • Vp: set of propositional variables • Logical operators (Connectives): • Nullary (Constants): 1, (or T), 0 (or F). They serve also as the truth values (semantic level) • Unary: (not) • Binary: (and), (or), (implies), (logical equal), (exclusive or). • Auxiliary symbols: Parenthesis “(“, “)”, comma, “,”. 4 2 9/9/2020 Propositional Formulas • The set of formulas, F, is defined as the smallest set of expressions such that: 1. Vp F 2. pF implies that (p) F 3. p, q F implies that (p o q) F, where o is a binary operator. 5 Formulas (BNF) • Context-Free Grammar – F ::= p, – F ::= ( F), – F ::= (F o F), where p is in Vp and o is a binary operator. • Backus-Naur Form (BNF) – F ::= Vp | ( F) | (FOpF), where Vp is a set of propositional variables and Op is a set of binary operators. 6 3 9/9/2020 Formulas (examples) • (p) • ( (p)) • (p (q r)) • (p (q r)) • Correct expressions of Propositional Logic are full of unnecessary parenthesis. 7 Formulas (Abbreviations) • Letobeoneof , , . We write A o B o C o … • in the place of (A o (B o (C o …))) • Thus, we write A B C, ABC, … • in the place of (A (B C)), (A (B C)) 8 4 9/9/2020 Precedence of Logical Operators • As in arithmetic, an ordering is imposed on the use of logical operators in compound propositions p q r instead of (p) (q (r)) • To avoid unnecessary parenthesis, the following precedence order holds: 1. Negation () 2. Conjunction () 3. Disjunction () 4. Implication () 5. Logical equal () 9 Formulas (precedence) • We omit parenthesis whenever we may restore them through operator precedence: • binds more strictly than , , and , bind more strictly than , . • Thus, we write: A B for (( A) B), A B C for ((A B) C) • How about A B C or A B C? – Answer: ((A B) C) and ((A B) C) 10 5 9/9/2020 Formula Trees • Each formula has a ((( p1 ( p0))) p0) unique tree: each node of the tree has a symbol. • Each subtree represents a subformula. • B is a proper subformula of A if B is a subformula of A and B A. 11 Logic as a Language • Syntax: – Symbols: What symbols are eligible – Grammars: how well-formed sentences (formulas) are formed • Semantics: – Meaning of symbols – Truthiness of formulas • Proof Procedures – How to prove theorems (true formulas if the premises are true) from the given premises. 12 6 9/9/2020 Meaning of symbols • Meaning of logical operators • Meaning of propositional variables 13 Logical Connective: Negation • p, the negation of a proposition p, is also a proposition • Example: Let p be “Today is Monday”, then p means – Today is not Monday – It is not the case that today is Monday, etc. • Truth table (define the meaning of operators) p p 0 1 1 0 14 7 9/9/2020 Logical Connective: And • The logical connective And is true only when both of the propositions are true. It is also called a conjunction and the propositions are called conjuncts • Examples – Tom’s cat is dead and Tom’s cat is not dead. – It is raining and it is warm – (2+3=5) and (1<2) p q pq • Truth table 0 0 0 0 1 0 1 0 0 1 1 1 15 Logical Connective: Or • The logical disjunction, or logical Or, is true if one or both of the propositions (called disjuncts) are true. • Examples – It is raining or it is the second lecture – (2+2=5) (1<2) – You may have cake or ice cream • Truth table p q pq pq 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 1 16 8 9/9/2020 Logical Connective: Exclusive Or • The exclusive Or, or XOR, of two propositions is true when exactly one of the propositions is true and the other one is false • Examples – The circuit is either ON or OFF but not both – Let ab<0, then either a<0 or b<0 but not both – You may have cake or ice cream, but not both • Truth table p q pq pq pq 0 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 1 0 17 Logical Connective: Implication • Definition: Let p and q be two propositions. The implication pq is the proposition that denotes a conditional statement which is false when p is true and q is false and true otherwise. – p is called the hypothesis, condition, premise – q is called the conclusion, consequence • Truth table p q pq pq pq pq 000001 010111 100110 111101 18 9 9/9/2020 Logical Connective: Implication The implication pq can be used for • If p then q • p implies q • If p, q • p only if q • q if p • q when p • q whenever p • q follows from p • p is a sufficient condition for q (p is sufficient for q) • q is a necessary condition for p (q is necessary for p) 19 Logical Connective: Implication Examples • If you buy you air ticket in advance, it is cheaper. • If x is an integer, then x2 0. • If it rains, the grass gets wet. • If the sprinklers operate, the grass gets wet. • If 2+2=5, then all unicorns are pink. 20 10 9/9/2020 Exercise: Which of the following is true? • If -1 is positive, then 2+2=5 True. The premise is obviously false, thus no matter what the conclusion is, the implication holds. • If -1 is positive, then 2+2=4 True. Same as above. • If sin(x) = 0, then x = 0 False. x can be a multiple of . If we let x=2, then sin x=0 but x0. The implication “if sin x = 0, then x = k, for some k” is true. 21 Converse, Inverse, Contrapositive Consider the proposition p q • Its converse is the proposition q p • Its inverse is the proposition p q • Its contrapositive is the proposition q p p q p q q p pq qp 0 0 1 1 1 1 0 1 1 0 0 1 1 0 0 1 1 0 1 1 1 1 1 1 22 11 9/9/2020 Logical Connective: Logical equal • Definition: The logical equal (or biconditional) pq is the proposition that is true when p and q have the same truth values. It is false otherwise. • Truth table p q pq pq pq pq p q 0000011 0101110 1001100 1111011 23 Logical Connective: Logical Equal • The logical equal pq can be used for – p if and only if q – p is a necessary and sufficient condition for q – if p then q, and conversely – p iff q • Examples – x>0 iff x2 is positive – The alarm goes off iff a burglar breaks in – You may have pudding if and only if you eat your meat 24 12 9/9/2020 Exercise: Which of the following relation is true? • x2 + y2 = 0 iff x=0 and y=0 True. Both implications hold • 2 + 2 = 4 iff 2<2 True. Both implications hold. • x2 0 iff x 0 False. The implication “if x 0 then x2 0” holds. However, the implication “if x2 0 then x 0” is false. Consider x = -1. The hypothesis (-1)2=1 0 but the conclusion fails. 25 Truth Tables • Truth tables are used to show/define the meanings of logical operators. It shows the relationships of truth values of – the primitive propositions and – the compound propositions based on them p q pq pq pq pq pq 0000011 0101110 1001100 1111011 26 13 9/9/2020 Constructing Truth Tables • Construct the truth table for the following compound proposition p q q p q p q q p q q 000 1 1 010 0 0 100 1 1 111 0 1 27 Meaning of Propositional Variables • Informal meaning: – Assigned in the beginning of application when introducing the symbol for a statement – E.g., p stands for “it is raining” in one example and “Mr. X killed Y” in another example. • Formal meaning: – The symbol is given a truth value, either true or false (1 or 0). – We can use a procedure (syntactic tool) to manipulate these values for formal reasoning. 28 14 9/9/2020 Interpretation (Truth Assignment ) • Definition: A (full) interpretation (truth assignment), σ is a total function σ: Vp {0, 1} • May represent σ by σ = { p 1, q 0 } if Vp = { p, q } • A short hand for σ is (1, 0) if Vp is viewed as (p, q). • It can be represented by a subset of Vp, i.e., an elements of 2Vp (the power set of Vp). • |Vp| There are 2 distinct interpretations. σ pq • Example: Vp = { p, q }, 2Vp = { {}, {p}, {q}, {p, q} } {} 00 • E.g., σ = { p } = { p 1, q 0 } { p } 1 0 { q } 0 1 • Alternative representation: { p, q } 1 1 σ is a set of literals, e.g.