1 COSC3306: Programming Paradigms Lecture 8: Declarative Programming Specifications Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003.

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

CS4026 Formal Models of Computation Part II The Logic Model Lecture 1 – Programming in Logic.
Biointelligence Lab School of Computer Sci. & Eng.
Inference Rules Universal Instantiation Existential Generalization
Chapter 11 :: Logic Languages
Knowledge & Reasoning Logical Reasoning: to have a computer automatically perform deduction or prove theorems Knowledge Representations: modern ways of.
Standard Logical Equivalences
Automated Reasoning Systems For first order Predicate Logic.
First Order Logic Resolution
Inference and Reasoning. Basic Idea Given a set of statements, does a new statement logically follow from this. For example If an animal has wings and.
For Friday No reading Homework: –Chapter 9, exercise 4 (This is VERY short – do it while you’re running your tests) Make sure you keep variables and constants.
Logic Use mathematical deduction to derive new knowledge.
13 Automated Reasoning 13.0 Introduction to Weak Methods in Theorem Proving 13.1 The General Problem Solver and Difference Tables 13.2 Resolution.
Logic CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Logic.
Logic Concepts Lecture Module 11.
CS 330 Programming Languages 12 / 02 / 2008 Instructor: Michael Eckmann.
Knowledge Representation Methods
Chapter 12 - Logic Programming
Prolog IV Logic, condensed. 2 Propositional logic Propositional logic consists of: The logical values true and false ( T and F ) Propositions: “Sentences,”
Outline Recap Knowledge Representation I Textbook: Chapters 6, 7, 9 and 10.
Formal Logic Proof Methods Direct Proof / Natural Deduction Conditional Proof (Implication Introduction) Reductio ad Absurdum Resolution Refutation.
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Logic Programming Languages. Objective To introduce the concepts of logic programming and logic programming languages To introduce a brief description.
1 Automated Reasoning Introduction to Weak Methods in Theorem Proving 13.1The General Problem Solver and Difference Tables 13.2Resolution Theorem.
Inference and Resolution for Problem Solving
Knoweldge Representation & Reasoning
Let remember from the previous lesson what is Knowledge representation
ISBN Chapter 16 Logic Programming Languages.
Logic Programming Languages
Notes for Chapter 12 Logic Programming The AI War Basic Concepts of Logic Programming Prolog Review questions.
Propositional Calculus Composed of symbols –P – some true statement P might represent something like “It is Monday” or “the car is red” And sentences –a.
Conjunctive normal form: any formula of the predicate calculus can be transformed into a conjunctive normal form. Def. A formula is said to be in conjunctive.
1 Chapter 8 Inference and Resolution for Problem Solving.
1-1 Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical.
Declarative vs Procedural Programming  Procedural programming requires that – the programmer tell the computer what to do. That is, how to get the output.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
Pattern-directed inference systems
Logical Agents Logic Propositional Logic Summary
ARTIFICIAL INTELLIGENCE [INTELLIGENT AGENTS PARADIGM] Professor Janis Grundspenkis Riga Technical University Faculty of Computer Science and Information.
CHAPTER 15 & 16 Functional & Logic Programming Languages.
CS Introduction to AI Tutorial 8 Resolution Tutorial 8 Resolution.
The AI War LISP and Prolog Basic Concepts of Logic Programming
Dr. Muhammed Al-Mulhem ICS An Introduction to Logical Programming.
Logic Programming Languages Session 13 Course : T Programming Language Concept Year : February 2011.
Automated Reasoning Early AI explored how to automated several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Automated Reasoning Early AI explored how to automate several reasoning tasks – these were solved by what we might call weak problem solving methods as.
Automated Reasoning Systems For first order Predicate Logic.
© Kenneth C. Louden, Chapter 12 - Logic Programming Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
Propositional Logic Predicate Logic
Programming Languages Third Edition Chapter 4 Logic Programming.
© Copyright 2008 STI INNSBRUCK Intelligent Systems Propositional Logic.
ISBN Chapter 16 Logic Programming Languages.
1-1 An Introduction to Logical Programming Sept
1 Propositional Logic Limits The expressive power of propositional logic is limited. The assumption is that everything can be expressed by simple facts.
Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
Introduction to Prolog Asst. Prof. Dr. Senem Kumova Metin Revised lecture notes of “Concepts of Programmig Languages, Robert W. Sebesta, Ch. 16”
Logical Agents Chapter 7. Outline Knowledge-based agents Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem.
Foundations of Discrete Mathematics Chapter 1 By Dr. Dalia M. Gil, Ph.D.
Copyright 1999Paul F. Reynolds, Jr. Foundations of Logic Programming.
Logical Agents. Outline Knowledge-based agents Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability.
Propositional Calculus
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Knowledge Representation and Reasoning
Logic Programming Languages
Logic Use mathematical deduction to derive new knowledge.
Prolog IV Logic, condensed.
Back to “Serious” Topics…
CS2136: Paradigms of Computation
Foundations of Discrete Mathematics
Presentation transcript:

