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
28 March 2008, 14:00 – 18:00
Points: The exam consists of 5 questions worth 37 points. You will need approximately 15
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 at approximately 15:00. He can also be reached
by phone 013-28 14 27 or 070-660 15 64.
Question 1: Lisp programming (9p)
1a (3p) We have created a variable bowl with information about some fruits. What will the Lisp
interpreter return if we enter the following three expressions (exactly as stated) with labels 2-4 in
the example?
CL-USER(1): (setq bowl '((banana . 5) (apple . 8)))
((BANANA . 5) (APPLE . 8))
CL-USER(2): (cadr bowl)
???
CL-USER(3): (list (first (second bowl)) 'macintosh)
???
CL-USER(4): (* (cdar bowl) 3)
???
1b (3p) Write a Lisp function sum that computes the sum of all the numbers in an ordinary list.
Elements that are not numbers should be ignored. Assume that the list does not contain sublists.
The following examples show how the function should work:
CL-USER(5): (sum '(one two 3 4))
7
CL-USER(6): (sum '(10 (8 is ignored) 3)))
13
CL-USER(7): (sum '(1.5 2))
3.5
1c (2p) Write a Lisp function sum-generic that is a more generic version of the previous
function. The second argument should be a predicate function to be applied to all numbers. The
function sum-generic should sum the numbers for which the predicate function returns true.
CL-USER(8): (sum-generic '(a 1 2 b 1.0 2.0) #'integerp)
3
CL-USER(9): (sum-generic '(-1 -1.0 1 1.0) #'minusp)
-2.0
1d (1p) What should we give as second argument to sum-generic in order to sum all numbers in
the interval -5 to 5?
CL-USER(10): (number-of-generic '(-10 -4 -1 0 2 4 20) ???)
1
Question 2: Logic (10p)
2a (2p) Construct a truth table for the following formula:
(P ∧ Q) ⇒ P
2b (2p) Is the formula in 2a satisfiable? Is it valid? Motivate your answer using the truth table.
2c (2p) Translate the following three sentences into suitable predicate formulas:
A: It never rains in southern California.
B: Oh, sure it does! Some winter days it rains, and now it’s late January.
C: You see, in the winter people always surf if it’s not raining, and the beach is completely
empty today.
2d (1p) Does it rain today? Assume that the three people talking are actually in southern
California. Use informal reasoning to find out if it rains or not. (Ignore what A is saying, since he
is only quoting song lyrics.)
2e (3p) Prove your claim from 2d using resolution. (Again, ignore what A is saying.)
If necessary, you will find standard logical equivalences in the appendix.
Question 3: Search (9p)
The following map shows some of the larger cities in northen Västergötland, a beautiful part of
Sweden on the other side of lake Vättern. The map also shows the distances between the cities in
km. In this problem we will use A* search to find the shortest route from Lidköping to
Karlsborg. The table beside the map gives you an approximation of the straight-line distance in
km from the different cities to Karlsborg.
Mariestad
Götene
32
Töreboda
20
20
41
38
Lidköping 18
Karlsborg
21
22
Skara
26
Tibro
28
32
16
Skövde
31
Hjo
City
Götene
Hjo
Karlsborg
Lidköping
Mariestad
Skara
Skövde
Tibro
Töreboda
hSLD
69
27
0
92
51
73
50
27
35
3a (2p) We are going to use the straight-line distance as a heuristic for this search problem. What
is a heuristic? Why is straight-line distance an admissible heuristic?
3b (5p) Illustrate the different stages in A* search for the shortest route from Lidköping to
Karlsborg. In each stage, label the leaf nodes with g + h, i.e. the distance so far plus the estimated
distance to the goal.
3c (2p) Assume that we have two search algorithms B and C. The description of the algorithms
say that B is O(kn) and C is O(n2). What could this mean (i.e. what does the O thing mean)?
Which algorithm is best?
Please note that there is a difference between Lidköping and Linköping. Even Swedish people have trouble telling
them apart.
Question 4: Planning (5p)
4a (1p) What is the difference between a planning domain and a problem instance?
4b (2p) Choose a real world planning situation that has restrictions that are difficult to model
using the techniques we have used in the course (e.g. time, space, resources). Describe the
planning situation briefly (in text, not using a planning language) and explain one of the
restrictions that is hard to model.
4c (2p) Using a planning definition language of your choice, formalize at least two actions from
the plannig problem that you chose in the previous question.
Question 5: Miscellaneous (4p)
5a (2p) Describe briefly the (representational) frame problem.
5b (2p) Describe briefly the ramification 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 ∧ B) ∨ (A ∧ C))
((A ∨ B) ∧ C) ≡ ((A ∨ B) ∧ (A ∨ 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