120 likes | 147 Views
Explore the fundamentals of Prolog, a logic programming language, its syntax, algorithms, and practical examples like family trees. Learn to solve complex problems efficiently using logic-based programming.
E N D
TS2023 Chapter 1: introduction to Prolog • What is PROLOG ?? • PROLOG – PROgamming in LOGic • Early 1970s- programming language. • Robert Kowalski(Edinburgh) in theory aspect & Colmersuer(Marseilles) in implementation aspect. • Associated with mantic logic and it is a programming language for symbolic calculation and non-numeric
TS2023 Chapter 1: introduction to Prolog • Most suitable – solve the problems associated with the objects and relationships between objects, pattern matching problem, back tracking problem and incomplete problems. • Prolog algorithm consists of logic and control • Logic - fact and rules that describe what should be done by algorithm • Control - a way algorithm can be implemented by using the rules • syntax in clause form or First Order Predicate Logic formula.
TS2023 Chapter 1: introduction to Prolog Clause:- parent(siti,abu). parent (ali,abu). parent (ali,rini). parent (abu,ani). parent (abu,alia). parent (alia,mat). parent (rini,adri). siti ali abu rini ani alia adri mat Figure 1.1 Family Tree
TS2023 Chapter 1: introduction to Prolog Qs:- ?-parent(abu,alia). ?-parent(rini,alia). ?-parent(ali,ahmad). ?-parent(X,rini). ?-parent(abu,X). ?-parent(X,Y).
TS2023 Chapter 1: introduction to Prolog • Complex Qs:- • Who are parents of Mat? Assume Y. • Who are parents of Y? Assume Y. X Grandfather/Grandmother Y mat
TS2023 Chapter 1: introduction to Prolog • Statement in Prolog:- • ?-parent(Y,mat),parent(X,Y). • Question 2 • Who are parents of Ani? Assume X. • Are parents (X) same with parents for alia? • Statement in Prolog:- • ?-parent(X,ani),parent(X,alia).
TS2023 Chapter 1: introduction to Prolog Extra Example:- : Aliya and Hasan world. Power_Ranger is a toy. Snoopy is a toy. Aliya play with Snoopy. Aliya likes every toy that she play with. Hasan likes what Aliya likes. Terjemahan dlm prolog toy(power_ranger). toy(snoopy). play(aliya,snoopy). likes(aliya,X):-toy(X),play(aliya,X). likes(hasan,Y):-likes(aliya,Y).
TS2023 Chapter 1: introduction to Prolog Fact and rule Fact – represents a unit of information which always true. Example :- Sky is blu sky(blue). Today is raining today(raining). Sim likes apple likes(sim,apple).
TS2023 Chapter 1: introduction to Prolog Control – a relationship between facts by using the logical implications‘:-’. Example:- X dan Y are friends if there is a Z where X likes Z and Y likes Z. Prolog statement Sim loves book loves(sim,book). Siti loves book loves(siti,book). friends(sim,siti):-loves(sim,book),loves(siti,book).
TS2023 Chapter 1: introduction to Prolog Expansion the program using rules Example:- Include the gender as additional information female(Siti). male(ali). male(abu). female(rini). ……
TS2023 Chapter 1: introduction to Prolog Example:- For every X and Y, X is mother of Y if X is parent of Y and X is female. Prolog statement mother(X,Y):- parent(X,Y),female(X).
Individual exercise • Please make a family tree program respectively. • Genealogies should have: • Uncle & aunty • son & daughter • Grandmother & grandfather • Grandchild • Great-grandmother & great-grandfather • Second cousin • Mother in law / father in law • Daughter in law • Extra mark untuk extra predikat.