1 COSC3306: Programming Paradigms Lecture 8: Declarative Programming Specifications Haibin Zhu, Ph.D. Computer Science Nipissing University (C) 2003

2 Contents Logic Programming First order predicate calculus and Horn clause ResolutionUnification Search structure Application

3 Logic Programming Logic programming refers to a paradigm that uses a form of symbolic logic as a programming language. The property of logic programming model is –{Logic Program} = {Logic Statements} + {Control Strategy} where logic statements consists of a set of rules and facts expressing the relationships between objects.

4 Logic Programming Control strategy is known as resolution or the sequence of steps the deduction system chooses to answer a question from the logic system. The form of logic used in logic programming languages is the first-order predicate calculus, which is a paradigm of formally expressing logical statements. A logical statement is a statement that is either true or false.

5 First-order predicate calculus Constant: A symbol that represents an object such as names and numbers also known as atoms, since it can not be broken down into sub  objects. Logical Statement: An unconditional term, sometimes called a fact, that represents relations between objects and asserts that something is a quality, attribute or property of something else.

6 First-order predicate calculus An example –Suppose that we want to express a logical statement (a fact) that Fred likes Elizabeth. This can be converted as: –Likes(Fred, Elizabeth). –In general, a relation that we would say in English as: Subject  Verb  Object, can be converted into a logical statement as: Verb(Subject, Object), or more generally as: –Relationship(Object1, Object2). –The relationship is called a predicate and the objects that are related are called arguments or parameters.

7 First-order predicate calculus Variable: A symbol that represents an unspecified object, meaning that it can represent different objects at different times of the computation logic. For example, integer(X) Function: A term that represents a predefined computation. It can be used to express the derivation of another predicate. For example, integer(X)  integer(successor(X)).

8 First-order predicate calculus Connector : A symbol that connects two or more terms (literals). In the following table, the names, symbols, examples and the meanings associated with the logical connectives of the predicate calculus are outlined. namesymbolexamplemeaning conjunction  x  yx and y disjunction  x  yx or y equivalence  x  yx is equivalent to y right implication  x  yx implies y left implication  x  yy implies x right-left implication  x  yx implies y and y implies x negation  xnegation of x

9 First-order predicate calculus Quantifier: A symbol that introduces variables such as  called for all known as universal quantifier and  called there exists known as existential quantifier. For example,  X(man(X)  human(X)) means that, for all x such that x is a man, then x is a human. And  X(human(X)  man(X)) means that, there exists an X such that if X is a human then x is a man. Because the scope of the quantifiers is the variables in which they are attached, one can use the parentheses in order to extend the scope of the universal and existential quantifiers.

10 First-order predicate calculus Punctuation: A symbol that is used in the structure of predicates and logic statements such as left and right parentheses, comma and the period.

11 First-order predicate calculus Precedence: Evaluation of operators in a precise sequence determined by the rules of operator precedence as outlined below from high to low level of priority. operatoroperationorder of evaluation (precedence) ,  universal quantifierfrom left to right existential quantifier  negationfrom left to right , ,  conjunctionfrom left to right disjunction equivalence , ,  right implicationfrom left to right left implication right-left implication

12 Equivalence P Q is equivalent to P Q P  Q is equivalent to  P  Q P Q is equivalent to Q P P  Q is equivalent to  Q  P P Q is equivalent to P  Q is equivalent to ( P Q ) ( Q V) (  P  Q )  (  Q  V) (P Q) means P Q  (P  Q) means  P   Q (P Q) means P Q  (P  Q) means  P   Q

13 Logical Statements We define a logical statement to be of the form (Q1 or Q2 or … or Qk)  (P1 and P2 and … and Pn) where the P’s and Q’s are predicates also known as literals or terms. The arrow pointing to the right is to be understood as meaning "implies or drives", and the logic statement is to be understood as meaning that Q1, or Q2, and so on, imply P1, and P2, and so on.

14 Logical Statements Horn clause: A restricted kind of logical statement. –Headed Horn clause: if the left-hand side is a single term such as: –mammals(human) legs(human, 2). –mammals(human)  legs(human, 2). –Headless Horn clause: if the left-hand side is empty such as: –arms(human, 2). Therefore, for the general form of a Horn clause such as Q (P1 and P2 and … and Pn) Q  (P1 and P2 and … and Pn) Or (P1 and P2 and … and Pn)  Q means that, Q is true if all the P’s are true. Q is called the head of the clause (only one literal as the head of the clause), and the (P1 and P2 and … and Pn) is the body of the clause. When logical statements are used for resolution, only Horn clauses, which simplify the resolution process are used.

15 Resolution In a logic programming system there is no indication about how a particular goal might be proved from a given set of predicates. A typical inference rule can be stated as: from the logical statements x  y and y  z, one can derive the logical statement x  z. In other words, an inference rule allows you to construct a new set of logical statements that are proved true from a given set of original logical statements that are already true. The essence of a logic program is that from a collection of logical statements, known as facts and rules, a desired fact, known as query or goal, might be proved to be true by application of the inference rule.

16 Resolution Resolution is a sequence of steps that deduction system chooses to derive a new logical statement. The resolution can be written symbolically in three equivalent ways as shown below. P or Q  Q  P(P or Q) and  P  P  P QQQ We say that Q is a logical consequences of logical statements if whenever all of the logical statements are interpreted as TRUE, so is Q.

17 Resolution P P1, P2, …, Pn-1, Pn P  P1, P2, …, Pn-1, Pn Q Q1, Q2, …, Qm-1, Qm Q  Q1, Q2, …, Qm-1, Qm If p matches Qm, Q Q1, Q2, …, Qm-1, P1, P2, …, Pn-1, Pn Q  Q1, Q2, …, Qm-1, P1, P2, …, Pn-1, Pn That is Q,P Q1, Q2, …, Qm-1, Qm, P1, P2, …, Pn-1, Pn Q,P  Q1, Q2, …, Qm-1, Qm, P1, P2, …, Pn-1, Pn

18 Example 1 Suppose we have a set of logical statements as the following: 1.not commited_crime or not got_caught or in_jail 2.got_caught or not in_jail 3.commited_crime 4.got_caught 5.not in_jail

19 Example 1 Using the resolution principles as the following, new logical statements are deduced. (1)not commited_crime or not got_caught or in_jail (3)commited_crime (6)not got_caught or in_jail(new clause) (4)got_caught (7)in_jail(new clause) (5)not in_jail FALSE

20 Example 1 By adding new generated logical statements the set of logical statements are: (1)not commited_crime or not got_caught or in_jail (2)got_caught or not in_jail (6)not got_caught or in_jail (3)commited_crime (4)got_caught (5)not in_jail (7)in_jail

21 Example 1 This listing of logical statements shows an inconsistency by including the two logical statements, (5) and (7), because in which no one can be both in jail and not in jail at the same time. This list of logical statements shows its resolution to FALSE. In general, the resolution strategy is to search through a set of logical statements, looking for two logical statements, one of which contains a term X and the other contains  X. Thus X  Xresolves to FALSE

22 Example 2 We need to show that happy(tom) is a logical consequences of the set of logical statements, (1) through (7). (1)happy(tom) or  watching(tom, football) or  has(tom, supplies) (2)has(tom, supplies) or  has(tom, beer) or  has(tom, pretzels) (3)watching(tom, football) or  is_on(tv) or  playing(cowboys) (4)is_on(tv) (5)playing(cowboys) (6)has(tom, beer) (7)has(tom, pretzels)

23 Example 2 We know from the resolution strategy that if: (8)  happy(tom) which is the negation of the query, and that (1)&(2)& … &(8) resolves to FALSE, then the query happy(tom) is TRUE. Now, let’s look at the resolution steps.

24 Example 2 (8)  happy(tom) (1)happy(tom) or  watching(tom, football) or  has(tom, supplies) (9)  watching(tom, football) or  has(tom, supplies) (3)watching(tom, football) or  is_on(tv) or  playing(cowboys) (10)  has(tom, supplies) or  is_on(tv) or  playing(cowboys) (2)has(tom, supplies) or  has(tom, beer) or  has(tom, pretzels) (11)  is_on(tv) or  playing(cowboys) or  has(tom, beer) or  has(tom, pretzels)

25 Example 2 (11)  is_on(tv) or  playing(cowboys) or  has(tom, beer) or  has(tom, pretzels) (4)is_on(tv) (12)  playing(cowboys) or  has(tom, beer) or  has(tom, pretzels) (5)playing(cowboys) (13)  has(tom, beer) or  has(tom, pretzels)

26 Example 2 (13)  has(tom, beer) or  has(tom, pretzels) (6)has(tom, beer) (14)  has(tom, pretzels) (7)has(tom, pretzels) FALSE Since we have derived FALSE from  happy(tom) and (1) through (7), we may conclude that Tom is indeed happy.

27 To be continued Unification Search Structures ApplicationsProlog

28 Unification Unification is a process of pattern matching to make terms identical in order to be discarded from both sides. Example: Suppose there is a set of facts as the following: –likes(Mary, food). –likes(Mary, milk). –likes(Mahsa, milk). –likes(Mahsa, Mary). Conjunctions and the use of variables can be combined in order to form the queries.

