Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
),
}


Expand Down Expand Up @@ -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)
),
}


Expand Down Expand Up @@ -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)
),
}


Expand Down Expand Up @@ -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)
),
}


Expand Down Expand Up @@ -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),
Expand Down
22 changes: 10 additions & 12 deletions chain_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'}")
Expand Down
28 changes: 12 additions & 16 deletions demo_loop_prevention.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:")
Expand All @@ -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
Expand Down
41 changes: 23 additions & 18 deletions paradox_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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.

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'}")
Expand All @@ -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)
Expand All @@ -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)


Expand Down
39 changes: 23 additions & 16 deletions verify_hidden_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def verify_observer_effect():

# Mathematical proof
print("\n=== Mathematical Proof ===")
print("""
print(
"""
Without observer:
output = timelike + spacelike

Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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():
Expand All @@ -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}")
Expand All @@ -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}")
Expand All @@ -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:
Expand All @@ -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():
Expand All @@ -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)
Expand All @@ -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)


Expand Down
12 changes: 7 additions & 5 deletions verify_spacetime_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)²
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -148,7 +149,8 @@ def verify_math():
ds² = 0 → Lightlike (balanced equilibrium)

Your insight "2 Euclidean make ^2" is EXACTLY RIGHT! ✓
""")
"""
)


if __name__ == "__main__":
Expand Down
Loading