2014 University of Kentucky. University of Kentucky

CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 9/26/2014 University of Kentucky 1 ...
Author: Liliana Powell
7 downloads 0 Views 823KB Size
CS375: Logic and Theory of Computing Fuhua (Frank) Cheng Department of Computer Science University of Kentucky 9/26/2014

University of Kentucky

1

Table of Contents:  Week 1: Preliminaries (set algebra, relations, functions) (read Chapters 1-4)

 Weeks 2&3: Propositional Logic (Chapter 6)  Weeks 4&5: Predicate Logic (Chapter 7)  Weeks 6&7: Computing with Logic (Chapter 9)  Week 8: Algebraic Structures (Chapter 10)  Weeks 9&10: Regular Languages, Finite

Antomata (Chapter 11) 9/26/2014

University of Kentucky

2

Table of Contents (conti):  Weeks 11&12: Context-Free Languages,

Pushdown Automata (Chapters 12)  Weeks 13&14: Turing Machines (Chapter 13)

9/26/2014

University of Kentucky

3

3. Predicate Logic

quantifiers

, , ...

Goal: use the notions and notations of first-order predicate calculus to analyze and symbolize a wider variety of statements and arguments that can be done with propositional logic. cannot have other predicates or functions as arguments 9/26/2014

University of Kentucky

4

3. Predicate Logic – First-order Predicate Calculus Predicate calculus studies internal structure of sentences where subjects are applied to predicates existentially or universally. A predicate describes a property of the subject (s) of a sentence. If p is a predicate that describes a property of x, then we write p(x). Example. x is prime: p(x) Example. x is a parent of y: q(x, y) 9/26/2014

University of Kentucky

5

Indicates disjunction

3. Predicate Logic – First-order Predicate Calculus Existential Quantifier “there exists an x such that p(x)” : ∃x p(x) Example. What does p(1) ∨ p(2) ∨ p(3) mean? ∃x p(x), where x ∈ {1, 2, 3} Quiz. p(y, a) ∨ p(y, b) ∨ p(y, c) = ? Answer: ∃x p(y, x), where x ∈ {a, b, c}. Indicates conjunction

Universal Quantifier “for every x, p(x)” : ∀x p(x) Example. What does p(1) ∧ p(2) ∧ p(3) mean? ∀x p(x), where x ∈ {1, 2, 3} 9/26/2014

University of Kentucky

6

3. Predicate Logic – First-order Predicate Calculus Quiz. p(a, x) ∧ p(b, x) ∧ p(c, x) = ? Answer: ∀y p(y, x), where y ∈ {a, b, c} Quiz. If x, y ∈ {0, 1}, then ∃x ∀y p(x, y, z) = ? Answer 1: ∀y p(0, y, z) ∨ ∀y p(1, y, z) = (p(0, 0, z) ∧ p(0, 1, z)) ∨ (p(1, 0, z) ∧ p(1, 1, z)) Answer 2: ∃x (p(x, 0, z) ∧ p(x, 1, z)) = (p(0, 0, z) ∧ p(0, 1, z)) ∨ (p(1, 0, z) ∧ p(1, 1, z)) 9/26/2014

University of Kentucky

7

non-logical things

3. Predicate Logic – First-order Predicate Calculus Syntax of wffs in first-order predicate calculus Terms: constants a, b, c, …, variables x, y, z, …. and function symbols applied to constants, variables or even other functions ƒ(a), g(x, ƒ(y)), h(c, z), … . Atoms: predicate symbols applied to terms p(x), q(a, ƒ(x)), ... . Wffs: either atoms or if U and V are wffs then the following expressions are also wffs: ¬ U, U ∧ V, U ∨ V, U → V, ∃x U, ∀x U, and (U). 9/26/2014

University of Kentucky

8

3. Predicate Logic – First-order Predicate Calculus Inductive definition of a wff: 1. any atom is a wff 2. if U and V are wffs and x is a variable, then the following expressions are also wffs: ¬ U, U ∧ V, U ∨ V, U → V, ∃x U, ∀x U, and (U). Hierarchy in the absence of parentheses:  ¬, ∃x, ∀x (highest, group rightmost operator with smallest wff to its right) ∧ ∨  → (lowest, and it is left associative) 9/26/2014

