<<

9/9/2020

CS4350: in Science

Propositional Logic

1

Propositional Logic

• In Propositional Logic (a.k.a or Sentential Logic), the primitive objects are called • Definition: A is a that is either true or , 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 • : – 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),  (). • 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. pF implies that (p) F 3. p, q F implies that (p o q)  F, where o is a binary operator.

5

Formulas (BNF)

-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) | (FOpF), 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 o … • in the place of (A o (B o (C o …))) • Thus, we write A  B  C, ABC, … • 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. () 2. () 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. • (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 pq • Truth table 0 0 0 0 1 0 1 0 0 1 1 1

15

Logical Connective: Or

• The , 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 pq pq 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 pq pq pq 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 pq 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 pq pq pq pq 000001 010111 100110 111101

18

9 9/9/2020

Logical Connective: Implication

The implication pq 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 x0. The implication “if sin x = 0, then x = k, for some k” is true.

21

Converse, Inverse, Contrapositive

Consider the proposition p  q • Its 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 pq qp

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) pq is the proposition that is true when p and q have the same truth values. It is false otherwise. • Truth table

p q pq pq pq pq p q

0000011 0101110 1001100 1111011

23

Logical Connective: Logical Equal

• The logical equal pq can be used for – p 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 pq pq pq pq pq

0000011 0101110 1001100 1111011

26

13 9/9/2020

Constructing Truth Tables

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 , 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 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. σ = { p, q } for (1, 0). 29

Algorithm eval(A, σ) Given a formula p and an interpretation σ: proc eval(A, σ) if A = 1 or A = 0 return A; else if A ∈ Vp return σ(A); else if A is ¬B return ¬eval(B, σ); else A is (B op C) return eval(B, σ) op eval(C, σ); // op is a binary logical operator

eval(A, σ) returns the truth value of A under σ. It takes O(|A|) time, where |A| is # of symbols in A.

30

15 9/9/2020

eval(A, σ) in Equational Form • Recursive Definition: eval(p, σ) = p if p = 0 or p = 1 eval(p, σ) = σ(p) if p  Vp eval( A, σ) =  eval(A, σ) eval(A  B) = eval(A, σ)  eval(B, σ) eval(A  B) = eval(A, σ)  eval(B, σ) eval(A  B) = eval(A, σ)  eval(B, σ) eval(A  B) = eval(A, σ)  eval(B, σ) eval(A  B) = eval(A, σ)  eval(B, σ)

31

Logician’s view • Let σ(A) = eval(A, σ), – σ( A) = (σ(A)) – σ(A op B) = (σ(A) op σ(A)) for all binary operators op. – So σ becomes a function from F to { 0, 1} • σ(A) = 1 means – σ satisfies A or – A is true in σ or – A holds at σ or – σ is a model of A

32

16 9/9/2020

Electrical Engineer’s view • σ (A) is a mapping of voltages on a set of wires (σ: Vp  {0,1}) over a circuit (formula A): : {0,1}  {0,1} • (0) = 1 and (1) = 0 : {0,1}2  {0,1} • (0  0) = (0  1) = (1  0) = 0 and (1  1) = 1  : {0,1}2  {0,1} • (1  1) = (0  1) = (1  0) = 1 and (0  0) = 0  : {0,1}2  {0,1} • (1  1) = (0  1) = (0  0) = 1 and (1  0) = 0

33

eval(A, ) when A is a formula tree

• Consider the formula A is (p  (q  r)) and  = { p, q, r}.

• The formula tree: 1  0 0 p 

1 0 • The nodes marked with q r truth values.

34

34

17 9/9/2020

M(A): Set of all models of A • Definition: For any formula A, M(A) is the set of all models of A, i.e., all interpretations that satisfy A. • Informally, formula A serves as a divider for interpretations, some are in M(A), and some are out. • Logician’s view: Function M: F  22Vp

35

Computing M(A)

• A simple algorithm: proc Models(A) M := {} for all σ  2Vp If (eval(A, σ) = 1) M := M  {σ} return M

• Models(A) takes O(|A|2|Vp|) time.

36

18 9/9/2020

Computing M(A) by Truth Tables

• Truth table for p  q q tells us which interpretations are models.

p q p  q  q p  q q M(p  q q ) = { 000 1 1 (0, 0), 010 0 0 100 1 1 (1, 0), 111 0 1 (1, 1) } interpretations

37

M(A): Set of all models of A Theorem: • M(p) = { σ 2Vp | σ(p) = 1 } for any p  Vp – σ(p) = 1 iff σ is a model of p • M( A) = 2Vp – M(A) – σ is a model of A iff σ is not a model of  A • M(A  B) = M(A)  M(B) – σ is a model of A  B iff σ is both a model of A and of B. • M(A  B) = M(A)  M(B) – σ is a model of A  B iff σ is either a model of A or of B. • M(A  B) = (2Vp – M(A))  M(B) – A  B is equivalent to  A  B

