Vous êtes sur la page 1sur 13

ARTIFICIAL

INTELLIGENCE

LAB FILE

AMITY SCHOOL OF ENGINEERING & TECHNOLOGY

SUBMITTED TO: BY:


MS. RUPALI ROHANKAR KAPIL DEPT. OF CSE 478 ASET

SUBMITTED
ANSH ROLL NO.: SECTION: 7CS-2 SEMESTER: VII

INDEX
S.No . 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. Experiment Show Arithmetic Operations Add, Subtract, Multiply, Divide Find GCD & LCM Find HCF Print a string N times To find Factorial of a no. Print next number of fibonacii series Print table of a number Disease problem To find simple interest Logic Problem Date Remarks

EXPERIMENT 1 AIM: Show Arithmetic Operations Add, Subtract, Multiply, Divide domains A=integer predicates num(A,A). clauses num(A,B):C=A+B, D=A-B, E=A*B, F=A/B, write("Sum: ",C), write("\nDifference: ",D), write("\nProduct: ",E), write("\nDivision: ",F), write("\n"). Output:

EXPERIMENT 2 AIM: Find GCD & LCM domains num,result=integer predicates lcm(num,num) lcm(num,num,result) gcd(num,num) gcd(num,num,result) clauses lcm(X1,X2):lcm(X1,X2,Y),write(Y),nl. lcm(X1,X2,Y):gcd(X1,X2,Y1),Y=X1*X2/Y1. gcd(X1,X2):gcd(X1,X2,Y),write(Y),nl. gcd(X1,0,Y):Y=X1. gcd(X1,X2,Y):X1=X2,Y=X2. gcd(X1,X2,Y):X1<X2,gcd(X2,X1,Y). gcd(X1,X2,Y):X3=X1 mod X2, gcd(X2,X3,Y). Output:

EXPERIMENT 3 AIM: Find HCF domains P=integer predicates hcf(P,P,P). clauses hcf(A,B,HCF):- A=B,HCF=A. hcf(A,B,HCF):- A<B,NB=B-A,hcf(A,NB,HCF). hcf(A,B,HCF):- A>B,NA=A-B,hcf(NA,B,HCF). Output:

EXPERIMENT 4 AIM: Print a string N times domains P=integer predicates times(P). clauses times(0). times(P):P1=P-1, write("Hello \n"), times(P1). Output:

EXPERIMENT 5 AIM: To find Factorial of a no. domains A=integer. predicates fact(A,A). clauses fact(1,1). fact(X,Y):X1=X-1, fact(X1,Y1), Y=X*Y1. Output:

EXPERIMENT 6 AIM: Print next number of fibonacii series domains A=integer. predicates fib(A,A). clauses fib(0,1). fib(1,1). fib(N,F):N>1, N1=N-1, N2=N-2, fib(N1,F1), fib(N2,F2), F=F1+F2. Output:

EXPERIMENT 7 AIM: Print table of a number Domains A=integer Predicates print(A,A). table(A). Clauses table(A):print(A,10). print(A,0):A=A. print(A,B):D=B-1, C=10-D, E=A*C, write(A,"*",C," = ",E), write("\n"), print(A,D). Output:

EXPERIMENT 8 AIM: Disease problem 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):clearwindow, symptom(Patient,fever), symptom(Patient,cough), symptom(Patient,conjunctivities), symptom(Patient,runny_nose), symptom(Patient,rash). hypothesis(Patient,german_measles):- symptom(Patient,fever), symptom(Patient,headache), symptom(Patient,runny_nose), symptom(Patient,rash). Output:

EXPERIMENT 9 AIM: To find simple interest domains n=integer. predicates si(n,n,n). clauses si(A,B,C):D=(A*B*C)/100. write(Simple Interest=,D,\n). Output:

EXPERIMENT 10 AIM: Logic Problem Domains P=Symbol. Predicates Born(P,integer). Male(P). Female(P). Parent(P,P). Father(P). Father(P,P). Mother(P,P). Sister(P,P). Brother(P,P). Son(P,P). Daughter(P,P). Uncle(P,P). Aunt(P,P). Child(P,P). WifeOf(P,P). HusbandOf(P,P). GrandFather(P,P). GrandMother(P,P). Person(symbol). Age(symbol,integer). Elder_Brother(P,P). Constants Now=2008. Clauses Person(X) if Male(X) ; Female(X). Age(X,A) if Person(X) , Born(X,Y). Born("rajiv",1999). Born("sanjay",1950). Father("motilal" , "jawaharlal"). Father("jawaharlal" , "indira"). Father("feroz" , "rajiv"). Father("feroz" , "sanjay"). Father("rajiv" , "rahul"). Father("rajiv" , "priyanka"). Father(X) if Father(X,_). Male(rahul) WifeOf("menka" , "sanjay"). WifeOf("sanjay" , "rajiv"). WifeOf("indira" , "feroz"). Female(priyanka). Female(X):- WifeOf(Y,X).

Elder_Brother(A,B) if eelder_brother. Parent(X,Y) :- Father(X,Y),Mother(X,Y). Mother(X,Y) :- WifeOf(X,Z),Father(Z,Y). Child(X,Y) :- Parent(Y,X). Son(X,Y) :- Child(X,Y) , Male(X). Daughter(X,Y) :- Child(X,Y) , Female(X). Brother(X,Y) :- Father(Z,X) , Father(Z,Y), Male(X) , not(X=Y). Sister(X,Y) :- Father(Z,X) , Father(Z,Y), Female(X) , not(X=Y). Aunt(X,Y) if Sister(X,Z) , Parent(Z,Y). Aunt(X,Y) :- WifeOf(X,Z) , Uncle(Z,Y). Grandfather(X,Y) :- Parent(X,Z), Parent(Z,Y) , Male(X). Grandmother(X,Y) :- Parent(X,Z), Parent(Z,Y) , Female(X). Output:

Vous aimerez peut-être aussi