+ All Categories
Home > Documents > CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A...

CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A...

Date post: 13-Jun-2021
Category:
Upload: others
View: 7 times
Download: 0 times
Share this document with a friend
194
CS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013
Transcript
Page 1: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

CS61A Lecture 40

Amir Kamil and Stephen MartinisUC Berkeley

April 24, 2013

Page 2: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

HW12 due tonight

HW13 out

Scheme project, contest due Monday

Announcements

Page 3: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

 

 

       

 

 

 

Page 4: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

 

       

 

 

 

Page 5: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

Expressions and their relations are Scheme lists

       

 

 

 

Page 6: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

Expressions and their relations are Scheme lists

logic> (fact (parent eisenhower fillmore))logic> (fact (parent fillmore abraham))logic> (fact (parent abraham clinton))    

 

 

 

Page 7: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

Expressions and their relations are Scheme lists

logic> (fact (parent eisenhower fillmore))logic> (fact (parent fillmore abraham))logic> (fact (parent abraham clinton))logic> (fact (ancestor ?a ?y) (parent ?a ?y))logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y))  

 

 

 

Page 8: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

Expressions and their relations are Scheme lists

logic> (fact (parent eisenhower fillmore))logic> (fact (parent fillmore abraham))logic> (fact (parent abraham clinton))logic> (fact (ancestor ?a ?y) (parent ?a ?y))logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y))logic> (query (ancestor ?who abraham)) 

 

 

 

Page 9: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

Expressions and their relations are Scheme lists

logic> (fact (parent eisenhower fillmore))logic> (fact (parent fillmore abraham))logic> (fact (parent abraham clinton))logic> (fact (ancestor ?a ?y) (parent ?a ?y))logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y))logic> (query (ancestor ?who abraham))Success!who: fillmorewho: eisenhower

 

 

 

Page 10: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

Expressions and their relations are Scheme lists

logic> (fact (parent eisenhower fillmore))logic> (fact (parent fillmore abraham))logic> (fact (parent abraham clinton))logic> (fact (ancestor ?a ?y) (parent ?a ?y))logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y))logic> (query (ancestor ?who abraham))Success!who: fillmorewho: eisenhower

If a fact has more than one relation, the first is the conclusion, and it is satisfied if the remaining relations, the hypotheses, are satisfied

 

 

Page 11: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

Expressions and their relations are Scheme lists

logic> (fact (parent eisenhower fillmore))logic> (fact (parent fillmore abraham))logic> (fact (parent abraham clinton))logic> (fact (ancestor ?a ?y) (parent ?a ?y))logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y))logic> (query (ancestor ?who abraham))Success!who: fillmorewho: eisenhower

If a fact has more than one relation, the first is the conclusion, and it is satisfied if the remaining relations, the hypotheses, are satisfied

If a query has more than one relation, all must be satisfied

 

Page 12: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Language Review

Expressions begin with query or fact followed by relations

Expressions and their relations are Scheme lists

logic> (fact (parent eisenhower fillmore))logic> (fact (parent fillmore abraham))logic> (fact (parent abraham clinton))logic> (fact (ancestor ?a ?y) (parent ?a ?y))logic> (fact (ancestor ?a ?y) (parent ?a ?z) (ancestor ?z ?y))logic> (query (ancestor ?who abraham))Success!who: fillmorewho: eisenhower

If a fact has more than one relation, the first is the conclusion, and it is satisfied if the remaining relations, the hypotheses, are satisfied

If a query has more than one relation, all must be satisfied

The interpreter lists all bindings that it can find to satisfy the query

Page 13: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Hierarchical Facts

 

        

 

   

   

Page 14: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Hierarchical Facts

Relations can contain relations in addition to atoms

        

 

   

   

Page 15: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Hierarchical Facts

Relations can contain relations in addition to atoms

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

 

   

   

Page 16: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

   

   

Page 17: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 18: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 19: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 20: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 21: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 22: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Example: Combining Multiple Data Sources

Which dogs have an ancestor of the same color?

   

     

E

F

A D G

B C H

