Skip to content

Instantly share code, notes, and snippets.

@akarnokd
Created May 5, 2026 18:02
Show Gist options
  • Select an option

  • Save akarnokd/a20aae8ecd18f269dd70f2fa229c30c9 to your computer and use it in GitHub Desktop.

Select an option

Save akarnokd/a20aae8ecd18f269dd70f2fa229c30c9 to your computer and use it in GitHub Desktop.
import time
import zlib
import pickle
from collections import deque
import functools
import random
def cpc_guard(timeout=0.3):
"""Hawking CPC: runtime guard with timeouts (no causality violations)."""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
if time.time() - start > timeout:
raise RuntimeError(f"CPC violation: timeout ({time.time()-start:.3f}s) — causality protected!")
return result
return wrapper
return decorator
class HolographicUniverse:
"""
dS/CFT toy model: universe as pure information processor.
AdS/CFT training wheels → full dS via Λ-driven expansion + CCC cycles.
Time emerges purely from scheduler + entropy processing rate (Landauer/Bekenstein spirit).
"""
def __init__(self, cosmological_constant=0.1, ops_per_tick=4, seed=42):
random.seed(seed)
self.ledger = deque() # append-only holographic boundary
self.cosmological_constant = cosmological_constant # Λ = memory allocator
self.virtual_time = 0.0 # emergent scheduler time
self.ops_per_tick = ops_per_tick # Time as RxJava scheduler: rate limit
self.aeon = 0
self.total_info_processed = 0
def allocate(self, data):
"""Cosmological Constant as memory allocator → dS expansion."""
current_size = len(self.ledger)
allocation = max(1, int(current_size * self.cosmological_constant) + 1)
for _ in range(allocation):
self.ledger.append(None) # expand boundary
# memcpy-style placement
if self.ledger:
idx = random.randint(0, len(self.ledger)-1)
self.ledger[idx] = data
else:
self.ledger.append(data)
print(f"[ALLOC Λ={self.cosmological_constant}] +{allocation} slots | '{data}' placed | size={len(self.ledger)}")
@cpc_guard()
def move_data(self, from_idx, to_idx):
"""Data movement (assignment/memcpy) under CPC guard."""
data = self.ledger[from_idx]
self.ledger[to_idx] = data
self.ledger[from_idx] = None
print(f"[MEMCPY t={self.virtual_time:.1f}] {from_idx} → {to_idx}")
return True
def scheduler_tick(self):
"""Time = RxJava virtual scheduler: controlled pace, limited work per tick."""
self.virtual_time += 1.0
ops_done = 0
print(f"\n[SCHEDULER t={self.virtual_time:.1f}] tick start — max {self.ops_per_tick} ops")
while ops_done < self.ops_per_tick and self.ledger:
if random.random() < 0.6 and len(self.ledger) > 1:
f = random.randint(0, len(self.ledger)-1)
t = random.randint(0, len(self.ledger)-1)
if f != t:
self.move_data(f, t)
ops_done += 1
self.total_info_processed += 1
else:
idx = random.randint(0, len(self.ledger)-1)
if self.ledger[idx] is not None:
self.ledger[idx] = f"proc_{self.ledger[idx]}"
ops_done += 1
self.total_info_processed += 1
print(f"[SCHEDULER] {ops_done} ops | total processed: {self.total_info_processed}")
def ccc_cycle(self):
"""Penrose CCC = garbage collector / compactor / zip on append-only ledger."""
print(f"\n[CCC AEON {self.aeon} → {self.aeon+1}] compressing ledger...")
serialized = pickle.dumps(list(self.ledger))
compressed = zlib.compress(serialized, level=9)
ratio = len(compressed) / len(serialized) if serialized else 1
print(f"[CCC] {len(serialized)} → {len(compressed)} bytes (ratio {ratio:.3f})")
# conformal reset to new low-entropy aeon
self.ledger = deque([f"aeon_{self.aeon}_seed"])
self.ledger.extend([None] * int(10 * self.cosmological_constant))
self.aeon += 1
self.virtual_time = 0.0 # time resets per aeon (emergent)
print(f"[CCC] new aeon ready | size={len(self.ledger)}")
def run_simulation(self, ticks=2, cycles=2):
print("=== Holographic dS/CFT Universe Simulation ===")
for c in range(cycles):
print(f"\n=== Aeon {c} ===")
self.allocate(f"bigbang_data_{c}")
for _ in range(ticks):
self.scheduler_tick()
self.ccc_cycle()
print(f"\n=== End of run ===\nAeons: {self.aeon} | Total info: {self.total_info_processed}")
# Run it
if __name__ == "__main__":
uni = HolographicUniverse(cosmological_constant=0.12, ops_per_tick=5)
uni.run_simulation(ticks=3, cycles=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment