Skip to content

Commit 509cf82

Browse files
Copilotfermga
andcommitted
Implement U5: Multi-Scale Coherence grammar rule
Intent: Add U5 canonical grammar constraint for multi-scale coherence preservation Operators involved: REMESH (Recursivity), IL (Coherence), THOL (Self-organization) Affected invariants: #7 (Operational Fractality), #2 (Structural Units) Key changes: - Added RECURSIVE_GENERATORS and SCALE_STABILIZERS operator sets - Implemented validate_multiscale_coherence() in GrammarValidator - Added depth parameter to Recursivity operator (default=1) - Updated unified_grammar.py facade to export U5 sets - Integrated U5 validation into grammar pipeline Physical basis: - Conservation of coherence: C_parent ≥ α·ΣC_child_i - Factor α = (1/√N)·η_phase(N)·η_coupling(N) ∈ [0.1, 0.4] - Operates in SPATIAL dimension (hierarchy) vs U1-U4 (TEMPORAL) - Independent of U2+U4b per decision test case Metrics: U5 ensures bounded multi-scale evolution when depth>1 Co-authored-by: fermga <203334638+fermga@users.noreply.github.com>
1 parent 0925501 commit 509cf82

File tree

3 files changed

+168
-5
lines changed

3 files changed

+168
-5
lines changed

