Skip to content

Commit 9e5fc35

Browse files
Copilotfermga
andcommitted
Implement SHA grammar validation: prohibit SHA→OZ and SHA→SHA transitions
Co-authored-by: fermga <203334638+fermga@users.noreply.github.com>
1 parent 5eda016 commit 9e5fc35

File tree

2 files changed

+373
-3
lines changed

2 files changed

+373
-3
lines changed

src/tnfr/operators/grammar.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,48 @@ def _validate_transition(
584584
Frequency transitions are validated:
585585
- Valid transitions: Pass silently
586586
- Invalid transitions: Raise SequenceSyntaxError
587+
588+
SHA (Silence) specific validations:
589+
- SHA → OZ: Prohibited (silence followed by dissonance contradicts preservation)
590+
- SHA → SHA: Prohibited (redundant silence without structural purpose)
587591
"""
588592

589593
# Only validate if prev is also a known operator
590594
if prev not in OPERATORS:
591595
return
592596

597+
# SHA-specific validations (R6: Silence operator compatibility)
598+
if prev == SILENCE:
599+
if curr == DISSONANCE:
600+
# SHA → OZ: Silence followed by Dissonance is contradictory
601+
# SHA reduces νf → 0 (preservation state)
602+
# OZ increases ΔNFR (instability, exploration)
603+
# Cannot introduce dissonance into a paused node
604+
raise SequenceSyntaxError(
605+
index=index,
606+
token=token,
607+
message=(
608+
f"{operator_display_name(DISSONANCE)} invalid after {operator_display_name(SILENCE)}: "
609+
f"Silence (νf → 0) contradicts Dissonance (ΔNFR ↑). "
610+
f"Cannot introduce dissonance into paused node. "
611+
f"Use {operator_display_name(SILENCE)}{operator_display_name(TRANSITION)}{operator_display_name(DISSONANCE)} "
612+
f"or {operator_display_name(SILENCE)}{operator_display_name(EMISSION)}{operator_display_name(DISSONANCE)} for reactivation."
613+
),
614+
)
615+
elif curr == SILENCE:
616+
# SHA → SHA: Redundant silence without structural purpose
617+
# If νf ≈ 0, second SHA has no effect
618+
# Violates operator closure principle (each operator must transform)
619+
raise SequenceSyntaxError(
620+
index=index,
621+
token=token,
622+
message=(
623+
f"Redundant {operator_display_name(SILENCE)} after {operator_display_name(SILENCE)}: "
624+
f"Consecutive silence operators serve no structural purpose. "
625+
f"Remove duplicate or insert transition operator."
626+
),
627+
)
628+
593629
# R5: Validate structural frequency transitions using ONLY canonical TNFR physics
594630
freq_valid, freq_msg = validate_frequency_transition(prev, curr)
595631
if not freq_valid:
@@ -964,14 +1000,15 @@ class StructuralPattern(Enum):
9641000
# Frequency compatibility: operators with harmonic frequencies can transition
9651001
# Valid transitions preserve structural coherence:
9661002
# - high ↔ medium: High energy can stabilize or stabilized can amplify
1003+
# - high → zero: High energy can pause (containment, closure) - SHA as terminator
9671004
# - medium ↔ zero: Stabilized can pause or resume from pause
9681005
# - high ↔ high: High energy can chain directly
9691006
# - zero → medium: Gradual reactivation from silence (structurally coherent)
9701007
#
9711008
# Invalid: zero → high (violates structural continuity - cannot jump from pause
9721009
# to high energy without intermediate stabilization)
9731010
FREQUENCY_TRANSITIONS: dict[str, set[str]] = {
974-
"high": {"high", "medium"},
1011+
"high": {"high", "medium", "zero"}, # Allow high → zero for SHA termination (OZ → SHA valid)
9751012
"medium": {"high", "medium", "zero"},
9761013
"zero": {"medium"}, # Must transition through medium before high (structural coherence)
9771014
}
@@ -999,12 +1036,17 @@ def validate_frequency_transition(
9991036
-----
10001037
Structural frequency transitions follow TNFR canonical rules:
10011038
- High ↔ Medium: Bidirectional, natural energy exchange
1039+
- High → Zero: High energy can pause (containment, closure via SHA terminator)
10021040
- Medium ↔ Zero: Stabilization can pause, pause can resume
10031041
- High ↔ High: High energy operators can chain directly
10041042
- **Invalid**: Zero → High without Medium intermediary
10051043
1006-
This validation generates warnings (not errors) to maintain flexibility while
1007-
alerting users to potentially incoherent structural transitions.
1044+
Special case: OZ → SHA (dissonance → silence) is valid and represents
1045+
contained dissonance, postponed conflict, or preserved tension for later processing.
1046+
This is a canonical therapeutic and crisis management pattern.
1047+
1048+
This validation generates errors (not warnings) to enforce structural coherence
1049+
and prevent incoherent state transitions.
10081050
"""
10091051
# Get frequency levels for both operators
10101052
prev_freq = STRUCTURAL_FREQUENCIES.get(prev_operator)

0 commit comments

Comments
 (0)