Presentation is loading. Please wait.

Presentation is loading. Please wait.

Logic Logic can be traced back to Aristotle, and more recently to Frege who introduced predicate logic as a language for representing and reasoning about.

Similar presentations


Presentation on theme: "Logic Logic can be traced back to Aristotle, and more recently to Frege who introduced predicate logic as a language for representing and reasoning about."— Presentation transcript:

1 Logic Logic can be traced back to Aristotle, and more recently to Frege who introduced predicate logic as a language for representing and reasoning about knowledge. There are many types of logic. Propositional logic is a simpler form of predicate logic. Other forms include modal and higher-order logics. Modal logic includes temporal, spatial, and preference logic. Propositional, predicate, temporal, and higher-order logics are relevant in the study of Formal Methods.

2 Syntax and Semantics A logic is specified by its syntax and semantics. Syntax is specified by a grammar, e.g. CFG, BNF. Logical semantics has two broad approaches: 1.Model Theory – for the truth value of formulae 2.Proof Theory – for reasoning using proof rules Two key properties: soundness and completeness Soundness  what is true is provable Completeness  what is provable is true

3 Propositional Logic Propositional Logic is a language of boolean formulae made up of variables and logical connectives such as ¬, Λ, and V. Grammar: F  Var | F Λ F | F V F | ¬ F | ( F ) Example: a Λ b V ¬ c Λ d The grammar is ambiguous WRT precedence of operators – although this is easily remedied. The above formula is interpreted as: (a Λ b) V ((¬ c) Λ d) That is, ¬ has higher precedence than Λ which in turn has higher precedence than V.

4 Other useful connectives The connectives  and  are useful, and stand for ‘implies’ and ‘if and only if’ respectively. They can be expressed in terms of ¬, Λ, and V. For example, P  Q is equivalent to ¬P V Q. And P  Q is equivalent to P  Q Λ Q  P which is eqvt to ¬P V Q Λ ¬Q V P. When  and  are used, they each have lower precedence that V.

5 Using Propositional Logic A proposition is a statement that has a truth value, i.e., it is true or false. Examples: “It is Sunday.”, “It is a holiday.” We can abstract such statements by variables. E.g.: P: It is Sunday Q: It is a holiday A statement such as “If it is Sunday then it is a holiday.” can be represented as: P  Q

6 Semantics: Models An Interpretation I is a mapping from the syntactic domain to a semantic domain. We assign a truth value (T or F) for each variable and we interpret the connectives in the usual way: Λ as ‘logical and’; V means ‘logical or’; etc. An Interpretation I is said to be a Model of a formula F, denoted I |= F, if F evaluates to true under the interpretation I. For propositional logic, the truth table covers all interpretations. Each row of the truth table forms one interpretation, and those rows for which the formula evaluates to true correspond to models.

7 Truth Table abcd a Λ b v ¬ c Λ d FFF FF FFFTT FFTFF FFTTF FTFFF …………… TTTFT TTTTT Rows that are highlighted in red correspond to models. For example, {a=F, b=F, c=F, d=T} is a model for a Λ b v ¬ c Λ d. Two other models are also highlighted: {a=b=c=T, d=F} and {a=b=c=d=T}.

8 Some Terminology A formula is said to be satisfiable if it has a model. A formula is inconsistent if it has no model. A formula is valid if it is true in all models. Well-known result: The satisfiability of a propositional logic formula is NP-complete. Given a conjunction of formulae, C, we say that F is a logical consequence of C, written C |= F, if every model for C is also a model for F.

9 Conjunctive Normal Form Propositional Logic formulae can be put into a Conjunctive Normal Form (CNF): (L 11 V … V L 1k 1 ) Λ … Λ (L n1 V … V L nk n ) where each L ij, called a literal, is either a variable V or the negation of a variable, ¬ V. A propositional logic formula can be rewritten into CNF using the following equivalences: F  G ≡ ¬ F V G ¬ (F V G) ≡ ¬ F Λ ¬ G ¬ (F Λ G) ≡ ¬ F V ¬ G F V (G Λ H) ≡ (F V G) Λ (F V H)

10 Clause Form The CNF is also known as the clausal form, and this is the basis for many theorem-provers. Each conjunct (L1 V … V L m ) in the CNF is referred to as a clause. A special case occurs when each clause has exactly one positive literal: (V 1 V ¬ V 2 … ¬ V m ). This is called a definite clause and it can be re-written as: V 1  V 2 Λ … Λ V m A definite clause need not have any negative literal in which case it is written just as: V 1

11 Resolution Theorem Proving Given two clauses (a 1 V … a i … V a m ) and (b 1 V … b j … V b n ) where a i ≡ ¬ b j for some i and j, their resolvent is the disjunction of all literals except a i and b j : (a 1 V … a i-1 V a i+1 … V a m V b 1 V … b j-1 V b j+1 … V b n ) Modus ponens is a special case of resolution: The resolvent of clauses (a) and (¬ a V b) is b.

12 Resolution (cont’d) A resolution proof is essentially a proof by contradiction. To prove that a formula F is a logical consequence of C, i.e., C |= F, we show that C Λ ¬ F is a contradiction, i.e., the result of applying successive resolution steps to C Λ ¬ F results in the empty clause. In the process of resolution, some simplification of clauses can be performed at each step: (i)removing repeated occurrences of a literal from a clause; (ii)deleting a clause containing a literal whose complement is not present in any clause; (iii) deleting a clause with two complementary literals.

