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

cs61a lecture 39
SMART_READER_LITE
LIVE PREVIEW

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,


slide-1
SLIDE 1

CS61A Lecture 39

Amir Kamil UC Berkeley April 22, 2013

slide-2
SLIDE 2

 HW12 due Wednesday  Scheme project, contest due next Monday

Announcements

slide-3
SLIDE 3

Databases

slide-4
SLIDE 4

Databases

A database is a collection of records (tuples) and an interface for adding, editing, and retrieving records

slide-5
SLIDE 5

Databases

A database is a collection of records (tuples) and an interface for adding, editing, and retrieving records The Structured Query Language (SQL) is perhaps the most widely used programming language on Earth

slide-6
SLIDE 6

Databases

A database is a collection of records (tuples) and an interface for adding, editing, and retrieving records The Structured Query Language (SQL) is perhaps the most widely used programming language on Earth SELECT * FROM toy_info WHERE color='yellow';

slide-7
SLIDE 7

Databases

A database is a collection of records (tuples) and an interface for adding, editing, and retrieving records The Structured Query Language (SQL) is perhaps the most widely used programming language on Earth SELECT * FROM toy_info WHERE color='yellow';

http://www.headfirstlabs.com/sql_hands_on/

slide-8
SLIDE 8

Databases

A database is a collection of records (tuples) and an interface for adding, editing, and retrieving records The Structured Query Language (SQL) is perhaps the most widely used programming language on Earth SELECT * FROM toy_info WHERE color='yellow'; SQL is an example of a declarative programming language.

http://www.headfirstlabs.com/sql_hands_on/

slide-9
SLIDE 9

Databases

A database is a collection of records (tuples) and an interface for adding, editing, and retrieving records The Structured Query Language (SQL) is perhaps the most widely used programming language on Earth SELECT * FROM toy_info WHERE color='yellow'; SQL is an example of a declarative programming language. It separates what to compute from how it is computed

http://www.headfirstlabs.com/sql_hands_on/

slide-10
SLIDE 10

Databases

A database is a collection of records (tuples) and an interface for adding, editing, and retrieving records The Structured Query Language (SQL) is perhaps the most widely used programming language on Earth SELECT * FROM toy_info WHERE color='yellow'; SQL is an example of a declarative programming language. It separates what to compute from how it is computed The language interpreter is free to compute the result in any way it deems appropriate

http://www.headfirstlabs.com/sql_hands_on/

slide-11
SLIDE 11

Declarative Programming

slide-12
SLIDE 12

Declarative Programming

The main characteristics of declarative languages:

slide-13
SLIDE 13

Declarative Programming

The main characteristics of declarative languages:

  • A "program" is a description of the desired solution
slide-14
SLIDE 14

Declarative Programming

The main characteristics of declarative languages:

  • A "program" is a description of the desired solution
  • The interpreter figures out how to generate such a solution
slide-15
SLIDE 15

Declarative Programming

The main characteristics of declarative languages:

  • A "program" is a description of the desired solution
  • The interpreter figures out how to generate such a solution

By contrast, in procedural languages such as Python & Scheme:

slide-16
SLIDE 16

Declarative Programming

The main characteristics of declarative languages:

  • A "program" is a description of the desired solution
  • The interpreter figures out how to generate such a solution

By contrast, in procedural languages such as Python & Scheme:

  • A "program" is a description of procedures
slide-17
SLIDE 17

Declarative Programming

The main characteristics of declarative languages:

  • A "program" is a description of the desired solution
  • The interpreter figures out how to generate such a solution

By contrast, in procedural languages such as Python & Scheme:

  • A "program" is a description of procedures
  • The interpreter carries out execution/evaluation rules
slide-18
SLIDE 18

Declarative Programming

The main characteristics of declarative languages:

  • A "program" is a description of the desired solution
  • The interpreter figures out how to generate such a solution

By contrast, in procedural languages such as Python & Scheme:

  • A "program" is a description of procedures
  • The interpreter carries out execution/evaluation rules

Building a universal problem solver is a difficult task

slide-19
SLIDE 19

Declarative Programming

The main characteristics of declarative languages:

  • A "program" is a description of the desired solution
  • The interpreter figures out how to generate such a solution

By contrast, in procedural languages such as Python & Scheme:

  • A "program" is a description of procedures
  • The interpreter carries out execution/evaluation rules

Building a universal problem solver is a difficult task Declarative programming languages compromise by solving only a subset of all problems

slide-20
SLIDE 20

Declarative Programming

