L9 Logic Concepts
L9 Logic Concepts
L9 Logic Concepts
Formally it deals with the notion of truth in an abstract sense and is concerned with the principles of valid inferencing. A proposition in logic is a declarative statements such as Jack is a male, "Jack loves Mary" etc. which are either true or false (but not both) in a given context.
If we are given some propositions to be true in a given context, then logic helps in inferencing new proposition, which is also true in the same context. For example, if we are given a set of propositions such as It is hot today" and If it is hot it will rain", then we can infer that It will rain today". Propositional Calculus (PC) is a language of propositions basically refers to set of rules used to combine the propositions to form compound propositions using logical operators often called connectives such as , V, ~, ,
Truth table gives us operational definitions of important logical operators. By using truth table, the truth values of wellformed formulae are calculated. Truth table elaborates all possible truth values of a formula. The meanings of the logical operators are given by the following truth table
P Q ~P PQ PVQ P Q P Q
T T F F
T F T F
F F T T
T F F F
T T T F
T F T T
T F F T
Equivalence Laws
Commutation 1. P Q 2. P V Q Association 1. P (Q R) 2. P V (Q V R) Double Negation ~ (~ P) Distributive Laws 1. P ( Q V R) 2. P V ( Q R) De Morgans Laws 1. ~ (P Q) 2. ~ (P V Q) Law of Excluded Middle P V ~P Law of Contradiction P ~P Q P Q V P (P Q) R (P V Q) V R P (P Q) V (P R) (P V Q) (P V R) ~P V~Q ~P ~Q T (true) F (false)
Idempotence 1. P P 2. P V P Absorption 1. P (P V Q) 2. P V (P Q) 3. P V ( ~ P Q) 4. P ( ~ P V Q)
P P P P P V Q P Q
There are some commonly used equivalence relations listed below: P F F P T P P V F P P V T T PQ ~PVQ PQ (P Q) (Q P) (P Q) V (~ P ~ Q
These laws can be verified using truth table approach. Let us verify A V (A B) A using truth table approach.
Showing A V (A B) A
A
T T F F
B
T F T F
AB
T F F F
AVA B
T T F F
Propositional Logic
It basically deals with the validity, satisfiability and unsatisfiability of a formula and derivation of a new formula using equivalence laws. Each row of a truth table for a given formula is called its interpretation under which a formula can be true or false. A formula is called tautology if and only if is true for all interpretations. A formula is also called valid if and only if it is a tautology.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Let be a formula and if there exist at least one interpretation for which is true, then is said to be consistent (satisfiable) i.e., if a model for , then is said to be consistent . A formula is said to be inconsistent (unsatisfiable), if and only if is always false under all interpretations. We can translate simple declarative and conditional (if .. then) sentences of natural language into its corresponding propositional formulae.
Example: Show that "If it is humid then it will rain and it is humid today then it will rain" is a valid argument. Solution: Let us symbolize English sentences by propositional atoms as follows: A B : : It is humid It will rain
Formula corresponding to a text: : ((A B) A) B Using truth table approach, one can see that is true under all four interpretations and hence is valid argument.
Example: If we have to show that a formula : (P Q R) ( Q V S) is valid using truth table, then we have to construct a table of 16 rows for which the truth values of are to be computed. If we carefully analyze , we realize that if P Q R is false, then is bound to be true because of the definition of . Since P Q R is false for 14 entries out of 16, we are left only with two entries to be tested for which P Q R. Therefore, we may find that in order to prove the validity of a formula, all the entries in the truth table are not relevant in this case. There are other methods where we will be concerned with proofs and deductions of logical formula.
Natural Deductive System Axiomatic System Semantic Tableaux Method Resolution Refutation Method
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Rule 1: I- (Introducing ) I- : If P1, P2, , Pn then P1 P2 Pn Interpretation: If we have hypothesized or proved P1, P2, and Pn , then their conjunction P1 P2 Pn is also proved or derived.
Rule 2: E- ( Eliminating ) E- : If P1 P2 Pn then Pi ( 1 i n) Interpretation: If we have proved P1 P2 Pn , then any Pi is also proved or derived. This rule shows that can be eliminated to yield one of its conjuncts. Rule 3: I-V (Introducing V) I-V : If Pi ( 1 i n) then P1V P2 V V Pn Interpretation: If any Pi (1 i n) is proved, then P1 V V Pn is also proved. Rule 4: E-V ( Eliminating V) E-V : If P1 V V Pn, P1 P, , Pn P then P Interpretation: If P1 VV Pn , P1 P, P2 P and Pn P are proved, then P is proved.
Rule 5: I- (Introducing ) I- : If from 1, , n infer is proved then 1 n is proved Interpretation: If given 1, 2, and n to be proved and from these we deduce then 1 2 n is also proved. Rule 6: E- (Eliminating ) - Modus Ponen E- : If P1 P, P1 then P Rule 7: I- (Introducing ) I- : If P1 P2, P2 P1 then P1 P2 Rule 8: E- (Elimination ) E- : If P1 P2 then P1 P2 , P2 P1 Rule 9: I- ~ (Introducing ~) I- ~ : If from P infer P1 ~ P1 is proved then ~P is proved Rule 10: E- ~ (Eliminating ~) E- ~ : If from ~ P infer P1 ~ P1 is proved then P is proved
Eliminate
(E:)
Introducing V
(I:V)
Eliminating V
(E:V)
Introducing
(I : )
Eliminating
(E: )
then A
Introducing Elimination
(I: ) (E: )
If A1 A2, then A1 A2
A2 A1
If A1 A2 then A1 A2 , A2
A1
Introducing ~
(I: ~ )
If from A infer A1 ~ A1 is proved then ~A is proved If from ~ A infer A1 ~A1 is proved then A is proved
Eliminating ~
(E: ~)
If a formula is derived / proved from a set of premises / hypotheses { 1,, n }, then one can write it as from 1, , n infer . In natural deductive system, a theorem to be proved should have a form from 1, , n infer If we write infer , then it means that there are no premises and is true under all interpretations i.e., is a tautology or valid.
Example: Prove that P (Q V R) follows from P Q . Solution: This problem is restated in natural deductive system as "from
P Q infer P (Q V R)". The formal proof is given as follows:
{Theorem} from P Q infer P (Q V R) { premise} PQ (1) { E- , (1)} P (2) { E- , (1)} Q (3) { I-V , (3) } QVR (4) { I-, ( 2, 4)} P (Q V R) Conclusion If we assume that is a premise, then we conclude that is proved if is given i.e., if from infer is a theorem then is concluded. The converse of this is also true. Deduction Theorem: To prove a formula 1 2 n , it is sufficient to prove a theorem from 1, 2, , n infer .
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Example: Prove the following theorem: infer ((Q P) (Q R)) (Q (P R)) Solution: In order to prove infer ((Q P) (Q R)) (Q (P
R)), we prove a theorem from {Q P, Q R} infer Q (P R). Further, for proving Q (P R), we have to prove a sub theorem from Q infer P R
{Theorem} from Q P, Q R infer Q (P R) { premise 1} Q P (1) { premise 2} Q R (2) { sub theorem} from Q infer P R (3) { premise } Q (3.1) { E- , (1, 3.1) } P (3.2) {E- , (2, 3.1) } R (3.3) { I-, (3.2,3.3) } P R (3.4) { I- , ( 3 )} Q (P R) Conclusion
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Example: Establish the following: 1. {Q} |- (P Q) i.e., P Q is a deductive consequence of {Q}. {Hypothesis} Q (1) {Axiom A1} Q (P Q) (2) {MP, (1,2)} P Q proved 2. { P Q, Q R } |- ( P R ) i.e., P R is a deductive consequence of { P Q, Q R }. {Hypothesis} P Q (1) {Hypothesis} Q R (2) {Axiom A1} (Q R) (P (Q R)) (3) {MP, (2, 3)} P (Q R) (4) {Axiom A2} (P (Q R)) ((P Q) (P R)) (5) {MP , (4, 5)} (P Q) (P R) (6) {MP, (1, 6)} P R proved
1. Useful tip Given , we can easily prove for any well-formed formulae and . Deduction Theorem: If is a set of hypotheses and and are well-formed formulae , then { } |- implies |- ( ). Converse of deduction theorem: Given |- ( ), we can prove { } |- . 2. Useful tip If is to be proved, then include in the set of hypotheses and derive from the set { }. Then using deduction theorem, we conclude . Example: Prove ~ P (P Q) using deduction theorem. Proof: We prove {~ P} |- (P Q) and |- ~ P (P Q) follows from deduction theorem.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Rule 1: A tableau for a formula ( ) is constructed by adding both and to the same path (branch). This can be represented as follows: Rule 2: A tableau for a formula ~ ( ) is constructed by adding two alternative paths one containing ~ and other containing ~. ~ ( ) ~ ~
Rule 3: A tableau for a formula ( V ) is constructed by adding two new paths one containing and other containing . V Rule 4: A tableau for a formula ~ ( V ) is constructed by adding both ~ and ~ to the same path. This can be expressed as follows: ` ~ ( V ) ~ ~
Rule 5:
Rule 6:
Rule 7:
Rule 8:
Rule 9:
~ (
) ( ~ ) V (~ ) ~ ( ) ~ ~
Example: Show that : (P Q R) ( ~P S) Q ~ R ~ S is inconsistent using tableaux method. (Root} (P Q R) ( P S) Q ~R ~S (1) {Apply rule 1 to 1} P Q R (2) ~P S (3) Q ~R ~S {Apply rule 6 to 3} ~ ~P = P S Closed: {S, ~ S} on the path {Apply rule 6 to 2)} ~ (P Q) R Closed { R, ~ R} ~P ~Q Closed {P, ~ P} Closed{Q, ~ Q}
Resolution Refutation in PL
Resolution refutation is another simple method to prove a formula by contradiction. Here negation of goal to be proved is added to given set of clauses and shown that there is a refutation in new set using resolution principle. During resolution we need to identify two clauses, one with positive atom (P) and other with negative atom (~ P) for the application of resolution rule. It is based on modus ponen inference rule.
Use De Morgans laws to push ~ (negation) immediately before atomic formula. ~ ( P Q) ~ P V ~ Q ~ ( P V Q) ~ P ~ Q Use distributive law to get CNF. P V (Q R) (P V Q) (P V R)
We notice that CNF representation of a formula is of the form (C1 .. Cn ) , where each Ck , (1 k n ) is a clause which is disjunction of literals.
Resolvent of Clauses
If two clauses C1 and C2 contain a complementary pair of literals {L, ~L}, then these clauses may be resolved together by deleting L from C1 and ~ L from C2 and constructing a new clause by the disjunction of the remaining literals in C1 and C2. The new clause thus generated is called resolvent of C1 and C2 . Here C1 and C2 are called parents of resolved clause. Inverted binary tree is generated with the last node of the binary tree to be a resolvent. This is also called resolution tree.
~Q V W
P V ~W
Theorem: If C is a resolvent of two clauses C1 and C2 , then C is a logical consequence of {C1 , C2 }. A deduction of an empty clause from a set S of clauses is called a resolution refutation of S.
Theorem: Let S be a set of clauses. A clause C is a logical consequence of S iff the set S= S {~ C} is unsatisfiable. In otherwords, C is a logical consequence of a given set S iff an empty clause is deduced from the set S'.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Example: Show that C V D is a logical consequence of S ={AVB, ~ AVD, C V~ B} using resolution refutation principle.
First we will add negation of logical consequence i.e., ~ (C V D) ~C ~D to the set S. Get S = {A V B, ~ A V D, C V~ B, ~C, ~D}. Now we show that S is unsatisfiable by deriving contradiction using resolution principle.
AVB
~A V D
CV~B
~C
~D
BVD CVD D
Since we get contradiction from S, we can conclude that (C V D) is a logical consequence of S = {AVB, ~ AVD, CV~ B}.
In Predicate Logic, such sentences can be easily represented and the limitations of propositional logic are removed to some extent. The predicate logic is logical extension of propositional logic. The first order predicate logic is one where the quantification is over simple variables.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Predicate Calculus
It has three more logical notions as compared to propositional calculus.
Terms, Predicates and Quantifiers (universal or existential quantifiers i.e. for all' and there exists)
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
A statement x loves y is represented as LOVE(x, y) which maps it to true or false when x and y get instantiated to actual values. A statement johns father loves john is represented as LOVE(father(john), john). Here father is a function that maps john to his father. The predicate names GREATER and LOVE take two terms and map to T or F depending upon the values of their terms.
Example: Translate the text "Every man is mortal. John is a man. Therefore, John is mortal" into Predicate Calculus formula. Solution: Let MAN(x), MORTAL(x) represent x is a man and x is mortal respectively. Every man is mortal :(x) (MAN(x) MORTAL(x)) John is a man : MAN(john) John is mortal : MORTAL(john) The whole text can be represented by the following formula. (x) ((MAN(x) MORTAL(x)) MAN(john)) MORTAL(john)
Example: Let : (x) ( y) P(x, y) be a formula. Evaluate it under the following interpretation I.
We
use notation I[] = T (or F), which means that is evaluated to be true or false under interpretation I over a domain D. Let and are formulae and I is an interpretation over any domain D. The following holds true. I[ ] = I[] I[] I[ V ] = I[] V I[] I[ ] = I[] I[] I[~] = ~ I[] = T iff I[] = F
A formula is said to be consistent (satisfiable) if and only if there exists an interpretation I such that I[] = T. Alternatively we say that I is a model of or I satisfies . A formula is said to be inconsistent (unsatisfiable) if and only if no interpretation that satisfies or there exists no model for . A formula is valid if and only if for every interpretation I, I[] = T. A formula is a logical consequence of a set of formulae {1, 2, ..., n } if and only if for every interpretation I, if I[1 n ] = T, then I[] = T.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Contd..
A closed formula of FOL is said to be in Prenex Normal Form (PNF) if and only if is represented as (q1 x1) (q2 x2) (qn xn) (M), where, qk , (1 k n ) quant ( or ) and M is a formula free from quantifiers. A list of quantifiers [(q1 x1) (qn xn)] is called prefix and M is called the matrix of a formula . Here M is represented in CNF.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Transformation of Formula into PNF A formula can be easily tranformed into PNF using various equivalence laws. We use the following conventions: [x] - a formula , which contains a variable x. - a formula without a variable x. q Quantifier ( or ).
Equivalence Laws: There are following pairs of logically equivalent formulae called equivalence laws in addition to the equivalence laws given for PL. 1. 2. 3. 4. 5. 6. (q x) [x] V V (q x) [x] (q x) [x] (q x) [x] ~ ((x) [x]) ~ ((x) [x]) (q x) ( [x] V ) (q x) ( V [x]) (q x) ( [x] ) (q x) ( [x]) (x) (~ [x]) (x) (~ [x])
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Any formula in FOL can be transformed into its standard form. Matrix of standard formula is in CNF and prefix is free from existential quantifiers. Formula in standard form is expressed as: (x1) (xn) (C1 Cm), Since all the variables in prefix are universally quantified, we omit prefix part from the standard form for the sake of convenience and write standard form as (C1 Cm). A clause is a closed formula of the form (x1) (xn) (L1V V Lm), where each Lk is a literal and x1,,xn are variables occurring in L1, , Lm. Since all the variables in a clause are universally quantified, we omit them and write clause as (L1V V Lm ) for the sake of simplicity.
where Ck ,(1 k m) is formula in disjunctive normal form.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
The standard form of any formula is of the form (C1 Cm), where each Ci , (1 i m) is a clause. We define S = { C1, ,Cm } to be a set of clauses that represents a standard form of a formula . S is said to be unsatisfiable (inconsistent) if and only if there no interpretation that satisfies all the clauses of S simultaneously. A formula is unsatisfiable (inconsistent) if and only if its corresponding set S is unsatisfiable. S is said to be satisfiable (consistent) if and only if each clause is consistent i.e., an interpretation that satisfies all the clauses of S simultaneously. Alternatively, an interpretation I models S if and only if I models each clause of S.
Example:
Consider two clauses C1 and C2 as follows: C1 = P(x) V Q(x) C2 = ~ P(f(x)) V R(x) Substitute 'f(a)' for 'x' in C1 and 'a' for 'x' in C2 , where 'a' is a new constant from the domain, then C3 = P(f(a)) V Q(f(a)) C4 = ~ P(f(a)) V R(a) Resolvent C of C3 and C4 is [Q(f(a)) V R(a)] Here C3 and C4 do not have variables. They are called ground instances of C1 and C2 . In general, if we substitute 'f(x)' for 'x' in C1 , then C'1 = P(f(x)) V Q(f(x)) Resolvent C' of C'1 and C2 is [Q(f(x)) V R(x)] We notice that C is an instance of C' .
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Theorem: L is a logical consequence of S iff {S ~L} = { C1,.... , Cn , ~ L} is unsatisfiable. A deduction of an empty clause from a set S of clauses is called a resolution refutation of S. Theorem: (Soundness and completeness of resolution): There is a resolution refutation of S if and only if S is unsatisfiable (inconsistent). Theorem: L is a logical consequence of S if and only if there is a resolution refutation of S {~L}. We can summarize that in order to show L to be a logical consequence the of set of formulae {1, , n }, use the following procedure.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Procedure:
Obtain a set S of all the clauses by converting each k to its corresponding standard form and then to the clauses. Show that a set S { ~ L} is unsatisfiable i.e., the set S { ~ L} contains either empty clause or empty clause can be derived in finite steps using resolution method. If so, then report 'Yes' and conclude that L is a logical consequence of S and subsequently of formulae 1, , n otherwise report 'No'. If the choice of clauses to resolve at each step is made in a systematic ways, then resolution algorithm will find a contradiction if one exists. There exist various strategies for making the right choice that can speed up the process considerably.
Useful Tips:
Initially choose a clause from the negated goal clauses as one of the parents to be resolved ( This corresponds to intuition that the contradiction we are looking for must be because of the formula we are trying to prove) . Choose a resolvent and some existing clause if both contain complementary literals. If such clauses do not exists, then resolve any pairs of clauses that contain complementary literals. Whenever possible, resolve with the clauses with single literal. Such resolution generate new clauses with fewer literals than the larger of their parent clauses and thus probably algorithm terminates faster. Eliminate tautologies and clauses that are subsumed by other clauses as soon as they are generated.
Logic Programming
Logic programming is based on first order predicate logic. Clauses are very common in logic programming which are special forms of FOL. Program in logic programming is a collection of clauses. Clause in logic programming adopts a special clausal notation. Queries are solved using resolution principle. A clause in logic programming is represented in a clausal notation as A1, , Ak B1,, Bt , where Aj are positive literals and Bk are negative literals.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Here Aj , (1 j k) are positive literals and Bi , (1 i t) are negative literals. It must be noted that interpretation of A B is same as B A In clausal notation, all variables are assumed to be universally quantified. Bi , (1 i t) (negative literals) are called antecedents and Aj , (1 j k) (positive literals) are called consequents. Commas in antecedent and consequent denote conjunction and disjunction respectively.
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2008 For Evaluation Only.
Applying the results of FOL to the logic programs, a goal G with respect to a program P (finite set of clauses) is solved by showing that the set of clauses P { ~ G} is unsatisfiable or there is a resolution refutation of P { ~ G}. If so, then G is logical consequence of a program P. The basic constructs of logic programming are inherited from FOL. There are three basic statements: facts, rules and queries. These are special forms of clauses.
Example:
GRANDFATHER (x, y) FATHER (x, z) , PARENT (z, y) PARENT (x, y) FATHER (x, y) PARENT (x, y) MOTHER (x, y) FATHER ( abraham, robert) FATHER ( robert, mike)
In FOL above program is represented as a set of clauses as: S = { GRANDFATHER (x, y) V ~ FATHER (x, z) V ~ PARENT
(z, y), PARENT(x, y) V ~ FATHER (x, y), PARENT(x, y) V ~ MOTHER (x, y), FATHER ( abraham, robert), FATHER ( robert, mike) }
Simple queries : (a)Ground Query Query: Is abraham a grandfather of mike ?" GRANDFATHER (abraham, mike). In FOL, ~ GRANDFATHER (abraham, mike) is negation of goal { GRANDFATHER (abraham, mike). Include {~goal} in the set S and show using resolution refutation that S {~ goal} is unsatisfiable in order to conclude the goal. Let ~ goal is numbered as ( vi) in continuation of first five clauses of S listed above. vi. ~ GRANDFATHER (abraham, mike) Resolution tree is given as follows:
(i)
{x / abraham, y / mike}
( vi )
{z / robert}
( ii)
(v)
Answer:
Yes
(b)
Non ground queries Query: Does there exist x such that x is a father of robert ? {Who is father of robert?} FATHER (x, robert). Query: Does there exist x such that abraham is a father of x?" {abraham is father of whom?} FATHER (abraham, x). Query : Do there exist x and y such that x is a father of y?" { who is father of whom?} FATHER (x, y).
Assignment 4
Write a program in language of your choice for Checkers game. Use - pruning concept. Last date of submission: 5th Nov.
Late submission : 6th Nov. (with penalty)