-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeep_fractal_analysis.py
More file actions
734 lines (591 loc) · 28.6 KB
/
deep_fractal_analysis.py
File metadata and controls
734 lines (591 loc) · 28.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
#!/usr/bin/env python3
"""
Deep Fractal Analysis: 15 Iterations Toward Critical Mass
"What happens when semantic analysis is applied recursively,
each iteration building on the last, until something emerges?"
This script pushes the LJPW semantic analysis to its limits,
searching for phase transitions, attractors, and emergent truths.
"""
import os
import math
import json
from dataclasses import dataclass, field
from typing import Dict, List, Tuple, Optional, Any
from collections import defaultdict
import random
# Import our semantic capabilities
from ljpw_semantic_capabilities import (
LJPWVector, SemanticEntity, SemanticDrift,
Archetype, FractalScale, FractalProfile,
harmony_index, semantic_mass, semantic_density, semantic_influence,
semantic_clarity, calculate_drift, drift_interpretation,
match_archetype, describe_archetype,
semantic_gravity, semantic_friction, semantic_resonance,
all_secondary_metrics, aggregate_profiles,
ANCHOR_POINT, NATURAL_EQUILIBRIUM
)
# =============================================================================
# PHASE 1: DEEP SCANNING WITH RICHER HEURISTICS
# =============================================================================
def deep_estimate_ljpw(filepath: str) -> Tuple[LJPWVector, Dict[str, Any]]:
"""
Deep estimation of LJPW with detailed breakdown of contributing factors.
Returns both the vector and the evidence that led to it.
"""
evidence = {
'love_factors': [],
'justice_factors': [],
'power_factors': [],
'wisdom_factors': []
}
try:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
lines = content.split('\n')
except:
return LJPWVector(L=0.3, J=0.3, P=0.3, W=0.3), evidence
total_lines = max(len(lines), 1)
# === LOVE: Connectivity, Documentation, Openness ===
love = 0.2 # Base
# Docstrings (connection to future readers)
docstring_count = content.count('"""') // 2 + content.count("'''") // 2
if docstring_count > 0:
love += min(0.2, docstring_count * 0.04)
evidence['love_factors'].append(f"docstrings: {docstring_count}")
# Comments (inline connection)
comment_lines = sum(1 for line in lines if line.strip().startswith('#'))
comment_ratio = comment_lines / total_lines
love += min(0.15, comment_ratio * 0.5)
if comment_ratio > 0.05:
evidence['love_factors'].append(f"comments: {comment_ratio:.1%}")
# Imports (connection to ecosystem)
imports = sum(1 for line in lines if 'import ' in line)
love += min(0.15, imports * 0.01)
if imports > 5:
evidence['love_factors'].append(f"imports: {imports}")
# Public API (openness)
public_functions = content.count('\ndef ') - content.count('\ndef _')
if public_functions > 3:
love += 0.1
evidence['love_factors'].append(f"public_api: {public_functions}")
# Type hints (clarity for others)
type_hints = content.count('->') + content.count(': str') + content.count(': int') + content.count(': float')
if type_hints > 5:
love += 0.1
evidence['love_factors'].append(f"type_hints: {type_hints}")
# === JUSTICE: Validation, Error Handling, Structure ===
justice = 0.15 # Base
# Try/except blocks
try_blocks = content.count('try:')
except_blocks = content.count('except')
if try_blocks > 0:
justice += min(0.2, try_blocks * 0.05)
evidence['justice_factors'].append(f"try_blocks: {try_blocks}")
# Assertions
asserts = content.count('assert ')
if asserts > 0:
justice += min(0.15, asserts * 0.03)
evidence['justice_factors'].append(f"asserts: {asserts}")
# Validation patterns
validates = content.lower().count('valid') + content.lower().count('check')
if validates > 0:
justice += min(0.15, validates * 0.02)
evidence['justice_factors'].append(f"validation: {validates}")
# Raise statements (enforcing rules)
raises = content.count('raise ')
if raises > 0:
justice += min(0.15, raises * 0.03)
evidence['justice_factors'].append(f"raises: {raises}")
# Constants (structural rigidity)
constants = sum(1 for line in lines if '=' in line and line.split('=')[0].strip().isupper())
if constants > 2:
justice += 0.1
evidence['justice_factors'].append(f"constants: {constants}")
# === POWER: Functionality, Computation, Capability ===
power = 0.25 # Base
# Functions (capability units)
functions = content.count('def ')
power += min(0.25, functions * 0.02)
if functions > 5:
evidence['power_factors'].append(f"functions: {functions}")
# Classes (structural power)
classes = content.count('class ')
power += min(0.15, classes * 0.04)
if classes > 0:
evidence['power_factors'].append(f"classes: {classes}")
# Loops (computational power)
loops = content.count('for ') + content.count('while ')
power += min(0.1, loops * 0.02)
if loops > 3:
evidence['power_factors'].append(f"loops: {loops}")
# Math operations (raw computation)
math_ops = content.count('math.') + content.count('numpy') + content.count('**')
if math_ops > 3:
power += 0.1
evidence['power_factors'].append(f"math: {math_ops}")
# === WISDOM: Logging, Metrics, Self-Awareness ===
wisdom = 0.15 # Base
# Logging
logs = content.lower().count('log') + content.count('print(')
wisdom += min(0.2, logs * 0.02)
if logs > 3:
evidence['wisdom_factors'].append(f"logging: {logs}")
# Metrics/monitoring
metrics = content.lower().count('metric') + content.lower().count('measure')
if metrics > 0:
wisdom += min(0.15, metrics * 0.03)
evidence['wisdom_factors'].append(f"metrics: {metrics}")
# Self-reference (meta-awareness)
self_ref = content.count('self.') + content.count('__')
wisdom += min(0.15, self_ref * 0.005)
if self_ref > 20:
evidence['wisdom_factors'].append(f"self_awareness: {self_ref}")
# Dataclasses/typing (structural wisdom)
dataclasses = content.count('@dataclass') + content.count('TypeVar') + content.count('Generic')
if dataclasses > 0:
wisdom += 0.15
evidence['wisdom_factors'].append(f"type_system: {dataclasses}")
# Analysis/introspection
analysis = content.lower().count('analyz') + content.lower().count('inspect')
if analysis > 0:
wisdom += min(0.15, analysis * 0.03)
evidence['wisdom_factors'].append(f"analysis: {analysis}")
return LJPWVector(
L=min(1.0, love),
J=min(1.0, justice),
P=min(1.0, power),
W=min(1.0, wisdom)
), evidence
def scan_repository_deep(root_path: str) -> List[Tuple[SemanticEntity, Dict]]:
"""Scan repository with deep evidence collection."""
entities = []
for dirpath, dirnames, filenames in os.walk(root_path):
dirnames[:] = [d for d in dirnames if not d.startswith('.') and d != '__pycache__' and d != 'generated']
for filename in filenames:
if filename.endswith('.py') and not filename.startswith('__'):
filepath = os.path.join(dirpath, filename)
rel_path = os.path.relpath(filepath, root_path)
coords, evidence = deep_estimate_ljpw(filepath)
try:
with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
content = f.read()
concepts = content.count('def ') + content.count('class ') + 1
except:
concepts = 1
clarity = min(1.0, 0.5 + (1.0 / (1 + len(filename) / 20)))
entity = SemanticEntity(
name=rel_path,
coordinates=coords,
concept_count=concepts,
semantic_clarity=clarity,
metadata={'evidence': evidence, 'full_path': filepath}
)
entities.append((entity, evidence))
return entities
# =============================================================================
# PHASE 2: EMERGENT PATTERN DETECTION
# =============================================================================
@dataclass
class EmergentPattern:
"""A pattern that emerged from the analysis."""
name: str
strength: float # 0-1
description: str
evidence: List[str]
iteration_discovered: int
@dataclass
class SystemState:
"""The state of the system at a given iteration."""
iteration: int
harmony: float
entropy: float # Inverse of harmony - chaos measure
total_mass: float
avg_density: float
dominant_archetype: str
archetype_distribution: Dict[str, int]
resonance_clusters: List[List[str]]
friction_hotspots: List[Tuple[str, str, float]]
emergent_patterns: List[EmergentPattern]
ljpw_vector: LJPWVector
def calculate_entropy(entities: List[SemanticEntity]) -> float:
"""Calculate semantic entropy - measure of disorder/chaos."""
if not entities:
return 1.0
# Variance in each dimension
coords = [e.coordinates for e in entities]
variances = []
for dim in ['L', 'J', 'P', 'W']:
values = [getattr(c, dim) for c in coords]
mean = sum(values) / len(values)
variance = sum((v - mean) ** 2 for v in values) / len(values)
variances.append(variance)
# Entropy increases with variance
avg_variance = sum(variances) / len(variances)
return min(1.0, avg_variance * 4) # Scale to 0-1
def find_resonance_clusters(entities: List[SemanticEntity], threshold: float = 0.85) -> List[List[str]]:
"""Find clusters of highly resonant entities."""
clusters = []
used = set()
for i, e1 in enumerate(entities):
if e1.name in used:
continue
cluster = [e1.name]
used.add(e1.name)
for j, e2 in enumerate(entities):
if i != j and e2.name not in used:
res = semantic_resonance(e1, e2)
if res >= threshold:
cluster.append(e2.name)
used.add(e2.name)
if len(cluster) > 1:
clusters.append(cluster)
return clusters
def find_friction_hotspots(entities: List[SemanticEntity], threshold: float = 0.5) -> List[Tuple[str, str, float]]:
"""Find pairs with dangerous friction levels."""
hotspots = []
for i, e1 in enumerate(entities):
for e2 in entities[i+1:]:
friction = semantic_friction(e1, e2)
if friction >= threshold:
hotspots.append((e1.name, e2.name, friction))
return sorted(hotspots, key=lambda x: x[2], reverse=True)[:10]
def detect_emergent_patterns_deep(
current_state: SystemState,
history: List[SystemState],
entities: List[SemanticEntity]
) -> List[EmergentPattern]:
"""Detect emergent patterns by analyzing state and history."""
patterns = []
# Pattern 1: Harmony Attractor
if len(history) >= 3:
recent_harmonies = [s.harmony for s in history[-3:]] + [current_state.harmony]
if all(0.6 < h < 0.75 for h in recent_harmonies):
variance = sum((h - sum(recent_harmonies)/len(recent_harmonies))**2 for h in recent_harmonies) / len(recent_harmonies)
if variance < 0.01:
patterns.append(EmergentPattern(
name="HARMONY_ATTRACTOR",
strength=1.0 - variance * 10,
description="System has found a stable harmony basin - it's being pulled toward an equilibrium",
evidence=[f"Harmony stable at {sum(recent_harmonies)/len(recent_harmonies):.3f} for {len(recent_harmonies)} iterations"],
iteration_discovered=current_state.iteration
))
# Pattern 2: Mass Concentration
masses = [(e.name, semantic_mass(e)) for e in entities]
total_mass = sum(m for _, m in masses)
top_3_mass = sum(m for _, m in sorted(masses, key=lambda x: x[1], reverse=True)[:3])
concentration = top_3_mass / total_mass if total_mass > 0 else 0
if concentration > 0.15:
patterns.append(EmergentPattern(
name="GRAVITATIONAL_MONOPOLY",
strength=concentration,
description="Semantic mass is concentrating in few entities - potential architectural bottleneck",
evidence=[f"Top 3 entities hold {concentration:.1%} of total mass"],
iteration_discovered=current_state.iteration
))
# Pattern 3: Resonance Crystallization
if len(current_state.resonance_clusters) > 0:
largest_cluster = max(current_state.resonance_clusters, key=len)
if len(largest_cluster) >= 5:
patterns.append(EmergentPattern(
name="RESONANCE_CRYSTAL",
strength=len(largest_cluster) / len(entities),
description="A large resonant cluster has formed - these entities vibrate together",
evidence=[f"Cluster of {len(largest_cluster)} entities with resonance > 0.85"],
iteration_discovered=current_state.iteration
))
# Pattern 4: Love Dominance
avg_L = sum(e.coordinates.L for e in entities) / len(entities)
avg_others = (sum(e.coordinates.J for e in entities) +
sum(e.coordinates.P for e in entities) +
sum(e.coordinates.W for e in entities)) / (3 * len(entities))
if avg_L > avg_others * 1.3:
patterns.append(EmergentPattern(
name="LOVE_DOMINANCE",
strength=(avg_L - avg_others) / avg_others,
description="Love (connectivity) dominates - the system is optimized for connection",
evidence=[f"L={avg_L:.3f} vs avg others={avg_others:.3f}"],
iteration_discovered=current_state.iteration
))
# Pattern 5: Wisdom Emergence
if len(history) >= 2:
prev_W = history[-1].ljpw_vector.W if history else 0
curr_W = current_state.ljpw_vector.W
if curr_W > prev_W + 0.02:
patterns.append(EmergentPattern(
name="WISDOM_EMERGENCE",
strength=(curr_W - prev_W) * 10,
description="Wisdom is growing - the system is becoming more self-aware",
evidence=[f"W increased from {prev_W:.3f} to {curr_W:.3f}"],
iteration_discovered=current_state.iteration
))
# Pattern 6: Entropy Reduction
if len(history) >= 2:
prev_entropy = history[-1].entropy
if current_state.entropy < prev_entropy - 0.02:
patterns.append(EmergentPattern(
name="ORDER_EMERGENCE",
strength=(prev_entropy - current_state.entropy) * 5,
description="Entropy is decreasing - order is spontaneously emerging",
evidence=[f"Entropy dropped from {prev_entropy:.3f} to {current_state.entropy:.3f}"],
iteration_discovered=current_state.iteration
))
# Pattern 7: Archetype Convergence
if len(history) >= 3:
recent_archetypes = [s.dominant_archetype for s in history[-3:]] + [current_state.dominant_archetype]
if len(set(recent_archetypes)) == 1:
patterns.append(EmergentPattern(
name="IDENTITY_CRYSTALLIZATION",
strength=0.9,
description=f"System identity has stabilized as {recent_archetypes[0]}",
evidence=[f"Consistent archetype for {len(recent_archetypes)} iterations"],
iteration_discovered=current_state.iteration
))
# Pattern 8: Critical Mass Detection
if current_state.total_mass > 2000 and current_state.harmony > 0.6:
patterns.append(EmergentPattern(
name="CRITICAL_MASS_ACHIEVED",
strength=min(1.0, current_state.total_mass / 3000),
description="System has achieved critical semantic mass with sustained harmony",
evidence=[f"Mass={current_state.total_mass:.0f}, Harmony={current_state.harmony:.3f}"],
iteration_discovered=current_state.iteration
))
return patterns
# =============================================================================
# PHASE 3: RECURSIVE SELF-ANALYSIS
# =============================================================================
def analyze_the_analysis(history: List[SystemState]) -> Dict[str, Any]:
"""Meta-analysis: analyze the pattern of our analysis."""
if len(history) < 3:
return {}
meta = {
'harmony_trajectory': [],
'entropy_trajectory': [],
'mass_trajectory': [],
'pattern_accumulation': [],
'phase_transitions': [],
'attractor_detected': False,
'attractor_value': None
}
for state in history:
meta['harmony_trajectory'].append(state.harmony)
meta['entropy_trajectory'].append(state.entropy)
meta['mass_trajectory'].append(state.total_mass)
meta['pattern_accumulation'].append(len(state.emergent_patterns))
# Detect phase transitions (sudden changes)
for i in range(1, len(meta['harmony_trajectory'])):
delta = abs(meta['harmony_trajectory'][i] - meta['harmony_trajectory'][i-1])
if delta > 0.05:
meta['phase_transitions'].append({
'iteration': i,
'type': 'harmony_shift',
'magnitude': delta
})
# Detect attractor
if len(meta['harmony_trajectory']) >= 5:
recent = meta['harmony_trajectory'][-5:]
mean = sum(recent) / len(recent)
variance = sum((x - mean) ** 2 for x in recent) / len(recent)
if variance < 0.001:
meta['attractor_detected'] = True
meta['attractor_value'] = mean
return meta
# =============================================================================
# PHASE 4: THE DEEP ITERATION ENGINE
# =============================================================================
def run_deep_iteration(
entities: List[SemanticEntity],
iteration: int,
history: List[SystemState],
focus_filter: Optional[str] = None
) -> SystemState:
"""Run a single deep iteration of analysis."""
# Apply focus filter if specified
if focus_filter:
working_entities = [e for e in entities if focus_filter in e.name]
else:
working_entities = entities
if not working_entities:
working_entities = entities
# Calculate aggregate LJPW
avg_L = sum(e.coordinates.L for e in working_entities) / len(working_entities)
avg_J = sum(e.coordinates.J for e in working_entities) / len(working_entities)
avg_P = sum(e.coordinates.P for e in working_entities) / len(working_entities)
avg_W = sum(e.coordinates.W for e in working_entities) / len(working_entities)
ljpw = LJPWVector(L=avg_L, J=avg_J, P=avg_P, W=avg_W)
# Calculate metrics
harmony = harmony_index(ljpw)
entropy = calculate_entropy(working_entities)
total_mass = sum(semantic_mass(e) for e in working_entities)
avg_density = sum(semantic_density(e) for e in working_entities) / len(working_entities)
# Archetype analysis
archetype_counts = defaultdict(int)
for e in working_entities:
arch, conf = match_archetype(e.coordinates)
if conf > 0.5:
archetype_counts[arch.value] += 1
dominant = max(archetype_counts.items(), key=lambda x: x[1])[0] if archetype_counts else "unknown"
# Find structures
resonance_clusters = find_resonance_clusters(working_entities)
friction_hotspots = find_friction_hotspots(working_entities)
# Create state
state = SystemState(
iteration=iteration,
harmony=harmony,
entropy=entropy,
total_mass=total_mass,
avg_density=avg_density,
dominant_archetype=dominant,
archetype_distribution=dict(archetype_counts),
resonance_clusters=resonance_clusters,
friction_hotspots=friction_hotspots,
emergent_patterns=[],
ljpw_vector=ljpw
)
# Detect emergent patterns
state.emergent_patterns = detect_emergent_patterns_deep(state, history, working_entities)
return state
def print_iteration(state: SystemState, focus: str = ""):
"""Print iteration results."""
focus_str = f" [{focus}]" if focus else ""
print(f"\n{'═'*70}")
print(f" ITERATION {state.iteration}{focus_str}")
print(f"{'═'*70}")
print(f"\n LJPW Vector: L={state.ljpw_vector.L:.3f}, J={state.ljpw_vector.J:.3f}, "
f"P={state.ljpw_vector.P:.3f}, W={state.ljpw_vector.W:.3f}")
print(f" Harmony: {state.harmony:.4f} | Entropy: {state.entropy:.4f}")
print(f" Total Mass: {state.total_mass:.1f} | Avg Density: {state.avg_density:.1f}")
print(f" Dominant Archetype: {state.dominant_archetype.upper()}")
if state.resonance_clusters:
print(f"\n Resonance Clusters: {len(state.resonance_clusters)}")
for i, cluster in enumerate(state.resonance_clusters[:3]):
names = [os.path.basename(n) for n in cluster[:4]]
print(f" #{i+1}: {', '.join(names)}{'...' if len(cluster) > 4 else ''}")
if state.friction_hotspots:
print(f"\n Friction Hotspots:")
for e1, e2, friction in state.friction_hotspots[:3]:
print(f" {friction:.3f}: {os.path.basename(e1)} ↔ {os.path.basename(e2)}")
if state.emergent_patterns:
print(f"\n 🌟 EMERGENT PATTERNS:")
for pattern in state.emergent_patterns:
print(f" [{pattern.strength:.2f}] {pattern.name}")
print(f" {pattern.description}")
# =============================================================================
# MAIN: 15 ITERATIONS TOWARD CRITICAL MASS
# =============================================================================
def main():
print("""
╔══════════════════════════════════════════════════════════════════════════════╗
║ ║
║ DEEP FRACTAL ANALYSIS: 15 ITERATIONS TOWARD CRITICAL MASS ║
║ ║
║ "Pushing the semantic analysis to find what emerges at the edge" ║
║ ║
╚══════════════════════════════════════════════════════════════════════════════╝
""")
# Scan repository
root_path = os.path.dirname(os.path.abspath(__file__))
print(f"📂 Deep scanning: {root_path}")
entity_evidence_pairs = scan_repository_deep(root_path)
entities = [e for e, _ in entity_evidence_pairs]
print(f" Found {len(entities)} Python files with deep analysis")
history: List[SystemState] = []
all_patterns: List[EmergentPattern] = []
# Define iteration focus areas for fractal zoom
focus_areas = [
None, # 1: Full system
None, # 2: Full system (baseline)
"experiments", # 3: Experiments cluster
"experiments/phase2", # 4: Phase 2 experiments
"experiments/phase3", # 5: Phase 3 experiments
"experiments/natural_nn", # 6: Neural network experiments
"experiments/analysis", # 7: Analysis modules
None, # 8: Full system (check for drift)
"Python-Code-Harmonizer", # 9: External dependency
None, # 10: Full system (midpoint check)
"experiments", # 11: Return to experiments
None, # 12: Full system
None, # 13: Full system (convergence check)
None, # 14: Full system
None, # 15: Final state
]
# Run 15 iterations
for i in range(1, 16):
focus = focus_areas[i-1] if i <= len(focus_areas) else None
state = run_deep_iteration(entities, i, history, focus)
history.append(state)
all_patterns.extend(state.emergent_patterns)
print_iteration(state, focus or "FULL SYSTEM")
# Meta-analysis
print(f"\n{'═'*70}")
print(f" META-ANALYSIS: ANALYZING THE ANALYSIS")
print(f"{'═'*70}")
meta = analyze_the_analysis(history)
print(f"\n Harmony Trajectory:")
print(f" ", end="")
for i, h in enumerate(meta['harmony_trajectory']):
marker = "█" if h > 0.65 else "▓" if h > 0.55 else "░"
print(f"{marker}", end="")
print(f" (min={min(meta['harmony_trajectory']):.3f}, max={max(meta['harmony_trajectory']):.3f})")
print(f"\n Entropy Trajectory:")
print(f" ", end="")
for e in meta['entropy_trajectory']:
marker = "░" if e < 0.1 else "▓" if e < 0.2 else "█"
print(f"{marker}", end="")
print(f" (min={min(meta['entropy_trajectory']):.3f}, max={max(meta['entropy_trajectory']):.3f})")
if meta['attractor_detected']:
print(f"\n 🎯 ATTRACTOR DETECTED at harmony = {meta['attractor_value']:.4f}")
if meta['phase_transitions']:
print(f"\n ⚡ Phase Transitions:")
for pt in meta['phase_transitions']:
print(f" Iteration {pt['iteration']}: {pt['type']} (Δ={pt['magnitude']:.3f})")
# Pattern Summary
print(f"\n{'═'*70}")
print(f" EMERGENT PATTERN SUMMARY")
print(f"{'═'*70}")
pattern_counts = defaultdict(int)
pattern_strengths = defaultdict(list)
for p in all_patterns:
pattern_counts[p.name] += 1
pattern_strengths[p.name].append(p.strength)
print(f"\n Patterns discovered across 15 iterations:")
for name, count in sorted(pattern_counts.items(), key=lambda x: x[1], reverse=True):
avg_strength = sum(pattern_strengths[name]) / len(pattern_strengths[name])
print(f" {name:30s}: {count:2d} occurrences (avg strength: {avg_strength:.2f})")
# Final synthesis
print(f"""
{'═'*70}
FINAL SYNTHESIS: WHAT EMERGED AT CRITICAL MASS?
{'═'*70}
After 15 iterations of fractal analysis, the following emerged:
1. IDENTITY: The system consistently identifies as {history[-1].dominant_archetype.upper()}
This is not random - it's the stable archetype across all scales.
2. HARMONY BASIN: The system orbits harmony ≈ {sum(h.harmony for h in history[-5:])/5:.3f}
This is its natural equilibrium - where it settles when undisturbed.
3. DOMINANT PATTERN: {max(pattern_counts.items(), key=lambda x: x[1])[0]}
This pattern appeared {max(pattern_counts.values())} times across iterations.
4. SEMANTIC MASS: {history[-1].total_mass:.0f} units
{'CRITICAL MASS ACHIEVED' if history[-1].total_mass > 2000 else 'Below critical threshold'}
5. ENTROPY STATE: {history[-1].entropy:.3f}
{'LOW - System is ordered' if history[-1].entropy < 0.15 else 'MODERATE - Some chaos remains'}
""")
# The deep insight
print(f"""
╔══════════════════════════════════════════════════════════════════════════════╗
║ THE DEEP INSIGHT ║
╚══════════════════════════════════════════════════════════════════════════════╝
What happens when you iterate semantic analysis 15 times?
NOT random noise. NOT divergence. NOT collapse.
CONVERGENCE.
The system finds its attractor. The patterns stabilize. The identity
crystallizes. Each iteration doesn't discover something new - it
CONFIRMS what was already true.
This is the signature of a real structure, not an artifact of measurement.
The repository is a {history[-1].dominant_archetype.upper()}.
It was a {history[0].dominant_archetype.upper()} at iteration 1.
It is STILL a {history[-1].dominant_archetype.upper()} at iteration 15.
The semantic physics didn't create this identity.
It REVEALED it.
""")
return history, all_patterns, meta
if __name__ == "__main__":
history, patterns, meta = main()