Docsity

Logic Programming and Artifical Intelligence, Solution Sheets - Computer Science 6, Study notes of Computer Numerical Control

Toggle sidebar
bg1
Logic Programming and Artificial Intelligence
3 March 2010
Solutions to LPA Problem Sheet 6
1. f(a, b)f(g(x), x)f(x, f (y, z)) y
{ } f(a, b)f(g(x), x)f(x, f (y, z)) y
{x7→ y, y 7→ z, z 7→ x}f(a, b)f(g(y), y)) f(y, f (z, x)) z
{x7→ g(y), y 7→ g(x)}f(a, b)f(g(g(y)), g(y)) f(g(y), f (g(x), z)) g(x)
{x7→ f(y, y), z 7→ a}f(a, b)f(g(f(y, y )), f(y , y)) f(f(y, y), f (y, a)) y
2. f(x, x)f(y, g(y)) f(a, y )f(a, b)f(y, g(x))
f(x0, x0){x7→ x0}None {x07→ a,
y7→ a}
None {x07→ g(x),
y7→ g(x)}
f(y0, g(y0)) XXXXX {y7→ y0} {y07→ a,
y7→ g(a)}
None {y7→ y0,
x7→ y0}
f(a, y0) XXXXX XXXXX {y7→ y0} {y07→ b} {y7→ a,
y07→ g(x)}
f(a, b) XXXXX XXXXX XXXXX {} None
f(y0, g(x0)) XXXXX XXXXX XXXXX XXXXX {x7→ x0,
y7→ y0}
Some of these boxes also have other most general unifiers. For example, {x07→ x}is
also a correct entry for the first column of the first row.
3. (a) (A) below(X,d)
(B) above(d,X) ........................ from 1
(C) on(d,X) ........................ from 2
(D) [] .......................... from 6 (goal)
(E) on(d,Y) & above(Y,X)......... .. from 4
(F) above(e,X) .................. from 6
(G) on(e,X) .................. from 2 (fail)
(H) on(e,Y2) & above(Y2,X) ... from 4 (fail)
(b) [trace] ?- below(X,d).
Call: (7) below(_G429, d) ? creep % A
Call: (8) above(d, _G429) ? creep % B
Call: (9) on(d, _G429) ? creep % C
Exit: (9) on(d, e) ? creep % D; C succeeds with X=e
Exit: (8) above(d, e) ? creep % B succeds with X=e
Exit: (7) below(e, d) ? creep % A succeeds with X=e
X=e;
Redo: (8) above(d, _G429) ? creep % B
Call: (9) on(d, _L204) ? creep % leftmost atom of E
Exit: (9) on(d, e) ? creep % leftmost atom of E suceeds
Call: (9) above(e, _G429) ? creep % F
Call: (10) on(e, _G429) ? creep % G
Fail: (10) on(e, _G429) ? creep % G fails
Redo: (9) above(e, _G429) ? creep % back to F
Call: (10) on(e, _L215) ? creep % leftmost atom of H
Fail: (10) on(e, _L215) ? creep % leftmost atom of H fails
Redo: (7) below(_G429, d) ? creep % back to A
No
1
pf3

Partial preview of the text

Download Logic Programming and Artifical Intelligence, Solution Sheets - Computer Science 6 and more Study notes Computer Numerical Control in PDF only on Docsity!

Logic Programming and Artificial Intelligence 3 March 2010 Solutions to LPA Problem Sheet 6

  1. f (a, b) f (g(x), x) f (x, f (y, z)) y { } f (a, b) f (g(x), x) f (x, f (y, z)) y {x 7 → y, y 7 → z, z 7 → x} f (a, b) f (g(y), y)) f (y, f (z, x)) z {x 7 → g(y), y 7 → g(x)} f (a, b) f (g(g(y)), g(y)) f (g(y), f (g(x), z)) g(x) {x 7 → f (y, y), z 7 → a} f (a, b) f (g(f (y, y)), f (y, y)) f (f (y, y), f (y, a)) y
  2. f (x, x) f (y, g(y)) f (a, y) f (a, b) f (y, g(x)) f (x′, x′) {x 7 → x′} None {x′^7 → a, y 7 → a}

None {x′^7 → g(x), y 7 → g(x)} f (y′, g(y′)) XXXXX {y 7 → y′} {y′^7 → a, y 7 → g(a)}

None {y 7 → y′, x 7 → y′} f (a, y′) XXXXX XXXXX {y 7 → y′} {y′^7 → b} {y 7 → a, y′^7 → g(x)} f (a, b) XXXXX XXXXX XXXXX {} None f (y′, g(x′)) XXXXX XXXXX XXXXX XXXXX {x 7 → x′, y 7 → y′}

