cs61a lecture 40 - university of california, berkeleycs61a/sp13/slides/40-unification_1pp.pdfcs61a...
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/1.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/2.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/3.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/4.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/5.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/6.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/7.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/8.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/9.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/10.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/11.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/12.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/13.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/14.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/15.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/16.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/17.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/18.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/19.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/20.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/21.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/22.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/23.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/24.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/25.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/26.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/27.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/28.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/29.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/30.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/31.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/32.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/33.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/34.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/35.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/36.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/37.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/38.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/39.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/40.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/41.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/42.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/43.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/44.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/45.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/46.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/47.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/48.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/49.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/50.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/51.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/52.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/53.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/54.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/55.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/56.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/57.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/58.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/59.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/60.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/61.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/62.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/63.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/64.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/65.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/66.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/67.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/68.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/69.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/70.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/71.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/72.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/73.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/74.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/75.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/76.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/77.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/78.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/79.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/80.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/81.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/82.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/83.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/84.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/85.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/86.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/87.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/88.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/89.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/90.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/91.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/92.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/93.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/94.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/95.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/96.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/97.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/98.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/99.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/100.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/101.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/102.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/103.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/104.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/105.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/106.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/107.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/108.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/109.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/110.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/111.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/112.jpg)
(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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/113.jpg)
(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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/114.jpg)
(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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/115.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/116.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/117.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/118.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/119.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/120.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/121.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/122.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/123.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/124.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/125.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/126.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/127.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/128.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/129.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/130.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/131.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/132.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/133.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/134.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/135.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/136.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/137.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/138.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/139.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/140.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/141.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/142.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/143.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/144.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/145.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/146.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/147.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/148.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/149.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/150.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/151.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/152.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/153.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/154.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/155.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/156.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/157.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/158.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/159.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/160.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/161.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/162.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/163.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/164.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/165.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/166.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/167.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/168.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/169.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/170.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/171.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/172.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/173.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/174.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/175.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/176.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/177.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/178.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/179.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/180.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/181.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/182.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/183.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/184.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/185.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/186.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/187.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/188.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/189.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/190.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/191.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/192.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/193.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022071511/61303ce61ecc51586943f7c3/html5/thumbnails/194.jpg)
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)