Page 23: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 24: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 25: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 26: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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: eisenhowername: clinton   color: white   ancestor: abrahamname: grover    color: tan     ancestor: eisenhowername: herbert   color: brown   ancestor: fillmore

E

F

A D G

B C H

Page 27: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Example: Appending Lists

 

 

 

 

 

 

Page 28: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Example: Appending Lists

Two lists append to form a third list if:

 

 

 

 

 

Page 29: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

 

 

 

 

Page 30: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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)

 

 

 

 

Page 31: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

 

Page 32: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

 

Page 33: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

 

Page 34: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

 

Page 35: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

 

Page 36: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

 

Page 37: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

Page 38: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

Page 39: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

Page 40: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

Page 41: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

 

Page 42: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

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

Page 43: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

 

 

  

 

   

Page 44: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:

 

  

 

   

Page 45: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list

 

  

 

   

Page 46: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

 

  

 

   

Page 47: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

 

  

 

   

Page 48: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

 

  

 

   

Page 49: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

 

  

 

   

Page 50: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r tar t

 

  

 

   

Page 51: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r tar trat

 

  

 

   

Page 52: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r tar tratr ta 

  

 

   

Page 53: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta 

  

 

   

Page 54: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at r

 

  

 

   

Page 55: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtar

 

  

 

   

Page 56: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

 

  

 

   

Page 57: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

  

 

   

Page 58: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

  

 

   

Element

Page 59: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

  

 

   

Element List

Page 60: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

  

 

   

Element List List with element 

Page 61: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

(fact (insert ?a (?b . ?r) (?b . ?s)) (insert ?a       ?r        ?s))

 

   

Element List List with element 

Page 62: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

(fact (insert ?a (?b . ?r) (?b . ?s)) (insert ?a       ?r        ?s))

(fact (anagram () ()))

   

Element List List with element 

Page 63: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

(fact (insert ?a (?b . ?r) (?b . ?s)) (insert ?a       ?r        ?s))

(fact (anagram () ()))

(fact (anagram (?a . ?r) ?b)   

Element List List with element 

Page 64: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

(fact (insert ?a (?b . ?r) (?b . ?s)) (insert ?a       ?r        ?s))

(fact (anagram () ()))

(fact (anagram (?a . ?r) ?b) (insert   ?a   ?s  ?b) 

Element List List with element 

Page 65: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Logic Example: Anagrams

A permutation (i.e., anagram) of a list is:• The empty list for an empty list• The first element of the list inserted into an anagram of the rest of the list

a r t

r t

t r

ar tratr ta

at rtart ra

(fact (insert ?a ?r (?a . ?r))))

(fact (insert ?a (?b . ?r) (?b . ?s)) (insert ?a       ?r        ?s))

(fact (anagram () ()))

(fact (anagram (?a . ?r) ?b) (insert   ?a   ?s  ?b) (anagram  ?r   ?s))

Element List List with element 

Page 66: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

 

 

Page 67: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

 

Page 68: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

Page 69: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

( (a  b) c  (a  b) ) 

Page 70: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

( (a  b) c  (a  b) ) 

(   ?x   c    ?x   )

Page 71: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

( (a  b) c  (a  b) ) 

(   ?x   c    ?x   )True, {x: (a b)}

Page 72: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

( (a  b) c  (a  b) ) 

(   ?x   c    ?x   )True, {x: (a b)}

( (a  b) c  (a  b) ) 

Page 73: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

( (a  b) c  (a  b) ) 

(   ?x   c    ?x   )True, {x: (a b)}

( (a  b) c  (a  b) ) 

( (a ?y) ?z (a  b) )

Page 74: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

( (a  b) c  (a  b) ) 

(   ?x   c    ?x   )True, {x: (a b)}

( (a  b) c  (a  b) ) 

( (a ?y) ?z (a  b) )True, {y: b, z: c}

Page 75: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

( (a  b) c  (a  b) ) 

(   ?x   c    ?x   )True, {x: (a b)}

( (a  b) c  (a  b) ) 

( (a ?y) ?z (a  b) )True, {y: b, z: c}

( (a  b) c  (a  b) ) 

(   ?x  ?x    ?x   )

Page 76: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Pattern Matching

The basic operation of the Logic interpreter is to attempt to unify two relations

Unification is finding an assignment to variables that makes two relations the same

( (a  b) c  (a  b) ) 

(   ?x   c    ?x   )True, {x: (a b)}

( (a  b) c  (a  b) ) 

( (a ?y) ?z (a  b) )True, {y: b, z: c}

( (a  b) c  (a  b) ) 

(   ?x  ?x    ?x   )False

Page 77: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

 

  

Page 78: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment  

Page 79: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment 

Page 80: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

Page 81: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

{ }

Page 82: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

{ }

Page 83: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

Page 84: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

Page 85: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

Page 86: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

(a  b)(a  b)

Lookup

Page 87: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

(a  b)(a  b)

Lookup

Page 88: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }Success!

