Outline
- Search and Proofs
- In-Class Exercise
- Conjunctive Normal Form
- Resolution
Introduction
- We were talking about Logical Agents.
- We were focusing initially on propositional logic as a framework for representing our knowledge base as this
is about the simplest logic in town.
- We were talking about algorithms by which a logical agent could infer things about its environments (which in turn would hopefully inform the choice of its actions).
- We looked at examples of how we could see if `KB models alpha` holds in the Wumpus World setting using
model checking. i.e., we check that in every model in which `KB` holds `alpha` holds as well.
- Checking all models of a collection of propositional logic statements involves checking all truth assignments
to the variables. If one has `n` variables, one gets `2^n` meaning this algorithm is slow.
- So we said we wanted to determine entailment via theorem proving -- applying rules of inference directly to the sentences in our knowledge base to construct a proof of the desired sentence without consulting models.
- To do this we need three notions: logical equivalence, validity, and satisfiability. We write `a equiv b` (a is logically equivalent to b) if `a models b` and `b models a`. A statement is valid if it is true in all models. This is related to entailment by the deduction theorem). A statement is satisfiable if there is some model in which it is true.
- We gave a list of common logical equivalences for propositional logic.
Things like (`neg (A wedge B) equiv (neg A vee neg B)` ).
- We used logical equivalence together with two rules of inferences: Modus Ponens and AND-elimination to show how a Wumpus World logical agent could deduce the contents of an as yet to be seen square.
- To start today, we are going to move on to a second theorem proving system known as resolution.
Search and Proofs
- Each line in the proof we just gave can be checked mechanically (say by a program) to determine it is either from the KB or
follows from preceding lines by one of our rules of inference.
- We found this proof by looking in our textbook, but we could imagine framing proof search as a problem and using one of
our algorithms from earlier in the semester to find proofs:
- Initial State: the initial knowledge base
- Actions: The set of actions consist of all inference rules applied to all the sentences that match the top half of an inference rule
- Result: The result of an action is to add the bottom half of the inference rule to our KB
- Goal: The goal is a KB that contains the statement we are trying to prove
- This gives an alternative to model-checking which is often faster as the proof can ignore irrelevant propositions no matter how many there are.
- Notice this algorithm and propositional logic illustrate a property of knowledge bases known as monotonicity: that the set of entailed sentences can only increase as information is added to the database.
- There are actually logics known as nonmonotonic logics (extensively studied in AI as connected with human reasoning) for which this property fails.
Proof by Resolution
- So far we have looked at making inference algorithms which are sound; we have not considered the completeness of our algorithms.
- We next consider a proof system that has a single inference rule, resolution, which is known to be sound and complete.
- In its simplest form, the rule says that if we know `(A vv B)` and we know `neg B` then we can conclude `A`.
- We can generalize this to:
`frac( L_1 vv ... vv L_m, quad neg L_m vv L_1' vv ...vv L_n')(L_1 vv ... vv L_(m-1) vv L_1' vv ... vv L_n')`
In the above, `L_i` and `L_j'` are literals: either variables or their negation.
- For a variable `X`, we often write `bar(X)` for `neg X`.
- That the top of the inference logically implies the bottom can be checked using model checking so the rule above is sound.
- The bottom line of this inference is called the resolvent.
- If we don't have any `L_j'`'s then it is called unit resolution. That is, the right hand clause consists of just `bar(L_m)`. (There are algorithms that work better for this case).
- You often see clauses written as `{L_1, ..., L_m}` rather than use `vv`.
- Set notation is used because `{L, L}` is logically equivalent to `{L}`.
- A resolution refutation of a set of clauses `Gamma` is a sequence of clauses `R_1, ..., R_m` where `R_m = {}` such that for `1 leq i leq m`, `R_i in Gamma` or for some `j,k < i`, `R_i` follows from `R_j` and `R_k` by resolution.
Resolution Example - the Pigeonhole Principle
- The m-into-n pigeonhole principle (`PHP_n^m`) states you can't map `m>n` many pigeons into `n` holes without multiple pigeons ending in some hole together.
- Let's see how we could express `\neg PHP_n^m` as clauses and give a refutation of the statement `\neg PHP_1^2`.
- First, we use the variables `p_{ij}` to denote the `i`th pigeon ends up in the `j`th hole.
- We express that each pigeons ends up in some hole by have for `1 \leq i leq m` a clause of the form `{p_{i1}, ..., p_{i\n}}`.
- To express that pigeon `i` and pigeon `j` don't end up in hole `k` together, we have for all `1 \leq i \ne j leq m` and for all `1 \leq k leq n`,
we have the clause `{bar{p_{ik}}, \bar{p_{jk}}}`.
- I am being lazy and not adding clauses that say a single pigeon can't be in more than one hole. Some people call this variant of the pigeonhole principle, the multifunction pigeonhole principle.
- If we use the above bullets to define `\neg PHP_n^m`, then `\neg PHP_1^2` is the set of clauses `{{p_{11}}, {p_{21}}, {bar{p}_{11},bar{p}_{21}}}`.
- A resolution refutation for `\neg PHP_1^2` is:
- R1: `{p_{11}}`
- R2: `{p_{21}}`
- R3: `{bar{p}_{11},bar{p}_{21}}`
- R4: `{bar{p}_{21}}` resolved from R1 and R3
- R5: `{}` resolved from R2 and R4
In-class Exercise
- Write down the clauses for `\neg PHP_2^3`.
- What would be the set of clauses if `p_{11}` was True? Give a refutation for these clauses.
- What would be the set of clauses if `p_{11}` was False? Give a refutation for these clauses.
- Figure out how to combine and modify these two proofs to give a refutation of `\neg PHP_2^3`.
- Post your solution to the Oct. 18 In-Class Exercise Thread.
Conjunctive Normal Form
- Notice resolution works on an AND of OR's of literals.
- Any propositional formula can be rewritten into one which is equivalent to an AND of ORs of literals. This equivalent form is called Conjunctive Normal Form
- To see this just write down the truth table for the formula, and consider the rows for which the formula is false. That one of these rows doesn't happen can be written as an OR of literals. That none of these rows happens, is just an AND of these ORs.
- Another way to see this is via formula rewriting: One uses implication and biconditional elimination, followed by DeMorgan laws
Example of Converting to CNF
- Consider the statement `(A wedge B) \vee (bar(A) wedge bar(B))\vee (A wedge neg B)`. If we view True as `1` and False as `0`. This expresses `A ge B`.
- We could express `A = max(A, B, C)` as `A ge B wedge A ge C`.
- This is an AND of ORs of ANDs as written, so not CNF.
- Its truth table looks:
A | B | C | A = max(A, B, C) |
True | True | True | True |
True | True | False | True |
True | False | True | True |
True | False | False | True |
False | True | True | False |
False | True | False | False |
False | False | True | False |
False | False | False | True |
- To make a CNF, we look at the three false rows. If the variable `X` for a column has a True in it we take that variable, if it has a false we take take `bar(X)`. So the row False, True, False, becomes `A vee bar(B) vee C`.
- This formula asserts that row didn't happen.
- So the CNF for the whole formula is:
`(A vee bar(B) vee bar(C)) wedge (A vee bar(B) vee C) wedge (A vee B vee bar(C))`
- As a collection of clauses we would write:
`{A, bar(B), bar(C)}, {A, bar(B), C}, {A, B, bar(C)}.`
An Algorithm For Resolution
- Inference procedures based on resolution work by trying to produce a refutation
- We take `KB ^^ neg alpha` (that is, the negation of `KB => alpha`) and convert it to a CNF formula.
- We then cycle over pairs of clauses and for each pair that contains a resolvable literal we resolve the clauses.
- We keep repeating until no new clauses can be derived.
- If we ever resolve and get the empty clause (equivalent to false), then we know `KB` entails `alpha`.
Example
- Consider the statement about natural numbers: `K le M` or `M le K`.
- To use propositional logic and resolution to show such a statement, we might consider `n`-bit variants of the statement, and show each `n`-bit variant is true.
- If we know, `K` and `M` are `n`-bit numbers, we can use propositional variables `K_1, ... K_n` and `M_1, ..., M_n` to represent these numbers. So `K le M` can be expressed as the OR over `j` of statements saying:
`(K_n iff M_n) wedge ... wedge (K_(j+1) iff M_(j+1)) wedge (neg K_(j) wedge M_j)`.
I.e., the high order bits are the same until `j` where `K_j` must be True and `M_j` must be False.
- Let's give a resolution refutation of the 1-bit version of `K le M` or `M le K`.
- This is just the statement: `(K_1 iff M_1) vee (M_1 wedge neg K_1) vee (K_1 iff M_1) vee (K_1 wedge neg M_1) ` which is the same as
`(K_1 iff M_1) vee (M_1 wedge neg K_1) vee (K_1 wedge neg M_1)`
- As a first step, we convert the negation of this formula to CNF using DeMorgan's Laws:
`{K_1, M_1}, {bar(K_1), bar(M_1)}, {bar(K_1), M_1}, {K_1, bar(M_1)}`
- Resolving the first and third clause gives `{M_1, M_1} = {M_1}`. Resolving the second and fourth clause gives `{bar(M_1), bar(M_1)} = {bar(M_1)}`. Then resolving these two gives the empty clause, completing the refutation.
Completeness
- To show resolution is complete we need to show that if a set of clauses is unsatisfiable then the resolution closure contains the empty clause.
- To prove this we actually show the contrapositive: If the resolution closure (RC) does not contain the empty clause then there is a satisfying assignment.
- The following procedure gives us the satisfying assignment:
For i from 1 to k (where i cycles over variable indexes):
- If there is a clause in RC(S) containing the literal `neg P_i` and all its other literals are false under the assignment chosen for `P_1, ... P_(i-1)` then assign false to `P_i`.
- Otherwise, assign true to `P_i`.
Example No Refutation
- Suppose we only had the following two clauses from the example a couple of slides back:
`{bar(K_1), M_1}, {K_1, bar(M_1)}`
- Then the resolution closure of these two clauses is:
`{bar(K_1), M_1}, {K_1, bar(M_1)}, {M_1, bar(M_1)}, {K_1, bar(K_1)}`.
- Letting `P_1 = K_1`, and `P_2 = M_1`. This gives:
`{bar(P_1), P_2}, {P_1, bar(P_2)}, {P_2, bar(P_2)}, {P_1, bar(P_1)}`.
- When `i=1`, in the for loop of the last slide, no assignments have been made so there is no clause in which all the other variables have been assigned False containing `bar(P_1)`. So we set `P_1` to True in our model.
- When `i=2`, again we don't find such a clause, so `P_2` is assigned true.
- Substituting back for `K_1` and `M_1` we get both of these would be assigned true by this algorithm. Notice this assignment does satisfy both clauses in:
`{bar(K_1), M_1}, {K_1, bar(M_1)}`
- Suppose we had started with the three clauses:
`{bar(P_1)},{bar(P_1), P_2}, {P_1, bar(P_2)}`
- In this case, the resolution closure would be:
`{bar(P_1)}, {bar(P_2)}, {bar(P_1), P_2}, {P_1, bar(P_2)}, {P_2, bar(P_2)}, {P_1, bar(P_1)}.`
- In the for loop when `i=1`, the first clause will force `P_1` to be false; when `i=2`, the second clause, will force `P_2` to be false. One can verify the `P_1->`False, `P_2->`False assignment in fact makes all of the clauses we started with true.