Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Logic Programming By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology Vishnu Institute of technology – Website: www.vishnu.edu.in Introduction • Programs are expressed in the form of symbolic logic and logical inferencing process is used to produce results. • Logic programs are declarative rather than procedural. • Programs in logic programming languages are collections of facts and rules. • Programming that uses a form of symbolic logic as a programming languages is often called logic programming. • Example of logic programming language is Prolog. Vishnu Institute of technology – Website: www.vishnu.edu.in Predicate Calculus • Predicate calculus is the basis of logic programming. • A proposition is a logical statement that may or may not be true. • Formal logic is a method for describing propositions. • Symbolic logic can be used for three basic needs of formal logic: – To express propositions – To express relationships between propositions – To describe how new propositions can be inferred from other propositions that are assumed to be true. • The form of symbolic logic that is used for logic programming is called first-order predicate calculus. Vishnu Institute of technology – Website: www.vishnu.edu.in Predicate Calculus : Propositions • The objects in propositions are represented by constants or variables. • A constant is a symbol that represents an object. • A variable is a symbol that can represent different objects at different times. • The simplest proposition is an atomic proposition which consists of compound terms. Vishnu Institute of technology – Website: www.vishnu.edu.in Predicate Calculus : Propositions (cont...) • A compound term is composed of two parts: a functor and an ordered list of parameters. • A functor is the function symbol that names the relation. • A compound term with a single parameter is a 1-tuple, one with two parameters is a 2-tuple and so on. Examples of 1-tuple and 2-tuple compound terms: man(jake) like(bob, steak) Vishnu Institute of technology – Website: www.vishnu.edu.in Predicate Calculus : Propositions (cont...) • A compound proposition have two or more atomic propositions which are connected by logical connectors, or operators. Vishnu Institute of technology – Website: www.vishnu.edu.in Predicate Calculus : Propositions (cont...) • Examples of compound propositions: a∩bƆc aϹbUc • Variables can be used in propositions but only when they are introduced by special symbols called quantifiers. Vishnu Institute of technology – Website: www.vishnu.edu.in Predicate Calculus : Clausal Form • One problem with predicate calculus is that there are too many different ways of stating propositions that have the same meaning. • A standard form for stating propositions is clausal form. • A proposition in clausal form has the following syntax: B1 U B2 U ... U Bn Ϲ A1 ∩ A2 ∩ ... ∩ Am Vishnu Institute of technology – Website: www.vishnu.edu.in Predicate Calculus : Clausal Form (cont...) • The meaning of the clausal form is: if all the A’s are true then at least one of the B’s is true. • Characteristics of clausal form: – Existential quantifiers are not required and universal quantifiers are implicit. – No operators other than conjunction and disjunction are supported. – Disjunction should appear on the left hand side and conjunction on the right hand side. Vishnu Institute of technology – Website: www.vishnu.edu.in Predicate Calculus : Clausal Form (cont...) • The right side of clausal form proposition is called the antecedent and the left side is called consequent. Ex: likes(bob, trout) Ϲ likes(bob, fish) ∩ fish(trout) Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog • Prolog was developed by Colmerauer and Roussel in 1972. • A program in Prolog is made up of several statements. • Each statement is made up of terms. • A Prolog term is a constant, a variable, or a structure. Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog (cont...) • A constant is either an atom or an integer. • Atoms are symbolic values of Prolog. • A variable is a string of letters, digits, and underscores that begins with a uppercase letter or an underscore ( _ ) . • A structure represents the atomic propositions of predicate calculus, and their form is: functor(parameter-list) Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog (cont...) • Prolog has three basic kinds of statements: – Fact statements – Rule statements – Goal statements • A fact statement is a proposition that is assumed to be true. • A fact statement is represented as a headless Horn clause. Ex: female(shelly). male(bill). father(bill, jake). mother(bill, shelly). Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog (cont...) • A rule statement specifies rules of implication between propositions. • A rule statement is represent as headed Horn clause. • The right side is the antecedent or if part and the left side is the consequent of then part. • The consequent is a single term and the antecedent can be either a single term or a conjunction. Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog (cont...) • In Prolog conjunction is specified as a comma. • General form of a Prolog rule statement is: consequence :- antecedent Ex: ancestor(mary, shelley) :- mother(mary, shelley) Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog (cont...) • In Prolog a theorem is in the form of proposition that we want the system to either prove or disprove. Such propositions are called goals or queries. • The syntax of a Prolog goal statement is same as that of a fact statement. Ex: man(fred). father(X, mike). Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog : Inferencing Process • Resolution is an inferencing process that allows inferred propositions to be computed from given propositions. • Queries are called goals. When a goal is a compound proposition, each of the facts is called a sub goal. • To prove that a goal is true, the inferencing process must find a chain of inference rules or facts in the database that connect the goal to one or more facts in the database. Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog : Inferencing Process (cont...) • For example, if Q is a goal, then either Q must be a fact in the database or the inferencing process must find a fact P1 and a sequence of propositions P2, P3, ..., Pn such that: P2 :- P1 P3 :- P2 ... Q :- Pn Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog : Inferencing Process (cont...) • There are two approaches for attempting to match a given goal to a fact in the database: – Top-down resolution or backward chaining – Bottom-up resolution or forward chaining • If the system starts with the goal and attempts to find a sequence of matching propositions that lead to some set of original facts in the database is known as top-down resolution or backward chaining. • If the system starts with the facts and rules of the database and attempts to find a sequence of matches that lead to a goal is known as bottom-up resolution or backward chaining. Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog : Inferencing Process (cont...) Example: Database: father(bob). man(X) :- father(X). Query: man(bob). Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog : Inferencing Process (cont...) • Solution search is done in one of the two ways: – Depth-first – Breadth-first • A depth-first search finds the complete sequence of propositions, a proof, for the first sub goal before working on others. • A breadth-first search works on all sub goals of a given goal in parallel. Vishnu Institute of technology – Website: www.vishnu.edu.in Prolog : Inferencing Process (cont...) • Prolog implementations use backward chaining for resolution and depth-first as its search process. Vishnu Institute of technology – Website: www.vishnu.edu.in Applications of Logic Programming • Relational Database Management Systems – RDBMS is similar logic programming. – Tables can be represented using Prolog structures and relationships between tables can be described by Prolog rules and the retrieval process is inherent in resolution operation. – The goal statements of Prolog provide the queries for the RDBMS. – One advantage of using logic programming to implement an RDBMS is that only a single language is required. – Another advantage of using logic programming to implement RDMS is that deductive capability is built in. • Expert Systems – Expert systems are computer systems designed to emulate human expertise in some particular domain. – Prolog can be used to construct expert systems. – Prolog’s facts, rules and inference mechanism can be used to implement expert systems. Vishnu Institute of technology – Website: www.vishnu.edu.in Applications of Logic Programming (cont...) – Missing from Prolog is the automatic ability of the system to query the user for additional information when it is needed. • Natural Language Processing – Natural language interfaces to computer systems can be easily implemented using logic programming languages. – For describing language syntax, logic programming is equivalent to context-free grammar. – Inferencing process (backward chaining) in logic programming is equivalent to parsing strategies. – Some kinds of semantics of natural languages can be made clear by modeling the languages with logic programming. Vishnu Institute of technology – Website: www.vishnu.edu.in