cs61a lecture 39
play

CS61A Lecture 39 Amir Kamil UC Berkeley April 22, 2013 - PowerPoint PPT Presentation

CS61A Lecture 39 Amir Kamil UC Berkeley April 22, 2013 Announcements HW12 due Wednesday Scheme project, contest due next Monday Databases Databases A database is a collection of records (tuples) and an interface for adding, editing,


  1. Simple Facts A simple fact expression in the Logic language declares a relation to be true Let's say I want to track my many dogs' ancestry Language Syntax: • A relation is a Scheme list • A fact expression is a Scheme list containing fact followed by one or more relations logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) A D B Herbert

  2. Simple Facts A simple fact expression in the Logic language declares a relation to be true Let's say I want to track my many dogs' ancestry Language Syntax: • A relation is a Scheme list • A fact expression is a Scheme list containing fact followed by one or more relations logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) logic> (fact (parent abraham clinton)) A D B Herbert

  3. Simple Facts A simple fact expression in the Logic language declares a relation to be true Let's say I want to track my many dogs' ancestry Language Syntax: • A relation is a Scheme list • A fact expression is a Scheme list containing fact followed by one or more relations logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) logic> (fact (parent abraham clinton)) A D B C Herbert

  4. Simple Facts A simple fact expression in the Logic language declares a relation to be true Let's say I want to track my many dogs' ancestry Language Syntax: • A relation is a Scheme list • A fact expression is a Scheme list containing fact followed by one or more relations logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) F logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) A D B C Herbert

  5. Simple Facts A simple fact expression in the Logic language declares a relation to be true Let's say I want to track my many dogs' ancestry Language Syntax: • A relation is a Scheme list • A fact expression is a Scheme list containing fact followed by one or more relations logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) F logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) A D logic> (fact (parent fillmore delano)) B C Herbert

  6. Simple Facts A simple fact expression in the Logic language declares a relation to be true Let's say I want to track my many dogs' ancestry Language Syntax: • A relation is a Scheme list • A fact expression is a Scheme list containing fact followed by one or more relations logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) F logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) A D G logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) B C Herbert

  7. Simple Facts A simple fact expression in the Logic language declares a relation to be true Let's say I want to track my many dogs' ancestry Language Syntax: • A relation is a Scheme list • A fact expression is a Scheme list containing fact followed by one or more relations E logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) F logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) A D G logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) B C Herbert logic> (fact (parent eisenhower fillmore))

  8. Relations are Not Procedure Calls

  9. Relations are Not Procedure Calls In Logic , a relation is not a call expression

  10. Relations are Not Procedure Calls In Logic , a relation is not a call expression • In Scheme, we write (abs -3) to call abs on -3

  11. Relations are Not Procedure Calls In Logic , a relation is not a call expression • In Scheme, we write (abs -3) to call abs on -3 • In Logic , (abs -3 3) asserts that the abs of -3 is 3

  12. Relations are Not Procedure Calls In Logic , a relation is not a call expression • In Scheme, we write (abs -3) to call abs on -3 • In Logic , (abs -3 3) asserts that the abs of -3 is 3 For example, if we wanted to assert that 1 + 2 = 3 :

  13. Relations are Not Procedure Calls In Logic , a relation is not a call expression • In Scheme, we write (abs -3) to call abs on -3 • In Logic , (abs -3 3) asserts that the abs of -3 is 3 For example, if we wanted to assert that 1 + 2 = 3 : (add 1 2 3)

  14. Relations are Not Procedure Calls In Logic , a relation is not a call expression • In Scheme, we write (abs -3) to call abs on -3 • In Logic , (abs -3 3) asserts that the abs of -3 is 3 For example, if we wanted to assert that 1 + 2 = 3 : (add 1 2 3) Why declare knowledge in this way? It will allow us to solve problems in two directions:

  15. Relations are Not Procedure Calls In Logic , a relation is not a call expression • In Scheme, we write (abs -3) to call abs on -3 • In Logic , (abs -3 3) asserts that the abs of -3 is 3 For example, if we wanted to assert that 1 + 2 = 3 : (add 1 2 3) Why declare knowledge in this way? It will allow us to solve problems in two directions: (add 1 2 _)

  16. Relations are Not Procedure Calls In Logic , a relation is not a call expression • In Scheme, we write (abs -3) to call abs on -3 • In Logic , (abs -3 3) asserts that the abs of -3 is 3 For example, if we wanted to assert that 1 + 2 = 3 : (add 1 2 3) Why declare knowledge in this way? It will allow us to solve problems in two directions: (add 1 2 _) (add _ 2 3)

  17. Relations are Not Procedure Calls In Logic , a relation is not a call expression • In Scheme, we write (abs -3) to call abs on -3 • In Logic , (abs -3 3) asserts that the abs of -3 is 3 For example, if we wanted to assert that 1 + 2 = 3 : (add 1 2 3) Why declare knowledge in this way? It will allow us to solve problems in two directions: (add 1 2 _) (add _ 2 3) (add 1 _ 3)

  18. Queries E F A D G B C Herbert

  19. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied E F A D G B C Herbert

  20. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? E F A D G B C Herbert

  21. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G B C Herbert

  22. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent abraham ?child)) B C Herbert

  23. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent abraham ?child)) Success! B C Herbert

  24. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent abraham ?child)) Success! child: barack B C Herbert

  25. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent abraham ?child)) Success! child: barack B C Herbert child: clinton

  26. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent abraham ?child)) Success! child: barack B C Herbert child: clinton

  27. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G B C Herbert

  28. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent ?who barack) B C Herbert

  29. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent ?who barack) (parent ?who clinton)) B C Herbert

  30. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent ?who barack) (parent ?who clinton)) Success! B C Herbert

  31. Queries A query contains one or more relations. The Logic interpreter returns whether (and how) they are all simultaneously satisfied Queries may contain variables: symbols starting with ? logic> (fact (parent delano herbert)) logic> (fact (parent abraham barack)) E logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) F logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) A D G logic> (query (parent ?who barack) (parent ?who clinton)) Success! B C Herbert who: abraham

  32. Compound Facts E F A D G B C Herbert

  33. Compound Facts A fact can include multiple relations and variables as well E F A D G B C Herbert

  34. Compound Facts A fact can include multiple relations and variables as well (fact <conclusion> <hypothesis 0 > <hypothesis 1 > ... <hypothesis N >) E F A D G B C Herbert

  35. Compound Facts A fact can include multiple relations and variables as well (fact <conclusion> <hypothesis 0 > <hypothesis 1 > ... <hypothesis N >) Means <conclusion> is true if a ll <hypothesi s K> are true hesis N >) E F A D G B C Herbert

  36. Compound Facts A fact can include multiple relations and variables as well (fact <conclusion> <hypothesis 0 > <hypothesis 1 > ... <hypothesis N >) Means <conclusion> is true if a ll <hypothesi s K> are true hesis N >) logic> (fact (child ?c ?p) (parent ?p ?c)) E F A D G B C Herbert

  37. Compound Facts A fact can include multiple relations and variables as well (fact <conclusion> <hypothesis 0 > <hypothesis 1 > ... <hypothesis N >) Means <conclusion> is true if a ll <hypothesi s K> are true hesis N >) logic> (fact (child ?c ?p) (parent ?p ?c)) E logic> (query (child herbert delano)) Success! F A D G B C Herbert

  38. Compound Facts A fact can include multiple relations and variables as well (fact <conclusion> <hypothesis 0 > <hypothesis 1 > ... <hypothesis N >) Means <conclusion> is true if a ll <hypothesi s K> are true hesis N >) logic> (fact (child ?c ?p) (parent ?p ?c)) E logic> (query (child herbert delano)) Success! logic> (query (child eisenhower clinton)) F Failure. A D G B C Herbert

  39. Compound Facts A fact can include multiple relations and variables as well (fact <conclusion> <hypothesis 0 > <hypothesis 1 > ... <hypothesis N >) Means <conclusion> is true if a ll <hypothesi s K> are true hesis N >) logic> (fact (child ?c ?p) (parent ?p ?c)) E logic> (query (child herbert delano)) Success! logic> (query (child eisenhower clinton)) F Failure. logic> (query (child ?child fillmore)) A D G Success! child: abraham child: delano child: grover B C Herbert

  40. Recursive Facts E F A D G B C Herbert

  41. Recursive Facts A fact is recursive if the same relation is mentioned in a hypothesis and the conclusion E F A D G B C Herbert

  42. Recursive Facts A fact is recursive if the same relation is mentioned in a hypothesis and the conclusion logic> (fact (ancestor ?a ?y) (parent ?a ?y)) logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y)) E F A D G B C Herbert

  43. Recursive Facts A fact is recursive if the same relation is mentioned in a hypothesis and the conclusion logic> (fact (ancestor ?a ?y) (parent ?a ?y)) logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y)) logic> (query (ancestor ?a herbert)) E Success! a: delano a: fillmore F a: eisenhower A D G B C Herbert

  44. Recursive Facts A fact is recursive if the same relation is mentioned in a hypothesis and the conclusion logic> (fact (ancestor ?a ?y) (parent ?a ?y)) logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y)) logic> (query (ancestor ?a herbert)) E Success! a: delano a: fillmore F a: eisenhower logic> (query (ancestor ?a barack) (ancestor ?a herbert)) A D G Success! a: fillmore a: eisenhower B C Herbert

  45. Searching to Satisfy Queries

  46. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment

  47. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment logic> (query (ancestor ?a herbert)) Success! a: delano a: fillmore a: eisenhower

  48. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment logic> (query (ancestor ?a herbert)) Success! a: delano a: fillmore a: eisenhower

  49. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment logic> (query (ancestor ?a herbert)) Success! a: delano a: fillmore a: eisenhower logic> (fact (parent delano herbert)) logic> (fact (parent fillmore delano))

  50. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment logic> (query (ancestor ?a herbert)) Success! a: delano a: fillmore a: eisenhower logic> (fact (parent delano herbert)) logic> (fact (parent fillmore delano)) logic> (fact (ancestor ?a ?y) (parent ?a ?y)) logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y))

  51. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment logic> (query (ancestor ?a herbert)) Success! a: delano a: fillmore a: eisenhower logic> (fact (parent delano herbert)) logic> (fact (parent fillmore delano)) logic> (fact (ancestor ?a ?y) (parent ?a ?y)) logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y)) (parent delano herbert) ; (1), a simple fact

  52. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment logic> (query (ancestor ?a herbert)) Success! a: delano a: fillmore a: eisenhower logic> (fact (parent delano herbert)) logic> (fact (parent fillmore delano)) logic> (fact (ancestor ?a ?y) (parent ?a ?y)) logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y)) (parent delano herbert) ; (1), a simple fact (ancestor delano herbert) ; (2), from (1) and the 1st ancestor fact

  53. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment logic> (query (ancestor ?a herbert)) Success! a: delano a: fillmore a: eisenhower logic> (fact (parent delano herbert)) logic> (fact (parent fillmore delano)) logic> (fact (ancestor ?a ?y) (parent ?a ?y)) logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y)) (parent delano herbert) ; (1), a simple fact (ancestor delano herbert) ; (2), from (1) and the 1st ancestor fact (parent fillmore delano) ; (3), a simple fact

  54. Searching to Satisfy Queries The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment logic> (query (ancestor ?a herbert)) Success! a: delano a: fillmore a: eisenhower logic> (fact (parent delano herbert)) logic> (fact (parent fillmore delano)) logic> (fact (ancestor ?a ?y) (parent ?a ?y)) logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y)) (parent delano herbert) ; (1), a simple fact (ancestor delano herbert) ; (2), from (1) and the 1st ancestor fact (parent fillmore delano) ; (3), a simple fact (ancestor fillmore herbert) ; (4), from (2), (3), & the 2nd ancestor fact

  55. Hierarchical Facts

  56. Hierarchical Facts Relations can contain relations in addition to atoms

  57. Hierarchical Facts Relations can contain relations in addition to atoms logic> (fact (dog (name abraham) (color white)))

  58. Hierarchical Facts Relations can contain relations in addition to atoms logic> (fact (dog (name abraham) (color white))) logic> (fact (dog (name barack) (color tan))) logic> (fact (dog (name clinton) (color white))) logic> (fact (dog (name delano) (color white))) logic> (fact (dog (name eisenhower) (color tan))) logic> (fact (dog (name fillmore) (color brown))) logic> (fact (dog (name grover) (color tan))) logic> (fact (dog (name herbert) (color brown)))

  59. Hierarchical Facts Relations can contain relations in addition to atoms logic> (fact (dog (name abraham) (color white))) logic> (fact (dog (name barack) (color tan))) logic> (fact (dog (name clinton) (color white))) logic> (fact (dog (name delano) (color white))) logic> (fact (dog (name eisenhower) (color tan))) logic> (fact (dog (name fillmore) (color brown))) logic> (fact (dog (name grover) (color tan))) logic> (fact (dog (name herbert) (color brown))) E F A D G B C H

  60. Hierarchical Facts Relations can contain relations in addition to atoms logic> (fact (dog (name abraham) (color white))) logic> (fact (dog (name barack) (color tan))) logic> (fact (dog (name clinton) (color white))) logic> (fact (dog (name delano) (color white))) logic> (fact (dog (name eisenhower) (color tan))) logic> (fact (dog (name fillmore) (color brown))) logic> (fact (dog (name grover) (color tan))) logic> (fact (dog (name herbert) (color brown))) E Variables can refer to atoms or relations F A D G B C H

  61. Hierarchical Facts Relations can contain relations in addition to atoms logic> (fact (dog (name abraham) (color white))) logic> (fact (dog (name barack) (color tan))) logic> (fact (dog (name clinton) (color white))) logic> (fact (dog (name delano) (color white))) logic> (fact (dog (name eisenhower) (color tan))) logic> (fact (dog (name fillmore) (color brown))) logic> (fact (dog (name grover) (color tan))) logic> (fact (dog (name herbert) (color brown))) E Variables can refer to atoms or relations F logic> (query (dog (name clinton) (color ?color))) Success! color: white A D G B C H

  62. Hierarchical Facts Relations can contain relations in addition to atoms logic> (fact (dog (name abraham) (color white))) logic> (fact (dog (name barack) (color tan))) logic> (fact (dog (name clinton) (color white))) logic> (fact (dog (name delano) (color white))) logic> (fact (dog (name eisenhower) (color tan))) logic> (fact (dog (name fillmore) (color brown))) logic> (fact (dog (name grover) (color tan))) logic> (fact (dog (name herbert) (color brown))) E Variables can refer to atoms or relations F logic> (query (dog (name clinton) (color ?color))) Success! color: white A D G logic> (query (dog (name clinton) ?info)) Success! B C H info: (color white)

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend