~/ learn/ comp-456/ cards/ Production systems: rules, working memory, recognize–act
1 of 3

Run a recognize–act cycle: repeatedly collect the enabled rules (conflict set), pick the most specific (conflict resolution), fire it, and stop when nothing matches. Print each firing.

Run a recognize–act cycle: repeatedly collect the enabled rules (conflict set), pick the most specific (conflict resolution), fire it, and stop when nothing matches. Print each firing.

Answer

def production_system(working_memory, rules): wm = set(working_memory) fired = set() # refraction: each rule fires once changed = True while changed: changed = False # conflict set = enabled rules (conditions in WM) not yet fired conflict_set = [r for r in rules if set(r[1]) <= wm and r[0] not in fired] if not conflict_set: break # conflict resolution: specificity (most conditions wins) conflict_set.sort(key=lambda r: -len(r[1])) name, conds, action = conflict_set[0] fired.add(name) if action not in wm: wm.add(action) print(f"fire {name}: assert {action}") changed = True print("halt: conflict set empty") rules = [ ("R1", ["has_feathers"], "is_bird"), ("R2", ["is_bird", "cannot_fly", "swims"], "is_penguin"), ("R3", ["is_bird", "can_sing"], "is_canary"), ] production_system(["has_feathers", "cannot_fly", "swims"], rules)

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/c8dd5aa7-e75b-4340-94ab-fa9d3e6eb4e1/flashcard utf-8 LF