1 / 80

Introduction to Logic Programming and Predicate Calculus

Explore the fundamental concepts of logic programming and predicate calculus, including symbolic logic, proposition, predicate calculus, compound propositions, quantifiers, and clausal forms.

Download Presentation

Introduction to Logic Programming and Predicate Calculus

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lectures 3,4 PROLOG LOGic PROgramming

  2. Logic: what is it? • Philosophical logic • fundamental questions • Mathematical logic • theory of correct reasoning • Computational logic • effectiveness of reasoning • Language of scientific thinking

  3. Logic Programming • Logic programming uses a form of symbolic logic and a logical inference process • Languages based on symbolic logic are called logic programming languages or declarative languages • Prolog is the most widely used logic language

  4. Predicate Calculus • Formal logic is the basis for logic programming • Key Points • Proposition: • a logical statement that may or may not be true • Symbolic logic used for three purposes • express propositions • express the relationships between propositions • describe how new propositions may be inferred • Predicate calculus is the form of symbolic logic used for logic programming

  5. Propositions

  6. Atomic propositions • Objects in logic programming propositions are • Constants: symbols that represent an object • Variables: symbols that can represent different objects at different times • Atomic propositions are the simplest propositions and consist of compound terms • Compound term: an element of a mathematical relation, written in form of function notation, which is an element of the tabular definition of a function

  7. Compound terms • Compound term has two parts • Functor: symbol that names the relation • An ordered list of parameters • Compound term with a single parameter is called a 1-tuple; with two – a 2-tuple, etc. • Example: man (jake) {jake} is a 1-tuple in relation man like (bob, steak) {bob, steak} is a 2-tuple in like

  8. Facts and queries • Simple terms in propositions – man, jake, bob, and steak – are constants • These propositions have no intrinsic semantics • like (bob, steak) could mean several things • Propositions are stated in two modes • Fact: one in which the proposition is defined to be true • Query: one in which the truth of the proposition is to be determined

  9. Logical operators

  10. Compound propositions • Compound proposition examples: a  b  c a  b  d equivalent to (a ( b))  d • Precedence of logical connectors:  highest precedence , ,  next ,  lowest precedence

  11. Quantifiers • Variables may appear in propositions – only when introduced by symbols called quantifiers • Note: The period separates the variable from the proposition

  12. Quantifiers • Examples of propositions with quantifiers • X.(woman(X)  human(X)) For any value of X, if X is a woman, then X is human • X.(mother(mary, X)  male (X)) There exists a value of X, such that mary is the mother of X and X is a male • Note: Quantifiers have a higher precedence than any of the logical operators

  13. Example of Logic Predicate Calculus • 0 is a natural number. natural (0) • 2 is a natural number. natural (2) • For all X, if X is a natural number, then so is the successor of X. X.natural (X)  natural (successor (X))

  14. Logic Statement to P.C. • A horse is a mammal. • A human is a mammal. • Mammals have four legs and no arms, or two legs and two arms. • A horse has no arms. • A human has arms. • A human has no legs.

  15. Solution:First Order Predicate Calculus • mammal (horse). • mammal (human). • X. mammal (X)  legs (X,4)  arms (X,0)  legs (X,2) arms (X,2) • arms (horse, 0). • arms (human, 2) or  arms (human, 0). • legs (human, 0).

  16. Clausal forms

  17. General statement • Redundancy is a problem with predicate calculus • there are many different ways of stating propositions that have the same meaning • not a problem for logicians • For computerized system, this is a problem • Clausal form is one standard form of propositions used for simplification: B1  B2  ...  Bn  A1  A2  ...  Am Meaning: If all As are true, then at least one B is true

  18. Characteristics • Existential quantifiers are not required • Universal quantifiers are implicit in the use of variable in the atomic propositions • Only the conjunction and disjunction operators are required • Disjunction appears on the left side of the casual form and conjunction on the right side • The left side is called the consequent • The right side is called the antecedent

  19. Examples • Proposition 1: likes (bob, trout)  likes (bob, fish)  fish (trout) • Meaning: if bob likes fish and a trout is a fish, then bob likes trout • Proposition 2: father(louis, al)  father(louis, violet)  father(al, bob)  mother(violet, bob)  grandfather(louis, bob) • Meaning: if al is bob’s father and violet is bob’s mother and louis is bob’s grandfather, then louis is either al’s father or violet’s father

  20. Resolution

  21. Proving theorems • One of the most significant breakthroughs in automatic theorem-proving was the discovery of the resolution principle by Robinson in 1965 • Resolution is an inference rule that allows inferred propositions to be computed from given propositions • Resolution was devised to be applied to propositions in clausal form

  22. Basic idea • The concept of resolution is the following: Given two propositions: P1  P2 Q1  Q2 • Suppose P1 is identical to Q2 and we rename them as T. Then T  P2 Q1  T • Since P2 implies T and T implies Q1, it is logically obvious that P2 implies Q1, that is Q1  P2

  23. Example • Consider the two propositions: older (joanne, jake)  mother (joanne, jake) wiser (joanne, jake)  older (joanne, jake) • We can conclude that wiser (joanne, jake)  mother (joanne, jake) • The mechanics of this resolution construction is one of cancellation of the common term when both left sides are combined and both right sides are combined

  24. Expanded Example • father(bob, jake)  mother(bob,jake)  parent (bob,jake) • grandfather(bob,fred)  father(bob,jake)  father(jake,fred) • Resolution process cancels common term on both the left and right sides: • mother(bob,jake)  grandfather(bob,fred)  parent (bob,jake)  father(jake,fred)

  25. Most important laws • Unification: The process of determining useful values for variables in propositions to find values for variables that allow the resolution process to succeed. • Instantiation: The temporary assigning of values to variables to allow unification. • Inconsistency detection: A critically important property of resolution is its ability to detect any inconsistency in a given set of propositions. This property allows resolution to be used to prove theorems.

  26. Horn clauses

  27. Basics • When propositions are used for resolution, only a restricted kind of clausal form can be used • Horn clauses • special kind of clausal form to simplify resolution • two forms: • single atomic proposition on the left side, or • an empty left side • left side of Horn clause is called the head • Horn clauses with left sides are called headed Horn clauses

  28. Relationships and facts • Headed Horn clauses are used to state relationships: likes(bob, trout)  likes (bob, fish)  fish(trout) • Headless Horn clauses are used to state facts: father(bob,jake) • Most propositions may be stated as Horn clauses

  29. Logic Programming

  30. Brief history • Resolution principle (Robinson 1965) • Prolog language (Colmerauer 1972) • Operational semantics (Kowalski 1974) • Prolog compiler (Warren 1977, 1983) • 5th generation project (Japan 1981--) • Constraint LP (Jaffar & Lassez 1987)

  31. Brief basics • Robert Kowalski says: Algorithm = Logic + Control • Prolog is the most popular logic programming language • A Prolog program is a collection of Horn clauses

  32. Declarative languages • Languages used for logic programming are called declarative languages • Programming with declarative languages is nonprocedural • programs do not state exactly how a result is to be computed but rather describe the form of the result • it is assumed that the computer can determine how the result is to be obtained • one needs to provide the computer with the relevant information and a method of inference for computing desirable results

  33. Important issues • Program • knowledge about the problem in the form of logical axioms • Call of the program • provide a problem description (as a logical statement) • Execution • attempt to prove the given statement (given the program) • Constructive proofs essential • can you prove sort([2,3,1], x)? • non-constructive answer: “Yes I can” • constructive answer: “Yes, with x = [1,2,3]”

  34. PROLOG

  35. Notation

  36. Example • /* simple rules for deductions */ sees(X,Y):-person(X),object(Y),open(eyes(X)),in_front_of(X,Y). sees(X,Y):- person(X),event(Y),watching(X,film_of(Y)). person(mother(nikos)). event(birthday(kostas)). event(graduation(nikos)). watching(mother(nikos),film_of(graduation(nikos))). person(kostas). open(eyes(kostas)). in_front_of(kostas,tv). object(tv). • /* questions */ /* does the mother of nikos see his graduation? */ ?-sees(mother(nikos),graduation(nikos)).

  37. General characteristics • A program uses terms such as constant symbols, variables, or functional terms • Queries may include conjunctions, disjunctions, variables, and functional terms • A program consists of a sequence of sentences, implicitly conjoined • All variables have implicit universal quantification • Prolog uses a negation as failure operator: a goal not P is assumed proved if the system fails to prove P

  38. Basic elements

  39. Terms • A Prolog term is a constant, a variable, or a structure • A constant is either an atom or an integer • Atoms are the symbolic values of Prolog • Atoms begin with a lowercase letter • Variables begin with an uppercase letter • not bound to types by declarations • binding of a value and type is an instantiation • Instantiations last only through completion of goal • Structures represent the atomic propositions of predicate calculus • form is functor (parameter list)

  40. Fact statements • Fact statements are used to construct hypotheses (database) from which new information may be inferred • Fact statements are headless Horn clauses assumed true • Examples: male(bill). female(mary). male(jake). father(bill, jake). mother(mary, jake).

  41. Rule statements • Rule statements are headed Horn clauses for constructing the database • The RHS is the antecedent (if), and the LHS is the consequent (then) • Consequent is a single term because it is a Horn clause • Conjunctions may contain multiple terms that are separated by logical ANDs denoted by commas, e.g.: female(shelley), child (shelley).

  42. Rule statements • General form of the Prolog headed Horn clause consequence_1 :- antecedent_expression • Example: ancestor(mary, shelley) :- mother(mary, shelley). • Demonstration of the use of variables: parent(X, Y) :- mother (X, Y). parent(X, Y) :- father(X, Y). grandparent(X, Z) :- parent(X, Y), parent (Y, Z). sibling(X,Y) :- mother(M,X), mother(M,Y), father(F,X), father(F,Y). universal objects are X, Y, Z, M, and F

  43. Goal statements • Because goal and some nongoal statements have the same form (headless Horn clauses), it is imperative to distinguish between the two • Interactive Prolog implementations do this by simply having two modes, indicated by different prompts: one for entering goals and one for entering fact and rule statements • Some versions of Prolog use ?- for goals

  44. Goal statements • Facts and rules are used to prove or disprove a theorem that is in the form of a proposition (called goal or query) • Syntactic form of Prolog goal statement is identical to headless Horn clauses, e.g. man (fred). to which the system will respond yes or no • Conjunctive propositions and propositions with variables are also legal goals, e.g. father ( X, mike). • When variables are present, the system identifies the instantiations of the variables that make the goal true

  45. Example • Database: likes(george,kate). likes(george,susie). likes(george,wine). likes(susie,wine). likes(kate,gin). likes(kate,susie).

  46. Example • Query: ?-likes(george,X). X = kate ; X = susie ; X = wine ; no

  47. Example • Database: likes(george,kate). likes(george,susie). likes(george,wine). likes(susie,wine). likes(kate,gin). likes(kate,susie). friends(X,Y) :- likes(X,Z), likes(Y,Z). • Query: ?- friends(george,susie) yes

  48. Inference process

  49. General scheme • Goals (queries) may be compound propositions; each of facts (structures) is called a subgoal • The inference process must find a chain of rules/facts in the database that connect the goal to one or more facts in the database • If Q is the goal, then either Q must be found as fact in the database or the inference process must find a sequence of propositions that give that result

  50. Matching • The process of proving (or satisfying) a subgoal by a proposition-matching process • Consider the goal or query: man (bob). • If the database includes the fact man(bob), the proof is trivial • If the database contains the following fact and inference father (bob). man (X) :- father (X) then Prolog would need to find these and infer the truth. This requires unification to instantiate X temporarily to bob

More Related