A R T I F I C I A L  I N T E L L I G E N C E  ( A I )
 

1.

Inroduction To PROLOG.
domains
disease,indication = symbol

predicates
symptom(disease,indication)

clauses
symptom(chicken_pox,high_fever).
symptom(chicken_pox,chills).
symptom(flu,chills).
symptom(cold,mild_body_ache).
symptom(flu,severe_body_ache).
symptom(cold,runny_nose).
symptom(flu,runny_nose).
symptom(flu,moderate_cough)

2.A

A simulated medical diagnostic system for childhood diseseas.
  domains
disease,indication,names = symbol

predicates
hypothesis(names,disease)
symptom(names,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,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).

hypothesis(Patient,flu) :-
symptom(Patient,fever),
symptom(Patient,headache),
symptom(Patient,body_ache),
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,sneezing),
symptom(Patient,sore_throat),
symptom(Patient,chills),
symptom(Patient,runny_nose).

hypothesis(Patient,mumps) :-
symptom(Patient,fever),
symptom(Patient,swollen_glands).

hypothesis(Patient,chicken_pox) :-
symptom(Patient,fever),
symptom(Patient,rash),
symptom(Patient,body_ache),
symptom(Patient,chills).

hypothesis(Patient,whooping_cough) :-
symptom(Patient,cough),
symptom(Patient,sneezing),
symptom(Patient,runny_nose).

2.B

The revised medical diagnostic progarm for childhood diseseas.
domains
disease, indication, name = symbol
patient = string

predicates
hypothesis(name,disease)
symptom(name,indication)
response(char)
go

clauses
go :-
write("What is the patient's name? "),
readln(Patient),
hypothesis(Patient,Disease),
write(Patient," probably has ",Disease,"."),nl.

go :-
write("Sorry, I don't seem to be able to"),nl,
write("digose the disease."),nl.

