Lecture 16: Normal Forms Conjunctive Normal Form CNF

advertisement
Conjunctive Normal Form
Lecture 16: Normal Forms
• Can be helpful if interested in validity:
• A formula is in conjunctive normal form if it is generated
by the following grammar.
CSCI 81
Spring, 2012
• CNF ::= C | C ∧ CNF
C ::=L | L ∨ C
L ::=⊥ | ⊤ | P | ¬ P
P ::=p|q|r|...
Kim Bruce
ca!ed literals
• For example, (¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q
CNF
• Any formula can be transformed into CNF:
• See algo in book
p
q
r
ψ
Τ
Τ
T
T
F
F
F
F
Τ
Τ
F
F
T
T
F
F
Τ
F
T
F
T
F
T
F
Τ
F
T
T
F
T
F
T
• Can also read off truth table
• Take false lines in truth table and negate prop
letters:
ψ ≈ (¬p∨¬q∨r) ∧(p ∨ ¬q∨¬r)∧(p∨q∨¬r)
Note ψ fails iff one of conjuncts fails.
Validity
Horn Formulas
• A Horn formula is one that is constructed from
• Disjunction of literals valid iff contains some p
and its negation
• ... p ∨...∨ ¬p ...
• To determine if fmla in CNF valid, check all
conjuncts.
the following grammar, with start symbol H.
• H ::= C | C ∧ H
C ::=A→P
A ::= P | P ∧ A
P ::=⊥ | ⊤ p | q | r |...
• Note that ⊤ → p is equivalent to p, and p → ⊥ to ¬p.
• Example: (p ∧ q ∧ s → p) ∧ (q ∧ r → p) ∧ (p ∧ s → s)
Satisfiability for Horn
Prolog
• Suppose that F is a Horn formula. Let P be the
collection of all subformulas of F.
• Mark ⊤ if it occurs in the list P.
• If P0 ∧P1 ∧ ... ∧Pk →Q is a clause in F, and all of the Pi’s
are marked, then mark Q. Repeat until there are no more
Q’s to mark.
• If ⊥ is marked, declare F to be unsatisfiable. If ⊥ is not
marked, then declare F to be satisfiable.
• Get V by making all marked symbols T and others F.
• Revise syntax from P0 ∧ P1 ∧ ... ∧ Pk → Q to
Q, if P0 ∧ P1 ∧ ... ∧ Pk to
Q :- P0 , P1 , ... , Pk
• Do more after predicate logic.
Predicate Logic
Syntax
• Symbols needed include
• variables: x, y, ...
•
• constant symbols: c, d, ...
Propositional Logic not expressive enough.
• Definition of limx→a f(x) = L iff for all ε > 0 there is a δ
>0 s.t. for all x s.t. |x-a| < δ, then |f(x)-L| < ε.
• Statement of pumping lemma, etc.
• k-ary function symbols: fk, gk, ... for all k
• k-ary predicate symbols: Pk, Qk, ... for all k
• parentheses: (, )
• truth constants ⊥, ⊤
• quantifiers: ∃, ∀
• logical connectives: ¬, ∧, ∨, →
Terms & Formulas
• A term is a variable, a constant symbol, or a term
of the form f(Term1,...,Termk) for f a k-ary
function symbol.
• Atomic formulas are of the form
P(Term1,...,Termk) for P a k-ary relation
• Formulas:
•
An atomic formula is a formula
• If φ, ψ are formulas, so are (¬φ), (φ∧ψ), (φ∨ψ), and (φ→ψ)
• If φ is a formula and x is a variable, so are (∀xφ), (∃xφ)
Examples
• Let L(x,y) stand for x loves y.
• “Everybody loves somebody”
• ∀x.∃y.L(x,y)
• “Someone loves everyone”
• Ambiguous: ∃x.∀y.L(x,y) or ∀y. ∃x.L(x,y)
• “Jane’s mother loves her”
• L(mother(Jane),Jane) where mother() is a function
Limiting Domains
Free & Bound Variables
• Historically confusing!
• Every person hates a wall
• ∀x. (P(x) → ∃y. H(x,y) ∧ W(y))
• There is a wall that is hated by all people.
• ∃y. W(y) ∧ ∀x. (P(x) → H(x,y))
• In Love(x,y) the variables x and y are free
• the meaning of the wff depends on the meaning of x,y
• In ∀x.∃y.L(x,y) occurrences of x and y are
bound by the quantifiers.
• Meaning does not depend on meanings of x, y.
Free Variables
Examples
• An occurrence of x in φ is free in φ if it is a leaf
node in the parse tree of φ such that there is
no path upwards from that node x to a node ∀x
or ∃x.
• Otherwise, that occurrence of x is called
bound.
• For ∀xφ, or ∃xφ, we say that φ – minus any of
φ’s subformulas ∃x ψ, or ∀x ψ – is the scope of
∀x, respectively ∃x.
• (∀x.∃y.L(x,y)) ∧ H(x,y)
• Some occurrences free and some bound.
Substitution
• Define φ[t/x] to be the formula obtained by
replacing each free occurrence of variable x in
φ with t.
• Expect ∀x.φ(x) ⇒ φ[t/x] for every term t
• What about ∀x.∃y.L(x,y) ⇒ ∃y.L(y,y) ?
• Say that t is free for x in φ if no free x leaf in φ
occurs in the scope of ∀y or ∃y for any variable
y occurring in t.
• y not free for x in ∃y.L(x,y)
• Only allow substitution φ[t/x] if t free for x in φ
Download