Skip to content

Commit c2e084e

Browse files
Copilotfermga
andcommitted
Implement RECEPTION dual-role frequency classification with context validation
Co-authored-by: fermga <203334638+fermga@users.noreply.github.com>
1 parent e9c04f1 commit c2e084e

File tree

3 files changed

+464
-6
lines changed

3 files changed

+464
-6
lines changed

src/tnfr/operators/grammar.py

Lines changed: 101 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
"FUNCTION_TO_GLYPH",
8888
"GLYPH_TO_FUNCTION",
8989
"STRUCTURAL_FREQUENCIES",
90+
"DUAL_FREQUENCY_OPERATORS",
9091
"FREQUENCY_TRANSITIONS",
9192
"glyph_function_name",
9293
"function_name_to_glyph",
@@ -661,6 +662,62 @@ def _has_recent_destabilizer(self, current_index: int) -> bool:
661662
for _, dest_index in self._bifurcation_context
662663
)
663664

665+
def _validate_reception_context(self, reception_index: int) -> bool:
666+
"""Validate that RECEPTION has sufficient prior coherence for destabilization.
667+
668+
RECEPTION (EN) as a weak destabilizer requires context: it must operate on
669+
a node with existing structural base to generate sufficient ΔNFR for transformers.
670+
671+
Parameters
672+
----------
673+
reception_index : int
674+
Index of the RECEPTION operator in the sequence
675+
676+
Returns
677+
-------
678+
bool
679+
True if RECEPTION has adequate prior structural coherence
680+
681+
Notes
682+
-----
683+
Valid patterns include:
684+
- AL → EN → IL → EN (emission provides base, first EN consolidated, second can destabilize)
685+
- EN → IL → EN (first EN consolidated, second can destabilize)
686+
- OZ → IL → EN (dissonance resolved provides base)
687+
688+
Invalid patterns include:
689+
- EN as first operator (no prior base)
690+
- EN immediately after SHA (silence removes base)
691+
692+
Theoretical justification:
693+
From nodal equation ∂EPI/∂t = νf · ΔNFR, RECEPTION has medium νf.
694+
For EN → ZHIR to be valid, EN must generate high ΔNFR. This is only possible
695+
when EN captures external coherence into a structurally prepared node,
696+
creating reorganization pressure from the integration.
697+
"""
698+
# RECEPTION at position 0 cannot have prior coherence
699+
if reception_index == 0:
700+
return False
701+
702+
# Look for stabilizer (IL or THOL) before RECEPTION
703+
# This indicates the node has structural base for destabilization
704+
for i in range(reception_index):
705+
op = self._canonical[i]
706+
if op in {COHERENCE, SELF_ORGANIZATION}:
707+
# Found stabilizer - check it's not too far back
708+
# For context, we require stabilizer within 3 operators before EN
709+
if reception_index - i <= 3:
710+
# Additionally, ensure no SILENCE between stabilizer and EN
711+
# (SILENCE would remove the coherent base)
712+
has_silence = any(
713+
self._canonical[j] == SILENCE
714+
for j in range(i + 1, reception_index)
715+
)
716+
if not has_silence:
717+
return True
718+
719+
return False
720+
664721
def _has_graduated_destabilizer(self, current_index: int) -> bool:
665722
"""Check if any level of destabilizer satisfies its window requirement.
666723
@@ -680,9 +737,16 @@ def _has_graduated_destabilizer(self, current_index: int) -> bool:
680737
- Strong destabilizers (OZ): window of 4 operators
681738
- Moderate destabilizers (NAV, VAL): window of 2 operators
682739
- Weak destabilizers (EN): must be immediate predecessor (window of 1)
740+
AND have sufficient prior coherence context
683741
684742
The method checks each level in order of window size (largest first)
685743
to provide the most permissive validation.
744+
745+
RECEPTION (EN) Context Validation:
746+
EN as weak destabilizer requires validation of structural context.
747+
According to DUAL_FREQUENCY_OPERATORS, EN has medium base frequency
748+
but can generate ΔNFR when capturing external coherence into a prepared
749+
node. This validation ensures EN → ZHIR transitions are structurally sound.
686750
"""
687751
# Check strong destabilizers (longest window = 4)
688752
if self._destabilizer_context["strong"]:
@@ -697,10 +761,14 @@ def _has_graduated_destabilizer(self, current_index: int) -> bool:
697761
return True
698762

