Upload
sara-quinn
View
225
Download
0
Embed Size (px)
Citation preview
Predicates & Quantifiers
Goal: • Introduce predicate logic, including existential &
universal quantification• Introduce translation between English sentences &
logical expressions.
Copyright © Peter Cappello
The Limits of Propositional LogicConsider the argument
– All computer science courses are easy.– CS 2 is a computer science course.– Therefore, CS 2 is easy.
Translating into propositions, gives the form:– p– q– Therefore, r.
But, (p q) r is not a tautology:
The argument is not valid in propositional logic.
Copyright © Peter Cappello
Declaration = subject + predicate
A declarative sentence has a subject & a predicate.
– A subject is a thing (e.g., object, entity, concept).
– A predicate asserts that its subject has some property.
Copyright © Peter Cappello
Examples
• Joe’s serves prime rib. [ P( Joe’s ) ]
• 7 is a prime number. [Q( 7 ) ]
• Jill is a prime candidate. [R( Jill ) ]
• Variable values are in a set called the domain.
• Each proposition above has a different domain
(i.e., restaurants, integers, candidates, respectively).
Copyright © Peter Cappello
Using variables
• Consider the argument:
If ( x is a CS course ) ( x is easy )
AND
CS 2 is a CS course.
then CS 2 is easy.
• “x is a CS course” is not a proposition because x is a variable.
Copyright © Peter Cappello
Propositional Function
• Denote “x is a CS class” by P( x ).
P( Math 3A ) is a proposition.
• Denote “x2 + y2 = z2” by P( x, y, z ).
P( -1, 1, 17 ) is a proposition.
Copyright © Peter Cappello
Preconditions & Postconditions
The Java assert statement incorporates an
executable propositional function.
assert x != null;
Copyright © Peter Cappello
Preconditions & Postconditions
Integer abs( Integer x ) {
assert x != null;if ( x < 0 )
x = new Integer( -x );assert x >= 0;return x;
}
Copyright © Peter Cappello
Quantifiers
• A propositional function also is converted to a
proposition via quantification.
• Let C denote the set of all UCSB courses.
• Let C be the domain of discourse or domain.
• Let P( x ) denote “x is a CS class”.
Copyright © Peter Cappello
Universal Quantification
Universal quantification of P( x ) is
– “For all x in the domain, P( x )”
– “For all x in C, P( x )”
– “For all x, P( x )”
– “x P( x )”
This is a proposition.
If C denotes the set of all UCSB courses, is x P( x ) true?
x P( x ): Logical Equivalence
If S, a set with n elements, ei, 1 ≤ i ≤ n,
is the domain of propositional
function P( x ),
Then
x P( x ) ≡ P( e1 ) ∧ P( e2 ) ∧ … ∧ P( en )
What if S is infinite?Copyright © Peter Cappello
Copyright © Peter Cappello
Computational Interpretation
// Pseudo-Java notation
boolean forAllxPx( Set domain )
{
for ( Object element : domain )
{
if ( ! P( element ) )
return false;
}
return true;
}
Copyright © Peter Cappello
Existential Quantification
Existential quantification of P( x ) is
– “There exists an x in the domain, P( x )”
– “There exists an x in C, P( x )”
– “There exists an x, P( x )”
– “x P( x )”
This is a proposition.
Is x P( x ) true?
x P( x ): Logical Equivalence
If S, a set with n elements, ei, 1 ≤ i ≤ n,
is the domain of propositional
function P( x ),
Then
x P( x ) ≡ P( e1 ) ∨ P( e2 ) ∨ … ∨ P( en )
What if S is infinite?Copyright © Peter Cappello
Copyright © Peter Cappello
Computational Interpretation
// Pseudo-Java notation
boolean thereExistsxPx( Set domain )
{
for ( Object element : domain )
{
if (P( element ) )
return true;
}
return false;
}
Copyright © Peter Cappello
Precedence of Quantifiers
and have higher precedence than logical operators.
x P( x ) P( x ) means ( x P( x ) ) P( x )
Is ( x P( x ) ) P( x ) a proposition?
x in “ P( x )” is called an unbound or free variable
Copyright © Peter Cappello
Logical Equivalence
• Let S & T be statements with predicates & quantifiers.
For example
• S denotes “x ( P( x ) Q (x ) )
• T denotes “x P( x ) x Q( x )
• S is logically equivalent to T, denoted S ≡ T, when they have the same truth value regardless of which
– Predicates are substituted into the statements
– Domain of discourse is used for the variables.
Is x ( P( x ) P( x ) ) ≡ x P( x ) x P( x ) ?
Copyright © Peter Cappello
Logically Equivalent Forms
Below, “one” means “at least one”
• “all true” x P( x ) ≡ ~x ~P( x ) “none false”
• “all false” x ~P( x ) ≡ ~x P( x ) “none true”
• “not all true” ~x P( x ) ≡ x ~P( x ) “one false”
• “not all false” ~x ~P( x ) ≡ x P( x ) “one true”
Copyright © Peter Cappello
Translate English to a Logical Expression
“A student is eligible to receive an MS degree, if the student has:
– at least 60 units, or at least 45 units and written a master’s thesis
– received a grade no lower than B in all required courses.”
Where
– M( s ) denotes “student s is eligible to receive an MS degree.”
– U( s, u ) denotes “student s has at least u units.”
– T( s ) denotes “student s has written a master’s thesis.”
– G( s ) denotes “student s received at least a B in all required courses.
Copyright © Peter Cappello
One Translation
– M( s ): “s eligible to receive an MS degree.”
– U( s, u ): “s has taken at least u units.”
– T( s ): “s has written a master’s thesis.”
– G( s ): “s received at least a B in all required courses.
s ( ( ( U( s, 60 ) ( U( s, 45 ) T( s ) ) ) G(s) ) M( s ) )
Is this what you think the department wanted?
Copyright © Peter Cappello
Translate English to a Logical Expression
“There is a student who has taken more than 21 units in a
quarter and received all As.”
Where
• P( s, q ) denotes “s took > 21 units in quarter q.”
• Q( s, q ) denotes “s got all As in quarter q.”
(Is Q defined correctly?)
Copyright © Peter Cappello
One Translation
s q ( P( s, q ) Q( s, q ) ), where
• P( s, q ): “s took > 21 units in quarter q.”
• Q( s, q ): “Student s got all As in quarter q.”
This is an example of nested quantifiers, our next topic.