Skip to content

Commit a79e289

Browse files
authored
Merge pull request #2905 from fermga/copilot/formalizar-u1-u4-restricciones
Formalize U1-U4 Constraints: Anti-patterns, Executable Examples, Cross-references
2 parents 747d5db + 1394ad9 commit a79e289

File tree

8 files changed

+2084
-80
lines changed

8 files changed

+2084
-80
lines changed

docs/grammar/02-CANONICAL-CONSTRAINTS.md

Lines changed: 343 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 374 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,374 @@
1+
# Cross-Reference Index: U1-U4 Constraints
2+
3+
**Complete traceability map for TNFR canonical grammar constraints**
4+
5+
Version: 2.0
6+
Last Updated: 2025-11-10
7+
Status: CANONICAL
8+
9+
---
10+
11+
## Purpose
12+
13+
This document provides a **complete cross-reference index** for the four canonical TNFR grammar constraints (U1-U4), mapping:
14+
15+
- Theory → Documentation → Implementation → Tests → Examples
16+
17+
**Use this index to:**
18+
- Find all resources related to a specific constraint
19+
- Trace a constraint from physics to code
20+
- Locate tests for validation
21+
- Find executable examples
22+
23+
---
24+
25+
## U1: STRUCTURAL INITIATION & CLOSURE
26+
27+
### U1a: Initiation
28+
29+
**Physics Basis**: ∂EPI/∂t undefined at EPI=0
30+
31+
**Theory**:
32+
- [UNIFIED_GRAMMAR_RULES.md § U1](../../UNIFIED_GRAMMAR_RULES.md)
33+
- [TNFR.pdf § 2.1 - Nodal Equation](../../TNFR.pdf)
34+
- [AGENTS.md § Invariant #1](../../AGENTS.md)
35+
36+
**Documentation**:
37+
- [02-CANONICAL-CONSTRAINTS.md § U1a](02-CANONICAL-CONSTRAINTS.md#u1a-initiation-generators)
38+
39+
**Implementation**:
40+
- `src/tnfr/operators/grammar.py::GrammarValidator.validate_initiation()`
41+
- `src/tnfr/operators/grammar.py::GENERATORS`
42+
43+
**Tests**:
44+
- `tests/unit/operators/test_unified_grammar.py::TestU1aInitiation`
45+
- `test_epi_zero_requires_generator`
46+
- `test_epi_zero_non_generator_fails`
47+
- `test_epi_nonzero_no_generator_needed`
48+
- `test_all_generators_valid_for_epi_zero`
49+
- `tests/integration/test_mutation_sequences.py::test_u1a_satisfied_with_emission`
50+
51+
**Examples**:
52+
- `examples/u1-initiation-closure-examples.py::example_u1a_valid`
53+
- `examples/u1-initiation-closure-examples.py::example_u1a_invalid`
54+
- `examples/u1-initiation-closure-examples.py::example_u1a_context_matters`
55+
56+
**Operators**:
57+
- Generators: `{emission, transition, recursivity}``{AL, NAV, REMESH}`
58+
59+
**Anti-Patterns**:
60+
- Using Reception as initiator
61+
- Forgetting generator when reusing sequences
62+
- Assuming EPI exists without checking
63+
64+
---
65+
66+
### U1b: Closure
67+
68+
**Physics Basis**: Sequences as action potentials need endpoints
69+
70+
**Theory**:
71+
- [UNIFIED_GRAMMAR_RULES.md § U1](../../UNIFIED_GRAMMAR_RULES.md)
72+
- [AGENTS.md § Invariant #4 - Operator Closure](../../AGENTS.md)
73+
74+
**Documentation**:
75+
- [02-CANONICAL-CONSTRAINTS.md § U1b](02-CANONICAL-CONSTRAINTS.md#u1b-closure-endpoints)
76+
77+
**Implementation**:
78+
- `src/tnfr/operators/grammar.py::GrammarValidator.validate_closure()`
79+
- `src/tnfr/operators/grammar.py::CLOSURES`
80+
81+
**Tests**:
82+
- `tests/unit/operators/test_unified_grammar.py::TestU1bClosure`
83+
- `test_sequence_must_have_closure`
84+
- `test_non_closure_end_fails`
85+
- `test_all_closures_valid`
86+
- `test_empty_sequence_fails_closure`
87+
- `tests/integration/test_mutation_sequences.py::test_u1b_closure_satisfied`
88+
- `tests/unit/operators/test_remesh_operator_integration.py::test_remesh_as_closure_U1b`
89+
90+
**Examples**:
91+
- `examples/u1-initiation-closure-examples.py::example_u1b_valid`
92+
- `examples/u1-initiation-closure-examples.py::example_u1b_invalid`
93+
- `examples/u1-initiation-closure-examples.py::example_dual_role_operators`
94+
95+
**Operators**:
96+
- Closures: `{silence, transition, recursivity, dissonance}``{SHA, NAV, REMESH, OZ}`
97+
98+
**Anti-Patterns**:
99+
- Ending with Coherence (not a closure)
100+
- Ending with data gathering operations
101+
- Confusing closure with stabilization
102+
103+
---
104+
105+
## U2: CONVERGENCE & BOUNDEDNESS
106+
107+
**Physics Basis**: ∫νf·ΔNFR dt must converge (integral convergence theorem)
108+
109+
**Theory**:
110+
- [UNIFIED_GRAMMAR_RULES.md § U2](../../UNIFIED_GRAMMAR_RULES.md)
111+
- [TNFR.pdf § 2.1 - Integrated Dynamics](../../TNFR.pdf)
112+
- [AGENTS.md § Convergence & Boundedness](../../AGENTS.md)
113+
114+
**Documentation**:
115+
- [02-CANONICAL-CONSTRAINTS.md § U2](02-CANONICAL-CONSTRAINTS.md#u2-convergence--boundedness)
116+
117+
**Implementation**:
118+
- `src/tnfr/operators/grammar.py::GrammarValidator.validate_convergence()`
119+
- `src/tnfr/operators/grammar.py::STABILIZERS`
120+
- `src/tnfr/operators/grammar.py::DESTABILIZERS`
121+
122+
**Tests**:
123+
- `tests/unit/operators/test_unified_grammar.py::TestU2Convergence`
124+
- `test_destabilizer_needs_stabilizer`
125+
- `test_no_destabilizers_passes`
126+
- `test_destabilizer_stabilizer_pairs`
127+
- `test_multiple_destabilizers_need_stabilizer`
128+
- `test_multiple_destabilizers_without_stabilizer_fail`
129+
- `tests/integration/test_mutation_sequences.py::test_u2_satisfied_with_stabilizers`
130+
- `tests/unit/operators/test_canonical_grammar_legacy.py::test_rc2_maps_to_u2`
131+
- `tests/unit/operators/test_grammar_c1_c3_deprecation.py::test_validate_c2_boundedness_*`
132+
133+
**Examples**:
134+
- `examples/u2-convergence-examples.py::example_u2_valid`
135+
- `examples/u2-convergence-examples.py::example_u2_invalid`
136+
- `examples/u2-convergence-examples.py::example_masking_antipattern`
137+
- `examples/u2-convergence-examples.py::example_interleaving_pattern`
138+
139+
**Operators**:
140+
- Destabilizers: `{dissonance, mutation, expansion}``{OZ, ZHIR, VAL}`
141+
- Stabilizers: `{coherence, self_organization}``{IL, THOL}`
142+
143+
**Anti-Patterns**:
144+
- Masking with weak stabilizers (multiple destabilizers, single stabilizer)
145+
- Assuming order doesn't matter (stabilizer before destabilizer ineffective)
146+
- Ignoring accumulation effects (long sequence of destabilizers)
147+
148+
---
149+
150+
## U3: RESONANT COUPLING
151+
152+
**Physics Basis**: Resonance physics + AGENTS.md Invariant #5
153+
154+
**Theory**:
155+
- [UNIFIED_GRAMMAR_RULES.md § U3](../../UNIFIED_GRAMMAR_RULES.md)
156+
- [AGENTS.md § Invariant #5 - Phase Verification](../../AGENTS.md)
157+
158+
**Documentation**:
159+
- [02-CANONICAL-CONSTRAINTS.md § U3](02-CANONICAL-CONSTRAINTS.md#u3-resonant-coupling)
160+
- [03-OPERATORS-AND-GLYPHS.md § Coupling (UM)](03-OPERATORS-AND-GLYPHS.md)
161+
162+
**Implementation**:
163+
- `src/tnfr/operators/grammar.py::GrammarValidator.validate_resonant_coupling()`
164+
- `src/tnfr/operators/grammar.py::COUPLING_RESONANCE`
165+
- Operator preconditions check phase compatibility
166+
167+
**Tests**:
168+
- `tests/unit/operators/test_unified_grammar.py::TestU3ResonantCoupling`
169+
- `test_coupling_requires_phase_awareness`
170+
- `test_no_coupling_not_applicable`
171+
- `test_coupling_resonance_ops_trigger_u3`
172+
- `test_multiple_coupling_ops_trigger_u3`
173+
- `tests/unit/operators/test_coupling_preconditions.py::test_um_phase_compatibility_*`
174+
- `tests/unit/metrics/test_phase_compatibility.py::test_grammar_u3_compliance`
175+
- `tests/unit/operators/test_canonical_grammar_legacy.py::test_rc3_maps_to_u3`
176+
177+
**Examples**:
178+
- `examples/u3-resonant-coupling-examples.py::example_phase_compatibility`
179+
- `examples/u3-resonant-coupling-examples.py::example_antipattern_no_check`
180+
- `examples/u3-resonant-coupling-examples.py::example_antipattern_phase_drift`
181+
- `examples/u3-resonant-coupling-examples.py::example_wave_interference`
182+
183+
**Operators**:
184+
- Coupling/Resonance: `{coupling, resonance}``{UM, RA}`
185+
186+
**Phase Condition**:
187+
- Formula: `|φᵢ - φⱼ| ≤ Δφ_max`
188+
- Typical threshold: `π/2 radians`
189+
190+
**Anti-Patterns**:
191+
- Coupling nodes without phase check
192+
- Assuming small phase differences are always OK
193+
- Ignoring phase drift during sequences
194+
195+
---
196+
197+
## U4: BIFURCATION DYNAMICS
198+
199+
### U4a: Bifurcation Triggers Need Handlers
200+
201+
**Physics Basis**: Contract OZ + bifurcation theory (∂²EPI/∂t² > τ)
202+
203+
**Theory**:
204+
- [UNIFIED_GRAMMAR_RULES.md § U4a](../../UNIFIED_GRAMMAR_RULES.md)
205+
- [AGENTS.md § Contract OZ](../../AGENTS.md)
206+
- [03-OPERATORS-AND-GLYPHS.md § Dissonance (OZ)](03-OPERATORS-AND-GLYPHS.md)
207+
208+
**Documentation**:
209+
- [02-CANONICAL-CONSTRAINTS.md § U4a](02-CANONICAL-CONSTRAINTS.md#u4a-triggers-need-handlers)
210+
211+
**Implementation**:
212+
- `src/tnfr/operators/grammar.py::GrammarValidator.validate_bifurcation_triggers()`
213+
- `src/tnfr/operators/grammar.py::BIFURCATION_TRIGGERS`
214+
- `src/tnfr/operators/grammar.py::BIFURCATION_HANDLERS`
215+
216+
**Tests**:
217+
- `tests/unit/operators/test_unified_grammar.py::TestU4aBifurcationTriggers`
218+
- `test_triggers_require_handlers`
219+
- `test_triggers_without_handlers_fail`
220+
- `test_trigger_handler_pairs`
221+
- `test_no_triggers_not_applicable`
222+
- `test_multiple_triggers_need_handler`
223+
- `tests/unit/operators/test_controlled_bifurcation.py::test_multiple_bifurcations_*`
224+
- `tests/unit/operators/test_bifurcation.py::test_bifurcation_above_threshold`
225+
226+
**Examples**:
227+
- `examples/u4-bifurcation-examples.py::example_u4a_valid`
228+
- `examples/u4-bifurcation-examples.py::example_u4a_invalid`
229+
- `examples/u4-bifurcation-examples.py::example_antipattern_cascade`
230+
231+
**Operators**:
232+
- Triggers: `{dissonance, mutation}``{OZ, ZHIR}`
233+
- Handlers: `{self_organization, coherence}``{THOL, IL}`
234+
235+
**Anti-Patterns**:
236+
- Uncontrolled bifurcation cascades (multiple triggers without handlers)
237+
- Wrong handler for trigger type
238+
- Assuming handler proximity doesn't matter
239+
240+
---
241+
242+
### U4b: Transformers Need Context
243+
244+
**Physics Basis**: Threshold energy needed for phase transition
245+
246+
**Theory**:
247+
- [UNIFIED_GRAMMAR_RULES.md § U4b](../../UNIFIED_GRAMMAR_RULES.md)
248+
- [AGENTS.md § Contract OZ + ZHIR Requirements](../../AGENTS.md)
249+
- [U4B_AUDIT_REPORT.md](../../U4B_AUDIT_REPORT.md) - Complete U4b analysis
250+
251+
**Documentation**:
252+
- [02-CANONICAL-CONSTRAINTS.md § U4b](02-CANONICAL-CONSTRAINTS.md#u4b-transformers-need-context)
253+
- [03-OPERATORS-AND-GLYPHS.md § Mutation (ZHIR)](03-OPERATORS-AND-GLYPHS.md)
254+
255+
**Implementation**:
256+
- `src/tnfr/operators/grammar.py::GrammarValidator.validate_transformer_context()`
257+
- `src/tnfr/operators/grammar.py::TRANSFORMERS`
258+
- Window size: ~3 operators
259+
260+
**Tests**:
261+
- `tests/unit/operators/test_unified_grammar.py::TestU4bTransformerContext`
262+
- `test_transformer_needs_recent_destabilizer`
263+
- `test_transformer_without_destabilizer_fails`
264+
- `test_mutation_needs_prior_coherence`
265+
- `test_recent_window_is_three_ops`
266+
- `test_destabilizer_within_window_valid`
267+
- `test_self_organization_needs_destabilizer`
268+
- `test_no_transformers_not_applicable`
269+
- `tests/integration/test_mutation_sequences.py::test_u4b_satisfied_in_canonical_sequence`
270+
- `tests/unit/operators/test_controlled_bifurcation.py::test_transformer_at_sequence_start_fails`
271+
- `tests/unit/operators/test_zhir_u4b_validation.py`
272+
- `tests/unit/operators/test_mutation_metrics_comprehensive.py::test_grammar_u4b_validation`
273+
274+
**Examples**:
275+
- `examples/u4-bifurcation-examples.py::example_u4b_valid`
276+
- `examples/u4-bifurcation-examples.py::example_u4b_invalid`
277+
- `examples/u4-bifurcation-examples.py::example_zhir_requirements`
278+
- `examples/u4-bifurcation-examples.py::example_antipattern_window`
279+
280+
**Operators**:
281+
- Transformers: `{mutation, self_organization}``{ZHIR, THOL}`
282+
- Context: Recent destabilizer from `{dissonance, mutation, expansion}`
283+
- ZHIR specific: Prior coherence (IL) for stable base
284+
285+
**Anti-Patterns**:
286+
- Transformer without sufficient energy (too far from destabilizer)
287+
- ZHIR without stable base (missing prior coherence)
288+
- Confusing context window (which destabilizer provides context?)
289+
290+
---
291+
292+
## JSON Schema
293+
294+
**Schema File**: `schemas/constraints-u1-u4.json`
295+
296+
Complete machine-readable specification with:
297+
- Operator sets
298+
- Physics basis
299+
- Validation functions
300+
- Test references
301+
- Example references
302+
- Anti-patterns
303+
304+
---
305+
306+
## Quick Navigation
307+
308+
**By Document Type**:
309+
310+
| Type | Location |
311+
|------|----------|
312+
| Theory | [UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md) |
313+
| Physics | [TNFR.pdf](../../TNFR.pdf) |
314+
| Documentation | [02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md) |
315+
| Implementation | `src/tnfr/operators/grammar.py` |
316+
| Tests | `tests/unit/operators/test_unified_grammar.py` |
317+
| Examples | `examples/u*-examples.py` |
318+
| Schema | `schemas/constraints-u1-u4.json` |
319+
| Invariants | [AGENTS.md](../../AGENTS.md) |
320+
321+
**By Constraint**:
322+
323+
| Constraint | Theory | Docs | Code | Tests | Examples |
324+
|------------|--------|------|------|-------|----------|
325+
| U1a | [Link](../../UNIFIED_GRAMMAR_RULES.md) | [Link](02-CANONICAL-CONSTRAINTS.md#u1a-initiation-generators) | `validate_initiation()` | TestU1aInitiation | u1-examples.py |
326+
| U1b | [Link](../../UNIFIED_GRAMMAR_RULES.md) | [Link](02-CANONICAL-CONSTRAINTS.md#u1b-closure-endpoints) | `validate_closure()` | TestU1bClosure | u1-examples.py |
327+
| U2 | [Link](../../UNIFIED_GRAMMAR_RULES.md) | [Link](02-CANONICAL-CONSTRAINTS.md#u2-convergence--boundedness) | `validate_convergence()` | TestU2Convergence | u2-examples.py |
328+
| U3 | [Link](../../UNIFIED_GRAMMAR_RULES.md) | [Link](02-CANONICAL-CONSTRAINTS.md#u3-resonant-coupling) | `validate_resonant_coupling()` | TestU3ResonantCoupling | u3-examples.py |
329+
| U4a | [Link](../../UNIFIED_GRAMMAR_RULES.md) | [Link](02-CANONICAL-CONSTRAINTS.md#u4a-triggers-need-handlers) | `validate_bifurcation_triggers()` | TestU4aBifurcationTriggers | u4-examples.py |
330+
| U4b | [Link](../../UNIFIED_GRAMMAR_RULES.md) | [Link](02-CANONICAL-CONSTRAINTS.md#u4b-transformers-need-context) | `validate_transformer_context()` | TestU4bTransformerContext | u4-examples.py |
331+
332+
---
333+
334+
## Verification Checklist
335+
336+
**To verify a constraint implementation**:
337+
338+
- [ ] Physics derivation in UNIFIED_GRAMMAR_RULES.md
339+
- [ ] Documentation section in 02-CANONICAL-CONSTRAINTS.md
340+
- [ ] Implementation in grammar.py
341+
- [ ] Operator sets defined
342+
- [ ] Test class exists with multiple test cases
343+
- [ ] Executable examples with valid/invalid patterns
344+
- [ ] Anti-patterns documented
345+
- [ ] JSON schema entry complete
346+
- [ ] Cross-references working
347+
348+
---
349+
350+
## Update Procedure
351+
352+
**When modifying a constraint**:
353+
354+
1. Update **theory** in UNIFIED_GRAMMAR_RULES.md
355+
2. Update **documentation** in 02-CANONICAL-CONSTRAINTS.md
356+
3. Update **implementation** in grammar.py
357+
4. Update **tests** in test_unified_grammar.py
358+
5. Update **examples** in u*-examples.py
359+
6. Update **schema** in constraints-u1-u4.json
360+
7. Update **this index** if cross-references change
361+
362+
**Maintain bidirectional traceability at all times.**
363+
364+
---
365+
366+
<div align="center">
367+
368+
**Complete traceability: Theory → Docs → Code → Tests → Examples**
369+
370+
---
371+
372+
*Single source of truth for TNFR canonical grammar*
373+
374+
</div>

0 commit comments

Comments
 (0)