The main characteristics of declarative languages:

  • A "program" is a description of the desired solution
  • The interpreter figures out how to generate such a solution

By contrast, in procedural languages such as Python & Scheme:

  • A "program" is a description of procedures
  • The interpreter carries out execution/evaluation rules

Building a universal problem solver is a difficult task Declarative programming languages compromise by solving only a subset of all problems They typically trade off data scale for problem complexity

slide-21
SLIDE 21

The Logic Language

slide-22
SLIDE 22

The Logic Language

The Logic language is invented for this course

slide-23
SLIDE 23

The Logic Language

The Logic language is invented for this course

  • Based on the Scheme project & ideas from Prolog
slide-24
SLIDE 24

The Logic Language

The Logic language is invented for this course

  • Based on the Scheme project & ideas from Prolog
  • Expressions are facts or queries, which contain relations
slide-25
SLIDE 25

The Logic Language

The Logic language is invented for this course

  • Based on the Scheme project & ideas from Prolog
  • Expressions are facts or queries, which contain relations
  • Expressions and relations are both Scheme lists
slide-26
SLIDE 26

The Logic Language

The Logic language is invented for this course

  • Based on the Scheme project & ideas from Prolog
  • Expressions are facts or queries, which contain relations
  • Expressions and relations are both Scheme lists
  • For example, (likes Amir dogs) is a relation
slide-27
SLIDE 27

The Logic Language

The Logic language is invented for this course

  • Based on the Scheme project & ideas from Prolog
  • Expressions are facts or queries, which contain relations
  • Expressions and relations are both Scheme lists
  • For example, (likes Amir dogs) is a relation
  • Implementation fits on a single sheet of paper (next lecture)
slide-28
SLIDE 28

The Logic Language

The Logic language is invented for this course

  • Based on the Scheme project & ideas from Prolog
  • Expressions are facts or queries, which contain relations
  • Expressions and relations are both Scheme lists
  • For example, (likes Amir dogs) is a relation
  • Implementation fits on a single sheet of paper (next lecture)

Today’s theme:

slide-29
SLIDE 29

The Logic Language

The Logic language is invented for this course

  • Based on the Scheme project & ideas from Prolog
  • Expressions are facts or queries, which contain relations
  • Expressions and relations are both Scheme lists
  • For example, (likes Amir dogs) is a relation
  • Implementation fits on a single sheet of paper (next lecture)

Today’s theme:

http://awhimsicalbohemian.typepad.com/.a/6a00e5538b84f3883301538dfa8f19970b‐800wi

slide-30
SLIDE 30

Simple Facts

slide-31
SLIDE 31

Simple Facts

A simple fact expression in the Logic language declares a relation to be true

slide-32
SLIDE 32

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

slide-33
SLIDE 33

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:

slide-34
SLIDE 34

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
slide-35
SLIDE 35

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

slide-36
SLIDE 36

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))

slide-37
SLIDE 37

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))

D Herbert

slide-38
SLIDE 38

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))

D Herbert

slide-39
SLIDE 39

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

slide-40
SLIDE 40

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

slide-41
SLIDE 41

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

slide-42
SLIDE 42

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)) logic> (fact (parent fillmore abraham))

F A D B C Herbert

slide-43
SLIDE 43

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)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano))

F A D B C Herbert

slide-44
SLIDE 44

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)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover))

F A D G B C Herbert

slide-45
SLIDE 45

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)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore))

E F A D G B C Herbert

slide-46
SLIDE 46

Relations are Not Procedure Calls

slide-47
SLIDE 47

Relations are Not Procedure Calls

In Logic, a relation is not a call expression

slide-48
SLIDE 48

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
slide-49
SLIDE 49

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
slide-50
SLIDE 50

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:

slide-51
SLIDE 51

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)

slide-52
SLIDE 52

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:

slide-53
SLIDE 53

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 _)

slide-54
SLIDE 54

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)

slide-55
SLIDE 55

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)

slide-56
SLIDE 56

Queries

E F A D G B C Herbert

slide-57
SLIDE 57

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

slide-58
SLIDE 58

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

slide-59
SLIDE 59

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore))

E F A D G B C Herbert

slide-60
SLIDE 60

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent abraham ?child))

E F A D G B C Herbert

slide-61
SLIDE 61

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent abraham ?child)) Success!

E F A D G B C Herbert

slide-62
SLIDE 62

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent abraham ?child)) Success! child: barack

E F A D G B C Herbert

