formula simpli cation, essential laws, normal formscs245/logic04_prop...some formula in disjunctive...
TRANSCRIPT
Formula Simplification, Essential Laws,Normal Forms
Lila Kari
University of Waterloo
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 1 / 27
Propositional calculus
In standard algebra, expressions in which the variables and constantsrepresent numbers are manipulated.Consider for instance the expression
(a + b)− b
One sees at a glance that this expressions yields a.In fact, we are so accustomed to performing such algebraicmanipulations that we are no longer aware of what is behind eachstep. Here we used the identities:
(x + y)− z = x + (y − z)
y − y = 0
x + 0 = xFormula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 2 / 27
Simplifications of logic formulas
Consider the following formula
(p ∧ q) ∧ ¬q.This formula can be simplified in a similar way, except that
(tauto)logical equivalences take the place of algebraic identities.
(A ∧ B) ∧ C |=|A ∧ (B ∧ C )
(A ∧ ¬A) |=|0
A ∧ 0 |=|0.We can now apply these equivalences to conclude
(p ∧ q) ∧ ¬q |=|p ∧ (q ∧ ¬q) |=|p ∧ 0 |=|0.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 3 / 27
Removing conditionals and biconditionals
Since the symbolic treatment of conditionals and biconditionals isrelatively cumbersome, one usually removes them before performingfurther formula manipulations.To remove the conditional, one uses the following logical equivalence:
p → q |=|¬p ∨ q.
There are two ways to remove the biconditional
p ↔ q |=| (p ∧ q) ∨ (¬p ∧ ¬q)
p ↔ q |=| (p → q) ∧ (q → p) |=|(¬p ∨ q) ∧ (p ∨ ¬q).
The first version expresses the fact that two formulas are equivalent ifthey have the same truth values.The second version stresses the fact that two formulas are equivalentif the first implies the second, and the second implies the first.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 4 / 27
Example
Example. Remove → and ↔ from the following formula:
(p → q ∧ r) ∨ ((r ↔ s) ∧ (q ∨ s)).
Solution.
(¬p ∨ q ∧ r) ∨ (((¬r ∨ s) ∧ (r ∨ ¬s)) ∧ (q ∨ s)).
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 5 / 27
Essential laws for propositional calculus
Law Namep ∨ ¬p |=|1 Excluded middle lawp ∧ ¬p |=|0 Contradiction lawp ∨ 0 |=|p, p ∧ 1 |=|p Identity lawsp ∨ 1 |=|1, p ∧ 0 |=|0 Domination lawsp ∨ p |=|p, p ∧ p |=|p Idempotent laws¬(¬p) |=|p Double-negation lawp ∨ q |=|q ∨ p, p ∧ q |=|q ∧ p Commutative laws(p ∨ q) ∨ r |=|p ∨ (q ∨ r) Associative laws(p ∧ q) ∧ r |=|p ∧ (q ∧ r)p ∨ (q ∧ r) |=|(p ∨ q) ∧ (p ∨ r) Distributive lawsp ∧ (q ∨ r) |=|(p ∧ q) ∨ (p ∧ r)¬(p ∧ q) |=|¬p ∨ ¬q De Morgan’s laws¬(p ∨ q) |=|¬p ∧ ¬q
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 6 / 27
Essential laws for propositional calculus
• All laws can be proved by the truth table method.
• With the exception of the double-negation law, all laws come inpairs, called dual pairs: For each formula depending only on theconnectives ¬,∧,∨, the dual is found by replacing all 1 by 0, all 0 by1, all ∧ by ∨, and all ∨ by ∧.
• The laws allow one to simplify a formula, and it is normally a goodidea to apply them whenever it is possible. For instance, the formula¬¬p ∧ (q ∨ ¬q) is logically equivalent to p.
• The commutative, associative and distributive laws have theirequivalents in standard algebra. In fact, the connective ∨ is oftentreated like +, and the connective ∧ is often treated like ×.
• NOTE: The above analogy sometimes breaks down.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 7 / 27
Further laws
• From these laws one can derive further laws, forexample, the absorption laws
p ∨ (p ∧ q) |=|p
p ∧ (p ∨ q) |=|p.
(To prove them, use identity law, distributive law,domination law and identity law again.)
• Another important law (and its dual):
(p ∧ q) ∨ (¬p ∧ q) |=|q
(p ∨ q) ∧ (¬p ∨ q) |=|q.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 8 / 27
Shortcuts for simplifying formulas
Definition. A formula is called a literal if it is of the form p or ¬p,where p is a propositional variable. The two formulas p and ¬p arecalled complementary literals.
The following rules are available to simplify conjunctions containingonly literals.
• If a conjunction contains complementary literals, or if itcontains the propositional constant 0, it always yields 0;that is, it is a contradiction.
• All instances of the propositional constant 1, and allduplicate copies of any literal, may be dropped.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 9 / 27
Shortcuts for simplifying formulas
To simplify disjunctions, the duals of the previous two rules are used.
• If a disjunction contains complementary literals, or if itcontains the propositional constant 1, it always yields 1;that is, it is a tautology.
• All instances of the propositional constant 0, and allduplicate copies of any literal may be dropped.
Example. Simplify
(p3 ∧ ¬p2 ∧ p3 ∧ ¬p1) ∨ (p1 ∧ p3 ∧ ¬p1).
Solution: ¬p1 ∧ ¬p2 ∧ p3.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 10 / 27
Disjunctive Normal Form (DNF)
Formulas can be transformed into standard forms so that theybecome more convenient for symbolic manipulations and makeidentification and comparison of two formulas easier.
There are two types of normal forms in propositional calculus: theDisjunctive Normal Form and the Conjunctive Normal Form.
Definition. A formula is said to be in Disjunctive Normal Form(DNF) if it is written as a disjunction, in which all the terms areconjunctions of literals.
Example: (p ∧ q) ∨ (p ∧ ¬q), p ∨ (q ∧ r), ¬p ∨ t are in disjunctivenormal forms.
The disjunction ¬(p ∧ q) ∨ r is not in disjunctive normal form.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 11 / 27
Conjunctive Normal Form (CNF)
Definition. A disjunctions with literals as disjuncts is called adisjunctive clause.A conjunction with literals as conjuncts is called a conjunctive clause.Example:
(p ∨ q ∨ ¬r) is a disjunctive clause
(¬p ∧ s ∧ ¬q) is a conjunctive clause
Disjunctive and conjunctive clauses are simply called clauses.
Definition. A conjunction with disjunctive clauses as its conjuncts issaid to be in Conjunctive Normal Form (CNF).
Example:
p ∧ (q ∨ r) and p ∧ q are in conjunctive normal form.
However p ∧ (r ∨ (p ∧ q)) is not in conjunctive normal form.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 12 / 27
DNF and CNF summary
A formula in Disjunctive Normal Form (DNF) is of the form(A11 ∧ . . .∧A1n1)∨ . . .∨ (Ak1 ∧ . . .∧Aknk ) where Aij are literals.
The formulas (Aj1 ∧ . . . ∧ Ajnj ) are the conjunctive clauses of theformula in DNF.
A formula in Conjunctive Normal Form (CNF) is of the form(A11 ∨ . . .∨A1n1)∧ . . .∧ (Ak1 ∨ . . .∨Aknk ), where Aij are literals.
The formulas (Aj1 ∨ . . . ∨ Ajnj ) are the disjunctive clauses of theformula in CNF.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 13 / 27
DNF and CNF examples
Observe the following formulas:
(1)p
(2)¬p ∨ q
(3)¬p ∧ q ∧ ¬r(4)¬p ∨ (q ∧ ¬r)
(5)¬p ∧ (q ∨ ¬r) ∧ (¬q ∨ r)
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 14 / 27
DNF and CNF examples - Comments
• (1) p - is an atom, and therefore a literal. It is a disjunction withonly one disjunct. It is also a conjunction with only one conjunct.Hence it is a disjunctive or conjunctive clause with one literal. It is aformula in disjunctive normal form with one conjunctive clause p. Itis also a formula in conjunctive normal form with one disjunctiveclause p.
• (2)¬p ∨ q - is a disjunction with two disjuncts, and a disjunctivenormal form with two clauses, each with one literal. It is also aconjunction with one conjunct, and thus a formula in conjunctivenormal form which consists of two literals.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 15 / 27
DNF and CNF examples - Comments
• (3)¬p ∧ q ∧ ¬r - is a conjunction and a formula in conjunctivenormal form. It is also a disjunction and a formula in disjunctivenormal form.
• (4)¬p ∨ (q ∧ ¬r) - is a formula in disjunctive normal form, but notin conjunctive normal form.
• (5)¬p ∧ (q ∨ ¬r) ∧ (¬q ∨ r) - is a formula in conjunctive normalform but not in disjunctive normal form.
• If ∨ is exchanged for ∧ in (4) and (5), then (4) becomes a formulain conjunctive normal form and (5) becomes a formula in disjunctivenormal form.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 16 / 27
How to obtain normal forms?
Use the following tautological equivalences:(1) A→ B |=|¬A ∨ B .(2) A↔ B |=|(¬A ∨ B) ∧ (A ∨ ¬B).(3) A↔ B |=|(A ∧ B) ∨ (¬A ∧ ¬B).(4) ¬¬A |=|A.(5) ¬(A1 ∧ . . . ∧ An) |=|¬A1 ∨ . . . ∨ ¬An.(6) ¬(A1 ∨ . . . ∨ An) |=|¬A1 ∧ . . . ∧ ¬An.(7) A ∧ (B1 ∨ . . . ∨ Bn) |=|(A ∧ B1) ∨ . . . ∨ (A ∧ Bn).
(B1 ∨ . . . ∨ Bn) ∧ A |=|(B1 ∧ A) ∨ . . . ∨ (Bn ∧ A).(8) A ∨ (B1 ∧ . . . ∧ Bn) |=|(A ∨ B1) ∧ . . . ∧ (A ∨ Bn).
(B1 ∧ . . . ∧ Bn) ∨ A |=|(B1 ∨ A) ∧ . . . ∧ (Bn ∨ A).
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 17 / 27
How to obtain normal forms?
By the replaceability of tautological equivalences, we can replace thepreceding formulas on the left with the corresponding ones on theright to yield a formula tautologically equivalent to the original one.
• By (1)–(3) we eliminate → and ↔.
• By (4)–(6) we eliminate ¬,∨,∧ from the scope of ¬such that any ¬ has only an atom as its scope.
• By (7) we eliminate ∨ from the scope of ∧.
• By (8) we eliminate ∧ from the scope of ∨.
This method leads to obtaining the disjunctive or conjunctive normalforms.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 18 / 27
Example
Example. Convert the following formula into a conjunctive normalform.
¬((p ∨ ¬q) ∧ ¬r).
The conjunctive normal form can be found by the followingderivations:
¬((p ∨ ¬q) ∧ ¬r) |=||=|¬(p ∨ ¬q) ∨ ¬¬r De Morgan|=|¬(p ∨ ¬q) ∨ r Double negation|=|(¬p ∧ ¬¬q) ∨ r De Morgan|=|(¬p ∧ q) ∨ r Double negation|=|(¬p ∨ r) ∧ (q ∨ r) Distributivity
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 19 / 27
Algorithm for Conjunctive Normal Form
1 Eliminate equivalence and implication, using A→ B |=|¬A ∨ Band A↔ B |=|(¬A ∨ B) ∧ (A ∨ ¬B).
2 Push ¬ inwards, to the variables, using De Morgan’s Laws3 Recursive procedure CNF (A) :
1 If A is a literal then return A.2 If A is B ∧ C then return CNF (B) ∧ CNF (C ).3 If A is B ∨ C then
- call CNF (B) and CNF (C )- suppose CNF (B) = B1 ∧ B2... ∧ Bn
- suppose CNF (C ) = C1 ∧ C2... ∧ Cm
- return ∧i=1...n,j=1...m(Bi ∨ Cj)
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 20 / 27
Example of Step 3.3 in converting to CNF
((a ∨ b) ∧ (c ∨ ¬a ∨ d))∨((¬a) ∧ (c ∨ d) ∧ (¬b ∨ ¬c ∨ ¬d))
n = 2 clauses
m = 3 clauses
the resulting CNF will have 2× 3 = 6 clauses
it can be further simplified
(a ∨ b ∨ ¬a) ∧ (a ∨ b ∨ c ∨ d) ∧ (a ∨ b ∨ ¬b ∨ ¬c ∨ ¬d)∧
∧(c∨¬a∨d∨¬a)∧(c∨¬a∨d∨c ∨ d)∧(c∨¬a∨d∨¬b ∨ ¬c ∨ ¬d) |=|
(a ∨ b ∨ c ∨ d) ∧ (¬a ∨ c ∨ d)
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 21 / 27
Existence of normal forms
Theorem. Any formula A ∈ Form(Lp) is tautologically equivalent tosome formula in disjunctive normal form.
Proof. (i) If A is a contradiction, then A is tautologically equivalentto the DNF p ∧ ¬p, p being any atom occurring in A.
(ii) If A is not a contradiction, we employ the following method (thisis the idea of the proof worked out on an example, not the full proof).
Suppose A has three atoms, p, q, r occuring in A, and the value of Ais 1 iff 1, 1, 0, or 1, 0, 1, or 0, 0, 1, are assigned to p, q, r respectively.
For each of these assignments, we form a conjunctive clause withthree literals, each being one of the atoms or its negation, accordingto whether this atom is assigned 1 or 0:
(p ∧ q ∧ ¬r), (p ∧ ¬q ∧ r), and ¬(p ∧ ¬q ∧ r)
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 22 / 27
Obviously,
(1) has value 1 iff 1, 1, 0 are assigned to p, q, r
(2) has value 1 iff 1, 0, 1 are assigned to p, q, r
(3) has value 1 iff 0, 0, 1 are assigned to p, q, r
Therefore, the following DNF is tautologically equivalent to A:
(p ∧ q ∧ ¬r) ∨ (p ∧ ¬q ∧ r) ∨ (¬p ∧ ¬q ∧ r).
Note: If A is a tautology, the required DNF may simply be p ∨ ¬pwhere p is any atom occurring in A. Q.E.D.
Similarly, we have:
Theorem. Any formula A ∈ Form(Lp) is tautologically equivalent tosome formula in conjunctive normal form.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 23 / 27
Disjunctive normal forms from truth tables
We have shown how to find the truth table of a logical formula.The previous theorem shows that the reverse is also possible:One can convert any given truth table into a (DNF) formula.
What is the DNF of the formula given by the following truth table?
p q r f1 1 1 1*1 1 0 01 0 1 1*1 0 0 00 1 1 00 1 0 00 0 1 1*0 0 0 0
f |=|(p ∧ q ∧ r) ∨ (p ∧ ¬q ∧ r) ∨ (¬p ∧ ¬q ∧ r).
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 24 / 27
Conjunctive Normal Form from truth tables
• Complementation can be used to obtain conjunctivenormal forms from truth tables.
• If A is a formula containing only the connectives ¬,∨and ∧, then its complement is formed by replacing all ∨by ∧, all ∧ by ∨, and all atoms by their negations.
• Example: Find the complement of the formulaA = (p ∧ q) ∨ ¬r .
• Answer: ¬A = (¬p ∨ ¬q) ∧ r .
• Note that if a formula A is in DNF, then itscomplement, ¬A, is in CNF
• This idea can be used to find the conjunctive normalform from the truth table of some Boolean function f .
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 25 / 27
CNF of f obtained from the truth table of f
One first determines the disjunctive normal form for ¬f .
If the resulting DNF formula is A, then A |=|¬fThen ¬A is a CNF formula, and ¬A |=|¬(¬)f |=|f
Example: Find the CNF of the function f1 given by the truth table:
p q r f11 1 1 11 1 0 11 0 1 01 0 0 00 1 1 10 1 0 10 0 1 00 0 0 1
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 26 / 27
Example contd.
Solution: ¬f1 is true for the following assignments:
p = 1, q = 0, r = 1
p = 1, q = 0, r = 0
p = 0, q = 0, r = 1
The DNF of ¬f1 is therefore
A = (p ∧ ¬q ∧ r) ∨ (p ∧ ¬q ∧ ¬r) ∨ (¬p ∧ ¬q ∧ r) |=|¬f1.
This formula has the complement
¬A |=|(¬p ∨ q ∨ ¬r) ∧ (¬p ∨ q ∨ r) ∧ (p ∨ q ∨ ¬r) |=|¬¬f1
which is the desired CNF for f1.
Formula Simplification, Essential Laws, Normal Forms CS245, Logic and Computation 27 / 27