You are on page 1of 17
PRINCIPLES OF ARTIFICIAL INTELLIGENCE LAB AIML207 "1 VIVEKANANDA SCHOOL OF ENGINEERING AND ceeds, TECHNOLOGY Academic Year (2022-2023) Department of Artificial Intelligence and Machine Learning Programme: B.Tech Student Name: Shruti Sharma Roll No: 05217711621 Faculty Coordinator: Dr. Puneet Singh S.No List of Experiments (651?U) introduction to Prolog. 2. Write a program to implement syntax and numeric functions in Prolog. 3. Write a program to implement basic list manipulation functions in Prolog. 4. Write a program to implement input, output, and predicates in Prolog. 5. | Write a program to implement local variables and conditional statements using Prolog. 6. | Write a program to calculate factorial of a given number using Prolog. 7. | Write a program to solve 4-Queen problem using Prolog. 8. | Write a program to solve any real-life problem using depth first search. 9%. Write a program to solve TIC-TAC-TOE Problem using Prolog. 10. Write a program to solve Monkey Banana Problem using Prolog. 11. _| Write a program to solve Water Jug Problem using Prolog. 12. | Write a program to solve 8 Puzzle Problem using Prolog 13. | Write a program to solve Tower of Hanoi Problem using Prolog, 14. Write a program for medical diagnosis using Prolog, SECTION 1 Principles of Artificial Intelligence Lab Experiments GGSIPU Program 1 Name: S\nusti Srotwma Rollno: 05219116271 Date of Performance: Faculty Signature: Program Name: Introduction to Prolog. Ireler as tre name j}selh Suggert, fs ‘lve. short foren 4} LOb Tak PRO frarneving. . Wt rs & hom'eak, ond — declasehive eae lomguaye loge Presteawmnai ve AS Ome of qh fadrackiyen j + Compo eh Proprumants tw watch, Progen Shaders SL fress Bh facts md qalts about Ai} ferent fretlems atltnror a Syptern of formal lowe +e, THe WS ge Wat ttee AY form or Logrea Claws | we hhtad and Poet ane present . Proton. Os, FRO Gmmy in LObIEA Ly Mogiemt owe declenmbin prepamncing Jevavare «It IS Owe nay Oh exmmble of. fount qowhation ye MAT SppoNts THE lt clagative Pepeunming pormtigmn, “hwy is peationlan Subteble fer progres tra : Fave t Spube'c or 0M —numuic restos Se Ts Pre mam vaso 40 SC Prloy- os bregrernoig Aswan an AL, whtte Symbol, manipulathow apg eet fonclowmental, jos can Prtloy rvat ned mot muti drt woy how ont jrovlom cam be solved, We fost ved so rumhbw vows ak problem Ls, $ That Prsloy autornat cally Solva 8 Howartr , in Pr olop we one jo give us Ant Solution ontaod v lompaage. bavicnay, day Tee differsut alarnouts . Facts: Wa fact 3 prutteate, tract hg Tae, few axmmaple + 4 we So, “Form 4 qe Son Ap Yack", moon quis 1S a fad. Rudra: Rubs ore vet nchews of feck strat coutadr Uo . To sakdfy a mk we Conditoyy should be mob . Br anowmble | ib wR As bTne a) oleate QramAtetin OY) I= Fete G2), pam (207) Ms vaputes That fer x de be qe grand fater of Y- Z Shows be a parwrct of Y¥ and % grould be fatwr of 7. Orastios: And to wun a frolog rrageun , yun Need Gomer qurtes, awd tose quutiod tm be anewirk 4. de git fe ond ols Some Agpicatton, on Prolog. Pooler. is used Tn voto domanyu. Ft ply avitel ple tm. artomahan Bystmn Fallouirg ar Somme oer Tpeviowt finds wn prolong. ty Used, i rd ged pareodse Rebtudl = Report Plamni 2 NEAL guage Under famcting + Prtomation. Sy Sten Bren eed + Problum Solvivy + Mate learn Program 2 Name: Shyu) Shanna Roll no: 0521 FH 624 Date of Performance: Faculty Signature: Program Name: Write a program to implement syntax and numeric functions in Prolog. Theory: AS we brow Te are fw mam Compommds 4” doqe Pagramoniy, \ Facts, Pals eC d gvere Tar i uit wilect facts aud as 04 & wswle fren that fms puouledye Bast. So we Ws” Se sqrox Puowledge, base Ty & CoUechdu faus eee. Arttumette Sfrwkors ONG usd te pf outamdre Opuatiows . “Mire. ore fer arfhrunt sbypes ef oxfam’, oprwtrrs 03 folios * + Prd dove RY — Srohathdve 2 ¥ pnt plicattows wy Rees a4 / pi vision, ve — fowy lt yey // pg, Disa a// ce rood Modulus a mod ap Source Code: Knowledge Base girl (priya) girl(tiyasha). girl (jaya). can_cook (priya). sing_a_song(ananya). listens_to_music(rchit). listens_to_music(ananya) :- sing ; happy(ananya) !- sing_a_song(ananya) . happy (rohit) stens_to_music(rohit). playes_guitar(rohit) :- listens_to_music(rchit). \_song (ananya) . a Relations female (pam) . female (liz). female(pat). female (ann) . male (jim). male (bob) . male (tom). male (pet. parent (pam, bob) . bob). parent (tom parent (tom,1iz). parent (bob, ann) . parent (bob, rat). parent (pat, j=m). Parent (bob, petez) . parent (peter, jm). mother (x, ¥) !- parent (x, ¥), female (xX). father (x arent (X,Y), male (x). sister (X, ¥) :-parent (2,X) , parent (Z, ¥) , female (X) ,X 2,X),parent (2, ¥ sparen ( mother (X,¥), parent (¥,5). grandparent (x, ¥ grandmother (x, =) ), female (x) ,»male(¥ uncle (X, 2) :-brother (X,Y) ,parent (¥,Z) Numeric Function 190 med Wawro hetiod mod Was Yywrine ly yn), Output: Knowledge Base ?- sing_a_song(rohit) false. ?- playes_guitar(rohit) true. 2= can_cook(priya). true. 2- girl (jamini) false. Relations grandparent (X,Y) pan, ann; pan pat ; pan. peter ; tom ann ; tom. pat ; ton peter ; bob. jin ; = bob, x Y x i X v x Y X Y x Y x Y x y 2— uncle(X, Y) X = peter, Y= jim; false. 7- nale(X) X= jim; X = bob ; X= tom; X = peter Numeric Functions 6 2- cale 100 + 200 rs 300 400 - 150 1s 250 10 = 300 15 3000 100 7 30 as 0 3333333333333333 100 77 30 1s 3 100 ** 2 as 10000 100 nod 30 15 10 true. Learning Outcomes: we get to Lr about lowowheaye base, Ruta dry ow numinic. famdion dvcouyh Ts wxpaiow Program 3 Name: Susi Srorma Rollno: 05214 +164 Date of Performance: Faculty Signature: Program Name: Write a program to implement basic list manipulation functions in Prolog. Theory: “Thu Uist is a simple dota Ehuere That a wildly Usch Jim son—nuunivie. programming ae 2] owns cat numbly, of Tes , fe 7nd Bue, voue, dosh - Ht uti] be presented 24 Rea pun, bun , white, doe]. tw Liat of Clem wilt be enclosed unit Spree brackel. A Usk can be ombty CJ, or nom—ompty. Non — st 0 Ny GEOR «Tt ie bank of st ,catled “Tul. Lek us wml, L= [a.b,0), Wy we write Tall = Cp, Tim we on alo wate L= (a) toll]. Ban Oprariovs om Usts Twdude + + Membumsp Ce . Length. Ce + Cndenation «Delle Trews + Appurd Tens * Fk Heme SOURCE CODE: Code to identify whether a given element is a member of a list or not list_member (x, [X|_]). Aist_member (x, [_|TAIL]) :- list member OUTPUT: 2= List_member(S.(5.7.11,14,17]) true. 2- List_neaber(e [a b c.d.e)) true SOURCE CODE: To calculate the number of elements in a list list_length([),0). list_length({_|TAIL],N) :- liet length (TAZL,Ni), OUTPUT: 2 Aast_length({S 7.11 14.17}.1) Les )- Anst_lengthi{a e 1 0 u) L) Des SOURCE CODE: Code to combine two lists list_concat({),L,L). ist_concat ((Xi|Li),L2, (x 13}) concat (Li,L2,13) . OUTPUT: 2 Lust_concet({$ 7}, [a bc] Nevlast) Mavlist= (5 7 9 bc) 2- Last_concat([e b].[e.d).Neviast) Nevlist™= [a b. cd) ?- last_concat(({§ 7) [11 14] NewList) Neviist= (5.7, 11, 14) SOURCE CODE: Code to delete an element from the list List_delete(x, (x), {)). ;_del e(XIL1), Li). Aist_delete(x, [y/12], [y|zi]) :- list @ (X,L2,L2) . OUTPUT: 2~ Last _delete(, [4,2 1,0.u] NevLsst Nehist = fete gp : f- Last_delete(11 [57.11.14 17] NevList) Neviist™= [57 14 17) SOURCE CODE: Code to add new members to list List_member list_member list_append List_append OUTPUT: ?- last_eppend(a.[e 1.0 u) Neviast) Megtvalecufeimen cae! ore 2— List_append(a [bc de] NevLast) Nevlist= (a boc. de] 2 Last_eppend(5.[7.11.17.25] NevList) Newliet* (5. 7. 11, 17, 25} SOURCE CODE: Code to insert a new element to list list_delete(x, [x], []). list_delete(x, (X|1i], Li). List_delete(x, [viL2], [¥J1i]} + list_delete st_delete(x,12,L:). xR, L) « OUTPUT: 2~ List_ansert(a.[2.1.0.u) MevList) Nevlist™= [a, ©, 1. 0. u) 2- Last_ansert(S.(7 11.14 17) Newlast) Nevlist™= (5 7 11 14. 17) ist TH Prole Learning Outcomes: we. yet to ow. aout Ust 4 a ark hous 40 fruplnunk baste US romaipulchee fmchow, aa Proley Program 4 Name: Shiu} Shaan Roll no: 0 521 91162) Date of Performance: Faculty Signature: Program Name: Write a program to implement input, output, and predicates in Prolog. Theory: TROL wa}el) Predicate : ; To wwitt we output wat oun Use Tue wore) preacats. hs prvvedt takes fe poumeta, as inpre ond, wrytes the comerd Tate comole by default . Wwaa'tel) cur~ alo Wate an filer. Te ~rwdt) Precticate! Tt sett) predicts py vised #2 wad from combole, USL Con wate Somutlum Fn cowolt, That Can be paca. ab dinpt amd poun it. D> ru VoL) Predict. wWharrs X¥ 4 wot fartralized, tata, it wall sow Tran, OTnbuuse, false, > Te overt) Prubieate | Wan x is mot Iitrvabized , Thee 1E wilt show fee, otvernulse Trae. . > TRE atom KD Prdleade \ ull web shel, wove a now VOATaLe Jou unify O atyurnuutD and not numey'c -fom Is posd oy KX, othtuuse false > ae NUMbALC) Predicate ? Mull rear trae, % Steud fore cueg- NDUMb + > Ta Mega) Preiade + wl reba dre, whan X'S a te oe Vu rg, Vel, arhnuuise fade, > THe Hoat4) Paai'ede - wall repr Trae, X 1S fleah'yy fait nunba. > Tar adoww'e 2) Predlatt Ire atom.) but acubts numb4 > THe compo x) Prectl code — aT bc rae, hp compound Sprucbire ts pad > te POLK) frediioae.— Rabwws Tre, iy X datm't oouten Own uniwatenstabed, sontudes, Source Code: A program to print the cube of the given number. cube e('Write a number: '), read (Number Process (Number) . Process(stop) :- write("Cube of ' cube. , ex) ,write(": '), c),ni, Output: Write a number: |: 8 Cube of 8: 512 PREDICATE: 2 var(X) true. mK. var(X) 2- x x-5 S.nonvar(X) 2 nonvar(X) false. 2 aton(paul) true. 2= atom(T}) false. 2 X25 5S. nunber (X) 2 number(5.46) true. 72 integer(5.46) false. 2 float(5) false. 2 float (5.46) true. 2= atomic(5) true. 2= compound([a]) true. 2= compound(b(a)) true. 7r sround({a.b.cl) true. Learning Outcomes: wr yt Jew. aout bili precl'ents and how wht) and vt) feichow. Raa works my Prolog Program 5 Name: Shruct} Saya Rollno: OS 21 FH1621 Date of Performance: Faculty Signature: Program Name: Write a program to implement local variables and conditional statements using Prolog. Theory: Lech statemants aX Used fo enerate code biel HUTTE ims » Coole Hoek o exeeted muth'pe Taw OMY] WeUMMVe predicate, fate - TAL an, no det wosps 2n Comme Pu, Wurpager , rout wie. com srmudade oops ul few Aifferut techulawr . To exeerte the Mspucron a freuk numba a Him, ee 8 ee Preley , swt. is no suc faclhity owailable, dilrbily bole usa. ALUM 7 WL COM Ohh Sy AL “tira: te ors a condos Stetemmt 4a gy THe comsntve of Tet data aud, cuispleg. TL rege Yoder IE eS Ve cmnditvron usima proleg. oa Source Code: ‘A program to compare two integers. numbers te('enter the numbers here...'), nl, Fead(Al), nl, read(Bi), ni, conditions (Al, B2). conditions (A.,2.):- Al > Bi, conditions (s_,B.): conditions (A.,61) :- te('A value is greater than B v (A value is less than B val te (‘A value al to B value'). Output: 2 numbers enter the nuabers here ne las Av true. 2 nunbers enter the nunbers here 123 1 sa lue is equal to B value A value is less than B value true. 2= nunbers enter the nusbers here. P99 134 4 value is greater than B value true. Source Code: A program to generate an integer value from first to last inclusive, output (1, e(L) ,n2, 2- output(4,4) t sh finss true ft Learning Outcomes: Wt at fo fear. coorct Jocal vatuturle onk wwdMtlonal Statawunts , berks set we Law eork if am far Loop array Tals rromceny, Program 6 Name: Shsurti Srianmna Roll no: 0.5 21TH116 71 Date of Performance: Faculty Signature: Program Name: Write a Program to calculate factorial of a given number using Prolog. an, . ark (1) Me factealal | Sprabol’seA ay oun Ax CLUmattr'en 7M y Aso quai pied for all Pakega, S qRale tron tr qual to 0. Rr am Tstegen, 1 yrtatth. hon er equal 401, the facto JS product of atl latya, ley tran er equal a mr bak qreattn Than ev egal to] . Te facto of 0 is dapud 03 egal, to |, MATEMAT ML. , Te formla for factorial a3 od Nows + er ml = ima) (n-2) (mes) — — (8a) Fo Ping, ome oh rom wnys fo fad ay Pato ofp oe gen mumnbs, 45 Use Bh) Hypwal. Statewout - oud, using UAL Fackeal ofp a mugatine munibeh, com alo bey fourar. Source Code: Program to print factorial of a number fact(0,i). orial. Output: 2- fact(4.R) R= 24 ?- fact(0.R) Ron, 2— fact(-5.R) R= -120 . Se oie esi about facial and vse ai sive’ We gc se get asin, our pak. we Bim Mage preppesns J : aso 4c Pp buon About “LeU .

You might also like