slide-63
SLIDE 63

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent abraham ?child)) Success! child: barack child: clinton

E F A D G B C Herbert

slide-64
SLIDE 64

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent abraham ?child)) Success! child: barack child: clinton

E F A D G B C Herbert

slide-65
SLIDE 65

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore))

E F A D G B C Herbert

slide-66
SLIDE 66

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent ?who barack)

E F A D G B C Herbert

slide-67
SLIDE 67

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent ?who barack) (parent ?who clinton))

E F A D G B C Herbert

slide-68
SLIDE 68

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent ?who barack) (parent ?who clinton)) Success!

E F A D G B C Herbert

slide-69
SLIDE 69

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)) logic> (fact (parent abraham clinton)) logic> (fact (parent fillmore abraham)) logic> (fact (parent fillmore delano)) logic> (fact (parent fillmore grover)) logic> (fact (parent eisenhower fillmore)) logic> (query (parent ?who barack) (parent ?who clinton)) Success! who: abraham

E F A D G B C Herbert

slide-70
SLIDE 70

Compound Facts

E F A D G B C Herbert

slide-71
SLIDE 71

Compound Facts

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

slide-72
SLIDE 72

Compound Facts

A fact can include multiple relations and variables as well

(fact <conclusion> <hypothesis0> <hypothesis1> ... <hypothesisN>)

E F A D G B C Herbert

slide-73
SLIDE 73

Compound Facts

A fact can include multiple relations and variables as well

(fact <conclusion> <hypothesis0> <hypothesis1> ... <hypothesisN>)

Means <conclusion> is true if all <hypothesisK> are true

hesisN>)

E F A D G B C Herbert

slide-74
SLIDE 74

Compound Facts

A fact can include multiple relations and variables as well

(fact <conclusion> <hypothesis0> <hypothesis1> ... <hypothesisN>)

Means <conclusion> is true if all <hypothesisK> are true

hesisN>) logic> (fact (child ?c ?p) (parent ?p ?c))

E F A D G B C Herbert

slide-75
SLIDE 75

Compound Facts

A fact can include multiple relations and variables as well

(fact <conclusion> <hypothesis0> <hypothesis1> ... <hypothesisN>)

Means <conclusion> is true if all <hypothesisK> are true

hesisN>) logic> (fact (child ?c ?p) (parent ?p ?c)) logic> (query (child herbert delano)) Success!

E F A D G B C Herbert

slide-76
SLIDE 76

Compound Facts

A fact can include multiple relations and variables as well

(fact <conclusion> <hypothesis0> <hypothesis1> ... <hypothesisN>)

Means <conclusion> is true if all <hypothesisK> are true

hesisN>) logic> (fact (child ?c ?p) (parent ?p ?c)) logic> (query (child herbert delano)) Success! logic> (query (child eisenhower clinton)) Failure.

E F A D G B C Herbert

slide-77
SLIDE 77

Compound Facts

A fact can include multiple relations and variables as well

(fact <conclusion> <hypothesis0> <hypothesis1> ... <hypothesisN>)

Means <conclusion> is true if all <hypothesisK> are true

hesisN>) logic> (fact (child ?c ?p) (parent ?p ?c)) logic> (query (child herbert delano)) Success! logic> (query (child eisenhower clinton)) Failure. logic> (query (child ?child fillmore)) Success! child: abraham child: delano child: grover

E F A D G B C Herbert

slide-78
SLIDE 78

Recursive Facts

E F A D G B C Herbert

slide-79
SLIDE 79

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

slide-80
SLIDE 80

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

slide-81
SLIDE 81

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)) Success! a: delano a: fillmore a: eisenhower

E F A D G B C Herbert

slide-82
SLIDE 82

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)) Success! a: delano a: fillmore a: eisenhower logic> (query (ancestor ?a barack) (ancestor ?a herbert)) Success! a: fillmore a: eisenhower

E F A D G B C Herbert

slide-83
SLIDE 83

Searching to Satisfy Queries

slide-84
SLIDE 84

Searching to Satisfy Queries

The Logic interpreter performs a search in the space of relations for each query to find a satisfying assignment

slide-85
SLIDE 85

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

slide-86
SLIDE 86

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

slide-87
SLIDE 87

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))

slide-88
SLIDE 88

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))

slide-89
SLIDE 89

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

slide-90
SLIDE 90

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

slide-91
SLIDE 91

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

slide-92
SLIDE 92

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

slide-93
SLIDE 93

Hierarchical Facts

slide-94
SLIDE 94

