Knowledge Representation and Reasoning
Chapter 4: Knowledge Representation and Reasoning
Topics Covered
- Introduction to Knowledge Representation
- Reasoning
- Knowledge-based Systems
- Logical Agents
- Logic and Inference
- Propositional Logic
- Predicate (First-Order) Logic
- Inference in First-Order Logic
Introduction to Knowledge Representation
- Humans possess intelligence due to the knowledge and information they gather through experience.
- Computers are initially like empty boxes, lacking inherent knowledge.
- Artificial Intelligence (AI) aims to imbue machines with intelligence, enabling them to function like humans.
- This involves providing machines with knowledge, allowing them to process information and make informed decisions.
Intelligence and Reasoning
- Intelligence is defined as the ability to utilize gathered knowledge effectively.
- Reasoning is closely linked to intelligence, involving the processing of knowledge to make decisions.
- Intelligent beings possess:
- Knowledge.
- The ability to process information.
- The ability to make decisions.
- Example: The decision not to jump is a result of knowledge, processing ability, and decision-making.
Machines and Decision-Making
- Machines, lacking knowledge, intelligence, and reasoning, are unlikely to make informed decisions such as choosing not to jump.
- To make machines intelligent, it is necessary to provide them with the correct knowledge, enabling them to process it and make appropriate decisions.
- The knowledge representation provided to machines must be accurate to avoid generating incorrect outputs.
Techniques of Knowledge Representation
- Humans excel at comprehension, reasoning, and knowledge interpretation, performing actions based on their knowledge.
- Knowledge Representation and Reasoning (KRR) governs how machines perform these tasks.
- KRR is the study of expressing an intelligent agent's beliefs, intentions, and judgments in a manner suitable for automated reasoning.
Knowledge Representation and Reasoning (KR, KRR)
- KR, KRR represent data from the real world, enabling computers to comprehend and utilize this knowledge to solve complex problems, such as natural language communication.
- There are four primary ways to represent knowledge:
- Logical Representation
- Semantic Network Representation
- Rules-Based Representation
- Frame Representation
1. Logical Representation
- Logical Representation is a language with concrete rules that deals with propositions and has no ambiguity in representation.
- It is a way of drawing conclusions based on various conditions.
- It consists of precisely defined syntax and semantics which supports sound inference. Each sentence can be translated into logics using syntax and semantics.
- Two types of Logical Representation:
- Propositional Logic
- Predicate Logic
- A proposition is a statement which is either true or false and doesn't depend on any parameters. E.g: 2+3=5
- Propositions must have a definite truth value (true or false) without ambiguity.
- Propositional logic deals with propositions.
- A predicate is a statement whose truth value depends on the parameters specified in the statement.
- A quantified predicate becomes a proposition when values are assigned to its variables. E.g., x+3=5 is a predicate dependent on the value of x.
- This predicate becomes a proposition when 'x' is assigned a value.
2. Semantic Network Representation
- Semantic refers to meaning, and network refers to a graph.
- A semantic network is a representation technique where knowledge is stored in the system as a meaningful graph.
- Example:
- Ram has a cycle.
- Ram is a boy.
- The cycle has a bell.
- Ram is 12 years old.
- The cycle has two paddles.
- In this graph, nodes represent objects, and arrows represent the relationships between objects.
- Semantic network representation shows the connectivity of objects.
3. Rules-Based Representation
- Knowledge is represented using "if" and "then" statements, and the machine makes decisions based on these rules.
- Format: If then
- Example: If Temperature is below 10 then the weather is cold
- If-Pattern, Premise or Antecedent
- Then-Pattern, Conclusion Consequent
4. Frame Representation
- It is a record-like structure consisting of attributes and their values to describe an entity in the world.
Knowledge-Based Agents
- A knowledge-based agent uses a knowledge base (KB), which is a collection of sentences.
- A sentence is a technical term representing an assertion about the world in a knowledge representation language (KR).
- Knowledge-based agents require knowledge about the real world for efficient decision-making and reasoning.
- These agents can maintain an internal state of knowledge, reason over it, update it based on observations, and take actions.
Components of Knowledge-Based Agents
- Knowledge-based agents consist of two main parts:
- Knowledge base (KB): A set of sentences in a formal language.
- Inference Engine (IE): Reasons with knowledge to produce new knowledge.
- Inference involves finding conclusions based on facts, information, and evidence or deriving new sentences from old ones.
How Knowledge-Based Agents Work
- By observing the environment, the knowledge-based agent (KBA) receives input.
- The agent's inference engine uses this input and communicates with the KB to make decisions.
- The KBA's learning component updates the KB with new information.
- The KBA makes decisions (output) through this process.
- Agents need a knowledge base to learn from experiences and take action based on knowledge.
Requirements of Sentences in the Knowledge Base
- Sentences in the KB must contain a range of information.
- The agent must be able to:
- Represent and update states of the environment.
- Represent its own actions.
- Incorporate new precepts into the KB.
- Update internal representations of the world.
- Deduce hidden properties of the environment.
- Deduce the 'right' action at any time.
- The KB must contain the goal(s) of the agent.
Propositional Logic
- Logic is a formal language used to represent information in a structured way, enabling us to draw valid conclusions.
- It consists of:
- Syntax: Rules for constructing valid sentences (like grammar in natural language).
- Example:
- x+2≥y is a sentence (syntactically correct).
- x2+y> is not a sentence (syntax error(invalid structure))
- Semantics define the "meaning" of sentences; i.e., define the truth of each sentence with respect to each possible world.
- Example:
- x+2≥y is true if the number x+2 is not less than the number y
- x+2≥y is true in a world where x = 7, y = 1 but false in a world where x = 0, y = 6
Types of Propositions
- (A) Atomic Propositions
- Simple, indivisible statements that are either true or false.
- Examples: "2+2=4" (true fact). "The Sun is cold" (false fact).
- (B) Compound Propositions
- Built by combining atomic propositions using logical connectives (e.g., ∧,∨,→).
- Examples: "It is raining today ∧ the street is wet." "Ankit is a doctor ∧ his clinic is in Mumbai." "9 is divisible by 3 ∧ 4 is an odd number."
Rules in Propositional Logic
- Any symbol can represent a proposition (especially atomic propositions), such as A, B, P, Q, R, etc.
- Each proposition is a declarative statement with a binary truth value: Either True (T) or False (F), but never both.
- Examples:
- P = "It is raining" (could be T/F depending on observation).
- Q = "2+2=4" (always T).
- Propositional logic consists of objects, relations, and logical connectives, also called logical operators.
- Propositions and connectives are the basic elements of propositional logic.
Logical Connectives
- Negation: ¬ P is called the negation of P.
- Conjunction: P ∧ Q is called a conjunction.
- Disjunction: P ∨ Q is called a disjunction, where P and Q are propositions.
- Implication: P → Q, also known as if-then rules.
- Biconditional: P ⇔ Q is a Biconditional sentence.
Truth Tables for Connectives
| P | Q | ¬P | P ∧ Q | P ∨ Q | P → Q | P ⇔ Q |
|---|
| false | false | true | false | false | true | true |
| false | true | true | false | true | true | false |
| true | false | false | false | true | false | false |
| true | true | false | true | true | true | true |
Semantics in Propositional Logic
- Rules for evaluating truth with respect to a model m:
- ¬S is true if S is false
- S1 ∧ S2 is true if S1 is true and S2 is true
- S1 ∨ S2 is true if S1 is true or S2 is true (i.e., is false if S1 is false and S2 is false)
- S1 ⇒ S2 is true if S1 is false or S2 is true (i.e., is false if S1 is true and S2 is false)
- S1 ⇔ S2 is true if S1⇒S2 is true and S2⇒S1 is true
Logical Equivalence
- Two sentences are logically equivalent if they are true in the same models: α ≡ ß if α╞ β and β╞ α.
Precedence of Operators (Logical Connectives)
- Levels of precedence, evaluating left to right:
- ¬ (NOT) - Highest
- ∧ (AND, conjunction)
- ∨ (OR, disjunction)
- ⇒ (implies, conditional)
- ⇔ (equivalence, biconditional) - Lowest
- Examples:
- P ∧ ¬ Q ⇒ R - (P ∧ (¬Q)) ⇒ R
- P ∨ Q ∧ R - P ∨ (Q ∧ R)
- P ⇒ Q ∧ R ⇒ S - P ⇒ ((Q ∧ R) ⇒ S)
Translation
- Translation of English sentences to propositional logic:
- Identify atomic sentences that are propositions.
- Use logical connectives to translate more complex composite sentences that consist of many atomic sentences.
- Example:
- It is not sunny this afternoon and it is colder than yesterday.
- Atomic sentences:
- p = It is sunny this afternoon
- q = it is colder than yesterday
- Translation: ¬ p ∧ q
- Assume the following sentences:
- It is not sunny this afternoon and it is colder than yesterday. ¬ p ∧ q
- We will go swimming only if it is sunny. r → p
- If we do not go swimming then we will take a canoe trip. ¬ r → s
- If we take a canoe trip, then we will be home by sunset. s → t
- Denote:
- p = It is sunny this afternoon
- q = it is colder than yesterday
- r = We will go swimming
- s= we will take a canoe trip
- t= We will be home by sunset
Entailment
- Entailment (╞) means that if one statement (KB) is true, then another statement (α) must also be true. That is, one sentence follows from another.
- The symbol for entailment is ‘╞’ as in KB ╞ α.
- Meaning: In every possible situation where KB is true, α is always true.
- Example:
- If x + y = 4 is true, then 4 = x + y must be true.
- Written as: x + y = 4 ╞ 4 = x + y referring x+y=4 entails 4=x+y
- Entailment is a relationship between sentences that is based on semantics.
Models
- A model (m) is a world where a given sentence is true. Think of it as a possible scenario or configuration where the statement holds.
- We say m is a model of a sentence α if α is true in m.
- Examples:
- Sentence: x + y = 4.
- M1: {x=2, y=2} (because 2+2=4).
- M2: {x=1, y=3} (because 1+3=4).
- Therefore, we can say M1 and M2 are models of x+y=4.
- Notation: M(α) is the set of all models of α.
Inference by Model Checking
- Inference means to find a conclusion based on the facts, information, and evidence.
- Model Checking: A way to test if a conclusion (α) logically follows from KB by comparing their possible models (scenarios where they are true).
- KB ╞ α iff M(KB) ⊆ M(α)
- This definition states that if (and only if) the models of the KB are a subset of the models of α, then the KB entails α.
- E.g. KB = Morocco won and Argentina won, α = Argentina won
- From this, KB is true in the world were {Morocco_won=True, Argentina_won=True}, implies α (Argentina won) is also true. I.e. M(KB) ⊆ M(α)
Validity and Satisfiability
- A sentence is valid if it is true in all models, e.g., A ∨ ¬A, A ⇒ A, is true in any world(for any values of A)
- Validity is connected to inference via the Deduction Theorem:
- KB ╞ α if and only if (KB ⇒ α) is valid
- A sentence is satisfiable if it is true in some model, e.g., A, A ∨ B, is true in some world only(i.e A=T, B=T/F)
- A sentence is unsatisfiable if it is true in no models
- e.g., A ∧ ¬A, can never be true;
- Satisfiability is connected to inference via the following:
- KB ╞ α if and only if (KB ∧ ¬α) is unsatisfiable. This means that if KB entails α, then it is impossible for KB to be true and α to be false simultaneously. Hence, (KB ∧ ¬α) is unsatisfiable.
Proof by Applying Inference Rules
- Instead of enumerating truth tables, we can do proof by successively applying sound inference rules:
- So, generating the conclusions from evidence and facts is termed as inference.
- Any logical equivalence relation can be used as an inference rule.
- Inference rules are the templates for generating valid arguments. They are applied to derive proofs in artificial intelligence(such as logical equivalence).
- The proof is a sequence of the conclusion that leads to the desired goal.
Propositional Logic: Rules of Inference or Method of Proof
| Rule of Inference | Tautology (Deduction Theorem) | Name |
|---|
| P / .. P ∨ Q | P→ (P ∨ Q) | Addition (OR introduction) |
| P ∧ Q / . P | (P ∧ Q) → P | Simplification |
| P / Q / .. P ∧ Q | [(P)(Q)] → (P ∧ Q) | Conjunction |
| P / P→Q / .. Q | [(P)(P→Q)] → (P→Q) | Modus Ponens |
| ¬Q / P→ Q / .. ¬P | [(Q) (P→Q)] → ¬P | Modus Tollens |
| P→ Q / Q→ R / … P→R | [(P→Q) (Q→R)] → (P→R) | Hypothetical Syllogism |
| P ∨ Q / -P / .. Q | [(P ∨ Q) (P)] → Q | Disjunctive syllogism |
| P ∨ Q / -P / R / .. Q ∨ R | [(P→Q) (P→R)] → (Q→R) | Resolution |
Types of Inference Rules
- Modus Ponens:
- States that if P and P → Q is true, then we can infer that Q will be true.
- It can be represented as: QP,P→Q
- Example: let P be I’m sleepy, Q be I go to bed.
- Statement-1: "If I am sleepy then I go to bed" P→ Q
- Statement-2: "I am sleepy" P
- Conclusion: "I go to bed." Q
- Hence, we can say that, if P→ Q is true and P is true then Q will be true. We can proof this using the truth table as shown. ((P→Q) ∧ P) => Q
- Modus Tollens:
- State that if P→ Q is true and ¬ Q is true, then ¬ P will also true.
- It can be represented as: ¬PP→Q,¬Q
- Example: let P be I’m sleepy, Q be I go to bed.
- "If I am sleepy then I go to bed" P→ Q
- "I do not go to the bed." ~Q
- Which infers that "I am not sleepy" ~P
- Hence, we can say that, if P→ Q is true and ~Q is true then ~P will be true. We can proof this using the truth table as shown. ((P→Q) ∧ ~Q) => ~P
- Conjunction elimination (also called AND elimination)
- It is a rule of inference which makes the inference that, if the conjunction A and B is true, then A is true, and B is also true.
- An example in English: let P be it's raining, Q be it's pouring.
- It's raining and it's pouring.
- Therefore it's raining. // also Therefore it is pouring.
- Hence, we can say that, if P∧Q is true, therefore Q is true. And P is also true.
- Prove it by truth table! ((P ∧ Q) => P , ((P ∧ Q) => Q
- Addition rule (also called OR introduction)
- States that if P is true, therefore what ever the value of Q, the logic P ∨ Q is always true. It is represented as follows:
- P∨QP
- Example:
- Let p be “I will study discrete math.”
- Let q be “I will visit Las Vegas.”
- “I will study discrete math.”
- “Therefore, I will study discrete math or I will visit Las Vegas.” P →(p ∨ q)
- Conjunction rule (also called AND introduction)
- States that if P is true, and Q is also true, therefore the logic P ∧ Q is always true. It is represented as follows:
- P∧QP,Q
- Example:
- Let p be “I will study discrete math.”
- Let q be “I will study English literature.”
- “I will study discrete math.”
- “I will study English literature.”
- “Therefore, I will study discrete math and I will study English literature.” ((p) ∧ (q)) →(p ∧ q)
Resolution
- Resolution is a method of proof that involves constructing proofs having some initial premises.
- It is employed when several statements are supplied and we need to prove a conclusion from those claims.
- Uses Conjunctive Normal Form (CNF), a sentence that is represented using conjunction of disjunctions of literals.
- A formula is in CNF if it is a conjunction of one or more than one clause, where each clause is a disjunction of literals. In other words, it is a product of sums where ∧ symbol occurs between the clauses and the ∨ symbol occurs in the clauses.
- Example:
- (A∨¬B)∧(B∨¬C∨¬D)
- Literal is a proposition(P) or its negation(¬P).
- Clause is a set of literals connected by using logical connective (disjunction in this case). I.e. P v Q
- Examples of CNF.
- a. (¬q ∨ p ∨ r) ∧ (¬p ∨ r) ∧ q
- b. (p ∨ r) ∧ (¬p ∨ r) ∧ (p ∨ ¬r)
- Examples of formulas that are not in CNF!
- a. (¬(q ∨ p) ∨ r) ∧ (q ∨ r), since ¬ is not resolved, cause (¬p ∧ ¬q)
- b. ¬(q ∨ p), since an OR is nested within a NOT
- c. p∧( q∨( r∧s) ), since an AND is nested within an OR
- d. ( p∧ q) ∨ r, since an AND is nested within an OR
Rules for Converting a Sentence to CNF
- Replace α⇔β by (α⇒β) ∧ (β⇒α). When this is complete, the sentence will have no occurrence of ⇔.
- Replace α⇒β by ¬α∨β. When this is complete, the only Boolean operators will be ∨, ¬, and ∧.
- Replace ¬(α∨β) by ¬α∧¬β; and ¬(α∧β) by ¬α∨¬β; and ¬¬α by α. Repeat as long as applicable. When this is done, all negations will be next to an atomic sentence.
- Replace (α ∧ β) ∨ γ by (α ∨ γ) ∧ (β ∨ γ), and α ∨ (β ∧ γ) by (α ∨ β) ∧ (α ∨ γ). Repeat as long as applicable. When this is done, all conjunctions will be at top level.
Conversion to CNF Example
- Convert into CNF: B1,1 (P1,2 ∨ P2,1)
- Eliminate , replacing α β with (α β) ∧ (β α).
- (B1,1 (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) B1,1)
- Eliminate , replacing α β with α ∨ β (implication law).
- (¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (¬(P1,2 ∨ P2,1) ∨ B1,1)
- Move inwards using deMorgan's rules and double negation:
- (¬B1,1 ∨ P1,2 ∨ P2,1) ∧ ((P1,2 ∧ P2,1) ∨ B1,1)
- Apply distributive law ( over ):
- (¬B1,1 ∨ P1,2 ∨ P2,1) ∧ (P1,2 ∨ B1,1) ∧ (P2,1 ∨ B1,1) (in CNF!)
First-Order Logic: Why FOL?
- Syntax and Semantics of FOL
- Using FOL
Introduction to First-Order Logic
- Propositional Logic:
- We can only represent facts which are either True or False.
- Example: 3 is an odd number.
- Represent a knowledge base (KB) using a formal language.
- It is limited in its expressiveness in that it is unable to represent facts about some or all objects in the universe.
- Example: Some humans are intelligent. All cars are beautiful.
- First-Order Logic:
- An alternative (and more expressive) language for representing KBs.
- It has the capability of expressing facts about some or all objects in the universe using quantifiers.
First-Order Logic (FOL)
- It is also known as predicate logic.
- First-order logic (like natural language) assumes the world contains,
- objects: represent things in the real world.
- E.g.: people, houses, numbers, colors …
- relations: represent attributes of object or relationships between objects.
- E.g.: red, round, prime, brother of, bigger than, part of, comes between…
- functions: take object(s) and return an object result.
- E.g.: Length(), TeammateOf(), best friend(), Sqrt() …
Syntax of FOL: Basic Elements
- Sentences in FOL represent these components of the world using the following elements:
- constants: represent objects
- E.g: Haileselassie, 2, Blue, …
- predicates: represent relations
- functions: represent functions
- variables: by convention lower case letters
- connectives: the same 5 connectives as are used
- equality: the two terms refer to the same object
- quantifiers: existential and universal
- Syntax of FOL: Function(term1, term2, …termn) Predicate(term1, term2, …termn)
- E.x: X is a girl. girl(x)
Atomic Sentences
- Atomic sentence:
- The simplest type of sentence in FOL. It doesn't have any logical connectives (like AND, OR, NOT, etc.) or quantifiers (like ∀ or ∃).
- An atomic sentence consists of:
- Atomic sentence = predicate(term1,…,termN) where a term is either:
- function (term1,…,termN) or constant or variable
- Example (1): TeammateOf(Kenenisa, HaileGebreselassie)
- The example consists of a predicate, TeammateOf, with two constant arguments, HaileGebreselassie and Kenenisa.
- Example (2): Length(LeftLegOf(Kenenisa)) = Length(RightLegOf(Kenenisa))
- The second example contains two constants (both Kenenisa), combined using three functions, Length, LeftLegOf and RightLegOf.
Complex Sentences
- Complex sentences are made from atomic sentences using connectives:
- We can make more complex sentences by combining atomic sentences using connectives, ¬S, S1 ∧ S2, S1 ∨ S2, S1⇒ S2, S1⇔S2,
- Examples:
- ¬Teammate(𝐾𝑒𝑛𝑒𝑛𝑖𝑠𝑎,𝐻𝑎𝑖𝑙𝑒𝐺𝑒𝑏𝑟𝑒𝑠𝑒𝑙𝑎𝑠𝑠𝑖𝑒) meaning "Kenenisa is not a teammate of HaileGebreselassie."
- Teammate(Kenenisa,Haile) ⇒ Teammate(Haile,Kenenisa)
- > (1,2) ∨ ≤ (1,2)
- > (1,2) ∧ >(1,2)
- Sentences are true with respect to a model and an interpretation.
- Model contains objects (domain elements) and relations among them.
- Interpretation specifies (real-world) referents for
- constant symbols → objects
- predicate symbols → relations
- function symbols → functional relations
- An atomic sentence predicate(term1,…,termN) is true if the objects referred to by term1,…,termN are in the relation referred to by predicate.
First-Order Logic Quantifiers
- It is FOL quantifiers that give the language its expressive power.
- There are two types of quantifier:
- universal quantifiers (∀)
- existential quantifiers (∃)
Universal Quantification
- The symbol for universal quantification is ∀.
- To interpret the universal quantification symbol in a FOL sentence we can read it as “for all …”.
- ∀
- E.g. ∀x At(CS , x) ⇒ Intelligent(x)
- Can be interpreted as stating that “for all x, At(CS, x) implies Intelligent(x)”.
- In other words, if everyone is at CS then they are intelligent.
- Definition:
- ∀x P is true in a model m iff P is true with x being each possible object in the model.
A Common Mistake to Avoid
- Typically, ⇒ is the main connective with ∀.
- Common mistake: using ∧ as the main connective with ∀:
- For Examples:
- ∀x At(CS , x) ∧ Intelligent(x)
- Means “Everyone is at CS and everyone is intelligent”
- ∀x At(CS , x) ⇒ Intelligent(x)
- Means “Everyone at CS is intelligent”
Existential Quantification
- The symbol for existential quantification is ∃.
- We can read this as “there exists …”. ∃
- Example: ∃x At (CS , x) ∧ Intelligent(x)
- can be interpreted as stating that “there exists some x, such that At(CS, x) and Intelligent(x) are both true.
- In other words, somebody at CS is intelligent.
- Definition:
- ∃x P is true in a model m iff P is true with x being some possible object in the model
Another Common Mistake to Avoid
- Typically, ∧ is the main connective with ∃.
- Common mistake: using ⇒ as the main connective with ∃:
- For Examples:
- ∃x At(CS , x) ⇒ Intelligent(x)
- is true if there is anyone who is not at CS!
- ∃x At (CS , x) ∧ Intelligent(x)
- Means “Someone at CS is intelligent”
Properties of Quantifiers
- ∀x ∀y is the same as ∀y ∀x
- ∃x ∃y is the same as ∃y ∃x
- ∃x ∀y is not the same as ∀y ∃x
- ∃x ∀y Loves(x, y)
- “There is a person who loves everyone in the world”
- Example: "There is a person, say Alice, who loves every other person (Bob, Charlie, etc.)."
- ∀y ∃x Loves(x, y)
- “Everyone in the world is loved by at least one person”
- Example: "Every person (Bob, Alice, etc.) is loved by at least one other person (could be different for each person)."
- Quantifier duality: each can be expressed using the other.
- ∀x Likes(x,dorowet) ¬∃x Likes(x,dorowet)
- ∃x Likes(x,genfo) ∀x Likes(x,genfo)
Equality in First-Order Logic
- The equality symbol in FOL does not mean that same as assignment in most programming languages.
- A sentence involving the ‘=’ symbol in FOL is true if both of its arguments refer to the same object.
- term1 = term2 is true under a given interpretation if and only if term1 and term2 refer to the same object.
- E.g., ∃x, y Brother(x, Abebe) ∧ Brother(y, Abebe) ∧ (x=y)
- x and y do not refer to the same object. In other words, Abebe has two (distinct) brothers.
- Without the use of the equality symbol, the above sentence would be true if x and y had the same value (i.e. Abebe has one brother).
More Examples on FOL
- All birds fly.
- The predicate is "fly(x)", where x = bird.