PRACTICAL-1 8 th I.T. En.No.:080240116057
PRACTICAL-1
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)
clauses male(alan). male(charles). male(bob). male(ivan).
female(beverly). female(fay).
8th I.T.
En.No.:080240116057
female(marilyn). female(sally).
mother(marilyn,beverly). mother(alan,sally).
father(alan,bob). father(beverly,charles). father(fay,bob). father(marilyn,alan).
parent(X,Y) if mother(X,Y). parent(X,Y) if father(X,Y).
brother(X,Y) if male(Y) and
/*The brother of X is Y if */ /*Y is a male and */
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 */
sister(X,Y) if female(Y) and
/*The sister of X is Y if */ /*Y is female and */
parent(X,P) and /*the parent of X is P and */
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 */
father(X,P) and /*the father of X is P and */ brother(P,U). /*the brother of P is U */
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).
hypothesis(patient,german_measles):symptom(patient,fever), symptom(patient,headache), symptom(patient,runny_nose),
8th I.T.
En.No.:080240116057
symptom(patient,rash).
hypothesis(patient,flu):symptom(patient,fever), symptom(patient,headache), symptom(patient,bodyache), symptom(patient,conjunctivitis), symptom(patient,chills), symptom(patient,sore_throat), symptom(patient,cough), symptom(patient,runny_nose).
hypothesis(patient,common_cold):symptom(patient,headache), symptom(patient,snezzing), symptom(patient,sore_throat), symptom(patient,chills), symptom(patient,runny_nose).
hypothesis(patient,mumps):symptom(patient,fever), symptom(patient,swollen_glands).
8th I.T.
En.No.:080240116057
hypothesis(patient,chicken_pox):symptom(patient,fever), symptom(patient,rash), symptom(patient,bodyache), symptom(patient,chills).
hypothesis(patient,whooping_cough):symptom(patient,cough), symptom(patient,snezzing), symptom(patient,runny_nose).
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).
mysqrt(X,Guess,Root) :NewGuess = Guess-(Guess*Guess-X)/2/Guess, not(equal(NewGuess,Guess)),!, mysqrt(X,NewGuess,Root).
8th I.T.
En.No.:080240116057
mysqrt(_,Guess,Guess).
equal(X,Y) :X/Y > 0.99999 , X/Y < 1.00001.
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]).
(B)- Aim: Write a Turbo PROLOG program based on Writing list.
domains list=symbol* predicates writelist(list) clauses writelist([]). writelist([Head|Tail]):write(Head),nl,writelist(Tail).8th I.T. En.No.:080240116057
(C)-Aim: Write a Turbo PROLOG program based on Reversing a list.
domains list=integer * predicates reverse_list(list,list) reverse(list,list,list) clauses reverse_list(Inputlist,Outputlist):reverse(Inputlist,[],Outputlist). reverse([],Inputlist,Inputlist). reverse([Head|Tail],List1,List2):reverse(Tail,[Head|List1],List2).
(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
write("please enter yr name:"), readln(Name),nl, write("enter password:"),nl. readln(Password),nl, user(Name,Password). user(bill,bigfoot).
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
(B)-Aim: Write a Turbo PROLOG program based on Fibonaci series.
predicates go fibo(integer,integer,integer)
clauses go:write("enter no="), readint(X), fibo(0,1,X).
fibo(_,_,1):write("1"),nl,write("1").
fibo(A,B,C):BB, 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
min(A,B,C):A