Department of Computer Science Midterm Examination 2 Computer Science 312 Functional and Logic Programming
Question 1 [12 marks] Department of Computer Science Midterm Examination 2 Computer Science 312 Functional and Logic Programming (a) [4 marks] In the semantic web, a URI is a “Uniform Resource Identifier”. What is a URI? Why are URIs useful? (b) [4 marks] Explain what “Triples are universal representations of relations” means, and why it is true. (c) [4 marks] Suppose you are told the triples using prop(Subject, Verb, Object): prop(bread,’rdfs:domain’,’ This entails that: i) p123 is a ii) b764 is a Question 2 [10 marks] (a) [3 marks] Give Clark’s completion (using explicit quantification) of del1(E, [E|R], R). del1(E, [H|T], [H|R]) :- del1(E,T,R). (b) [5 marks] Given the logic program: del1(E, [E|R], R). del1(E, [H|T], [H|R]) :- del1(E,T,R). Give a proof for the first answer that Prolog finds for the query: ?- del1(a(X),[b(c),e(f),a(d),a(c)],Y). You need to show the answer clause and an appropriately renamed cause to resolve against, but you do not need to show substitutions. (c) [2 marks] What is the first answer that Prolog gives for this query? Question 3 [10 marks] (a) [6 marks] Define the relation shuffle(L1, L2, L3) that is true if L3 is an interleaving of the elements of S1 and S2 (i.e., some elements of one, followed by some elements of the other, followed by some elements of the first, etc. The orders of elements in S1 and S2 should be preserved). For example, it should work as follows: ?- shuffle([a,b],[1,2],S). S = [a, b, 1, 2] ; S = [a, 1, b, 2] ; S = [a, 1, 2, b] ; S = [1, a, b, 2] ; S = [1, a, 2, b] ; S = [1, 2, a, b] ; false. ?- shuffle([a,b,c],[],S). S = [a, b, c] ; false. (b) [4 marks] What are all of the answers to the following query? (You should be able to answer this even if you cannot answer part (a)). ? shuffle([a,e],L,[a,v,e,r,a,g,e]). Question 4 [10 marks] (a) [6 marks] For each the following pairs of terms, either give their most general unifier or say why no most general unifier exists. i) [3 marks] p(f (h(X, d)), h(X, Y), Y) and p(f (Z), Z, c). ii) [3 marks] k([u, n, f , u, n], R) and k([u, n|Z], [n, o|Z]). (b) [4 marks] Consider the code: noun_phrase(T1,T3,Obj,C1,C3) :- adjectives(T1,T2,Obj,C1,C2), noun(T2,T3,Obj,C2,C3). adjectives(T,T,_,C,C). adjectives(T0,T2,Obj,C0,C2) :- adj(T0,T1,Obj,C0,C1), adjectives(T1,T2,Obj,C1,C2). adj([Lang,speaking | T],T,Obj,C,[language(Obj,Lang)|C]). noun([country | T],T,Obj,C,[country(Obj)|C]). What is the answer to the query: ?- noun_phrase([french,speaking,country,borders,a, spanish, speaking, country],L,Ind,[large(Ind)],R).
Document information
- Uploaded on
- December 5, 2022
- Number of pages
- 2
- Written in
- 2022/2023
- Type
- Exam (elaborations)
- Contains
- Questions & answers