350 likes | 1.33k Views
First order predicate calculus. Provides a richer modeling languageWe have objects and propertiesWe have relationships between objects We have quantification
E N D
1. Limitations of Propositional logic We Can’t describe things in terms of their properties or relationships
We can’t express rules or generalizations
If the train is late and there are no taxis, john is late for the meeting
If trains are late and there are no taxis, anyone traveling by trains is late for the meeting…
3. First order Predicate Logic Predicate Logic (also called predicate calculus) is more expressive than propositional logic because it can represent objects, properties of objects, and relationships between objects.
Examples include:
Objects: birds, Elvis, stores, numbers, colors, ...
Properties: blue, small, tall, ugly, ...
Relations: has part, father, lookslike, contains, ...
First-order predicate logic cannot naturally represent categories, time, or events.
4. Syntax… Non-logical symbols
Constants (or names) are usually symbols for real-people or things… e.g., John, Eiffel_Tower, University_of_North Texas.
Note: Logicians often use the convention that constant names begin with Uppercase . (This is the EXACT opposite of the convention in languages such as Prolog.
Numbers (often integers) can also serve as constants
Constants are also called atoms.
5. Predicates Predicate is an assertion that some property or relationship holds for one or more arguments.
For example, to assert that John is a man, we might right man(John) or is-man(John)…To assert that John loves Joan, we would write loves(John, Joan)…
Logicians often use the convention that predicate names begin with an upper-case such as Brother, Married…..(sometimes just P, Q, R…). But Prolog doesn’t (nor will we)…
6. Predicates…more Predicates have a truth value: loves(John, Joan) is T; loves(John,Sally)=F.
When a predicate has more than one argument, the order is significant….but it is up to the designer…
Number of arguments are called “arity” …
ALL of these things are Syntax – Semantics comes from the designer..
7. Variables Represents a currently unknown constant…or for all possible constants. (Ex… dog(X) is true of ALL dogs or One dog…
In logic, these are represented as lower-case. In Prolog (and other lang), represented in Upper case….We will do this.
8. Connectors Complex wffs are built by joining connectors
Connectives (same as logic)
¬ (not), ^ (and), ? (or),
? (conditional) Expression on left called antecedent, expression on right is consequent.
= equivalence
We can use these to represent rules, such as:
“dogs chase cats” can be represented as:
If animal is a dog
Then animal chases cats
OR dog(X) -> chasescats(X)
Or dog (X) ^ cat(Y) -> chases (X,Y)
9. Connectors Note: an implication is true if the antecedent is true and the consequent is true. It is also true if the antecedent is false, regardless of the consequent…
Beagle(X) -> dog (X)
madeof(greenCheese,moon) -> president(us,obama)
madeof(greenCheese,moon) -> president (us,cain)
1st is true because any animal that is a beagle is a dog. The second and third are true because the moon is not made of green cheese.
A->B is equivalent to ¬ A ? B
10. Quantifiers The correct interpretation of a variable is made explicit by
preceding the WFF in which it appears with one of two quantifiers - ? or ?.
(1) The universal quantifier ? (read “for all”) indicates that any value may be substituted for the indicated variable.
(2) The existential quantifier ? (read “there exists” indicates that there is some value (at least one, perhaps more) of the indicated variable for which the WFF is true.
(3) When a variable appears in a WFF, the choice of quantifier affects the meaning of the WFF.
11. Quantifiers For example: (?X) (dog(X) ? barks(X))
This says “all dogs bark”
(The existential quantifier would also yield a meaningful sentence, but probably not what we want:
(?x) (dog(X) ? barks(X))
“There exists at least one creature such that its being a dog implies that it barks”
On the other hand: dog(X)
we clearly want the existential quantifier: (?X) (dog(X))
(If we used the universal quantifier (?X) (dog(X)) we would be saying “everything is a dog” )
12. Quantifiers Normally, in a WFF, all variables are quantified. Such variables are said to be bound.
We speak of the scope of a quantifier as the region in which the variable it names is bound. For example, in
p(a) V (?X) (q(a,X)) V (?X) r(a, X), the scope of the (?X) quantifier is q(a, X), and the variable “X” that appears in r(a, X) is not necessarily the same as the variable “X” that appears in q(a, X)
a WFF can be written in such a way as to eliminate all existential quantifiers; therefore, it is common practice to drop the quantifiers.
Ex: (?X) (?Y) dog(X) ^ cat(Y) ? chases(X, Y)
is often written as simply dog(X) ^ cat(Y) ? chases(X, Y)
13. Functions A predicate calculus function stands for some (currently not known) constant that is related in some way to its argument(s). Ex. in our pets world every pet has an owner. Ex: “The owner of Rocco” could be represented by owner(rocco)
Ex. The statement “the owner of a cat that is chased by a dog will be mad at the owner of the dog” can be represented by:
(?X) (?Y) [(dog(X) ^ cat(Y) ^ chases(X, Y)) ? madAt(owner(Y), owner(X))]
14. Functions By convention, function names are written in lower case letters. And by a single letter near the middle of the alphabet (f, g, h etc.) is used.
Notice that for every function we can invent a related predicate - e.g. for the function owner(X) we have the related predicate owner(X, Y) that asserts that the owner of X is Y (or vice versa if you prefer - just be consistent). The meanings are different, however:
owner(X) is a function yielding an individual
owner(X, Y) is a predicate that is true just when Y owns X
Therefore, the following is certainly true:
(?X) (pet(X) => owner(X, owner(X))
15. Functions However, we would rarely use both the function and the predicate in the same WFF, because this can be quite confusing!
Ex. We could have used the owner predicate instead:
(?W) (?X) (?Y) (?Z) [(dog(W) ^ cat(X) ^ chases(W, X) ^ owner(W, Y) ^ owner(X, Z )) ? madAt(Z, Y)]
* In practice, functions are avoided where possible because predicate calculus has no mechanism for expressing algorithms for computing them
16. Using the First Order Predicate Calculus. "formalization“ describes the process of converting an English statement into an equivalent expression in some formal language like predicate calculus. Any sort of automated reasoning process will require some sort of formalization scheme.
In general, when we formalize an English statement:
We convert verbs to predicates
We convert nouns and adjectives to constants.
Clauses of the form: “Every ____ has ____ property” or “All
members of _____ category ____” generally translate into a WFF with one (or more) universally-quantified variables with an implication in the scope of the quantifier.
17. Formalizing Ex: “Dogs bark” (i.e. “every dog has the barks property” or “all members of the dog category bark”)
?X (dog(X) ? barks(X)
As a general rule, universally quantified variables always contain a top level implication in their scope -
Ex: ?X createdBy(X, god) might seem to be an exception, but this says that God created even Himself, so even this WFF is not really correct!
18. Formalizing When we have a qualified generic noun, we have two basic options: Ex: “The dog who lives with Garfield does not chase cats” (“There is a dog who lives with Garfield and it is not the case that this dog chases cats”)
We can use an existentially-quantified variable
?X (dog(X) ^ livesWith(X, garfield) ^ ¬ chasesCats(X)
19. Formalizing We can create a special sort of name - called a Skolem constant in honor of its inventor - to stand for the otherwise unknown name of “the dog”, since we do not have the dog's name - only the statement that it is the dog who lives with Garfield. We can invent a name like dog1, and formalize as:
dog(dog1) ^ livesWith(dog1, garfield) ^ ¬ chasesCats(dog1)]
20. Some examples Rocco is a dog == dog(rocco)or species(rocco, dog)
Garfield is orange == orange(garfield) or color(garfield, orange)
Rocco chases cats == chasesCats(rocco) or
?X cat(X) ? chases(rocco, X)
Cats eat mice ?X (cat(X) ? eatsMice(X) or
(?X) (?Y) (cat(X) ^ mouse(Y)? eats(X, Y)
21. Examples The cat who lives at address #11 is orange –
(cat1, 11) ^ color(cat1, orange) or (?X)(cat(X) ^ address(X, 11) ^ color(X. orange))
Note: There are a number of wrong ways to formalize this:
(?X) (cat(X) ^ address(X, 11) ? color(X, orange)
This says that any cat who lives at #11 is orange - not that a particular cat that lives there is orange. (This would allow for an arbitrary number of orange cats at #11, and would preclude a nonorange
cat at #11 - though probably the latter is intentional.)
22. More examples (?X) (cat(X) ^ address(X, 11) ^ color(X, orange)
- This says that everything is a cat, lives at #11, and is orange - i.e. all of us are orange cats living at #11!
23. Examples Some more complicated examples arise where we need quantifiers inside the scope of other quantifiers:
Every mailman has been chased by a dog
(?X) [mailman(X) => (?Y) { dog(Y) ^ hasChased(Y,X) }]
Every city has a dogcatcher who has been bitten by every dog in town” (Example from Nilsson’s earlier book)
(?X) [city(X) ? (?Y) { dogCatcher(Y) ^ worksFor(Y, X) ^ (?Z) (dog(Z) ^ livesIn(Z,X) ? hasBitten(Z,Y))}]
24. Inferencing Answering questions of a knowledge base (predicate calculus statements)
for example, that a question like “Who chases Alexander?”can be turned into a predicate calculus theorem (?X) (chases(X, alexander))
We use laws of inferencing
Modus ponens
Modus tolens
25. Resolution Given A V B -- where A,B, C are any WFFs
and ¬A V C
We may infer (B V C)
a) The term B V is called the resolvent.
26. However….to use resolution We need to do some things to resolution because we now have clauses with variables….
We need to say that you can resolve similar predicates if……
They both contain the same constant
cat(Garfield) resolves with cat(Garfield)
If one contains a variable and the other a constant
cat(X) resolves with cat(Garfield)
They both contain variables…
cat(X) resolves with cat(Y) --- that is x=y
27. An Example: An Example:
Given the following axioms
(?X) (dog(X) ^ cat(Y) => chases(X, Y))
dog(rocco)
cat(alexander)
Prove chases(rocco, alexander)
28. Proof… Convert the axioms to clause form. The first is equivalent to the clause
¬ dog(X) V ¬ cat(Y) V chases(X, Y)
(note how negating the antecedent turns the and to or by DeMorgan’s theorem; and how the universal quantifier is dropped because implicit)
The second and third axioms are already clauses - we will refer to these as (2) and (3) in the proof
29. (1) ¬ dog(X) V ¬ cat(Y) V chases(X, Y)
(2) dog(rocco)
(3) cat(alexander)
Add the negation of the theorem to the database:
(4) ¬ chases(rocco, alexander)
Resolve (4) with (1) with unifier { rocco/X, alexander/Y }
(5) ¬ dog(rocco) V ¬ cat(alexander)
Resolve (5) with (2) to get
(6) ¬ cat(alexander)
Resolve (6) with (3) to get
NIL - a contradiction
Since we have been able to “prove” we have proven the theorem
30. Putting things into clausal form… Before we can use resolution refutation as a proof technique, we first have to do some preliminary work on our representation. Resolution refutation requires that all our axioms be expressed in a particular form: they must comprise a set of clauses.
(This is a long process…so bear with me….)
31. Steps Eliminate implications
P ? Q = ¬P ? Q
Move negations down to atomic formulas
¬(P ? Q) = (¬P) ? (¬Q)
¬(P ? Q) = (¬P) ? (¬Q)
¬?x(P(x)) = ?x(¬P(x))
¬?x(P(x)) = ?x(¬P(x))
Rename variables as necessary so that no two variables are the same.
?x P(x) = ?y P(y)
(?xP(x)) ? (?x Q(x)) = (?x P(x)) ? (?y Q(y))
Move quantifiers left
P ? (?xQ(x)) = ?x [P ? Q(x)]
32. Next Eliminate existential quantifiers. (called Skolemization)
a) ?x P(x) replaced by P(A)
where A is a constant.
b) ?y?x P(x,y) replaced by ?xP(x,A)
Move disjunctions down to literals
P ? (Q ? R) = (P ? Q) ? (P ? R)
Eliminate conjunctions
(P(x) ? Q(x)) ? (R(x) ? S(x))
Is decomposed into two clauses
a) P(x) ? Q(x)
b) R(x) ? S(x)
In fact we do not eliminate conjunctions, we only write differently.
33. Eliminate universal quantifiers. We do not actually eliminate but instead we consider that all variables are universally quantified.
?x P(x) becomes P(x)
34. Example:
35. Proving
36. Murder mystery Example d has been murdered
a, b, and c are suspects (i.e., at most one of a, b, and c are guilty)
b claims that he did not know the victim d (i.e, if b did know d, then b is lying)
a and c claim that b did know d (i.e., if b did not know d, then a and c are lying)
anyone who lies is guilty prove that b committed the murder (is guilty)
Prove that b committed murder (is guilty)
37. Predicate calculus
Guilty(a) ? Guilty(b) ? Guilty(c)
¬(Guilty(a) ? Guilty(b))
¬(Guilty(a) ? Guilty(c))
¬(Guilty(b) ? Guilty(c))
Knows(b, d) ? Lies(b)
¬Knows(b, d) ? Lies(a)
¬Knows(b, d) ? Lies(c)
?x (Lies(x) ? Guilty(x))
38. Clausal form convert to clausal form
(1) Guilty(a) ? Guilty(b) ? Guilty(c)
(2) ¬Guilty(a) ? ¬Guilty(b)
(3) ¬Guilty(a) ? ¬Guilty(c)
(4) ¬Guilty(b) ? ¬Guilty(c)
(5) ¬Knows(b, d) ? Lies(b)
(6) Knows(b, d) ? Lies(a)
(7) Knows(b, d) ? Lies(c)
(8) ?x (¬Lies(x) ? Guilty(x))
and add the negation of the formula we want to prove
(9) ¬Guilty(b)
39. Poof through resolution 1 ?x (¬Lies(x) ? Guilty(x)) (8)
2 ¬Guilty(b) (9)
3 ¬Lies(b) 1, 2, by resolution with x/b
4 ¬Knows(b, d) ? Lies(b) (5)
5 ¬Knows(b, d) 3, 4 by resolution
6 Knows(b, d) ? Lies(a) (6)
7 Lies(a) 5, 6 by resolution
8 Knows(b, d) ? Lies(c) (7)
9 Lies(c) 5, 8 by resolution
10 Guilty(a) 1, 7 by resolution with x/a
11 Guilty(c) 1, 9 by resolution with x/c
12 ¬Guilty(a) ? ¬Guilty(c) (3)
13 ¬Guilty(c) 10, 12 by resolution
14 Ø 11, 13 by resolution
40. A Sample KB Suppose we wanted to create a knowledge base for the following facts:
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Roman.
4. Caesar was a ruler.
5. All Romans were either loyal to Caesar or hated him.
6. Everyone is loyal to someone.
7. People only try to assassinate rulers they are not loyal to.
8. Marcus tried to assassinate Caesar.
41. A Sample KB in Predicate Logic 1. Marcus was a man. man(MARCUS)
2. Marcus was a Pompeian. Pompeian(MARCUS)
3. All Pompeians were Roman. ?x Pompeian(x) ? Roman(x)
4. Caesar was a ruler. ruler(CAESAR)
5. All Romans were either loyal to Caesar or hated him.
?x Roman(x) ? (loyal(x,CAESAR) ? hated(x,CAESAR))
6. Everyone is loyal to someone. ?x ?y loyal-to(x,y)
7. People only try to assassinate rulers they are not loyal to.
?x,y person(x) ? ruler(y) ? trytoassassinate(x,y) ? ?loyal-to(x,y)
8. Marcus tried to assassinate Caesar. trytoassassinate(MARCUS,CAESAR)
42. Proving a new fact Let's try to answer the question: Was Marcus loyal to Caesar?
The strategy is to assume it is not true and try to force a contradiction.
1. By the rule:
?x,y person(x) ? ruler(y) ? trytoassassinate(x,y) ? ?loyal-to(x,y)
we can conclude:
? person(MARCUS) ? ? ruler(CAESAR) ?
?trytoassassinate(MARCUS,CAESAR)
2. We know: trytoassassinate(MARCUS,CAESAR)
So we conclude: ? person(MARCUS) ? ? ruler(CAESAR)
3. We know: ruler(CAESAR)
So we conclude: ?person(MARCUS)
43. Hmmm, no contradiction. We need one more fact in the KB:
?x man(x) ? person(x)
and then we can prove loyal-to(MARCUS,CAESAR)!
44. Common Problems Time. Notice that past/present/future tense is not represented anywhere.
Ambiguity. ``Everyone is loyal to someone'' could mean that everyone is loyal to some person, or that everyone is loyal to the same person.
Even for simple tasks, the KB may not contain all the facts that are needed to derive useful statements.
It is very easy to forgot to include statements that represent the most obvious facts!
45. Algorithm for the General Resolution Rule Algorithm: Resolution/Refutation
Negate the theorem to be proved, and add the result to the list of statements.
Put the list of statements into clause form.
Until there is no resolvable pair of clauses,
-- Find resolvable clauses and resolve them.
-- Add the results of resolution to the list of clauses.
-- If nil is produced, stop and report that the theorem is true.
Stop and report that the theorem is not necessarily true.
46. Another example of resolution Question
Is marcus alive in the year 2003?
Marcus was a man
Marcus was a pompeian
Marcus was born in 40AD
All men are mortal
All pompeians died when the volcano erupted
The volcano erupted in 79 AD
No mortal lives longer than 150 years
Alive means not dead
If someone dies, they remain dead
47. Axioms in clause form (assuming subtraction operator, gt predicate)
man(Marcus)
pompean(Marcus)
born(Marcus, 40AD)
? man(x1) ? mortal (x1)
? pompean(x2) ? died(x2,79)
erupted(Volcano,79)
? mortal(x3) ? ? born(x3,t1) ? ? gt(t2-t1,150) ? dead(x3,t2)
? alive(x4,t3) ? ? dead(x4,t3)
dead(x5,t4) ? alive(x5,t4)
? died(x6,t5) ? ? gt(t6,t5) ? dead(x6,t6)
Prove ? alive(Marcus,2003)
Negate clause to be proved and add to list:
Alive (Marcus, 2002)
48. Alive(Marcus, 2003)
8. ? alive(x4,t3) ? ? dead(x4,t3)
R1: ? dead(Marcus,2003)
10. ? died(x6,t5) ? ? gt(t6,t5) ? dead(x6,t6)
R2: ? died(x6,t5) ? ? gt(t6,t5)
5. ? pompean(x2) ? died(x2,79)
R3: ? pompean(x2) ? ? gt(t6,t5)
Substitute
? pompean(Marcus) ? ? gt(2003, 79)
Pompean(Marcus)
2003 is greater than 79
49. Proof as search We magically knew all the right steps. But when viewed as a search problem, proof can be large.
Initial state: The KB
Operators: resolution, or other inference rules
Goal state: statement to be proved (or contradiction)
Branching factor increases as proof progresses
Universal Elimination can have huge branching factor
50. The problem – How to select which pair of clauses to resolve next….
Unit preference strategy – give preference to resolutions involving clauses with the smallest number of literals
Input resolution – try to resolve against statements from the query first
Set-of-support – identify key factors that are relevant to the problem and always resolve them first
Subsumption – Eliminate all sentences that are subsumed (I.e., more specific)
,,,,this is still an issue
51. Also, how to select the unit of representation How to represent “Pen #7 is red”
Red(pen7) It’s easy to ask “What’s red?”
Can’t ask “What is the color of pen7?”
Color(pen7,red).It’s easy to ask “What’s red?”
It’s easy to ask “What is the color of pen7?”
Can’t ask “What property of pen7 has the value red?”
Prop(pen7, color, red). It’s easy to ask all these questions.
52. In-class Problems Represent the following in Pred cal.
All basketballs are made of rubber.
Every flower located in Sue’s yard is red
At least one question on HW4 was hard
All birds can fly except for penguins and ostriches
John’s boss is Mary
53. Consider the following facts The members of the bridge club are joe, sally bill, and ellen
Joe is married to sally.
Bill is ellen’s brother
The spouse of every married person in the club is also in the club
The last meeting of the club was at joe’s house.
Prove: The last meeting of the club was at sally’s house.