Skip to content

Commit a2762b4

Browse files
Copilotfermga
andcommitted
Implement R6: Operational closure via controlled mutation validation
Co-authored-by: fermga <203334638+fermga@users.noreply.github.com>
1 parent 9e8f399 commit a2762b4

File tree

2 files changed

+135
-239
lines changed

2 files changed

+135
-239
lines changed

src/tnfr/operators/grammar.py

Lines changed: 91 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,12 +1031,10 @@ def _check_operational_closure(self, sequence: Sequence[str]) -> bool:
10311031
return destabilizers <= stabilizers
10321032

10331033
def _validate_operational_closure(self, sequence: Sequence[str]) -> None:
1034-
"""R6: Validate sequence has operational closure through proper balance.
1034+
"""R6: Validate operational closure - controlled mutation only.
10351035
1036-
R6 validates that operator sequences achieve operational closure by
1037-
ensuring destabilization is properly balanced with stabilization.
1038-
This prevents divergent trajectories while allowing all valid purposes:
1039-
stabilizing, neutral, and destabilizing sequences.
1036+
R6 philosophy: Trust R1-R5 for structural correctness.
1037+
R6 adds minimal validation for special cases that require context.
10401038
10411039
Parameters
10421040
----------
@@ -1046,87 +1044,111 @@ def _validate_operational_closure(self, sequence: Sequence[str]) -> None:
10461044
Raises
10471045
------
10481046
SequenceSyntaxError
1049-
If sequence violates operational closure requirements
1047+
If sequence violates controlled mutation requirements
10501048
10511049
Notes
10521050
-----
1053-
**R6 Philosophy:**
1051+
**R6 Canonical Simplification:**
10541052
1055-
R3 validates syntactic correctness (valid start/end operators).
1056-
R6 validates semantic coherence (sustainable balance).
1053+
After deep analysis, R6 does NOT validate destabilizer/stabilizer balance.
1054+
Why? Because:
10571055
1058-
R6 does NOT reject any R3-valid endings (SHA, NAV, REMESH, OZ).
1059-
Instead, it validates that each ending type has appropriate balance.
1056+
1. **R3 already validates endings** - All four (SHA, NAV, REMESH, OZ)
1057+
provide valid closure types:
1058+
- SHA: Terminal closure (freeze)
1059+
- NAV: Handoff closure (transfer to next regime)
1060+
- REMESH: Recursive closure (fractal distribution)
1061+
- OZ: Intentional closure (preserve tension)
10601062
1061-
**Valid Ending Types** (from R3):
1063+
2. **Sequences are context-dependent** - Same dest/stab ratio serves
1064+
different purposes depending on system state:
1065+
- High ΔNFR system + stabilizing sequence = healing
1066+
- Low ΔNFR system + destabilizing sequence = activation
1067+
- Balance is RELATIVE to initial state, not absolute
10621068
1063-
1. **SHA (Silence)**: Terminal closure
1064-
- Freezes evolution (νf → 0)
1065-
- Accepts ANY destabilizer/stabilizer ratio
1066-
- Provides absolute closure regardless of balance
1067-
1068-
2. **NAV (Transition)**: Handoff closure
1069-
- Regime transfer to next state
1070-
- Requires: destabilizers ≤ stabilizers
1071-
- Needs balance for sustainable handoff
1072-
1073-
3. **REMESH (Recursivity)**: Recursive closure
1074-
- Fractal echo across scales
1075-
- Requires: destabilizers ≤ stabilizers
1076-
- Needs balance for stable recursion
1077-
1078-
4. **OZ (Dissonance)**: Intentional tension preservation
1079-
- Therapeutic/activation pattern
1080-
- Requires: destabilizers ≤ stabilizers
1081-
- Must be CONTROLLED dissonance with prior stabilization
1082-
1083-
**Balance Validation:**
1069+
3. **Multi-sequence patterns are valid** - Closure at chain level:
1070+
- Sequence 1: Destabilize → NAV (handoff)
1071+
- Sequence 2: Stabilize → SHA (resolution)
1072+
- Individual sequences don't need balance if chain has it
1073+
1074+
4. **All endings provide closure** - Each R3-valid ending has
1075+
physical mechanism for operational closure:
1076+
- NAV can handle imbalance (hands off to next regime)
1077+
- REMESH can handle imbalance (distributes across scales)
1078+
- OZ can handle imbalance (intentional tension preservation)
1079+
- Not just SHA (freezing)
1080+
1081+
**What R6 DOES Validate:**
10841082
1085-
Operational closure requires appropriate balance for non-SHA endings:
1086-
- dest ≤ stab: Ensures sustainability
1087-
- dest = stab: Neutral (maintains coherence)
1088-
- dest < stab: Stabilizing (reduces ΔNFR)
1083+
**Controlled Mutation (IL → ZHIR):**
1084+
Phase transformations (ZHIR) require stable coherent base.
1085+
IL before ZHIR ensures transformation has structural foundation.
10891086
1090-
SHA exception: Can handle dest > stab because freezing (νf → 0)
1091-
provides absolute closure that doesn't depend on balance.
1087+
Without IL before ZHIR: ungrounded transformation (unstable)
1088+
With IL before ZHIR: transformation from coherence (stable)
10921089
1093-
**Why Allow OZ Endings?**
1090+
This is the ONLY balance-related check that's truly canonical,
1091+
and it's not about counts but about PREPARATION for transformation.
10941092
1095-
OZ endings serve valid purposes:
1096-
- Therapeutic: Intentionally preserve tension for processing
1097-
- Activation: Wake up stuck systems
1098-
- Multi-sequence chains: Open tension for next sequence to resolve
1093+
**What R6 Does NOT Validate:**
10991094
1100-
The key: OZ ending must be CONTROLLED (have prior stabilization),
1101-
not runaway destabilization. Balance check ensures this.
1095+
- Destabilizer/stabilizer balance (context-dependent)
1096+
- Ending-specific balance requirements (R3 handles endings)
1097+
- Net ΔNFR state (depends on initial conditions)
11021098
1103-
**Controlled Mutation Exception:**
1099+
**Frequency Balance (Future):**
1100+
Could calculate frequency balance for informational/telemetry purposes,
1101+
but NOT as validation constraint. Balance emerges from usage, not rules.
11041102
1105-
IL → ZHIR allows imbalance because coherence provides stable base
1106-
for intentional phase transformation.
1103+
**Theoretical Justification:**
11071104
1108-
Theoretical foundation:
1109-
From integrated equation: EPI(t_f) = EPI(t_0) + ∫ νf · ΔNFR dt
1105+
From nodal equation: ∂EPI/∂t = νf · ΔNFR(t)
11101106
1111-
For physical coherence:
1112-
- SHA: νf → 0, so integral converges regardless of ΔNFR
1113-
- Others: Need dest ≤ stab to ensure ∫ νf · ΔNFR dt converges
1107+
The equation doesn't prescribe dest = stab. It describes evolution.
1108+
Valid sequences can have any dest/stab ratio if ending provides closure.
1109+
1110+
R3 ensures operational closure through valid endings.
1111+
R6 trusts R3 and adds only mutation-specific validation.
1112+
1113+
This is most canonical because it:
1114+
✓ Respects existing rules (R1-R5)
1115+
✓ Removes arbitrary restrictions
1116+
✓ Allows context-dependent usage
1117+
✓ Supports multi-sequence patterns
1118+
✓ Aligns with TNFR flexibility
11141119
"""
1115-
# Validate balance (no separate convergence check - respect R3)
1116-
if not self._check_operational_closure(sequence):
1117-
last_op = sequence[-1]
1118-
raise SequenceSyntaxError(
1119-
index=-1,
1120-
token=None,
1121-
message=(
1122-
f"R6: Sequence lacks operational closure. "
1123-
f"Ending with {operator_display_name(last_op)} requires destabilizers ≤ stabilizers for sustainability. "
1124-
f"Purpose-aware balance: STABILIZING (dest < stab), NEUTRAL (dest = stab), or DESTABILIZING (dest > stab, needs {operator_display_name(SILENCE)} ending). "
1125-
f"Destabilizers: {operator_display_name(DISSONANCE)}, {operator_display_name(TRANSITION)}, {operator_display_name(EXPANSION)}, {operator_display_name(RECEPTION)}. "
1126-
f"Stabilizers: {operator_display_name(COHERENCE)}, {operator_display_name(SELF_ORGANIZATION)}, {operator_display_name(SILENCE)}, {operator_display_name(RESONANCE)}. "
1127-
f"Note: {operator_display_name(DISSONANCE)} endings are valid for therapeutic/activation patterns when properly balanced."
1128-
),
1129-
)
1120+
# Only validation: Controlled mutation (if ZHIR present)
1121+
if MUTATION in sequence:
1122+
# ZHIR requires prior coherence base for stable transformation
1123+
if COHERENCE not in sequence:
1124+
raise SequenceSyntaxError(
1125+
index=sequence.index(MUTATION),
1126+
token=MUTATION,
1127+
message=(
1128+
f"R6: {operator_display_name(MUTATION)} (phase transformation) requires "
1129+
f"prior {operator_display_name(COHERENCE)} for stable structural foundation. "
1130+
f"Controlled mutation: {operator_display_name(COHERENCE)}{operator_display_name(MUTATION)} "
1131+
f"ensures transformation occurs from coherent base state."
1132+
),
1133+
)
1134+
1135+
# If IL present, verify it comes before ZHIR
1136+
coherence_idx = sequence.index(COHERENCE)
1137+
mutation_idx = sequence.index(MUTATION)
1138+
if coherence_idx >= mutation_idx:
1139+
raise SequenceSyntaxError(
1140+
index=mutation_idx,
1141+
token=MUTATION,
1142+
message=(
1143+
f"R6: {operator_display_name(MUTATION)} must follow {operator_display_name(COHERENCE)}. "
1144+
f"Controlled mutation requires coherent base BEFORE transformation. "
1145+
f"Current order: {operator_display_name(MUTATION)} before {operator_display_name(COHERENCE)} (invalid)."
1146+
),
1147+
)
1148+
1149+
# Future: Could add frequency balance calculation here (informational)
1150+
# freq_balance = self._compute_frequency_balance(sequence)
1151+
# Store in metadata, but don't enforce as validation
11301152

11311153
def _finalize(self, names: Sequence[str]) -> None:
11321154
if self._unknown_tokens:

0 commit comments

Comments
 (0)