وكيل المعرفة: قاعدة المعرفة (KB) تخزن جملًا بلغة رسمية (Syntax + Semantics). النهج التقريري: أخبر الوكيل ما يحتاج معرفته، ثم اسأله عما يجب فعله. حلقة الاستدلال: تحويل المدركات → استعلام KB عن الإجراء → تسجيل الإجراء → زيادة العداد الزمني → تنفيذ الإجراء.
2. Wumpus World — Environment Properties (Exam Favorite)
Observable?
No — only local perception
Agent only senses current square (Breeze, Stench, Glitter, Bump, Scream)
Deterministic?
Yes — outcomes exactly specified
Actions have known, predictable results
Episodic?
No — sequential
Current actions affect future states (long-term planning needed)
Static?
Yes — no movement
Wumpus and Pits do not move
Discrete?
Yes
Finite states, finite percepts, finite actions
Single-agent?
Yes — Wumpus is a natural feature
Not an active opponent
📐 Key Wumpus World Rules
Breeze → Pit adjacentStench → Wumpus adjacentGlitter → Gold in cellBump → Hit wallScream → Wumpus killedWumpus dies if shotAgent dies in pit/Wumpus
⚠️ Exam Trap: Breeze in (1,2) and (2,1) ⇒ No safe actions! This is a classic Wumpus world tight spot. The agent can deduce pits must be in adjacent squares but cannot safely move.
عالم وامبوس: غير قابل للملاحظة الكاملة (إدراك محلي فقط)، حتمي، تسلسلي (ليس عرضيًا)، ثابت، متقطع، وكيل واحد. النسيم = حفرة مجاورة، الرائحة = وامبوس مجاور، اللمعان = ذهب، صوت الموت = قُتل الوامبوس. لا يوجد إجراء آمن إذا كان النسيم في (1,2) و (2,1) معًا.
Logic is a structured way to represent knowledge using formal languages with precise syntax and semantics.
It provides rules for valid reasoning, allowing us to derive new conclusions from existing facts without ambiguity.
📝 Syntax
The grammar/rules for constructing valid sentences. Defines what expressions are allowed in the language.
Example: In propositional logic, "P ∧ Q" is syntactically correct; "∧ P Q" is not.
🌍 Semantics
The meaning of sentences — defines truth conditions relative to possible worlds (models).
Example: "P ∧ Q" is true only when both P and Q are true in the world.
🔍 Inference
The process of deriving new sentences (conclusions) from existing ones while preserving truth.
Example: From "P ⇒ Q" and "P", infer "Q" (Modus Ponens).
💡 Why Logic in AI? Logic provides a declarative approach to knowledge representation — separate what the agent knows from how it reasons. This enables automated reasoning, theorem proving, and intelligent decision-making.
تعريف المنطق: المنطق هو طريقة منظمة لتمثيل المعرفة باستخدام لغات رسمية ذات قواعد نحوية (Syntax) دلالات (Semantics) محددة. يوفر قواعد للاستدلال الصحيح، مما يسمح باستنتاج حقائق جديدة من المعرفة الموجودة بدون غموض. التركيب (Syntax): قواعد تكوين الجمل الصحيحة. الدلالات (Semantics): تحديد معنى الجمل وشروط صدقها. الاستدلال (Inference): عملية اشتقاق استنتاجات جديدة مع الحفاظ على الصدق.
KB |= α
Entailment: In every model where KB is true, α must also be true
🔤 Propositional Logic — Connectives
Negation
¬S
"not S"
Conjunction
S₁ ∧ S₂
"S₁ and S₂"
Disjunction
S₁ ∨ S₂
"S₁ or S₂"
Implication
S₁ ⇒ S₂
"if S₁ then S₂"
Biconditional
S₁ ⇔ S₂
"S₁ if and only if S₂"
🕳️ Wumpus World in Propositional Logic
Pi,j = true if pit in [i,j]
Bi,j = true if breeze in [i,j]
Rule: B1,1 ⇔ (P1,2 ∨ P2,1)
"A square is breezy iff there is an adjacent pit"
3 Boolean choices for pits ⇒ 8 possible models
Model checking proves: KB |= α₁ ("[1,2] is safe")
المنطق: Syntax (قواعد تكوين الجمل)، Semantics (تحديد الصدق)، Model (عالم منظم لتقييم الصدق). الاستلزام: KB |= α إذا كانت α صحيحة في كل نموذج تكون فيه KB صحيحة. المنطق الافتراضي: روابط ¬ ∧ ∨ ⇒ ⇔. في عالم وامبوس: B₁,₁ ⇔ P₁,₂ ∨ P₂,₁. فحص النماذج يثبت أن المربع [1,2] آمن.
⚠️ ALWAYS use ⇒ with ∀!
✅ Correct: ∀x King(x) ⇒ Person(x)
❌ Wrong: ∀x King(x) ∧ Person(x) — This means "Everything is both a king and a person"
∃ Existential Quantification (∃) — "There Exists"
⚠️ ALWAYS use ∧ with ∃!
✅ Correct: ∃x Crown(x) ∧ OnHead(x, John)
❌ Wrong: ∃x Crown(x) ⇒ OnHead(x, John) — Logically too weak; true even if no crown exists!
FOL: كائنات، علاقات، دوال. المحمول الكلي ∀ يستخدم مع ⇒ (كل ملك هو شخص). المحمول الوجودي ∃ يستخدم مع ∧ (يوجد تاج على رأس جون). الترتيب مهم في المحمولات المتداخلة. ¬∀x P ≡ ∃x ¬P. المساواة = للتعبير عن التميز.
مشكلة الإطار: كيفية تمثيل ما لا يتغير بعد الإجراء دون كتابة عدد هائل من البديهيات. الحل: بديهية الحالة اللاحقة (Successor-State Axiom) تجمع التغيير وعدمه في قاعدة واحدة لكل خاصية. مثال: تملك السهم في الحالة التالية ⇔ لم تطلق النار وكنت تملكه سابقًا.
📑 Lecture 09 · pages 1–12🔗 Unification — The Key to FOL Inference
6. Unification in First-Order Logic
Unify(p, q) = θ where Subst(θ, p) = Subst(θ, q)
📌 Conditions for Unification
Predicate symbol must be identical
Number of arguments must match
No "occurs check" violation (cannot unify x with f(x))
Standardizing apart eliminates variable overlap
📊 Unification Examples (Exam Table)
p
q
θ (Unifier)
Knows(John, x)
Knows(John, Jane)
{x/Jane}
Knows(John, x)
Knows(y, OJ)
{x/OJ, y/John}
Knows(John, x)
Knows(y, Mother(y))
{y/John, x/Mother(John)}
Knows(John, x)
Knows(x, OJ)
FAILS (overlap)
Greedy(x)
Greedy(f(x))
FAILS (occurs check)
التوحيد: إيجاد تعويض θ يجعل تعبيرين متطابقين. الشروط: نفس المحمول، نفس عدد الوسائط، لا انتهاك لفحص الوقوع. أمثلة: Knows(John,x) مع Knows(John,Jane) تعطي θ={x/Jane}. يفشل إذا كان هناك تداخل في المتغيرات.
1. P ⇒ Q 2. Q ⇒ R 3. L ∧ M ⇒ P 4. B ∧ L ⇒ M 5. A ∧ P ⇒ L 6. A ∧ B ⇒ L
Facts: A, B
Goal: Q (or R)
Forward Chaining to Q
1. A, B given → Rule 6 fires → L added
2. B, L → Rule 4 fires → M added
3. L, M → Rule 3 fires → P added
4. P → Rule 1 fires → Q reached!
Backward Chaining from R
Goal: R → need Q (Rule 2)
Subgoal Q → need P (Rule 1)
Subgoal P → need L ∧ M (Rule 3)
L → need A ∧ B (Rule 6) — Facts match!
M → need B ∧ L (Rule 4) — Facts match!
Goal R proved!
الاستدلال الأمامي: يبدأ من الحقائق المعروفة ويطبق القواعد حتى الوصول للهدف. الاستدلال الخلفي: يبدأ من الهدف ويبحث عن قواعد تدعمه ثم يتحقق من مقدماتها كأهداف فرعية حتى الوصول للحقائق.
📑 Lecture 08 · pages 8–11🕳️ FOL Applied to Wumpus World
Returns bindings of variables that make the sentence true
📋 Action Terms
Turn(Right)Turn(Left)ForwardShootGrabClimb
قاعدة المعرفة في عالم وامبوس: قواعد الإدراك تحول المدركات إلى حقائق (نسيم، لمعان). استعلام الإجراء: ASKVARS يعيد ربط المتغيرات مثل {a/Grab}. إجراءات: استدر يمين/يسار، تقدم، أطلق، التقط، اصعد.
📑 Lecture 07 · pages 6–7🌫️ Fuzzy Logic vs Probability Theory
Wumpus agent: believes Wumpus in [1,3] with prob 0.75
المنطق الضبابي: درجة صدق بين 0 و1 (حقائق جزئية). نظرية الاحتمالات: درجة اعتقاد (عدم يقين حول حقيقة محددة). الأنطولوجيا: الكيانات الموجودة. الإبستيمولوجيا: كيفية الاستدلال عليها.
📌 Use Arabic translation buttons above each section | Key traps: ∀ with ⇒ (not ∧), ∃ with ∧ (not ⇒), occurs check in unification, Breeze in (1,2) & (2,1) ⇒ no safe actions