420 likes | 1.26k Views
Prime implicants, prime implicates and consequence finding. Material from: A new algorithm for generating prime implicants [J.Slagle et al.]. An improved incremental algorithm for generating prime implicates [J. de Kleer].
E N D
Prime implicants, prime implicates and consequence finding. Material from: • A new algorithm for generating prime implicants [J.Slagle et al.]. • An improved incremental algorithm for generating prime implicates [J. de Kleer]. • A new method for consequence finding and compilation in restricted languages [del Val]. Digested by: Alexandre Klementiev.
Prime Implicants and Implicates • Prime implicantαof a formula φ is a conjunction of literals s.t. α |=φ, but deprived of a literal α |≠φ. • Prime implicateβof a formula φ is a clause s.t. φ |=β and there is no other implicate β’ s.t. β’ |=β. • Property: Prop. formulae are equivalent iff they have the same set of prime implicates/implicants.
Prime Implicants and Implicates: Motivation • Reduce prop. formula φ to its simplest equivalent. • Many applications: digital circuits, logic, etc. • Define simplifying φ as finding the simplest equivalent in some normal form. • Every φ can be represented by disjunction of all of its prime implicants. • However, we may not need all prime implicants.
Prime Implicants and Implicates: Objective • Generate the set of all prime implicates/implicants of φ. • Known to be NP-complete, but we can do much better than brute force. • If φ if redundant - get rid of unnecessary prime implicates/implicants.
Consequence Finding: Motivation and Objective • Given a knowledge base Δ, derive a set of formulas logically implied by Δ. • May wan to derive some subset of the set of all implicates of Δ. • Provide restrictions to guide the search. • Such task is called consequence finding.
Outline of the rest of the talk • Slagle et. al. (1970) • Generating prime implicants and implicates. • Finding minimal sum. • de Kleer (1992) • Generating prime implicates. • del Val (1999) • Consequence finding.
Approach I: Slagle et. al. • Start with φ in CNF. • Think of φ as a set of clauses. Remove clauses containing complimentary literals. Call new set S. • Choose literal ordering OS for S (e.g. based on literal “frequency”).
S . . . a b c d S1 • If Si = Ø – create terminal success node. • Else, delete from clauses in Si xi and all literals preceding xi in OS. • If Si contains an empty clause – create terminal failure node. • Else – create non-terminal node Si. S = 4. Build a “semantic tree”. • Start with S as a root node. • For each literal in OS, sprout a node from S. • For xi, create a set Si by deleting all clauses in S containing xi. S1 =
Start with S as a root node. S S1 S2 S3 S4 a d b d c d v v v v v x x • If Si = Ø – create terminal success node. • Else, delete from clauses in Si xi and all literals preceding xi in OS. • If Si contains an empty clause – create terminal failure node. • Else – create non-terminal node Si. S11 S12 S13 S21 S22 S31 S32 S33 S311 d c d S1 = S31 = S2 = S3 = S4 = 4. Build a “semantic tree”. • For each literal in OS, sprout a node from S. . . . a b c d x • For xi, create a set Si by deleting all clauses in S containing xi. v
Start with S as a root node. S S1 S2 S3 S4 a d b d c d v v v v v x x • If Si = Ø – create terminal success node. • Else, delete from clauses in Si xi and all literals preceding xi in OS. • If Si contains an empty clause – create terminal failure node. • Else – create non-terminal node Si. S11 S12 S13 S21 S22 S31 S32 S33 S311 d d c 4. Build a “semantic tree”. • For each literal in OS, sprout a node from S. . . . a b c d x • For xi, create a set Si by deleting all clauses in S containing xi. v W(S) =
What we have so far… • Slagle proves that: • Every element of W(S) is an implicant. • Every prime implicant is in W(S). • Shows that a symmetric algorithm used to obtain prime implicates if φ is in DNF (A). • May still be interested in finding the minimal sum. • Can use the algorithm again…
Minimal sum • How do we find the minimum sum? • Back to example: W(S) = • Put it in a table [McCluskey, 1956]…
McCluskey: Select the fewest rows such that each column has at least one cross in each selected row. • Slagle: Use the “semantic tree” algorithm again. First, represent table as a product of factors: • R = (P7+P8)(P5+P8)(P4+P5)(P6+P7)(P3+P6)(P3+P4)(P2+P5)P1 (P1+P2+P4+P5)P2(P1+P3)(P1+P2+P3+P4)
SR P1 P2 P3 P4 P5 P6 P7 P8 P7 P4 P4 P5 P8 P6 v v P8 P8 P6 P7 v v v v only success nodes shown • (P1, P2, P3, P5, P7) or Minimal sum • Represent table as a product of factors. (P7+P8)(P5+P8)(P4+P5)(P6+P7)(P3+P6)(P3+P4)(P2+P5) P1(P1+P2+P4+P5)P2(P1+P3)(P1+P2+P3+P4) • Come up with ordering OR using heuristic. • E.g. lower weight (e.g. fewer literals) – earlier. • Use algorithm again to construct tree. • Each element of W(SR) is a consistent table row set. • One of the elements corresponds to the minimal sum.
Slagle: Summary / Remarks • An algorithm to compute all prime + some non-prime implicates. • Use subsumption to get rid of non-primes. • A heuristic attempt to find minimal sum. • Any ordering OS works, practically frequency ordering generates fewer non-primes.
Approach II: de Kleer • Some resolution strategies are complete in proof finding, others in consequence finding. • Example: pure literal removal resolutions are not deduction complete. • Deduction complete resolution strategies will find all prime implicates of formula φ in CNF. • [Tison, de Kleer, etc.]: use deduction complete resolution to generate prime implicates of φ.
Approach II: de Kleer Brute force attempt: • Start with Δ in clausal form. • Repeatedly resolve pairs of clauses of Δ. • Add the result of resolution back to Δ, while removing all subsumed clauses.
Improving Efficiency • Many redundant resolutions. • E.g. for 3 resolvable clauses α, β, γ there are 3 ways to resolve r(α, r(β, γ)), r(r(α, β), γ), and r(r(α, γ), β). • Number of ways to derive result grows quickly. • Key idea [Tison]: place ordering on symbols, and iterate over these symbols in order. • Once all resolutions for a symbol are done, it is never necessary to resolve with respect to that symbol even for new resolution results produced later.
Improving Efficiency Consider 3 clauses: and order literals: a, b, c.
N S Improved Algorithm S is the current set of clauses, and N is the current set of prime implicates. Gist: Pick one clause (C) at a time from S, and for every literal in C (in order) resolve with N. Add new clauses to N.
Remove the next C = from S, add to N, and let Σ = {C}. N S Σ Improved Algorithm: Iteration 2 For each literal x in C, create Nx = clauses in N which resolve with x.
N S Σ Improved Algorithm: Iteration 2 • For each literal x in C: • Resolve each clause in Σ (which is still in N) with each clause in Nx (which is still in N). • For every new clause, discard it if it is subsumed by N U S, or remove any clauses it subsumes from N U S. Add it to N and Σ.
N S Σ Improved Algorithm: Iteration 3 • For each literal x in C: • Resolve each clause in Σ (which is still in N) with each clause in Nx (which is still in N). • For every new clause, discard it if it is subsumed by N U S, or remove any clauses it subsumes from N U S. Add it to N and Σ. Considers literals in order avoiding many redundant resolution steps
Subsumption • This algorithm (and many others) uses subsumption checking heavily. • For clauses subsumption check is a subset check. • e.g. a+b subsumes a+b+c • However, de Kleer can do better.
Subsumption For our algorithm, we are interested in three operations: • Check if clause x is subsumed by some clause in the Δ. • Add clause x to the Δ. • Remove all clauses from Δ which are subsumed by x.
a b b d d b+d a+d c a+b+c Subsumption: Representation • Order literals, turn clauses into lists of literals according to the chosen order. • Build a discrimination tree (trie). c+b+a d+b a+d [ [ [ a b a b d d c ] ] ] Choose order : a,b,c,d
c Subsumption: Checking Checking if clause x is subsumed by some clause in Δ can be done in one go. x = c + b + d a b [ ] b d b d d c v b+d a+d a+b+c subsumed by b + d
d c a+b+d Subsumption: Addition Adding a new (not subsumed) clause x to the knowledge base is easy. x = a + b + d a b [ ] a b d d b d b+d a+d a+b+c
b d b+d d c a+b+d Subsumption: Deletion To remove clauses subsumed by clause x - search trie in left-to-right depth-first fashion removing all clauses containing x. a x = b+d b d [ ] b d a+d a+b+c
de Kleer: Summary • Part 1: Existing [Tison] idea for reducing unnecessary resolutions. • Part 2: New idea: more efficient subsumption using the trie representation.
Consequence Finding: del Val • A clausal knowledge base Δ is written over some clausal language L. • We may be interested in all implicates of Δ or only those that belong to some LT L (LT implicates). • Consequence finding is the task of finding LT implicates.
skip or s(a+c) (a + c) kernel or k(a+c) Write (a+c) as a[c] Kernel Resolution • Recall Tison’s approach: ordered literals – fewer resolutions. Idea: any clause C can be resolved only upon literals (kernel of C) appearing later in the ordering then literal used to obtain C. and order: a, b, c. a b c d
Kernel Resolution In kernel resolution deductions every literal resolved upon is in its clause’s kernel.
Kernel Resolution: Example After C10 clauses containing d are deleted (subsumed).
Skip-filtered Kernel Resolution • What about consequence finding (finding implicates or restricted language LT)? • Extension of kernel resolution. • Produce resolvent C only if skip(C) LT. C is called LT– acceptable. • For any implicate of Δ in LT, we produce a logically stronger implicate. • Need a strategy to find all deductions for LT.
Search Strategy: Bucket Elimination • Associate buckets with each variable xi: b[xi]. • Each bucket contains clauses Ck containing xi only if resolving Ck upon xi can generate LT– acceptable clause. • Process buckets in order x1… xn. • Compute all resolvents on xi for ith bucket. • LT– acceptable resolvents are added in corresponding buckets.
Search Strategy: Incremental Saturation • Idea: take one clause at a time, process it until no more unsubsumed LT– acceptable resolvents can be generated. • Two sets of buckets: active and passive. • Put Δ into passive buckets. • For each clause of Δ • Put in active buckets, use BE (over active/passive) • When done, dump active buckets into passive.
del Val: Summary • Extended the Tison’s approach to consequence finding. • Approach is agnostic to search strategy of of LT-acceptable deductions. • Two search strategies (BE and IS) suggested. • IS may be preferred if Δ grows.
S . . . b a x x b a e a v v x x x x c d a c e a v Appendix A: Slagle for prime implicate generation back