Skip to main content
AiIntermediate12 min readUpdated March 2025

Knowledge Representation

Knowledge Representation (KR) is how AI systems store and use information about the world. This article covers propositional logic, first-order logic (FOL), semantic networks, and ontologies.

What is Knowledge Representation?

For an AI system to reason and make decisions, it must have a way to represent knowledge about the world. Knowledge Representation (KR) is the field of AI concerned with:

- What information to store - How to structure it for efficient reasoning - How to use it to draw conclusions

A good KR scheme must be expressive enough to capture complex knowledge, yet efficient enough to support fast inference.

Propositional Logic

Propositional logic (Boolean logic) represents knowledge as true/false statements called propositions.

Logical connectives: - NOT P (negation) - P AND Q (conjunction) - P OR Q (disjunction) - P -> Q (If P then Q, implication) - P <-> Q (P if and only if Q, biconditional)

Limitation: Propositional logic cannot express relationships between objects or quantify over sets (e.g., "all humans are mortal").

python
# Propositional Logic in Python
# Represent facts as boolean variables

is_raining = True
has_umbrella = False

# Rule: If raining AND no umbrella -> get wet
get_wet = is_raining and not has_umbrella
print(f"Will get wet: {get_wet}")  # True

# Simple inference engine
def modus_ponens(p: bool, p_implies_q: bool) -> bool:
    """If P is true and P->Q, then Q is true."""
    if p and p_implies_q:
        return True
    return False

# Example: If it rains (P), the ground is wet (Q)
raining = True
rain_implies_wet_ground = True
ground_is_wet = modus_ponens(raining, rain_implies_wet_ground)
print(f"Ground is wet: {ground_is_wet}")  # True

First-Order Logic (FOL)

First-Order Logic (also called Predicate Logic) extends propositional logic with:

- Objects: Individual entities (Socrates, 42, "Paris") - Predicates: Properties or relations (Human(x), GreaterThan(x, y)) - Quantifiers: - forall x - "For all x" (universal quantification) - exists x - "There exists an x" (existential quantification)

Classic syllogism in FOL: ``` forall x: Human(x) -> Mortal(x) # All humans are mortal Human(Socrates) # Socrates is human therefore: Mortal(Socrates) # Therefore, Socrates is mortal ```

FOL is the foundation of Prolog, description logics, and many knowledge bases.

python
# Simulating First-Order Logic reasoning in Python

# Knowledge base: facts and rules
facts = {
    "Human": ["Socrates", "Plato", "Aristotle"],
    "Mortal": [],
}

rules = [
    # Rule: forall x: Human(x) -> Mortal(x)
    ("Human", "Mortal"),
]

# Forward chaining inference
def forward_chain(facts, rules):
    changed = True
    while changed:
        changed = False
        for antecedent, consequent in rules:
            for entity in facts.get(antecedent, []):
                if entity not in facts.get(consequent, []):
                    facts.setdefault(consequent, []).append(entity)
                    changed = True
    return facts

result = forward_chain(facts, rules)
print("Mortal entities:", result["Mortal"])
# Output: Mortal entities: ['Socrates', 'Plato', 'Aristotle']

Semantic Networks and Ontologies

Semantic Networks represent knowledge as a graph of nodes (concepts) and edges (relationships). For example:

- "Dog" IS-A "Animal" - "Fido" IS-AN-INSTANCE-OF "Dog" - "Dog" HAS-PART "Tail"

Ontologies are formal, structured vocabularies that define concepts and their relationships in a domain. Examples: - WordNet - lexical database of English - Gene Ontology - biological processes - OWL (Web Ontology Language) - used in the Semantic Web

Ontologies enable AI systems to share and reuse knowledge across applications.

Frames and Scripts

Frames (proposed by Marvin Minsky) represent stereotyped situations as data structures with slots and values:

``` Frame: Car slots: color: <value> make: <value> num_wheels: 4 (default) engine: <value> ```

Scripts represent sequences of events in typical situations (e.g., "going to a restaurant": enter -> sit -> order -> eat -> pay -> leave). Scripts help AI systems understand narratives and predict next actions.

Key Takeaways

  • Knowledge Representation defines how AI stores and reasons about world knowledge.
  • Propositional logic uses true/false statements; limited to non-relational facts.
  • First-Order Logic adds objects, predicates, and quantifiers - much more expressive.
  • Semantic networks and ontologies represent knowledge as graphs of concepts and relations.
  • Frames and scripts capture stereotyped situations for narrative understanding.

Contact Us

Have a question or feedback? Fill out the form below or reach us directly at support@nvaitraining.com