src/tnfr/operators/definitions.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4064,6 +4064,21 @@ class Recursivity(Operator):
40644064
40654065
Critical: REMESH preserves identity across scales - fundamental to TNFR fractality.
40664066
4067+
Parameters
4068+
----------
4069+
depth : int, optional
4070+
Hierarchical nesting depth for multi-scale recursion (default: 1).
4071+
- depth=1: Shallow recursion (single level, no multi-scale constraint)
4072+
- depth>1: Deep recursion (multi-level hierarchy, requires U5 stabilizers)
4073+
4074+
Notes
4075+
-----
4076+
**U5: Multi-Scale Coherence**: When depth>1, U5 grammar rule applies requiring
4077+
scale stabilizers (IL or THOL) within ±3 operators to preserve coherence across
4078+
hierarchical levels. This ensures C_parent ≥ α·ΣC_child per conservation principle.
4079+
4080+
See UNIFIED_GRAMMAR_RULES.md § U5 for complete physical derivation.
4081+
40674082
Examples
40684083
--------
40694084
>>> from tnfr.constants import EPI_PRIMARY, VF_PRIMARY
@@ -4083,16 +4098,33 @@ class Recursivity(Operator):
40834098
>>> run_sequence(G, node, [Recursivity()])
40844099
>>> G.graph["echo_trace"]
40854100
[(0.54, 0.95)]
4101+
4102+
Deep recursion example requiring U5 stabilizers:
4103+
>>> from tnfr.operators.definitions import Recursivity, Coherence, Silence
4104+
>>> # depth=3 creates multi-level hierarchy - requires IL for U5
4105+
>>> ops = [Recursivity(depth=3), Coherence(), Silence()]
40864106
40874107
**Biomedical**: Fractal physiology (HRV, EEG), developmental recapitulation
40884108
**Cognitive**: Recursive thinking, meta-cognition, self-referential processes
40894109
**Social**: Cultural fractals, organizational self-similarity, meme propagation
40904110
"""
40914111

4092-
__slots__ = ()
4112+
__slots__ = ("depth",)
40934113
name: ClassVar[str] = RECURSIVITY
40944114
glyph: ClassVar[Glyph] = Glyph.REMESH
40954115

4116+
def __init__(self, depth: int = 1):
4117+
"""Initialize Recursivity operator with hierarchical depth.
4118+
4119+
Parameters
4120+
----------
4121+
depth : int, optional
4122+
Nesting depth for multi-scale recursion (default: 1)
4123+
"""
4124+
if depth < 1:
4125+
raise ValueError(f"depth must be >= 1, got {depth}")
4126+
self.depth = depth
4127+
40964128
def _validate_preconditions(self, G: TNFRGraph, node: Any) -> None:
40974129
"""Validate REMESH-specific preconditions."""
40984130
from .preconditions import validate_recursivity

src/tnfr/operators/grammar.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ def function_name_to_glyph(
199199
"BIFURCATION_TRIGGERS",
200200
"BIFURCATION_HANDLERS",
201201
"TRANSFORMERS",
202+
"RECURSIVE_GENERATORS",
203+
"SCALE_STABILIZERS",
202204
]
203205

204206

@@ -230,6 +232,10 @@ def function_name_to_glyph(
230232
# U4b: Transformers - Execute structural bifurcations
231233
TRANSFORMERS = frozenset({"mutation", "self_organization"})
232234

235+
# U5: Multi-Scale Coherence - Recursive generators and scale stabilizers
236+
RECURSIVE_GENERATORS = frozenset({"recursivity"})
237+
SCALE_STABILIZERS = frozenset({"coherence", "self_organization"})
238+
233239

234240
# ============================================================================
235241
# Grammar Errors
@@ -894,6 +900,120 @@ def validate_remesh_amplification(sequence: List[Operator]) -> tuple[bool, str]:
894900
f"bound recursive amplification of {destabilizers_present}",
895901
)
896902

903+
@staticmethod
904+
def validate_multiscale_coherence(sequence: List[Operator]) -> tuple[bool, str]:
905+
"""Validate U5: Multi-scale coherence preservation.
906+
907+
Physical basis: Multi-scale hierarchical structures created by REMESH
908+
with depth>1 require coherence conservation across scales. This operates
909+
in the SPATIAL dimension (hierarchy) versus U1-U4 (TEMPORAL sequences).
910+
911+
From coherence conservation principle:
912+
C_total = C_parent + Σ C_child_i = constant
913+
914+
For bounded evolution:
915+
C_parent ≥ α · Σ C_child_i
916+
917+
Where α = (1/√N) · η_phase(N) · η_coupling(N)
918+
- 1/√N: Scale factor (sublinear growth)
919+
- η_phase: Phase synchronization efficiency (decreases with N)
920+
- η_coupling: Coupling efficiency (decreases with N)
921+
- Typical range: α ∈ [0.1, 0.4]
922+
923+
Without stabilizers:
924+
Deep REMESH (depth>1) creates nested EPIs
925+
→ Coherence fragments across scales
926+
→ C_parent < α · Σ C_child (conservation violated)
927+
→ System fragments
928+
929+
With stabilizers (IL or THOL):
930+
Multi-level coherence stabilization
931+
→ C_parent ≥ α · Σ C_child (conservation preserved)
932+
→ Bounded multi-scale evolution
933+
934+
Parameters
935+
----------
936+
sequence : List[Operator]
937+
Sequence of operators to validate
938+
939+
Returns
940+
-------
941+
tuple[bool, str]
942+
(is_valid, message)
943+
944+
Notes
945+
-----
946+
U5 is INDEPENDENT of U2+U4b:
947+
- U2/U4b: TEMPORAL dimension (operator sequences in time)
948+
- U5: SPATIAL dimension (hierarchical nesting in structure)
949+
950+
Decision test case that passes U2+U4b but fails U5:
951+
[AL, REMESH(depth=3), SHA]
952+
- U2: ✓ No destabilizers (trivially convergent)
953+
- U4b: ✓ REMESH not a transformer (U4b doesn't apply)
954+
- U5: ✗ Deep recursivity without stabilization → fragmentation
955+
956+
Physical derivation: See UNIFIED_GRAMMAR_RULES.md § U5
957+
Canonicity: STRONG (derived from conservation of coherence)
958+
959+
References
960+
----------
961+
- Problem statement: "El pulso que nos atraviesa.pdf"
962+
- AGENTS.md: Invariant #7 (Operational Fractality)
963+
- TNFR.pdf § 2.1: Nodal equation and coherence
964+
"""
965+
# Check for deep REMESH (depth > 1)
966+
# Note: Currently Recursivity doesn't expose depth parameter in operator
967+
# This is a forward-looking validation for when depth is added
968+
deep_remesh_indices = []
969+
970+
for i, op in enumerate(sequence):
971+
op_name = getattr(op, "canonical_name", op.name.lower())
972+
if op_name == "recursivity":
973+
# Check if operator has depth attribute
974+
depth = getattr(op, "depth", 1) # Default depth=1 if not present
975+
if depth > 1:
976+
deep_remesh_indices.append((i, depth))
977+
978+
if not deep_remesh_indices:
979+
# No deep REMESH present, U5 not applicable
980+
return True, "U5: not applicable (no deep recursivity depth>1 present)"
981+
982+
# For each deep REMESH, check for stabilizers in window
983+
violations = []
984+
for idx, depth in deep_remesh_indices:
985+
# Check window of ±3 operators for scale stabilizers
986+
window_start = max(0, idx - 3)
987+
window_end = min(len(sequence), idx + 4)
988+
989+
has_stabilizer = False
990+
stabilizers_in_window = []
991+
992+
for j in range(window_start, window_end):
993+
op_name = getattr(
994+
sequence[j], "canonical_name", sequence[j].name.lower()
995+
)
996+
if op_name in SCALE_STABILIZERS:
997+
has_stabilizer = True
998+
stabilizers_in_window.append((j, op_name))
999+
1000+
if not has_stabilizer:
1001+
violations.append(
1002+
f"recursivity at position {idx} (depth={depth}) lacks scale "
1003+
f"stabilizer in window [{window_start}:{window_end}]. "
1004+
f"Deep hierarchical nesting requires {sorted(SCALE_STABILIZERS)} "
1005+
f"for multi-scale coherence preservation (C_parent ≥ α·ΣC_child)"
1006+
)
1007+
1008+
if violations:
1009+
return (False, f"U5 violated: {'; '.join(violations)}")
1010+
1011+
return (
1012+
True,
1013+
f"U5 satisfied: deep recursivity has scale stabilizers "
1014+
f"for multi-scale coherence preservation",
1015+
)
1016+
8971017
@classmethod
8981018
def validate(
8991019
cls,
@@ -907,6 +1027,7 @@ def validate(
9071027
- U2: Convergence & boundedness
9081028
- U3: Resonant coupling
9091029
- U4: Bifurcation dynamics
1030+
- U5: Multi-scale coherence
9101031
9111032
Parameters
9121033
----------
@@ -960,6 +1081,11 @@ def validate(
9601081
messages.append(f"U2-REMESH: {msg_remesh}")
9611082
all_valid = all_valid and valid_remesh
9621083

1084+
# U5: Multi-scale coherence
1085+
valid_multiscale, msg_multiscale = cls.validate_multiscale_coherence(sequence)
1086+
messages.append(f"U5: {msg_multiscale}")
1087+
all_valid = all_valid and valid_multiscale
1088+
9631089
return all_valid, messages
9641090

9651091

src/tnfr/operators/unified_grammar.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
"""Unified TNFR Grammar - Facade to GrammarValidator.
22
33
This module provides a clean facade to the canonical grammar validation
4-
implemented in grammar.py. It exports the unified grammar constraints (U1-U4)
4+
implemented in grammar.py. It exports the unified grammar constraints (U1-U5)
55
and the validator for use in tests and applications.
66
77
All grammar rules derive inevitably from TNFR physics:
88
- U1: STRUCTURAL INITIATION & CLOSURE
99
- U2: CONVERGENCE & BOUNDEDNESS
1010
- U3: RESONANT COUPLING
1111
- U4: BIFURCATION DYNAMICS (U4a: triggers, U4b: transformers)
12+
- U5: MULTI-SCALE COHERENCE
1213
1314
References
1415
----------
@@ -40,6 +41,8 @@
4041
COUPLING_RESONANCE,
4142
DESTABILIZERS,
4243
GENERATORS,
44+
RECURSIVE_GENERATORS,
45+
SCALE_STABILIZERS,
4346
STABILIZERS,
4447
TRANSFORMERS,
4548
)
@@ -52,7 +55,7 @@
5255
"UnifiedGrammarValidator",
5356
# Convenience function
5457
"validate_unified",
55-
# Operator sets (U1-U4 categories)
58+
# Operator sets (U1-U5 categories)
5659
"GENERATORS",
5760
"CLOSURES",
5861
"STABILIZERS",
@@ -61,14 +64,16 @@
6164
"BIFURCATION_TRIGGERS",
6265
"BIFURCATION_HANDLERS",
6366
"TRANSFORMERS",
67+
"RECURSIVE_GENERATORS",
68+
"SCALE_STABILIZERS",
6469
]
6570

6671

6772
def validate_unified(
6873
sequence: List["Operator"],
6974
epi_initial: float = 0.0,
7075
) -> bool:
71-
"""Validate sequence using unified TNFR grammar (U1-U4).
76+
"""Validate sequence using unified TNFR grammar (U1-U5).
7277
7378
Convenience function that returns only boolean result.
7479
For detailed messages, use UnifiedGrammarValidator.validate().
@@ -83,7 +88,7 @@ def validate_unified(
8388
Returns
8489
-------
8590
bool
86-
True if sequence satisfies all U1-U4 constraints
91+
True if sequence satisfies all U1-U5 constraints
8792
8893
Examples
8994
--------

0 commit comments

Comments
 (0)