Predicate Logic One step stronger than propositional logic

  • Slides: 41
Download presentation
Predicate Logic One step stronger than propositional logic Creative Commons License – Curt Hill

Predicate Logic One step stronger than propositional logic Creative Commons License – Curt Hill

Introduction • What we have seen so far is called propositional logic • It

Introduction • What we have seen so far 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 Creative Commons License – Curt Hill

Statement Categories • In mathematics, there are three types of statements: – True –

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 Creative Commons License – Curt Hill

True Statements • 5=2+3 • 5>2 • The United States won its independence from

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 q Creative Commons License – Curt Hill

False statement • False statements have a similar form but are false • 5=4

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 Creative Commons License – Curt Hill

Open statements • Open standards generally cannot have a true or false value until

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 • 5 x = 10 is neither true nor false • It is true if x = 2 and false otherwise Creative Commons License – Curt Hill

Discussion • Logic is two valued, we cannot allow true, false, and maybe •

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 – A predicate is a Boolean function Creative Commons License – Curt Hill

Predicates • Up to this point we have mostly dealt with variables and operators

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 Creative Commons License – Curt Hill

An Example • Let P(x) be the statement x>8 • P(x) is still open

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 Creative Commons License – Curt Hill

Naming • Mathematicians seldom need to consider large real-world problems • Thus, they tend

Naming • Mathematicians seldom need 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 Creative Commons License – Curt Hill

Mathematicians v. Computer Scientists • prime(n) – The argument n is prime or not

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 Creative Commons License – Curt Hill

Predicate Notation • As always there are multiple ways to represent the same thing

Predicate Notation • As always there are multiple ways to represent the same thing • I prefer: predicate(parameter 1, parameter 2) – This matches programming notation • Others use single letter predicates with subscript indicating parameter: Gx • Thus P(x, y) or Px, y Creative Commons License – Curt Hill

Usage • One of the uses of predicates is in program and statement specifications

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 Creative Commons License – Curt Hill

Example • Consider the statements: if(x>0) x = x+1; • Since we know nothing

Example • Consider the statements: if(x>0) x = x+1; • Since we know nothing about the context the precondition must be simply T as in True • However, the postcondition would be: (x 1) Creative Commons License – Curt Hill

Example Again • Recall these statements: if(x>0) x = x+1; • Suppose that P(x)

Example Again • Recall these statements: if(x>0) x = x+1; • 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 Creative Commons License – Curt Hill

Open Statements • In a real sense we have skirted the Open statement problem

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 Creative Commons License – Curt Hill

Quantifiers via familiar example • You are probably familiar with summation notation – It

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 Creative Commons License – Curt Hill

Summation and Product Creative Commons License – Curt Hill

Summation and Product Creative Commons License – Curt Hill

Logical Quantifiers • Just at the denotes repeated addition and the repeated multiplication, so

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 Creative Commons License – Curt Hill

Universal Quantifier • Notation: – x. P(x) – Read: for all x, P(x) •

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 Creative Commons License – Curt Hill

More • The term, P(x) may also be more complicated than a single predicate

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 of sets, not always stated • We may also specify them explicitly Creative Commons License – Curt Hill

Explicit domains • We are able to specify them as part of the quantification:

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 Creative Commons License – Curt Hill

Existential Quantifier • • Notation: x. P(x) Read: there exists an x, P(x) This

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 Creative Commons License – Curt Hill

Number? • The existential quantifier is true if one or more x’s make the

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) Creative Commons License – Curt Hill

Notation • This is not the only notation, another is: (OP i: r: t)

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 Creative Commons License – Curt Hill

Open Questions Again • We now have a way to reduce an open question

Open Questions Again • We now have a way to reduce an open question into a true false proposition • The open question: 3 x + 5 = 5 x - 11 • Becomes x 3 x + 5 = 5 x – 11 • This statement may be true only if a solution exists or false otherwise – No longer open Creative Commons License – Curt Hill

More on quantifiers • Quantifiers allow us to state things that are not directly

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 Creative Commons License – Curt Hill

Precedence • The quantifiers have higher precedence than any of the logical operators •

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)) Creative Commons License – Curt Hill

Variables • There are two types of variables in a quantified expression: bound and

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 Creative Commons License – Curt Hill

Variable Example • Consider: x(P(x+y) Q(x+y)) • The variable x is a bound variable

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 Creative Commons License – Curt Hill

Variable Scope • The scope of a variable is that part of the expression

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 Creative Commons License – Curt Hill

Equivalences • Since quantifiers have the same characteristics as propositions, we may consider equivalences

Equivalences • Since quantifiers have the same characteristics as propositions, we may consider equivalences with them as well • Some of these will considered Creative Commons License – Curt Hill

Distribution • x(P(x) Q(x)) x. P(x) x. Q(x)) – This is distributing a universal

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)) Creative Commons License – Curt Hill

Negation • De. Morgan’s generalizes to quantifiers • i. T i T – T

Negation • De. Morgan’s generalizes to quantifiers • 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 Creative Commons License – Curt Hill

Audience Participation • For each of the following: – Is it true? – What

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 xx 0 = 0 xx+1>x x 1/x Creative Commons License – Curt Hill

English to Logic • Translating English statements to Logic statements is important but sometimes

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 Creative Commons License – Curt Hill

Translation • All students in CS 161 have had CS 160 – x. C

Translation • All students in CS 161 have had CS 160 – x. C 160(x) – Where x is students in 161 and C 160 is a predicate – You might also use: x(C 161(x) C 160(x)) Creative Commons License – Curt Hill

Some quantifier examples • • Some apples are rotten a Apples rotten(a) All women

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 Creative Commons License – Curt Hill

Prime Definition • Can we define a prime number? • prime(n) = i i

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 Creative Commons License – Curt Hill

Summary • What was open before (that is not possible to assign to truth

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 Creative Commons License – Curt Hill

Exercises • Rosen 1. 4 • Problems: 5, 9, 15, 21, 25, 33, 39

Exercises • Rosen 1. 4 • Problems: 5, 9, 15, 21, 25, 33, 39 Creative Commons License – Curt Hill