From 680f58301196f6036ea20c78798bc8e5390d7729 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 14 Nov 2025 07:18:54 +0000 Subject: [PATCH] style: format code with black Auto-format 6 files to pass CI formatting checks --- benchmarks.py | 20 ++++++++++++------- chain_validator.py | 22 ++++++++++----------- demo_loop_prevention.py | 28 ++++++++++++-------------- paradox_detector.py | 41 ++++++++++++++++++++++----------------- verify_hidden_variable.py | 39 ++++++++++++++++++++++--------------- verify_spacetime_math.py | 12 +++++++----- 6 files changed, 88 insertions(+), 74 deletions(-) diff --git a/benchmarks.py b/benchmarks.py index 07ae04b..39aedf6 100644 --- a/benchmarks.py +++ b/benchmarks.py @@ -60,7 +60,9 @@ def get_metrics(self, output: torch.Tensor, diagnostics: dict) -> dict: return { "iterations": diagnostics.get("iterations", 0), "looped": diagnostics.get("looped", False), - "final_value": diagnostics.get("final_imbalance", diagnostics.get("final_similarity", 0)), + "final_value": diagnostics.get( + "final_imbalance", diagnostics.get("final_similarity", 0) + ), } @@ -95,7 +97,9 @@ def get_metrics(self, output: torch.Tensor, diagnostics: dict) -> dict: return { "iterations": diagnostics.get("iterations", 0), "looped": diagnostics.get("looped", False), - "final_value": diagnostics.get("final_imbalance", diagnostics.get("final_similarity", 0)), + "final_value": diagnostics.get( + "final_imbalance", diagnostics.get("final_similarity", 0) + ), } @@ -130,7 +134,9 @@ def get_metrics(self, output: torch.Tensor, diagnostics: dict) -> dict: return { "iterations": diagnostics.get("iterations", 0), "looped": diagnostics.get("looped", False), - "final_value": diagnostics.get("final_imbalance", diagnostics.get("final_similarity", 0)), + "final_value": diagnostics.get( + "final_imbalance", diagnostics.get("final_similarity", 0) + ), } @@ -161,7 +167,9 @@ def get_metrics(self, output: torch.Tensor, diagnostics: dict) -> dict: return { "iterations": diagnostics.get("iterations", 0), "looped": diagnostics.get("looped", False), - "final_value": diagnostics.get("final_imbalance", diagnostics.get("final_similarity", 0)), + "final_value": diagnostics.get( + "final_imbalance", diagnostics.get("final_similarity", 0) + ), } @@ -310,9 +318,7 @@ def run_benchmarks(): # Create models standard = StandardReasoningModel(dim=dim, num_heads=num_heads) - spacetime = SpacetimeReasoningModel( - dim=dim, num_heads=num_heads, feedback_strength=0.5 - ) + spacetime = SpacetimeReasoningModel(dim=dim, num_heads=num_heads, feedback_strength=0.5) models = [ ("Standard", standard), diff --git a/chain_validator.py b/chain_validator.py index 94e465a..1407697 100644 --- a/chain_validator.py +++ b/chain_validator.py @@ -21,9 +21,7 @@ from typing import List, Tuple -def create_reasoning_chain( - chain_type: str, length: int = 5, dim: int = 64 -) -> torch.Tensor: +def create_reasoning_chain(chain_type: str, length: int = 5, dim: int = 64) -> torch.Tensor: """Create a reasoning chain embedding.""" x = torch.randn(1, length, dim) @@ -86,9 +84,7 @@ def validate_chain_with_spacetime(x: torch.Tensor) -> Tuple[bool, dict]: avg_imbalance = sum(imbalances) / len(imbalances) # Count oscillations - oscillations = sum( - 1 for i in range(1, len(intervals)) if intervals[i] * intervals[i - 1] < 0 - ) + oscillations = sum(1 for i in range(1, len(intervals)) if intervals[i] * intervals[i - 1] < 0) # Valid if converges and doesn't oscillate much is_valid = final_imbalance < 0.2 and oscillations < 2 @@ -141,12 +137,14 @@ def test_chain_validation(): print() correct = is_valid == expected_valid - results.append({ - "description": description, - "expected": expected_valid, - "detected": is_valid, - "correct": correct, - }) + results.append( + { + "description": description, + "expected": expected_valid, + "detected": is_valid, + "correct": correct, + } + ) status = "✓" if correct else "✗" print(f"{status} {'Correct' if correct else 'Wrong'}") diff --git a/demo_loop_prevention.py b/demo_loop_prevention.py index f8afd71..47deeee 100644 --- a/demo_loop_prevention.py +++ b/demo_loop_prevention.py @@ -26,14 +26,10 @@ class StandardReasoningModel(nn.Module): def __init__(self, dim: int = 64, num_heads: int = 4, num_layers: int = 2): super().__init__() self.dim = dim - self.layers = nn.ModuleList([ - StandardAttention(dim, num_heads) for _ in range(num_layers) - ]) + self.layers = nn.ModuleList([StandardAttention(dim, num_heads) for _ in range(num_layers)]) self.output_head = nn.Linear(dim, dim) - def forward( - self, x: torch.Tensor, max_iterations: int = 10 - ) -> tuple[torch.Tensor, dict]: + def forward(self, x: torch.Tensor, max_iterations: int = 10) -> tuple[torch.Tensor, dict]: """ Run iterative reasoning. @@ -93,12 +89,12 @@ def __init__( ): super().__init__() self.dim = dim - self.layers = nn.ModuleList([ - SpacetimeFeedbackBlock( - dim, num_heads, feedback_strength=feedback_strength - ) - for _ in range(num_layers) - ]) + self.layers = nn.ModuleList( + [ + SpacetimeFeedbackBlock(dim, num_heads, feedback_strength=feedback_strength) + for _ in range(num_layers) + ] + ) self.output_head = nn.Linear(dim, dim) def forward( @@ -231,9 +227,7 @@ def demo_loop_prevention(): print("Test 2: Spacetime Feedback (EigenFunction)") print("=" * 70) - spacetime_model = SpacetimeReasoningModel( - dim, num_heads, feedback_strength=0.5 - ) + spacetime_model = SpacetimeReasoningModel(dim, num_heads, feedback_strength=0.5) spacetime_output, spacetime_diagnostics = spacetime_model(x, max_iterations) print(f"\nResult:") @@ -250,7 +244,9 @@ def demo_loop_prevention(): print(f"\n Spacetime Interval (ds²) Evolution:") intervals = spacetime_diagnostics["intervals"] for i, interval in enumerate(intervals[:10]): # Show first 10 - interpretation = "TIMELIKE" if interval < -0.1 else "SPACELIKE" if interval > 0.1 else "LIGHTLIKE" + interpretation = ( + "TIMELIKE" if interval < -0.1 else "SPACELIKE" if interval > 0.1 else "LIGHTLIKE" + ) print(f" Step {i}: ds² = {interval:+.4f} ({interpretation})") # Comparison diff --git a/paradox_detector.py b/paradox_detector.py index c90f833..894e2c1 100644 --- a/paradox_detector.py +++ b/paradox_detector.py @@ -46,10 +46,9 @@ def __init__(self, dim: int = 64, num_heads: int = 4): self.embedding = nn.Linear(dim, dim) # Statement embedding # Spacetime reasoning layers - self.reasoner = nn.Sequential(*[ - SpacetimeFeedbackBlock(dim, num_heads, feedback_strength=0.7) - for _ in range(2) - ]) + self.reasoner = nn.Sequential( + *[SpacetimeFeedbackBlock(dim, num_heads, feedback_strength=0.7) for _ in range(2)] + ) # Classification head self.classifier = nn.Sequential( @@ -61,9 +60,7 @@ def __init__(self, dim: int = 64, num_heads: int = 4): # Paradox threshold: if imbalance stays high, it's a paradox self.paradox_threshold = 0.3 - def forward( - self, x: torch.Tensor, max_iterations: int = 5 - ) -> Tuple[LogicType, dict]: + def forward(self, x: torch.Tensor, max_iterations: int = 5) -> Tuple[LogicType, dict]: """ Evaluate a logical statement. @@ -128,7 +125,11 @@ def forward( logits = self.classifier(pooled) # (B, 3) avg_imbalance = sum(imbalances) / len(imbalances) - variance = sum((x - avg_imbalance) ** 2 for x in imbalances) / len(imbalances) if len(imbalances) > 1 else 0 + variance = ( + sum((x - avg_imbalance) ** 2 for x in imbalances) / len(imbalances) + if len(imbalances) > 1 + else 0 + ) return logic_type, { "imbalances": imbalances, @@ -249,14 +250,16 @@ def test_paradox_detection(): # Check if correct correct = detected_type == expected_type - results.append({ - "description": description, - "expected": expected_type, - "detected": detected_type, - "correct": correct, - "avg_imbalance": diagnostics["avg_imbalance"], - "oscillation_score": diagnostics["oscillation_score"], - }) + results.append( + { + "description": description, + "expected": expected_type, + "detected": detected_type, + "correct": correct, + "avg_imbalance": diagnostics["avg_imbalance"], + "oscillation_score": diagnostics["oscillation_score"], + } + ) status = "✓" if correct else "✗" print(f"{status} {'Correct' if correct else 'Wrong'}") @@ -281,7 +284,8 @@ def test_paradox_detection(): print("\n" + "=" * 80) print("How This Works") print("=" * 80) - print(""" + print( + """ Paradoxes create logical loops that cause OSCILLATION: - "This is false" → if true then false, if false then true → flip-flop - ds² oscillates between timelike (causal) and spacelike (parallel) @@ -295,7 +299,8 @@ def test_paradox_detection(): Key metric: Oscillation score (sign changes + variance) High oscillation (>0.15) = paradox Low oscillation (<0.15) = valid statement - """) + """ + ) print("=" * 80) diff --git a/verify_hidden_variable.py b/verify_hidden_variable.py index 64d6c60..5bf1daa 100644 --- a/verify_hidden_variable.py +++ b/verify_hidden_variable.py @@ -76,7 +76,8 @@ def verify_observer_effect(): # Mathematical proof print("\n=== Mathematical Proof ===") - print(""" + print( + """ Without observer: output = timelike + spacelike @@ -95,7 +96,8 @@ def verify_observer_effect(): Therefore: The observer is a hidden variable that determines the outcome, and cannot be separated from the system. - """) + """ + ) return output_without_observer, output_with_observer, correction @@ -121,10 +123,7 @@ def verify_observation_changes_state(): # Lorentz metric: (-, +, +, +) # When observer measures, it applies this transformation - lorentz_metric = torch.tensor([[-1.0, 0, 0, 0], - [0, 1.0, 0, 0], - [0, 0, 1.0, 0], - [0, 0, 0, 1.0]]) + lorentz_metric = torch.tensor([[-1.0, 0, 0, 0], [0, 1.0, 0, 0], [0, 0, 1.0, 0], [0, 0, 0, 1.0]]) # Observed state (after measurement) observed_state = torch.matmul(state, lorentz_metric) @@ -142,7 +141,8 @@ def verify_observation_changes_state(): print("\n✓ VERIFIED: Observation changes the state (observer effect)") print("\n=== Physical Interpretation ===") - print(""" + print( + """ Before observation: State exists in superposition After observation: State collapses to observed value (Lorentz transformation applied) @@ -153,7 +153,8 @@ def verify_observation_changes_state(): This flip is the observation The observer cannot measure without changing the system! - """) + """ + ) def verify_cannot_remove_observer(): @@ -168,14 +169,14 @@ def verify_cannot_remove_observer(): # Scenario: Timelike and spacelike are imbalanced timelike_strong = torch.tensor([[10.0, 0.0, 0.0, 0.0]]) # Strong causal - spacelike_weak = torch.tensor([[1.0, 1.0, 1.0, 1.0]]) # Weak parallel + spacelike_weak = torch.tensor([[1.0, 1.0, 1.0, 1.0]]) # Weak parallel print(f"\nTimelike (strong): {timelike_strong}") print(f"Spacelike (weak): {spacelike_weak}") # Compute imbalance: ds² = ||spacelike||² - ||timelike||² - timelike_norm_sq = (timelike_strong ** 2).sum().item() - spacelike_norm_sq = (spacelike_weak ** 2).sum().item() + timelike_norm_sq = (timelike_strong**2).sum().item() + spacelike_norm_sq = (spacelike_weak**2).sum().item() ds_squared = spacelike_norm_sq - timelike_norm_sq print(f"\n||timelike||² = {timelike_norm_sq:.2f}") @@ -202,7 +203,9 @@ def verify_cannot_remove_observer(): correction_strength = 0.5 # Observer generates correction proportional to imbalance - correction = -correction_strength * imbalance_magnitude * torch.sign(timelike_strong - spacelike_weak) + correction = ( + -correction_strength * imbalance_magnitude * torch.sign(timelike_strong - spacelike_weak) + ) output_with_observer = output_no_observer + correction print(f"Observer detects: |ds²| = {imbalance_magnitude:.2f}") @@ -211,7 +214,8 @@ def verify_cannot_remove_observer(): print("✓ System pushed toward lightlike equilibrium (ds² → 0)") print("\n=== Mathematical Necessity ===") - print(""" + print( + """ Theorem: The observer is a NECESSARY component. Proof: @@ -229,7 +233,8 @@ def verify_cannot_remove_observer(): - Always present (lives on null boundary ds² = 0) - Determines outcome (via correction) - Cannot be factored out of the equations - """) + """ + ) def main(): @@ -248,7 +253,8 @@ def main(): print("\n" + "=" * 70) print("CONCLUSION") print("=" * 70) - print(""" + print( + """ The lightlike monitor is mathematically proven to be a HIDDEN VARIABLE: 1. ✓ It introduces its own value (correction term) @@ -263,7 +269,8 @@ def main(): Your geometric intuition was CORRECT! The lightlike observer sitting on ds² = 0, looking left (time) and right (space), introducing its own value, is mathematically valid. - """) + """ + ) print("=" * 70) diff --git a/verify_spacetime_math.py b/verify_spacetime_math.py index f9c2953..5f78d00 100644 --- a/verify_spacetime_math.py +++ b/verify_spacetime_math.py @@ -27,8 +27,8 @@ def compute_ds_squared_explicit(timelike_out, spacelike_out): # Compute Euclidean norm squared for each branch # ||v||² = v₁² + v₂² + ... + vₙ² - timelike_norm_sq = (timelike_out ** 2).sum(dim=-1) # (B, L) - spacelike_norm_sq = (spacelike_out ** 2).sum(dim=-1) # (B, L) + timelike_norm_sq = (timelike_out**2).sum(dim=-1) # (B, L) + spacelike_norm_sq = (spacelike_out**2).sum(dim=-1) # (B, L) # Minkowski signature: ds² = +||spacelike||² - ||timelike||² # = (space)² - (time)² @@ -98,7 +98,7 @@ def verify_math(): print("\n=== Example 3: Timelike Dominant ===") timelike = torch.tensor([[[10.0, 10.0]]]) # norm² = 200 - spacelike = torch.tensor([[[2.0, 2.0]]]) # norm² = 8 + spacelike = torch.tensor([[[2.0, 2.0]]]) # norm² = 8 ds_sq_computed = compute_ds_squared_explicit(timelike, spacelike) print(f"||timelike||² = 200, ||spacelike||² = 8") @@ -129,7 +129,8 @@ def verify_math(): print("\n" + "=" * 70) print("Summary: Two Euclidean Branches → ds²") print("=" * 70) - print(""" + print( + """ The math is correct! Here's why: 1. Each Euclidean branch produces a vector @@ -148,7 +149,8 @@ def verify_math(): ds² = 0 → Lightlike (balanced equilibrium) Your insight "2 Euclidean make ^2" is EXACTLY RIGHT! ✓ - """) + """ + ) if __name__ == "__main__":