38

19 9/9/2020

Exercise Problem

Suppose Vp = { p, q, r }. Then • M((p  q)  r) = ? 2Vp = { , {p}, {q}, {r}, {p, q}, {p, r}, {q, r}, {p, q, r} } • M(p) = { {p}, {p, q}, {p, r}, {p, q, r}} • M(q) = { {q}, {p, q}, {q, r}, {p, q, r}} • M(r) = { {r}, {p, r}, {q, r}, {p, q, r}} • M(p  q) = (2Vp – M(p))  M(q) = { {}, {q}, {r}, {q, r}, {p, q}, {p, q, r} } • M((p  q)  r) = M(p  q)  M(r) = { {r}, {q, r}, { p, q, r } }

39

Theorem

• Let A  F and σ  2Vp, then σ(A) = 1 iff σ  M(A)

Proof: σ(A) = 1 means eval(A, σ) = 1, i,e, σ is a model of A, thus σ  M(A) by the definition of M(A).

40

20 9/9/2020

Valid, Satisfiable,

• A formula A is called valid (a ) if M(A) = 2Vp. We denote validity of A by |= A • A formula A is called satisfiable if M(A) ≠ . That is, A has at least one model. • A formula A is not satisfiable, i.e., M(A) = , is called unsatisfiable or contradiction.

41

Valid, Satisfiable, Contradiction

Theorem: • A formula A is valid iff  A is unsatisfiable – M(A) = 2Vp iff M( A) = 2Vp – M(A) = 

• A is satisfiable iff  A is not valid – M(A) ≠  iff M( A) = 2Vp – M(A) ≠ 2Vp

42

21 9/9/2020

Satisfiability Problem

• Given a formula A, is A satisfiable?

• A simple algorithm: proc SAT(A) for all σ  2Vp If eval(A, σ) return 1 return 0

• SAT(A) takes O(|A|2|Vp|) time. • The first NP-Complete Problem

43

Entailment: |=

• First definition: |= is a unary relation on F: |= A iff A is valid. • Second definition |= is a binary relation on F: A |= B iff M(A)  M(B) We say “A entails B”, or “B is entailed by A”, or “B is a of A”, or “B follows A logically”. The first definition is a special case of the second: |= A iff 1 |= A. Notational difference: p |= q versus p  q Alert: |= is not a logical operator.

44

22 9/9/2020

Logical Consequence: Example • Is the formula (p  q) a logical consequence of (p q) ? • To find out, we construct the truth tables for each:

p q pq  p  q 00 1 1 01 1 0 10 0 0 11 1 0

• M(p  q) = { , { q }, {p, q} } = { (0, 0), (0, 1), (1, 1) } • M(p q) = {  } = { (0, 0) }  M(p  q)

45

Logical Equivalence 

• Definition: Formulas A and B are logically equivalent if M(A) = M(B), and we denote this relation by A  B. • Informally, A and B are equivalent if whenever A is true in an interpretation, so is B, and vice versa • Notational difference: p  q versus p  q • Alert:  is not a logical connective.

46

23 9/9/2020

Logical Equivalence: Example • Are the formulas (p  q) and (p  q) logically equivalent? • To find out, we construct the truth tables for each:

p q p  q  p  p  q 00 1 1 1 01 1 1 1 10 0 0 0 11 1 0 1

The two columns in the truth table are identical, thus we conclude that (p  q)  (p  q)

47

Logical Equivalence: Example

• Show (p  r)  (q  r)  (p  q)  r

p q r p r q r (p r)  (q  r) p  q (p  q)  r 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1

48

24 9/9/2020

Logical Equivalence: Example

(p  r)  (q  r)  (p  q)  r

p q r p r q r (p r)  (q  r) p  q (p  q)  r 00011 1 0 1 00111 1 0 1 01010 1 0 1 01111 1 0 1 10001 1 0 1 10111 1 0 1 11000 0 1 0 11111 1 1 1 Both (p  r)  (q  r) and (p  q)  r have the same set of seven models.

49

Logical Equivalences (, )

• p  1 ≡ 1 Domination law • p  0 ≡ 0 Domination law • p  0 ≡p Identitylaw • p  1 ≡p Identitylaw • p  p ≡ p Idempotent law • p  p ≡ p Idempotent law • p  q ≡ q  p Commutative law • p  q ≡ q  p Commutative law

50

50

25 9/9/2020

