P. 1
AI lab

AI lab

|Views: 48|Likes:
Published by Dheeraj Mishra

More info:

Published by: Dheeraj Mishra on Feb 09, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

07/23/2013

pdf

text

original

List of programs

:-
Predicates in Prolog
Construction of Family tree in Prolog
Building of Haryana Map in prolog
Source code to sort a list of unsorted list using Quick Sort in Prolog
Source code to traverse a grap using BFS in prolog
Source code to traverse a grap using !FS in prolog
!evelop a Medical "#pert System in Prolog
!evelop a "lectrical "#pert System in Prolog
Source code of $-%ueen pro&lem in Prolog
Source code of '-Pu((le pro&lem in Prolog
Program-)
Predicates in Prolog
domains
list=integer*
predicates
union(list,list,list)
member(integer,list)
append(list,list,list)
delete1(integer,list,list)
deleteall(integer,list,list)
occur(integer,list,integer)
replace(integer,integer,list,list)
intersection(list,list,list)
setdiff(list,list,list)
samelist(list,list)
equal(list,list)
equiv(list,list)
rev(list,list)
sum(list,integer)
palin(list)
merger(list,list,list)
clauses
member(X,[X|_]).
member(X,[|!])"#$%X,member(X,!).
delete1(_,[],[]).
delete1(X,[|!1],[|!&])"#$%X,delete1(X,!1,!&).
delete1(X,[X|!1],!1).
deleteall(_,[],[]).
deleteall(X,[|!1],[|!&])"#$%X,deleteall(X,!1,!&).
deleteall(X,[X|!1],!&)"#deleteall(X,!1,!&).
union([],[],[]).
union([],',').
union(',[],').
union([1|!1],[&|!&],[1|(!])"#1=&,union(!1,!&,(!).
union([1|!1],[&|!&],[1|(!])"#1$%&,deleteall(1,[&|!&],('),union(!1,(',(!).
intersection([],[],[]).
intersection([],_,[]).
intersection(_,[],[]).
intersection([1|!1],[&|!&],[1|(!])"#1=&,intersection(!1,!&,(!).
intersection([1|!1],[&|!&],(!)"#1$%&,intersection(!1,[&|!&],(!).
occur(X,[],)).
occur(X,[|!],()"#X=,occur(X,!,*),(=*+1.
occur(X,[|!],()"#X$%,occur(X,!,*),(=*.
setdiff([],[],[]).
setdiff(',[],').
setdiff([],_,[]).
setdiff([1|!1],[&|!&],(!)"#1=&,setdiff(!1,!&,(!).
setdiff([1|!1],[&|!&],[1|(!])"#1$%&,setdiff(!1,[&|!&],(!).
append([],[],[]).
append(',[],').
append([],',').
append([1|!1],'&,[1|!,])"#append(!1,'&,!,).
rev([],[]).
rev([|!],(')"#rev(!,(!),append((!,[],(').
samelist([],[]).
samelist([1|!1],[&|!&])"#1=&,samelist(!1,!&).
equal([],[]).
equal([1|!1],[&|!&])"#member(1,[&|!&]),delete1(1,[&|!&],',),equal(!1,',).
Program-*
Construction of Family tree in Prolog
domains
person=s-mbol
predicates
fat.er(person,person)
mot.er(person,person)
.usband(person,person)
/ife(person,person)
son(person,person)
daug.ter(person,person)
c.ac.a(person,person)
c.ac.i(person,person)
mama(person,person)
mami(person,person)
brot.er(person,person)
sister(person,person)
bua(person,person)
0i0a(person,person)
mausi(person,person)
male(person)
female(person)
dada(person,person)
dadi(person,person)
nana(person,person)
nani(person,person)
b.ab.i(person,person)
clauses
fat.er(1prit.vira01,1ra02apoor1).
fat.er(1prit.vira01,1s.ammi1).
fat.er(1prit.vira01,1s.as.i1).
fat.er(1ra02apoor1,1rand.ir1).
fat.er(1ra02apoor1,1ris.i1).
fat.er(1ra02apoor1,1ra0iv1).
fat.er(1ra02apoor1,1ritu1).
fat.er(1rand.ir1,12aris.ma1).
fat.er(1rand.ir1,12areena1).
fat.er(1ris.i1,1ranveer1).
fat.er(1s.as.i1,12unal1).
fat.er(1s.as.i1,1san0na1).
fat.er(1ra0an1,1ni2.il1).
.usband(1ra02apoor1,12ris.na1).
.usband(1s.ammi1,1geeta1).
.usband(1s.as.i1,10enifer1).
.usband(1rand.ir1,1babita1).
.usband(1ris.i1,1neetu1).
.usband(1ra0an1,1ritu1).
.usband(1san0a-1,12aris.ma1).
.usband(1ni2.il1,1s.e/ta1).
/ife(X,3)"#.usband(3,X).
dada(X,3)"#fat.er(X,4),fat.er(4,3).
dadi(X,3)"#/ife(X,4),dada(4,3).
mot.er(X,3)"#/ife(X,4),fat.er(4,3).
son(X,3)"#fat.er(3,X),male(X).
daug.ter(X,3)"#fat.er(3,X),female(X).
nana(X,3)"#fat.er(X,4),mot.er(4,3).
nani(X,3)"#mot.er(X,4),mot.er(4,3).
brot.er(X,3)"#fat.er(4,3),fat.er(4,X),male(X),X$%3.
sister(X,3)"#fat.er(4,3),fat.er(4,X),female(X),X$%3.
0i0a(X,3)"#.usband(X,4),sister(4,3).
b.ab.i(X,3)"#/ife(X,4),brot.er(4,3).
c.ac.a(X,3)"#brot.er(X,4),fat.er(4,3).
c.ac.i(X,3)"#/ife(X,4),c.ac.a(4,3).
mama(X,3)"#brot.er(X,4),mot.er(4,3).
mami(X,3)"#/ife(X,4),mama(4,3).
mausi(X,3)"#sister(X,4),mot.er(4,3).
bua(X,3)"#sister(X,4),fat.er(4,3).
male(X)"#.usband(X,_).
male(1ra0iv1).
male(12unal1).
male(1ranveer1).
male(1prit.vira01).
female(X)"#/ife(X,_).
female(1san0na1).
female(12areena1).
Program-+
Building of Haryana Map in prolog
domains
cit-=s-mbol
distance=integer
pat.=cit-*
predicates
5oad(cit-,cit-,distance,pat.)
st_route(cit-,cit-,distance,pat.)
rev_route(cit-,cit-,distance,pat.)
append(pat.,pat.,pat.)
reverse(pat.,pat.)
route(cit-,cit-,distance,pat.)
clauses
5oad(1.odal1,1pal/al1,,),[1.odal1]).
5oad(1pal/al1,1fbd1,&6,[1pal/al1]).
5oad(1fbd1,1del.i1,,6,[1fbd1]).
5oad(1del.i1,1sonipat1,76,[1del.i1]).
5oad(1sonipat1,1panipat1,6),[1sonipat1]).
5oad(1panipat1,12arnal1,,6,[1panipat1]).
5oad(12arnal1,1-amunagar1,8),[12arnal1]).
5oad(1-amunagar1,122r1,6),[1-amunagar1]).
5oad(12arnal1,122r1,,6,[12arnal1]).
5oad(122r1,1ambala1,7),[122r1]).
5oad(1ambala1,1c.d1,66,[1ambala1]).
st_route(91,9&,:,;)"#5oad(91,9&,:,;).
st_route(91,9&,:,;)"#
st_route(91,X,:1,;1),5oad(X,9&,:&,;&),:=:1+:&,append(;1,;&,;).
rev_route(91,9&,:,;)"#st_route(9&,91,:,;1),reverse(;1,;).
reverse([],[]).
reverse([|!1],'&)"#reverse(!1,'1),append('1,[],'&).
append([],',').
append(',[],').
append([|!1],'&,[|!,])"#append(!1,'&,!,).
route(91,9&,:,;)"#st_route(91,9&,:,;).
route(91,9&,:,;)"#rev_route(91,9&,:,;).
Program-,
Source code to sort a list of unsorted list using Quick Sort in Prolog
domains
list=integer*
predicates
qsort(list,list)
partition(integer,list,list,list)
append(list,list,list)
clauses
qsort([],[]).
qsort([X|!1],<')"#partition(X,!1,'=',>'),qsort('=',<'1),qsort(>',<'&),append(<'1,
[X|<'&],<').
partition(_,[],[],[]).
partition(X,[|!&],[|!,],'7)"#$=X,partition(X,!&,!,,'7).
partition(X,[|!&],',,[|!7])"#%X,partition(X,!&,',,!7).
append(',[],').
append([],',').
append([|!1],'&,[|',])"#append(!1,'&,',).
Program--
Source code to traverse a grap using BFS in prolog
domains
list=s-mbol*
predicates
bfs(list,s-mbol,list)
append(list,list,list)
c.ild(s-mbol,list)
clauses
c.ild(a,[b,c,d]).
c.ild(b,[e,f]).
c.ild(c,[g]).
c.ild(d,[.,i]).
c.ild(e,[]).
c.ild(f,[]).
c.ild(g,[2]).
c.ild(.,[l]).
c.ild(i,[]).
c.ild(2,[]).
c.ild(l,[]).
append([],',').
append([|!1],'&,[|!,])"#append(!1,'&,!,).
bfs([],_,[]).
bfs([|_],,[]).
bfs([|!],X,[|!,])"#$%X,
c.ild(,'1),
append(!,'1,(t),
bfs((t,X,!,).
Program-.
Source code to traverse a grap using !FS in prolog
domains
list=s-mbol*
predicates
dfs(list,s-mbol,list)
append(list,list,list)
c.ild(s-mbol,list)
clauses
c.ild(a,[b,c,d]).
c.ild(b,[e,f]).
c.ild(c,[g]).
c.ild(d,[.,i]).
c.ild(e,[]).
c.ild(f,[]).
c.ild(g,[2]).
c.ild(.,[l]).
c.ild(i,[]).
c.ild(2,[]).
c.ild(l,[]).
append([],',').
@*append(',[],').
append([],[],[]).*@
append([|!1],'&,[|!,])"#append(!1,'&,!,).
dfs([],_,[]).
dfs([|_],,[]).
dfs([|!],X,[|!,])"#$%X,
c.ild(,'1),
append('1,!,(t),
dfs((t,X,!,).
Program-/
!evelop a Medical "#pert System in Prolog
domains
s-m= s1As&As,As7As6As8
dis=d1Ad&Ad,Ad7
med=m1Am&Am,Am7
pat=p1Ap&Ap,Ap7
database
pat_s-m_-es(pat,s-m)
pat_s-m_no(pat,s-m)
pat_dis_-es(pat,dis)
pat_dis_no(pat,dis)
predicates
.as_s-m(pat,s-m)
.as_dis(pat,dis)
tell_med(pat)
clear
clauses
pat_s-m_-es(p1,s1).
pat_s-m_-es(p1,s&).
pat_s-m_-es(p&,s&).
pat_s-m_-es(p,,s7).
pat_s-m_-es(p7,s6).
pat_s-m_-es(p7,s&).
.as_s-m(;,<)"#pat_s-m_-es(;,<),B.
.as_s-m(;,<)"#pat_s-m_no(;,<),B,fail.
.as_s-m(;,<)"#/rite(1Cn *r 1 ,;,1do u .ave
s-mtom1,< ,1(-@n)D1),readln(Ens),Ens=1-1,assert(pat_s-m_-es(;,<))Aassert(pat_s-m_no(
;,<)).
.as_dis(;,d1)"#pat_dis_-es(;,d1),B.
.as_dis(;,d1)"#pat_dis_no(;,d1),B,fail.
.as_dis(;,d1)"#.as_s-m(;,s1),.as_s-m(;,s,),.as_s-m(;,s6).
.as_dis(;,d&)"#pat_dis_-es(;,d&),B.
.as_dis(;,d&)"#pat_dis_no(;,d&),B,fail.
.as_dis(;,d&)"#.as_s-m(;,s&),.as_s-m(;,s7),.as_s-m(;,s6).
.as_dis(;,d,)"#pat_dis_-es(;,d,),B.
.as_dis(;,d,)"#pat_dis_no(;,d,),B,fail.
.as_dis(;,d,)"#.as_s-m(;,s&),.as_s-m(;,s,),.as_s-m(;,s6).
.as_dis(;,d7)"#pat_dis_-es(;,d7),B.
.as_dis(;,d7)"#pat_dis_no(;,d7),B,fail.
.as_dis(;,d7)"#.as_s-m(;,s1),.as_s-m(;,s7),.as_s-m(;,s6).
tell_med(;)"#.as_dis(;,d1),/rite(1Cn *r1,;,1do ta2e medicine1,m1).
tell_med(;)"#.as_dis(;,d&),/rite(1Cn *r1,;,1do ta2e medicine1,m&).
tell_med(;)"#.as_dis(;,d,),/rite(1Cn *r1,;,1do ta2e medicine1,m,).
tell_med(;)"#.as_dis(;,d7),/rite(1Cn *r1,;,1do ta2e medicine1,m7).
clear"#retract(pat_s-m_-es(_,_)),fail.
clear"#retract(pat_s-m_no(_,_)),fail.
clear"#retract(pat_dis_-es(_,_)),fail.
clear"#retract(pat_dis_no(_,_)),fail.
clear.
Program-)0
Source code of '-Pu((le pro&lem in Prolog
domains
list=integer*
listoflist=list*
predicates
c.ildren(list,listoflist)
bfs(listoflist,list,listoflist)
append(listoflist,listoflist,listoflist)
samelist(list,list)
clauses
samelist([X],[X]).
samelist([1|!1],[&|!&])"#1=&,samelist(!1,!&).
c.ildren([),E,F,9,:,=,G,>,],[[E,),F,9,:,=,G,>,],[9,E,F,),:,=,G,>,]]).
c.ildren([E,),F,9,:,=,G,>,],[[),E,F,9,:,=,G,>,],[E,F,),9,:,=,G,>,],
[E,:,F,9,),=,G,>,]]).
c.ildren([E,F,),9,:,=,G,>,],[[E,),F,9,:,=,G,>,],[E,F,=,9,:,),G,>,]]).
c.ildren([E,F,9,),:,=,G,>,],[[),F,9,E,:,=,G,>,],[E,F,9,G,:,=,),>,],
[E,F,9,:,),=,G,>,]]).
c.ildren([E,F,9,:,),=,G,>,],[[E,),9,:,F,=,G,>,],[E,F,9,:,>,=,G,),],
[E,F,9,),:,=,G,>,],[E,F,9,:,=,),G,>,]]).
c.ildren([E,F,9,:,=,),G,>,],[[E,F,),:,=,9,G,>,],[E,F,9,:,=,,G,>,)],
[E,F,9,:,),=,G,>,]]).
c.ildren([E,F,9,:,=,G,),>,],[[E,F,9,),=,G,:,>,],[E,F,9,:,=,G,>,),]]).
c.ildren([E,F,9,:,=,G,>,),],[[E,F,9,:,),G,>,=,],[E,F,9,:,=,G,),>,],
[E,F,9,:,=,G,>,,)]]).
c.ildren([E,F,9,:,=,G,>,,)],[[E,F,9,:,=,G,>,),],[E,F,9,:,=,),>,,G]]).
append([],['],[']).
append([[]|!1],['&],[[]|!,])"#append(!1,['&],!,).
@*bfs([],_,[]).
bfs([|_],[E,F,9,:,=,G,>,,)],[]).
bfs([|!],[E,F,9,:,=,G,>,,)],[|!,])"#$%X,
c.ildren([],'1),
append(!,'1,(t),
bfs((t,X,!,).*@
bfs(['1|_],'&,['1])"#samelist('1,'&),B.
bfs(['1|!1],'&,[;at.])"#
not(samelist('1,'&)),c.ildren('1,',),append(!1,',,(list),bfs((list,'&,
[(pat.]),append(['1],[(pat.],[;at.]).

T2.[].list.N=M+1.NT):-H1<>H2.[]).T1.list) intersection(list.list.[]).[]).[H2|T2].[X|_]). union([].list.NT).integer) replace(integer.T2.NT)._.list) equiv(list.NL).list.T2):-deleteall(X.[].0).list) equal(list.list) samelist(list.[]). intersection([H1|T1].[H|T2]):-H<>X. occur(X.intersection(T1.list) clauses member(X. deleteall(X.[H1|NT]):-H1=H2.[H|T2]):-H<>X.list) append(list.L).Program-1 Predicates in Prolog domains list=integer* predicates union(list.[].NT).list) occur(integer.list) member(integer.list. union(L.L.M).occur(X.L).[H|T]):-H<>X.[H2|T2].list.[H2|T2].list. intersection([].T2).[H1|NT]):-H1=H2.list.T.T1.deleteall(H1.union(T1. delete1(_. delete1(X.[]. union([H1|T1].intersection(T1.list) sum(list.T).list) setdiff(list.integer) palin(list) merger(list.M).[H|T].[H|T1]. intersection([].T.list) deleteall(integer.[H2|T2].integer. intersection(_.[X|T1].delete1(X.list) delete1(integer.list.T2).union(T1.N):-X<>H.[]).N):-X=H.T2).[H2|T2].T1.NL.[H|T1].N=M. intersection([H1|T1]. occur(X.[]. union([]. .[X|T1]. deleteall(_.list) rev(list.[]. member(X.[H|T].deleteall(X.occur(X.member(X. deleteall(X. delete1(X.[H2|T2].[]).[]).[]. setdiff([].T1).[].NT). union([H1|T1]. occur(X.[H1|NT]):-H1<>H2.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->