Homework 4
This homework is due on Tuesday December 3rd (This deadline is
immutable).
This homework deals with Logic Programming, C and Memory management.
This homework is to be done in a group of two students by following
the rules of 'Extreme Mathematical Thinking' and 'Pair
Programming'. Take advantage of working in group. The groups
are assigned. Each group has a number. You can find the email of your
group member in Blackboard. If you are alone it means that you asked
me to be alone or I do not have enough information (grades) to assign
you a group.
You have to submit a report on your group member. These reports can be
given apart (but must be given on the due date). In case of problem with
your group member during the time of the homework please contact me
(but you cannot change group). Your grade will be based on the reports
you will submit. It means that if you are in the same group it does
NOT mean you will have the same grade.
Students have to hand-in a hard-copy with their answers and the
listing of all their PROLOG, JAVA and C code. The presentation of your
homework will be taken into account and you have to do the questions
in order. The code must be accessible from matrix in the directory
called CS361/HW4/. ALL your PROLOG code must be saved in a directory
called PROLOG. ALL your JAVA code must be saved in a directory called
JAVA. The JAVA code you write must be clear and commented. ALL your C
code must be saved in a directory called C. All the explanations to
access the code on matrix must be provided on the cover page of your
hard-copy.
All the names (names of directories, files, classes, methods, ...)
must be respected (exactly) for automated testing.
1. Do set 3 in WeBWorK (Select the text-formatted option
before accessing the problems).
2. PROLOG
a. British Royal Family
- Write the program of the notes concerning the British Royal
Family in PROLOG.
- Add and define a predicate Female such that
Female(X) means that X is a female.
- Add and define a predicate Mother(X,Y) such that
Mother(X,Y) means that X is the mother of Y.
b. Logic Programming
Do the following proofs and verify them using the Logic programming
software. You may abbreviate the names of the predicates provided
below. You have to provide the proofs in your handout. You have to
provide a screen snapshot of the proof you did in the Logic
programming software.
If you notice any bug in the software write a bug report
explaining what is the bug, how and when you met it. I must be able to
replay the bug. If you submit a bug that is not a bug you will loose
credit.
The software is accessible on matrix
(~cscharff/Logical*). Copy all the files Logical*.class (cp ~cscharff/Logical* .)
and run it.
- If you group number is odd do the following exercises:
mortalSocrates <- manSocrates
manSocrates <-
Prove that mortalSocrates is true.
square <- rectangle, equalsides
rectangle <- parallelogram, rightangles
parallelogram <-
rightangles <-
equalsides <-
Prove that square is true.
- If you group number is even do the following exercises:
takeumbrella <- itrains
itrains <-
Prove that takeumbrella is true.
catFelix <- FelineFelix, mammalFelix
hasclawsFelix <-
FelineFelix <- whiskeredFelix, hasclawsFelix
mammalFelix <-
whiskeredFelix <-
Prove that catFelix is true.
Extra-credit 1: Find a name for the software. If there is a
name I like the winner will have 5 points of extra-credit for
the homework.
Extra-credit 2: Do the following proofs:
Proof 1:
p<-q,r
t<-p,s
s<-a,b
a<-
b<-
q<-
r<-
Prove that t is true.
Proof 2:
k<-r,a
r<-u,w
u<-
w<-a
a<-b,c
b<-
c<-
Prove that k is true.
Extra-credit 3: Practice with the Unification software
(instructions will be posted in Blackboard).
3. C
This is a C program called prog.c.
#include <stdio.h>
main()
{
int i = 0;
int A[10] = {3,5,6,7,8,8,3,23,6,7};
for (i=0; i<11; i=i+1)
printf("\n A[%d] = %d\n",i,A[i]);
}
Compile it (cc prog.c) and use it (./a.out). What do you
think about this program? Correct it if necessary. Write the same
program in JAVA and compare C and JAVA on this example.
4. Memory management
a. Do exercises 5.1 and 5.3 in the book. You have to be very
precise and use the book notations.
b.What are the different algorithms of garbage collector that
exist? (Make a list only)