(a  b)(a  b)

Lookup

Page 89: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

( (a  b) c  (a  b) ) 

(   ?x   ?x   ?x   )

{ }Success!

(a  b)(a  b)

Lookup

Page 90: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

( (a  b) c  (a  b) ) 

(   ?x   ?x   ?x   )

{ }Success!

(a  b)(a  b)

Lookup

Page 91: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

( (a  b) c  (a  b) ) 

(   ?x   ?x   ?x   )

x: (a b){ }Success!

(a  b)(a  b)

Lookup

Page 92: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

( (a  b) c  (a  b) ) 

(   ?x   ?x   ?x   )

x: (a b){ }Success!

(a  b)(a  b)

Lookup

Page 93: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

( (a  b) c  (a  b) ) 

(   ?x   ?x   ?x   )

x: (a b){ }

c (a b)

Lookup

Success!

(a  b)(a  b)

Lookup

Page 94: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

( (a  b) c  (a  b) ) 

(   ?x   ?x   ?x   )

x: (a b){ }

c (a b)

Lookup

Success!

Symbols/relations without variables only 

unify if they are the same

(a  b)(a  b)

Lookup

Page 95: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification

Unification unifies each pair of corresponding elements in two relations, accumulating an assignment1. Look up variables in the current environment2. Establish new bindings to unify elements

( (a  b) c (a  b) ) 

(   ?x   c   ?x   )

x: (a b){ }

( (a  b) c  (a  b) ) 

(   ?x   ?x   ?x   )

x: (a b){ }

c (a b)

Lookup

Success! Failure.

Symbols/relations without variables only 

unify if they are the same

(a  b)(a  b)

Lookup

Page 96: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

   

Page 97: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

   

Page 98: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )   

Page 99: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, { 

  

Page 100: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, { 

  

Page 101: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

  

Page 102: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

  

Page 103: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

  

(a ?y  c)

(a  b ?z)

Lookup

Page 104: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

  

(a ?y  c)

(a  b ?z)

Lookup

Page 105: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

  

(a ?y  c)

(a  b ?z)

Lookup

Page 106: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b, 

(a ?y  c)

(a  b ?z)

Lookup

Page 107: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b, 

(a ?y  c)

(a  b ?z)

Lookup

Page 108: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b,z: c}

(a ?y  c)

(a  b ?z)

Lookup

Page 109: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b,z: c}

(a ?y  c)

(a  b ?z)

Lookup

Page 110: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b,z: c}

Substituting values for variables may require multiple steps

(a ?y  c)

(a  b ?z)

Lookup

Page 111: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b,z: c}

Substituting values for variables may require multiple steps

lookup('?x')

(a ?y  c)

(a  b ?z)

Lookup

Page 112: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

(a ?y c)

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b,z: c}

Substituting values for variables may require multiple steps

lookup('?x') (a ?y c)

(a ?y  c)

(a  b ?z)

Lookup

Page 113: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

(a ?y c)

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b,z: c}

Substituting values for variables may require multiple steps

lookup('?x') (a ?y c) lookup('?y')

(a ?y  c)

(a  b ?z)

Lookup

Page 114: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

(a ?y c)

Unification with Two Variables

