المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Learn Prolog


اختكم في الله
06-30-2004, 03:21 PM
السلام عليكم...
سنحاول ان شاء الله في هذه المساحة ان نلقي درس بسيط في ال Prolog و اولا يجب التعريف بهذه اللغة ، ال Prolog هي اختصار لكلمة Programming in Logic ، و هي لغة تعتمد على المنطق كما هو واضح من التسمية ..
لغة البرولوج عبارة عن اجابات على اسئلة تطرح (Query) ، و هذه الاجابات يستوحيها او يحصل عليها البرنامج من الحقائق المعرفة (Facts) او القوانتين (Rules) المعرفة ايضا من قبل المبرمج ، هذا يحتاج الى امثلة سنوردها لاحقا...
كمقدمة يجب ان نعرف ان منطق عمل البرولوج هو اعتمادها على تكنيك ال Backtracking و هذ معناه ان البحث عن الاجابات من خلال الحقائق يبدأ من جديد عند كل قانون، و هذا ايضا يحتاج الى امثلة نوردها لا حقا...
من الطبيعي جدا ان نرى اشارة الاستفهام (؟ ) في البرولوج وذلك لانها عبارة عن اجابات لاسئلة مطروحة كما اوردنا...
مثال بسيط ، مثلا كحقيقة نستطيع ان نكتب father(jassim,ali) وكذلك father(ahmed,kadhem) و كقانون نستطيع ان نكتب brother(X,Y):-father(X,Z),father(Y,Z) اما بالنسبة للسؤال في البرنامج قفد يكون كالتالي: ?-father(ahmed,ali).
لاحقا سنعرف ان شاء الله كيف حصلنا على هذه الاجابات على الاسئلة المعروضة

المنهل
06-30-2004, 04:40 PM
موضوع ممتاز و أتمنى المواصلة
ودنا نتعلم و عندنا الأستعداد

+++
لكن الأمثلة ما فهمتها إلا بعد التركيز الشديد
لو كان هناك تنسيق للكتابة لكان أفضل
حيث يكون كل رمز في سطر بروحه... خصوصا الأشارات مثل () و ،

و نحن في أنتظار الطريقة التي أستخرجت الحل بها

و لك الشكر الجزيل.

اختكم في الله
06-30-2004, 06:49 PM
السلام عليكم
اسفة جدا لهذا القصور ، ولكن يبدو انه هناك مشكلة عند التنويع في الشرح بين اللغة العربية و اللغة الانجليزية...

اسفين مرة ثانية على القصور ، ونعدكم بالمزيد

نسألكم الدعاء
اختكم في الله

مطهر حسن
06-30-2004, 07:57 PM
father(jassim,ali)
father(ahmed,kadhem)

brother(X,Y):-father(X,Z),father(Y,Z)

?-father(ahmed,ali).


أعتقد باستخدام خاصية تنسيق الكود http://www.malkiya.net/vb/images/toolbox/code.gif .. يمكن كتابة الأكواد بشكل أفضل

تحياتي .. وشكرا لكم على هذه الجهود :)

Sheeva
06-30-2004, 10:29 PM
مشكورة اختي

حبيت اضيف...

موقع يقدم لكم نبذة عن لغة prolog



http://www.geocities.com/ai_group6/prolog.htm#2l

بما أن الكمبيوتر عندي فيه خلل.. يعني ماقدر ارفع الوصلة فووووق... تقدرون تسوون كوبي بيت حق الوصلة وتشوفون محتوياتها...:)

اختكم في الله
07-02-2004, 01:58 AM
The second Lesson in Prolog:

