Beruflich Dokumente
Kultur Dokumente
IS GREATER THAN 15 AND LIVING IN RAJKOT 3] STUDENTS WHO HAS MORE THAN 60 % domains predicates student(symbol,symbol,integer,integer) clauses student("Sita","Rajkot",20,70). student("Rita","Delhi",35,55). student("Nita","Bangalore",19,90). student("Mita","Rajkot",55,30). student("Hita","Mumbai",60,67).
Page 1
Practical:-3
AIM: A Simple Program Using Rule predicates food(symbol) taste(symbol, symbol) likes(symbol, symbol) clauses likes(bill,Food):-food(Food),taste(Food,good). food(pizza). food(samosa). taste(pizza,good). taste(samosa,good). Output: Goal: likes (bill, What). What= pizza What= samosa Define predicates location (city, state).print all cities except Delhi using NOT predicate predicates find location(String,String) chkcity(String) clauses location("ahmedabad","gujrat"). location("delhi","up"). location("bhopal","mp"). location("jaipur","rajsthan"). chkcity("delhi"). find:writef("%10 %-5","City","State"),nl,fail. find:location(City,State), not (chkcity(City)), writef("%10 %-5",City,State),nl, fail.
Prepared By Kaushik Raviya (Assistant Professor CSE/IT) Page 2
A Simple program using Backtracking. ANS:human(socrates). human(aristotle). human(plato). god(zeus). god(apollo). mortal(X) :- human(X). mortal_report :write('Report of all known mortals'), nl, nl, mortal(X), write(X), nl, fail. human_report :write(heading), human(X), write(X), fail. goal: mortal_report. Report of all known mortals socrates aristotle plato yes With given database of statements, write the goal statements that gives answers to following questions: Database : Hobbies 1. Mamta ,Ekta, Manan, Hetal and Rakhi are persons. 2. Mamta likes reading and music. 3. Ekta likes eating. 4. hetal likes reading. 5. Manan likes traveling and eating. 6. Rakhi likes music and reading. 7. Manna likes reading and music.
Prepared By Kaushik Raviya (Assistant Professor CSE/IT) Page 3
Question. 1. Display the persons that enjoy reading. 2. Display all the persons that enjoy reading as well as music 3. Display the persons that enjoy all the hobbies. 4. Display the person that enjoys the thing enjoy by person1. 5. Display the person that enjoys the thing enjoy by person1 as well asperson2. 6. Display the person that enjoys nothing. 7. Display the person that enjoys the thing not enjoy by person1. ANS:person(mamta). person(Ekta). person(manan). person(hetal). person(rakhi). likes(mamta, music). likes(mamta, reading). likes(ekta, eating). likes(hetal, reading). likes(manan, traveling). likes(manan, eating). likes(rakhi, music). likes(rakhi, reading). likes(manan, music). likes(manan, reading). 1) goal: likes(X, reading). output: X=mamta, hetal, rakhi, manan 2) goal: likes(X, reading) and likes(X, music). output: X=mamta, rakhi, manan 3) goal: likes(X, reading) and likes(X, music) and likes(X, eating) and likes(X, traveling). output: X=false 4) goal: likes(mamta, X) and likes(Y, X) output: X=reading, music Y=rakhi, manan 5) goal: likes(mamta, X) and likes(ekta, X) and (Y, X). output: X=false Y=false
Prepared By Kaushik Raviya (Assistant Professor CSE/IT) Page 4
Practical 4 Aim: - Write a program to find the maximum and minimum from the given numbers.
domains A,B,C = integer predicates max(integer,integer,integer) min(integer,integer,integer) go clauses go:write("Enter number 1:"), readint(A), write("Enter number 2:"), readint(B), write("Enter number 3:"), readint(C), max(A,B,C), min(A,B,C). max(A,B,C):A>B,A>C,write(A," is the largest"),nl. max(A,B,C):B>A,B>C,write(B," is the largest"),nl. max(A,B,C):C>B,C>A,write(C," is the largest"),nl. min(A,B,C):A<B,A<C,write(A," is the smallest"),nl. min(A,B,C):B<A,B<C,write(B," is the smallest"),nl. min(A,B,C):C<B,C<A,write(C," is the smallest"),nl. Output:Enter number 1: 12 Enter number 2: 23 Enter number 3: 9 23 is the largest 9 is the smallest Yes
Page 5
readln(Password), try(Username, Password), write("Successful Login"). try("artificial","intelligence"). try("kaushik","raviya"). %-----------OUTPUT-------------Goal: logon. Enter username: kaushik Enter password: raviya Successful Login
Page 7
Practical 5:
Write a Program to Demonstrate the FAIL Predicate. predicates location(string,string) go clauses go:location(City,State), writef("%-10 %5 \n",City,State), fail. go. location("Junagadh","Gujarat"). location("Abu","Rajsthan"). location("Shahda","Maharashtra"). Output: Goal: go City Junagadh Abu Shahda
getinput(Name,Pass):write("Enter username : "), readln(Name), write("Enter password : "), readln(Pass). user("kaushik","raviya"). user("artificial","intelligence"). Output Goal: logon. Enter username: kaushik Enter password: raviya Successful Login
Page 10
AIM: Write a program to input character and check if the character is lowercase alphabet and uppercase alphabet or digit.
predicates go check(char) clauses go:write("Enter a character : "), readchar(A), check(A), nl. check(A):A>='A', A<='Z', write("Upper case : ", A). check(A):A>='a', A<='z', write("lower case : ", A). check(A):A>='0', A<='9', write("Digit : ",A). Output: Goal: go. Enter a character: A Upper case Yes.
Page 11
Page 12