Sei sulla pagina 1di 7

Medical diagnosis

/*trace*/
domains
disease, indication=symbol
name=string
predicates
hypothesis (name,disease)
symptom (name,indication)
response (char)
go
goonce
clauses
go:-
goonce,
write("will you like to try again (y/n)?"),
response (Reply),
Reply='n'.
go.
goonce:-
write("what is the patient's name?"),nl,
readln(Patient),
hypothesis (Patient,Disease),!,
write(Patient, "probably has", Disease),nl.
goonce:-
write("sorry, i am not in position to diagnose"),
write("the disease.").
symptom(Patient,fever):-
write("does",Patient," has a fever (y/n)?"),nl,
response (Reply),
Reply='y',nl.
symptom(Patient,rash):-
write("does", Patient," has a rash (y/n)?"),nl,
response(Reply),
Reply='y',nl.
symptom(Patient,body_ache):-
write("does",Patient," has a body_ache (y/n)?"),nl,
response(Reply),
Reply='y',nl.
symptom(Patient,runny_nose):-
write("does",Patient,"has a runny_nose (y/n)?"),
response(Reply),
Reply='y'.
hypothesis(Patient,flu):-
symptom(patient,fever),
symptom(Patient,body_ache).
hypothesis(Patient,common_cold):-
symptom(Patient,body_ache),
symptom(Patient,runny_nose).
response(Reply):-
readchar(Reply),
write(Reply).
goal
makewindow(1,7,7,"EXPERT MEDICAL DIAGNOSIS",2,2,23,70),
go.
output
Family
/*trace*/
domains
name=symbol
predicates
father(name,name)
g_father(name,name)
brother(name,name)
clauses
father(dashrath,ram).
father(dashrath,lakshman).
father(ram,lov).
father(ram,kush).
g_father(X,Z):-
father(X,Y),
father(Y,Z).
brother(X,Y):-
father(Z,X),
father(Z,Y),
X<>Y.
output

Fi
le handling

domains
file = temp_fl
Undefined = symbol
Sym,Sym1,Sym2 = integer
Sym3,Int = integer
predicates
exec
process(integer)
readfile
openthefile
repeat
check(integer)
clauses
exec :-
makewindow(1,7,7,"File Operations",0,0,25,80),nl,
write("\tOPERATIONS SUPPORTED ..."),nl,
write("\t 1 > Enter write data for new file "),nl,
write("\t 2 > Enter write data to append to file "),nl,
write("\t 3 > Enter write data for modifying contents of file "),nl,
write("\t 4 > Read file contents "),nl,
write("\t 5 > Exit program "),nl,
write("\t Enter selection : "),
readint (Int),
process(Int).

process(Var) :-
Var = 1,nl,
makewindow(1,7,7,"File Write Operation",0,0,25,80),nl,
write("Enter string to write to file : "),
readln(Sym1),
openwrite(temp_fl,"file1.pro"),
writedevice(temp_fl),nl,
write(Sym1),
closefile(temp_fl),
write("Writing to file ..."),
/*readchar(Undefined),*/
readchar(_),
check(Var).
process(Var) :-
Var = 2,nl,
makewindow(1,7,7,"File Append Operation",0,0,25,80),nl,
write("Enter string to append : "),
readln(Sym1),
openappend(temp_fl,"file1.pro"),
writedevice(temp_fl),nl,
write(Sym1),
closefile(temp_fl),
write("Writing to file ..."),
/*readchar(Undefined),*/
readchar(_),
check(Var).
process(Var) :-
Var = 3,nl,
makewindow(1,7,7,"File Modify Operation",0,0,25,80),nl,
write("Enter new string to be used to modify the file : "),
readln(Sym2),nl,
write("Enter file position to be changed ( from start ) : "),
readint(Sym3),
openmodify(temp_fl,"file1.pro"),
filepos(temp_fl,Sym3,0),
writedevice(temp_fl),
write(Sym2),
closefile(temp_fl),
write("Writing to file ..."),
readchar(_),
check(Var).
process(Var) :-
Var = 4,nl,
makewindow(1,7,7,"File Read Operation",0,0,25,80),nl,
write("\t Reading file contents "),nl,
openthefile,
readfile,
check(Var).
openthefile:-
openread(temp_fl,"file1.pro"),
readdevice(temp_fl),
writedevice(screen).

check(Var) :-
not(5 = Var),
exec.
check(Var):-
Var= 5,!.
readfile:-
not(eof(temp_fl)),
readln(S),
write(S),nl,
repeat. /* exit condn . */
readfile :-
nl,write("\t End of file "),
readdevice(keyboard),
readchar(_),
closefile(temp_fl).
repeat:-
readfile.
goal
exec.

output

Login
domains
name,password=symbol
predicates
logon
getinput(name,Password)
user(name,password)
clauses
logon:-
clearwindow,
getinput(Name,Password),
write("u can work").
logon:-
write("u are not allowed pl try again"),
logon.
getinput(Name,Password):-
write("enter ur name pl"),
readln(Name),
write("enter ur password pl"),nl,
readln(Password),
user(Name,Password).
user(deepankar,hb).
user(akshay,aksethi).
user(ikshwansu,iksh).
user(krishna,kc).
/*
goal:-
clearwindow,
logon.*/
output

Login graphical
domains
name,password=symbol
predicates
logon
getinput(name,Password)
user(name,password)
clauses
logon:-
getinput(name,password),nl,
/*write("u can work"),*/
clearwindow,
makewindow(2,7,7,"U CAN WORK EDITOR",4,4,18,50),nl,
cursor(12,12),
edit(" ",_).
logon:-
write("u are not allowed pl try again"),
logon.
getinput(_,_):-
write("enter ur name pl"),nl,
readln(Name),
write("enter ur password pl"),nl,
attribute(0),
readln(Password),
attribute(7),
user(Name,Password).
user(rp,arora).
user(mona,ar).
user(xx,aa).
goal
clearwindow,
makewindow(1,7,7,"NAME_PASSWORD",2,3,20,60),
logon.

Output

Prolog in SWI PROLOG


Factorial
factorial(0,1).
factorial(A,B):-
A>0,
C is A-1,
factorial(C,D),
B is A*D.
yes
output
% library(win_menu) compiled into win_menu 0.00 sec, 11,948 bytes
% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 2,188 bytes
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.10.2)
Copyright (c) 1990-2010 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?-
% c:/Users/deepankar/Desktop/ai/fact.pl compiled 0.00 sec, 1,160 bytes
1 ?-
| factorial(10,What).
What = 3628
Fibonacci
fib(0, 1).
fib(1, 1).
fib(X, Y):-
X > 1, X1 is X - 1, X2 is X - 2, fib(X1, Z), fib(X2, W), Y is W + Z.
Output
% library(win_menu) compiled into win_menu 0.00 sec, 11,948 bytes
% library(swi_hooks) compiled into pce_swi_hooks 0.00 sec, 2,188 bytes
Welcome to SWI-Prolog (Multi-threaded, 32 bits, Version 5.10.2)
Copyright (c) 1990-2010 University of Amsterdam, VU Amsterdam
SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to redistribute it under certain conditions.
Please visit http://www.swi-prolog.org for details.
For help, use ?- help(Topic). or ?- apropos(Word).
1 ?-
% c:/Users/deepankar/Desktop/ai/fib.pro compiled 0.00 sec, 1,196 bytes
1 ?-
| fib(10,What).
What = 89

Potrebbero piacerti anche