A comprehensive engineering treatment of symbolic AI: knowledge-based agent architectures, propositional calculus, resolution refutation proofs, first-order logic with unification and generalized modus ponens, forward and backward chaining on Horn clauses, semantic networks, frames, production rules, ontologies, and description logics.
In artificial intelligence, Knowledge Representation (KR) is the formal study of how an autonomous agent translates its understanding of the real physical world—including objects, facts, relationships, constraints, and causal rules—into structured, computer-tractable symbolic structures. Reasoning is the algorithmic manipulation of these symbolic structures to infer new, previously unstated facts and make provably sound decisions.
"Any mechanically embodied intelligent process will be comprised of structural ingredients that we, as external observers, naturally take to represent a propositional account of the knowledge that the overall process exhibits, and independent of such external semantic attribution, play a formal, but causal, role in generating the behavior that manifests that knowledge."
In short: genuine intelligent action requires an explicit internal model of facts and rules that causally governs the agent's motor actions.
38.5).Patient temperature = 38.5 Celsius).IF temperature > 38.0 C AND symptoms include stiff neck THEN consider meningitis and alert physician).A Knowledge-Based Agent (KB Agent) maintains an explicit internal Knowledge Base (KB): a centralized repository of sentences expressed in a formal representation language.
+------------------+ Percepts +---------------------+
| Environment | ------------------------> | TELL(KB, Make-Percept-Sentence(percept, t))
+------------------+ +---------------------+
^ |
| Update Knowledge Base
| v
| Action +---------------------+
| | Knowledge Base |
| | (Sentences) |
| +---------------------+
| |
| v
+------------------+ +---------------------+
| Execute Action | <------------------------ | ASK(KB, Make-Action-Query(t))
+------------------+ Best Action | (Inference Engine) |
+---------------------+
Decoupled Architecture: A profound advantage of KB agents is the strict separation between the Knowledge Base (domain-specific facts) and the Inference Engine (domain-independent logical derivation algorithms). This allows developers to swap, scale, and update domain knowledge without rewriting algorithmic inference code.
| Knowledge Type | Definition & Characteristics | Canonical Example |
|---|---|---|
| Declarative Knowledge | Static facts, world concepts, and assertions about "WHAT" is true. Expressed as explicit statements that can be verified as true or false. | Paris is the capital of France. or A triangle has three interior angles summing to 180 degrees. |
| Procedural Knowledge | Operational rules, step-by-step algorithms, and recipes explaining "HOW" to accomplish a specific objective. | To sort a list: select minimum element, swap with first unsorted slot, repeat until end. |
| Meta-Knowledge | Knowledge ABOUT knowledge. Describes reliability, freshness, ownership, confidence, and scope of other knowledge items. | This medical diagnosis rule has 94% statistical confidence and was verified in 2024 clinical trials. |
| Heuristic Knowledge | Rules of thumb, expert insights, and practical intuitions that accelerate search without guaranteeing mathematical optimality. | In chess, controlling the four center squares typically yields tactical superiority. |
| Structural Knowledge | Taxonomies, object relationships, and part-whole aggregations connecting concepts hierarchically. | An Engine is part-of a Car; a Car is a subtype-of MotorVehicle. |
Propositional Logic (Boolean Logic) is the simplest formal logic. Its primitive elements are atomic proposition symbols (e.g., P, Q, R) representing facts that can be either True or False.
~P is True if and only if P is False.P ^ Q is True if and only if both P and Q are True.P v Q is True if either P is True, Q is True, or both are True.P → Q is False only when P is True and Q is False; otherwise it is True. (Equivalent to ~P v Q). P is the antecedent; Q is the consequent.P ↔ Q is True if and only if both P and Q have the exact same truth value. (Equivalent to (P → Q) ^ (Q → P)).| P | Q | NOT P (~P) | P AND Q (P ^ Q) | P OR Q (P v Q) | P IMPLIES Q (P → Q) | P IFF 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 |
A sentence is valid (a tautology) if it evaluates to True in all possible models (under every possible truth assignment).
Example: P v ~P is always True regardless of P's value.
A sentence is satisfiable if it evaluates to True in at least one model.
Example: P ^ Q is satisfiable because it is True when P = True and Q = True.
A sentence is unsatisfiable (a contradiction) if it evaluates to False in all models.
Example: P ^ ~P is always False.
| Equivalence Law | Logical Formulation | Intuitive Meaning |
|---|---|---|
| Commutativity | P ^ Q ≡ Q ^ PP v Q ≡ Q v P |
Order of operands does not change truth value. |
| Associativity | (P ^ Q) ^ R ≡ P ^ (Q ^ R)(P v Q) v R ≡ P v (Q v R) |
Grouping of identical operators does not matter. |
| Double Negation Elimination | ~(~P) ≡ P |
Two negatives make an affirmative. |
| De Morgan's Laws | ~(P ^ Q) ≡ ~P v ~Q~(P v Q) ≡ ~P ^ ~Q |
Negating an AND yields an OR of negations; negating an OR yields an AND of negations. |
| Distributivity | P ^ (Q v R) ≡ (P ^ Q) v (P ^ R)P v (Q ^ R) ≡ (P v Q) ^ (P v R) |
AND distributes over OR; OR distributes over AND. |
| Implication Elimination | P → Q ≡ ~P v Q |
"P implies Q" means either P is false or Q is true. |
| Contraposition | P → Q ≡ ~Q → ~P |
"If it rains then ground is wet" ≡ "If ground is not wet then it didn't rain". |
Logical Entailment (KB |= α): A sentence α is entailed by KB if and only if in every model where KB is True, α is also True.
An Inference Rule is a mechanical transformation pattern that derives new sentences from existing ones while guaranteeing Soundness (only deriving sentences that are genuinely entailed).
If it is known that "If it rains, the grass is wet" and it is known that "It is raining", we can soundly infer: "The grass is wet".
If "If John has the flu, he has a fever" and "John does NOT have a fever", we soundly infer: "John does not have the flu".
Resolution is a single, complete inference rule that operates on sentences expressed in Conjunctive Normal Form (CNF): a conjunction of clauses, where each clause is a disjunction of literals.
The literal P and its negation ~P are called complementary literals. They cancel out, leaving the remaining disjuncts as the newly derived clause (resolvent).
To prove that KB |= α:
α to yield ~α.KB and ~α into Conjunctive Normal Form (CNF clauses).~α to the set of clauses.KB ^ ~α is unsatisfiable! Therefore, the original hypothesis α is proven to be True!
Knowledge Base Clauses:
(1) ~Rain v WetGrass (Rain implies WetGrass)
(2) Rain (It is raining)
Query: Prove WetGrass
Step 1: Negate query:
(3) ~WetGrass (Assumed contradiction)
Step 2: Resolve Clause (1) and Clause (2) on complementary pair [Rain, ~Rain]:
Resolvent (4): WetGrass
Step 3: Resolve Clause (4) and Clause (3) on complementary pair [WetGrass, ~WetGrass]:
Resolvent (5): [ ] <-- EMPTY CLAUSE (Contradiction!)
Conclusion: Since deriving False was inevitable, the assumption ~WetGrass is impossible.
Therefore, WetGrass is mathematically PROVEN!
Propositional logic treats the world as a collection of atomic facts with zero internal structure. In propositional logic, to say "Every student is human", we would need a separate proposition for every individual student (StudentAlice → HumanAlice, StudentBob → HumanBob...), causing a catastrophic combinatorial explosion.
First-Order Logic (FOL / Predicate Calculus) introduces an ontological commitment to:
Alice, Socrates, 3, Earth).Human(Socrates), FatherOf(John, Alice), GreaterThan(5, 2)).MotherOf(Alice), Plus(2, 3)).Expresses that a property holds for all objects in the universe of discourse:
FOR-ALL x [ Human(x) → Mortal(x) ]
Writing FOR-ALL x [ Human(x) ^ Mortal(x) ] means: "Everything in the universe is human AND mortal" (including rocks, trees, and planets!). Always pair FOR-ALL with IMPLIES (→).
Expresses that a property holds for at least one object in the universe:
THERE-EXISTS x [ Student(x) ^ Scored100(x) ]
Writing THERE-EXISTS x [ Student(x) → Scored100(x) ] is trivially True if there exists ANY object that is NOT a student (because False implies anything is True!). Always pair THERE-EXISTS with AND (^).
In first-order inference, we frequently need to make two predicate sentences look identical by finding a substitution dictionary θ for their variables. This process is called Unification:
UNIFY(Knows(John, x), Knows(John, Jane)) → θ = { x: Jane }UNIFY(Knows(John, x), Knows(y, Bill)) → θ = { x: Bill, y: John }UNIFY(Knows(John, x), Knows(x, Bill)) → FAILS! (x cannot simultaneously be John and Bill).
Occurs Check: A variable cannot be unified with a term containing that same variable (e.g., unifying x with Father(x) would cause an infinite recursive loop: Father(Father(Father(...)))).
Full first-order theorem proving with resolution is semi-decidable (if a query is not entailed, the algorithm may run forever). To guarantee polynomial-time inference in production systems, AI uses a restricted subset of logic called Horn Clauses.
~P v ~Q v R ≡ (P ^ Q) → RR is the Head (consequent); the conjunction of negative literals (P ^ Q) is the Body (antecedents). Facts are clauses with zero negative literals (e.g., P).
Starts with the known atomic facts in the KB. Fires rules whose premises are completely satisfied. The conclusions of fired rules are added to the KB as new facts. This cycle repeats until the query is derived or no new facts can be added.
Starts from the target query goal. Works backward by locating rules whose head (consequent) matches the goal, then recursively establishes whether all premises in that rule's body can be proven as subgoals.
Knowledge Base Rules:
Rule 1: A ^ B -> C
Rule 2: C ^ D -> E
Rule 3: E -> Goal
Known Facts: A, B, D
FORWARD CHAINING (Bottom-Up):
[A, B, D] ---> Fires Rule 1: derives C
[A, B, C, D] -> Fires Rule 2: derives E
[A, B, C, D, E] -> Fires Rule 3: derives Goal! (Proven)
BACKWARD CHAINING (Top-Down):
Goal? -> Look for head: Rule 3 needs E.
Subgoal E? -> Look for head: Rule 2 needs C and D.
Is D a known fact? Yes!
Subgoal C? -> Look for head: Rule 1 needs A and B.
Are A and B known facts? Yes! -> Base reached, Goal Proven!
Developed by Allan Collins and Ross Quillian (1968). Represents knowledge as a directed graph where:
Key power: Property Inheritance along is-a (subclass) and instance-of edges. If Canary is-a Bird and Bird can-fly, then Canary inherits the ability to fly automatically!
Precursor to Object-Oriented Programming (OOP). A Frame is a collection of named slots and associated values representing stereotypical entities:
color, doors).if-needed, if-added).Used in classical Expert Systems (e.g., MYCIN, CLIPS). Consists of a working memory and a rule base structured as:
IF <condition> THEN <action>
RETE Algorithm: A pattern-matching algorithm that eliminates re-evaluating rules whose conditions have not changed.
Conflict Resolution: When multiple rules match, pick using recency, specificity, or priority weights.
In modern computer science and knowledge graphs, an Ontology is a formal, explicit specification of a shared conceptualization. It defines the formal vocabulary of concepts, classes, attributes, and relationships governing a specific domain (e.g., Gene Ontology, SNOMED CT for medicine, Schema.org for web semantics).
Description Logics are a family of decidable fragments of First-Order Logic specifically engineered to balance expressive power with computational tractability. Description logics provide the formal logical foundation for the W3C standard OWL (Web Ontology Language).
The schema or vocabulary of the domain. Defines concepts (classes) and roles (binary relations) and axioms describing their relationships.
Woman ≡ Person AND FemaleMother ≡ Woman AND (HAS-CHILD SOME Person)
The instance data of the domain. Asserts facts about specific named individual entities.
Mother(Mary)ChildOf(John, Mary)
C is more general than concept D (i.e., whether every instance of D must necessarily be an instance of C).Below is an executable Python implementation demonstrating: 1. A Forward Chaining Engine on Horn Clauses. 2. A Backward Chaining Engine proving subgoals recursively. 3. A Propositional Resolution Prover demonstrating proof by refutation.
"""
AI Track Unit 5: Knowledge Representation & Logical Inference Engine
Forward Chaining, Backward Chaining, and Resolution Refutation
Author: DevAscent Engineering Team
"""
from typing import List, Set, Dict, Optional, Tuple
# =====================================================================
# 1. HORN CLAUSE KNOWLEDGE BASE & CHAINING ENGINES
# =====================================================================
class HornClause:
def __init__(self, premises: List[str], conclusion: str):
self.premises: List[str] = premises
self.conclusion: str = conclusion
def __repr__(self):
if not self.premises:
return f"Fact({self.conclusion})"
return f"{' ^ '.join(self.premises)} -> {self.conclusion}"
class KnowledgeBase:
def __init__(self):
self.clauses: List[HornClause] = []
self.facts: Set[str] = set()
def tell_fact(self, fact: str):
self.facts.add(fact)
def tell_rule(self, premises: List[str], conclusion: str):
self.clauses.append(HornClause(premises, conclusion))
# -----------------------------------------------------------------
# Forward Chaining Algorithm
# -----------------------------------------------------------------
def forward_chain(self, query: str) -> Tuple[bool, List[str]]:
"""
Data-driven bottom-up inference.
Returns (is_entailed, derivation_order).
"""
known_facts = set(self.facts)
if query in known_facts:
return True, [query]
# Count of unsatisfied premises for each clause
count = {clause: len(clause.premises) for clause in self.clauses}
agenda = list(self.facts)
derivation_order = []
while agenda:
p = agenda.pop(0)
derivation_order.append(p)
for clause in self.clauses:
if p in clause.premises:
count[clause] -= 1
# If all premises satisfied, fire rule
if count[clause] == 0:
concl = clause.conclusion
if concl == query:
derivation_order.append(concl)
return True, derivation_order
if concl not in known_facts:
known_facts.add(concl)
agenda.append(concl)
return False, derivation_order
# -----------------------------------------------------------------
# Backward Chaining Algorithm
# -----------------------------------------------------------------
def backward_chain(self, query: str, visited: Optional[Set[str]] = None) -> bool:
"""
Goal-driven top-down recursive inference.
"""
if visited is None:
visited = set()
# If already known as base fact, base case succeeded
if query in self.facts:
return True
if query in visited:
return False # Prevent infinite loops in circular rules
visited.add(query)
# Find all rules concluding this query
for clause in self.clauses:
if clause.conclusion == query:
# All premises must recursively be proven True
all_premises_proven = True
for premise in clause.premises:
if not self.backward_chain(premise, visited.copy()):
all_premises_proven = False
break
if all_premises_proven:
return True
return False
# =====================================================================
# 2. PROPOSITIONAL RESOLUTION PROVER (CNF Refutation)
# =====================================================================
Clause = frozenset
def resolve_pair(ci: Clause, cj: Clause) -> Set[Clause]:
"""Resolve two clauses on any complementary literal pair."""
resolvents = set()
for literal in ci:
complement = literal[1:] if literal.startswith('~') else '~' + literal
if complement in cj:
# Combine remaining literals
new_clause = (ci - {literal}) | (cj - {complement})
resolvents.add(new_clause)
return resolvents
def pl_resolution(clauses_input: List[List[str]], negated_query: List[str]) -> bool:
"""
Propositional Resolution Refutation Theorem Prover.
Returns True if KB |= Query (empty clause derived).
"""
clauses: Set[Clause] = {frozenset(c) for c in clauses_input}
clauses.add(frozenset(negated_query))
new_derived = set()
step = 0
while True:
step += 1
clause_list = list(clauses)
pairs = [(clause_list[i], clause_list[j])
for i in range(len(clause_list))
for j in range(i + 1, len(clause_list))]
for ci, cj in pairs:
resolvents = resolve_pair(ci, cj)
if frozenset() in resolvents:
print(f"[Resolution Refutation] Contradiction (Empty Clause derived at step {step})!")
return True
new_derived.update(resolvents)
if new_derived.issubset(clauses):
return False # No new clauses can be derived; query not entailed
clauses.update(new_derived)
# =====================================================================
# DEMONSTRATION HARNESS
# =====================================================================
if __name__ == "__main__":
print("=" * 68)
print("DEMO 1: HORN CLAUSE INFERENCE (FORWARD & BACKWARD CHAINING)")
print("=" * 68)
kb = KnowledgeBase()
# Facts
kb.tell_fact("Colleague(John)")
kb.tell_fact("HasFever(John)")
kb.tell_fact("Coughing(John)")
# Rules
kb.tell_rule(["HasFever(John)", "Coughing(John)"], "Infected(John)")
kb.tell_rule(["Infected(John)", "Colleague(John)"], "NeedsQuarantine(John)")
kb.tell_rule(["NeedsQuarantine(John)"], "AlertManager(John)")
target = "AlertManager(John)"
# Forward Chaining
fc_result, derivation_path = kb.forward_chain(target)
print(f"Forward Chaining Result for '{target}': {fc_result}")
print(f"Facts Derivation Sequence: {' -> '.join(derivation_path)}")
# Backward Chaining
bc_result = kb.backward_chain(target)
print(f"Backward Chaining Result for '{target}': {bc_result}\n")
print("=" * 68)
print("DEMO 2: PROPOSITIONAL RESOLUTION REFUTATION")
print("Rules: (P implies Q) and (Q implies R) and P. Query: Prove R.")
print("=" * 68)
# KB in CNF:
# (~P v Q), (~Q v R), (P)
# Negated query: (~R)
cnf_kb = [
["~P", "Q"],
["~Q", "R"],
["P"]
]
query_negated = ["~R"]
proof_success = pl_resolution(cnf_kb, query_negated)
print(f"Resolution Proof of R: {'SUCCESSFULLY PROVEN' if proof_success else 'FAILED'}")
Answer: Propositional logic has zero structural representation: it can only express that an entire statement is True or False. To express a generalized principle across a universe of N entities (e.g., "All humans are mortal"), propositional logic requires N individual duplicate propositions (Human1 → Mortal1, Human2 → Mortal2...). It has no mechanism to quantify over objects. First-Order Logic (FOL) solves this by introducing predicates, functions, objects, and quantifiers (FOR-ALL ∀ and THERE-EXISTS ∃), allowing infinite generalizations in a single expressive sentence: FOR-ALL x [ Human(x) → Mortal(x) ].
Answer:
Soundness: An inference engine is sound if it derives only true consequences. If KB derives α, then KB |= α (no false derivations).
Completeness: An inference engine is complete if it can derive every sentence that is logically entailed. If KB |= α, then the algorithm is guaranteed to find a proof.
Soundness guarantees mathematical truthfulness; completeness guarantees that no valid answers are missed.
Answer: Instead of attempting to prove α directly, Resolution uses proof by contradiction. It asserts the negation of the query (~α) into the Knowledge Base (all converted to Conjunctive Normal Form). It then repeatedly resolves clauses containing complementary literals (e.g., P and ~P). If the empty clause [ ] (False) is derived, it proves that KB ^ ~α is mathematically unsatisfiable. Because assuming ~α causes an unavoidable contradiction, the original query α must be True.
Answer: Unification is the algorithmic procedure of finding a substitution dictionary θ for variables that makes two distinct first-order expressions syntactically identical. The Occurs Check prevents a variable from being unified with a compound term that contains that same variable (e.g., unifying x with f(x)). If the occurs check were omitted, x would expand into an infinite cyclic expression f(f(f(...))), causing infinite loops and generating mathematically unsound derivations.
Answer: Forward Chaining is data-driven (bottom-up): it starts with known facts and fires rules to derive all possible consequences. It is ideal for monitoring, event processing, automated synthesis, and reactive control. However, it can derive many facts irrelevant to a specific question. Backward Chaining is goal-driven (top-down): it starts with a specific target query and recursively works backwards to see if base facts support the required premises. It is ideal for question answering, medical diagnosis, and legal verification where the system only needs to evaluate facts directly relevant to the target query.
Answer: In Description Logic (the formal underpinning of OWL ontologies):
TBox (Terminological Box): Defines the schema, classes, roles, and structural constraints of the domain (e.g., Professor is-a AcademicStaff).
ABox (Assertional Box): Contains instance data and facts about specific named individuals (e.g., Professor(DrAlanSmith)).
In modern enterprise knowledge graphs, the TBox corresponds to the ontology / graph schema, while the ABox corresponds to the actual nodes and edges instantiated in the graph database.