Two relations that contain variables can be unified as well

(    ?x       ?x    )

( (a ?y c) (a b ?z) )True, {x: (a ?y c),

y: b,z: c}

Substituting values for variables may require multiple steps

lookup('?x') (a ?y c) lookup('?y') b

(a ?y  c)

(a  b ?z)

Lookup

Page 115: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

def unify(e, f, env):

e = lookup(e, env)f = lookup(f, env)

if e == f:return True

elif isvar(e):env.define(e, f)return True

elif isvar(f):env.define(f, e)return True

elif scheme_atomp(e) or scheme_atomp(f):return False

else:return unify(e.first, f.first, env) and \

unify(e.second, f.second, env)

Implementing Unification

Page 116: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

def unify(e, f, env):

e = lookup(e, env)f = lookup(f, env)

if e == f:return True

elif isvar(e):env.define(e, f)return True

elif isvar(f):env.define(f, e)return True

elif scheme_atomp(e) or scheme_atomp(f):return False

else:return unify(e.first, f.first, env) and \

unify(e.second, f.second, env)

Implementing Unification

1. Look up variables in the current environment

Page 117: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

def unify(e, f, env):

e = lookup(e, env)f = lookup(f, env)

if e == f:return True

elif isvar(e):env.define(e, f)return True

elif isvar(f):env.define(f, e)return True

elif scheme_atomp(e) or scheme_atomp(f):return False

else:return unify(e.first, f.first, env) and \

unify(e.second, f.second, env)

Implementing Unification

1. Look up variables in the current environment

2. Establish new bindings to unify elements.

Page 118: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

def unify(e, f, env):

e = lookup(e, env)f = lookup(f, env)

if e == f:return True

elif isvar(e):env.define(e, f)return True

elif isvar(f):env.define(f, e)return True

elif scheme_atomp(e) or scheme_atomp(f):return False

else:return unify(e.first, f.first, env) and \

unify(e.second, f.second, env)

Implementing Unification

Symbols/relationswithout variables only 

unify if they are the same

1. Look up variables in the current environment

2. Establish new bindings to unify elements.

Page 119: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

def unify(e, f, env):

e = lookup(e, env)f = lookup(f, env)

if e == f:return True

elif isvar(e):env.define(e, f)return True

elif isvar(f):env.define(f, e)return True

elif scheme_atomp(e) or scheme_atomp(f):return False

else:return unify(e.first, f.first, env) and \

unify(e.second, f.second, env)

Implementing Unification

Symbols/relationswithout variables only 

unify if they are the same

1. Look up variables in the current environment

Unification recursively unifies each

pair of elements

2. Establish new bindings to unify elements.

Page 120: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

Page 121: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

Page 122: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

Page 123: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

Page 124: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

Page 125: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

Page 126: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

Page 127: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

Page 128: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))Variables are local to facts and queries

Page 129: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

Variables are local to facts and queries

Page 130: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

Variables are local to facts and queries

Page 131: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

Variables are local to facts and queries

Page 132: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

(app () ?x ?x)

Variables are local to facts and queries

Page 133: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

(app () ?x ?x)

Variables are local to facts and queries

Page 134: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

(app () ?x ?x)

Variables are local to facts and queries

Page 135: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left:(app () ?x ?x)

Variables are local to facts and queries

Page 136: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left:(app () ?x ?x)

Variables are local to facts and queries

Page 137: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left:(app () ?x ?x)

Variables are local to facts and queries

