;
; levels-to-common-sense.scm
;
; Map the layers from raw text → common sense rules
; AND show that common sense itself is a structured space
;
; FRAMING NOTE (2026-02-03): This file presents one PROJECTION of
; a multi-dimensional emergent structure onto a single vertical axis
; (Layers 0-7). This is useful as a first approximation but is not
; the true architecture. Key corrections:
;
; - "Layer 7" is NOT a ceiling. The recursion continues as long as
; new structure emerges from counting (meta-rules can have
; meta-meta-rules, etc.)
;
; - "Layer 0" is NOT a floor. Sub-word structure (morphemes,
; phonemes, characters) is discoverable by the same method
; below the word level.
;
; - The numbered layers are NOT the only dimensions. See
; concepts/dimensions-of-structure.scm for 10+ orthogonal
; dimensions (temporal, causal, modal, social, etc.) that are
; perpendicular to this stack, not part of it.
;
; - Each dimension contains fractal sub-structure discoverable
; by the same COUNT → CLUSTER → STRUCTURE method.
;
; The true architecture: an unknown number of emergent dimensions,
; each with unknown depth, discovered by recursive counting.
; The structure IS the data's structure, not ours.
;
(use-modules (srfi srfi-1))
(use-modules (ice-9 format))
(display "═══════════════════════════════════════════════════════════════════\n")
(display " LEVELS FROM LANGUAGE TO COMMON SENSE \n")
(display "═══════════════════════════════════════════════════════════════════\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; THE LAYER STACK
;; ═══════════════════════════════════════════════════════════════════
(display "THE LAYER STACK: Raw Text → Common Sense\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Each layer is built by counting patterns in the layer below.\n")
(display " Common sense emerges at the UPPER layers.\n\n")
(display " ┌─────────────────────────────────────────────────────────────┐\n")
(display " │ │\n")
(display " │ LAYER 7: META-RULES (rules about rules) │\n")
(display " │ ↑ 'Physical laws override social conventions' │\n")
(display " │ │ │\n")
(display " │ LAYER 6: COMMON SENSE RULES │\n")
(display " │ ↑ 'Fish swim', 'Fire is hot', 'Hungry→Eat' │\n")
(display " │ │ │\n")
(display " │ LAYER 5: SCRIPTS / EVENT SCHEMAS │\n")
(display " │ ↑ Restaurant script, Morning routine │\n")
(display " │ │ │\n")
(display " │ LAYER 4: SEMANTIC FRAMES │\n")
(display " │ ↑ COOKING frame, FINANCIAL frame, MOTION frame │\n")
(display " │ │ │\n")
(display " │ LAYER 3: SEMANTIC ROLES / RELATIONS │\n")
(display " │ ↑ Agent-Action, Object-Property, Cause-Effect │\n")
(display " │ │ │\n")
(display " │ LAYER 2: WORD CATEGORIES / CLUSTERS │\n")
(display " │ ↑ Nouns, Verbs, Agent-words, Action-words │\n")
(display " │ │ │\n")
(display " │ LAYER 1: WORD ASSOCIATIONS (PMI) │\n")
(display " │ ↑ 'fish' ↔ 'swim', 'fire' ↔ 'hot' │\n")
(display " │ │ │\n")
(display " │ LAYER 0: RAW TEXT │\n")
(display " │ Word sequences, tokens │\n")
(display " │ │\n")
(display " └─────────────────────────────────────────────────────────────┘\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; DETAILED LAYER DESCRIPTIONS
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "LAYER 0: RAW TEXT\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Input: Character stream\n")
(display " Output: Word sequences\n\n")
(display " Example:\n")
(display " 'the fish swam in the river'\n")
(display " → ['the', 'fish', 'swam', 'in', 'the', 'river']\n\n")
(display " No structure yet - just tokens.\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "LAYER 1: WORD ASSOCIATIONS (PMI)\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Input: Word sequences\n")
(display " Count: Which words co-occur?\n")
(display " Output: Association strengths (PMI table)\n\n")
(display " Example:\n")
(display " PMI(fish, swim) = 4.2 (high - often together)\n")
(display " PMI(fish, bank) = 2.1 (medium - sometimes)\n")
(display " PMI(fish, computer) = -1.5 (low - rarely together)\n\n")
(display " Structure discovered: Which words 'go together'\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "LAYER 2: WORD CATEGORIES / CLUSTERS\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Input: PMI table\n")
(display " Count: Which words have similar PMI profiles?\n")
(display " Output: Word clusters (categories)\n\n")
(display " Example:\n")
(display " CLUSTER-AGENT: {fish, bird, dog, human, chef}\n")
(display " (all have high PMI with action verbs)\n")
(display " CLUSTER-ACTION: {swim, fly, run, walk, cook}\n")
(display " (all have high PMI with agents)\n")
(display " CLUSTER-PROPERTY: {hot, cold, wet, dry, muddy}\n")
(display " (all have high PMI with 'is/was')\n\n")
(display " Structure discovered: Word TYPES (proto-grammar)\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "LAYER 3: SEMANTIC ROLES / RELATIONS\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Input: Word clusters\n")
(display " Count: How do clusters combine in sentences?\n")
(display " Output: Relation types\n\n")
(display " Example:\n")
(display " AGENT + ACTION: 'fish swam', 'bird flew', 'chef cooked'\n")
(display " OBJECT + PROPERTY: 'water was cold', 'fire was hot'\n")
(display " ACTION + LOCATION: 'swam in river', 'walked to store'\n")
(display " CAUSE + EFFECT: 'hungry so ate', 'rained so wet'\n\n")
(display " Structure discovered: HOW things relate\n")
(display " (not just THAT they co-occur, but their ROLE)\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "LAYER 4: SEMANTIC FRAMES\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Input: Semantic relations\n")
(display " Count: Which relations cluster together?\n")
(display " Output: Frames (stereotyped situations)\n\n")
(display " Example:\n")
(display " COOKING-FRAME:\n")
(display " Agent: chef/cook/person\n")
(display " Action: cook/bake/fry/stir\n")
(display " Object: food/ingredients\n")
(display " Location: kitchen\n")
(display " Instrument: pan/oven/stove\n\n")
(display " SWIMMING-FRAME:\n")
(display " Agent: fish/person/animal\n")
(display " Action: swim/float/dive\n")
(display " Location: water/river/pool\n")
(display " Result: wet\n\n")
(display " Structure discovered: Situation TEMPLATES\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "LAYER 5: SCRIPTS / EVENT SCHEMAS\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Input: Frames\n")
(display " Count: Which frames follow which in sequences?\n")
(display " Output: Scripts (stereotyped sequences)\n\n")
(display " Example:\n")
(display " RESTAURANT-SCRIPT:\n")
(display " 1. ENTER-FRAME\n")
(display " 2. SIT-FRAME\n")
(display " 3. ORDER-FRAME\n")
(display " 4. EAT-FRAME\n")
(display " 5. PAY-FRAME\n")
(display " 6. LEAVE-FRAME\n\n")
(display " FISHING-SCRIPT:\n")
(display " 1. TRAVEL-TO-WATER-FRAME\n")
(display " 2. PREPARE-EQUIPMENT-FRAME\n")
(display " 3. CAST-LINE-FRAME\n")
(display " 4. WAIT-FRAME\n")
(display " 5. CATCH-FRAME (or FAIL-FRAME)\n\n")
(display " Structure discovered: Temporal PATTERNS\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "LAYER 6: COMMON SENSE RULES \n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Input: All lower layers\n")
(display " Count: What ALWAYS/USUALLY/NEVER happens?\n")
(display " Output: Defeasible rules (common sense)\n\n")
(display " Example rules:\n\n")
(display " CAPABILITY RULES (from agent-action counts):\n")
(display " fish CAN swim (count: 100, exceptions: 0)\n")
(display " fish CANNOT walk (count: 0, never observed)\n")
(display " humans CAN swim (count: 30, some do)\n")
(display " humans CAN walk (count: 95, most do)\n\n")
(display " PROPERTY RULES (from object-property counts):\n")
(display " water IS wet (count: 100, universal)\n")
(display " fire IS hot (count: 100, universal)\n")
(display " banks ARE muddy (count: 20, geographic sense)\n")
(display " banks HAVE money (count: 35, financial sense)\n\n")
(display " CAUSAL RULES (from cause-effect counts):\n")
(display " hungry CAUSES eating (count: 80, strong rule)\n")
(display " rain CAUSES wetness (count: 90, strong rule)\n")
(display " studying HELPS passing (count: 40, weaker rule)\n\n")
(display " LOCATION RULES (from location patterns):\n")
(display " fish LIVE IN water (count: 98, near-universal)\n")
(display " birds LIVE IN trees (count: 70, typical)\n")
(display " money IS KEPT IN banks (count: 50, financial sense)\n\n")
(display " Structure discovered: PROBABILISTIC RULES\n")
(display " (not absolute truths, but strong expectations)\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "LAYER 7: META-RULES (Rules about Rules)\n")
(display "─────────────────────────────────────════════════════════════════\n\n")
(display " Input: Common sense rules\n")
(display " Count: When do rules conflict? Which wins?\n")
(display " Output: Rule priorities, exception handling\n\n")
(display " Example:\n")
(display " PHYSICAL > SOCIAL:\n")
(display " 'You should pay at restaurants' (social rule)\n")
(display " 'You cannot pay if you have no money' (physical constraint)\n")
(display " → Physical constraint overrides social rule\n\n")
(display " SPECIFIC > GENERAL:\n")
(display " 'Birds can fly' (general rule)\n")
(display " 'Penguins cannot fly' (specific exception)\n")
(display " → Specific knowledge overrides general\n\n")
(display " RECENT > OLD:\n")
(display " 'Banks are open 9-5' (old knowledge)\n")
(display " 'This bank is closed today' (recent observation)\n")
(display " → Recent information overrides default\n\n")
(display " Structure discovered: RULE HIERARCHY\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; THE SPACE OF COMMON SENSE
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "THE SPACE OF COMMON SENSE RULES\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " You asked: 'Common sense must itself be a space of rules'\n")
(display " YES - common sense has STRUCTURE:\n\n")
(display " ┌─────────────────────────────────────────────────────────────┐\n")
(display " │ │\n")
(display " │ COMMON SENSE RULE SPACE │\n")
(display " │ │\n")
(display " │ Dimensions: │\n")
(display " │ 1. DOMAIN: physical / biological / social / mental │\n")
(display " │ 2. STRENGTH: always / usually / sometimes / rarely │\n")
(display " │ 3. SCOPE: universal / cultural / individual │\n")
(display " │ 4. TYPE: capability / property / causal / temporal │\n")
(display " │ │\n")
(display " │ Rules form a GRAPH: │\n")
(display " │ - Some rules imply others │\n")
(display " │ - Some rules conflict with others │\n")
(display " │ - Some rules are more specific versions of others │\n")
(display " │ │\n")
(display " └─────────────────────────────────────────────────────────────┘\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; DIMENSIONS OF COMMON SENSE
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "DIMENSION 1: DOMAIN\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " PHYSICAL DOMAIN:\n")
(display " - Objects fall when dropped\n")
(display " - Fire is hot\n")
(display " - Water flows downhill\n")
(display " - Solid objects cannot pass through each other\n\n")
(display " BIOLOGICAL DOMAIN:\n")
(display " - Living things need food\n")
(display " - Fish breathe underwater, mammals cannot\n")
(display " - Animals have offspring similar to themselves\n\n")
(display " PSYCHOLOGICAL DOMAIN:\n")
(display " - Hunger motivates eating\n")
(display " - Pain motivates avoidance\n")
(display " - People have beliefs and desires\n\n")
(display " SOCIAL DOMAIN:\n")
(display " - People follow conventions\n")
(display " - Money is exchanged for goods\n")
(display " - Promises create obligations\n\n")
(display " These domains have DIFFERENT rules and DIFFERENT reliability.\n")
(display " Physical rules are more universal than social rules.\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "DIMENSION 2: RULE STRENGTH\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " ALWAYS (universal, no exceptions):\n")
(display " 'Objects fall when unsupported' (physical law)\n")
(display " 'Fire requires oxygen' (physical law)\n")
(display " Count: 100% in observations\n\n")
(display " USUALLY (strong default, rare exceptions):\n")
(display " 'Birds can fly' (but penguins, ostriches...)\n")
(display " 'People eat when hungry' (but fasting, no food...)\n")
(display " Count: 80-99% in observations\n\n")
(display " OFTEN (tendency, many exceptions):\n")
(display " 'Students study before exams'\n")
(display " 'People go to work on weekdays'\n")
(display " Count: 50-80% in observations\n\n")
(display " SOMETIMES (possible but not typical):\n")
(display " 'People swim to work' (rarely, but happens)\n")
(display " 'Fish are kept as pets' (some are)\n")
(display " Count: 10-50% in observations\n\n")
(display " NEVER (impossible or unobserved):\n")
(display " 'Fish walk on land' (0 observations)\n")
(display " 'Fire is cold' (contradicts definition)\n")
(display " Count: 0% in observations\n\n")
;; ---
(display "═══════════════════════════════════════════════════════════════════\n")
(display "DIMENSION 3: RULE TYPE\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " CAPABILITY rules: What CAN/CANNOT X do?\n")
(display " fish CAN swim\n")
(display " fish CANNOT fly\n")
(display " humans CAN think\n\n")
(display " PROPERTY rules: What IS X like?\n")
(display " water IS wet\n")
(display " fire IS hot\n")
(display " banks ARE buildings OR landforms\n\n")
(display " CAUSAL rules: What CAUSES what?\n")
(display " hunger CAUSES eating\n")
(display " rain CAUSES wetness\n")
(display " fire CAUSES burning\n\n")
(display " TEMPORAL rules: What FOLLOWS what?\n")
(display " cooking PRECEDES eating\n")
(display " waking PRECEDES dressing\n")
(display " working PRECEDES getting paid\n\n")
(display " LOCATION rules: What is WHERE?\n")
(display " fish IN water\n")
(display " birds IN trees\n")
(display " money IN banks (financial sense)\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; COMMON SENSE AS A GRAPH
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "COMMON SENSE AS A GRAPH STRUCTURE\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Rules don't exist in isolation - they form a GRAPH:\n\n")
(display " IMPLICATION EDGES:\n")
(display " 'fish live in water' → 'fish can swim'\n")
(display " 'fire is hot' → 'fire can burn'\n")
(display " 'humans are animals' → 'humans need food'\n\n")
(display " CONFLICT EDGES:\n")
(display " 'fish swim' CONFLICTS WITH 'fish walk'\n")
(display " 'fire is hot' CONFLICTS WITH 'fire is cold'\n")
(display " 'bank is building' CONFLICTS WITH 'bank is landform'\n")
(display " (in the same context)\n\n")
(display " SPECIALIZATION EDGES:\n")
(display " 'birds fly' IS-GENERAL-OF 'sparrows fly'\n")
(display " 'birds fly' HAS-EXCEPTION 'penguins cannot fly'\n")
(display " 'animals eat' IS-GENERAL-OF 'fish eat'\n\n")
(display " PART-OF EDGES:\n")
(display " 'restaurant script' CONTAINS 'ordering frame'\n")
(display " 'cooking frame' CONTAINS 'heat-source slot'\n\n")
(display " This graph structure lets the system:\n")
(display " - Inherit rules (fish IS animal → fish needs food)\n")
(display " - Detect conflicts (both senses can't be true HERE)\n")
(display " - Find exceptions (penguins are birds but can't fly)\n")
(display " - Navigate related concepts\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; DISCOVERING COMMON SENSE STRUCTURE
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "HOW TO DISCOVER THE STRUCTURE OF COMMON SENSE\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Same counting method, applied to RULES:\n\n")
(display " 1. Extract rules from corpus (Layers 0-6)\n")
(display " Result: Set of rules with counts\n\n")
(display " 2. Count RULE co-occurrences\n")
(display " Which rules appear together in same texts?\n")
(display " PMI between rules\n\n")
(display " 3. Cluster rules by co-occurrence\n")
(display " Rules about fish cluster together\n")
(display " Rules about cooking cluster together\n")
(display " → Domain structure emerges\n\n")
(display " 4. Find rule implications\n")
(display " If rule A appears, does rule B always appear?\n")
(display " P(B|A) ≈ 1 → A implies B\n\n")
(display " 5. Find rule conflicts\n")
(display " Do rules A and B never appear together?\n")
(display " P(A and B) ≈ 0 → A conflicts with B\n\n")
(display " 6. Find rule hierarchies\n")
(display " Is rule A a more specific version of rule B?\n")
(display " (fish swim) specializes (animals move)\n\n")
(display " Result: The GRAPH STRUCTURE of common sense\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; TRAVERSAL: FROM TEXT TO COMMON SENSE
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "COMPLETE TRAVERSAL: Raw Text → Common Sense Graph\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " Starting: 'the fish swam in the river'\n\n")
(display " LAYER 0 → LAYER 1:\n")
(display " Tokens: [the, fish, swam, in, the, river]\n")
(display " Update: PMI(fish,swam)++, PMI(fish,river)++, PMI(swam,river)++\n\n")
(display " LAYER 1 → LAYER 2:\n")
(display " 'fish' clusters with {bird, dog, cat} (agents)\n")
(display " 'swam' clusters with {ran, flew, walked} (actions)\n")
(display " 'river' clusters with {lake, ocean, pond} (water-bodies)\n\n")
(display " LAYER 2 → LAYER 3:\n")
(display " fish(AGENT) + swam(ACTION) → AGENT-ACTION relation\n")
(display " swam(ACTION) + river(LOCATION) → ACTION-LOCATION relation\n\n")
(display " LAYER 3 → LAYER 4:\n")
(display " AGENT:fish + ACTION:swim + LOCATION:water → SWIMMING-FRAME\n\n")
(display " LAYER 4 → LAYER 5:\n")
(display " SWIMMING-FRAME often appears in FISHING-SCRIPT\n")
(display " SWIMMING-FRAME often appears in AQUATIC-LIFE-SCRIPT\n\n")
(display " LAYER 5 → LAYER 6:\n")
(display " Many observations of fish+swim → RULE: fish CAN swim\n")
(display " Many observations of fish+water → RULE: fish LIVE IN water\n")
(display " Zero observations of fish+walk → RULE: fish CANNOT walk\n\n")
(display " LAYER 6 → LAYER 7:\n")
(display " 'fish swim' is BIOLOGICAL rule (high reliability)\n")
(display " 'fish cannot walk' is PHYSICAL constraint (absolute)\n")
(display " 'fish live in water' IMPLIES 'fish can swim'\n")
(display " 'fish can swim' is MORE SPECIFIC than 'animals move'\n\n")
;; ═══════════════════════════════════════════════════════════════════
;; SUMMARY
;; ═══════════════════════════════════════════════════════════════════
(display "═══════════════════════════════════════════════════════════════════\n")
(display "SUMMARY\n")
(display "─────────────────────────────────────────────────────────────────\n\n")
(display " LEVELS TO COMMON SENSE:\n\n")
(display " Layer 0: Raw text (tokens)\n")
(display " Layer 1: Word associations (PMI)\n")
(display " Layer 2: Word categories (clusters)\n")
(display " Layer 3: Semantic relations (who does what)\n")
(display " Layer 4: Frames (situation templates)\n")
(display " Layer 5: Scripts (event sequences)\n")
(display " Layer 6: Common sense rules (expectations)\n")
(display " Layer 7: Meta-rules (rule priorities)\n\n")
(display " COMMON SENSE SPACE STRUCTURE:\n\n")
(display " Dimensions: domain, strength, scope, type\n")
(display " Relations: implication, conflict, specialization, containment\n")
(display " Form: Directed graph with typed edges\n\n")
(display " KEY INSIGHT:\n\n")
(display " ┌─────────────────────────────────────────────────────────────┐\n")
(display " │ │\n")
(display " │ Common sense is not a flat list of rules. │\n")
(display " │ │\n")
(display " │ It's a STRUCTURED SPACE discovered by applying │\n")
(display " │ the same COUNT → CLUSTER → STRUCTURE method │\n")
(display " │ recursively to higher and higher levels. │\n")
(display " │ │\n")
(display " │ The structure OF common sense is itself learnable │\n")
(display " │ by counting patterns IN common sense rules. │\n")
(display " │ │\n")
(display " └─────────────────────────────────────────────────────────────┘\n\n")