Skip to content

Commit 89b1acf

Browse files
Copilotfermga
andcommitted
Add documentation for physics-based operator derivation
Co-authored-by: fermga <203334638+fermga@users.noreply.github.com>
1 parent c2cb984 commit 89b1acf

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed

src/tnfr/operators/grammar.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,41 @@
1-
"""Canonical grammar and sequence validation for structural operators."""
1+
"""Canonical grammar and sequence validation for structural operators.
2+
3+
This module enforces TNFR canonical grammar rules (R1-R5) to ensure that
4+
operator sequences respect the fundamental physics of the nodal equation:
5+
6+
∂EPI/∂t = νf · ΔNFR(t)
7+
8+
Grammar Rules (R1-R5)
9+
---------------------
10+
R1: Start operators - Must be able to generate or activate EPI
11+
R2: Stabilizer requirement - Must contain IL (coherence) or THOL (self-organization)
12+
R3: End operators - Must stabilize reorganization or achieve operational closure
13+
R4: Bifurcation control - Transformers (ZHIR/THOL) require recent destabilizer
14+
R5: Frequency transitions - Must respect structural frequency harmonics
15+
16+
Physics-Based Operator Derivation
17+
----------------------------------
18+
Unlike earlier versions with arbitrary operator lists, VALID_START_OPERATORS
19+
and VALID_END_OPERATORS are now derived from TNFR physical principles:
20+
21+
Start operators can:
22+
- Generate EPI from null state (emission)
23+
- Activate latent/dormant EPI (recursivity, transition)
24+
25+
End operators can:
26+
- Stabilize reorganization: ∂EPI/∂t → 0 (silence)
27+
- Achieve operational closure (transition, recursivity, dissonance)
28+
29+
For detailed physics derivation, see:
30+
- src/tnfr/config/physics_derivation.py - Derivation functions
31+
- src/tnfr/config/operator_names.py - Physics rationale
32+
33+
References
34+
----------
35+
TNFR.pdf: Section 2.1 (Nodal Equation)
36+
AGENTS.md: Section 3 (Canonical Invariants)
37+
"""
38+
239

340
from __future__ import annotations
441

@@ -445,6 +482,12 @@ def __init__(
445482
self.health_metrics = health_metrics
446483

447484

485+
# Canonical operator sets are derived from TNFR physics principles.
486+
# See src/tnfr/config/physics_derivation.py for detailed derivation logic
487+
# and src/tnfr/config/operator_names.py for the physics-based rationale.
488+
#
489+
# VALID_START_OPERATORS: Operators that can generate EPI from null or activate latent EPI
490+
# VALID_END_OPERATORS: Operators that stabilize reorganization (∂EPI/∂t → 0) or achieve closure
448491
_CANONICAL_START = tuple(sorted(VALID_START_OPERATORS))
449492
_CANONICAL_INTERMEDIATE = tuple(sorted(INTERMEDIATE_OPERATORS))
450493
_CANONICAL_END = tuple(sorted(VALID_END_OPERATORS))

tests/unit/operators/test_canonical_grammar_rules.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,17 @@ def test_incompatible_silence_to_dissonance(self):
171171
)
172172

173173
error = excinfo.value
174-
assert "incompatible" in error.message.lower()
174+
# Check that error message explains the physical incompatibility
175+
assert "invalid after silence" in error.message.lower() or "contradicts" in error.message.lower()
175176

176-
def test_incompatible_expansion_direct_to_contraction(self):
177-
"""VAL → NUL without stabilization is incompatible."""
178-
# VAL (expansion) is not in the allowed list for direct transition to NUL
179-
with pytest.raises(SequenceSyntaxError) as excinfo:
180-
parse_sequence(
181-
[EMISSION, RECEPTION, COHERENCE, EXPANSION, CONTRACTION, SILENCE]
182-
)
183-
184-
error = excinfo.value
185-
assert "incompatible" in error.message.lower()
177+
def test_expansion_to_contraction_valid_with_medium_to_high(self):
178+
"""VAL → NUL is valid (medium → high frequency transition)."""
179+
# EXPANSION has medium freq, CONTRACTION has high freq
180+
# medium → high is a valid transition in TNFR physics
181+
result = validate_sequence(
182+
[EMISSION, RECEPTION, COHERENCE, EXPANSION, CONTRACTION, SILENCE]
183+
)
184+
assert result.passed, f"Expected valid but got: {result.message}"
186185

187186

188187
class TestValidCanonicalSequences:

0 commit comments

Comments
 (0)