7.1 Expert System
Definition
- An expert system utilizes knowledge base and inference engine to emulate the decision-making ability of a human expert

Components
- User Interface: Handles queries from users and provides advice
- Inference Engine: Processes queries and generates answers
- Knowledge Base: Contains facts and rules in a specific domain
- Collections of facts and rules
- We can first-order logic!
- Expert: Provides domain knowledge
- Knowledge Engineer: Extracts knowledge from experts
Knowledge Base
- Contains facts and rules in a specific domain
- Extracted from a human expert by a knowledge engineer
- Can be stored in several forms:

1. Inference Rules (If-Then Statements)
IF the collateral is satisfactory AND
the applicant is able to the loan payments AND
the applicant has a good financial situation
THEN
the loan is approved.
2. Decision Tree
- Internal node = question
- Leaf node = label/class

Inference Engine
- Accepts queries from users
- Searches for matched facts in the knowledge base
- Generates appropriate answers
- Performs inference according to ==rules of inference==
Modus Ponens (Rule of Inference)
-
Rule: "P implies Q. P is true. Therefore, Q must also be true."
-
Notation: p → q, p, ∴ q
-
Based on propositional logic
7.2 First-Order Logic (FOL)
Describe objects and their relations
Definition
- Also called predicate logic
- Collection of formal systems
- Extends propositional logic by additionally covering:
- Predicates — Relations among objects
- Quantifiers
7.3 Syntax for FOL
Basic Elements
1. Constant Symbols
- Specific objects such as:
- Person names (Tom)
- Particular objects (a specific apple)
2. Variable Symbols
- Countably infinite set of unknowns
- Examples:
3. Function Symbols
- Takes n-tuples of terms (constants, variables, or functions)
- Returns another term
- Notation: f → an object

4. Predicate Symbols
Return either true or false (boolean function), relation among objects
- n-ary predicate defined as a function from tuples of n terms to True/False
- Notation: p → True/False

5. Connective Symbols
- ∨ (or)
- ∧ (and)
- (implies)
- ↔ (equivalent)
- ¬ (not)
6. Quantifier Symbols
- (for all/universal quantifier)
- (there exists/existential quantifier)
- Allows statements about entire or some collections of objects rather than enumerating objects by name
7. Equality Symbol
- = (equality)
7.4 Logical Sentences
Atomic Logical Sentences
- Simplest structure in FOL
- A predicate applied to a set of terms
- Format:
- Where can be variable or constant
Example 7.1
FOL:
- Brother(x, y): predicate "x is a brother of y" ← อันนี้ต้องกำหนดมาให้นะ
- Richard and John: constants
- Translation: "John is a brother of Richard"

