Presentation is loading. Please wait.

Presentation is loading. Please wait.

Section 1.4 1 Predicates & Quantifiers. Open Statement 2 x > 8 p < q -5 x = y + 6 Neither true nor false.

Similar presentations


Presentation on theme: "Section 1.4 1 Predicates & Quantifiers. Open Statement 2 x > 8 p < q -5 x = y + 6 Neither true nor false."— Presentation transcript:

1 Section 1.4 1 Predicates & Quantifiers

2 Open Statement 2 x > 8 p < q -5 x = y + 6 Neither true nor false

3 Propositional Functions 3 x > 8 x is greater than 8. x subject is greater than 8. predicate

4 Propositional Functions 4 x subject is greater than 8. predicate P(x) propositional function P at x

5 Terminology We will just call Propositional Functions “Predicates” 5

6 Predicates 6 There are two ways a propositional function P(x) “ x > 8 ” can become true or false (a proposition)

7 P(x) “ x > 8 ” 7 1. The variable may be given a value P(5) FALSE “ 5 > 8 ” “ 12 > 8 ” P(12)TRUE

8 Multi-variable Predicates 8 Let Q(x,y) be the statement “ x is the capital of y. ” What are the truth values of: Q(Carson City, Nevada) Q(Detroit, Michigan) Q(Nebraska, Lincoln)

9 Quantifiers 9 2. A propositional function P(x) “ x > 8 ” can become true or false (a proposition) by using quantifiers.

10

11 Universal Quantification 11 A Universal Quantifier states that P(x) is true for all values of x in the universe of discourse. states the universal quantification of P(x)

12 12 Every student in this class has had CS1400 or its equivalent. Let P(x) denote the statement “ x has had CS1400 or its equivalent. ” represents the statement, where the universe of discourse for x is this class.

13 13 True

14 14 False

15 15 False

16 16 False

17 17 If S(x) represented the statement “ x is in this class ” and P(x) denotes the statement “ x has had CS1400 or its equivalent. ” also represents the statement.

18 Universe of Discourse 18 It is important to note that the universe of discourse must be defined before the logical value of a propositional function may be discussed.

19 Example: 19 Let P(x) be the statement “ x spends more than five hours every weekday in class, ” where the universe of discourse for x is the set of students. Express in English. No student spends more than five hours every weekday in class

20 Existential Quantification 20 States that P(x) is true for some value of x in the universe of discourse. states the existential quantification of P(x)

21 Existential Quantification 21 There is at least one person in this class who has completed CS2420. Let P(x) represent the statement “ x has completed CS2420 ” where the universe of discourse is this class. then represents the above statement.

22 22 True

23 23 True

24 24 True

25 25 False

26 Example: 26 Let P(x) be the statement “ x spends more than five hours every weekday in class, ” where the universe of discourse for x is the set of students. Express in English. There is some student (maybe more than one) who does not spend more than five hours every weekday in class.

27 Thinking about Quantifiers as Conjunctions and Disjunctions If the domain is finite Even if the domains are infinite, you can still think of the quantifiers in this fashion, but the equivalent expressions without quantifiers will be infinitely long.

28 Negating Quantified Expressions Consider  x J(x) “Every student in your class has taken a course in Java.” Here J(x) is “x has taken a course in calculus” and the domain is students in your class. Negating the original statement gives “It is not the case that every student in your class has taken Java.” This implies that “There is a student in your class who has not taken calculus.” Symbolically ¬  x J(x) and  x ¬J(x) are equivalent

29 Negating Quantified Expressions (continued) Now Consider  x J(x) “There is a student in this class who has taken a course in Java.” Where J(x) is “x has taken a course in Java.” Negating the original statement gives “It is not the case that there is a student in this class who has taken Java.” This implies that “Every student in this class has not taken Java” Symbolically ¬  x J(x) and  x ¬J(x) are equivalent

30 De Morgan’s Laws for Quantifiers The rules for negating quantifiers are: The reasoning in the table shows that: These are important. You will use these.

31 Translation from English to Logic Examples: 1.“Some student in this class has visited Mexico.” Solution: Let M(x) denote “x has visited Mexico” and S(x) denote “x is a student in this class,” and U be all people.  x (S(x) ∧ M(x)) 2.“Every student in this class has visited Canada or Mexico.” Solution: Add C(x) denoting “x has visited Canada.”  x (S(x)→ (M(x)∨C(x)))