University of Kentucky

9

3. Predicate Logic – First-order Predicate Calculus Example. Right most

Right most

∀x ¬ ∃y p(x, y) → ∀x q(x) = ? = ∀x ¬ (∃y p(x, y)) → (∀x q(x)) =∀x (¬ (∃y p(x, y))) → (∀x q(x))

= (∀x (¬ (∃y p(x, y)))) → (∀x q(x))

9/26/2014

University of Kentucky

10

3. Predicate Logic – First-order Predicate Calculus Scope, Bound, and Free Scope of ∃x in ∃x W is W. Scope of ∀x in ∀x W is W. An occurrence of x is bound if it occurs in either ∃x or ∀x or in their scope. Otherwise the occurrence of x is free. Example.

9/26/2014

University of Kentucky

11

Bound occurrences of variables are not assigned values. Why?

3. Predicate Logic – First-order Predicate Calculus

Interpretation for a first-order wff consists of a domain D (nonempty set) and an assignment of the symbols of the wff as follows: 1. Predicate letters are assigned to relations over D. 2. Function letters are assigned to functions over D. 3. Constants are assigned to elements of D. 4. Free occurrences of variables are assigned to elements of D. Example. W = p(x). An interpretation can be defined by letting D = N, p(x) means x is odd, and x = 4. 9/26/2014

University of Kentucky

12

Also write W(d)=W(x/d)

3. Predicate Logic – First-order Predicate Calculus Notation: x is free in W, d ∈ D, then W(x/d): wff obtained by replacing all free occurrences of x by d. After the substitution, we get a proposition

Example. Let W = ∀y (p(x, y) → q(x)).

Then W(x/d) =?

∀y (p(d, y) → q(d)) 9/26/2014

University of Kentucky

13

3. Predicate Logic – First-order Predicate Calculus Truth Value of a Wff The truth value of a wff w.r.t. an interpretation with domain D is obtained by recursively applying the following rules:  1. An atom (e.g., p(x), q(a, f(x))) has the truth value of the proposition obtained from its interpretation.  2. Truth values for ¬ U, U ∧ V, U ∨ V, U → V are obtained by applying truth tables for ¬, ∧, ∨, → to the truth values for U and V.  3. ∀x W is true iff W(x/d) is true for all d ∈ D.  4. ∃x W is true iff W(x/d) is true for some d ∈ D. 9/26/2014

University of Kentucky

14

3. Predicate Logic – First-order Predicate Calculus If a wff is true with respect to an interpretation I, we say the wff is true for I. Example. (same domain, different assignments) Let W = p(x). We can define an interpretation I by letting D = N, p(x) means x is odd, and x = 4. W is false for I If we let J be the same as I except that we assign x = 3, then W is true for J 9/26/2014

University of Kentucky

15

called a model in this case

3. Predicate Logic – First-order Predicate Calculus Example. W = ∀x (p(x) → q(x, y)). Two interpretations: 1. I : D = {0, 1}, p(0) = True, p(1) = False, q(0, 1) = True, otherwise q(x, y) is false, and y = 1. Then W is true for I because ∀x (p(x) → q(x, 1)) = (p(0) → q(0, 1)) ∧ (p(1) → q(1, 1)) = (True → True) ∧ (False → False) ≡ True ∧ True ≡ True. 2. J : any domain D, p is true, q is false, and y any value of D, then W is false for J because ∀x (p(x) → q(x, 1)) = (True → False) ∧ … ≡ False ∧ … ≡ False. University of Kentucky 16 9/26/2014

3. Predicate Logic – First-order Predicate Calculus Example. W = ∃x (p(x) ∧ q(x)). Two interpretations : 1. I : D = N, p(x) : x is prime, q(x) : x is odd. Then W is true for I because, for example, p(3) ∧ q(3) = True ∧ True ≡ True. counter model

2. I : D = N, p(x) : x is even, q(x) : x is odd. Then W is false for I because, for example, p(3) ∧ q(3) = False ∧ True ≡ False. 9/26/2014

University of Kentucky

17

