Skip to content

Commit ea989bf

Browse files
authored
Merge pull request #2806 from fermga/copilot/validate-sha-grammar-rules
SHA grammar validation: prohibit SHA→OZ and SHA→SHA, unlock 4 canonical variants
2 parents 1d9ee9e + 09cb77b commit ea989bf

File tree

4 files changed

+862
-3
lines changed

4 files changed

+862
-3
lines changed

src/tnfr/operators/canonical_patterns.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
"THEORY_SYSTEM",
3030
"FULL_DEPLOYMENT",
3131
"MOD_STABILIZER",
32+
# New variants unlocked by high → zero frequency transition
33+
"CONTAINED_CRISIS",
34+
"RESONANCE_PEAK_HOLD",
35+
"MINIMAL_COMPRESSION",
36+
"PHASE_LOCK",
3237
]
3338

3439

@@ -190,6 +195,114 @@ class CanonicalSequence(NamedTuple):
190195
)
191196

192197

198+
# ============================================================================
199+
# New Canonical Variants: Direct high → zero Termination
200+
# Unlocked by frequency transition update allowing high → zero for SHA
201+
# ============================================================================
202+
203+
CONTAINED_CRISIS = CanonicalSequence(
204+
name="contained_crisis",
205+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.OZ, Glyph.SHA],
206+
pattern_type=StructuralPattern.THERAPEUTIC,
207+
description=(
208+
"Direct crisis containment: dissonance immediately preserved without processing. "
209+
"OZ creates ΔNFR ↑ (tension, exploration), SHA immediately contains via νf → 0, "
210+
"preserving tension in suspended state for later resolution. This is the canonical "
211+
"'contained dissonance' pattern: trauma held safely, conflict postponed, tension "
212+
"preserved. Essential for trauma first response, emergency pause, and protective freeze "
213+
"when immediate processing would overwhelm the system."
214+
),
215+
use_cases=[
216+
"Trauma containment (immediate safety response without processing)",
217+
"Crisis management (pause before system overwhelm)",
218+
"Strategic hold (preserve tension for optimal timing)",
219+
"Protective freeze (contain instability temporarily)",
220+
"Emergency stop (halt exploration when risk detected)",
221+
],
222+
domain="therapeutic",
223+
references=(
224+
"SHA Grammar Validation Issue: OZ → SHA as valid therapeutic pattern. "
225+
"Frequency transition update: high → zero for containment/termination."
226+
),
227+
)
228+
229+
RESONANCE_PEAK_HOLD = CanonicalSequence(
230+
name="resonance_peak_hold",
231+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.RA, Glyph.SHA],
232+
pattern_type=StructuralPattern.RESONATE,
233+
description=(
234+
"Peak state preservation: amplified resonance frozen at maximum coherence. "
235+
"RA amplifies network coherence (high C(t), increased νf), SHA suspends dynamics "
236+
"(νf → 0) while preserving peak state, creating 'resonance memory'. Used for "
237+
"flow state capture, optimal pattern preservation, and network snapshots. The "
238+
"amplified coherence is held in latent form for later reactivation without decay."
239+
),
240+
use_cases=[
241+
"Flow state preservation (hold peak performance)",
242+
"Peak coherence memory (capture optimal synchronization)",
243+
"Network snapshot (freeze synchronized state)",
244+
"Resonance consolidation (lock amplified pattern)",
245+
"Optimal moment capture (preserve heightened state)",
246+
],
247+
domain="cognitive",
248+
references=(
249+
"Frequency transition update: high → zero enables direct RA → SHA termination. "
250+
"Memory consolidation pattern for peak states."
251+
),
252+
)
253+
254+
MINIMAL_COMPRESSION = CanonicalSequence(
255+
name="minimal_compression",
256+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.NUL, Glyph.SHA],
257+
pattern_type=StructuralPattern.COMPRESS,
258+
description=(
259+
"Compressed latency: structure reduced to essential form and preserved. "
260+
"NUL concentrates EPI to core (contraction, high νf), SHA immediately freezes "
261+
"minimal form (νf → 0), creating efficient storage. Distills pattern to fundamentals "
262+
"then preserves in latent state. Used for information compression, core essence "
263+
"extraction, and efficient memory storage of essential structure only."
264+
),
265+
use_cases=[
266+
"Information compression (minimal viable form)",
267+
"Core essence extraction (distill to fundamentals)",
268+
"Efficient storage (compact representation)",
269+
"Essential pattern hold (preserve only critical structure)",
270+
"Minimal memory (reduce before suspend)",
271+
],
272+
domain="cognitive",
273+
references=(
274+
"Frequency transition update: high → zero enables direct NUL → SHA termination. "
275+
"Compression-then-freeze pattern for efficient storage."
276+
),
277+
)
278+
279+
PHASE_LOCK = CanonicalSequence(
280+
name="phase_lock",
281+
glyphs=[Glyph.AL, Glyph.EN, Glyph.IL, Glyph.OZ, Glyph.ZHIR, Glyph.SHA],
282+
pattern_type=StructuralPattern.BIFURCATED,
283+
description=(
284+
"Phase transition hold: mutation immediately locked without stabilization. "
285+
"OZ creates bifurcation threshold (ΔNFR ↑), ZHIR pivots phase θ (high νf), "
286+
"SHA immediately locks new phase (νf → 0) before potential regression. Preserves "
287+
"transformed state in latent form, preventing return to previous configuration. "
288+
"Used for identity consolidation, paradigm shift memory, and transformation lock. "
289+
"Simpler than full ZHIR → IL → SHA when immediate preservation desired."
290+
),
291+
use_cases=[
292+
"Identity shift hold (lock new configuration)",
293+
"Phase memory (preserve transformed state)",
294+
"Mutation consolidation (hold before integration)",
295+
"Paradigm capture (freeze new perspective)",
296+
"Transformation lock (prevent regression)",
297+
],
298+
domain="cognitive",
299+
references=(
300+
"Frequency transition update: high → zero enables direct ZHIR → SHA termination. "
301+
"Immediate phase lock pattern without intermediate stabilization."
302+
),
303+
)
304+
305+
193306
# ============================================================================
194307
# MOD_STABILIZER: Reusable Glyphic Macro
195308
# ============================================================================
@@ -231,6 +344,11 @@ class CanonicalSequence(NamedTuple):
231344
THEORY_SYSTEM,
232345
FULL_DEPLOYMENT,
233346
MOD_STABILIZER,
347+
# New variants unlocked by high → zero frequency transition
348+
CONTAINED_CRISIS,
349+
RESONANCE_PEAK_HOLD,
350+
MINIMAL_COMPRESSION,
351+
PHASE_LOCK,
234352
]
235353
}
236354
"""Registry of all canonical operator sequences.

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)