Chapterبەش 7 · Lectureوانە 7.1
Propositional Logic and Knowledge Basesلۆجیکی گوزارەیی و بنکەکانی زانین
How an AI can store facts and reason with them: propositions and symbols, the five connectives () and their truth tables, translating sentences into logic, knowledge bases, queries, entailment (KB ⊨ α) and model checking.
چۆن دەتوانێت ڕاستییەکان هەڵبگرێت و بە لۆجیک بیریان لێ بکاتەوە: و هێماکان، پێنج بەستەرەکە () و ، وەرگێڕانی ڕستە بۆ لۆجیک، ، ، (KB ⊨ α) و .
What you will learnچی فێر دەبیت
- Tell a proposition from other sentences and choose good proposition symbols.
- Use the five connectives and fill in their truth tables.
- Explain when an implication and a biconditional are true.
- Translate an English or Kurdish sentence into a formula with the right brackets.
- Explain knowledge base, query and entailment (KB ⊨ α), and decide entailment by model checking.
- لە ڕستەکانی دیکە جیا بکەیتەوە و هێمای باش بۆ هەڵبژێریت.
- پێنج بەستەرەکە بەکار بهێنیت و پڕ بکەیتەوە.
- ڕوونی بکەیتەوە و کەی ڕاستن.
- ڕستەیەکی ئینگلیزی یان کوردی بکەیت بە فۆرمولا بە کەوانەی دروستەوە.
- ، و (KB ⊨ α) ڕوون بکەیتەوە و بە بڕیار لەسەر بدەیت.
Why logic? Agents that know thingsبۆچی لۆجیک؟ ئەیجێنتەکان کە شت دەزانن
The search lessons built agents that find a path by trying moves. Another kind of agent knows facts about its world and reasons with them to find new facts. Such a knowledge-based agent keeps its facts as sentences in a knowledge base. Logic is the language of those sentences: it says exactly what a sentence means and which new sentences follow from it.
وانەکانی گەڕان ئەو دروست کرد کە بە تاقیکردنەوەی جووڵەکان ڕێگە دەدۆزنەوە. جۆرێکی دیکەی ڕاستییەکان دەربارەی جیهانەکەی دەزانێت و بە بیرکردنەوەی لۆجیکی ڕاستیی نوێ دەدۆزێتەوە. ئەم جۆرە ڕاستییەکانی وەک ڕستە لە هەڵدەگرێت. لۆجیک زمانی ئەو ڕستانەیە: ڕێک دەڵێت ڕستەیەک چ واتایەکی هەیە و چ ڕستەیەکی نوێ لێی دەکەوێتەوە.
An example from a winter day in Kurdistan: If it snows tonight, the road to Penjwen closes. If the road closes, Karwan stays at home. From these two facts you can conclude, without seeing the road: if it snows tonight, Karwan stays at home. In this lesson you learn how a computer can draw such conclusions safely.
نموونەیەک لە ڕۆژێکی زستانی کوردستان: ئەگەر ئەمشەو بەفر ببارێت، ڕێگای پێنجوێن دادەخرێت. ئەگەر ڕێگاکە دابخرێت، کاروان لە ماڵەوە دەمێنێتەوە. لەم دوو ڕاستییە، بەبێ بینینی ڕێگاکە، دەگەیتە ئەو ئەنجامەی کە: ئەگەر ئەمشەو بەفر ببارێت، کاروان لە ماڵەوە دەمێنێتەوە. لەم وانەیەدا فێر دەبیت کۆمپیوتەر چۆن دەتوانێت بە شێوەیەکی متمانەپێکراو ئەم جۆرە ئەنجامانە دەربهێنێت.
The simplest logic: its sentences are proposition symbols (P, Q, R …) joined by connectives such as ¬ (not), ∧ (and), ∨ (or), → (if … then) and ↔ (if and only if).
سادەترین لۆجیکە: ڕستەکانی لە (P، Q، R …) پێک دێن کە بە بەستەری وەک ¬ (نا)، ∧ (و)، ∨ (یان)، → (ئەگەر … ئەوا) و ↔ (ئەگەر و تەنیا ئەگەر) بەیەکەوە دەبەسترێن.
Propositional logic is the simplest logic: it gives a symbol to each sentence that can be true or false, and joins symbols with a few connectives.
سادەترین لۆجیکە: هێمایەک دەدات بە هەر ڕستەیەک کە دەکرێت ڕاست یان هەڵە بێت و هێماکان بە چەند بەستەرێک پێکەوە دەبەستێت.
Propositions and symbolsگوزارەکان و هێماکان
A statement that is either true or false, such as "It is raining".
ڕستەیەکە کە یان ڕاستە یان هەڵە، وەک «باران دەبارێت».
"It is raining" is a proposition: it is either true or false. "Is it raining?" and "Close the window!" are not: a question or an order is neither true nor false.
«باران دەبارێت» : یان ڕاستە یان هەڵە. «ئایا باران دەبارێت؟» و «پەنجەرەکە دابخە!» نین: پرسیار یان فەرمان نە ڕاستە و نە هەڵە.
To write propositions short, we give each one a capital letter, a proposition symbol. The course takes the letters from P to Z: P, Q, R, S, T… (this is a habit, not a rule; in code we often use names such as rain). Write each symbol as one simple statement, without the connective words and, or, not, if or either. For example:
بۆ کورتکردنەوەی ، پیتێکی گەورە دەدەین بە هەر یەکێکیان، واتە . کۆرسەکە پیتەکانی P تا Z بەکار دەهێنێت: P، Q، R، S، T… (ئەمە نەریتێکە، نەک یاسا؛ لە کۆددا زۆرجار ناوی وەک rain بەکار دەهێنین). هەر هێمایەک وەک یەک ڕستەی سادە بنووسە، بەبێ وشە بەستەرەکانی وەک و، یان، نا، ئەگەر یان یان…یان. بۆ نموونە:
| Symbolهێما | Proposition |
|---|---|
| P | It is raining.باران دەبارێت. |
| Q | It is snowing.بەفر دەبارێت. |
| R | I have an umbrella.چەترم هەیە. |
| S | I will stay dry.وشک دەمێنمەوە. |
| T | I will get wet.تەڕ دەبم. |
The five connectivesپێنج بەستەرەکە
Connectives (also called logical operators) join propositions into bigger sentences. Propositional logic uses five:
بەستەرەکان (کە هەروەها پێیان دەوترێت ) پێکەوە دەبەستن و ڕستەی گەورەتر دروست دەکەن. پێنجیان بەکار دەهێنێت:
| Signهێما | In the course pictureلە وێنەکەی کۆرسەکەدا | Name of the signناوی هێماکە | Connectiveبەستەر | Read it asوا دەیخوێنیتەوە |
|---|---|---|---|---|
| ¬ | ~ | tildetilde (تیلدە) | negation (NOT)نەفی (NOT) | "it is not the case that …"«وا نییە کە …» |
| ∧ | & | ampersandampersand (ئەمپەرساند) | conjunction (AND)بەستنەوە بە «و» (AND) | "… and …"«… و …» |
| ∨ | ∨ | wedgewedge (وێج) | disjunction (OR)بەستنەوە بە «یان» (OR) | "… or …"«… یان …» |
| → | → | arrowarrow (تیر) | conditional: مەرجی: | "if … then …"«ئەگەر … ئەوا …» |
| ↔ | ↔ | double arrowdouble arrow (تیری دووسەر) | "… if and only if …"«… ئەگەر و تەنیا ئەگەر …» |
If you know PHP, you have met AND, OR and NOT as its logical operators (&&, ||, !): they follow exactly the same truth tables.
ئەگەر PHP دەزانیت، AND، OR و NOTـت وەک کارپێکەرە لۆجیکییەکانی (&&، ||، !) بینیوە: ڕێک هەمان پەیڕەو دەکەن.
Truth tablesخشتەکانی ڕاستی
A table that lists every combination of true and false for the symbols and shows the value of a sentence in each row.
خشتەیەکە کە هەموو تێکەڵەکانی ڕاست و هەڵە بۆ هێماکان ڕیز دەکات و نرخی ڕستەکە لە هەر ڕیزێکدا پیشان دەدات.
Here is the truth table of all five connectives for two symbols A and B (T = true, F = false). Two symbols give 2 × 2 = 4 rows:
ئەمە هەر پێنج بەستەرەکەیە بۆ دوو هێمای A و B (T = ڕاست، F = هەڵە). دوو هێما 2 × 2 = 4 ڕیز دەدەن:
| A | B | ¬B | A ∧ B | A ∨ B | A → B | A ↔ B |
|---|---|---|---|---|---|---|
| T | T | F | T | T | T | T |
| T | F | T | F | T | F | F |
| F | T | F | F | T | T | F |
| F | F | T | F | F | T | T |
- ¬ flips the value: ¬B is T when B is F.
- ∧ is T only when both sides are T.
- ∨ is T when at least one side is T (also when both are: an inclusive or).
- is F in only one row: A is T and B is F.
- ↔ is T when both sides have the same value.
- ¬ نرخەکە پێچەوانە دەکاتەوە: ئەگەر B هەڵە (F) بێت، ¬B ڕاستە (T).
- ∧ تەنیا کاتێک ڕاستە کە هەردوو لا ڕاست بن.
- ∨ کاتێک ڕاستە کە لانیکەم یەک لا ڕاست بێت (هەروەها کاتێک هەردووکیان ڕاست بن: «یان»ـی گشتگیر).
- تەنیا لە یەک ڕیزدا هەڵەیە: کاتێک A ڕاستە و B هەڵەیە.
- ↔ کاتێک ڕاستە کە هەردوو لا هەمان نرخیان هەبێت.
# The truth table of the five connectives, worked out by Python.
def tf(value):
return "T" if value else "F"
print("A B | ¬B A∧B A∨B A→B A↔B")
for a in (True, False):
for b in (True, False):
row = [not b, a and b, a or b, (not a) or b, a == b]
print(tf(a), "", tf(b), " |", " ".join(tf(v) for v in row))A B | ¬B A∧B A∨B A→B A↔B T T | F T T T T T F | T F T F F F T | F F T T F F F | T F F T T
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-3
Turn
True/Falseinto the letters T/F.True/Falseدەکات بە پیتەکانی T/F.- Lineدێڕی 7-8
Two nested loops give the four rows.
دوو چوار ڕیزەکە دەدەن.
- Lineدێڕی 9
A → Bhas no Python operator, so we write it as(not a) or b;A ↔ Bisa == b.A → Bنییە، بۆیە وەک(not a) or bدەینووسین؛A ↔ Bبریتییە لەa == b.
Implication: if … then …گوزارەی مەرجی: ئەگەر … ئەوا …
The connective P → Q, 'if P then Q'. It is false only when P is true and Q is false.
بریتییە لە بەستەری P → Q، واتە «ئەگەر P ئەوا Q». تەنیا کاتێک هەڵەیە کە P ڕاست بێت و Q هەڵە بێت.
An implication P → Q connects two statements: if the first one (the antecedent, P) is true, then the second one (the consequent, Q) must also be true. As the truth table shows, an implication is false only when the first input is true and the second input is false.
P → Q دوو ڕستە پێکەوە دەبەستێت: ئەگەر یەکەمیان (پێشەکی، P) ڕاست بێت، ئەوا دووەمیان (دەرەنجام، Q)ـیش دەبێت ڕاست بێت. وەک لە دیارە، تەنیا کاتێک هەڵەیە کە یەکەم ڕاست بێت و دووەم هەڵە بێت.
Karwan's father says: "If it snows tonight, I will drive you to school tomorrow." When has he broken his promise? Only if it snows and he does not drive Karwan. If it does not snow, he has kept his word whether he drives or not: he promised nothing for a day without snow. That is why P → Q is true in every row where P is false.
باوکی کاروان دەڵێت: «ئەگەر ئەمشەو بەفر ببارێت، سبەینێ بە ئۆتۆمبێل دەتبەم بۆ قوتابخانە.» کەی بەڵێنەکەی شکاندووە؟ تەنیا ئەگەر بەفر ببارێت و کاروان نەبات. ئەگەر بەفر نەبارێت، بەڵێنەکەی بەجێ هێناوە چ بیبات چ نەیبات: بۆ ڕۆژێکی بێ بەفر هیچ بەڵێنێکی نەداوە. بۆیە P → Q لە هەموو ئەو ڕیزانەدا ڕاستە کە P تێیاندا هەڵەیە.
Where the analogy stops workingسنووری ئەم نموونەیە
In everyday speech "if" often means that P causes Q. In logic, needs no cause or connection: "If 2 + 2 = 5, then Penjwen is in Germany" is a true implication, because its first part is false.
لە قسەی ڕۆژانەدا «ئەگەر» زۆرجار واتای ئەوە دەدات کە P دەبێتە هۆی Q. لە لۆجیکدا پێویستی بە هۆ یان پەیوەندی نییە: «ئەگەر 2 + 2 = 5 بێت، ئەوا پێنجوێن لە ئەڵمانیایە» ڕاستە، چونکە بەشی یەکەمی هەڵەیە.
Biconditional: if and only ifگوزارەی دوومەرجی: ئەگەر و تەنیا ئەگەر
The connective P ↔ Q, 'P if and only if Q'. It is true when both sides have the same truth value.
بریتییە لە بەستەری P ↔ Q، واتە «P ئەگەر و تەنیا ئەگەر Q». کاتێک ڕاستە کە هەردوو لا هەمان نرخی ڕاستییان هەبێت.
A biconditional is true only when both parts have the same truth value: both true or both false. P ↔ Q means the same as (P → Q) ∧ (Q → P): the rule works in both directions.
تەنیا کاتێک ڕاستە کە هەردوو بەشەکەی هەمان نرخی ڕاستییان هەبێت: هەردووکیان ڕاست یان هەردووکیان هەڵە. P ↔ Q هەمان واتای (P → Q) ∧ (Q → P) دەدات: یاساکە بە هەردوو ئاڕاستەدا کار دەکات.
Example: "You can enter the club if and only if you are 18 years old." P: You can enter the club. Q: You are 18 years old. So P ↔ Q, which means: ✔ if you are 18, you can enter; ✔ if you are not 18, you cannot enter.
نموونە: «دەتوانیت بچیتە ناو یانەکەوە ئەگەر و تەنیا ئەگەر تەمەنت 18 ساڵ بێت.» P: دەتوانیت بچیتە ناو یانەکەوە. Q: تەمەنت 18 ساڵە. کەواتە P ↔ Q، واتە: ✔ ئەگەر 18 ساڵ بیت، دەتوانیت بچیتە ژوورەوە؛ ✔ ئەگەر 18 ساڵ نەبیت، ناتوانیت بچیتە ژوورەوە.
From English to logicلە زمانی ئاساییەوە بۆ لۆجیک
- Find the simple statementsڕستە سادەکان بدۆزەرەوە
Give each simple statement a symbol (P, Q, R, …). Leave out the connective words.
هێمایەک بدە بە هەر ڕستەیەکی سادە (P، Q، R، …). وشە بەستەرەکان لابدە.
- Find the connective wordsوشە بەستەرەکان بدۆزەرەوە
and → , or → , not → , if … then → , if and only if → .
و ← ، یان ← ، نا ← ، ئەگەر … ئەوا ← ، ئەگەر و تەنیا ئەگەر ← .
- Write the sentence with bracketsڕستەکە بە کەوانەوە بنووسە
Use brackets to show which parts belong together.
کەوانە بەکاربهێنە بۆ پیشاندانی ئەوەی کام بەشانە پێکەوەن.
- Check itبیپشکنە
Later, model checking tests the sentence in every possible world.
دواتر ڕستەکە لە هەموو جیهانێکی گونجاودا تاقی دەکاتەوە.
Example 1
نموونەی ١
"If it is raining or snowing, and I have an umbrella, then I will stay dry, and not get wet." With P: It is raining, Q: It is snowing, R: I have an umbrella, S: I will stay dry, T: I will get wet:
«ئەگەر باران یان بەفر ببارێت و چەترم هەبێت، ئەوا وشک دەمێنمەوە و تەڕ نابم.» بە P: باران دەبارێت، Q: بەفر دەبارێت، R: چەترم هەیە، S: وشک دەمێنمەوە، T: تەڕ دەبم:
(P ∨ Q) ∧ R → (S ∧ ¬T)
From English to logicلە زمانی ئاساییەوە بۆ لۆجیک
More examplesنموونەی زیاتر
| Sentenceڕستە | Symbolsهێماکان | Logicلۆجیک |
|---|---|---|
| "If I study hard and get enough sleep, then I will either pass the exam or not be tired."«ئەگەر زۆر بخوێنم و بەس بخەوم، ئەوا یان لە تاقیکردنەوەکە دەردەچم یان ماندوو نابم.» | P: I study hard; Q: I get enough sleep; R: I will pass the exam; S: I will be tiredP: زۆر دەخوێنم؛ Q: بەس دەخەوم؛ R: لە تاقیکردنەوەکە دەردەچم؛ S: ماندوو دەبم | (P ∧ Q) → (R ∨ ¬S) |
| "If I study hard and do not get enough sleep, then I will either pass the exam or not be tired."«ئەگەر زۆر بخوێنم و بەس نەخەوم، ئەوا یان لە تاقیکردنەوەکە دەردەچم یان ماندوو نابم.» | the same P, Q, R, Sهەمان P، Q، R، S | (P ∧ ¬Q) → (R ∨ ¬S) |
| "I will go to the party if and only if my best friend goes."«دەچم بۆ ئاهەنگەکە ئەگەر و تەنیا ئەگەر باشترین هاوڕێکەم بچێت.» | P: I will go to the party; Q: My best friend goesP: دەچم بۆ ئاهەنگەکە؛ Q: باشترین هاوڕێکەم دەچێت | P ↔ Q |
Knowledge basesبنکەکانی زانین
A set of sentences that an agent knows (or believes) to be true about the world, written in a logic so that new facts can be inferred from them.
کۆمەڵێک ڕستەیە کە دەیزانێت (یان باوەڕی وایە) دەربارەی جیهان ڕاستن؛ بە زمانێکی لۆجیکی نووسراون بۆ ئەوەی ڕاستیی نوێیان لێ دەربهێنرێت.
We have all heard the word database: it is made of data and base. "Base" means a base or store («بنکە»): a database is a store that holds data. In the same way, a knowledge base (KB) is a set of facts, sentences we know to be true, that a system uses. In logic we join the facts of a KB with ∧, because all of them are true at the same time.
هەموومان وشەی مان بیستووە: لە Data و Base پێکهاتووە. «Base» بە واتای «بنکە» دێت: بنکەیەکە کە لەخۆ دەگرێت. بە هەمان شێوە، (KB) کۆمەڵێک ڕاستییە، واتە ئەو ڕستانەی دەزانین ڕاستن، کە سیستەمێک بەکاریان دەهێنێت. لە لۆجیکدا ڕاستییەکانی KB بە ∧ پێکەوە دەبەستین، چونکە هەموویان لە یەک کاتدا ڕاستن.
A small example. Two facts: 1. All humans are mortal (all humans die). 2. Aram is a human. These two sentences are our knowledge base. Using reasoning we can make a new sentence: Aram is mortal.
نموونەیەکی بچووک. دوو ڕاستی: ١. هەموو مرۆڤەکان دەمرن. ٢. ئارام مرۆڤە. ئەم دوو ڕستەیە . بە بیرکردنەوەی لۆجیکی دەتوانین ڕستەیەکی نوێ دروست بکەین: ئارام دەمرێت.
Queries and entailment (⊨)پرسەکان و لێکەوتنەوە (⊨)
In logic, a sentence α that we ask about: does it follow from the knowledge base?
لە لۆجیکدا، ڕستەیەکە (α) کە پرسیاری لەسەر دەکەین: ئایا لە دەکەوێتەوە؟
In AI and logic, alpha (α) is the query: the sentence that we check against our knowledge base, to see whether it follows from it. Example: ("if Aram is a human, he is mortal" and "Aram is a human"). Query α: M, "Is Aram mortal?" If we can show that KB ⊨ α, then α is true according to the KB.
لە و لۆجیکدا، ئەلفا (α) : ئەو ڕستەیەی بە دەیپشکنین بۆ ئەوەی بزانین لێی دەکەوێتەوە یان نا. نموونە: («ئەگەر ئارام مرۆڤ بێت، دەمرێت» و «ئارام مرۆڤە»). α: M، «ئایا ئارام دەمرێت؟» ئەگەر بتوانین پیشانی بدەین کە KB ⊨ α، ئەوا α بەپێی KB ڕاستە.
KB ⊨ α means that α is true in every model in which the knowledge base is true: whenever the KB is true, α must be true too. (⊢ means something different: α can be proved.)
KB ⊨ α واتە α لە هەموو ئەو ڕاستە کە تێیاندا ڕاستە: هەر کاتێک KB ڕاست بێت، αیش دەبێت ڕاست بێت. (⊢ واتایەکی ترە: دەکرێت α بسەلمێنرێت.)
| Pointخاڵ | Implication: P → Q: P → Q | Entailment: KB ⊨ α: KB ⊨ α |
|---|---|---|
| What is it?چییە؟ | A connective inside a sentenceبەستەرێکە لەناو ڕستەیەکدا | A statement about sentencesڕستەیەکە دەربارەی ڕستەکان |
| True or false…ڕاست یان هەڵە… | in one model (one row of the table)لە یەک (یەک ڕیزی خشتەکە) | considering all modelsبە لەبەرچاوگرتنی هەموو |
| Exampleنموونە | rain → bus can be one fact of a KBrain → bus دەتوانێت یەکێک لە ڕاستییەکانی KB بێت | KB ⊨ bus asks whether bus must be trueKB ⊨ bus دەپرسێت ئایا bus دەبێت ڕاست بێت |
When we ask the KB a question α, there are three possible answers: yes (KB ⊨ α), no (KB ⊨ ¬α), or unknown (neither: the KB does not contain enough knowledge).
کاتێک پرسیاری α لە KB دەکەین، سێ وەڵامی گونجاو هەیە: بەڵێ (KB ⊨ α)، نەخێر (KB ⊨ ¬α)، یان نەزانراو (هیچیان: KB زانیاریی پێویستی تێدا نییە).
Harvard's CS50 AI lecturer explains each idea with clear pictures and Python code; each placement plays only the chapter that matches its screen.
مامۆستای کۆرسی CS50 AIـی زانکۆی Harvard هەر بیرۆکەیەک بە وێنەی ئاشکرا و کۆدی ڕوون دەکاتەوە؛ لە هەر شوێنێک تەنها ئەو بەشەی لێدەدرێت کە لەگەڵ ئەو شاشەیە دەگونجێت.
Plays 2:08:03–2:11:15: what a knowledge base is, entailment (α ⊨ β: in every world where α is true, β is true too) and what inference means.
لە 2:08:03 تا 2:11:15 لێدەدرێت: چییە، (α ⊨ β: لە هەر جیهانێکدا α ڕاست بێت، βـیش ڕاستە) و واتای چییە.
Model checking: try every possible worldپشکنینی مۆدێل: هەموو جیهانێکی گونجاو تاقی بکەرەوە
In logic, one assignment of true or false to every proposition symbol: one possible world, one row of the truth table.
لە لۆجیکدا، دانانی ڕاست یان هەڵەیە بۆ هەر : یەک جیهانی گونجاو، یەک ڕیزی .
With 1 symbol there are 2 models (T or F); every new symbol doubles the number. So with n symbols there are 2ⁿ models. That is what the course's note means: "Model Checking = 2 ^ 5 = 32": Example 1 has 5 symbols (P, Q, R, S, T), so model checking must look at 2⁵ = 32 models, the 32 rows of its truth table.
بە 1 هێما 2 هەیە (T یان F)؛ هەر هێمایەکی نوێ ژمارەکە دوو هێندە دەکات. کەواتە بە n هێما 2ⁿ هەیە. ئەمە واتای تێبینییەکەی کۆرسەکەیە: «Model Checking = 2 ^ 5 = 32»: نموونەی ١ 5 هێمای هەیە (P، Q، R، S، T)، بۆیە دەبێت سەیری 2⁵ = 32 بکات، واتە 32 ڕیزی .
Deciding whether KB ⊨ α by checking every model: if α is true in every model where the KB is true, the KB entails α. With n symbols there are 2ⁿ models to check.
بڕیاردانە لەسەر ئەوەی ئایا KB ⊨ α بە پشکنینی هەموو : ئەگەر α لە هەموو ئەو مۆدێلانەدا ڕاست بێت کە KB تێیاندا ڕاستە، ئەوا α لە KB دەکەوێتەوە. بە n هێما 2ⁿ مۆدێل هەیە بۆ پشکنین.
List every model of the symbols.
هەموو هێماکان ڕیز بکە.
Keep only the models where the KB is true.
تەنیا ئەو بهێڵەرەوە کە KB تێیاندا ڕاستە.
Check α in each of them. If α is true in all of them, KB ⊨ α. One model where the KB is true and α is false is a counter-example: then KB does not entail α.
α لە هەریەکەیاندا بپشکنە. ئەگەر α لە هەموویاندا ڕاست بێت، KB ⊨ α. یەک کە KB تێیدا ڕاست و α هەڵە بێت نموونەیەکی پێچەوانەیە: ئەوکات α لە KB ناکەوێتەوە.
Let us check the snow story. P: it snows, Q: the road to Penjwen closes, R: Karwan stays at home. . Question 1: ? Question 2: R?
با چیرۆکی بەفرەکە بپشکنین. P: بەفر دەبارێت، Q: ڕێگای پێنجوێن دادەخرێت، R: کاروان لە ماڵەوە دەمێنێتەوە. . پرسیاری یەکەم: ؟ پرسیاری دووەم: R؟
# Model checking with plain loops: the snow story.
# P = it snows, Q = the road to Penjwen closes, R = Karwan stays at home
from itertools import product
def tf(value):
return "T" if value else "F"
kb_models = 0 # models where the KB is true
query_holds = 0 # ... and where P → R is also true
r_holds = 0 # ... and where R is also true
print("P Q R | KB | P→R | R")
for p, q, r in product([True, False], repeat=3):
kb = ((not p) or q) and ((not q) or r) # (P → Q) ∧ (Q → R)
query = (not p) or r # P → R
print(tf(p), "", tf(q), "", tf(r), " |", tf(kb), " |", tf(query), " |", tf(r))
if kb:
kb_models += 1
query_holds += query
r_holds += r
print("KB is true in", kb_models, "of 8 models.")
print("P → R is true in", query_holds, "of them:",
"KB ⊨ P → R" if query_holds == kb_models else "not entailed")
print("R is true in", r_holds, "of them:",
"KB ⊨ R" if r_holds == kb_models else "not entailed")P Q R | KB | P→R | R T T T | T | T | T T T F | F | F | F T F T | F | T | T T F F | F | F | F F T T | T | T | T F T F | F | T | F F F T | T | T | T F F F | T | T | F KB is true in 4 of 8 models. P → R is true in 4 of them: KB ⊨ P → R R is true in 3 of them: not entailed
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 14
product([True, False], repeat=3)gives all 2³ = 8 models.product([True, False], repeat=3)هەموو 2³ = 8 دەدات.- Lineدێڕی 15-16
written in Python:
(not p) or q.بە :
(not p) or q.- Lineدێڕی 18-21
Count only the models where the KB is true. Adding
Truecounts as 1.تەنیا ئەو بژمێرە کە KB تێیاندا ڕاستە. زیادکردنی
Trueوەک 1 دەژمێردرێت.
The answer to question 1 is yes: if it snows, Karwan stays at home. The answer to question 2 is unknown: maybe it does not snow and Karwan goes out. Model checking is simple and always correct, but 2ⁿ grows very fast: 10 symbols give 1,024 models, 20 symbols over a million. The next lesson builds a small Python toolkit that does this for any knowledge base.
وەڵامی پرسیاری یەکەم بەڵێیە: ئەگەر بەفر ببارێت، کاروان لە ماڵەوە دەمێنێتەوە. وەڵامی پرسیاری دووەم نەزانراوە: لەوانەیە بەفر نەبارێت و کاروان بچێتە دەرەوە. سادەیە و هەمیشە دروستە، بەڵام 2ⁿ زۆر خێرا گەورە دەبێت: 10 هێما 1,024 دەدات و 20 هێما زیاتر لە یەک ملیۆن. وانەی داهاتوو ئامرازێکی بچووکی دروست دەکات کە ئەمە بۆ هەر دەکات.
Harvard's CS50 AI lecturer explains each idea with clear pictures and Python code; each placement plays only the chapter that matches its screen.
مامۆستای کۆرسی CS50 AIـی زانکۆی Harvard هەر بیرۆکەیەک بە وێنەی ئاشکرا و کۆدی ڕوون دەکاتەوە؛ لە هەر شوێنێک تەنها ئەو بەشەی لێدەدرێت کە لەگەڵ ئەو شاشەیە دەگونجێت.
Plays 2:13:54–2:19:11: does KB ⊨ α? Model checking on paper: P (Tuesday), Q (raining), R (Harry runs), all 8 models, keep the ones where the KB is true.
لە 2:13:54 تا 2:19:11 لێدەدرێت: ئایا KB ⊨ α؟ لەسەر کاغەز: P (سێشەممەیە)، Q (باران دەبارێت)، R (Harry ڕادەکات)، هەر 8 ، پاشان تەنها ئەوانە هەڵدەبژێردرێن کە تێیاندا ڕاستە.
Inference rules and resolution (in brief)یاساکانی دەرەنجامگیری و Resolution (بە کورتی)
Model checking tries every model. Another way to reason is inference: start from the facts of the KB and derive new sentences step by step, using inference rules that never turn true sentences into false ones. Each new sentence is added to the KB.
هەموو تاقی دەکاتەوە. ڕێگەیەکی دیکەی بیرکردنەوە ـە: لە ڕاستییەکانی KBـەوە دەست پێدەکەیت و هەنگاو بە هەنگاو ڕستەی نوێ دەردەهێنیت، بە بەکارهێنانی کە هەرگیز ڕستەی ڕاست ناکەن بە هەڵە. هەر ڕستەیەکی نوێ دەخرێتە سەر KB.
| Ruleیاسا | Fromلە | You may concludeدەتوانیت ئەمە دەربهێنیت |
|---|---|---|
| Modus ponensیاسای Modus ponens | P → Q, P | Q |
| And eliminationلابردنی AND | P ∧ Q | P |
| Double negation eliminationلابردنی نەفیی دووانە | ¬¬P | P |
| Implication eliminationلابردنی | P → Q | ¬P ∨ Q |
| Biconditional eliminationلابردنی | P ↔ Q | (P → Q) ∧ (Q → P) |
| De Morgan's lawsیاساکانی De Morgan | ¬(P ∧ Q) / ¬(P ∨ Q) | ¬P ∨ ¬Q / ¬P ∧ ¬Q |
With modus ponens, the Aram example takes one step: from H → M and H we conclude M. Here the sign ⊢ is the right one: (H → M) ∧ H ⊢ M, because we derived M with a rule.
بە modus ponens، نموونەکەی ئارام یەک هەنگاوە: لە H → M و H، M دەردەهێنین. لێرەدا هێمای ⊢ دروستە: (H → M) ∧ H ⊢ M، چونکە Mـمان بە یاسایەک دەرهێنا.
Computer provers often use one powerful rule, resolution: from P ∨ Q and ¬P ∨ R, conclude Q ∨ R (P and ¬P cancel out). To prove α, the prover adds ¬α to the KB, writes everything as ANDs of ORs (conjunctive normal form), and applies resolution until it finds a contradiction. Then α must be true.
سەلمێنەرە کۆمپیوتەرییەکان زۆرجار یەک یاسای بەهێز بەکار دەهێنن، Resolution: لە P ∨ Q و ¬P ∨ R، Q ∨ R دەردەهێنرێت (P و ¬P یەکتر لادەبەن). بۆ سەلماندنی α، سەلمێنەرەکە ¬α دەخاتە سەر KB، هەموو شتێک وەک ANDـی چەند ORێک دەنووسێت (conjunctive normal form) و Resolution بەکار دەهێنێت تا دژبەرییەک دەدۆزێتەوە. ئەوکات α دەبێت ڕاست بێت.
Common mistakesهەڵە باوەکان
| Mistakeهەڵە | Why it is wrongبۆچی هەڵەیە | Do this insteadلە جیاتی ئەوە |
|---|---|---|
| Putting not or if inside a symbolدانانی نا یان ئەگەر لەناو هێمادا | The connective is hidden, so the formula is wrong.بەستەرەکە شاراوە دەبێت، بۆیە فۆرمولاکە هەڵە دەبێت. | Symbols are simple, positive statements; write , outside.هێماکان ڕستەی سادە و ئەرێنین؛ و لە دەرەوە بنووسە. |
| Leaving out bracketsلابردنی کەوانە | ∧ binds before ∨, so the meaning changes.∧ پێش ∨ دەبەستێت، بۆیە واتاکە دەگۆڕێت. | Bracket every group: (P ∨ Q) ∧ R.هەموو گرووپێک بخە ناو کەوانەوە: (P ∨ Q) ∧ R. |
| Thinking P → Q is false when P is falseوا بزانیت P → Q هەڵەیە کاتێک P هەڵە بێت | A promise about snowy days is not broken on a dry day.بەڵێنێک دەربارەی ڕۆژانی بەفرین لە ڕۆژێکی وشکدا ناشکێت. | is false only for . تەنیا بۆ هەڵەیە. |
| Reading ∨ as "one but not both"خوێندنەوەی ∨ وەک «یەکێکیان بەڵام نەک هەردووکیان» | In logic ∨ is also true when both sides are true.لە لۆجیکدا ∨ کاتێک هەردوو لاش ڕاست بن ڕاستە. | For "exactly one", write (P ∨ Q) ∧ ¬(P ∧ Q).بۆ «تەنیا یەکێک» بنووسە (P ∨ Q) ∧ ¬(P ∧ Q). |
| Using ⊢ or for entailmentبەکارهێنانی ⊢ یان بۆ | ⊨ is about all models; is inside one sentence; ⊢ is about proofs.⊨ دەربارەی هەموو ؛ لەناو یەک ڕستەدایە؛ ⊢ دەربارەی سەلماندنە. | Write KB ⊨ α.بنووسە KB ⊨ α. |
| Saying "not entailed" means "false"وتنی «لێی ناکەوێتەوە» بە واتای «هەڵەیە» | The KB may simply not know.لەوانەیە KB بە سادەیی نەزانێت. | Check α and ¬α: yes, no or unknown.α و ¬α بپشکنە: بەڵێ، نەخێر یان نەزانراو. |
Exercisesڕاهێنانەکان
The lab notes end with an empty template: P –, Q –, R –, S – and the formula . Choose four simple statements from your own day for P, Q, R and S, and write the English (or Kurdish) sentence that the formula says.
تێبینییەکانی تاقیگە بە قاڵبێکی بەتاڵ کۆتایی دێن: P –، Q –، R –، S – و فۆرمولای . چوار ڕستەی سادە لە ڕۆژی خۆت بۆ P، Q، R و S هەڵبژێرە و ئەو ڕستە کوردییە (یان ئینگلیزییە) بنووسە کە فۆرمولاکە دەیڵێت.
Hintئاماژە
Write the symbols first, without not. Then read ¬Q as "not Q".
یەکەمجار هێماکان بێ نا بنووسە. پاشان ¬Q وەک «Q نا» بخوێنەرەوە.
Show answerوەڵامەکە پیشان بدە
One possible answer. P: I get up early; Q: I drink tea; R: I catch the first bus; S: I feel sleepy. The formula says: "If I get up early and do not drink tea, then I catch the first bus or I do not feel sleepy." Check: the symbols are simple and positive; not appears only as ¬.
یەک وەڵامی گونجاو. P: زوو هەڵدەستم؛ Q: چا دەخۆمەوە؛ R: یەکەم پاس دەگرم؛ S: خەوم دێت. فۆرمولاکە دەڵێت: «ئەگەر زوو هەڵبستم و چا نەخۆمەوە، ئەوا یان یەکەم پاس دەگرم یان خەوم نایەت.» بیپشکنە: هێماکان سادە و ئەرێنین؛ نا تەنیا وەک ¬ دەردەکەوێت.
When is the sentence of Example 1, (P ∨ Q) ∧ R → (S ∧ ¬T), false? Say it in words.
ڕستەکەی نموونەی ١، (P ∨ Q) ∧ R → (S ∧ ¬T)، کەی هەڵەیە؟ بە وشە بیڵێ.
Show answerوەڵامەکە پیشان بدە
An implication is false only when its left side is true and its right side is false. So it is false when it rains or snows and I have an umbrella (left side true), but I do not stay dry or I do get wet (right side false). In every other case the sentence is true.
تەنیا کاتێک هەڵەیە کە لای چەپی ڕاست و لای ڕاستی هەڵە بێت. کەواتە هەڵەیە کاتێک باران یان بەفر دەبارێت و چەترم هەیە (لای چەپ ڕاستە)، بەڵام وشک نامێنمەوە یان تەڕ دەبم (لای ڕاست هەڵەیە). لە هەموو حاڵەتەکانی دیکەدا ڕستەکە ڕاستە.
. Is KB ⊨ bus? Use model checking with the 4 models of rain and bus.
. ئایا KB ⊨ bus؟ بە 4 rain و bus بەکاربهێنە.
Show answerوەڵامەکە پیشان بدە
| rain | bus | rain → bus | KB | bus |
|---|---|---|---|---|
| T | T | T | T | T |
| T | F | F | F | F |
| F | T | T | F | T |
| F | F | T | F | F |
The KB is true in only one model (rain = T, bus = T), and bus is true there. So KB ⊨ bus. This is modus ponens.
KB تەنیا لە یەک ڕاستە (rain = T، bus = T) و bus لەوێدا ڕاستە. کەواتە KB ⊨ bus. ئەمە modus ponensـە.
Write the club rule with exact symbols so that a 19-year-old can enter.
یاسای یانەکە بە هێمای ورد بنووسە بۆ ئەوەی کەسێکی 19 ساڵان بتوانێت بچێتە ژوورەوە.
Show answerوەڵامەکە پیشان بدە
P: You can enter the club. Q: You are 18 years old or older. Rule: P ↔ Q.
P: دەتوانیت بچیتە ناو یانەکەوە. Q: تەمەنت 18 ساڵ یان زیاترە. یاسا: P ↔ Q.
Summary and reviewپوختە و پێداچوونەوە
- A proposition is a statement that is true or false; a proposition symbol (P, Q, …) stands for one.
- Five connectives: (not), (and), (or), (if … then), (if and only if).
- P → Q is false only when P is true and Q is false; P ↔ Q is true when both have the same value.
- A knowledge base is the AND of the facts we know; a query α is a sentence we ask about.
- KB ⊨ α: α is true in every model where the KB is true. Model checking tests all 2ⁿ models.
- ڕستەیەکە کە ڕاستە یان هەڵە؛ (P، Q، …) نوێنەرایەتیی یەکێکیان دەکات.
- پێنج بەستەر: (نا)، (و)، (یان)، (ئەگەر … ئەوا)، (ئەگەر و تەنیا ئەگەر).
- P → Q تەنیا کاتێک هەڵەیە کە P ڕاست و Q هەڵە بێت؛ P ↔ Q کاتێک ڕاستە کە هەردووکیان هەمان نرخیان هەبێت.
- بریتییە لە ANDـی ئەو ڕاستییانەی دەیانزانین؛ α ڕستەیەکە کە پرسیاری لەسەر دەکەین.
- KB ⊨ α: α لە هەموو ئەو ڕاستە کە KB تێیاندا ڕاستە. هەموو 2ⁿ تاقی دەکاتەوە.
What is the difference between and ⊨?جیاوازیی نێوان و ⊨ چییە؟
is a connective inside one sentence and can be true or false in a model. ⊨ is a statement about sentences: KB ⊨ α says that α is true in every model of the KB.
بەستەرێکە لەناو یەک ڕستەدا و لە دەکرێت ڕاست یان هەڵە بێت. ⊨ ڕستەیەکە دەربارەی ڕستەکان: KB ⊨ α دەڵێت α لە هەموو KBدا ڕاستە.
Why does Example 1 need brackets?بۆچی نموونەی ١ پێویستی بە کەوانەیە؟
Without brackets ∧ is applied before ∨, so "P ∨ Q ∧ R" would mean P ∨ (Q ∧ R), a different sentence.
بەبێ کەوانە ∧ پێش ∨ جێبەجێ دەکرێت، بۆیە «P ∨ Q ∧ R» واتای P ∨ (Q ∧ R) دەدات، کە ڕستەیەکی دیکەیە.
How many models does model checking need for 5 symbols? What does this tell you about speed?پشکنینی مۆدێل بۆ 5 هێما چەند مۆدێلی پێویستە؟ ئەمە چی دەربارەی خێرایی پێ دەڵێیت؟
2⁵ = 32. Every extra symbol doubles the work, so model checking becomes slow for large knowledge bases.
2⁵ = 32. هەر هێمایەکی زیادە کارەکە دوو هێندە دەکات، بۆیە بۆ گەورە خاو دەبێت.
A KB does not entail α and does not entail ¬α. What is the answer to the query?α لە KB ناکەوێتەوە و ¬αـش لێی ناکەوێتەوە. وەڵامی پرسەکە چییە؟
Unknown: the KB has models where α is true and models where α is false.
نەزانراو: KB هەندێک هەیە کە α تێیاندا ڕاستە و هەندێکی دیکە کە α تێیاندا هەڵەیە.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
Explains propositions, NOT, AND, OR, truth tables, implication and the biconditional, with clear pictures and examples.
، NOT، AND، OR، ، و ڕوون دەکاتەوە، بە وێنە و نموونەی ئاشکرا.
Whole video (10:31). It also shows XOR and logical equivalence, which the lesson does not need.
هەموو ڤیدیۆکە (10:31). هەروەها XOR و هاوتایی لۆجیکی پیشان دەدات کە وانەکە پێویستی پێیان نییە.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Reasoning with a Knowledge Base in Pythonبیرکردنەوە بە بنکەیەکی زانین لە Pythonـدا
Related lecturesوانە پەیوەندیدارەکان
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.