1 / 25

Logic

This presentation introduces the basics of first-order predicate calculus, including logical statements, axioms, and inference rules. Examples and explanations are provided to aid understanding.

faithg
Télécharger la présentation

Logic

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. Logic We begin with some preliminaries on mathematical logic: first-order predicate calculus (a formal way of expressing logical statements). 01/21/98 Reference: Programming Languages by Louden Logic Slide -1

  2. #1: “0 is a natural number” becomes natural (0). #2: “2 is a natural number” becomes natural (2). #3: “-1 is a natural number”becomes natural (-1). (false) #4: “for all x, if x is a natural number then so is the successor of x.” becomes "x, natural (x) natural (successor (x)). #1 and #4 are assumed true; they are axioms. #2 can be deduced from the axioms since 2 is the successor of the successor of 0. Assertion #3 cannot be proved from the axioms and is assumed to be false. 01/21/98 Reference: Programming Languages by Louden Logic Slide -2

  3. First-Order Predicate Calculus uses the following concepts: • Constants :numbers or names, also called atoms. • Predicates :functions that return true or false. • Functions :other functions • Variables :quantities that are not yet given a specific value 01/21/98 Reference: Programming Languages by Louden Logic Slide -3

  4. Connectives : •  (and), •  (or), •  (implies, also denoted ), •  (is implied by, also denoted ), •  (if and only if, also denoted ), •  (not) • Quantifiers : (for all),  (there exists) • Punctuation : comma, period, parentheses. 01/21/98 Reference: Programming Languages by Louden Logic Slide -4

  5. Now we can write: mammal (horse). mammal (human). x, mammal (x ) (legs (x, 4) arms (x, 0))  (legs (x, 2) arms (x, 2)). arms (horse, 0). arms (human, 0). arms (human, 2). arms(horse, 2). 01/21/98 Reference: Programming Languages by Louden Logic Slide -5

  6. We can deduce legs (horse, 4). From x, mammal (x ) (legs (x, 4) arms (x, 0))  (legs (x, 2) arms (x, 2)). And mammal (horse). And arms (horse, 0). And arms(horse, 2). • We need a systematic notation which allows us to develop automatic computerized proof system. • One successful approach is based on Horn clauses. 01/21/98 Reference: Programming Languages by Louden Logic Slide -6

  7. Alfred Horn studied a restricted form of inference rules. • Inference rules are ways of deriving or proving new statements from a list of statements. • It is not as expressive as full predicate calculus but it does handle a large number of logical statements. • Horn clauses have the form a1 a2  ... an b 01/21/98 Reference: Programming Languages by Louden Logic Slide -7

  8. a1 a2  ... an b • The left hand side consists of a conjunction (sequence of “and’s”) and there is only one conclusion. • Axioms or facts are written  b • The opposite of a fact is a query. b  01/21/98 Reference: Programming Languages by Louden Logic Slide -8

  9. When there are variables in a Horn clause that appear on both sides of the we assume that there is a “for all” for every variable at the front of the clause. • Hence (u > 0)  (v < 0) (v < u). means u, v, (u > 0)  (v < 0)  (v < u). 01/21/98 Reference: Programming Languages by Louden Logic Slide -9

  10. If there are variables that appear on the left of the  only, then we assume there is a “there exists” for all such variables. (u > z)  (z > v)  (u > v). means u, v, z (u > z)  (z > v)  (u > v). 01/21/98 Reference: Programming Languages by Louden Logic Slide -10

  11. The following example in Prolog, grandparent( X , Y ) :– parent(X , Z),parent(Z,Y). , could be interpreted as, “x is a grandparent of y if x is the parent of someone who is a parent of y.” This Prolog example translates to u, v, z , parent(u, z )  parent(z, v ) grandparent(u, v ). Rewritten as a Horn clause it has the following form: parent(u, z )  parent(z, v ) grandparent(u, v ). 01/21/98 Reference: Programming Languages by Louden Logic Slide -11

  12. In order to start an automated reasoning process, Horn clauses are written in reverse: (u > v)  (u > z )  (z > v ). grandparent(u, v )  parent(u, z )  parent(z, v ). • A query or goal is written  grandparent( x, y ). • We can have a conjunction of several queries, which form a compound query: parent(x, z ), parent(z, y ). 01/21/98 Reference: Programming Languages by Louden Logic Slide -12

  13. Now the semantic effect of procedures can be specified as one or more Horn clauses: sort(x, y)  permutation(x, y)  sorted(y). • This line specifies “sort.” “permutation” and “sorted” are a bit difficult to express but we will see how to do it in Prolog. • Next we drop the symbol  and write simply a comma. • A fact in this format is sort(empty-list, empty-list )  . 01/21/98 Reference: Programming Languages by Louden Logic Slide -13

  14. Resolution and Unification • Resolution is an efficient inference rule, attributed to Alan Robinson, now retired from Syracuse University. Given a  a1 , a2 , ... , an b  b1 , b2 , ... , bm • Unification is the process of pattern matching to make statements identical. • When a variable is set equal to a pattern the variable is said to be instantiated. 01/21/98 Reference: Programming Languages by Louden Logic Slide -14

  15. If bimatches a then we can infer b b1 , b2, ... , bi - 1 , a1 , a2 , ... , an, bi + 1 , ... , bm • If we have a goal  a and if we have a Horn clause a  a1 , a2 , ... , an then resolution replaces the original goal by  a1 , a2 , ... , an a sequence of subgoals. 01/21/98 Reference: Programming Languages by Louden Logic Slide -15

  16. Simplest case is when the goal is already a known fact: mammal(horse). Query: • mammal(horse). Using resolution, the two Horn clauses are combined mammal(horse)  mammal(horse). Canceling both sides we get: . This is regarded as a success.

  17. More complicated example: • Horn clauses: legs(x, 2)  mammal(x), arms(x, 2). legs(x, 4)  mammal(x), arms(x, 0). mammal(horse) . arms(horse, 0) . • Query: legs(horse, 4). 01/21/98 Reference: Programming Languages by Louden Logic Slide -16

  18. Applying resolution requires a match x = horse in the second Horn clause then we can substitute the query by the subgoals:  mammal(horse), arms(horse, 0). • We can resolve between this subgoal and the clause mammal(horse)  . • giving  arms(horse, 0). 01/21/98 Reference: Programming Languages by Louden Logic Slide -17

  19. Resolving with the last input Horn clause:  arms(horse, 0). arms(horse, 0) . gives  which is regarded as success. 01/21/98 Reference: Programming Languages by Louden Logic Slide -18

  20. A little extra background may help to see exactly why goals are written “a.” and why reaching “.” is regarded as success. • First recall the truth table for “is implied by:” P Q P  Q T T T T F T F T F F F T 01/21/98 Reference: Programming Languages by Louden Logic Slide -19

  21. The only case where “is implied by” is false, is when we are asserting that a false statement is implied by a true statement. • Next, we shall write facts and goals differently. A fact is always true and is therefore “implied by” T, since T cannot imply F: a T. 01/21/98 Reference: Programming Languages by Louden Logic Slide -20

  22. The next issue is that if we wanted to deduce that b is true, then we could equally show that F b. is false, since F b. is false exactly when b is true. • The inference technique using resolution and inference is to include the Horn clause F b. with the others in the program ... • and then see if there is a contradiction. • If adding this clause causes a contradiction, then b must have been true. 01/21/98 Reference: Programming Languages by Louden Logic Slide -21

  23. How do we detect a contradition? We simply add F b. and then try to deduce that F  T. which is known to be false. • This is why “.” is regarded as success. • It really means that we have arrived at F  T. If we add F  legs(horse, 4). to the set of Horn clauses. F  legs(horse, 4). must have been false, i.e. legs(horse, 4) must be true. 01/21/98 Reference: Programming Languages by Louden Logic Slide -22

  24. For example, given 1) legs(x, 2)  mammal(x), arms(x, 2). 2) legs(x, 4)  mammal(x), arms(x, 0). 3) mammal(horse) T. 4) arms(horse, 0) T. 5) F legs(horse, 4). • resolve between 2) and 5) unifying x = horse to obtain 6) F  mammal(horse), arms(horse, 0). • resolve between 3) and 6) to obtain 7) F T, arms(horse, 0). 01/21/98 Reference: Programming Languages by Louden Logic Slide -23

  25. 4) arms(horse, 0) T. 7) F T, arms(horse, 0). • resolve between 4) and 7) to obtain: 8) F  T, T. i.e. the contradiction F  T. and T, T normally written T  T is true. 01/21/98 Reference: Programming Languages by Louden Logic Slide -24

More Related