//The following are the facts which the program depend on to find the answers, the should be written in small letters without spaces and with a dot at the end of the fact
.(eat(ali,apple
.(eat(fatima,orange
.(eat(hassan,orange
.(father(ali,jassim
.(father(fatima,jassim
.(father(jassim,hassan
.(father(samaya,jassim

// The following are the queries of the program, the queries are just questions which the program try to answer depending on the facts above.

.(eat(fatima,orange-؟
yes.
//the query means does Fatima eats orange, the answer is yes since we have this fact above.

.(eat(ali,orange-؟
no
//the query means does ali eats orange, the answer is no since we don't have this fact above, the answer no means can't prove the query because we haven't this fact in our program.

.(eat(X,apple-؟
X=ali
no.
// X means a variable, every word begins with a capital letter means variable, the program will look in the facts to find what can't agree with the query, and he will find that eat(ali,apple) can agree with the query, ali will be instantiated with X, the answer will be X=ali, if I click Enter the program will look again on the queries to find if there are any other agreed queries , and since there are not, the answer will be no


Now please, depending on the facts above, write the answer for these queries:
.(father(ahmed,jassim-؟
.(father(Ahmed,jassim-؟

You can ask any question..
نسألكم الدعاء
اختكم في الله

اختكم في الله
07-05-2004, 03:16 PM
السلام عليكم
لازلنا في الدرس الاول من تعلم لغة البرولوج ، الا يوجد متابع للدرس؟؟

نسألكم الدعاء
اختكم في الله

صانع السلام
07-10-2004, 02:08 AM
بلى يوجد ..

نحن هنا ننظر بعين الإكبار و التعظيم لك أختي الكريمة ..
جهود جبارة ، تشكرين عليها ...
there is no fact from above contents these statemnts
therefore I think
.(father(ahmed,jassim-؟
no
.(father(Ahmed,jassim-؟
no
but I dont know what about Ahmed , the first letter is capital , is it variable ?? I dont think that ....

شكرا جزيلا مرة أخرى أختي الكريمة ..

تحياتي
صانع

اختكم في الله
07-11-2004, 03:14 PM
شكرا لك اخي صانع السلام على المتابعة ، احسنت الاجابة بالنسبة للسؤال الاول اما في السؤال الثاني فيجب ان نعتبر Ahmed متغير variable وذلك لانها بدأت ب capital letter وعليه فان الاجابة على السؤال الثاني ستكون كالتالي...

,Ahmed=ali
,Ahmed=fatima
,Ahmed=samaya
.no

وذلك بعد استخام الانتر بعد كل جواب..

الدرس الثاني...

في الدرس الثاني سنتعلم كيف نكتب القواعد في البرولوج حيث تعتمد القواعد على الحقائق الموجودة في البرنامج و من المهم ان نعرف بعض العلا مات و معانيها قبل كتابة القواعد..

not = +/
and = ,
or = ;
any thing can be instantiated here..=_
if , note we will use this sign widely in writing the rules.=:- .

والان سنتستخدم الحقائق التالية في كتابة القاعدة:
.(likes(ali,apple
.(likes(fatima,orange
.(likes(hassan,orange

اما القاعدة فهي عبارة عن التالي:
:-(friends(ْْْX,Y
,(likes(X,Z
.(likes(Y,Z

This means that X and Y are friends if they like the same thing which is Z.



:The query will be
.(friends(ali,fatima-؟
.no
To solve this rule the program will instatiate X with ali and Y with fatima and will try to find the same Z for them, the program will found that Z for ali is apple and the Z for fatima is orange which are different...

.(friends(fatima,hassan-؟
.yes
The program then will do the same jobtaking fatima as X and hassan as Y and it will find that the Z for the both are the same which orange

هذه نهاية الدرس الثاني ، اذا كان هناك اي استفهام فنحن في الانتظار...
نسألكم الدعاء
أختكم في الله

صانع السلام
07-12-2004, 01:48 AM
درس جدا جميل ..
أشعر بالمتعة عندما أقرأ نص لغة برمجة و أفهمة ..
كم هو جميل عالم البرمجة ..

شكرا جزيلا على هذا الدرس ..
و محن بانتظار المزيد ..

تحياتي

صانع

اختكم في الله
07-13-2004, 03:25 AM
سنواصل التعلم في كيفية كتابة القواعد في هذا الدرس و ذلك باستخام بعض الاشارات التي تم شرحها في الدرس السابق...
فمثلا اذا استخدمنا نفس الحقائق المعرفة في الدرس السابق وهي ...(likes(ali,apple
.(likes(fatima,orange
.(likes(hassan,orange

وكذلك عرفنا نفس القاعدة المعرفة في الدرس السابق وهي..
:-(friends(ْْْX,Y
,(likes(X,Z
.(likes(Y,Z

فانه بامكاننا ان نعرف قاعدة اخرى باستخدام القاعدة السابقة وهي..
:-(hates(ْْْX,Y
(friends(ْْْX,Y +/

which means that X hates Y if they are not friends

نسألكم الدعاء
اختكم في الله

اختكم في الله
07-13-2004, 03:58 AM
We can also define the minimum function which finds the minimum between two numbers which we do it widely in C..

:-(min(X,Y,X
!,X=<Y
:-(min(X,Y,Y
Y=<X

Note that the less than and equal sign is written such that it is not like arrow (<=) but (=<) and such that the more than and equal is written like this (>=)..
( ! ) this sign means cut, such that the program will stop if the rule succeed and will not go to the second rule...
The program will check if X is less than Y in the first rule if it suceed then no need to go to the next rule.
.(min(3, 5 ,3-?
yes
But if the query is not succeed by the first rule, it will go to the next rule like this query..
.(min(5, 3 ,3-؟
yes
also this program can find the minimum between two numbers..
.(min(3, 5 ,A-؟
A=3
where the program will instantiate A with X which is 3 using the first rule..

.(min(5, 3 ,A-؟
A=5
where the program will do the same after checking the first rule and passing to the next rule which achieve the query..

Can U pls answer these questions using the same two rules..
.(min(5, 3 ,5-؟
.(min(6, 9 ,B-؟
.(min(6, 6 ,B-؟

نسألكم الدعاء
اختكم في الله

صانع السلام
07-14-2004, 01:40 PM
سلام الله عليكم
جهود جبارة أختي الكريمة , و نحن دائما معكم منواصلون ، و لأسئلتكم مجاوبون ..

.(min(5, 3 ,5-؟
yes
.(min(6, 9 ,B-؟
B=6
.(min(6, 6 ,B-؟
B=6

لا زلنا متلهفين للمزيد
شكرا شكرا على هذه العطاء المتميز ..

تحياتي
صانع

السراج
07-14-2004, 02:26 PM
ما شاء الله تبارك الرحمن ،،
لدينا مبدعين ،، أينكم من ذي قبل ؟

أستمري أختي ،، فهناك من يرمق دروسك من بعيد :)

اختكم في الله
07-18-2004, 02:56 PM
شكرا لكم اخي السراج على تواصلكم في درسنا المتواضع...
اخي صانع السلام ، مرة اخرى تتحفنا باجاباتك الرائعة عدا انه في السؤال الاول


.(min(5, 3 ,5-؟
the answer must be no since the minimum between 5 and 3 is 3 and not 5.

Th lesson today is about the list in prolog, the list is a collection of order elements. The list in prolog consist of the head which is the first element in the list and the tail which is the rest of the elements in the list..
[X=[ 5 , 3 , 2 , 8, 6
the head of this list is 5 and the tail is [[ 5 , 3 , 2 , 8, 6
[Y=[hazen,sannea alssalam,alseraj
the head is hazen and the tail is [[sannea alssalam,alseraj

and so on..

If I made a function which do some process in the list the function will call it self to do the same process in all the list using the construction to construct the elements, this job is like the recursion functions.

.([ ])prlist
:-([prlist([H/T
,(write(H
,nl
.(prlist(T

This function is about printing a list say for example X=[[ 5 , 3 , 2 , 8 , 6 the list first will go in the first prlist and since it took the empty list it will not enstantiate with X which is full list then it will go to the second list and will construct the head H whic is 5 and will write it using the function ready function write and then new line will be made using the ready function nl. The tail the will go on the third prlist which will call the function again and the tail will go to the first prlist where will not be an istantiation between the tail and the empty list. This job will be done until the empty list is occured where it will instatiate with the first prlist and cannot be constructed by the second prlist.

The answer of this function for the X list will be:

5
3
2
8
6
yes

hope the lesson was easy
نسألكم الدعاء
اختكم في الله

صانع السلام
07-25-2004, 09:07 PM
جهد عظيم ، و دروس شيقة في هذه اللغة ...

أعتقد أنه ما شرحتيه هو أساس إلى recursion في لغة السي بلس بلس ...
و LIST أيضا كذلك...

أتمنى ألا ينقطع عنا الغيث ...
شكرا شكرا جزيلا ..

صانع

اختكم في الله
07-26-2004, 06:34 PM
شكرا لكم اخي صانع السلام على جهدكم البناء و تشجيعكم المحفز و عذرا لانقطاعنا لفترة بسبب بعض الانشغالات ، لكننا نعدكم بالمزيد فكونوا معنا...
نسألكم الدعاء
اختكم في الله