32 Some Fun with Translating from English into Logical Expressions U = {fleegles, snurds, thingamabobs} F(x): x is a fleegle S(x): x is a snurd T(x): x is a thingamabob Translate “Everything is a fleegle” Solution:  x F(x)

33 Translation (cont) U = {fleegles, snurds, thingamabobs} F(x): x is a fleegle S(x): x is a snurd T(x): x is a thingamabob “Nothing is a snurd.” Solution: ¬  x S(x) What is this equivalent to? Solution:  x ¬ S(x)

34 Translation (cont) U = {fleegles, snurds, thingamabobs} F(x): x is a fleegle S(x): x is a snurd T(x): x is a thingamabob “All fleegles are snurds.” Solution:  x (F(x)→ S(x))

35 Translation (cont) U = {fleegles, snurds, thingamabobs} F(x): x is a fleegle S(x): x is a snurd T(x): x is a thingamabob “Some fleegles are thingamabobs.” Solution:  x (F(x) ∧ T(x))

36 Translation (cont) U = {fleegles, snurds, thingamabobs} F(x): x is a fleegle S(x): x is a snurd T(x): x is a thingamabob “No snurd is a thingamabob.” Solution: ¬  x (S(x) ∧ T(x)) What is this equivalent to? Solution:  x (¬S(x) ∨ ¬T(x))

37 Translation (cont) U = {fleegles, snurds, thingamabobs} F(x): x is a fleegle S(x): x is a snurd T(x): x is a thingamabob “If any fleegle is a snurd then it is also a thingamabob.” Solution:  x ((F(x) ∧ S(x))→ T(x))

38 System Specification Example Predicate logic is used for specifying properties that systems must satisfy. For example, translate into predicate logic: “Every mail message larger than one megabyte will be compressed.” “If a user is active, at least one network link will be available.” Decide on predicates and domains (left implicit here) for the variables: Let L(m, y) be “Mail message m is larger than y megabytes.” Let C(m) denote “Mail message m will be compressed.” Let A(u) represent “User u is active.” Let S(n, x) represent “Network link n is state x. Now we have:

39 Logic Programming (optional) Prolog (from Programming in Logic) is a programming language developed in the 1970 s by researchers in artificial intelligence (AI). Prolog programs include Prolog facts and Prolog rules. As an example of a set of Prolog facts consider the following: instructor(chan, math273). instructor(patel, ee222). instructor(grossman, cs301). enrolled(kevin, math273). enrolled(juana, ee222). enrolled(juana, cs301). enrolled(kiko, math273). enrolled(kiko, cs301). Here the predicates instructor(p,c) and enrolled(s,c) represent that professor p is the instructor of course c and that student s is enrolled in course c.

40 Logic Programming (cont) In Prolog, names beginning with an uppercase letter are variables. If we have a predicate teaches(p,s) representing “professor p teaches student s,” we can write the rule: teaches(P,S) :- instructor(P,C), enrolled(S,C). This Prolog rule can be viewed as equivalent to the following statement in logic (using our conventions for logical statements).  p  c  s(I(p,c) ∧ E(s,c)) → T(p,s))

41 Logic Programming (cont) Prolog programs are loaded into a Prolog interpreter. The interpreter receives queries and returns answers using the Prolog program. For example, using our program, the following query may be given: ?enrolled(kevin,math273). Prolog produces the response: yes Note that the ? is the prompt given by the Prolog interpreter indicating that it is ready to receive a query.

42 Logic Programming (cont) The query: ?enrolled(X,math273). produces the response: X = kevin; X = kiko; no The query: ?teaches(X,juana). produces the response: X = patel; X = grossman; no The Prolog interpreter tries to find an instantiation for X. It does so and returns X = kevin. Then the user types the ; indicating a request for another answer. When Prolog is unable to find another answer it returns no.

43 Logic Programming (cont) The query: ?teaches(chan,X). produces the response: X = kevin; X = kiko; no A number of very good Prolog texts are available. Learn Prolog Now! is one such text with a free online version at http://www.learnprolognow.org/ http://www.learnprolognow.org/ There is much more to Prolog and to the entire field of logic programming.


Download ppt "Section 1.4 1 Predicates & Quantifiers. Open Statement 2 x > 8 p < q -5 x = y + 6 Neither true nor false."

Similar presentations


Ads by Google