Download presentation
Presentation is loading. Please wait.
Published byRafe McKenzie Modified over 9 years ago
1
Predicate Logic One step stronger than propositional logic Copyright © 2007-2014 Curt Hill
2
Introduction What we have seen is called propositional logic It includes axioms and theorems concerning the operators of Boolean Algebra It lacks something We want to strengthen this into predicate logic –AKA First order logic or predicate calculus Copyright © 2007-2014 Curt Hill
3
Statement Categories In mathematics, there are three types of statements: –True –False –Open True statements are usually characterized by: –Statements with only constants and a comparison such as = or > –A statement of fact –A tautology Copyright © 2007-2014 Curt Hill
4
True Statements 5=2+3 5>2 The United States won its independence from England They may include variables in limited ways: –x+5 = 5+x – p q p q q Copyright © 2007-2014 Curt Hill
5
False statement False statements have a similar form but are false 5=4 2>5 The United States won its independence from Germany They may also include variables: –x (y z) x y x z –x = x + 1 Copyright © 2007-2014 Curt Hill
6
Open statements Open standards generally cannot have a true or false value until a variable is given a value Almost all equations are open, the task of solving is finding a set of values that makes the statement true or determining that the set is empty 5x = 10 is neither true nor false It is true if x = 2 and false otherwise Copyright © 2007-2014 Curt Hill
7
Discussion Logic is two valued, we cannot allow true, false, and maybe Therefore, we have to find a way to make a statement that is open into one that is true or false We now use predicates –AKA Propositional functions Copyright © 2007-2014 Curt Hill
8
Predicates Up to this point we have mostly dealt with variables and operators We may also use predicates Predicate is a fancy name for a function that returns a boolean value It may have one or more arguments The argument does not have to be a boolean variable This is not startling since any boolean variable could hold the result of a predicate Copyright © 2007-2014 Curt Hill
9
An Example Let P(x) be the statement x>8 P(x) is still open We may determine the truth value of: –P(12) –P(2) If the predicate is arbitrary single letter names are sufficient We may have others as well Copyright © 2007-2014 Curt Hill
10
Naming Mathematicians seldom have to consider large real world problems Thus they tend to use single letter predicates to keep the notation easy Computer Science is an area where we want to describe these, so many variables or predicates may exist More descriptive names are then needed This also explains using parenthesis for arguments Copyright © 2007-2014 Curt Hill
11
Mathematicians v. Computer Scientists prime(n) –The argument n is prime or not student(p) –A person p is a student at VCSU or not odd(n) or even(n) Predicate names generally are single word This word should indicate the purpose Copyright © 2007-2014 Curt Hill
12
Predicate Notation As always there are multiple ways to represent the same thing I prefer: predicate(parameter1, parameter2) –This matches programming notation Others use single letter predicates with subscript indicating parameter: G x Thus P(x,y) or P x,y Copyright © 2007-2014 Curt Hill
13
Usage One of the uses of predicates is in program and statement specifications –Correctness proofs as well We express the precondition and postcondition of a statement using this notation –Precondition captures the state before a statement is executed –Postcondition after Copyright © 2007-2014 Curt Hill
14
Example Consider the statements: if(x>0) x = x+1; Since we know nothing about the context the precondition must be simply T However, the postcondition would be: (x 1) Copyright © 2007-2014 Curt Hill
15
Example Again Suppose that P(x) denotes x>0 Moreover x 0 is the value of x before the statement The postcondition becomes: P(x) x=x 0 +1 P(x) x=x 0 Copyright © 2007-2014 Curt Hill
16
Open Statements In a real sense we have skirted the Open statement problem P(x) is just as open as x>0 We next need quantifiers to say something useful about the possible values Copyright © 2007-2014 Curt Hill
17
Quantifiers via familiar example You are probably familiar with summation notation –It gives us a compact way to express an infinite sum or even a large finite sum This gives us a convenient way to denote the sum of a finite or infinite number of terms We also have a similar notation of products Copyright © 2007-2014 Curt Hill
18
Summation and Product Copyright © 2007-2014 Curt Hill
19
Logical Quantifiers Just at the denotes repeated addition and the repeated multiplication, so we have symbols for And and Or is the universal quantifier –Possibly infinite number of terms connected by is the existential quantifier –Number of terms connected by A quantified expression, like a proposition, still has a true or false value Copyright © 2007-2014 Curt Hill
20
Universal Quantifier Notation: – x P(x) –Read: for all x, P(x) The x is a dummy variable –It has an implied domain or range based on its type This is the same as: P(x 0 ) P(x 1 ) P(x 2 ) P(x 3 ) … –Through potentially infinite terms Copyright © 2007-2014 Curt Hill
21
More The term, P(x) may also be more complicated than a single predicate Most of the time the type of the dummy is real numbers –We may just infer the type and range –They may be explicitly stated outside of the quantified expression –Like the universe of discourse, not always stated We may also specify them explicitly Copyright © 2007-2014 Curt Hill
22
Explicit domains We are able to specify them as part of the quantification: x (P(x) x x>0) Sometimes this is abbreviated into the dummy declaration x>0 x P(x) –This is the textbook’s preference –Recall the difference between mathematicians and computer scientists Copyright © 2007-2014 Curt Hill
23
Existential Quantifier Notation: x P(x) Read: there exists an x, P(x) This is the same as: P(x 0 ) P(x 1 ) P(x 2 ) P(x 3 ) … –Through potentially infinite terms The dummy variable and term rules are the same Copyright © 2007-2014 Curt Hill
24
Number? The existential quantifier is true if one or more x’s make the condition true –We are only stating that there is at least one An infrequently used quantifier is that uniqueness quantifier states that there is one and only one: – ! x P(x) Copyright © 2007-2014 Curt Hill
25
Notation This is not the only notation, another is: (OP i:r:t) OP is an operator which is commutative, associative, and binary How many do we have? i is a list of dummies –Often just one but sometimes more r is the range t is the term Copyright © 2007-2014 Curt Hill
26
Open Questions Again We now have a way to reduce an open question into a true false proposition The open question: 3x + 5 = 5x - 11 Becomes x 3x + 5 = 5x – 11 This statement may be true only if a solution exists or false otherwise –No longer open Copyright © 2007-2014 Curt Hill
27
More on quantifiers Quantifiers allow us to state things that are not directly expressible with just predicates, variables and the operators In practice this should allow us to state almost any real world fact or supposition A predicate may be defined in terms of a quantifier Copyright © 2007-2014 Curt Hill
28
Precedence The quantifiers have higher precedence than any of the logical operators Thus: x P(x) Q(x) is ( x P(x)) Q(x) and not x (P(x) Q(x)) Copyright © 2007-2014 Curt Hill
29
Variables There are two types of variables in a quantified expression: bound and free A bound variable is part of the quantifier –It ranges over some set of values as part of quantification –These are often known as dummies A free variable exists outside the quantified expression –These require a value, otherwise the quantifier is still open Copyright © 2007-2014 Curt Hill
30
Variable Example Consider: x (P(x+y) Q(x+y)) The variable x is a bound variable It may only have a certain set of values determined by the quantifier The variable y is free –It may take on any value –The y variable must be given a value outside of the expression for this not to be open Copyright © 2007-2014 Curt Hill
31
Variable Scope The scope of a variable is that part of the expression where it is known In any quantified expression the bound variables have a scope contained by the quantifier This occasionally gets messy when a quantified expression contains another quantified expression Copyright © 2007-2014 Curt Hill
32
Equivalences Since quantifiers have the same characteristics as propositions, we may consider equivalences with them as well Some of these will considered Copyright © 2007-2014 Curt Hill
33
Distribution x (P(x) Q(x)) x P(x) x Q(x)) –This is distributing a universal quantifier over a conjunction Similarly we can distribute an existential quantifier over disjunctions x (P(x) Q(x)) x P(x) x Q(x)) Does existential distribute over conjunctions? x (P(x) Q(x)) x P(x) x Q(x)) Copyright © 2007-2014 Curt Hill
34
Negation DeMorgan’s generalizes to quantifiers i T i T i T i T –T is any term or combination of predicates –Connects and –The outside negation may be moved across implication as well – i T i T – i T i T Copyright © 2007-2014 Curt Hill
35
Audience Participation For each of the following: –Is it true? –What does it mean? –Assume Reals if no type is given x 3<x x 2<x x x 0 = 0 x x+1>x x 1/x x 1/x Copyright © 2007-2014 Curt Hill
36
English to Logic Translating English statements to Logic statements is important but sometimes tricky –The ambiguity of English is a problem Certain words translate in an obvious fashion –Every, all –Not –And –Or –The variety of ways to say the same thing complicates Copyright © 2007-2014 Curt Hill
37
Translation All students in CS 161 have had CS 160 – x C160(x) –Where x is students in 161 and C160 is a predicate –You might also use: x (C161(x) C160(x)) Copyright © 2007-2014 Curt Hill
38
Some quantifier examples Some apples are rotten a Apples rotten(a) All women are beautiful w Females beautiful(w) Some integers are positive All squares are rectangles Not all rectangles are squares Prime numbers exist in the integers Copyright © 2007-2014 Curt Hill
39
Prime Definition Can we define a prime number? prime(n) = i i > 1 i ≠ n 0 ≠ n-floor(n i)*i floor truncates a real number to an integer i is a dummy variable that can range over all integers greater than 1 and not equal to n Notice that for this expression i is bound but n is free Copyright © 2007-2014 Curt Hill
40
Summary What was open before (that is not possible to assign to truth value to) is now closed –We may not always know the truth value –We do know that one exists We should now be able to state in a concise form any proposition Copyright © 2007-2014 Curt Hill
41
Exercises Rosen 1.4 Problems: 5, 9, 15, 21, 25, 33, 39 Copyright © 2007-2014 Curt Hill
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.