Beruflich Dokumente
Kultur Dokumente
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program for Family Relationship. domains person = symbol
predicates male(person) female(person) father(person,person) mother(person,person) sister(person,person) parent(person,person) brother(person,person) uncle(person,person) grandfather(person,person)
female(beverly). female(fay).
8th I.T.
En.No.:080240116057
female(marilyn). female(sally).
mother(marilyn,beverly). mother(alan,sally).
parent(X,P) and /*the parent of X is P and */ parent(Y,P) and /*the parent of Y is P and */ X <> Y. /* X and Y are not the same */
8th I.T.
En.No.:080240116057
parent(Y,P) and /*the parent of Y is P and */ X <> Y. /*X and Y are not the same */
uncle(X,U) if
/*The uncle of X is U if */
mother(X,P) and /*the mother of X is P and */ brother(P,U). uncle(X,U) if /*the brother of P is U. */ /*The uncle of X is U if */
grandfather(X,G) if /*The grandfather of X is G */ father(P,G) and /*if the father of P is G */ mother(X,P). /*and the mother of X is P. */
grandfather(X,G) if /*The grandfather of X is G */ father(X,P) and /*if the father of X is P */ father(P,G). /*the father of P is G */
8th I.T.
En.No.:080240116057
PRACTICAL-2
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program that list four address in a label form, each address should list a name, one-line address, city, state &ZIP code.
predicates reference(symbol,symbol) goal write("Please type a name :"), readln(The_Name), reference(The_Name,Address,City,State,Zipcode), write("The Address is ",Address). write("The City is ",City). write("The State is ",State). write("The Zipcode is ",Zipcode). clauses reference("Albert","df", "hmt","guj","231565"). reference("Betty", "ew", "abd","guj","458979"). reference("Carol", "sdf", "surat","guj","6789"). reference("Dorothy","sf","nd","guj","488979").
8th I.T.
En.No.:080240116057
PRACTICAL-3
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program for diagnosis the childhood diseases. domains disease,indication,name = symbol predicates hypothesis(name,disease) symptom(name,indication) clauses symptom(charlie,fever). symptom(charlie,rash). symptom(charlie,headache). symptom(charlie,runny_nose). hypothesis(patient,measles):symptom(patient,fever), symptom(patient,cough), symptom(patient,conjunctivitis), symptom(patient,runny_nose), symptom(patient,rash).
8th I.T.
En.No.:080240116057
symptom(patient,rash).
hypothesis(patient,mumps):symptom(patient,fever), symptom(patient,swollen_glands).
8th I.T.
En.No.:080240116057
8th I.T.
En.No.:080240116057
PRACTICAL-4
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program to calculate the roots of quadratic equation Consider all possibilities real, equal,imaginary. predicates solve(real,real,real) reply(real,real,real) mysqrt(real,real,real) equal(real,real) clauses solve(A,B,C) :D = B*B-4*A*C, reply(A,B,D), nl. reply(_,_,D) :- D < 0, write("No solution"), !. reply(A,B,D) :D = 0, X=-B/(2*A), write("x=",X), !. reply(A,B,D) :mysqrt(D,D,SqrtD), X1 = (-B + SqrtD)/(2*A), X2 = (-B - SqrtD)/(2*A), write("x1 = ",X1," and x2 = ",X2).
8th I.T.
En.No.:080240116057
mysqrt(_,Guess,Guess).
8th I.T.
En.No.:080240116057
PRACTICAL-5
8th I.T.
En.No.:080240116057
(A)- Aim: Write a Turbo PROLOG program based on simple list. domains namelist=symbol* predicates member(symbol,namelist) club_member(symbol) clauses member(X,[X|_]). member(X,[_|Tail]):member(X,Tail). club_member(Name):member(Name,[alfred,susan,foram,bill,frank,mary]).
(D)-Aim: Write a Turbo PROLOG program based on last Element of a list. domains list =integer * predicates last_ele(list,list) clauses last_ele([Head],X):-
8th I.T.
En.No.:080240116057
X=[Head]. last_ele([_|Tail],X):last_ele(Tail,X).
(E)-Aim: Write a Turbo PROLOG program based on nth Element of a list. domains list =integer * predicates n_element() clauses n_element([Head|_],1,X):X=Head. n_element([_|Tail],N,X):n_element([Head|Tail],N,X):NN=N-1 n_element(Tail,NN,X).
8th I.T.
En.No.:080240116057
PRACTICAL-6
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program Checking for Password. domains name,password=symbol predicates getentry(name,password) logon(integer) user(name,password) go clauses go:logon(3), write("u r now logon:"),nl. logon(0):-!, write("sorry u r not permitted access:"), fail. logon(_):getentry(_,_). logon(X):write("illegal entry:"),nl, XX=X-1, logon(XX). getentry(Name,Password):8th I.T. En.No.:080240116057
8th I.T.
En.No.:080240116057
PRACTICAL-7
8th I.T.
En.No.:080240116057
(A)-Aim: Write a Turbo PROLOG program based on Factorial. domains n, f = real predicates factorial(n,f) clauses factorial(1,1). factorial(N,Res) if N > 0 and N1 = N-1 and factorial(N1,FacN1) and Res = N*FacN1.
8th I.T.
En.No.:080240116057
predicates go fibo(integer,integer,integer)
fibo(_,_,1):write("1"),nl,write("1").
8th I.T.
En.No.:080240116057
PRACTICAL-8
8th I.T.
En.No.:080240116057
Aim: Write a program to find Minimum and Maximum from give Numbers. domains predicates max(integer,integer,integer) min(integer,integer,integer) maxmin(integer,integer,integer) clauses max(A,B,C):A>B, A>C, write(A). max(A,B,C):A>B, write(C). max(_,B,C):B>C, write(B). max(_,_,C):write(C).
8th I.T.
En.No.:080240116057
maxmin(A,B,C):max(A,B,C), min(A,B,C).
8th I.T.
En.No.:080240116057
PRACTICAL-9
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program to implement Tower Of Hanoi Problem. domains loc = right ; middle ; left predicates hanoi(integer) move(integer,loc,loc,loc) inform(loc,loc) clauses hanoi(N) :- move(N,left,middle,right).
8th I.T.
En.No.:080240116057
PRACTICAL-10
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program for finding the average salary of an employee and for adding and deleting employees from the database.
8th I.T.
En.No.:080240116057
PRACTICAL-11
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program to solve Water-Jug Problem. domains j1=integer j2=integer predicates water(j1,j2) water(integer,integer,integer,integer) clauses water(2,B,_,_):-B<4. water(A,_):-A>4,write("Jug One capacity exceeded"). water(_,B):-B>3,write("Jug two capacity exceeded"). water(A,B):-A=4,B=0,X=1,Y=3,write("jug1=",X," ","jug2=",Y). water(P,Q):-P=1,Q=3,P1=1,Q1=0,write("jug1=",P1," ","jug2=",Q1). water(P,Q):-P=1,Q=0,P1=0,Q1=1,write("jug1=",P1," ","jug2=",Q1). water(P,Q):-P=0,Q=1,P1=4,Q1=1,write("jug1=",P1," ","jug2=",Q1). water(P,Q):-P=4,Q=1,P1=2,Q1=3,write("jug1=",P1," ,"jug2=",Q1), write("Solution reached").
8th I.T.
En.No.:080240116057
PRACTICAL-12
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program to demonstrate the effective use of Cut .
predicates location(string,string) go chkstate(string) clauses go:writef("%-10 %5 \n","city","state"), fail. gp:location(city,state), writef("%-10 %2 \n",city,state), fail. go. location("Jackson","MS"). location("washington","DC"). location("Raleigh","NC"). chkstate("DC"):!,fail. chkstate(_).
8th I.T.
En.No.:080240116057
Aim: Write a Turbo PROLOG program to demonstrate the effective use of Fail. predicates location(string,string) go clauses go:location(city,state), writef("%-10 %2 \n",city,state), fail. go. location("Jackson","MS"). location("washington","DC"). location("Raleigh","NC").
8th I.T.
En.No.:080240116057
PRACTICAL-13
8th I.T.
En.No.:080240116057
Domains town = symbol distance = unsigned rib = r(town,town,distance) tlist = town* rlist = rib* predicates nondeterm way(town,town,rlist,distance) nondeterm route(town,town,rlist,tlist,distance) nondeterm route1(town,tlist,rlist,tlist,distance) nondeterm ribsmember(rib,rlist) nondeterm townsmember(town,tlist) nondeterm tsp(town,town,tlist,rlist,tlist,distance) nondeterm ham(town,town,tlist,rlist,tlist,distance) nondeterm shorterRouteExists(town,town,tlist,rlist,distance) nondeterm alltown(tlist,tlist) nondeterm write_list(tlist)
8th I.T.
En.No.:080240116057
clauses write_list([]). write_list([H|T]):write(H,' '), write_list(T). townsmember(X,[X|_]). townsmember(X,[_|L]):townsmember(X,L). ribsmember(r(X,Y,D),[r(X,Y,D)|_]). ribsmember(X,[_|L]):ribsmember(X,L). alltown(_,[]). alltown(Route,[H|T]):townsmember(H,Route), alltown(Route,T). way(Town1,Town2,Ways,OutWayDistance):ribsmember(r(Town1,Town2,D),Ways), OutWayDistance = D. %/* way(Town1,Town2,Ways,OutWayDistance):ribsmember(r(Town2,Town1,D),Ways), OutWayDistance = D.
8th I.T.
En.No.:080240116057
%*/ route(Town1,Town2,Ways,OutRoute,OutDistance):route1(Town1,[Town2],Ways,OutRoute,T1T2Distance), %SWITCH HERE way(Town2,Town1,Ways,LasDist), OutDistance = T1T2Distance + LasDist. route1(Town1,[Town1|Route1],_,[Town1|Route1],OutDistance):OutDistance = 0. route1(Town1,[Town2|PassedRoute],Ways,OutRoute,OutDistance):way(TownX,Town2,Ways,WayDistance), not(townsmember(TownX,PassedRoute)), route1(Town1,[TownX,Town2|PassedRoute],Ways,OutRoute,Completin gRoadDistance), OutDistance = CompletingRoadDistance + WayDistance. shorterRouteExists(Town1,Town2,Towns,Ways,Distance):ham(Town1,Town2,Towns,Ways,_,Other), Other < Distance. tsp(Town1,Town1,Towns,Ways,BestRoute,MinDistance):way(OtherTown,Town1,Ways,_), tsp(Town1,OtherTown,Towns,Ways,BestRoute,MinDistance). tsp(Town1,Town2,Towns,Ways,BestRoute,MinDistance):ham(Town1,Town2,Towns,Ways,Route,Distance),
8th I.T. En.No.:080240116057
not(shorterRouteExists(Town1,Town2,Towns,Ways,Distance)), BestRoute = Route, MinDistance = Distance. ham(Town1,Town2,Towns,Ways,Route,Distance):route(Town1,Town2,Ways,Route,Distance), %SWITCH HERE alltown(Route,Towns), % if you want simple road without including all towns you could uncomment this line write_list(Route), write(" \tD = ",Distance,"\n"). % fail.
8th I.T.
En.No.:080240116057
PRACTICAL-14
8th I.T.
En.No.:080240116057
8th I.T.
En.No.:080240116057
Practical 15
8th I.T.
En.No.:080240116057
domains queen = q(integer,integer) queens=queen* freelist = integer* board=board(queens,freelist,freelist,freelist,freelist) predicates placeN(integer,board,board) place_a_queen(integer,board,board) nqueens(integer) makelist(integer,freelist) findandremove(integer,freelist,freelist) clauses nqueens(N):makelist(N,L),Diagonal=N*2-1,makelist(Diagonal,LL), placeN(N,board([],L,L,LL,LL),Final),write(Final).
placeN(_,board(D,[],[],D1,D2),board(D,[],[],D1,D2)):-!. placeN(N,Board1,Result):place_a_queen(N,Board1,Board2),
8th I.T.
En.No.:080240116057
placeN(N,Board2,Result).
findandremove(X,[X|Rest],Rest). findandremove(X,[Y|Rest],[Y|Tail]):findandremove(X,Rest,Tail).
makelist(1,[1]). makelist(N,[N|Rest]):N>0,N1=N-1,makelist(N1,Rest).
8th I.T.
En.No.:080240116057