Page 138: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left:(app () ?x ?x) (e . 

Variables are local to facts and queries

Page 139: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left:(app () ?x ?x) (e . 

Variables are local to facts and queries

Page 140: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left:(app () ?x ?x) (e . 

Variables are local to facts and queries

Page 141: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left: (b .(app () ?x ?x) (e . 

Variables are local to facts and queries

Page 142: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left: (b .(app () ?x ?x) (e . 

Variables are local to facts and queries

Page 143: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left: (b . ()))(app () ?x ?x) (e . 

Variables are local to facts and queries

Page 144: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Searching for Proofs

The Logic interpreter searches the space of facts to find unifying facts and an env that prove the query to be true

(fact  (app () ?x ?x))

(fact  (app (?a . ?r) ?y (?a . ?z))(app       ?r  ?y       ?z ))

(query (app ?left (c d) (e b c d)))

(app ?left (c d) (e b c d))

(app (?a . ?r) ?y (?a . ?z))

{a: e, y: (c d), z: (b c d), left: (?a . ?r)}

(app ?r (c d) (b c d)))conclusion <‐ hypothesis

(app (?a2 . ?r2) ?y2 (?a2 . ?z2))

{a2: b, y2: (c d), z2: (c d), r: (?a2 . ?r2)}

conclusion <‐ hypothesis(app ?r2 (c d) (c d))

{r2: (), x: (c d)}

left: (e b)(b . ()))(app () ?x ?x) (e . 

Variables are local to facts and queries

Page 145: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

 

 

   

        

 

 

Page 146: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

 

 

   

        

Now that we know about Unification, let’s look at an underspecified query

 

Page 147: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

 

 

   

        

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 148: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

 

   

        

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 149: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

   

        

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 150: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what))   

        

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 151: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

        

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 152: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

> (query (append‐to‐form (1 2 . ?r) (3) ?what)       

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 153: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

> (query (append‐to‐form (1 2 . ?r) (3) ?what)Success!      

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 154: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

> (query (append‐to‐form (1 2 . ?r) (3) ?what)Success!r: () what: (1 2 3)     

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 155: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

> (query (append‐to‐form (1 2 . ?r) (3) ?what)Success!r: () what: (1 2 3)r: (?s_6) what: (1 2 ?s_6 3)    

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 156: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

> (query (append‐to‐form (1 2 . ?r) (3) ?what)Success!r: () what: (1 2 3)r: (?s_6) what: (1 2 ?s_6 3)r: (?s_6 ?s_8) what: (1 2 ?s_6 ?s_8 3)   

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 157: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

> (query (append‐to‐form (1 2 . ?r) (3) ?what)Success!r: () what: (1 2 3)r: (?s_6) what: (1 2 ?s_6 3)r: (?s_6 ?s_8) what: (1 2 ?s_6 ?s_8 3)r: (?s_6 ?s_8 ?s_10) what: (1 2 ?s_6 ?s_8 ?s_10 3)  

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 158: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

> (query (append‐to‐form (1 2 . ?r) (3) ?what)Success!r: () what: (1 2 3)r: (?s_6) what: (1 2 ?s_6 3)r: (?s_6 ?s_8) what: (1 2 ?s_6 ?s_8 3)r: (?s_6 ?s_8 ?s_10) what: (1 2 ?s_6 ?s_8 ?s_10 3)r: (?s_6 ?s_8 ?s_10 ?s_12) what: (1 2 ?s_6 ?s_8 ?s_10 ?s_12 3) 

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 159: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Underspecified Queries

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

> (fact (append‐to‐form (?a . ?r) ?x (?a . ?s))(append‐to‐form ?r ?x ?s))

> (query (append‐to‐form (1 2) (3) ?what)) Success!what: (1 2 3)

> (query (append‐to‐form (1 2 . ?r) (3) ?what)Success!r: () what: (1 2 3)r: (?s_6) what: (1 2 ?s_6 3)r: (?s_6 ?s_8) what: (1 2 ?s_6 ?s_8 3)r: (?s_6 ?s_8 ?s_10) what: (1 2 ?s_6 ?s_8 ?s_10 3)r: (?s_6 ?s_8 ?s_10 ?s_12) what: (1 2 ?s_6 ?s_8 ?s_10 ?s_12 3)...

Now that we know about Unification, let’s look at an underspecified query

What are the results of these queries?

Page 160: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

 

 

       

 

Page 161: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

 

       

 

Page 162: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

       

 

Page 163: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):      

 

Page 164: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

    

 

Page 165: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)

   

 

Page 166: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)if unification succeeds:

  

 

Page 167: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)if unification succeeds:

env_rule <‐ search(hypotheses of fact, env_head)

 

 

Page 168: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)if unification succeeds:

env_rule <‐ search(hypotheses of fact, env_head)result <‐ search(rest of clauses, env_rule)

 

Page 169: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)if unification succeeds:

env_rule <‐ search(hypotheses of fact, env_head)result <‐ search(rest of clauses, env_rule)

yield each result

 

Page 170: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)if unification succeeds:

env_rule <‐ search(hypotheses of fact, env_head)result <‐ search(rest of clauses, env_rule)

yield each result

Some good ideas:

Page 171: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)if unification succeeds:

env_rule <‐ search(hypotheses of fact, env_head)result <‐ search(rest of clauses, env_rule)

yield each result

Some good ideas:• Limiting depth of the search avoids infinite loops

Page 172: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)if unification succeeds:

env_rule <‐ search(hypotheses of fact, env_head)result <‐ search(rest of clauses, env_rule)

yield each result

Some good ideas:• Limiting depth of the search avoids infinite loops• Each time a fact is used, its variables are renamed

Page 173: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Search for possible unification

The space of facts is searched exhaustively, starting from the query and following a depth‐first exploration order

A possible proof is explored exhaustively before another one is considered

def search(clauses, env):for fact in facts:

env_head <‐ unify(conclusion of fact, first clause, env)if unification succeeds:

env_rule <‐ search(hypotheses of fact, env_head)result <‐ search(rest of clauses, env_rule)

yield each result

Some good ideas:• Limiting depth of the search avoids infinite loops• Each time a fact is used, its variables are renamed• Bindings are stored in separate frames to allow backtracking

Page 174: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Implementing Search

def search(clauses, env, depth):

if clauses is nil:

yield env

elif DEPTH_LIMIT is None or depth <= DEPTH_LIMIT:

for fact in facts:

fact = rename_variables(fact, get_unique_id())

env_head = Frame(env)

if unify(fact.first, clauses.first, env_head):

for env_rule in search(fact.second, env_head, depth+1):

for result in search(clauses.second, env_rule, depth+1):

yield result

Page 175: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Implementing Search

def search(clauses, env, depth):

if clauses is nil:

yield env

elif DEPTH_LIMIT is None or depth <= DEPTH_LIMIT:

for fact in facts:

fact = rename_variables(fact, get_unique_id())

env_head = Frame(env)

if unify(fact.first, clauses.first, env_head):

for env_rule in search(fact.second, env_head, depth+1):

for result in search(clauses.second, env_rule, depth+1):

yield result

Page 176: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Implementing Search

def search(clauses, env, depth):

if clauses is nil:

yield env

elif DEPTH_LIMIT is None or depth <= DEPTH_LIMIT:

for fact in facts:

fact = rename_variables(fact, get_unique_id())

env_head = Frame(env)

if unify(fact.first, clauses.first, env_head):

for env_rule in search(fact.second, env_head, depth+1):

for result in search(clauses.second, env_rule, depth+1):

yield result

Page 177: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Implementing Search

def search(clauses, env, depth):

if clauses is nil:

yield env

elif DEPTH_LIMIT is None or depth <= DEPTH_LIMIT:

for fact in facts:

fact = rename_variables(fact, get_unique_id())

env_head = Frame(env)

if unify(fact.first, clauses.first, env_head):

for env_rule in search(fact.second, env_head, depth+1):

for result in search(clauses.second, env_rule, depth+1):

yield result

Page 178: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

Implementing Search

def search(clauses, env, depth):

if clauses is nil:

yield env

elif DEPTH_LIMIT is None or depth <= DEPTH_LIMIT:

for fact in facts:

fact = rename_variables(fact, get_unique_id())

env_head = Frame(env)

if unify(fact.first, clauses.first, env_head):

for env_rule in search(fact.second, env_head, depth+1):

for result in search(clauses.second, env_rule, depth+1):

yield result Whatever calls search can access all yielded results

Page 179: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

     

   

   

    

Page 180: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:    

   

   

    

Page 181: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))   

   

   

    

Page 182: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))  

   

   

    

