|
| 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