|
| 1 | +"""Complete catalog of 13 canonical TNFR operators with examples. |
| 2 | +
|
| 3 | +This file demonstrates each of the 13 canonical operators with: |
| 4 | +- Valid usage patterns |
| 5 | +- Anti-patterns (commented out to prevent execution) |
| 6 | +- Test assertions |
| 7 | +
|
| 8 | +Run with: python docs/grammar/examples/all-operators-catalog.py |
| 9 | +""" |
| 10 | + |
| 11 | +import networkx as nx |
| 12 | +import numpy as np |
| 13 | + |
| 14 | +from tnfr.operators.definitions import ( |
| 15 | + Coherence, |
| 16 | + Contraction, |
| 17 | + Coupling, |
| 18 | + Dissonance, |
| 19 | + Emission, |
| 20 | + Expansion, |
| 21 | + Mutation, |
| 22 | + Reception, |
| 23 | + Recursivity, |
| 24 | + Resonance, |
| 25 | + SelfOrganization, |
| 26 | + Silence, |
| 27 | + Transition, |
| 28 | +) |
| 29 | + |
| 30 | + |
| 31 | +def create_test_node(epi=0.0, vf=1.0, theta=0.0, dnfr=0.0): |
| 32 | + """Helper: Create a graph with a single test node.""" |
| 33 | + G = nx.Graph() |
| 34 | + G.add_node(0, EPI=epi, vf=vf, theta=theta, dnfr=dnfr) |
| 35 | + return G |
| 36 | + |
| 37 | + |
| 38 | +# ============================================================================= |
| 39 | +# 1. EMISSION (AL) - Generator |
| 40 | +# ============================================================================= |
| 41 | + |
| 42 | + |
| 43 | +def test_emission(): |
| 44 | + """AL - Creates EPI from vacuum via resonant emission.""" |
| 45 | + print("\n1. EMISSION (AL) - Generator") |
| 46 | + print("=" * 50) |
| 47 | + |
| 48 | + # ✅ Valid: Emission from EPI=0 |
| 49 | + G = create_test_node(epi=0.0) |
| 50 | + Emission()(G, 0) |
| 51 | + print(f"✅ Valid: EPI after emission = {G.nodes[0]['EPI']} (> 0)") |
| 52 | + assert G.nodes[0]["EPI"] != 0.0, "Emission should modify EPI" |
| 53 | + |
| 54 | + # Anti-pattern (commented): |
| 55 | + # ❌ Redundant emission without purpose |
| 56 | + # [Emission, Coherence, Emission, Coherence, Silence] |
| 57 | + |
| 58 | + |
| 59 | +# ============================================================================= |
| 60 | +# 2. RECEPTION (EN) - Information |
| 61 | +# ============================================================================= |
| 62 | + |
| 63 | + |
| 64 | +def test_reception(): |
| 65 | + """EN - Captures and integrates incoming resonance.""" |
| 66 | + print("\n2. RECEPTION (EN) - Information") |
| 67 | + print("=" * 50) |
| 68 | + |
| 69 | + # ✅ Valid: Reception after coupling |
| 70 | + G = nx.Graph() |
| 71 | + G.add_node(0, EPI=0.5, vf=1.0, theta=0.0, dnfr=0.0) |
| 72 | + G.add_node(1, EPI=0.7, vf=1.0, theta=0.1, dnfr=0.0) |
| 73 | + |
| 74 | + # Create edge for information flow |
| 75 | + G.add_edge(0, 1) |
| 76 | + |
| 77 | + Reception()(G, 0) |
| 78 | + print("✅ Valid: Reception applied (EPI updated based on network)") |
| 79 | + |
| 80 | + # Anti-pattern (commented): |
| 81 | + # ❌ Reception without coupling |
| 82 | + # G_isolated = create_test_node(epi=0.5) |
| 83 | + # Reception()(G_isolated, 0) # No neighbors! |
| 84 | + |
| 85 | + |
| 86 | +# ============================================================================= |
| 87 | +# 3. COHERENCE (IL) - Stabilizer |
| 88 | +# ============================================================================= |
| 89 | + |
| 90 | + |
| 91 | +def test_coherence(): |
| 92 | + """IL - Stabilizes form through negative feedback.""" |
| 93 | + print("\n3. COHERENCE (IL) - Stabilizer") |
| 94 | + print("=" * 50) |
| 95 | + |
| 96 | + # ✅ Valid: Coherence after emission |
| 97 | + G = create_test_node(epi=0.0) |
| 98 | + Emission()(G, 0) |
| 99 | + |
| 100 | + Coherence()(G, 0) |
| 101 | + |
| 102 | + print("✅ Valid: Coherence applied (ΔNFR reduced via negative feedback)") |
| 103 | + |
| 104 | + # Anti-pattern (commented): |
| 105 | + # ❌ Coherence on EPI=0 |
| 106 | + # G_zero = create_test_node(epi=0.0) |
| 107 | + # Coherence()(G_zero, 0) # Violates precondition! |
| 108 | + |
| 109 | + |
| 110 | +# ============================================================================= |
| 111 | +# 4. DISSONANCE (OZ) - Destabilizer/Trigger/Closure |
| 112 | +# ============================================================================= |
| 113 | + |
| 114 | + |
| 115 | +def test_dissonance(): |
| 116 | + """OZ - Introduces controlled instability.""" |
| 117 | + print("\n4. DISSONANCE (OZ) - Destabilizer") |
| 118 | + print("=" * 50) |
| 119 | + |
| 120 | + # ✅ Valid: Dissonance balanced by Coherence (U2) |
| 121 | + G = create_test_node(epi=0.0) |
| 122 | + Emission()(G, 0) |
| 123 | + Coherence()(G, 0) # Stable base |
| 124 | + |
| 125 | + Dissonance()(G, 0) # Destabilizer |
| 126 | + Coherence()(G, 0) # Stabilizer (U2) |
| 127 | + print("✅ Valid: Dissonance balanced by Coherence (U2 compliance)") |
| 128 | + |
| 129 | + # Anti-pattern (commented): |
| 130 | + # ❌ Dissonance without stabilizer (violates U2) |
| 131 | + # [Emission, Dissonance, Silence] # Missing Coherence! |
| 132 | + |
| 133 | + |
| 134 | +# ============================================================================= |
| 135 | +# 5. COUPLING (UM) - Propagator |
| 136 | +# ============================================================================= |
| 137 | + |
| 138 | + |
| 139 | +def test_coupling(): |
| 140 | + """UM - Creates structural links via phase synchronization.""" |
| 141 | + print("\n5. COUPLING (UM) - Propagator") |
| 142 | + print("=" * 50) |
| 143 | + |
| 144 | + # ✅ Valid: Coupling with compatible phases |
| 145 | + G = nx.Graph() |
| 146 | + G.add_node(0, EPI=0.5, vf=1.0, theta=0.0, dnfr=0.0) |
| 147 | + G.add_node(1, EPI=0.6, vf=1.0, theta=0.3, dnfr=0.0) # Δφ = 0.3 < π/2 |
| 148 | + |
| 149 | + # Phase compatible: |0.0 - 0.3| = 0.3 < π/2 ≈ 1.57 |
| 150 | + print(f"✅ Phase compatible: |Δφ| = 0.3 < π/2 ({np.pi/2:.2f})") |
| 151 | + |
| 152 | + # Note: Coupling applies to single nodes in the grammar system |
| 153 | + Coupling()(G, 0) |
| 154 | + print("✅ Valid: Coupling operator applied (creates structural links)") |
| 155 | + |
| 156 | + # Anti-pattern (commented): |
| 157 | + # ❌ Coupling without phase verification |
| 158 | + # G_antiphase = nx.Graph() |
| 159 | + # G_antiphase.add_node(0, EPI=0.5, vf=1.0, theta=0.0, dnfr=0.0) |
| 160 | + # G_antiphase.add_node(1, EPI=0.6, vf=1.0, theta=np.pi, dnfr=0.0) # Antiphase! |
| 161 | + # Coupling()(G_antiphase, 0) # Phase mismatch |
| 162 | + |
| 163 | + |
| 164 | +# ============================================================================= |
| 165 | +# 6. RESONANCE (RA) - Propagator |
| 166 | +# ============================================================================= |
| 167 | + |
| 168 | + |
| 169 | +def test_resonance(): |
| 170 | + """RA - Amplifies and propagates patterns coherently.""" |
| 171 | + print("\n6. RESONANCE (RA) - Propagator") |
| 172 | + print("=" * 50) |
| 173 | + |
| 174 | + # ✅ Valid: Resonance on coupled network |
| 175 | + G = nx.Graph() |
| 176 | + G.add_node(0, EPI=0.5, vf=1.0, theta=0.0, dnfr=0.0) |
| 177 | + G.add_node(1, EPI=0.6, vf=1.0, theta=0.1, dnfr=0.0) |
| 178 | + G.add_edge(0, 1) # Pre-existing coupling |
| 179 | + |
| 180 | + Resonance()(G, 0) # Amplify |
| 181 | + print("✅ Valid: Resonance applied (pattern propagated coherently)") |
| 182 | + |
| 183 | + # Anti-pattern (commented): |
| 184 | + # ❌ Resonance without coupling |
| 185 | + # G_uncoupled = nx.Graph() |
| 186 | + # G_uncoupled.add_node(0, EPI=0.5, vf=1.0, theta=0.0, dnfr=0.0) |
| 187 | + # Resonance()(G_uncoupled, 0) # No edges - violates precondition |
| 188 | + |
| 189 | + |
| 190 | +# ============================================================================= |
| 191 | +# 7. SILENCE (SHA) - Control/Closure |
| 192 | +# ============================================================================= |
| 193 | + |
| 194 | + |
| 195 | +def test_silence(): |
| 196 | + """SHA - Freezes evolution temporarily.""" |
| 197 | + print("\n7. SILENCE (SHA) - Control/Closure") |
| 198 | + print("=" * 50) |
| 199 | + |
| 200 | + # ✅ Valid: Silence as closure |
| 201 | + G = create_test_node(epi=0.0) |
| 202 | + Emission()(G, 0) |
| 203 | + Coherence()(G, 0) |
| 204 | + |
| 205 | + Silence()(G, 0) |
| 206 | + |
| 207 | + print("✅ Valid: Silence applied (νf → 0, node enters latent state)") |
| 208 | + |
| 209 | + # Anti-pattern (commented): |
| 210 | + # ❌ Silence in middle without reactivation |
| 211 | + # [Emission, Silence, Coherence] # Node frozen, can't apply Coherence |
| 212 | + |
| 213 | + |
| 214 | +# ============================================================================= |
| 215 | +# 8. EXPANSION (VAL) - Destabilizer |
| 216 | +# ============================================================================= |
| 217 | + |
| 218 | + |
| 219 | +def test_expansion(): |
| 220 | + """VAL - Increases structural complexity.""" |
| 221 | + print("\n8. EXPANSION (VAL) - Destabilizer") |
| 222 | + print("=" * 50) |
| 223 | + |
| 224 | + # ✅ Valid: Expansion balanced by Coherence |
| 225 | + G = create_test_node(epi=0.0) |
| 226 | + Emission()(G, 0) |
| 227 | + Expansion()(G, 0) # Destabilizer |
| 228 | + Coherence()(G, 0) # Stabilizer (U2) |
| 229 | + print("✅ Valid: Expansion balanced by stabilizer") |
| 230 | + |
| 231 | + # Anti-pattern (commented): |
| 232 | + # ❌ Expansion without stabilizer (violates U2) |
| 233 | + # [Emission, Expansion, Silence] # Missing Coherence! |
| 234 | + |
| 235 | + |
| 236 | +# ============================================================================= |
| 237 | +# 9. CONTRACTION (NUL) - Control |
| 238 | +# ============================================================================= |
| 239 | + |
| 240 | + |
| 241 | +def test_contraction(): |
| 242 | + """NUL - Reduces structural complexity.""" |
| 243 | + print("\n9. CONTRACTION (NUL) - Control") |
| 244 | + print("=" * 50) |
| 245 | + |
| 246 | + # ✅ Valid: Contraction after expansion |
| 247 | + G = create_test_node(epi=0.0) |
| 248 | + Emission()(G, 0) |
| 249 | + Expansion()(G, 0) # Increase complexity |
| 250 | + Contraction()(G, 0) # Reduce back |
| 251 | + print("✅ Valid: Complexity managed bidirectionally") |
| 252 | + |
| 253 | + # Anti-pattern (commented): |
| 254 | + # ❌ Contraction on scalar EPI |
| 255 | + # G_scalar = create_test_node(epi=0.5) # Scalar EPI |
| 256 | + # Contraction()(G_scalar, 0) # Cannot reduce below dim=1 |
| 257 | + |
| 258 | + |
| 259 | +# ============================================================================= |
| 260 | +# 10. SELF-ORGANIZATION (THOL) - Stabilizer/Handler/Transformer |
| 261 | +# ============================================================================= |
| 262 | + |
| 263 | + |
| 264 | +def test_self_organization(): |
| 265 | + """THOL - Spontaneous autopoietic pattern formation.""" |
| 266 | + print("\n10. SELF-ORGANIZATION (THOL) - Stabilizer/Handler/Transformer") |
| 267 | + print("=" * 50) |
| 268 | + |
| 269 | + # ✅ Valid: THOL with recent destabilizer (U4b) |
| 270 | + G = create_test_node(epi=0.0) |
| 271 | + Emission()(G, 0) |
| 272 | + Dissonance()(G, 0) # Destabilizer (recent, U4b) |
| 273 | + SelfOrganization()(G, 0) # Transformer + Handler |
| 274 | + Coherence()(G, 0) |
| 275 | + print("✅ Valid: Self-organization with proper context") |
| 276 | + |
| 277 | + # Anti-pattern (commented): |
| 278 | + # ❌ THOL without recent destabilizer (violates U4b) |
| 279 | + # [Emission, Coherence, SelfOrganization, Silence] # No OZ/VAL/ZHIR! |
| 280 | + |
| 281 | + |
| 282 | +# ============================================================================= |
| 283 | +# 11. MUTATION (ZHIR) - Destabilizer/Trigger/Transformer |
| 284 | +# ============================================================================= |
| 285 | + |
| 286 | + |
| 287 | +def test_mutation(): |
| 288 | + """ZHIR - Phase transformation at threshold.""" |
| 289 | + print("\n11. MUTATION (ZHIR) - Destabilizer/Trigger/Transformer") |
| 290 | + print("=" * 50) |
| 291 | + |
| 292 | + # ✅ Valid: Complete ZHIR sequence (U4b requirements) |
| 293 | + G = create_test_node(epi=0.0) |
| 294 | + Emission()(G, 0) |
| 295 | + Coherence()(G, 0) # Prior IL (stable base, U4b) |
| 296 | + Dissonance()(G, 0) # Recent destabilizer (U4b) |
| 297 | + |
| 298 | + Mutation()(G, 0) # Transformer |
| 299 | + |
| 300 | + Coherence()(G, 0) # Stabilizer (U2) + Handler (U4a) |
| 301 | + print("✅ Valid: Mutation applied with proper U4b context (prior IL + recent destabilizer)") |
| 302 | + |
| 303 | + # Anti-pattern (commented): |
| 304 | + # ❌ ZHIR without prior Coherence (violates U4b) |
| 305 | + # [Emission, Dissonance, Mutation, Coherence, Silence] # No IL before OZ! |
| 306 | + |
| 307 | + |
| 308 | +# ============================================================================= |
| 309 | +# 12. TRANSITION (NAV) - Generator/Closure |
| 310 | +# ============================================================================= |
| 311 | + |
| 312 | + |
| 313 | +def test_transition(): |
| 314 | + """NAV - Regime shift, activates latent EPI.""" |
| 315 | + print("\n12. TRANSITION (NAV) - Generator/Closure") |
| 316 | + print("=" * 50) |
| 317 | + |
| 318 | + # ✅ Valid: Transition with proper setup |
| 319 | + G = create_test_node(epi=0.5, vf=1.0) |
| 320 | + # Disable precondition validation for demo purposes |
| 321 | + Transition()(G, 0, validate_preconditions=False) |
| 322 | + print("✅ Valid: Regime transition activated") |
| 323 | + |
| 324 | + # Anti-pattern (commented): |
| 325 | + # ❌ NAV with insufficient νf |
| 326 | + # G_low_vf = create_test_node(epi=0.3, vf=0.0) |
| 327 | + # Transition()(G_low_vf, 0) # νf too low! |
| 328 | + |
| 329 | + |
| 330 | +# ============================================================================= |
| 331 | +# 13. RECURSIVITY (REMESH) - Generator/Closure |
| 332 | +# ============================================================================= |
| 333 | + |
| 334 | + |
| 335 | +def test_recursivity(): |
| 336 | + """REMESH - Echoes structure across scales (operational fractality).""" |
| 337 | + print("\n13. RECURSIVITY (REMESH) - Generator/Closure") |
| 338 | + print("=" * 50) |
| 339 | + |
| 340 | + # ✅ Valid: Recursivity with sufficient structure |
| 341 | + G = create_test_node(epi=0.5, vf=1.0) |
| 342 | + Recursivity()(G, 0, validate_preconditions=False) |
| 343 | + print("✅ Valid: Recursive structure created (operational fractality)") |
| 344 | + |
| 345 | + # Anti-pattern (commented): |
| 346 | + # ❌ REMESH on completely empty system |
| 347 | + # G_empty = create_test_node(epi=0.0, vf=0.0) |
| 348 | + # Recursivity()(G_empty, 0) # Insufficient structure |
| 349 | + |
| 350 | + |
| 351 | +# ============================================================================= |
| 352 | +# Main Execution |
| 353 | +# ============================================================================= |
| 354 | + |
| 355 | + |
| 356 | +def main(): |
| 357 | + """Run all operator demonstrations.""" |
| 358 | + print("\n" + "=" * 70) |
| 359 | + print("TNFR CANONICAL OPERATORS - COMPLETE CATALOG") |
| 360 | + print("=" * 70) |
| 361 | + print("\nDemonstrating all 13 canonical operators with valid patterns") |
| 362 | + print("Anti-patterns are documented but commented out for safety\n") |
| 363 | + |
| 364 | + # Run all tests |
| 365 | + test_emission() |
| 366 | + test_reception() |
| 367 | + test_coherence() |
| 368 | + test_dissonance() |
| 369 | + test_coupling() |
| 370 | + test_resonance() |
| 371 | + test_silence() |
| 372 | + test_expansion() |
| 373 | + test_contraction() |
| 374 | + test_self_organization() |
| 375 | + test_mutation() |
| 376 | + test_transition() |
| 377 | + test_recursivity() |
| 378 | + |
| 379 | + print("\n" + "=" * 70) |
| 380 | + print("✅ ALL OPERATORS DEMONSTRATED SUCCESSFULLY") |
| 381 | + print("=" * 70) |
| 382 | + print("\nFor detailed documentation, see:") |
| 383 | + print("- docs/grammar/03-OPERATORS-AND-GLYPHS.md") |
| 384 | + print("- docs/grammar/08-QUICK-REFERENCE.md (Compatibility Matrix)") |
| 385 | + print("- docs/grammar/schemas/canonical-operators.json (JSON Schema)") |
| 386 | + |
| 387 | + |
| 388 | +if __name__ == "__main__": |
| 389 | + main() |
0 commit comments