SlideShare a Scribd company logo
PROLOG
‫أ‬/‫العربي‬ ‫إبراهيم‬
PROgramming in LOGic
Ibrahim.Elaraby@Outlook.Com
‫مقدمة‬
•‫لغة‬‫البرولوج‬(PROLOG)‫هي‬‫اختصار‬(PROgramming in LOGic)
‫أي‬‫البرمجة‬‫المنطقية‬.‫وصمم‬‫هذه‬‫اللغة‬‫أستاذ‬‫بجامعة‬‫مرسيليا‬‫بفرنسا‬‫يدعى‬‫أل‬‫ن‬
‫كولمرير‬(Alan Colmeraur)‫وظل‬‫استخدام‬‫لغة‬‫البرولوج‬‫محصورا‬‫في‬‫معامل‬
‫أبحاث‬‫الذكاء‬‫االصطناعي‬‫بقارة‬‫أوروبا‬‫حتى‬‫أكتوبر‬1981
•‫وتعتمد‬‫لغة‬‫البرولوج‬‫على‬‫مفهوم‬‫البرمجة‬‫المنطقية‬(Logic Programming),
‫والتي‬‫تتعامل‬‫مع‬‫جمل‬(Statement)‫تحتوي‬‫على‬‫أشياء‬(Objects)
‫والعالقات‬(Relationships)‫التي‬‫تربط‬‫بينها‬‫وبين‬‫الجملة‬.
‫مثال‬
‫في‬‫هذه‬‫الجملة‬‫تسمى‬‫كلمة‬(Professor)‫بالمسند‬(Predicate)‫وتمثل‬
‫العالقة‬‫بين‬‫المعامالت‬،‫حيث‬‫ان‬(Mohammad)‫هو‬‫أستاذ‬(Ali)
‫وعلى‬‫هذا‬‫فإن‬‫لغة‬‫البرولوج‬‫تسمح‬‫للمبرمج‬‫بتمثيل‬‫العالقات‬‫بين‬‫األشياء‬‫وتجميع‬
‫وتنظيم‬‫هذه‬‫العالقات‬‫حتى‬‫يمكن‬‫الوصول‬‫إلى‬‫استنتاج‬‫منطقي‬‫من‬‫الحقائق‬‫ا‬‫لتي‬
‫تمثلها‬‫تلك‬‫العالقات‬.‫وذلك‬‫على‬‫عكس‬‫اللغات‬‫التقليدية‬‫مثل‬‫الباسكال‬‫وسي‬‫التي‬
‫تطلب‬‫من‬‫المبرمج‬‫كتابة‬‫الخطوات‬‫التفصيلية‬‫التي‬‫يجب‬‫إتباعها‬.
Professor (Mohammad, Ali).
‫برنامج‬‫البرولوج‬
‫يقوم‬‫برنامج‬‫البرولوج‬‫بإعطاء‬‫الحاسب‬‫وصف‬‫المشكلة‬‫بإستخدام‬‫عدد‬‫من‬‫الحقائق‬
"Facts"‫والقواعد‬"Rules"‫ثم‬‫يسأل‬‫الحاسب‬‫عن‬‫ايجاد‬‫كل‬‫الحلول‬‫المحتملة‬
‫للمشكلة‬.
‫ا‬ ‫وتنقسم‬‫هي‬ ‫مراحل‬ ‫ثالثة‬ ‫إلى‬ ‫البرولوج‬ ‫بلغة‬ ‫لبرمجة‬:
.1‫األشياء‬ ‫عن‬ ‫الحقائق‬ ‫إعالن‬(Objects)‫بينها‬ ‫تربط‬ ‫التي‬ ‫والعالقات‬.
.2‫القواعد‬ ‫تعريف‬(Rules)‫تحكم‬ ‫التي‬‫هذه‬‫تربط‬ ‫التي‬ ‫والعالقات‬ ‫األشياء‬‫بينها‬.
.3‫االستعالم‬‫تربطها‬ ‫التي‬ ‫والعالقات‬ ‫األشياء‬ ‫عن‬.
‫ملحوظه‬
‫يمكن‬‫أن‬‫تأتي‬‫المرحلة‬‫الثالثة‬‫بعد‬‫المرحلة‬‫األولي‬‫مباشرة‬‫حيث‬‫يمكن‬‫السؤال‬‫عن‬‫ا‬‫ألشياء‬
‫دون‬‫تطبيق‬‫أي‬‫قواعد‬.
‫كيفية‬‫اإلعالن‬‫عن‬‫الحقائق‬‫والسؤال‬‫عنها‬:
‫اإلعالن‬‫عن‬‫الحقائق‬‫في‬‫برنامج‬‫البرولوج‬‫يجب‬‫أوال‬‫تحديد‬‫األش‬‫ياء‬
(Objects)‫والعالقات‬‫التي‬‫تمثل‬‫تلك‬‫الحقائق‬.‫فمثال‬‫إذا‬‫كانت‬‫هناك‬
‫حقيقة‬‫تقول‬.(Likes (ali , Mohamed‫فاألشياء‬‫في‬‫هذه‬
‫الحقيقة‬‫هي‬‫األسماء‬(Ali , Mohamed)‫أما‬‫العالقة‬‫بينهما‬‫فهي‬
(Likes)‫وتسمى‬‫بالمسند‬(Predicate)‫أي‬‫الصفة‬‫التي‬‫تتعلق‬
‫بشيء‬‫ما‬‫أو‬‫العالقة‬‫التي‬‫تربط‬‫بين‬‫شيئين‬‫أو‬‫اكثر‬.‫ولتمثي‬‫ل‬‫هذه‬
‫الحقيقة‬‫في‬‫برنامج‬‫البرولوج‬‫تكتب‬‫كاآلتي‬:
likes ( ali , mohamed(.
•‫يتم‬‫كتابة‬‫أسماء‬‫األشياء‬‫والعالقات‬‫بالحروف‬‫الصغيرة‬(Small Letters)‫وذلك‬‫ألن‬‫األسماء‬‫التي‬
‫تبدأ‬‫بالحروف‬‫الكبيرة‬(Capital Letters)‫أو‬‫بالحرف‬(Underscore (_))‫يعتبرها‬
‫البرولوج‬‫متغيرات‬(Variable).‫وتختلف‬‫الحقيقة‬‫باختالف‬‫ترتيب‬‫أسماء‬‫األشياء‬‫بمعنى‬‫أن‬
likes ( ali , mohamed).‫تختلف‬‫عن‬likes (mohamed, ali).‫وينتهي‬‫اإلعالن‬
‫عن‬‫الحقيقة‬‫بوضع‬‫نقطة‬(.)‫في‬‫آخرها‬.
•‫ويطلق‬‫على‬‫التعبير‬likes ( ali , mohamed).‫في‬‫لغة‬‫البرولوج‬‫لفظ‬‫العبارة‬(Clause)
‫ويمكن‬‫ترجمة‬‫اللغة‬‫المكتوبة‬‫بإحدى‬‫اللغات‬‫الطبيعية‬(‫اإلنجليزية‬‫أو‬‫العربية‬)‫إلى‬‫عبارة‬‫أو‬‫اكثر‬‫من‬
‫عبارات‬‫البرولوج‬.‫ويتم‬‫ذلك‬‫بتحديد‬‫األشياء‬‫التي‬‫يدور‬‫حولها‬‫موضوع‬‫الجملة‬‫وتحديد‬‫الصف‬‫ات‬‫أو‬
‫العالقات‬‫التي‬‫تميزها‬,‫أو‬‫محمول‬‫الجملة‬.
EXAMPLE 1
prof (mohamed,ali).
Queries :-
1- ? prof (M,N).
2- ? prof (_,M).
3- ? prof (M,_).
4- ? prof (mohamed,ali).
Start – All Program – Accessories - Notepad
‫الـ‬ ‫برنامج‬ ‫فتح‬NOTEPAD
‫الـ‬ ‫برنامج‬ ‫فتح‬PROLOG
Start – All Programs – SWI-Prolog
‫المطلوبه‬ ‫االستعالمات‬ ‫إجراء‬ ‫يتم‬
•likes(ali,mohamad(.
•likes(ali,ahmad(.
•likes(ali,omar(.
•likes(ali,adel(.
•likes(ahmad,mohamad).
EXAMPLE 2
Queries :-
1-? likes(M,N).
2-?likes(_,M).
3-?likes(M,_).
4-?likes(ali,ahmed).
5-?likes(M,adel).
6-?likes(_,_).
EXAMPLE 3
prof(youssef,dss,1clook,m1).
prof(waffa,vb,3clook,m2).
prof(mona,nw,3clook,m1).
prof(hend,mm,5clook,m2).
prof(Youssef,net,4clook,m3).
Queries :-
1-?prof(M,N,X,Y).
2-?prof(M,N,_,_).
3-?prof(_,_,_,_).
4-?prof(M,dss,N,X).
5-?prof(youssef,B,N,H).
6-?Prof(M,dss,N,X).
7-?prof(hend,mm,5clook,m2).
8-?prof(Hend,mm,5clook,m2).
9-?prof(HEND,MM,5clook,m2).
EXAMPLE 4
A fast – car is fun.
A big – car is nice.
A little – car is practical.
Ali likes a car if the car is fun.
What does ail likes?
In prolog
car(fast,fun).
car(big,nice).
car(little,practical).
likes(ali,X):-
car(X,fun).
Query
1-? Likes (ali, X).
EXAMPLE 5
Ali likes Ahmed.
Ali likes dogs.
Salwa likes everything Ali likes.
What does salwa likes?
In prolog
likes(ali,ahmed).
likes(ali,dogs).
likes(salwa,Something):-
likes(ali,Something).
Query
1-? Likes (salwa, what).
EXAMPLE 6
parent(hala,hany).
parent(aly,hany).
parent(hany,yaser).
parent(hany,aml).
female(hala).
female(mona).
female(aml).
male(aly).
male(yaser).
Hala
Hany
Yasser
Amal
Aly
CONTINUE
sister(X,Y):-
parent(Z,X),parent(Z,Y),female(X),X=Y.
father(X,Y):-
parent(X,Y),male(X).
mother(X,Y):-
parent(X,Y),female(X).
brother(X,Y):-
parent(Z,X),parent(Z,Y),male(X),X=Y.
off(hany,hala).
off(hany,aly).
off(aml,hany).
off(yaser,hany).
off(X,Y):- parent(Y,X).X=Y.
gf(X,Z):-
parent(Y,Z),parent(X,Y),male(X),X=Y.
gm(X,Z):-
parent(Y,Z),parent(X,Y),female(X),X=Y.
CONTINUE
Queries :-
1-?sister(X,Y). 2-?brother(X,Y).
3-?father(X,Y). 4-?mother(X,Y).
5-?gf(X,Z). 6-?gm(X,Z). 7-?off(X,Y)
END
Ibrahim.Elaraby@Outlook.Com

More Related Content

Viewers also liked

Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL AnimationKiran Munir
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
Ankit Kumar
 
Prolog programming
Prolog programmingProlog programming
Prolog programming
Harry Potter
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
Arvind Devaraj
 
Predicate Calculus
Predicate CalculusPredicate Calculus
Predicate Calculus
Serge Garlatti
 
Interestingand unusual
Interestingand unusualInterestingand unusual
Interestingand unusual
Hamdy Attia
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
Vivek Kumar Sinha
 
Computer Graphics Project Development Help with OpenGL computer graphics proj...
Computer Graphics Project Development Help with OpenGL computer graphics proj...Computer Graphics Project Development Help with OpenGL computer graphics proj...
Computer Graphics Project Development Help with OpenGL computer graphics proj...
Team Codingparks
 
تشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائيتشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائي
محمد الجمل
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligenceiarthur
 
Leveraging Symfony2 Forms
Leveraging Symfony2 FormsLeveraging Symfony2 Forms
Leveraging Symfony2 Forms
Bernhard Schussek
 
Computer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithmComputer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithm
RAJEEV KUMAR SINGH
 
شقق للبيع بالتقسيط وبدون مقدم لفترة محدودة بنست كايرو بجوار قطامية جاردينز ال...
شقق للبيع بالتقسيط وبدون مقدم لفترة محدودة بنست كايرو بجوار قطامية جاردينز ال...شقق للبيع بالتقسيط وبدون مقدم لفترة محدودة بنست كايرو بجوار قطامية جاردينز ال...
شقق للبيع بالتقسيط وبدون مقدم لفترة محدودة بنست كايرو بجوار قطامية جاردينز ال...
ahmed khallaf
 
The Role Of Ontology In Modern Expert Systems Dallas 2008
The Role Of Ontology In Modern Expert Systems   Dallas   2008The Role Of Ontology In Modern Expert Systems   Dallas   2008
The Role Of Ontology In Modern Expert Systems Dallas 2008
Jason Morris
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
Priya Goyal
 

Viewers also liked (16)

Open GL Animation
Open GL  AnimationOpen GL  Animation
Open GL Animation
 
Computer graphics lab manual
Computer graphics lab manualComputer graphics lab manual
Computer graphics lab manual
 
Prolog programming
Prolog programmingProlog programming
Prolog programming
 
Graphics programming in open gl
Graphics programming in open glGraphics programming in open gl
Graphics programming in open gl
 
Predicate Calculus
Predicate CalculusPredicate Calculus
Predicate Calculus
 
Interestingand unusual
Interestingand unusualInterestingand unusual
Interestingand unusual
 
Akashdeepsinghjandu13
Akashdeepsinghjandu13Akashdeepsinghjandu13
Akashdeepsinghjandu13
 
COMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUALCOMPUTER GRAPHICS LAB MANUAL
COMPUTER GRAPHICS LAB MANUAL
 
Computer Graphics Project Development Help with OpenGL computer graphics proj...
Computer Graphics Project Development Help with OpenGL computer graphics proj...Computer Graphics Project Development Help with OpenGL computer graphics proj...
Computer Graphics Project Development Help with OpenGL computer graphics proj...
 
تشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائيتشخيص وعلاج صعوبات الفهم القرائي
تشخيص وعلاج صعوبات الفهم القرائي
 
Artificial Intelligence
Artificial IntelligenceArtificial Intelligence
Artificial Intelligence
 
Leveraging Symfony2 Forms
Leveraging Symfony2 FormsLeveraging Symfony2 Forms
Leveraging Symfony2 Forms
 
Computer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithmComputer graphics mini project on bellman-ford algorithm
Computer graphics mini project on bellman-ford algorithm
 
شقق للبيع بالتقسيط وبدون مقدم لفترة محدودة بنست كايرو بجوار قطامية جاردينز ال...
شقق للبيع بالتقسيط وبدون مقدم لفترة محدودة بنست كايرو بجوار قطامية جاردينز ال...شقق للبيع بالتقسيط وبدون مقدم لفترة محدودة بنست كايرو بجوار قطامية جاردينز ال...
شقق للبيع بالتقسيط وبدون مقدم لفترة محدودة بنست كايرو بجوار قطامية جاردينز ال...
 
The Role Of Ontology In Modern Expert Systems Dallas 2008
The Role Of Ontology In Modern Expert Systems   Dallas   2008The Role Of Ontology In Modern Expert Systems   Dallas   2008
The Role Of Ontology In Modern Expert Systems Dallas 2008
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 

More from DrSamahAhmed

Decision support system(9)
Decision support system(9)Decision support system(9)
Decision support system(9)
DrSamahAhmed
 
Computer skills (ch1)
Computer skills (ch1)Computer skills (ch1)
Computer skills (ch1)
DrSamahAhmed
 
Decision support systems (ch5)
Decision support systems (ch5)Decision support systems (ch5)
Decision support systems (ch5)
DrSamahAhmed
 
Decision support systems (ch1)
Decision support systems (ch1)Decision support systems (ch1)
Decision support systems (ch1)
DrSamahAhmed
 
Decision support systems (ch4)
Decision support systems (ch4)Decision support systems (ch4)
Decision support systems (ch4)
DrSamahAhmed
 
Decision support systems (ch3)
Decision support systems (ch3)Decision support systems (ch3)
Decision support systems (ch3)
DrSamahAhmed
 
Decision support systems (ch2)
Decision support systems (ch2)Decision support systems (ch2)
Decision support systems (ch2)
DrSamahAhmed
 

More from DrSamahAhmed (7)

Decision support system(9)
Decision support system(9)Decision support system(9)
Decision support system(9)
 
Computer skills (ch1)
Computer skills (ch1)Computer skills (ch1)
Computer skills (ch1)
 
Decision support systems (ch5)
Decision support systems (ch5)Decision support systems (ch5)
Decision support systems (ch5)
 
Decision support systems (ch1)
Decision support systems (ch1)Decision support systems (ch1)
Decision support systems (ch1)
 
Decision support systems (ch4)
Decision support systems (ch4)Decision support systems (ch4)
Decision support systems (ch4)
 
Decision support systems (ch3)
Decision support systems (ch3)Decision support systems (ch3)
Decision support systems (ch3)
 
Decision support systems (ch2)
Decision support systems (ch2)Decision support systems (ch2)
Decision support systems (ch2)
 

Recently uploaded

687065تاىىز458-الخط-الزمني-و-الخريطة.pptx
687065تاىىز458-الخط-الزمني-و-الخريطة.pptx687065تاىىز458-الخط-الزمني-و-الخريطة.pptx
687065تاىىز458-الخط-الزمني-و-الخريطة.pptx
ninapro343
 
تدريب ف دوره على برنامج 3 1 d max
تدريب  ف  دوره  على   برنامج  3 1 d  maxتدريب  ف  دوره  على   برنامج  3 1 d  max
تدريب ف دوره على برنامج 3 1 d max
maymohamed29
 
تطور-الحركة-الوطنية-في-السودان-1919-–-1924-the-evolution-of-the-national-move...
تطور-الحركة-الوطنية-في-السودان-1919-–-1924-the-evolution-of-the-national-move...تطور-الحركة-الوطنية-في-السودان-1919-–-1924-the-evolution-of-the-national-move...
تطور-الحركة-الوطنية-في-السودان-1919-–-1924-the-evolution-of-the-national-move...
Gamal Mansour
 
DOC-20240602-W ggdcvgccccbbA0000..pdf
DOC-20240602-W     ggdcvgccccbbA0000..pdfDOC-20240602-W     ggdcvgccccbbA0000..pdf
DOC-20240602-W ggdcvgccccbbA0000..pdf
Gamal Mansour
 
تدريب ف دوره على برنامج 3 2 d max
تدريب  ف  دوره  على  برنامج  3  2  d  maxتدريب  ف  دوره  على  برنامج  3  2  d  max
تدريب ف دوره على برنامج 3 2 d max
maymohamed29
 
ورشة تحليل الممارسات المهنية (قطب الإنسانيات).pptx
ورشة تحليل الممارسات المهنية (قطب الإنسانيات).pptxورشة تحليل الممارسات المهنية (قطب الإنسانيات).pptx
ورشة تحليل الممارسات المهنية (قطب الإنسانيات).pptx
akrimo1978
 
مفهوم النخب_c2a9ebf68281ad450b0aec32b2014d05.pptx
مفهوم النخب_c2a9ebf68281ad450b0aec32b2014d05.pptxمفهوم النخب_c2a9ebf68281ad450b0aec32b2014d05.pptx
مفهوم النخب_c2a9ebf68281ad450b0aec32b2014d05.pptx
movies4u7
 
مقدمة عن لغة بايثون.pdf-اهم لغات البرمجة
مقدمة عن لغة بايثون.pdf-اهم لغات البرمجةمقدمة عن لغة بايثون.pdf-اهم لغات البرمجة
مقدمة عن لغة بايثون.pdf-اهم لغات البرمجة
elmadrasah
 
تعلم البرمجة للأطفال- مفتاح المستقبل الرقمي.pdf
تعلم البرمجة للأطفال- مفتاح المستقبل الرقمي.pdfتعلم البرمجة للأطفال- مفتاح المستقبل الرقمي.pdf
تعلم البرمجة للأطفال- مفتاح المستقبل الرقمي.pdf
elmadrasah8
 

Recently uploaded (9)

687065تاىىز458-الخط-الزمني-و-الخريطة.pptx
687065تاىىز458-الخط-الزمني-و-الخريطة.pptx687065تاىىز458-الخط-الزمني-و-الخريطة.pptx
687065تاىىز458-الخط-الزمني-و-الخريطة.pptx
 
تدريب ف دوره على برنامج 3 1 d max
تدريب  ف  دوره  على   برنامج  3 1 d  maxتدريب  ف  دوره  على   برنامج  3 1 d  max
تدريب ف دوره على برنامج 3 1 d max
 
تطور-الحركة-الوطنية-في-السودان-1919-–-1924-the-evolution-of-the-national-move...
تطور-الحركة-الوطنية-في-السودان-1919-–-1924-the-evolution-of-the-national-move...تطور-الحركة-الوطنية-في-السودان-1919-–-1924-the-evolution-of-the-national-move...
تطور-الحركة-الوطنية-في-السودان-1919-–-1924-the-evolution-of-the-national-move...
 
DOC-20240602-W ggdcvgccccbbA0000..pdf
DOC-20240602-W     ggdcvgccccbbA0000..pdfDOC-20240602-W     ggdcvgccccbbA0000..pdf
DOC-20240602-W ggdcvgccccbbA0000..pdf
 
تدريب ف دوره على برنامج 3 2 d max
تدريب  ف  دوره  على  برنامج  3  2  d  maxتدريب  ف  دوره  على  برنامج  3  2  d  max
تدريب ف دوره على برنامج 3 2 d max
 
ورشة تحليل الممارسات المهنية (قطب الإنسانيات).pptx
ورشة تحليل الممارسات المهنية (قطب الإنسانيات).pptxورشة تحليل الممارسات المهنية (قطب الإنسانيات).pptx
ورشة تحليل الممارسات المهنية (قطب الإنسانيات).pptx
 
مفهوم النخب_c2a9ebf68281ad450b0aec32b2014d05.pptx
مفهوم النخب_c2a9ebf68281ad450b0aec32b2014d05.pptxمفهوم النخب_c2a9ebf68281ad450b0aec32b2014d05.pptx
مفهوم النخب_c2a9ebf68281ad450b0aec32b2014d05.pptx
 
مقدمة عن لغة بايثون.pdf-اهم لغات البرمجة
مقدمة عن لغة بايثون.pdf-اهم لغات البرمجةمقدمة عن لغة بايثون.pdf-اهم لغات البرمجة
مقدمة عن لغة بايثون.pdf-اهم لغات البرمجة
 
تعلم البرمجة للأطفال- مفتاح المستقبل الرقمي.pdf
تعلم البرمجة للأطفال- مفتاح المستقبل الرقمي.pdfتعلم البرمجة للأطفال- مفتاح المستقبل الرقمي.pdf
تعلم البرمجة للأطفال- مفتاح المستقبل الرقمي.pdf
 

Decision support systems (ch10) prolog