Previous sheets

Introduction to Prolog

Write the prolog predicates described in the assignments. Try to use ``don't cares'' (instead of variable names) where appropriate. Don't use the builtin predicates. Numerical comparison...

Start time:
Mo 03 Jun 2019 16:00:00
End time:
Mo 17 Jun 2019 16:00:00

Assignments 9

lastelem (1P)
lastelem(L,X) if L is a list then X should be the last element of L
contains (1P)
contains(L,X) is true if L is a list and L contains at minimum one element equal to X
backwards (1P)
backwards(L,R) if L is a list then R is a list with the same elements in reverse order
neighbors (1P)
neighbors(X,Y,L) is true if L is a list and X and Y are neighboring elements in L
replace (2P)
replace(L,X,Y,R) if L is a list then R is the same list with all occurrences of X replaced with Y
compress (2P)
compress(L1,L2) The list L2 is obtained from the list L1 by compressing repeated occurrences of elements into a single copy of the element. Example: ?- compress([1,1,2,2,2,3,3,4],L) should yield L...
pack (2P)
pack(L1,L2) The list L2 is obtained from the list L1 by packing repeated occurrences of elements into separate sublists. Example: ?- compress([1,1,2,2,2,3,3,4],L) should yield L =...
Natural Numbers (4P)
Assume that s is a functor that represents the successor of a number, i.e. s(0)=1, s(s(0))=2 etc. Now given the following predicates: natural_number(0). natural_number(s(X)) :- natural_number(X)....
Puzzle (16P)
The Problem: A farmer comes by a river with a cabbage, a wolf and a goat. He wants to safely cross the river. There is a boat that can only accommodate two things at a time and only the farmer can...
Abduction

In this exercise we will use Prolog to formulate hypotheses about faulty components in a malfunc- tioning system. Consider the above example of a 3-bit subtractor ( Figure: By Nitianabhigyan - Own...

Start time:
Mo 17 Jun 2019 16:00:00
End time:
Mo 24 Jun 2019 16:00:00

Assignments 1

Subtractor
a) Write predicates for the logical gates: logic xor/3, logic or/3, logic and/3 and logic not/2. E.g. logic xor(0,1,1). should be true. b) Write a predicate subtractor(X,Y,Z,D,BO) using the...