TDDC65 Artificial Intelligence and Lisp TDDA23 Artificial Intelligence and Lisp Written exam

advertisement
Written exam
TDDC65 Artificial Intelligence and Lisp
TDDA23 Artificial Intelligence and Lisp
20 December 2008, 14:00 – 18:00
Points: The exam consists of 5 questions worth 45 points. You will need approximately 18
points to pass the exam.
Auxiliary items: You may bring any kind of generic dictionary to the exam. You may not use
calculators, other books, articles or handwritten notes.
Directions: You can answer in English or Swedish. Use notations and methods that have been
discussed in the course. If an exercise has not been specified completely as you see it, state which
reasonable assumptions you have made. Begin each main question on a new sheet of paper. Write
only on one side of the paper. Write clearly!
Contact: Peter Dalenius will visit the exam hall once around 15:00. He can also be reached by
phone 013-28 14 27 or 070-660 15 64.
Question 1: Lisp programming (8p)
1a (2p) What will the Lisp interpreter return if we enter the following four expressions (exactly as
stated) with labels 1-4 in the example?
CL-USER(1):
???
CL-USER(2):
???
CL-USER(3):
???
CL-USER(4):
???
(setq fruits (list 'apple 'banana (cons 'orange '())))
(cons (+ 1 2) '(* 3 4))
(append '(clockwork) (third fruits))
(list (second fruits) 'phone)
1b (4p) Write a Lisp function change that replaces all occurences of an atom (symbol or number)
with another in a list. If the list contains sublists, these should be processed as well. The
following examples show how the function should work:
CL-USER(5): (change '(do re me do re mi) 'me 'mi)
(DO RE MI DO RE MI)
CL-USER(6): (change '((14 17 19) -1 (4 -1 (3 4))) -1 0)
((14 17 19) 0 (4 0 (3 4)))
A function that only works on simple lists, without sublists, will give you 2 points.
1c (2p) Assume that we have a more generic function change2 that also replaces atoms, but
instead takes two functions as arguments. The first function returns true if the atom should be
replaced. The second function takes the old atom as input and gives the new one as output. If
we, for example, want to double all numbers in a list we can do the following:
CL-USER(7): (change2 '(one 2 three 4) #'numberp
#'(lambda (x) (* x 2)))
(ONE 4 THREE 8)
Assuming that the function change2 exists, what functions or lambda expressions should we
give as arguments if we want to replace all numbers divisible by 3 with the atom hop?
CL-USER(8): (change2 '(1 2 3 4 5 6 7 8 9) #'??? #'???)
(1 2 HOP 4 5 HOP 7 8 HOP)
Question 2: Logic (12p)
2a (2p) Prove the following equivalence in a suitable way:
P ⇒ (Q ∧ R) ≡ ¬(¬Q ∧ P) ∧ (R ∨ ¬P)
2b (2p) Are the formulas in 2a satisfiable? Are they valid? Motivate your answer.
2c (2p) John is a student who sometimes likes to party, and we are going to analyze his behavior
using logic. We know three things about John:
a) If there is nothing on the TV, John will go to a party or go to sleep.
b) If John doesn't go to a party, he will feel lonely.
c) When John feels lonely and there is something on TV, he will not go to sleep.
From these three sentences we draw the following conclusion:
d) John will go to a party if there is nothing on TV.
Translate the four sentences to suitable formulas in propositional logic.
2d (3p) Prove that the conclusion follows from the first three sentences using resolution.
2e (3p) How does first order predicate logic extend propositional logic? Describe the added
features and how they can help us better represent knowledge. Give a small example that
illustrates some of the merits of predicate logic.
Question 3: Search (11p)
A group of school children at the Ånestad school are going to celebrate the Swedish tradition of
Lucia and they want to visit a retirement home in Ryd to sing for the elders. They want to find
the shortest route through Linköping, from Ånestad to Ryd. Their map looks like the picture
below.
Abisko
Ryd
3.1
2.5
2.3
Old town
Railway station
1.6
1.5 2.1
Castle
4.3
2.9
2.9
3.0
Tannefors
4.1
1.7
1.1
6.0
Hospital
3.4
Place
University
Old town
Abisko
Hospital
Castle
Station
Tannefors
Ånestad
hSLD
1.7
1.4
2.3
3.4
3.0
3.7
4.4
5.5
University
Anestad
The school children want you to find the shortest route, but they want you to use the A* search
algorithm. Since the search space is an ordinary map, we can use the straight line distance as an
admissible heuristic. The straight line distance from different places in the town to Ryd is given in
the table. All distances are given in km.
3a (5p) Illustrate the different stages in A* search for the shortest route from Ånestad to Ryd. In
each stage, label the leaf nodes with g + h, i.e. the distance so far plus the estimated distance to
the goal.
3b (3p) Answer the following questions briefly:
What is an informed search strategy?
What is uniform cost search?
What is bidirectional search?
3c (3p) Prove that A* is optimal if we use an admissible heuristic!
Question 4: Planning (8p)
4a (4p) The Tower of Hanoi is a classic mathematical puzzle. It consists of three pegs and a set of
discs of different sizes that can be stacked on the pegs. At the start of the game, all the discs are
stacked on the leftmost peg in increasing size with the largest disc at the bottom. The goal is to
move all the discs to the rightmost peg, following the game rules:
-
You can only move one disc at a time.
You can only move the upper disc from one of the pegs and move it to another peg.
You can not place a bigger disc on top of a smaller disc.
The following picture shows the setup for a game with five discs:
Define this planning domain in PDDL. As you may remember the domain is defined as a set of
predicates and a set of actions, using the following basic syntax:
(define (domain hanoi)
(:requirements :strips)
(:predicates ...)
(:action name_of_action
:parameters ...
:precondition ...
;; When is the action possible
:effect ...)
;; What will change
...)
4b (2p) Define a problem instance for a Tower of Hanoi problem with three discs. A problem in
PDDL uses the following basic syntax:
(define (problem hanoi-3)
(:domain hanoi)
(:objects ...)
;; Objects in this problem
(:init ...)
;; The world at the start of the problem
(:goal ...))
;; Desired outcome
4c (2p) Describe briefly one of the restrictions (assumptions about the world) that we have to
make when using classical planning.
Question 5: Miscellaneous (6p)
5a (2p) Describe briefly the difference between a reflex agent and a goal based agent.
5c (2p) Describe briefly the Turing test. Which approach to artificial intelligence does the Turing
test imply?
5b (2p) Describe briefly the (representational) frame problem.
Appendix
Standard logical equivalences
A∧B≡B∧A
A∨B≡B∨A
((A ∧ B) ∧ C) ≡ (A ∧ (B ∧ C))
((A ∨ B) ∨ C) ≡ (A ∨ (B ∨ C))
¬(¬A) ≡ A
(A ⇒ B) ≡ (¬B ⇒ ¬A)
(A ⇒ B) ≡ (¬A ∨ B)
(A ⇔ B) ≡ ((A ⇒ B) ∧ (B ⇒ A))
¬(A ∧ B) ≡ (¬A ∨ ¬B)
¬(A ∨ B) ≡ (¬A ∧ ¬B)
((A ∧ B) ∨ C) ≡ ((A ∨ C) ∧ (B ∨ C))
((A ∨ B) ∧ C) ≡ ((A ∧ C) ∨ (B ∧ C))
commutativity
associativity
double negation elimination
contraposition
implication elimination
bidirectional elimination
De Morgan
distributivity
Process for converting any propositional formula to CNF
1. Eliminate biconditional
2. Eliminate implication
3. Move negations inwards
4. Distribute ∨ over ∧
Download