symptom(Patient,fever) :-
write("Dose ",Patient," have a fever (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,rash) :-
write("Dose ",Patient," have a rash (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,headache) :-
write("Dose ",Patient," have a headache (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,runny_nose) :-
write("Dose ",Patient," have a runny_nose (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,conjustivitis) :-
write("Dose ",Patient," have a conjustivitis (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,cough) :-
write("Dose ",Patient," have a cough (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,body_ache) :-
write("Dose ",Patient," have a body_ache (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,chills) :-
write("Dose ",Patient," have a chills (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,sore_throat) :-
write("Dose ",Patient," have a sore_throat (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,sneezing) :-
write("Dose ",Patient," have a sneezing (y/n) ?"),nl,
response(Reply),
Reply='y'.

symptom(Patient,swollen_glands) :-
write("Dose ",Patient," have a swollen_glands (y/n) ?"),nl,
response(Reply),
Reply='y'.

hypothesis(Patient,measles) :-
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).

hypothesis(Patient,flu) :-
symptom(Patient,fever),
symptom(Patient,headache),
symptom(Patient,body_ache),
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,sneezing),
symptom(Patient,sore_throat),
symptom(Patient,chills),
symptom(Patient,runny_nose).

hypothesis(Patient,mumps) :-
symptom(Patient,fever),
symptom(Patient,swollen_glands).

hypothesis(Patient,chicken_pox) :-
symptom(Patient,fever),
symptom(Patient,rash),
symptom(Patient,body_ache),
symptom(Patient,chills).

hypothesis(Patient,whooping_cough) :-
symptom(Patient,cough),
symptom(Patient,sneezing),
symptom(Patient,runny_nose).

response(Reply) :-
readchar(Reply),
write(Reply),nl.

3. Random File Access.
domains
file = inputdata

predicates
go
check_pos(integer)
repeat

clauses
go :-
write("Please enter file name: "),
readln(Filename),
openread(inputdata,Filename),
repeat,
readdevice(keyboard),
check_pos(X),
X = 999,
closefile(inputdata).

check_pos(Data) :-
nl,write("Position: "),
readreal(Pos),
readdevice(inputdata),
filepos(inputdata,Pos,0),
readchar(Data),
write(Data).
repeat.
repeat :-
repeat.

4. Username Password
domains
name, password = symbol

predicates
getinput(name,password)
logon
user(name,password)
repeat

clauses
repeat.
repeat :-
repeat.

logon :-
clearwindow,
getinput(_,_),
write("You are now logged on."),nl.

logon :-
repeat,
write("Sorry, you are not permitted access."),nl,
write("Please try again."),nl,
getinput(_,_),
write("You are now logged on."),nl.

getinput(Name,Password) :-
write("Please Enter Your Name: "),
readln(Name),nl,
write("Please Enter Password: "),
readln(Password),nl,
user(Name,Password).

user(skumar,matrix).
user(sumit,matrix1).
user(abhinav,matrix2).

5. The Cut Predicate.
predicates
location(string,string).
go
chkstate(string)

clauses
go :-
writef("%-10 %5 \n","CITY","STATE"),
fail.
go :-
location(City,State),
chkstate(State),
writef("%-10 %5 \n","CITY","STATE"),
fail.
go.
location("Jackson","MS").
location("Washington","DC").
location("Raleigh","NC").

chkstate("DC") :-
!,fail.
chkstate(_).

6. Arithmatic Operation.
predicates
go
equal(real,real)
clauses
go :-
X = sqrt(2),
equal(X,1.414),
write(X).
equal(X,Y) :-
X/Y > 0.99,
X/Y < 1.01.

7. Medical diagnostic system with dynamic database.
domains
disease, symptom = symbol
query = string
reply = char

database
xpositive(symptom)
xnegative(symptom)

predicates
hypothesis(disease)
symptom(symptom)
response(reply)
go
positive(query,symptom)
clear_facts
remember(symptom,reply)
ask(query,symptom,reply)

clauses
go :-
clearwindow,
hypothesis(Diesease),!,
write("The patient probably has ",Disease),nl,
clear_facts.

go :-
write("Sorry, I don't seem to be able to"),nl,
write("digose the diesease."),nl,clear_facts.

positive(_,Symptom) :-
xpositive(Symptom),!.

positive(Query,Symptom) :-
not(xnegative(Symptom)),
ask(Query,Symptom,Reply),
Reply='y'.

ask(Query,Symptom,Reply) :-
write(Query),nl,
readchar(Reply),
write(Reply),nl,
remember(Symptom,Reply).

remember(Symptom,'y') :-
asserta(xpositive(Symptom)).

remember(Symptom,'n') :-
asserta(xnegative(Symptom)).

clear_facts :-
retract(xpositive(_)),fail.

clear_facts :-
retract(xnegative(_)),fail.

clear_facts.

symptom(fever) :-
write("Dose the patient have a fever (y/n) ?",fever).

symptom(rash) :-
write("Dose the patient have a rash (y/n) ?",rash).

symptom(headache) :-
write("Dose the patient have a headache (y/n) ?",headache).

symptom(runny_nose) :-
write("Dose the patient have a runny_nose (y/n) ?",runny_nose).

symptom(conjustivitis) :-
write("Dose the patient have a conjustivitis (y/n) ?",conjustivitis).

symptom(cough) :-
write("Dose the patient have a cough (y/n) ?",cough).

symptom(body_ache) :-
write("Dose the patient have a body_ache (y/n) ?",body_ache).

symptom(chills) :-
write("Dose the patient have a chills (y/n) ?",chills).

symptom(sore_throat) :-
write("Dose the patient have a sore_throat (y/n) ?",sore_throat).

symptom(sneezing) :-
write("Dose the patient have a sneezing (y/n) ?",sneezing).

symptom(swollen_glands) :-
write("Dose the patient have a swollen_glands (y/n) ?",swollen_glands).

hypothesis(measles) :-
symptom(fever),
symptom(cough),
symptom(conjunctivities),
symptom(runny_nose),
symptom(rash).

hypothesis(german_measles) :-
symptom(fever),
symptom(headache),
symptom(runny_nose),
symptom(rash).

hypothesis(flu) :-
symptom(fever),
symptom(headache),
symptom(body_ache),
symptom(conjunctivitis),
symptom(chills),
symptom(sore_throat),
symptom(cough),
symptom(runny_nose).

hypothesis(common_cold) :-
symptom(headache),
symptom(sneezing),
symptom(sore_throat),
symptom(chills),
symptom(runny_nose).

hypothesis(mumps) :-
symptom(fever),
symptom(swollen_glands).

hypothesis(chicken_pox) :-
symptom(fever),
symptom(rash),
symptom(body_ache),
symptom(chills).

hypothesis(whooping_cough) :-
symptom(cough),
symptom(sneezing),
symptom(runny_nose).

response(Reply) :-
readchar(Reply),
write(Reply),nl.
 

 

Previous << Hoindex.htmme >> Next

   Page last modified:
© 2004  k.skumar &Group. 
     All rights reserved.  
 
      March 14, 2004