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
17 April 2009, 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 (9p)
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 animals (list 'dog (cons 'cat '(mouse))))
(cons 'bob (car (second animals)))
(funcall #'length (append animals '()))
(list '(* 5 7) (* 5 7))
1b (3p) Write a Lisp function sum-intervals that takes a list of numeric intervals. The function
should calculate the sum of all those intervals. Assume that each interval is a list of two numbers
where the first one is smaller than the second one. The following example show how the
function should work:
CL-USER(5): (sum-intervals '((2 4) (7 10)))
7
Please note that the size of the interval from 2 to 4 is 3, i.e. both the start and end is included.
1c (4p) Write a more generic Lisp function do-intervals that can process the same kind of
numeric intervals as in the previous question. However, what the function should do with the
intervals is to be specified by the arguments to do-intervals. The second argument should be a
function that takes an interval and a current value. The third argument should be the starting
value. For example, if we want to sum the intervals, we might want to do like this:
CL-USER(6): (do-intervals '((2 4) (7 10)) #'+ 0)
Error: `(7 10)' is not of the expected type `NUMBER'
The second argument indicates that we want to sum the intervals, and the third argument
indicates that the starting value should be 0 (the starting point of all additions). However, this will
not work, since the + function cannot be applied to intervals.
First of all, write the generic function do-intervals. Secondly, replace #’+ in the call above
with a more suitable function or lambda expression that works.
Question 2: Logic (12p)
2a (2p) Prove that the following formula is valid using a truth table:
P ∧ (¬Q ∨ R) ⇒ ¬(¬P ∧ Q) ∨ R
2b (2p) Prove that the same formula is valid by rewriting it to a known tautology (i.e. a much
simpler formula that is trivially always true).
2c (2p) Coffee is a necessary supply when preparing and correcting exams. Let’s assume that the
following three facts are true:
a) If I don’t get my coffee, I will be tired or irritated, and sometimes both.
b) However, if I’m already in a good mood and don’t get coffee, I will at least not be
irritated.
c) Coffee always gets me in a good mood.
From these three sentences we draw the following conclusion:
d) I’m tired.
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 new student has arrived in Linköping and his first task is to get from the railway station to the
university. He has decided to walk, but wants to find the shortest route given the following map.
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
Ryd
Old Town
Hospital
Abisko
Castle
Railway St.
Tannefors
Ånestad
hSLD
1.9
1.3
2.8
2.8
3.0
4.1
4.5
4.7
University
Anestad
The student wants to use your knowledge of different search algorithms, particularly A* search,
so your task is to help him find the shortest route from the railway station to the university using
A*. 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 the university
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 the station to the
university. In each stage, label the leaf nodes with g + h, i.e. the distance so far plus the estimated
distance to the goal. If you decide to exclude a node, state explicitly why you have done that and
explain why it is ok!
3b (4p) A* is an informed search strategy that is optimal, but only if the heuristic function is
admissible. Explain the underlined terms briefly, i.e. answer the following questions:
What do we mean by informed search?
What is an optimal search algorithm?
What is a heuristic?
What does admissible mean?
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?
Question 4: Planning (7p)
4a (4p) Let’s say that we have a number of holes that need to be covered with some kind of blobs
of unknown material. The blobs are stacked in a pile somewhere next to the holes. The situation
might look like this:
The shape of the blobs are not interesting in this problem. The only thing that matters is that
each hole is covered completely with a blob. In order to solve the problem, we have to move a
blob from the pile and place it on top of a hole (provided that it covers the hole). It is possible to
place a blob on top of another, if we find it necessary, or to move a blob back to the pile. The
blobs can be stacked on top of each other in any order, regardless of their relative size.
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 blobworld)
(:requirements :strips)
(:predicates ...)
(:action name_of_action
:parameters ...
:precondition ...
;; When is the action possible
:effect ...)
;; What will change
...)
4b (3p) Define a problem instance for the Blob World. A problem in PDDL uses the following
basic syntax:
(define (problem blob-3)
(:domain blobworld)
(:objects ...)
;; Objects in this problem
(:init ...)
;; The world at the start of the problem
(:goal ...))
;; Desired outcome
In this particular problem instance there are three holes and three blobs in a pile. You can think
of the holes as being shaped as a square, a triangle and a circle, but it doesn’t really matter. The
first blob can cover any hole. The second blob can cover only the triangular hole. The third blob
can cover the square one and the triangular one. At the start, all three blobs are stacked in the
pile.
Question 5: Miscellaneous (6p)
5a (2p) Describe briefly the difference between a reflex agent and a goal based agent.
5b (2p) Describe briefly the Turing test. Which approach to artificial intelligence does the Turing
test imply?
5c (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