|
| 1 | +# Grammar Code-Documentation Cross-Reference Index |
| 2 | + |
| 3 | +**Purpose**: Bidirectional mapping between TNFR grammar documentation and implementation. |
| 4 | + |
| 5 | +**Last Updated**: 2025-11-10 |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Documentation → Code |
| 10 | + |
| 11 | +### Constraint Rules |
| 12 | + |
| 13 | +| Rule | Documentation | Code Implementation | |
| 14 | +|------|---------------|---------------------| |
| 15 | +| **U1a: Initiation** | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) | `GrammarValidator.validate_initiation()` in `src/tnfr/operators/grammar.py:476` | |
| 16 | +| **U1b: Closure** | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) | `GrammarValidator.validate_closure()` in `src/tnfr/operators/grammar.py:520` | |
| 17 | +| **U2: Convergence** | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) | `GrammarValidator.validate_convergence()` in `src/tnfr/operators/grammar.py:558` | |
| 18 | +| **U3: Resonant Coupling** | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) | `GrammarValidator.validate_resonant_coupling()` in `src/tnfr/operators/grammar.py:616` | |
| 19 | +| **U4a: Bifurcation Triggers** | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) | `GrammarValidator.validate_bifurcation_triggers()` in `src/tnfr/operators/grammar.py:672` | |
| 20 | +| **U4b: Transformer Context** | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) | `GrammarValidator.validate_transformer_context()` in `src/tnfr/operators/grammar.py:727` | |
| 21 | +| **U2-REMESH** | [UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) | `GrammarValidator.validate_remesh_amplification()` in `src/tnfr/operators/grammar.py:807` | |
| 22 | + |
| 23 | +### Operator Sets |
| 24 | + |
| 25 | +| Set | Documentation | Code Definition | |
| 26 | +|-----|---------------|-----------------| |
| 27 | +| **GENERATORS** | [03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md) | `grammar.py:210` → `{"emission", "transition", "recursivity"}` | |
| 28 | +| **CLOSURES** | [03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md) | `grammar.py:213` → `{"silence", "transition", "recursivity", "dissonance"}` | |
| 29 | +| **STABILIZERS** | [03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md) | `grammar.py:216` → `{"coherence", "self_organization"}` | |
| 30 | +| **DESTABILIZERS** | [03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md) | `grammar.py:219` → `{"dissonance", "mutation", "expansion"}` | |
| 31 | +| **COUPLING_RESONANCE** | [03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md) | `grammar.py:222` → `{"coupling", "resonance"}` | |
| 32 | +| **BIFURCATION_TRIGGERS** | [03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md) | `grammar.py:225` → `{"dissonance", "mutation"}` | |
| 33 | +| **BIFURCATION_HANDLERS** | [03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md) | `grammar.py:228` → `{"self_organization", "coherence"}` | |
| 34 | +| **TRANSFORMERS** | [03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md) | `grammar.py:231` → `{"mutation", "self_organization"}` | |
| 35 | + |
| 36 | +### Functions |
| 37 | + |
| 38 | +| Function | Documentation | Code Location | |
| 39 | +|----------|---------------|---------------| |
| 40 | +| `validate_grammar()` | [05-TECHNICAL-IMPLEMENTATION.md](05-TECHNICAL-IMPLEMENTATION.md) | `grammar.py:966` | |
| 41 | +| `GrammarValidator.validate()` | [05-TECHNICAL-IMPLEMENTATION.md](05-TECHNICAL-IMPLEMENTATION.md) | `grammar.py:897` | |
| 42 | +| `glyph_function_name()` | [05-TECHNICAL-IMPLEMENTATION.md](05-TECHNICAL-IMPLEMENTATION.md) | `grammar.py:90` | |
| 43 | +| `function_name_to_glyph()` | [05-TECHNICAL-IMPLEMENTATION.md](05-TECHNICAL-IMPLEMENTATION.md) | `grammar.py:141` | |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Code → Documentation |
| 48 | + |
| 49 | +### From `grammar.py` |
| 50 | + |
| 51 | +| Code Element | Line | Referenced In | |
| 52 | +|--------------|------|---------------| |
| 53 | +| Module docstring | 1-36 | [README.md](README.md), [05-TECHNICAL-IMPLEMENTATION.md](05-TECHNICAL-IMPLEMENTATION.md) | |
| 54 | +| `GENERATORS` | 210 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U1a | |
| 55 | +| `CLOSURES` | 213 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U1b | |
| 56 | +| `STABILIZERS` | 216 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U2 | |
| 57 | +| `DESTABILIZERS` | 219 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U2 | |
| 58 | +| `validate_initiation()` | 476 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U1a, [examples/u1-initiation-closure-examples.py](examples/u1-initiation-closure-examples.py) | |
| 59 | +| `validate_closure()` | 520 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U1b, [examples/u1-initiation-closure-examples.py](examples/u1-initiation-closure-examples.py) | |
| 60 | +| `validate_convergence()` | 558 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U2, [examples/u2-convergence-examples.py](examples/u2-convergence-examples.py) | |
| 61 | +| `validate_resonant_coupling()` | 616 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U3, [examples/u3-resonant-coupling-examples.py](examples/u3-resonant-coupling-examples.py) | |
| 62 | +| `validate_bifurcation_triggers()` | 672 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U4a, [examples/u4-bifurcation-examples.py](examples/u4-bifurcation-examples.py) | |
| 63 | +| `validate_transformer_context()` | 727 | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) § U4b, [examples/u4-bifurcation-examples.py](examples/u4-bifurcation-examples.py) | |
| 64 | +| `validate_remesh_amplification()` | 807 | [../../UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) § U2-REMESH | |
| 65 | + |
| 66 | +### From Examples |
| 67 | + |
| 68 | +| Example File | Uses Code | |
| 69 | +|--------------|-----------| |
| 70 | +| [u1-initiation-closure-examples.py](examples/u1-initiation-closure-examples.py) | `validate_grammar()`, `GrammarValidator.validate()`, `GENERATORS`, `CLOSURES` | |
| 71 | +| [u2-convergence-examples.py](examples/u2-convergence-examples.py) | `validate_grammar()`, `GrammarValidator.validate()`, `STABILIZERS`, `DESTABILIZERS` | |
| 72 | +| [u3-resonant-coupling-examples.py](examples/u3-resonant-coupling-examples.py) | `validate_grammar()`, `GrammarValidator.validate()`, `COUPLING_RESONANCE` | |
| 73 | +| [u4-bifurcation-examples.py](examples/u4-bifurcation-examples.py) | `validate_grammar()`, `GrammarValidator.validate()`, `BIFURCATION_TRIGGERS`, `BIFURCATION_HANDLERS`, `TRANSFORMERS` | |
| 74 | +| [01-basic-bootstrap.py](examples/01-basic-bootstrap.py) | `validate_grammar()`, All operator sets | |
| 75 | +| [02-intermediate-exploration.py](examples/02-intermediate-exploration.py) | `GrammarValidator.validate()`, Complex sequences | |
| 76 | +| [03-advanced-bifurcation.py](examples/03-advanced-bifurcation.py) | `validate_bifurcation_triggers()`, `validate_transformer_context()` | |
| 77 | + |
| 78 | +--- |
| 79 | + |
| 80 | +## Test Coverage |
| 81 | + |
| 82 | +| Code Element | Test File | Test Function | |
| 83 | +|--------------|-----------|---------------| |
| 84 | +| `validate_initiation()` | `tests/unit/operators/test_unified_grammar.py` | `TestU1aInitiation::test_*` | |
| 85 | +| `validate_closure()` | `tests/unit/operators/test_unified_grammar.py` | `TestU1bClosure::test_*` | |
| 86 | +| `validate_convergence()` | `tests/unit/operators/test_unified_grammar.py` | `TestU2Convergence::test_*` | |
| 87 | +| `validate_resonant_coupling()` | `tests/unit/operators/test_unified_grammar.py` | `TestU3ResonantCoupling::test_*` | |
| 88 | +| `validate_bifurcation_triggers()` | `tests/unit/operators/test_unified_grammar.py` | `TestU4aBifurcationTriggers::test_*` | |
| 89 | +| `validate_transformer_context()` | `tests/unit/operators/test_unified_grammar.py` | `TestU4bTransformerContext::test_*` | |
| 90 | +| Operator sets | `tests/unit/operators/test_unified_grammar.py` | `TestOperatorSets::test_*` | |
| 91 | + |
| 92 | +--- |
| 93 | + |
| 94 | +## Schema Mapping |
| 95 | + |
| 96 | +| Schema Element | Code Element | |
| 97 | +|----------------|--------------| |
| 98 | +| `canonical-operators.json::operators[].name` | Operator function names in `definitions.py` | |
| 99 | +| `canonical-operators.json::operators[].glyph` | `GLYPH_TO_FUNCTION` mapping in `grammar.py:70` | |
| 100 | +| `canonical-operators.json::operators[].classification.generator` | Membership in `GENERATORS` set | |
| 101 | +| `canonical-operators.json::operators[].classification.closure` | Membership in `CLOSURES` set | |
| 102 | +| `canonical-operators.json::operators[].classification.stabilizer` | Membership in `STABILIZERS` set | |
| 103 | +| (etc for all classifications) | (corresponding sets in grammar.py) | |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Physics Basis Traceability |
| 108 | + |
| 109 | +| Grammar Rule | Physics Basis | Code Implementation | Documentation | |
| 110 | +|--------------|---------------|---------------------|---------------| |
| 111 | +| U1a | ∂EPI/∂t undefined at EPI=0 | `validate_initiation()` checks `epi_initial == 0` | [UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) § U1 | |
| 112 | +| U1b | Sequences need coherent endpoints | `validate_closure()` checks last operator | [UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) § U1 | |
| 113 | +| U2 | ∫νf·ΔNFR dt must converge | `validate_convergence()` checks stabilizers | [UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) § U2 | |
| 114 | +| U3 | \|φᵢ - φⱼ\| ≤ Δφ_max | Phase checked in operator preconditions | [UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) § U3 | |
| 115 | +| U4a | ∂²EPI/∂t² > τ requires handlers | `validate_bifurcation_triggers()` | [UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) § U4a | |
| 116 | +| U4b | Transformers need threshold energy | `validate_transformer_context()` checks window | [UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) § U4b | |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## Maintenance Notes |
| 121 | + |
| 122 | +**When updating code**: |
| 123 | +1. Run `python tools/sync_documentation.py --all` to verify sync |
| 124 | +2. Update this cross-reference if new functions added |
| 125 | +3. Update schema if operator sets change |
| 126 | +4. Re-run examples to verify they still work |
| 127 | + |
| 128 | +**When updating documentation**: |
| 129 | +1. Verify code references are still accurate |
| 130 | +2. Check line numbers in cross-references |
| 131 | +3. Test that examples still execute correctly |
| 132 | + |
| 133 | +**Sync Tool**: Use `python tools/sync_documentation.py` for automated validation: |
| 134 | +- `--audit`: Audit grammar.py only |
| 135 | +- `--validate`: Test all examples |
| 136 | +- `--all`: Full synchronization check (default) |
| 137 | + |
| 138 | +--- |
| 139 | + |
| 140 | +**Last Sync**: 2025-11-10 via `tools/sync_documentation.py` |
| 141 | +**Status**: ✅ All checks passing |
0 commit comments