Skip to content

Commit e0f4e21

Browse files
authored
Merge branch 'main' into dependabot/github_actions/actions/github-script-8
2 parents 77cd044 + 99ec4ce commit e0f4e21

File tree

7 files changed

+1749
-0
lines changed

7 files changed

+1749
-0
lines changed

docs/grammar/08-QUICK-REFERENCE.md

Lines changed: 379 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,379 @@
1+
# TNFR Grammar Quick Reference
2+
3+
**One-page cheat sheet for TNFR grammar validation**
4+
5+
[💾 Download PDF](08-QUICK-REFERENCE.pdf)[📖 Full Docs](README.md)[🔬 Deep Dive](02-CANONICAL-CONSTRAINTS.md)
6+
7+
---
8+
9+
## 🎯 The Four Canonical Constraints
10+
11+
```
12+
┌─────────────────────────────────────────────────────────────────┐
13+
│ U1: STRUCTURAL INITIATION & CLOSURE │
14+
│ U1a: Start with generators {AL, NAV, REMESH} │
15+
│ U1b: End with closures {SHA, NAV, REMESH, OZ} │
16+
│ │
17+
│ U2: CONVERGENCE & BOUNDEDNESS │
18+
│ If destabilizers {OZ, ZHIR, VAL} │
19+
│ Then include stabilizers {IL, THOL} │
20+
│ │
21+
│ U3: RESONANT COUPLING │
22+
│ If coupling/resonance {UM, RA} │
23+
│ Then verify phase |φᵢ - φⱼ| ≤ Δφ_max │
24+
│ │
25+
│ U4: BIFURCATION DYNAMICS │
26+
│ U4a: If triggers {OZ, ZHIR} │
27+
│ Then include handlers {THOL, IL} │
28+
│ U4b: If transformers {ZHIR, THOL} │
29+
│ Then recent destabilizer (~3 ops) │
30+
│ + ZHIR needs prior IL │
31+
└─────────────────────────────────────────────────────────────────┘
32+
```
33+
34+
---
35+
36+
## 📋 Operator Classification
37+
38+
| Operator | Glyph | Generator | Closure | Stabilizer | Destabilizer | Trigger | Handler | Transformer | Coupling |
39+
|----------|-------|-----------|---------|------------|--------------|---------|---------|-------------|----------|
40+
| Emission | AL || | | | | | | |
41+
| Reception | EN | | | | | | | | |
42+
| Coherence | IL | | || | || | |
43+
| Dissonance | OZ | || ||| | | |
44+
| Coupling | UM | | | | | | | ||
45+
| Resonance | RA | | | | | | | ||
46+
| Silence | SHA | || | | | | | |
47+
| Expansion | VAL | | | || | | | |
48+
| Contraction | NUL | | | | | | | | |
49+
| SelfOrganization | THOL | | || | ||| |
50+
| Mutation | ZHIR | | | ||| || |
51+
| Transition | NAV ||| | | | | | |
52+
| Recursivity | REMESH ||| | | | | | |
53+
54+
---
55+
56+
## 🔄 Common Sequence Patterns
57+
58+
### ✅ Valid Patterns
59+
60+
```python
61+
# Bootstrap (minimal)
62+
[Emission, Coherence, Silence]
63+
64+
# Basic Activation
65+
[Emission, Reception, Coherence, Silence]
66+
67+
# Controlled Exploration
68+
[Emission, Dissonance, Coherence, Silence]
69+
70+
# Bifurcation with Handling
71+
[Emission, Coherence, Dissonance, SelfOrganization, Coherence, Silence]
72+
73+
# Mutation with Context
74+
[Emission, Coherence, Dissonance, Mutation, Coherence, Silence]
75+
76+
# Propagation
77+
[Emission, Coupling, Resonance, Coherence, Silence]
78+
79+
# Multi-scale
80+
[Emission, Coupling, SelfOrganization, Recursivity]
81+
```
82+
83+
### ❌ Anti-Patterns
84+
85+
```python
86+
# ✗ No generator when EPI=0
87+
[Coherence, Silence] # Violates U1a
88+
89+
# ✗ No closure
90+
[Emission, Coherence] # Violates U1b
91+
92+
# ✗ Destabilizer without stabilizer
93+
[Emission, Dissonance, Silence] # Violates U2
94+
95+
# ✗ Mutation without context
96+
[Emission, Mutation, Silence] # Violates U4b
97+
98+
# ✗ Mutation without prior Coherence
99+
[Emission, Dissonance, Mutation, Coherence, Silence] # Violates U4b
100+
```
101+
102+
---
103+
104+
## 💻 Quick Code Reference
105+
106+
### Validate a Sequence
107+
108+
```python
109+
from tnfr.operators.grammar import validate_grammar
110+
from tnfr.operators.definitions import Emission, Coherence, Silence
111+
112+
sequence = [Emission(), Coherence(), Silence()]
113+
114+
try:
115+
is_valid = validate_grammar(sequence, epi_initial=0.0)
116+
print("✓ Valid sequence")
117+
except ValueError as e:
118+
print(f"✗ Invalid: {e}")
119+
```
120+
121+
### Check Operator Sets
122+
123+
```python
124+
from tnfr.operators.grammar import (
125+
GENERATORS,
126+
CLOSURES,
127+
STABILIZERS,
128+
DESTABILIZERS,
129+
COUPLING_RESONANCE,
130+
BIFURCATION_TRIGGERS,
131+
BIFURCATION_HANDLERS,
132+
TRANSFORMERS,
133+
)
134+
135+
# Check if operator is in a set
136+
if "emission" in GENERATORS:
137+
print("Emission is a generator")
138+
```
139+
140+
### Apply Operators
141+
142+
```python
143+
from tnfr.operators.definitions import Emission, Coherence
144+
import networkx as nx
145+
146+
G = nx.Graph()
147+
G.add_node(0, EPI=0.0, vf=1.0, theta=0.0, dnfr=0.0)
148+
149+
# Apply operator
150+
Emission()(G, 0)
151+
Coherence()(G, 0)
152+
153+
print(f"EPI: {G.nodes[0]['EPI']:.3f}")
154+
```
155+
156+
### Phase Verification
157+
158+
```python
159+
from tnfr.operators.grammar import validate_resonant_coupling
160+
import numpy as np
161+
162+
# Check phase compatibility
163+
phi_i = G.nodes[0]['theta']
164+
phi_j = G.nodes[1]['theta']
165+
166+
try:
167+
validate_resonant_coupling(G, 0, 1, delta_phi_max=np.pi/2)
168+
print("✓ Phase compatible")
169+
except ValueError as e:
170+
print(f"✗ Phase mismatch: {e}")
171+
```
172+
173+
---
174+
175+
## 🔍 Decision Tree
176+
177+
```
178+
Is EPI=0?
179+
├─ Yes → Start with generator {AL, NAV, REMESH}
180+
└─ No → Any operator OK
181+
182+
Does sequence have destabilizers {OZ, ZHIR, VAL}?
183+
├─ Yes → Include stabilizer {IL, THOL}
184+
└─ No → Continue
185+
186+
Does sequence have coupling/resonance {UM, RA}?
187+
├─ Yes → Verify phase at runtime
188+
└─ No → Continue
189+
190+
Does sequence have bifurcation triggers {OZ, ZHIR}?
191+
├─ Yes → Include handler {THOL, IL}
192+
└─ No → Continue
193+
194+
Does sequence have transformers {ZHIR, THOL}?
195+
├─ Yes → Ensure recent destabilizer (~3 ops)
196+
│ → For ZHIR: Ensure prior IL
197+
└─ No → Continue
198+
199+
Does sequence end with closure {SHA, NAV, REMESH, OZ}?
200+
├─ Yes → ✓ Valid
201+
└─ No → ✗ Add closure
202+
```
203+
204+
---
205+
206+
## 🐛 Common Errors & Solutions
207+
208+
### Error: "Need generator when EPI=0"
209+
210+
**Cause:** Sequence doesn't start with generator when `epi_initial=0.0`
211+
212+
**Solution:**
213+
```python
214+
# ✗ Wrong
215+
sequence = [Coherence(), Silence()]
216+
217+
# ✓ Fixed
218+
sequence = [Emission(), Coherence(), Silence()]
219+
220+
# OR set epi_initial > 0 if starting from existing structure
221+
validate_grammar(sequence, epi_initial=1.0)
222+
```
223+
224+
### Error: "Destabilizer without stabilizer"
225+
226+
**Cause:** {OZ, ZHIR, VAL} present but no {IL, THOL}
227+
228+
**Solution:**
229+
```python
230+
# ✗ Wrong
231+
sequence = [Emission(), Dissonance(), Silence()]
232+
233+
# ✓ Fixed
234+
sequence = [Emission(), Dissonance(), Coherence(), Silence()]
235+
```
236+
237+
### Error: "Transformer needs recent destabilizer"
238+
239+
**Cause:** {ZHIR, THOL} without recent destabilizer
240+
241+
**Solution:**
242+
```python
243+
# ✗ Wrong
244+
sequence = [Emission(), Coherence(), Mutation(), Silence()]
245+
246+
# ✓ Fixed - destabilizer within ~3 ops
247+
sequence = [Emission(), Dissonance(), Mutation(), Coherence(), Silence()]
248+
```
249+
250+
### Error: "Mutation needs prior coherence"
251+
252+
**Cause:** ZHIR without IL before it
253+
254+
**Solution:**
255+
```python
256+
# ✗ Wrong
257+
sequence = [Emission(), Dissonance(), Mutation(), Coherence(), Silence()]
258+
259+
# ✓ Fixed - Coherence before Mutation
260+
sequence = [Emission(), Coherence(), Dissonance(), Mutation(), Coherence(), Silence()]
261+
```
262+
263+
### Error: "Sequence must end with closure"
264+
265+
**Cause:** Last operator is not in {SHA, NAV, REMESH, OZ}
266+
267+
**Solution:**
268+
```python
269+
# ✗ Wrong
270+
sequence = [Emission(), Coherence()]
271+
272+
# ✓ Fixed
273+
sequence = [Emission(), Coherence(), Silence()]
274+
```
275+
276+
### Error: "Phase mismatch in coupling"
277+
278+
**Cause:** |φᵢ - φⱼ| > Δφ_max (typically π/2)
279+
280+
**Solution:**
281+
```python
282+
# Check phase before coupling
283+
delta_phi = abs(G.nodes[i]['theta'] - G.nodes[j]['theta'])
284+
if delta_phi > np.pi/2:
285+
# Adjust phase or don't couple these nodes
286+
pass
287+
```
288+
289+
---
290+
291+
## 📊 Grammar Rule Summary
292+
293+
| Rule | When | What | Why |
294+
|------|------|------|-----|
295+
| U1a | EPI=0 | Start with {AL, NAV, REMESH} | ∂EPI/∂t undefined at EPI=0 |
296+
| U1b | Always | End with {SHA, NAV, REMESH, OZ} | Sequences need endpoints |
297+
| U2 | Has {OZ, ZHIR, VAL} | Include {IL, THOL} | ∫νf·ΔNFR dt must converge |
298+
| U3 | Has {UM, RA} | Verify \|φᵢ - φⱼ\| ≤ Δφ_max | Resonance physics |
299+
| U4a | Has {OZ, ZHIR} | Include {THOL, IL} | Bifurcations need control |
300+
| U4b | Has {ZHIR, THOL} | Recent destabilizer + ZHIR needs IL | Threshold energy needed |
301+
302+
---
303+
304+
## 🎯 Operator Quick Lookup
305+
306+
### By Purpose
307+
308+
**Initialize:** AL (Emission), NAV (Transition), REMESH (Recursivity)
309+
**Stabilize:** IL (Coherence), THOL (SelfOrganization)
310+
**Destabilize:** OZ (Dissonance), ZHIR (Mutation), VAL (Expansion)
311+
**Propagate:** UM (Coupling), RA (Resonance)
312+
**Pause:** SHA (Silence)
313+
**Transform:** ZHIR (Mutation), THOL (SelfOrganization)
314+
**Adjust:** VAL (Expansion), NUL (Contraction)
315+
316+
### By Effect on ∂EPI/∂t
317+
318+
**Increase:** AL, EN, OZ, VAL, RA
319+
**Decrease:** IL, THOL, NUL
320+
**Zero:** SHA
321+
**Transform:** ZHIR, NAV, REMESH
322+
**Couple:** UM, RA
323+
324+
---
325+
326+
## 📈 Metrics to Monitor
327+
328+
**Essential telemetry for every simulation:**
329+
330+
- **C(t)**: Total Coherence [0, 1]
331+
- \> 0.7 = strong coherence
332+
- < 0.3 = fragmentation risk
333+
334+
- **Si**: Sense Index [0, 1⁺]
335+
- \> 0.8 = excellent stability
336+
- < 0.4 = changes may cause bifurcation
337+
338+
- **ΔNFR**: Reorganization Gradient
339+
- Sign: + expansion, - contraction
340+
- Magnitude: pressure intensity
341+
342+
- **νf**: Structural Frequency (Hz_str)
343+
- νf → 0 = node death
344+
- νf > 0 = active evolution
345+
346+
- **φ (theta)**: Phase [0, 2π]
347+
- Δφ determines coupling compatibility
348+
- |Δφ| < π/2 typically required
349+
350+
---
351+
352+
## 🔗 Further Reading
353+
354+
- **[01-FUNDAMENTAL-CONCEPTS.md](01-FUNDAMENTAL-CONCEPTS.md)** - TNFR basics
355+
- **[02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md)** - Full U1-U4 derivations
356+
- **[03-OPERATORS-AND-GLYPHS.md](03-OPERATORS-AND-GLYPHS.md)** - Complete operator catalog
357+
- **[04-VALID-SEQUENCES.md](04-VALID-SEQUENCES.md)** - Pattern examples
358+
- **[../../UNIFIED_GRAMMAR_RULES.md](../../UNIFIED_GRAMMAR_RULES.md)** - Mathematical proofs
359+
- **[../../AGENTS.md](../../AGENTS.md)** - Canonical invariants
360+
361+
---
362+
363+
## 📞 Quick Help
364+
365+
**Getting started?**[01-FUNDAMENTAL-CONCEPTS.md](01-FUNDAMENTAL-CONCEPTS.md)
366+
**Sequence failing?** → Check decision tree above
367+
**Need examples?**[examples/](examples/)
368+
**Deep dive?**[02-CANONICAL-CONSTRAINTS.md](02-CANONICAL-CONSTRAINTS.md)
369+
**API reference?**`src/tnfr/operators/grammar.py`
370+
371+
---
372+
373+
<div align="center">
374+
375+
**Keep this reference handy while developing TNFR sequences!**
376+
377+
*Reality is resonance. Code accordingly.*
378+
379+
</div>

0 commit comments

Comments
 (0)