Example 7.2
FOL:
Length(a): function returning the length of aLeftLegOf(b): function returning the left leg of b>(x, y): predicate "x is longer than y"- Richard and John: constants
- Translation: "The length of left leg of Richard is longer than length of left leg of John"
Compound Logical Sentences
- Constructed from multiple atomic sentences using connectives (∨, ∧, ¬, →, ↔)
Example 7.3
FOL:
- Owns(x, y): predicate "x owns y"
John,Car1,Car2: constants- Translation: "John owns Car1 and Car2" or "John owns Car1 and John owns Car2"
7.5 Truth in FOL
Key Concepts
- Sentences are true with respect to a model and an interpretation
- Model: Contains objects and relations among objects
- Interpretation: Specifies referents for:
- Constant symbols → objects
- Predicate symbols → relations
- Function symbols → functional relations → objects
Truth Condition
- An atomic sentence
predicate(term1, ..., termn)is true - If and only if the objects referred by term1, ..., termn are in the relation referred by the predicate
Example 7.4
Given: be predicate , domain is all integers
- :
- True () → is true.
- :
- True () → is true.
- :
- False () → is false.
Example 7.5
Given: be predicate "", domain is all integers
- :
- True ()
- :
- False ()
- :
- True ()
7.6 Quantifiers in FOL
7.6.1 Universal Quantification ()
Basic Form
- Used to describe situations/things true about all objects in the domain
- is true if and only if is true with x being each possible object in the model
Example
- "Everyone is smart" →
- If domain = {John, Richard}, then equivalent to:
Smart(John) ∧ Smart(Richard)
Universal Quantification with Conditions
-
Pattern:
-
Example: "Everyone studying at SIIT is smart"
-
Equivalent to:
Common Mistake
- Wrong:
- This means: "Everyone is studying at SIIT AND everyone is smart"
- Not the intended meaning
คือถ้าเป็น For All ให้ใช้ Implies () ในการเชื่อมเด้อออออออ
7.6.2 Existential Quantification ()
Basic Form
- Used to state properties of some objects without naming them
- is true if and only if is true for at least one object in the domain
Example
- "Someone is smart" →
- If domain = {John, Richard}, then equivalent to: `
Existential Quantification with Conditions
-
Pattern:
-
Example: "Someone studying at SIIT is smart"
-
Equivalent to:
Common Mistake
- Wrong:
- This means: "There exists someone who is smart OR does not study at SIIT"
- Not the intended meaning
คือถ้าเป็น For some ให้ใช้ And () ในการเชื่อมเด้อออออออ
7.6.3 Negation of Quantifiers
De Morgan's Rules
Additional Rules
Example 7.6
Given: ICT(x) = "x is an ICT student", ITS336(x) = "x is enrolling in ITS336"
- "Every ICT student is enrolling in ITS336"
- "Some ICT students are enrolling in ITS336"
- "There are some non ICT students who are enrolling in ITS336"
- "There are some ICT students who are not enrolling in ITS336"
7.7 Nested Quantifiers
Definition
- Multiple quantifiers in a single statement
- Can be thought of as nested loops
Programming Analogy
def check_all(Dx, Dy, P):
for x in Dx:
for y in Dy:
if not P(x,y):
return False
return TrueCombinations with Same Quantifiers
Both Universal
- P(x, y) is true for all pairs of x and y
- Order doesn't matter

Both Existential
- P(x, y) is true for at least one pair of x and y
- Order doesn't matter

Mixed Quantifiers (Order Matters!)
Universal then Existential
- For every x, there is at least one y such that P(x, y) is true
- The value of y does not have to be the same for all x

Existential then Universal
- There is at least one x such that P(x, y) is true for every y

Example 7.7
- Question: "There is at least one y such that P(x, y) is true for every x"
- Answer:
Example 7.8
Let ParentOf(x, y) be the predicate ' is a parent of ', and Female(x) be the predicate ‘x is a female.' The domain and is the set of all creatures in the world. Translate the following FOL sentence into plain English.
- FOL:
∀y ∃x (Person(y) → (ParentOf(x, y) ∧ Female(x))) - Equivalent:
∀y (Person(y) → ∃x (ParentOf(x, y) ∧ Female(x))) - Translation: "Every person has a female parent" or "For every person, there exists a female who is their parent"
- (LONG) For every creature , if is a person, there exists at least one such that is a parent of and is a female.
Example 7.9
Let Student(x) mean "a is a student in the class" and Friend(x, y) mean "x is a friend of y". The domain of x and y is all people. Translate the following English sentence into a logical sentence:
- English: "Every student in the class has at least one friend"
- FOL:
7.8 Equality
Definition
- Sometimes needed in FOL statements to address identity relation
term1 = term2is true under a given interpretation- If and only if term1 and term2 refer to the same object
Example 7.10
FOL: ∃x∃y (Owns(Mickey, x) ∧ Dog(x) ∧ Owns(Mickey, y) ∧ Dog(y) ∧ ¬(x = y))
- Owns(x, y): predicate "x owns y"
- Dog(x): predicate "x is a dog"
- Translation: "Mickey owns at least two dogs"
- Inequality ensures x and y are distinct
- ถ้าไม่มีตัวนี้อยู่ จะเกิดสถานการณ์แบบนี้ได้เลยล่ะ

Example 7.11
FOL:
Equivalent:
Translation: "Everyone is married to exactly one person"
- First part: x is married to y
- Second part: y is the unique spouse of x
Example 7.12
Given: L(x, y) = "x loves y", domain is all people
- "Everybody loves Kitty"
- "Everybody loves somebody"
- "There is somebody whom everybody loves"
- "Everyone has someone who loves them"
- "Everyone loves himself or herself"
- "There is someone who loves no one besides himself or herself"
- "Everyone loves everyone except himself/herself"
- หรือ ๆ
- "Kitty loves exactly two people"
- "At least one people do not love Kitty"
- "Nobody loves everybody"
- ¬ (At least one person loves everybody)
- or
Example 7.13
Given: Lent(x, y) = "x lent some money to y"
-
- "Piglet lent some money to Pooh"
¬(∀x Lent(Pooh, x))- "Pooh did not lend money to everyone" or "It is not the case that Pooh lent money to everyone"
- Cholwich: There exists at least one creature that Pooh did not lend some money to.
∃x∃y (Lent(x, Piglet) ∧ Lent(y, Piglet) ∧ ¬(x = y))- "At least two people lent money to Piglet"
∃x (Lent(x, Piglet) ∧ ∀y (Lent(y, Piglet) → (x = y)))- "Exactly one person lent money to Piglet"
∀x∀y ((Lent(x, Piglet) ∧ Lent(y, Piglet)) → (x = y))- "At most one person lent money to Piglet"