Skip to content
    Intelligentia

    KNOWLEDGE REPRESENTATION · 9 MIN

    Knowledge & Logic

    Knowledge-based agents store facts and rules, then infer new facts with logic.

    NEURA explains

    • Propositional logic uses statements that are True/False joined by AND, OR, NOT, IMPLIES.
    • Forward chaining starts from known facts and fires rules until nothing new appears.
    • First-order logic adds objects and relations: Parent(asha, ravi).

    Real world: A medical expert system: if fever AND rash then suspect measles.

    Code

    facts = {"rain"}
    rules = [({"rain"}, "wet_road"), ({"wet_road"}, "slow_traffic")]
    changed = True
    while changed:
        changed = False
        for need, new in rules:
            if need <= facts and new not in facts:
                facts.add(new); changed = True
    print(sorted(facts))
    Output ›
    ['rain', 'slow_traffic', 'wet_road']
    Try it in the online compiler →

    Checkpoint quiz

    Forward chaining starts from…