1 / 28

ICS 313: Programming Language Theory

ICS 313: Programming Language Theory. Module 14: Logic Overview. Logic 101 Review. A proposition is a logical statement that may or may not be true. Formal logic is a method for describing propositions and checking their validity. Symbolic logic is a kind of formal logic with:

Télécharger la présentation

ICS 313: Programming Language Theory

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. ICS 313:Programming Language Theory Module 14: Logic Overview

  2. Logic 101 Review • A proposition is a logical statement that may or may not be true. • Formal logic is a method for describing propositions and checking their validity. • Symbolic logic is a kind of formal logic with: • A syntax for describing propositions • A syntax for expressing relationships between propositions • A method for inferring new propositions based upon other propositions that are assumed to be true. • Predicate calculus is a form of symbolic logic used for logic programming.

  3. Propositions in predicate calculus • Represented by terms, which are either 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. • A compound term is one element of a relation, and has two parts: • functor: the function symbol that names the relation • parameters: an ordered list of terms • Examples: man(jake), like(bob, redheads)

  4. Propositions (cont.) • Propositions can be stated in two modes: • Assertion: the proposition is defined to be true • Query: the truth of the proposition is something to be determined.

  5. Compound propositions • Atomic propositions connected by logical connectives. • Examples of compound propositions: • a  b  c • a b  d

  6. Quantified variables • Variables in propositions must be quantified: • Universal quantifier: X.P • for all X, P is true • Existential quantifier: X.P • there exists an X such that P is true • Examples: • X . (woman (X)  human(X)) • X . (mother (mary, X)  male(X))

  7. Clausal form • Predicate calculus allows multiple representations for the same proposition. • Clausal form is one standard representation for all propositions. • Clausal form has the following structure: • B1  B2  ... Bn  A1  A2  ... An • If all of the A’s are true, then at least one B is true. • Example: • likes(bob, mary)  likes(bob, redhead)  redhead(mary)

  8. Properties of clausal form • Existential quantifiers are not required. • Variables are implicitly universally quantified. • No operators other than  and  needed. • Any predicate calculus proposition can be converted to clausal form algorithmically.

  9. Theorem Proving • One important use of predicate calculus is theorem proving: inferring new facts from collections of propositions. • Resolution is an inference rule that allows inferred propositions to be automatically computed from given propositions, allowing automated theorem proving. • Resolution applies to propositions in clausal form.

  10. Resolution • Suppose: • P1  P2 • Q1  Q2 • Now suppose that P1 and Q2 are identical (match), so they could be renamed T. • Then: • T  P2 • Q1  T • and therefore: Q1  P2

  11. Resolution example • If: • father(bob, jake)  mother(bob, jake)  parent(bob, jake) • grandfather(bob, fred)  father(bob, jake)  father(jake, fred) • Then: • mother(bob, jake)  grandfather(bob, fred)  parent(bob, jake)  father(jake, fred)

  12. Variables • Use of variables in propositions: • Implies that the resolution process must find values for variables to make propositions identical (match). • Finding variable values to make two propositions match is called unification. • Unification requires backtracking, since initial choice of a variable substitution may need to be undone.

  13. Resolution in automated theorem proving • Resolution detects any inconsistencies in the set of propositions • Allows use in automated theorem proving (logic programming): • Supply a set of hypotheses • Propositions defined as true • Supply the goal • The negation of the theorem to be proven • If resolution finds an inconsistency, then the theorem is true • This is proof by contradiction.

  14. Horn clauses for ATP • ATP requires a restricted kind of clausal form called ‘Horn Clauses’: • A single atomic proposition on the left side • ‘Headed Horn Clauses’ • likes(bob, mary)  likes(bob, redhead)  redhead(mary) • An empty left side • ‘Headless Horn Clauses’ • father(bob, jake)

  15. Pros and cons of resolution-based inference • Strengths of resolution/theorem proving • ‘Programmer’ supplies what to do, not how to do it. • ‘What’ is expressed in predicate calculus • ‘How’ is accomplished through resolution • Analogous to high-level program synthesis from specifications.

  16. Pros and cons (cont.) • Weaknesses of resolution/theorem proving • ‘Programmer’ supplies what to do, not how to do it. • Time required to find an inconsistency in a large set of hypotheses may be huge • Minimizing the number of unsuccessful matches, unifications, and backtracking • Automatic determination of ‘intermediate’ theorems

  17. Prolog: one flavor of logic programming • Syntax is a modified version of predicate calculus • Inferencing method is a modified version of resolution. • Terms (headless Horn clauses): • Constant, variable, structure • Analogous to simple propositions in predicate calculus

  18. Prolog (cont.) • Variables: • Not bound to types by declarations • Can be instantiated to arbitrary terms during resolution. • Take on a type dynamically (when instantiated) • Instantiations last only as long as it takes to satisfy one complete goal. • Structures: • Syntax similar to function invocation, but use more analogous to Pascal records

  19. Prolog rules • Prolog rules are headed Horn clauses • Right hand side is the if part • contains only conjunctions • Left hand side is the then part • restricted to only a single disjunction • Example: • grandparent (X, Z) :- parent (X, Y), parent (Y, Z)

  20. Prolog inferencing • Prolog queries are called goals. • When a goal is a compound proposition, each term is called a subgoal. • To prove a goal is true, Prolog must find a chain of inference rules and/or facts that connect the goal to the facts in the database.

  21. Prolog inference example • If Q is the goal, then either • Q must be found as a fact in the database, or • The inferencing process must find a sequence of propositions P1... Pn such that: • P1 :- P2 • P1 :- P2 • : : • Pn :- Q • and P1 is a fact.

  22. Forward chaining • Forward chaining • Use database to systematically generate new theorems until one matching query is found • Example: • father(bob). • man(X) :- father(X) • Given the goal: man(bob) • Under forward chaining, father(bob) is matched against father(X) to derive the new fact man(bob) in the database. • This new fact satisfies the goal.

  23. Backward chaining • Use goal to work backward to a fact • Example: • Given man(bob) as goal • Match against man(X) to create new goal: father(bob). • father(bob) goal matches pre-existing fact, thus the query is satisfied.

  24. Breadth vs. depth-first searching • How to order search when goal has multiple subgoals? • Breadth-first • Work on all subgoals in parallel • Depth-first • Find a complete sequence of propositions (a proof) for the first subgoal before working on the others.

  25. Prolog Example: Syntax of lists • Enumerated lists • [a, b, c] • [] • Lists as a head and tail • [a, b, c | []] • [a, b | [c]] • [a | [b, c]]

  26. Variables in Lists • Variables can be used to destructure lists: • ?- [H | T] = [a, b, c] • H = a • T = [b, c] • ?- [a | T] = [H, b, c] • T = [b,c] • H = a

  27. Prolog examples: append • append([],Y,Y). • append([H|X],Y,[H|Z]) :- append(X,Y,Z). • Rule 2: In order to show that A appended to B equals C, show that X appended to B equals Z, where X is the tail of A and Z is the tail of C. • ?- append([a,b],[c,d],Z). • Z = [a,b,c,d] • ?- append ([a,b],Y,[a,b,c,d]). • Y = [c,d] • ?- append (X,[d,c],[a,b,c,d]). • no

  28. end of module

More Related