29 Example Assume we ask the following question from the logic system: Is there anything that Mahsa and Mary both like? This question contains two goals: First, find out if there is some X (a variable) that Mary likes. Second, find out if Mahsa likes whatever X is. Two goals might be written as a conjunction of two subgoals like this: ?-likes(Mary, X), likes(Mahsa, X).

30 Example ?-likes(Mary, X), likes(Mahsa, X). likes(Mary, food). likes(Mary, milk). likes(Mahsa, milk). likes(Mahsa, Mary). likes(Mahsa, milk). likes(Mahsa, Mary). Resolution: first goal is succeeded. Unification: variable X is instantiated to food. Next: attempt to satisfy the second goal.

31 Example ?-likes(Mary, food), likes(Mahsa, food). likes(Mary, food). likes(Mary, milk). likes(Mahsa, milk). likes(Mahsa, Mary). likes(Mahsa, milk). likes(Mahsa, Mary). Resolution: second goal is failed, because there is no term to be matched. Next: attempt to re-satisfy the first goal.

32 Example ?-likes(Mary, X), likes(Mahsa, X). likes(Mary, food). likes(Mary, milk). likes(Mahsa, milk). likes(Mahsa, Mary). likes(Mahsa, milk). likes(Mahsa, Mary). Resolution: first goal is succeeded. Unification: variable X is instantiated to milk. Next: attempt to satisfy the second goal.

33 Example likes(Mary, milk), likes(Mahsa, milk). likes(Mary, food). likes(Mary, milk). likes(Mary, food). likes(Mary, milk). likes(Mahsa, milk). likes(Mahsa, Mary). likes(Mahsa, milk). likes(Mahsa, Mary). Resolution: second goal is succeeded. Unification: system notifies you of success with X = milk. Next: waits for a reply. The answer of this query indicates that, Mahsa and Mary both like milk.

34 Figure 10.1 The resolution and verification process for the query likes (Mary, X), likes (Mahsa, X) © 2003 Brooks/Cole Publishing / Thomson Learning™

35 Logical program development Logical Analysis: Correctness that the correct logical statements are introduced and produced Control Analysis: the efficiency when it is performed entirely by the logic programming control system The difference of Resolution and Unification –The result of resolution is FALSE or True –The result of unification is Fail or some facts

36 Search Structure Depth-first (DFS) Of Breadth- first (BFS)

37 Example married(John)<= wife(Mary, John), husband(John, Mary) married(John)<= husband(John, Mary) wife(Mary, John) husband(John, Mary)

38 Figure 10.2 The search space for the query married(John)

39 Backward and Forward Search Backward –Phase 1: A given goal is reduced to simple sub-goals corresponding to basic facts or procedures. The process is repeated until the goal is represented as a tree having only simple sub-goals corresponding to basic facts or procedures as leaves. Such tree is called a tree on inference or resolution tree (see example below). –Phase 2: Searching for values for (Verifying) the simple sub-goals and putting them together to form the response. This process is actually called a backtracking. Forward –Counterpart for the Backward Chaining is called Forward Chaining Procedure. The Forward Chaining Procedure deals with putting basic facts together to infer all possible new facts.

40 Example of backward search Basic Facts: –B1(2). B1(3). B1(4). –B21(1). B21(2). B21(3). –B22(1). B22(3). B22(9). –B3(1). B3(2). B3(5). B3(36). Rules of Inference: –P(x) <= B1(x) –P(x) <= P2 (x), B3(x) –P2(x) <= B21(x), B22(x) Verifier Goal: ? P(1) true

42 Example of forward search Basic Facts: –B11(1). B11(2). B11(3). B11(4). –B12(3). B12(4). B12(5). B12(6). –B21(1). B21(2). B21(3). B21(4). –B22(1). B22(2). B22(3). B22(5). Rules of Inference: –P(x) <= P1(x). –P(x) <= P2(x) –P1(x) <= B11(x), B12(x) –P2(x) <= B21(x), B22(x) P(1), P(2), P(3), P(4) P1(3), P1(4)P2(1),p2(2),P2(3)

43

44

45 Application of Logic Programming Production systems –System State –Production Rules –Control system

46 Figure 10.3 Computation model of a production system © 2003 Brooks/Cole Publishing / Thomson Learning™

47 Reasoning systems A reasoning system consists of –Agents –Communication paths Reasoning: a process by which new information is extracted from a knowledge base. Knowledge base: only a small portion of the knowledge is stated explicitly and more knowledge could be made explicit via an inference mechanism.

48 Features Modularity –The system maintains a collection of modules rather than one huge one. Reliability –The problem solving can continue even if one of the agents fails. Heterogeneous unification –Problem-solving techniques and knowledge representation may vary for different parts of a reasoning problem.

49 Prolog Platform Installation

50 Summary First order predicate calculus and Horn clause ResolutionUnification Search structure Application