Skip to content

Commit 3a3333d

Browse files
Copilotfermga
andcommitted
Add executable grammar examples demonstrating U1-U4 constraints
Co-authored-by: fermga <203334638+fermga@users.noreply.github.com>
1 parent 018224f commit 3a3333d

File tree

3 files changed

+501
-0
lines changed

3 files changed

+501
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env python
2+
"""
3+
Grammar Example 01: Basic Bootstrap Pattern
4+
5+
Demonstrates U1a (Initiation) and U1b (Closure) constraints.
6+
7+
This is the simplest valid TNFR sequence - a basic bootstrap pattern that:
8+
1. Starts with a generator (U1a)
9+
2. Stabilizes the structure
10+
3. Ends with a closure (U1b)
11+
12+
Pattern: [Generator → Stabilizer → Closure]
13+
Health: Excellent (minimal, focused, complete)
14+
"""
15+
16+
from tnfr.operators.definitions import (
17+
Emission, # Generator (U1a)
18+
Coherence, # Stabilizer
19+
Silence, # Closure (U1b)
20+
)
21+
from tnfr.operators.grammar import validate_grammar
22+
import networkx as nx
23+
24+
print("="*70)
25+
print(" " * 15 + "Grammar Example 01: Basic Bootstrap")
26+
print("="*70)
27+
print()
28+
29+
# ============================================================================
30+
# Example 1: Valid Bootstrap from EPI=0
31+
# ============================================================================
32+
33+
print("Example 1: Valid Bootstrap (Starting from EPI=0)")
34+
print("-" * 70)
35+
36+
sequence_1 = [
37+
Emission(), # U1a: Generator (creates EPI from vacuum)
38+
Coherence(), # Stabilizes the new structure
39+
Silence() # U1b: Closure (freezes evolution)
40+
]
41+
42+
print("Sequence: Emission → Coherence → Silence")
43+
print()
44+
print("Why this works:")
45+
print(" ✓ U1a: Emission is a generator (can create from EPI=0)")
46+
print(" ✓ U1b: Silence is a closure (provides terminal endpoint)")
47+
print(" ✓ Coherence stabilizes without needing U2 (no destabilizers)")
48+
print()
49+
50+
try:
51+
is_valid = validate_grammar(sequence_1, epi_initial=0.0)
52+
print(f"Validation: {'✓ PASS' if is_valid else '✗ FAIL'}")
53+
print()
54+
except ValueError as e:
55+
print(f"Validation: ✗ FAIL - {e}")
56+
print()
57+
58+
# ============================================================================
59+
# Example 2: Invalid - No Generator
60+
# ============================================================================
61+
62+
print("Example 2: Invalid Bootstrap (No generator when EPI=0)")
63+
print("-" * 70)
64+
65+
sequence_2 = [
66+
Coherence(), # NOT a generator!
67+
Silence()
68+
]
69+
70+
print("Sequence: Coherence → Silence")
71+
print()
72+
print("Why this fails:")
73+
print(" ✗ U1a violation: Coherence is NOT a generator")
74+
print(" ✗ Cannot evolve from EPI=0 without generator")
75+
print(" ✗ ∂EPI/∂t undefined at EPI=0")
76+
print()
77+
78+
try:
79+
is_valid = validate_grammar(sequence_2, epi_initial=0.0)
80+
print(f"Validation: {'✓ PASS' if is_valid else '✗ FAIL'}")
81+
except ValueError as e:
82+
print(f"Validation: ✗ FAIL - {e}")
83+
print()
84+
85+
# ============================================================================
86+
# Example 3: Valid - Starting from EPI>0
87+
# ============================================================================
88+
89+
print("Example 3: Valid Bootstrap (Starting from existing EPI)")
90+
print("-" * 70)
91+
92+
sequence_3 = [
93+
Coherence(), # No generator needed when EPI>0
94+
Silence() # Closure
95+
]
96+
97+
print("Sequence: Coherence → Silence")
98+
print()
99+
print("Why this works:")
100+
print(" ✓ U1a: No generator needed when epi_initial > 0")
101+
print(" ✓ U1b: Silence is a closure")
102+
print(" ✓ Can operate on existing structure without creation")
103+
print()
104+
105+
try:
106+
is_valid = validate_grammar(sequence_3, epi_initial=1.0) # EPI > 0!
107+
print(f"Validation: {'✓ PASS' if is_valid else '✗ FAIL'}")
108+
except ValueError as e:
109+
print(f"Validation: ✗ FAIL - {e}")
110+
print()
111+
112+
# ============================================================================
113+
# Summary
114+
# ============================================================================
115+
116+
print("="*70)
117+
print(" " * 25 + "Summary")
118+
print("="*70)
119+
print()
120+
print("Key Lessons:")
121+
print()
122+
print("1. U1a (Initiation):")
123+
print(" • When EPI=0, MUST start with generator {Emission, Transition, Recursivity}")
124+
print(" • Generators create structure from null/dormant states")
125+
print(" • When EPI>0, no generator needed")
126+
print()
127+
print("2. U1b (Closure):")
128+
print(" • All sequences MUST end with closure {Silence, Transition, Recursivity, Dissonance}")
129+
print(" • Closures provide coherent endpoints")
130+
print(" • Like action potentials need repolarization")
131+
print()
132+
print("3. Bootstrap Pattern:")
133+
print(" • Simplest valid pattern: Generator → Stabilizer → Closure")
134+
print(" • Creates structure, stabilizes it, provides endpoint")
135+
print(" • Foundation for more complex sequences")
136+
print()
137+
print("Next: See 02-intermediate-exploration.py for U2 (Convergence)")
138+
print()
139+
print("="*70)
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#!/usr/bin/env python
2+
"""
3+
Grammar Example 02: Intermediate Exploration
4+
5+
Demonstrates U2 (Convergence & Boundedness) constraint.
6+
7+
This example shows controlled destabilization with stabilization:
8+
1. Destabilizers increase |ΔNFR|
9+
2. Must include stabilizers to prevent divergence
10+
3. ∫νf·ΔNFR dt must converge
11+
12+
Pattern: [Generator → Destabilizer → Stabilizer → Closure]
13+
Health: Good (balanced feedback)
14+
"""
15+
16+
from tnfr.operators.definitions import (
17+
Emission, # Generator (U1a)
18+
Dissonance, # Destabilizer (U2)
19+
Coherence, # Stabilizer (U2)
20+
Silence, # Closure (U1b)
21+
Expansion, # Destabilizer (U2)
22+
)
23+
from tnfr.operators.grammar import validate_grammar
24+
25+
print("="*70)
26+
print(" " * 10 + "Grammar Example 02: Intermediate Exploration")
27+
print("="*70)
28+
print()
29+
30+
# ============================================================================
31+
# Example 1: Valid Exploration with Destabilizer + Stabilizer
32+
# ============================================================================
33+
34+
print("Example 1: Valid Exploration (Dissonance + Coherence)")
35+
print("-" * 70)
36+
37+
sequence_1 = [
38+
Emission(), # Generator (U1a)
39+
Dissonance(), # Destabilizer - increases |ΔNFR|
40+
Coherence(), # Stabilizer - prevents divergence (U2)
41+
Silence() # Closure (U1b)
42+
]
43+
44+
print("Sequence: Emission → Dissonance → Coherence → Silence")
45+
print()
46+
print("Why this works:")
47+
print(" ✓ U1a: Emission is generator")
48+
print(" ✓ U2: Dissonance (destabilizer) + Coherence (stabilizer)")
49+
print(" ✓ U1b: Silence is closure")
50+
print()
51+
print("Physics:")
52+
print(" • Dissonance increases |ΔNFR| (positive feedback)")
53+
print(" • Without Coherence: ∫νf·ΔNFR dt → ∞ (divergence)")
54+
print(" • With Coherence: integral converges (bounded evolution)")
55+
print()
56+
57+
try:
58+
is_valid = validate_grammar(sequence_1, epi_initial=0.0)
59+
print(f"Validation: {'✓ PASS' if is_valid else '✗ FAIL'}")
60+
except ValueError as e:
61+
print(f"Validation: ✗ FAIL - {e}")
62+
print()
63+
64+
# ============================================================================
65+
# Example 2: Invalid - Destabilizer without Stabilizer
66+
# ============================================================================
67+
68+
print("Example 2: Invalid Exploration (Destabilizer without stabilizer)")
69+
print("-" * 70)
70+
71+
sequence_2 = [
72+
Emission(),
73+
Dissonance(), # Destabilizer
74+
Silence() # No stabilizer!
75+
]
76+
77+
print("Sequence: Emission → Dissonance → Silence")
78+
print()
79+
print("Why this fails:")
80+
print(" ✗ U2 violation: Destabilizer without stabilizer")
81+
print(" ✗ |ΔNFR| grows unbounded (exponential)")
82+
print(" ✗ ∫νf·ΔNFR dt diverges → fragmentation")
83+
print()
84+
print("Physics failure:")
85+
print(" dΔNFR/dt > 0 always (only positive feedback)")
86+
print(" → ΔNFR(t) ~ e^(λt)")
87+
print(" → System loses coherence")
88+
print()
89+
90+
try:
91+
is_valid = validate_grammar(sequence_2, epi_initial=0.0)
92+
print(f"Validation: {'✓ PASS' if is_valid else '✗ FAIL'}")
93+
except ValueError as e:
94+
print(f"Validation: ✗ FAIL - {e}")
95+
print()
96+
97+
# ============================================================================
98+
# Example 3: Multiple Destabilizers
99+
# ============================================================================
100+
101+
print("Example 3: Multiple Destabilizers (still need ONE stabilizer)")
102+
print("-" * 70)
103+
104+
sequence_3 = [
105+
Emission(),
106+
Dissonance(), # Destabilizer 1
107+
Expansion(), # Destabilizer 2
108+
Coherence(), # Stabilizer (covers both)
109+
Silence()
110+
]
111+
112+
print("Sequence: Emission → Dissonance → Expansion → Coherence → Silence")
113+
print()
114+
print("Why this works:")
115+
print(" ✓ Multiple destabilizers allowed")
116+
print(" ✓ One stabilizer can handle multiple destabilizers")
117+
print(" ✓ Coherence provides sufficient negative feedback")
118+
print()
119+
print("Physics:")
120+
print(" • Both Dissonance and Expansion increase |ΔNFR|")
121+
print(" • Cumulative positive feedback")
122+
print(" • Coherence stabilizes entire accumulated gradient")
123+
print()
124+
125+
try:
126+
is_valid = validate_grammar(sequence_3, epi_initial=0.0)
127+
print(f"Validation: {'✓ PASS' if is_valid else '✗ FAIL'}")
128+
except ValueError as e:
129+
print(f"Validation: ✗ FAIL - {e}")
130+
print()
131+
132+
# ============================================================================
133+
# Summary
134+
# ============================================================================
135+
136+
print("="*70)
137+
print(" " * 25 + "Summary")
138+
print("="*70)
139+
print()
140+
print("Key Lessons:")
141+
print()
142+
print("1. U2 (Convergence & Boundedness):")
143+
print(" • Destabilizers {Dissonance, Mutation, Expansion} increase |ΔNFR|")
144+
print(" • Must include stabilizers {Coherence, SelfOrganization}")
145+
print(" • Without stabilizers: ∫νf·ΔNFR dt → ∞ (divergence)")
146+
print()
147+
print("2. Destabilizers:")
148+
print(" • Dissonance (OZ): Strong positive feedback")
149+
print(" • Mutation (ZHIR): Phase transformation")
150+
print(" • Expansion (VAL): Increases dimensionality")
151+
print()
152+
print("3. Stabilizers:")
153+
print(" • Coherence (IL): Direct negative feedback")
154+
print(" • SelfOrganization (THOL): Emergent self-limiting")
155+
print()
156+
print("4. Exploration Pattern:")
157+
print(" • Generator → Destabilizer(s) → Stabilizer → Closure")
158+
print(" • Controlled instability with recovery")
159+
print(" • Enables adaptation while maintaining coherence")
160+
print()
161+
print("Next: See 03-advanced-bifurcation.py for U4 (Bifurcation)")
162+
print()
163+
print("="*70)

0 commit comments

Comments
 (0)