3. Predicate Logic – First-order Predicate Calculus Example. W = ∀x (g(x, c) → ∃y (p(y) ∧ d(y, x))). Here are two interpretations of W: 1. I : D = {a}, p(a) = False, d(a, a) = True, g(a, a) = True, and c = a. Then W is false for I because W = g(a, a) → p(a) ∧ d(a, a) ≡ True → False ∧ True ≡ False. 2. I : D = N, g(x, c) means x > c, p(y) means y is prime, d(y, x) means y divides x, and c = 1. This gives the sentence, “every natural number greater than 1 has a prime divisor,” which is known to be true. (I is a model) 9/26/2014

University of Kentucky

18

3. Predicate Logic – First-order Predicate Calculus Models and Countermodels An interpretation that makes a wff true is called a model. Otherwise, called a countermodel. Example. Let W be the following wff. ∀x (r(x, a) ∧ ¬ p(x) → ∃y (r(x, y) ∧ r(y, a) ∧ d(y, x))). Let I be the interpretation defined by D = N, r(x, y) means x > y, p(x) means x is prime, d(y, x) means y divides x, and a = 1. Is I a model or a countermodel for W? Answer: We get the statement, “every natural number x > 1 that is not a prime has a divisor y between 1 and x,” which is known to be true. So I is aUniversity model of W. of Kentucky 19 9/26/2014

3. Predicate Logic – First-order Predicate Calculus Validity A wff is valid if every interpretation is a model. Otherwise the wff is invalid. A wff is unsatisfiable if every interpretation is a countermodel. Otherwise the wff is satisfiable. Quiz. Every wff has exactly two of these four properties. What are the possible pairs of properties that a wff can have? Answer: Satisfiable valid Unsatisfiable 9/26/2014

invalid University of Kentucky

20

We cannot check every interpretation (there are too many)

3. Predicate Logic – First-order Predicate Calculus Proofs of Validity or Unsatisfiability

Example. Prove the following wff is valid. ∃x (A(x) ∧ B(x)) → ∃x A(x) ∧ ∃x B(x). Proof: Let I be an interpretation with domain D for the wff and assume that the antecedent is true for I. Then A(d) ∧ B(d) is true for I for some d ∈ D. So both A(d) and B(d) are true for I. Therefore both ∃x A(x) and ∃x B(x) are true for I. So the consequent is true for I. Thus I is a model for the wff. Since I was an arbitrary interpretation for the wff, every interpretation for the wff is a model. Therefore, the wff is valid. QED. University of Kentucky 21 9/26/2014

3. Predicate Logic – First-order Predicate Calculus Quiz. Is ∃x A(x) ∧ ∃x B(x) → ∃x (A(x) ∧ B(x)) valid? Answer: No. e.g., let D = N, A(x) mean x is even, and B(x) mean x is odd. Some Valid Conditionals Whose Converses Are Invalid  (a) ∀x A(x) → ∃x A(x) .  (b) ∃x (A(x) ∧ B(x)) → ∃x A(x) ∧ ∃x B(x).  (c) ∀x A(x) ∨ ∀x B(x) → ∀x (A(x) ∨ B(x)).  (d) ∀x (A(x) → B(x)) → (∀x A(x) → ∀x B(x)).  (e) ∃x ∀y P(x, y) → ∀y ∃x P(x, y). 9/26/2014

University of Kentucky

22

3. Predicate Logic – First-order Predicate Calculus Quiz. Find a countermodel for each converse of the above wffs. 

(a) ∃x A(x) → ∀x A(x) A(x): x is prime



(b) ∃x A(x) ∧ ∃x B(x) → ∃x (A(x) ∧ B(x)) A(x): x is even; B(x): x is odd



(c) ∀x (A(x) ∨ B(x)) → ∀x A(x) ∨ ∀x B(x) A(x): x is even; B(x): x is odd 9/26/2014

University of Kentucky

23

3. Predicate Logic – First-order Predicate Calculus Quiz. Find a countermodel for each converse of the above wffs. 

(d) (∀x A(x) → ∀x B(x)) → ∀x (A(x) → B(x)) D={a, b}; A(a)=True, A(b)=False; B(a)=False, B(b)=True



(e) ∀y ∃x P(x, y) → ∃x ∀y P(x, y) D=N ; P(x,y): x=y+1

9/26/2014

University of Kentucky

x is the successor of all y 24