699763
# Check weak destabilizers (window = 1, must be immediate)
764+
# RECEPTION requires additional context validation for dual-role coherence
700765
if self._destabilizer_context["weak"]:
701766
last_weak = self._destabilizer_context["weak"][-1]
702767
if current_index - last_weak == 1:
703-
return True
768+
# Validate that RECEPTION has sufficient context for destabilization
769+
# This implements the "requires_prior_coherence" condition from
770+
# DUAL_FREQUENCY_OPERATORS
771+
return self._validate_reception_context(last_weak)
704772

705773
return False
706774

@@ -983,7 +1051,7 @@ class StructuralPattern(Enum):
9831051
# - zero: Operators that suspend reorganization while preserving form
9841052
STRUCTURAL_FREQUENCIES: dict[str, str] = {
9851053
EMISSION: "high", # AL: initiation/reorganization
986-
RECEPTION: "medium", # EN: structural capture
1054+
RECEPTION: "medium", # EN: structural capture (base frequency)
9871055
COHERENCE: "medium", # IL: stabilization
9881056
DISSONANCE: "high", # OZ: tension
9891057
COUPLING: "medium", # UM: coupling
@@ -997,6 +1065,37 @@ class StructuralPattern(Enum):
9971065
RECURSIVITY: "medium", # REMESH: fractal echo
9981066
}
9991067

1068+
# Dual-role operators: operators with context-dependent destabilization capacity
1069+
# Resolves the structural inconsistency between base frequency (νf) and ΔNFR generation.
1070+
#
1071+
# RECEPTION (EN) is the canonical dual-role operator:
1072+
# - Base frequency: "medium" (νf for structural capture)
1073+
# - Destabilization capacity: "weak" (can generate ΔNFR when integrating external coherence)
1074+
# - Condition: Requires prior coherence base for effective destabilization
1075+
#
1076+
# Theoretical foundation (nodal equation):
1077+
# ∂EPI/∂t = νf · ΔNFR
1078+
#
1079+
# RECEPTION has medium νf (moderate reorganization rate) but can act as weak
1080+
# destabilizer in graduated bifurcation (R4) when capturing external coherence
1081+
# into a node with existing structural base. The external input can generate
1082+
# sufficient ΔNFR to enable transformers (ZHIR/THOL) despite medium base frequency.
1083+
#
1084+
# Context requirement: EN → ZHIR valid only when EN operates on coherent base
1085+
# (e.g., AL → EN → IL → EN → ZHIR). Direct EN → ZHIR without context violates
1086+
# structural coherence as medium νf alone cannot sustain high ΔNFR for mutation.
1087+
DUAL_FREQUENCY_OPERATORS: dict[str, dict[str, str]] = {
1088+
RECEPTION: {
1089+
"base_freq": "medium",
1090+
"destabilization_capacity": "weak",
1091+
"conditions": "requires_prior_coherence",
1092+
"rationale": (
1093+
"Captures external coherence which can generate ΔNFR when "
1094+
"integrated into structurally prepared node"
1095+
),
1096+
}
1097+
}
1098+
10001099
# Frequency compatibility: operators with harmonic frequencies can transition
10011100
# Valid transitions preserve structural coherence:
10021101
# - high ↔ medium: High energy can stabilize or stabilized can amplify

tests/unit/operators/test_graduated_destabilizer_windows.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,26 @@ def test_en_with_stronger_destabilizer(self):
166166
assert result.passed
167167

168168
def test_en_immediate_thol_also_requires_coherence(self):
169-
"""EN → THOL also needs EN → IL → THOL per R2."""
170-
# R2 requires RECEPTION → COHERENCE segment
169+
"""EN → THOL fails because EN lacks coherent context for destabilization.
170+
171+
Updated with dual-role context validation: EN as weak destabilizer now
172+
requires prior coherence base. AL → EN → THOL fails because EN at position 1
173+
has no prior stabilizer (IL or THOL) to provide context for destabilization.
174+
175+
This is more precise than the generic "missing reception→coherence segment"
176+
error, as it specifically identifies that EN cannot destabilize THOL without
177+
structural preparation.
178+
"""
171179
with pytest.raises(SequenceSyntaxError) as excinfo:
172180
parse_sequence(
173181
[EMISSION, RECEPTION, SELF_ORGANIZATION, SILENCE]
174182
)
175183

176184
error = excinfo.value
177-
# Should fail on missing coherence segment, not destabilizer
178-
assert "reception" in error.message.lower() and "coherence" in error.message.lower()
185+
# With dual-role validation, fails on destabilizer requirement
186+
# (more specific than generic EN→IL segment requirement)
187+
assert "self_organization" in error.message.lower()
188+
assert "destabilizer" in error.message.lower()
179189

180190
def test_en_with_intermediate_thol_fails(self):
181191
"""EN → IL → THOL (fails - EN requires immediate)."""

0 commit comments

Comments
 (0)