Logical Equivalences (, )

• (p  q)  r ≡ p  (q  r) Associative law • (p  q)  r ≡ p  (q  r) Associative law • (p  q)  r ≡ (p  r)  (q  r) Distributive law • r  (p  q) ≡ (r  p)  (r  p) Distributivelaw • (p  q)  r ≡ (p  r)  (q  r) Distributive law • r  (p  q) ≡ (r  p)  (r  p) Distributivelaw • p  (p  q) ≡ p • p  (p  q) ≡ p Absorption law

51

51

Logical Equivalences (¬)

• ¬¬p≡p Doublenegationlaw • p  ¬p≡1 Negationlaw • p  ¬p≡0 Negationlaw • ¬ (p  q) ≡ ¬ p  ¬ q DeMorgan’s law • ¬ (p  q) ≡ ¬ p  ¬ q DeMorgan’s law

52

52

26 9/9/2020

Logical Equivalences (,,)

• p  q ≡ ¬ p  q implication elimination • p  q ≡ (p  q)  (q  p) • p  q ≡ (¬ p  q)  (p  ¬q) equal elimination • p  q ≡ (p  q)  (¬ p  ¬q) • p  q ≡ ¬(p  q) ≡ (¬p  q) ≡ (p  ¬ q) • p  q ≡ (p  q)  (¬ p  ¬q) excl. or elimination • p  q ≡ (p  ¬ q)  (p  ¬q)

53

53

|= vs  and  vs  • |= is reflexive and transitive •  is reflexive, symmetric and transitive • A |= B iff |= A  B Proof: A |= B iff M(A)  M(B) iff for any interpretation , ((A)(B))  1, iff (A  B)  1. • A  B iff |= A  B Proof: A  B iff A|= B and B |= A, A  B  A  B  B  A. Use A |= B iff |= A  B twice.

54

27 9/9/2020

Using Logical Equivalences

• Logical equivalences can be used to construct additional logical equivalences • Example: Show that (p  q) q is a tautology 0. (p  q) q 1. (p  q)  q Implication Law on 0 2.  (p q)  q De Morgan’s Law (1st) on 1 3. p  (q  q) Associative Law on 2 4. p  1 Negation Law on 3 5.  1 Domination Law on 4

55

Using Logical Equivalences: Example

• Show that (q  p)  (p  q)  q 0. (q  p)  (p  q) 1. (q  p)  (p  q) Implication Law 2.  ( q p)  (p  q) De Morgan’s Law 3.  (q p)  (p  q) Double negation 4.  (q p)  (q  p) Commutative Law 5.  q  (p  p) Distributive Law 6.  q  1 Law 7.  q Identity Law

56

28 9/9/2020

Using Logical Equivalences: Example

• Show that (p  q)  (p q) • Sometimes it helps to start with the second proposition (p q) 0. (p q) 1.  (p q)  (q  p) Equivalence Law on 0 2.  (p q)  (q  p) Implication Law on 1 3. (((p q)  (q  p))) Double negation on 2 4. ((p q) (q  p)) De Morgan’s Law… 5. ((p  q)  (q p)) De Morgan’s Law 6. ((p q)  (p p)  (q q)  (q p)) Distribution Law 7. ((p q)  (q p)) Identity Law 8. ((q  p )  (p  q)) Implication Law 9. (p  q) Equivalence Law

57

Logic Puzzle (Knights and Knaves)

• A very special island is inhabited only by knights and knaves. Knights always tell the truth, and knaves always lie. • You meet two inhabitants: Zoey and Mel. Zoey tells you that Mel is a knave. Mel says, “Neither Zoey nor I are knaves.” • Can you determine who is a knight and who is a knave?

58

29 9/9/2020

Logic Puzzle (Knights and Knaves)

• Define p: Zoey is knight (not knave) • Define q: Mel is knight (not knave) Truth Table • says(knight, X)  X // axioms p q (1) (2) • says(knave, X) X // axioms • (1) says(Zoey,  q) 0 0 0 1 0 1 1 0 // Zoey tells you that Mel is a knave. • (2) says(Mel, p  q) 1 0 1 1 1 1 0 1 // Mel says, “Neither Zoey nor I are knaves.”

The truth table tells that when p = 1 (Zoey is knight) and q = 0 (Mel is knave), both (1) and (2) are true. So it’s the solution.

59

Logic Puzzle (Knights and Knaves)

• A very special island is inhabited only by knights and knaves. Knights always tell the truth, and knaves always lie. • You meet two inhabitants: Zoey and Mel. Zoey tells you that Mel is a knave. Mel says, “Neither Zoey nor I are knaves.” • Can you determine who is a knight and who is a knave?

60

30