13 Justifying the Simplifications 1. Removing repeated literals: Since a clause is a disjunction of literals, L V L ≡ L, and hence we can remove repeated occurrences of L 2. Deleting a clause containing a literal P whose complement is not present in any clause. We can safely assign P to be true as it would not contradict any clause. Since a clause is a disjunct of literals, if P ≡ true, the entire clause is true. 3. Deleting a clause with two complementary literals, P and ¬P. Since P V ¬P ≡ true, the entire clause is true and can be removed.

14 Resolution (cont’d) Multiple resolutions of two clauses are possible when more than one literal occurs in a clause has a complementary literal in another clause. This could happen at each step, and hence a resolution proof involves searching within a tree of possible choices. Example: Let C = (a V ¬ b V ¬ c) Λ b Λ c and F = a To prove C |= F, we derive a contradiction from C Λ ¬ F, as illustrated on the next slide.

15 An Example Consider the formula: F = (a  b Λ c) Λ b Λ c To prove F |= a, we show that F Λ ¬ a is a contradiction. In clausal form, F Λ ¬ a is: (a V ¬ b V ¬ c) Λ b Λ c Λ ¬ a

16 (¬ b V ¬ c) Λ b Λ c (a V ¬ c) Λ c Λ ¬ a (a V ¬ b) Λ b Λ ¬ a ¬ c Λ c¬ b Λ b ¬ c Λ ca Λ ¬ a ¬ b Λ b a Λ ¬ a F F FF F F Resolution Search Tree OR

17 Soundness and Completeness of Resolution Resolution is a sound and complete proof procedure for first-order logic, not just propositional logic. Thus, if some path in the search tree results in a contradiction, all paths will result in a contradiction (for propositional logic). In first-order logic, if some path results in a contradiction, there could be other paths that are infinitely long. But soundness assures us that there will not be another path that is successful. Because of the possibility of infinite paths, the search has to be carried carefully.

18 From Propositional to Predicate Logic Resolution is known to be a sound and complete proof strategy for propositional (as well as first-order) logic. When the clauses are all definite clauses, the search tree is less complex – this is the underlying idea behind the Prolog language execution model, which is based upon first-order (not propositional) logic. In first-order logic, we have predicates, functions, constants and variables. As a result, some paths of the search tree could be infinite (non-termination), and we need a good control strategy to find a proof if one exists.

19 Predicate Logic/Calculus (  x,y) parent(x,y)  father(x,y) Λ (  x,y) parent(x,y)  mother(x,y) In clausal form, it will be: (parent(x,y) V ¬ father(x,y)) Λ (parent(x,y) V ¬ mother(x,y)) Λ In Datalog notation: parent(X,Y) :- father(X,Y). parent(X,Y) :- mother(X,Y).

20 Datalog Datalog is an extension of propositional logic where the logical statements are given as clauses, which are of two kinds: 1. p(terms) 2. p(terms) :- p 1 (terms 1 ) /\ … /\ p n (terms n ) Terms: Comma-separated sequence of constants and/or variables. Finite number of constants.

21 Examples of Datalog Clauses mother(bob, mary). mother(ann, mary). mother(mark, jane). mother(mary, sue). father(bob, mark). father(ann, mark). father(mark, joe). father(mary, steve). parent(X, Y)  father(X, Y). parent(X, Y)  mother(X, Y).

22

23 Recursive Rules How do we define the grandparent relation using the parent relation? How do we define the ancestor relation?

24 Another Example: Graphs

25 Datalog Semantics Given a set of clauses, P, the semantics of P can be given as the least fixed point of T P : 2 B  2 B 2 B is the set of all possible interpretations of the predicates. Each interpretation I ⊆ B. B is called the Herbrand Base: B = { p(c 1,…c n ) : p is a predicate in P, each c i is some constant } T P (I) = { Head : Head  Body is ground instance* of some clause and Body ⊆ I } * - replacing all variables by constants.

26 Fixed Points and Logical Semantics The set of all interpretations, 2 B, forms a lattice under ⊆, with U and ∩ as the lub and glb respectively. T P : 2 B  2 B is monotonic (easy), hence it has a least fixed point, which we can obtain as T P ↑ k ( ∅ ) for some finite k. lfp(T P ) = smallest model for P = the set of logical consequences of P.

27

28

29

30 Smallest Model of P The term “least model” of P is similar to the concept of “least fixed point”. And a model of P is similar to a fixed point. (Good Periodical Question: Prove that every fixed point of T P is a model of P, a Datalog program.) In pure Datalog, there is no negation operator and all conclusions are “positive” facts. Hence, we can over-estimate a model without causing inconsistencies. Example: Although a model for ‘father’ will have those 4 facts, we can add a spurious fact, such as father(bob,bob), and still have a model. Of course, this will result in ‘parent’, ‘gp’, and ‘ancestor’ also having extra, spurious facts. Hence we are interested in the smallest model, or least model, of P as this coincides exactly with the set of logical consequences of P, a theorem that needs to be proved (later).

31 Example of T P m(bob, mary). m(ann, mary). m(mark, jane). m(mary, sue). f(bob,mark). f(ann,mark). f(mark,joe). f(mary,steve). p(X, Y) :- f(X, Y). p(X, Y) :- m(X, Y). gp(X,Y) :- p(X,Z), p(Z,Y).


Download ppt "Logic Logic can be traced back to Aristotle, and more recently to Frege who introduced predicate logic as a language for representing and reasoning about."

Similar presentations


Ads by Google