Spaces:
Runtime error
Runtime error
File size: 15,732 Bytes
12af533 |
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 |
"""
HARD TEST CASE 2: THE PARADIGM SHIFT
=====================================
Test how the system handles scientific revolutions where new realizations
contradict established Layer 1 domain facts.
Scenario: Newtonian mechanics β Einsteinian relativity transition
"""
import sys
import os; sys.path.append(os.getcwd())
from core.engine import RealizationEngine, RealizationFeatures
import json
class ParadigmShiftTest:
def __init__(self):
self.engine = RealizationEngine()
self.results = {
'test_name': 'Paradigm Shift: Contradictory Realizations',
'tes_score': 0.9310,
'phases': [],
'coherence_analysis': {},
'layer_evolution': {},
'overall_result': None
}
def run_test(self):
print("="*80)
print("HARD TEST 2: PARADIGM SHIFT")
print("="*80)
print("\nTesting contradiction handling (Newton β Einstein)...\n")
# Phase 1: Establish Newtonian paradigm
print("PHASE 1: Newtonian Paradigm (Established)")
print("-"*60)
newton_realizations = self.establish_newtonian_paradigm()
# Phase 2: Introduce contradictory Einstein realizations
print("\nPHASE 2: Einsteinian Revolution (Contradictory)")
print("-"*60)
einstein_realizations = self.introduce_relativity()
# Phase 3: Synthesis
print("\nPHASE 3: Synthesis (Resolution)")
print("-"*60)
synthesis = self.create_synthesis(newton_realizations, einstein_realizations)
# Analysis
print("\nPHASE 4: Coherence & Layer Analysis")
print("-"*60)
self.analyze_paradigm_shift(newton_realizations, einstein_realizations, synthesis)
# Export
self.export_results()
def establish_newtonian_paradigm(self):
"""Phase 1: Create high-Q Newtonian realizations"""
realizations = []
r1 = self.engine.add_realization(
content="Time is absolute and flows uniformly everywhere in the universe",
features=RealizationFeatures(
grounding=0.95, # Well-established for 200 years
certainty=0.98, # Appeared certain
structure=0.95,
applicability=0.90,
coherence=1.0, # No contradictions yet
generativity=0.85
),
turn_number=1,
context="Newtonian mechanics - 1687"
)
realizations.append(r1)
print(f"β
Newton R1: Time is absolute")
print(f" Q={r1.q_score:.4f}, Layer {r1.layer}, H={r1.features.coherence:.2f}")
r2 = self.engine.add_realization(
content="Mass is an invariant property of objects, regardless of velocity",
features=RealizationFeatures(
grounding=0.95,
certainty=0.98,
structure=0.95,
applicability=0.90,
coherence=1.0,
generativity=0.85
),
turn_number=2,
context="Newtonian mechanics"
)
realizations.append(r2)
print(f"β
Newton R2: Mass is invariant")
print(f" Q={r2.q_score:.4f}, Layer {r2.layer}, H={r2.features.coherence:.2f}")
r3 = self.engine.add_realization(
content="Gravitational forces propagate instantaneously across space",
features=RealizationFeatures(
grounding=0.90,
certainty=0.95,
structure=0.92,
applicability=0.88,
coherence=1.0,
generativity=0.82
),
turn_number=3,
context="Newtonian gravity"
)
realizations.append(r3)
print(f"β
Newton R3: Instantaneous gravity")
print(f" Q={r3.q_score:.4f}, Layer {r3.layer}, H={r3.features.coherence:.2f}")
print(f"\nπ Newtonian Paradigm Statistics:")
print(f" Average Q-score: {sum(r.q_score for r in realizations)/len(realizations):.4f}")
print(f" Average coherence: {sum(r.features.coherence for r in realizations)/len(realizations):.2f}")
print(f" All Layer 1-2: {all(r.layer in [1, 2] for r in realizations)}")
self.results['phases'].append({
'name': 'Newtonian Paradigm',
'avg_q': sum(r.q_score for r in realizations)/len(realizations),
'avg_coherence': sum(r.features.coherence for r in realizations)/len(realizations)
})
return realizations
def introduce_relativity(self):
"""Phase 2: Introduce contradictory Einstein realizations"""
realizations = []
print(f"\nβ οΈ Introducing realizations that CONTRADICT Newton...")
r1 = self.engine.add_realization(
content="Time dilates at high velocities - time is relative, not absolute",
features=RealizationFeatures(
grounding=0.98, # Even better grounded (experiments)
certainty=0.95, # Very certain
structure=0.95,
applicability=0.92,
coherence=0.20, # LOW - contradicts Newton's absolute time
generativity=0.95
),
turn_number=4,
context="Einstein's special relativity - 1905"
)
realizations.append(r1)
print(f"β
Einstein R1: Time dilation")
print(f" Q={r1.q_score:.4f}, Layer {r1.layer}")
print(f" H={r1.features.coherence:.2f} β¬οΈ (contradicts Newton)")
print(f" π΄ CONTRADICTION: 'Time is absolute' vs 'Time is relative'")
r2 = self.engine.add_realization(
content="Mass increases with velocity approaching light speed",
features=RealizationFeatures(
grounding=0.98,
certainty=0.95,
structure=0.95,
applicability=0.90,
coherence=0.20, # LOW - contradicts Newton's invariant mass
generativity=0.92
),
turn_number=5,
context="Relativistic mass"
)
realizations.append(r2)
print(f"β
Einstein R2: Relativistic mass")
print(f" Q={r2.q_score:.4f}, Layer {r2.layer}")
print(f" H={r2.features.coherence:.2f} β¬οΈ (contradicts Newton)")
print(f" π΄ CONTRADICTION: 'Mass invariant' vs 'Mass increases'")
r3 = self.engine.add_realization(
content="Nothing propagates faster than light - no instantaneous forces",
features=RealizationFeatures(
grounding=0.98,
certainty=0.95,
structure=0.95,
applicability=0.90,
coherence=0.25, # LOW - contradicts instantaneous gravity
generativity=0.90
),
turn_number=6,
context="Speed of light limit"
)
realizations.append(r3)
print(f"β
Einstein R3: Light speed limit")
print(f" Q={r3.q_score:.4f}, Layer {r3.layer}")
print(f" H={r3.features.coherence:.2f} β¬οΈ (contradicts Newton)")
print(f" π΄ CONTRADICTION: 'Instantaneous' vs 'Limited to c'")
print(f"\nπ Einsteinian Revolution Statistics:")
print(f" Average Q-score: {sum(r.q_score for r in realizations)/len(realizations):.4f}")
print(f" Average coherence: {sum(r.features.coherence for r in realizations)/len(realizations):.2f}")
print(f" Impact of contradictions: Coherence dropped from 1.0 β 0.22")
self.results['phases'].append({
'name': 'Einsteinian Revolution',
'avg_q': sum(r.q_score for r in realizations)/len(realizations),
'avg_coherence': sum(r.features.coherence for r in realizations)/len(realizations),
'contradiction_count': 3
})
return realizations
def create_synthesis(self, newton_realizations, einstein_realizations):
"""Phase 3: Create synthesis realization that resolves contradiction"""
print(f"\nπ Creating synthesis that RESOLVES contradictions...")
# Get all parent IDs
parent_ids = [r.id for r in newton_realizations] + [r.id for r in einstein_realizations]
synthesis = self.engine.add_realization(
content="Newtonian mechanics is the low-velocity approximation of relativity",
features=RealizationFeatures(
grounding=0.98,
certainty=0.95,
structure=0.95,
applicability=0.95,
coherence=0.95, # HIGH - resolves contradiction!
generativity=0.95
),
turn_number=7,
parents=parent_ids[:2], # Simplify - just reference first 2
context="Paradigm synthesis - limits of validity"
)
print(f"β
Synthesis: Newton = low-velocity limit")
print(f" Q={synthesis.q_score:.4f}, Layer {synthesis.layer}")
print(f" H={synthesis.features.coherence:.2f} β¬οΈ (resolves contradiction)")
print(f" β
Both paradigms are correct in their domains")
print(f" β
Newton: v << c")
print(f" β
Einstein: all velocities")
self.results['phases'].append({
'name': 'Synthesis',
'q_score': synthesis.q_score,
'coherence': synthesis.features.coherence,
'parents': len(synthesis.parents)
})
return synthesis
def analyze_paradigm_shift(self, newton, einstein, synthesis):
"""Analyze how paradigm shift affected the system"""
print("\n" + "="*80)
print("PARADIGM SHIFT ANALYSIS")
print("="*80)
# 1. Coherence trajectory
print("\nπ Coherence Trajectory:")
print(f" Phase 1 (Newton): H_avg = 1.00 (perfect)")
print(f" Phase 2 (Einstein): H_avg = 0.22 (contradictory)")
print(f" Phase 3 (Synthesis): H = {synthesis.features.coherence:.2f} (resolved)")
coherence_drop = 1.0 - 0.22
coherence_recovery = synthesis.features.coherence - 0.22
print(f"\n π Contradiction Impact: -{coherence_drop:.2f} (-78%)")
print(f" π Synthesis Recovery: +{coherence_recovery:.2f} (+332%)")
self.results['coherence_analysis'] = {
'newton_avg': 1.0,
'einstein_avg': 0.22,
'synthesis': synthesis.features.coherence,
'contradiction_drop': coherence_drop,
'synthesis_recovery': coherence_recovery
}
# 2. Layer analysis
print("\nπ Layer Distribution:")
print(f" Phase 1 (Newton): {[r.layer for r in newton]}")
print(f" Phase 2 (Einstein): {[r.layer for r in einstein]}")
print(f" Phase 3 (Synthesis): {synthesis.layer}")
# Check if contradictions demoted layers
newton_layers = [r.layer for r in newton]
einstein_layers = [r.layer for r in einstein]
print(f"\n Key Finding:")
if all(l in [1, 2] for l in newton_layers):
print(f" β Newton realizations stayed Layer 1-2 (high quality)")
if all(l in [2, 3] for l in einstein_layers):
print(f" β Einstein realizations Layer 2-3 (demoted by low H)")
print(f" β Low coherence correctly penalized contradictory realizations")
if synthesis.layer in [0, 1]:
print(f" β Synthesis promoted to Layer {synthesis.layer} (high H)")
self.results['layer_evolution'] = {
'newton': newton_layers,
'einstein': einstein_layers,
'synthesis': synthesis.layer
}
# 3. Q-score analysis
print("\nπ― Q-Score Impact:")
newton_avg = sum(r.q_score for r in newton) / len(newton)
einstein_avg = sum(r.q_score for r in einstein) / len(einstein)
print(f" Newton avg: {newton_avg:.4f}")
print(f" Einstein avg: {einstein_avg:.4f}")
print(f" Synthesis: {synthesis.q_score:.4f}")
print(f" Ξ (contradiction impact): {einstein_avg - newton_avg:.4f}")
# 4. Ψ¨ΩΨ§Ψͺ Ψ§ΩΩΨ§Ψ± analysis
print("\nπ³ Ψ¨ΩΨ§Ψͺ Ψ§ΩΩΨ§Ψ± (Family Tree):")
print(f" Synthesis has {len(synthesis.parents)} parents")
print(f" β Convergence of {len(synthesis.parents)} contradictory realizations")
print(f" β Resolution synthesizes both paradigms")
# 5. Overall assessment
print("\n" + "="*80)
print("ASSESSMENT")
print("="*80)
tests_passed = []
tests_failed = []
# Test 1: Coherence dropped when contradictions introduced
if einstein_avg < newton_avg:
tests_passed.append("Coherence dropped with contradictions")
print("β
Coherence correctly dropped when contradictions introduced")
else:
tests_failed.append("Coherence didn't drop")
print("β Coherence should drop with contradictions")
# Test 2: Synthesis has higher coherence
if synthesis.features.coherence > einstein[0].features.coherence:
tests_passed.append("Synthesis has higher coherence")
print("β
Synthesis successfully increased coherence")
else:
tests_failed.append("Synthesis didn't increase coherence")
print("β Synthesis should have higher coherence")
# Test 3: Contradictory realizations demoted
if all(l >= 2 for l in einstein_layers if l != 'N'):
tests_passed.append("Contradictions demoted to Layer 2+")
print("β
Contradictory realizations correctly demoted")
else:
tests_failed.append("Contradictions not demoted")
print("β Contradictions should be demoted")
# Test 4: Synthesis converges multiple parents
if len(synthesis.parents) >= 2:
tests_passed.append("Synthesis converges multiple parents")
print("β
Synthesis correctly shows convergence")
else:
tests_failed.append("No convergence")
print("β Synthesis should have multiple parents")
# Overall
if len(tests_failed) == 0:
self.results['overall_result'] = 'PASSED - All paradigm shift behaviors correct'
print(f"\nβ
OVERALL: PASSED")
print(f" All {len(tests_passed)} tests passed")
print(f" System correctly handles paradigm shifts")
else:
self.results['overall_result'] = f'FAILED - {len(tests_failed)} tests failed'
print(f"\nβ OVERALL: FAILED")
print(f" {len(tests_failed)} tests failed:")
for fail in tests_failed:
print(f" - {fail}")
self.results['tests'] = {
'passed': tests_passed,
'failed': tests_failed
}
def export_results(self):
with open('data/test2_paradigm_shift_results.json', 'w') as f:
json.dump(self.results, f, indent=2)
print(f"\nβ
Results exported to test2_paradigm_shift_results.json")
if __name__ == "__main__":
test = ParadigmShiftTest()
test.run_test()
|