Some of these boxes also have other most general unifiers. For example, {x′^7 → x} is also a correct entry for the first column of the first row.

  1. (a) (A) below(X,d) (B) above(d,X) ........................ from 1 (C) on(d,X) ........................ from 2 (D) [] .......................... from 6 (goal) (E) on(d,Y) & above(Y,X)......... .. from 4 (F) above(e,X) .................. from 6 (G) on(e,X) .................. from 2 (fail) (H) on(e,Y2) & above(Y2,X) ... from 4 (fail) (b) [trace] ?- below(X,d). Call: (7) below(_G429, d)? creep % A Call: (8) above(d, _G429)? creep % B Call: (9) on(d, _G429)? creep % C Exit: (9) on(d, e)? creep % D; C succeeds with X=e Exit: (8) above(d, e)? creep % B succeds with X=e Exit: (7) below(e, d)? creep % A succeeds with X=e

X = e ; Redo: (8) above(d, _G429)? creep % B Call: (9) on(d, _L204)? creep % leftmost atom of E Exit: (9) on(d, e)? creep % leftmost atom of E suceeds Call: (9) above(e, _G429)? creep % F Call: (10) on(e, _G429)? creep % G Fail: (10) on(e, _G429)? creep % G fails Redo: (9) above(e, _G429)? creep % back to F Call: (10) on(e, _L215)? creep % leftmost atom of H Fail: (10) on(e, _L215)? creep % leftmost atom of H fails Redo: (7) below(_G429, d)? creep % back to A

No

  1. (a) A(x,j) P(x,j) ..................... from 3 fail P(x,y) & A(y,j) ............ from 4 A(f(x),j) ............... from 1 P(f(x),j) ............ from 3 fail P(f(x),y) & A(y,j) ... from 4 A(m(x),j) ............... from 2 P(m(x),j) ............ from 3 fail P(m(x),y) & A(y,j) ... from 4

The search space continues forever in a similar manner. It contains no solutions. Given this problem, PROLOG would run forever, or until it ran out of space. It would go down the infinite path from the node labelled P(f(x),y) & A(y,j). (b) A(x,j) P(x,j) ............ from 3 fail P(y,j) & A(x,y) ... from 4’ fail

(c) A(j,x) [x=x] P(j,x) [x=x] ..................... from 3 [] [x=f(j)] ................... from 1 [] [x=m(j)] ................... from 2 P(j,y) & A(y,x) [x=x] ............ from 4 A(f(j),x) [x=x] ............... from 1 P(f(j),x) [x=x]............. from 3 [][x=f(f(j))] ........... from 1 [][x=m(f(j))] ........... from 2 P(f(j),y & A(y,x) [x=x] .... from 4 A(f(f(j)),x) [x=x] ...... from 1 A(m(f(j)),x) [x=x] ...... from 2 A(m(j),x) [x=x] ............... from 2 P(m(j),x) [x=x]............. from 3 [][x=f(m(j))] ........... from 1 [][x=m(m(j))] ........... from 2 P(m(j),y & A(y,x) [x=x] .... from 4 A(f(m(j)),x) [x=x] ...... from 1 A(m(m(j)),x) [x=x] ...... from 2

This search space is infinite and contains no failed paths. In contains an infinite set of solutions, all of the form [x=ANSWER], where ANSWER is any term generated by the following rules:

  • m(j) and f(j) are ANSWERs
  • if X is an ANSWER then so are f(X) and m(X). (d) PROLOG would first find [x=f(j)]. Replacing x with f(j) in the goal clause yields A(j,f(j)), which means that PROLOG has proved A(j,f(j)). That is, it has proved that the father of j is an ancestor of j. Then PROLOG would find [x=m(j)]. Replacing x with m(j) in the goal clause yields A(j,m(j)), which means that the father of j is an ancestor of j. Continuing the execution would forever produce more answers. (e) A(x,y) [x=x,y=y] P(x,y) [x=x,y=y] ........ from 3 [] [x=x,y=f(x)] ...... from 1 [] [x=x,y=m(x)] ...... from 1

The first answer means that PROLOG has proved ∀x A(x, f (x)), that is, “one’s father is one’s ancestor.” The second answer means that PROLOG has proved ∀x A(x, m(x)), that is, “one’s mother is one’s ancestor.” (f) No inferences can be performed by SLD. P (x, x) does not unify with premise 1 or 2 because of an occur check. However, since PROLOG does not detect occur