THOERY ---LINK
PRACTICAL---
CHAPTER WISE QUESTION----
ASSIGNMENT----
CBCS SYLLABUS-----
FOL PRACTISE--LINK
1.
The Cohen-Sutherland Algorithm
2.
The Sutherland-Hodgman Algorithm
3.
Midpoint Subdivision Algorithm
1.
If P represents 'This book is good' and Q represents 'This
book is cheap', write the following sentences in symbolic form:
(a) This book is good and cheap.
(b) This book is not good but cheap.
(c) This book is costly but good.
(d) This book is neither good nor cheap.
(e) This book is either good or cheap.
2.
Translate the following sentences
into propositional forms:
(a) If it is not raining and I
have the time. then I will go to a movie.
(b) It is raining and I will not
go to a movie.
(c) It is not raining.
(d) I will not go to a movie.
(e) I will go to a movie only if
it is not raining.
Hints:
Let P be the proposition 'It is raining'.
Let Q be the proposition 'I have
the time'.
Let R be the proposition '1 will
go to a movie'.
3.
Write the following sentences in
symbolic form: (
a) This book is interesting but
the exercises are difficult.
(b) This book is interesting but
the subject is difficult.
(c) This book is not interesting.
the exercises are difficult but the subject is not difficult.
(d) If this book is interesting
and the exercises are not difficult then the subject is not difficult.
(e) This book is interesting means
that the subject is not difficult, and conversely.
(f) The subject is not difficult
but this book is interesting and the exercises are difficult.
(g) The subject is not difficult
but the exercises are difficult.
(h) Either the book is interesting
or the subject is difficult.
4.
Derive S from the following
premises using a valid argument:
(i)
P => Q
(ii)
Q => ¬R
(iii)
P v S
(iv)
R
5.
Check the validity of the
following argument:
If Ram has completed B.E.
(Computer Science) or MBA, then he is assured of a good job.
If Ram is assured of a good job, he is happy.
Ram is not happy.
So Ram has not completed MBA.
6.
Express the following sentences
involving predicates in symbolic form:
1. All students are clever.
2. Some students are not
successful.
3. Every clever student is
successful.
4. There are some successful
students who are not clever.
5. Some students are clever and
successful.
7.
Discuss the validity of the
following argument:
All educated persons are well
behaved.
Ram is educated.
No well-behaved person is
quarrelsome.
Therefore. Ram is not quarrelsome.
8.
Test the validity of the following
argument:
Babies are illogical.
Nobody is despised who can manage
a crocodile.
Illogical persons are despised.
Therefore babies cannot manage
crocodiles.
9.
Show that the following argument
is valid:
All men are mortal.
Socrates is a man.
So Socrates is mortal.
10.
Test the validity of the following
argument:
If Ram is clever then Prem is
well-behaved.
If Joe is good then Sam is bad and
Prem is not well-behaved.
If Lal is educated then Joe is
good or Ram is clever.
Hence if Lal is educated and Prem
is not well-behaved then Sam is bad.
15. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List using cut predicate.
maxlist([H],H).
maxlist([H|T],R):-
maxlist(T,M1),
H>=M1,
R is H,!.
maxlist([H|T],R):-
maxlist(T,M1),
H<M1,
R is M1.
OUTPUT:.
maxlist([1,20,2],X).
X = 20
16. Write a Prolog program to implement GCD of two numbers.
gcd(X,0,X).
gcd(X,Y,Z):-
R is mod(X,Y),
gcd(Y,R,Z).
OUTPUT:
gcd(6,9,X).
X = 3
17. Write a prolog program that implements Semantic Networks/Frame Structures.
OUTPUT:
11. Write a Prolog program to implement maxlist(List,Max) so that Max is the greatest number in the list of numbers List.
max([H|T],R):-
length(T,L),
L>0 -> ( max(T,R1), ( H > R1 -> R is H ; R is R1 ) ) ; R is H.
OUTPUT:
max([6,9,7],X).
X = 9
max([6,9,70],X).
X = 70
10. Write a Prolog program to implement max(X,Y,Max) so that Max is the greater of two numbers X and Y.
max(X,Y,R):-
X>=Y ->
R is X,
write(R)
;
R is Y,
write(R).
OUTPUT:
max(2,6,X).
6
X = 6
12. Write a Prolog program to implement sumlist(List,Sum) so that Sum is the sum of a given list of numbers List.
sumlist([],0).
sumlist([H|T],R):-
sumlist(T,R1),
R is H+R1.
OUTPUT:
sumlist([6,9,70],X).
X = 85
14. Write a Prolog program to implement reverse(List,ReversedList) that reverses lists.
reverse([],[]).
reverse([X|T],REV):-reverse(T,R),append(R,[X],REV).
OUTPUT:
reverse([1,2,2],X).
X = [2, 2, 1]
13. Write a Prolog program to implement two predicates evenlength(List) and oddlength(List) so that they are true if their argument is a list of even or odd length respectively.
evenlength:-
write('true --> even').
oddlength:-
write('true --> odd').
oddeven([_|T]):- length(T,L), L>=0 -> ( L1 is L+1, L2 is mod(L1,2), L2=:=0 ->evenlength ; oddlength ).
OUTPUT:
oddeven([5,8,9]).
true
--> odd
1true
oddeven([5,8,6,9]).
true
--> even
1true
8. Write a Prolog program to implement append for two lists.
app([],L,L).
app([X|M],N,[X|Q]):-
app(M,N,Q).
OUTPUT:
app([1,2],[3,4],X).
X = [1, 2, 3, 4]
app([1,2],[],X).
X = [1, 2]
7. Write a Prolog program, remove-nth(Before, After) that asserts the After list is the Before list with the removal of every n‘th item from every list at all levels.
del(1,[_|T],T).
del(P,[X|Y],[X|R]):-
P1 is P-1,
del(P1,Y,R).
dalpos(P,L,R):-
P1 is P-1,
del(P1,L,R1),
del(P,R1,R).
OUTPUT:
del(2,[10,20,30,40],X).
X = [10, 30, 40]
Next101001,000 Stop
9. Write a Prolog program to implement palindrome (List).
pal([]):- write('palindrome').
pal([_]):- write('palindrome').
pal(L) :-
append([H|T], [H], L),
pal(T) ;write('Not a palindrome').
OUTPUT:
pal([1,2,1]).
palindrome
1true
Next101001,000 Stop
pal([1,2,2]).
Not
a palindrome
1true
6. Write a Prolog program to remove the Nth item from a list.
del(1,[_|T],T).
del(P,[X|Y],[X|R]):-
P1 is P-1,
del(P1,Y,R).
OUTPUT:
del(2,[1,2],X).
X = [1]
Next101001,000 Stop
del(3,[1,2,3,4],X).
X = [1, 2, 4]
Next101001,000 Stop
del(5,[1,2,3,4],X).
false
5. Write a prolog program, insert_nth(item, n, into_list, result) that asserts that result is the list into_list with item inserted as the n‘th element into every list at all levels.
insert_nth(Item,1,List,[Item|List]).
insert_nth(Item,Pos,[H|List],[H|Result]):-Pos1 is Pos-1,insert_nth(Item,Pos1,List,Result).
OUTPUT:
4. Write a prolog program to calculate the nth Fibonacci number.
fib(0, 1) :- !.
fib(1, 1) :- !.
fib(N, F) :- N > 1, N1 is N-1, N2 is N-2, fib(N1, F1), fib(N2, F2), F is F1+F2.
OUTPUT:
3. Write a prolog program to calculate the factorial of a given number.
fact(0,1).
fact(N,F):-( N>0, N1 is N-1, fact(N1,F1), F is N*F1).
OUTPUT:
fact(5,N).
N = 120
Next101001,000 Stop