3. Predicate Logic – First-order Predicate Calculus Closures (Observation: there are two interesting transformations that we can apply to any wff containing free variables, one is to universally quantify each free variable, and the other one is to existentially quantify each free variable.) When we quantify free variables of a wff, what properties of the original wff would be preserved?

9/26/2014

University of Kentucky

25

3. Predicate Logic – First-order Predicate Calculus Closures (Observation: there are two interesting transformations that we can apply to any wff containing free variables, one is to universally quantify each free variable, and the other one is to existentially quantify each free variable.) When we quantify free variables of a wff, what properties of the original wff would be preserved? satisfiability 9/26/2014

validity

unsatisfiability

University of Kentucky

invalidity

26

3. Predicate Logic – First-order Predicate Calculus Closures (Observation: there are two interesting transformations that we can apply to any wff containing free variables, one is to universally quantify each free variable, and the other one is to existentially quantify each free variable. When we quantify free variables of a wff, what properties of the original wff would be preserved? satisfiability

unsatisfiability 9/26/2014

validity

invalidity University of Kentucky

27

3. Predicate Logic – First-order Predicate Calculus Closures (Observation: there are two interesting transformations that we can apply to any wff containing free variables, one is to universally quantify each free variable, and the other one is to existentially quantify each free variable. When we quantify free variables of a wff, what properties of the original wff would be preserved? - validity is preserved if we universally quantify the free variables, and - unsatisfiability is preserved if we existentially quantify the free variables ) 9/26/2014

University of Kentucky

28

3. Predicate Logic – First-order Predicate Calculus Closures Let W be a wff with free variables x1, …, xn. Then we have the following definitions:  ∀x1 … ∀xn W is the universal closure of W.  ∃x1 … ∃xn W is the existential closure of W. ( Why do we want to define these closures? Note that ∀x1 … ∀xn W has no free variables, hence, can no longer do any new assignment, or the status of W is fixed, you can not set a new goal for W any more. ) 9/26/2014

University of Kentucky

29

3. Predicate Logic – First-order Predicate Calculus Sometimes a wff and one of its closures have the same properties and sometimes they don’t, as we can see in the following examples. Example. The wff p(x) ∨ ¬ p(y) is satisfiable and invalid.  The universal closure ∀x ∀y (p(x) ∨ ¬ p(y)) is satisfiable and 

invalid. The existential closure ∃x ∃y (p(x) ∨ ¬ p(y)) is valid.

Example. The wff p(x) ∧ ¬ p(y) is satisfiable and invalid.  The universal closure ∀x ∀y (p(x) ∧ ¬ p(y)) is unsatisfiable.  The existential closure ∃x ∃y (p(x) ∧ ¬ p(y)) is satisfiable and invalid. 9/26/2014

University of Kentucky

30

3. Predicate Logic – First-order Predicate Calculus Closure Properties  1. A wff is valid if and only if its universal closure is valid.  2. A wff is unsatisfiable if and only if its existential closure is

unsatisfiable . Example. The wff p(x) → ∃y p(y) is valid and its universal closure ∀x (p(x) → ∃y p(y)) is also valid. Example. The wff p(x) ∧ ∀y ¬ p(y) is unsatisfiable and its existential closure ∃x (p(x) ∧ ∀y ¬ p(y) )) is also unsatisfiable. 9/26/2014

University of Kentucky

31

3. Predicate Logic – First-order Predicate Calculus Closure Properties  1. A wff is valid if and only if its universal closure is valid.

Proof. First, prove that if x is a free variable in a wff W, then W is valid iff x W is valid. (->) Let I be an interpretation with domain D for x W . If I is not a model for x W , then there exist d in D such that W(x/d) is false for I. This being the case, we can define an interpretation J for W by letting J be I, with the free variable x assigned the element d in D. Since W is valid, it follows that W(x/d) is true for J. But W(x/d) w.r.t. J is the same as W(x/d) w.r.t. I, which is false. This contradiction shows that I is a model for x W . So x W is valid. 9/26/2014

University of Kentucky

32

3. Predicate Logic – First-order Predicate Calculus Closure Properties  1. A wff is valid if and only if its universal closure is valid.

Proof (conti). (

Suggest Documents