Download presentation
Presentation is loading. Please wait.
Published byDavid Wilcox Modified over 6 years ago
1
PROLOG – PROgamming in LOGic Early 1970s- programming language.
TS 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
2
Prolog algorithm consists of logic and control
TS 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.
3
Clause:- parent(siti,abu). parent (ali,abu). parent (ali,rini).
TS 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
4
Qs:- ?-parent(abu,alia). ?-parent(rini,alia). ?-parent(ali,ahmad).
TS Chapter 1: introduction to Prolog Qs:- ?-parent(abu,alia). ?-parent(rini,alia). ?-parent(ali,ahmad). ?-parent(X,rini). ?-parent(abu,X). ?-parent(X,Y).
5
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
6
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? ?-parent(X,ani),parent(X,alia).
7
Extra Example:- : Aliya and Hasan world. Power_Ranger is a toy.
TS 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).
8
Fact – represents a unit of information which always true.
TS 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).
9
X dan Y are friends if there is a Z where X likes Z and Y likes Z.
TS 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).
10
Expansion the program using rules Example:-
TS 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). ……
11
mother(X,Y):- parent(X,Y),female(X).
TS 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).
12
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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.