Page 183: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4)) 

   

   

    

Page 184: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

   

   

    

Page 185: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:  

   

    

Page 186: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y)) 

   

    

Page 187: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y))logic> (fact (add ?x ?y ?z)

(ints ?x‐1 ?x) (ints ?z‐1 ?z) (add ?x‐1 ?y ?z‐1))

   

    

Page 188: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y))logic> (fact (add ?x ?y ?z)

(ints ?x‐1 ?x) (ints ?z‐1 ?z) (add ?x‐1 ?y ?z‐1))

Finally, we define the evaluator:  

    

Page 189: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y))logic> (fact (add ?x ?y ?z)

(ints ?x‐1 ?x) (ints ?z‐1 ?z) (add ?x‐1 ?y ?z‐1))

Finally, we define the evaluator:logic> (fact (eval ?x ?x) (ints ?x ?something)) 

    

Page 190: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y))logic> (fact (add ?x ?y ?z)

(ints ?x‐1 ?x) (ints ?z‐1 ?z) (add ?x‐1 ?y ?z‐1))

Finally, we define the evaluator:logic> (fact (eval ?x ?x) (ints ?x ?something))logic> (fact (eval (+ ?op0 ?op1) ?val)

(add ?a0 ?a1 ?val) (eval ?op0 ?a0) (eval ?op1 ?a1))    

