Artificial Intelligence · Unit 4 · 14 hrs
Knowledge Representation
Exam-focused notes for Knowledge Representation (Artificial Intelligence, CSC266): what the TU syllabus asks and how it has actually been tested, with 18 solved past questions from this unit.
Knowledge Representation in short
This unit is about representing what an intelligent system knows so that it can be reasoned over mechanically: the general issues any representation scheme must address, the main families of representation in use, propositional and predicate logic in enough formal detail to build and check a resolution proof, and two ways of representing what is not known for certain, probability and fuzzy logic.
What this unit covers
- Definition and importance of Knowledge
- Issues in Knowledge Representation
- Knowledge Representation Systems
- Properties of Knowledge Representation Systems
- Types of Knowledge Representation Systems: Semantic Nets, Frames, Conceptual Dependencies, Scripts, Rule Based Systems, Propositional Logic, Predicate Logic
- Propositional Logic(PL): Syntax, Semantics, Formal logic-connectives, truth tables, tautology, validity, well-formed-formula, Inference using Resolution, Backward Chaining and Forward Chaining
- Predicate Logic: FOPL, Syntax, Semantics, Quantification, Inference with FOPL: By converting into PL (Existential and universal instantiation), Unification and lifting, Inference using resolution
- Handling Uncertain Knowledge, Radom Variables, Prior and Posterior Probability, Inference using Full Joint Distribution, Bayes' Rule and its use, Bayesian Networks, Reasoning in Belief Networks
- Fuzzy Logic
Predicate Logic
2081 · 10 marks
What is Skolem constant? How is Skolemization done during resolution? Represent the following statements into FOPL. - All movies are not hit. - Sarangi is a movie. - All movies which have good script are hit. - Sarangi has a good script but Sarangi is sentimental. - There is a movie which is comedy.[10]
Show solved answerHide answer
Skolem Constant, Skolemization, and FOPL Representation
1. Skolem Constant
A Skolem constant is a special constant introduced during the process of Skolemization to eliminate existential quantifiers from a First Order Predicate Logic (FOPL) formula. When an existential quantifier appears in a formula without any enclosing universal quantifier, the existentially quantified variable is replaced by a unique new constant (called a Skolem constant) that represents the specific (but unnamed) individual whose existence is asserted.
Example:
- Formula:
∃x P(x) - After Skolemization:
P(a)whereais a Skolem constant.
If the existential quantifier is within the scope of a universal quantifier, the existential variable is replaced by a Skolem function (not a constant) of the universally quantified variables.
Example:
- Formula:
∀x ∃y Loves(x, y) - After Skolemization:
∀x Loves(x, f(x))wheref(x)is a Skolem function.
2. Skolemization During Resolution
Skolemization is the process of removing existential quantifiers from a FOPL formula to prepare it for resolution. Resolution works on clausal form (CNF), and existential quantifiers must be eliminated before conversion to clause form.
Steps of Skolemization (as part of full conversion to clause form):
| Step | Operation |
|---|---|
| 1 | Eliminate implications and biconditionals |
| 2 | Move negations inward (using De Morgan's laws) |
| 3 | Standardize variables apart |
| 4 | Move quantifiers to the left (Prenex Normal Form) |
| 5 | Skolemize: eliminate existential quantifiers |
| 6 | Drop universal quantifiers |
| 7 | Convert to Conjunctive Normal Form (CNF) |
| 8 | Write as a set of clauses |
Rules of Skolemization:
-
Case 1: If
∃xappears outside the scope of any universal quantifier, replacexwith a Skolem constant (e.g.,a,b,c).∃x Movie(x)becomesMovie(SK1)whereSK1is a Skolem constant. -
Case 2: If
∃xappears within the scope of universal quantifiers∀y1, ∀y2, ..., replacexwith a Skolem function of those variables.∀x ∃y HasScript(x, y)becomes∀x HasScript(x, f(x))wheref(x)is a Skolem function.
3. Representation of Statements into FOPL
Predicates Used:
Movie(x): x is a movieHit(x): x is a hitGoodScript(x): x has a good scriptSentimental(x): x is sentimentalComedy(x): x is a comedy
Statement 1: "All movies are not hit."
Every x, if x is a movie, then x is not a hit.
$$\forall x ; Movie(x) \Rightarrow \neg Hit(x)$$
Statement 2: "Sarangi is a movie."
Sarangi is a specific individual (constant).
$$Movie(Sarangi)$$
Statement 3: "All movies which have good script are hit."
Every x, if x is a movie AND x has a good script, then x is a hit.
$$\forall x ; [Movie(x) \wedge GoodScript(x)] \Rightarrow Hit(x)$$
Statement 4: "Sarangi has a good script but Sarangi is sentimental."
Conjunction of two facts about the constant Sarangi.
$$GoodScript(Sarangi) \wedge Sentimental(Sarangi)$$
Statement 5: "There is a movie which is comedy."
There exists some x such that x is a movie and x is a comedy.
$$\exists x ; [Movie(x) \wedge Comedy(x)]$$
After Skolemization (since ∃x has no enclosing universal quantifier, replace x with Skolem constant SK1):
$$Movie(SK1) \wedge Comedy(SK1)$$
Summary Table
| Statement | FOPL Representation |
|---|---|
| All movies are not hit | ∀x Movie(x) ⇒ ¬Hit(x) |
| Sarangi is a movie | Movie(Sarangi) |
| All movies with good script are hit | ∀x [Movie(x) ∧ GoodScript(x)] ⇒ Hit(x) |
| Sarangi has good script but is sentimental | GoodScript(Sarangi) ∧ Sentimental(Sarangi) |
| There is a movie which is comedy | ∃x [Movie(x) ∧ Comedy(x)] |
Note: Statements 1 and 3 appear contradictory (all movies are not hit vs. movies with good script are hit). This is intentional in the problem, likely to test resolution-based contradiction detection. In resolution, we would derive a contradiction from
Movie(Sarangi),GoodScript(Sarangi), Statement 1, and Statement 3.
2080 · 10 marks
Write the rules to convert statements in predicate logic into CNF form. Convert the following sentences into FOPL. All students of BSC CSIT are intelligent person. All friends of intelligent person are smart. Laxmi is a friend of Rojina. Rojina is smart. All beautiful students are girl. Laxmi is beautiful. Using resolution algorithm infer that 'Laxmi is smart'.[10]
Show solved answerHide answer
Converting Statements to CNF and Resolution in FOPL
Part 1: Rules to Convert FOPL into CNF
- Eliminate implications and biconditionals: replace $P \to Q$ with $\neg P \lor Q$, and $P \leftrightarrow Q$ with $(\neg P \lor Q) \land (\neg Q \lor P)$.
- Move negation inward (De Morgan / quantifier duals):
- $\neg(P \lor Q) \equiv \neg P \land \neg Q$
- $\neg(P \land Q) \equiv \neg P \lor \neg Q$
- $\neg \forall x,P(x) \equiv \exists x,\neg P(x)$
- $\neg \exists x,P(x) \equiv \forall x,\neg P(x)$
- $\neg\neg P \equiv P$
- Standardize variables apart: rename so each quantifier binds a unique variable.
- Move quantifiers to front (prenex form).
- Skolemize: replace existential variables with Skolem constants (no enclosing $\forall$) or Skolem functions of the enclosing universal variables.
- Drop universal quantifiers (remaining variables are implicitly universal).
- Distribute $\lor$ over $\land$: $P \lor (Q \land R) \equiv (P \lor Q) \land (P \lor R)$.
- Write as a set of clauses (each conjunct is a clause), renaming variables apart across clauses.
Part 2: FOPL Representation
Predicates:
- $CSIT(x)$: $x$ is a student of BSc CSIT
- $Intel(x)$: $x$ is an intelligent person
- $Friend(x,y)$: $x$ is a friend of $y$
- $Smart(x)$: $x$ is smart
- $Beautiful(x)$: $x$ is beautiful
- $Girl(x)$: $x$ is a girl
| Sentence | FOPL |
|---|---|
| All students of BSc CSIT are intelligent | $\forall x,(CSIT(x) \to Intel(x))$ |
| All friends of an intelligent person are smart | $\forall x,\forall y,((Intel(y) \land Friend(x,y)) \to Smart(x))$ |
| Laxmi is a friend of Rojina | $Friend(Laxmi, Rojina)$ |
| Rojina is smart | $Smart(Rojina)$ |
| All beautiful students are girls | $\forall x,((Beautiful(x) \land CSIT(x)) \to Girl(x))$ |
| Laxmi is beautiful | $Beautiful(Laxmi)$ |
Important data note. The conclusion "Laxmi is smart" uses the rule "all friends of an intelligent person are smart" plus "Laxmi is a friend of Rojina." So we need $Rojina$ to be an intelligent person. This requires $Rojina$ to be a BSc CSIT student, i.e. $CSIT(Rojina)$. This fact is NOT stated in the question. The listed facts ($Smart(Rojina)$, $Beautiful(Laxmi)$, "beautiful students are girls") do not lead to $Smart(Laxmi)$. As written, the proof is not derivable.
To make the intended chain work, the standard exam assumption is that Rojina is a BSc CSIT student ($CSIT(Rojina)$). I proceed with that assumption stated explicitly; without it, the inference fails.
Part 3: Convert to CNF (Clause Form)
- C1: $\neg CSIT(x) \lor Intel(x)$ (from sentence 1)
- C2: $\neg Intel(y) \lor \neg Friend(x,y) \lor Smart(x)$ (from sentence 2)
- C3: $Friend(Laxmi, Rojina)$
- C4: $Smart(Rojina)$
- C5: $\neg Beautiful(z) \lor \neg CSIT(z) \lor Girl(z)$ (from sentence 5)
- C6: $Beautiful(Laxmi)$
- C7 (assumed): $CSIT(Rojina)$
Part 4: Resolution to Infer "Laxmi is Smart"
Negated goal (C8): $\neg Smart(Laxmi)$
Step 1. Resolve C2 with C8, unifier ${x/Laxmi}$: $$\neg Intel(y) \lor \neg Friend(Laxmi, y) \lor Smart(Laxmi) ;\text{ and }; \neg Smart(Laxmi)$$ $$\Rightarrow \textbf{C9: } \neg Intel(y) \lor \neg Friend(Laxmi, y)$$
Step 2. Resolve C9 with C3 $Friend(Laxmi, Rojina)$, unifier ${y/Rojina}$: $$\Rightarrow \textbf{C10: } \neg Intel(Rojina)$$
Step 3. Resolve C10 with C1 $\neg CSIT(x) \lor Intel(x)$, unifier ${x/Rojina}$: $$\Rightarrow \textbf{C11: } \neg CSIT(Rojina)$$
Step 4. Resolve C11 with C7 $CSIT(Rojina)$: $$\Rightarrow \textbf{C12: } \square ;\text{(empty clause)}$$
Since we derived the empty clause (contradiction), the negated goal is false, so the original goal holds: $$\boxed{Smart(Laxmi) \text{ is TRUE}}$$
Caveat: This proof depends on the added premise $CSIT(Rojina)$. With only the six sentences exactly as given (no $CSIT(Rojina)$), the empty clause cannot be derived and "Laxmi is smart" is not provable. The clauses C5, C6 (beauty/girl) are irrelevant to this conclusion.
2079 · 5 marks
Convert Following Sentences into Predicate: a) All animal who can bark are dog. b) Someone is firing a gun c) All tigers are not fierce [5]
2079 · 5 marks
Writes short note of the following(any TWO): a. Pragmatic Analysis b. Unification and lifting c. Turing test [5]
2078 · 10 marks
Consider following facts: Every traffic chases driver. Every driver who horns is smart. No traffic catches any smart driver. Any traffic who chases some driver but does not catch him frusted. Now configure FoPL knowledge base for above statements. Use resolution algorithm to draw a conclusion that “If all drivers horn, then all traffics are frusted.”[10]
Show solved answerHide answer
Resolution Algorithm: Proving "If All Drivers Horn, Then All Traffics Are Frustrated"
Step 1: Identify the Facts and Convert to FoPL (First Order Predicate Logic)
Let us define the predicates:
Traffic(x): x is a trafficDriver(x): x is a driverHorns(x): x hornsSmart(x): x is smartChases(x, y): x chases yCatches(x, y): x catches yFrustrated(x): x is frustrated
FoPL Knowledge Base
| # | Natural Language Statement | FoPL Formula |
|---|---|---|
| F1 | Every traffic chases (every) driver | ∀x ∀y [Traffic(x) ∧ Driver(y) → Chases(x, y)] |
| F2 | Every driver who horns is smart | ∀x [Driver(x) ∧ Horns(x) → Smart(x)] |
| F3 | No traffic catches any smart driver | ∀x ∀y [Traffic(x) ∧ Smart(y) → ¬Catches(x, y)] |
| F4 | Any traffic who chases some driver but does not catch him is frustrated | ∀x ∀y [Traffic(x) ∧ Driver(y) ∧ Chases(x,y) ∧ ¬Catches(x,y) → Frustrated(x)] |
Goal (to prove):
If all drivers horn, then all traffics are frustrated.
∀x ∀y [Driver(y) ∧ Horns(y) ∧ Traffic(x) → Frustrated(x)]
Step 2: Convert All Statements to Conjunctive Normal Form (CNF) / Clause Form
Using the implication elimination rule: A → B ≡ ¬A ∨ B
C1 (from F1):
∀x ∀y [Traffic(x) ∧ Driver(y) → Chases(x, y)]
≡ ¬Traffic(x) ∨ ¬Driver(y) ∨ Chases(x, y)
C2 (from F2):
∀x [Driver(x) ∧ Horns(x) → Smart(x)]
≡ ¬Driver(x) ∨ ¬Horns(x) ∨ Smart(x)
C3 (from F3):
∀x ∀y [Traffic(x) ∧ Smart(y) → ¬Catches(x, y)]
≡ ¬Traffic(x) ∨ ¬Smart(y) ∨ ¬Catches(x, y)
C4 (from F4):
∀x ∀y [Traffic(x) ∧ Driver(y) ∧ Chases(x,y) ∧ ¬Catches(x,y) → Frustrated(x)]
≡ ¬Traffic(x) ∨ ¬Driver(y) ∨ ¬Chases(x,y) ∨ Catches(x,y) ∨ Frustrated(x)
Step 3: Negate the Goal (for Proof by Refutation / Resolution)
The goal to prove:
∀x ∀y [Traffic(x) ∧ Driver(y) ∧ Horns(y) → Frustrated(x)]
Negate the goal:
¬[∀x ∀y (Traffic(x) ∧ Driver(y) ∧ Horns(y) → Frustrated(x))]
≡ ∃x ∃y [Traffic(x) ∧ Driver(y) ∧ Horns(y) ∧ ¬Frustrated(x)]
Using Skolemization (replace existential variables with constants a and b):
C5: Traffic(a)
C6: Driver(b)
C7: Horns(b)
C8: ¬Frustrated(a)
Step 4: Apply Resolution Algorithm
We now have the clause set:
C1: ¬Traffic(x) ∨ ¬Driver(y) ∨ Chases(x, y)
C2: ¬Driver(x) ∨ ¬Horns(x) ∨ Smart(x)
C3: ¬Traffic(x) ∨ ¬Smart(y) ∨ ¬Catches(x, y)
C4: ¬Traffic(x) ∨ ¬Driver(y) ∨ ¬Chases(x,y) ∨ Catches(x,y) ∨ Frustrated(x)
C5: Traffic(a)
C6: Driver(b)
C7: Horns(b)
C8: ¬Frustrated(a)
Resolution Steps:
Step R1: Resolve C2 with C6 and C7
C2 : ¬Driver(x) ∨ ¬Horns(x) ∨ Smart(x) [x = b]
C6 : Driver(b)
C7 : Horns(b)
----------------------------------------------
R1 : Smart(b)
Step R2: Resolve C1 with C5 and C6
C1 : ¬Traffic(x) ∨ ¬Driver(y) ∨ Chases(x, y) [x = a, y = b]
C5 : Traffic(a)
C6 : Driver(b)
----------------------------------------------
R2 : Chases(a, b)
Step R3: Resolve C3 with C5 and R1
C3 : ¬Traffic(x) ∨ ¬Smart(y) ∨ ¬Catches(x, y) [x = a, y = b]
C5 : Traffic(a)
R1 : Smart(b)
----------------------------------------------
R3 : ¬Catches(a, b)
Step R4: Resolve C4 with C5, C6, and R2
C4 : ¬Traffic(x) ∨ ¬Driver(y) ∨ ¬Chases(x,y) ∨ Catches(x,y) ∨ Frustrated(x) [x = a, y = b]
C5 : Traffic(a)
C6 : Driver(b)
R2 : Chases(a, b)
----------------------------------------------
R4 : Catches(a, b) ∨ Frustrated(a)
Step R5: Resolve R4 with R3
R4 : Catches(a, b) ∨ Frustrated(a)
R3 : ¬Catches(a, b)
----------------------------------------------
R5 : Frustrated(a)
Step R6: Resolve R5 with C8
R5 : Frustrated(a)
C8 : ¬Frustrated(a)
----------------------------------------------
NIL (Empty Clause -- Contradiction!)
Step 5: Conclusion
Since resolution derives the empty clause (NIL) from the knowledge base together with the negated goal, the negated goal is unsatisfiable together with the facts. By the refutation principle, this proves the original statement:
$$\boxed{\text{If all drivers horn, then all traffics are frustrated.}}$$
2076 · 10 marks
How resolution algorithm is used in FOPL to infer conclusion? Consider the facts; Anyone whom Pugu loves is a star. Any hero who does not rehearse does not act. Anmol is a hero. Any hero who does not work does not rehearse. Anyone who does not act is not a star. Convert above into FOPL and use resolution to infer that “If Anmol does not work, then Pugu does not love Anmol”.[10]
2080.1 · 10 marks
What do you mean by unification and lifting? Convert following sentences into FOPL: Sushma likes all kinds of practical courses. AI and DBMS are practical courses. Any subject anyone practices is practical course. Ruby practices PHP. Rita practices everything that Ruby practices. Using resolution check whether 'Sushma likes PHP' is inferred or not.[10]
Show solved answerHide answer
Unification, Lifting, and Resolution in FOPL
Part 1: Unification and Lifting
Unification
Unification is the process of finding a substitution (a unifier) that makes two or more logical expressions identical.
- A substitution $\theta$ is a set of bindings ${x/term, \dots}$.
- Applying $\theta$ to an expression $P$ gives $\text{SUBST}(\theta, P)$.
- $\theta$ unifies $P$ and $Q$ if $\text{SUBST}(\theta, P) = \text{SUBST}(\theta, Q)$.
- The Most General Unifier (MGU) is the least restrictive such substitution.
Example: $P = Knows(John, x)$, $Q = Knows(John, Jane)$. MGU $\theta = {x/Jane}$, giving $Knows(John, Jane)$.
Lifting
Lifting raises a propositional inference rule to the first-order level using variables and unification. In propositional logic Modus Ponens works only on ground facts; Generalized (Lifted) Modus Ponens extends it to FOPL.
For $P_1', \dots, P_n'$ and $(P_1 \wedge \dots \wedge P_n \Rightarrow Q)$, if there is $\theta$ with $\text{SUBST}(\theta, P_i') = \text{SUBST}(\theta, P_i)$, then conclude $\text{SUBST}(\theta, Q)$.
Example: $King(John)$, $Greedy(y)$ with $King(x)\wedge Greedy(x)\Rightarrow Evil(x)$, $\theta={x/John, y/John}$ gives $Evil(John)$.
Part 2: Converting Sentences to FOPL
Predicates:
- $Likes(x,y)$: x likes y
- $Practical(x)$: x is a practical course
- $Practices(x,y)$: x practices y
| No. | English | FOPL |
|---|---|---|
| 1 | Sushma likes all kinds of practical courses | $\forall x,[Practical(x) \Rightarrow Likes(Sushma, x)]$ |
| 2 | AI and DBMS are practical courses | $Practical(AI) \wedge Practical(DBMS)$ |
| 3 | Any subject anyone practices is a practical course | $\forall x,\forall y,[Practices(x,y) \Rightarrow Practical(y)]$ |
| 4 | Ruby practices PHP | $Practices(Ruby, PHP)$ |
| 5 | Rita practices everything Ruby practices | $\forall x,[Practices(Ruby, x) \Rightarrow Practices(Rita, x)]$ |
Part 3: Resolution to Prove "Sushma likes PHP"
Step 1: Clause Form (CNF)
| Clause | Clause Form |
|---|---|
| $C_1$ | $\neg Practical(x) \vee Likes(Sushma, x)$ |
| $C_2$ | $Practical(AI)$ |
| $C_3$ | $Practical(DBMS)$ |
| $C_4$ | $\neg Practices(u, v) \vee Practical(v)$ |
| $C_5$ | $Practices(Ruby, PHP)$ |
| $C_6$ | $\neg Practices(Ruby, w) \vee Practices(Rita, w)$ |
Step 2: Negate the Goal
Goal: $Likes(Sushma, PHP)$. Negated goal: $$C_7: \neg Likes(Sushma, PHP)$$
Step 3: Apply Resolution
Resolve $C_1$ and $C_7$, $\theta = {x/PHP}$: $$C_8: \neg Practical(PHP)$$
Resolve $C_4$ and $C_5$, $\theta = {u/Ruby,; v/PHP}$: $$C_9: Practical(PHP)$$
Resolve $C_8$ and $C_9$: $$\square \quad (\text{empty clause, contradiction})$$
Resolution Proof Tree
C1: ¬Practical(x) ∨ Likes(Sushma,x) C7: ¬Likes(Sushma,PHP)
\ {x/PHP} /
C8: ¬Practical(PHP)
C4: ¬Practices(u,v) ∨ Practical(v) C5: Practices(Ruby,PHP)
\ {u/Ruby, v/PHP} /
C9: Practical(PHP)
C8: ¬Practical(PHP) C9: Practical(PHP)
\ /
[ NIL ] ← contradiction
Conclusion
Since resolution derives the empty clause $\square$, the negated goal is unsatisfiable with the KB. Therefore "Sushma likes PHP" is inferred (proved TRUE).
(Note: clauses $C_6$, and facts about $AI$/$DBMS$, are not needed for this particular proof, since PHP is shown to be practical directly from Ruby practicing it.)
Types of Knowledge Representation Systems
2081 · 5 marks
How can you represent knowledge using scripts? Create a knowlege base using script based on your own assumption. [5]
2080 · 5 marks
How knowledge is represented using frames? Represent following knowledge using frames. Ram is name of an employee. His age is 27. He is male. He belongs to the department HR, where the number of employees is 110 and the average salary of the department is Rs. 45000. All departments are under Tribhuvan University. The organization type of Tribhuvan University is Educational. [5]
2078 · 5 marks
Construct semantic network for following facts: Ram is person. Persons are humans. All human have nose. Humans are instances of mammals. Ram has weight of 60 kg. Weight of Ram is less than weight of Sita. [5]
2076 · 5 marks
Define frame. How knowledge is encoded in a frame? Justify with an example. [5]
2080.1 · 5 marks
What is semantic network? Given following knowledge base, represent it using semantic network. Subash is a student. All students are person. Person has hair. Ram is a player. All player play game. Game is a physical action. Height of all players is larger than the height of all student. Physical action starts from 7:00 AM and ends at 9:00 AM. [5]
Fuzzy Logic
2081 · 5 marks
Define fuzzy logic. Construct a fuzzy rule base expert system with your own considerations of fuzzy set. [5]
2079 · 5 marks
What is fuzzy logic? Discuss the different operators used in genetic algorithm. [5]
2076 · 5 marks
What do you mean by membership of an element in a fuzzy set? Given a domain of discourse X={10, 20, 30, 40, 50, 60, 70}, construct a fuzzy set from X. Use your own assumptions for defining membership. [5]
Propositional Logic
2079 · 5 marks
What is forward chaining? Explain with appropriate example. [5]
Handling Uncertain Knowledge, Radom Variables, Prior and Posterior Probability, Inference using Full Joint Distribution, Bayes' Rule and its use, Bayesian Networks, Reasoning in Belief Networks
2078 · 5 marks
What is prosteroir probability? Consider a scenario that a patient have liver disease is 15% probability. A test says that 5% of patients are alcholic. Among those patients diagnosed with liver disease, 7% are alcoholic. Now computer the chance of having liver disease, if the patient is alcoholic. [5]
2076 · 5 marks
How uncertain knowledge is represented? Given following full joint probability distribution representing probabilities of having different sizes of CD, find the probability that a CD cover has a length of 130mm given the width is 15mm.
$$\begin{array}{|c|c|c|c|c|}\hline \text{y=Width} & \text{x=Length} & 129 & 130 & 131 \ \hline 15 & & 0.12 & 0.42 & 0.06 \ 16 & & 0.08 & 0.28 & 0.04 \ \hline \end{array}$$
[5]
Make Unit 4 stick
Practice CSC266 with flashcards & quizzes