Hierarchical Facts

Relations can contain relations in addition to atoms

slide-95
SLIDE 95

Hierarchical Facts

Relations can contain relations in addition to atoms

logic> (fact (dog (name abraham) (color white)))

slide-96
SLIDE 96

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)))

slide-97
SLIDE 97

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

slide-98
SLIDE 98

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)))

Variables can refer to atoms or relations E F A D G B C H

slide-99
SLIDE 99

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)))

Variables can refer to atoms or relations

logic> (query (dog (name clinton) (color ?color))) Success! color: white

E F A D G B C H

slide-100
SLIDE 100

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)))

Variables can refer to atoms or relations

logic> (query (dog (name clinton) (color ?color))) Success! color: white logic> (query (dog (name clinton) ?info)) Success! info: (color white)

E F A D G B C H

slide-101
SLIDE 101

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)))

Variables can refer to atoms or relations

logic> (query (dog (name clinton) (color ?color))) Success! color: white logic> (query (dog (name clinton) ?info)) Success! info: (color white)

E F A D G B C H

slide-102
SLIDE 102

Example: Combining Multiple Data Sources

Which dogs have an ancestor of the same color?

E F A D G B C H

slide-103
SLIDE 103

Example: Combining Multiple Data Sources

Which dogs have an ancestor of the same color?

logic> (query (dog (name ?name) (color ?color))

E F A D G B C H

slide-104
SLIDE 104

Example: Combining Multiple Data Sources

Which dogs have an ancestor of the same color?

logic> (query (dog (name ?name) (color ?color)) (ancestor ?ancestor ?name)

E F A D G B C H

slide-105
SLIDE 105

Example: Combining Multiple Data Sources

Which dogs have an ancestor of the same color?

logic> (query (dog (name ?name) (color ?color)) (ancestor ?ancestor ?name) (dog (name ?ancestor) (color ?color)))

E F A D G B C H

slide-106
SLIDE 106

Example: Combining Multiple Data Sources

Which dogs have an ancestor of the same color?

logic> (query (dog (name ?name) (color ?color)) (ancestor ?ancestor ?name) (dog (name ?ancestor) (color ?color))) Success! name: barack color: tan ancestor: eisenhower name: clinton color: white ancestor: abraham name: grover color: tan ancestor: eisenhower name: herbert color: brown ancestor: fillmore

E F A D G B C H

slide-107
SLIDE 107

Example: Appending Lists

slide-108
SLIDE 108

Example: Appending Lists

Two lists append to form a third list if:

slide-109
SLIDE 109

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same
slide-110
SLIDE 110

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

slide-111
SLIDE 111

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c) logic> (fact (append‐to‐form () ?x ?x))

slide-112
SLIDE 112

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:

logic> (fact (append‐to‐form () ?x ?x))

slide-113
SLIDE 113

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element

logic> (fact (append‐to‐form () ?x ?x))

slide-114
SLIDE 114

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x))

slide-115
SLIDE 115

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x))

slide-116
SLIDE 116

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x))

slide-117
SLIDE 117

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x)) logic> (fact (append‐to‐form (?a . ?r) ?y (?a . ?z))

slide-118
SLIDE 118

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element
  • The rest of list 1 and all of list 2 append to form the rest of list 3

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x)) logic> (fact (append‐to‐form (?a . ?r) ?y (?a . ?z))

slide-119
SLIDE 119

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element
  • The rest of list 1 and all of list 2 append to form the rest of list 3

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x)) logic> (fact (append‐to‐form (?a . ?r) ?y (?a . ?z))

slide-120
SLIDE 120

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element
  • The rest of list 1 and all of list 2 append to form the rest of list 3

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x)) logic> (fact (append‐to‐form (?a . ?r) ?y (?a . ?z))

slide-121
SLIDE 121

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element
  • The rest of list 1 and all of list 2 append to form the rest of list 3

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x)) logic> (fact (append‐to‐form (?a . ?r) ?y (?a . ?z))

slide-122
SLIDE 122

Example: Appending Lists

Two lists append to form a third list if:

  • The first list is empty and the second and third are the same

() (a b c) (a b c)

  • Both of the following hold:
  • List 1 and 3 have the same first element
  • The rest of list 1 and all of list 2 append to form the rest of list 3

(a b c) (d e f) (a b c d e f) logic> (fact (append‐to‐form () ?x ?x)) logic> (fact (append‐to‐form (?a . ?r) ?y (?a . ?z)) (append‐to‐form ?r ?y ?z))