Page 191: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y))logic> (fact (add ?x ?y ?z)

(ints ?x‐1 ?x) (ints ?z‐1 ?z) (add ?x‐1 ?y ?z‐1))

Finally, we define the evaluator:logic> (fact (eval ?x ?x) (ints ?x ?something))logic> (fact (eval (+ ?op0 ?op1) ?val)

(add ?a0 ?a1 ?val) (eval ?op0 ?a0) (eval ?op1 ?a1))logic> (query (eval (+ 1 (+ ?what 2)) 5))   

Page 192: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y))logic> (fact (add ?x ?y ?z)

(ints ?x‐1 ?x) (ints ?z‐1 ?z) (add ?x‐1 ?y ?z‐1))

Finally, we define the evaluator:logic> (fact (eval ?x ?x) (ints ?x ?something))logic> (fact (eval (+ ?op0 ?op1) ?val)

(add ?a0 ?a1 ?val) (eval ?op0 ?a0) (eval ?op1 ?a1))logic> (query (eval (+ 1 (+ ?what 2)) 5))Success!  

Page 193: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y))logic> (fact (add ?x ?y ?z)

(ints ?x‐1 ?x) (ints ?z‐1 ?z) (add ?x‐1 ?y ?z‐1))

Finally, we define the evaluator:logic> (fact (eval ?x ?x) (ints ?x ?something))logic> (fact (eval (+ ?op0 ?op1) ?val)

(add ?a0 ?a1 ?val) (eval ?op0 ?a0) (eval ?op1 ?a1))logic> (query (eval (+ 1 (+ ?what 2)) 5))Success!what: 2 

Page 194: CS61A Lecture 40 - University of California, Berkeleycs61a/sp13/slides/40-Unification_1pp.pdfCS61A Lecture 40 Amir Kamil and Stephen Martinis UC Berkeley April 24, 2013 HW12 due tonight

An Evaluator in Logic

We can define an evaluator in Logic; first, we define numbers:logic> (fact (ints 1 2))logic> (fact (ints 2 3))logic> (fact (ints 3 4))logic> (fact (ints 4 5))

Then we define addition:logic> (fact (add 1 ?x ?y) (ints ?x ?y))logic> (fact (add ?x ?y ?z)

(ints ?x‐1 ?x) (ints ?z‐1 ?z) (add ?x‐1 ?y ?z‐1))

Finally, we define the evaluator:logic> (fact (eval ?x ?x) (ints ?x ?something))logic> (fact (eval (+ ?op0 ?op1) ?val)

(add ?a0 ?a1 ?val) (eval ?op0 ?a0) (eval ?op1 ?a1))logic> (query (eval (+ 1 (+ ?what 2)) 5))Success!what: 2what: (+ 1 1)


Recommended