Seal Phase 4AJ fixed APL timing hypothesis audit

This commit is contained in:
Digital Drosophila Archive
2026-09-30 12:08:25 +08:00
parent 8d6b063aaf
commit cb6937666f
1992 changed files with 258416 additions and 10 deletions
@@ -0,0 +1,87 @@
"""Pure NumPy reference for the fixed 0/18-step generated-APL output delay.
No brain dynamics, gain, float arithmetic or implicit tail advancement occurs
here. Pending rows are the next D application slots, including initial +0
padding if fewer than D samples have been generated.
"""
import numpy as np
class TimingQueue:
def __init__(self, delay_steps, width=4064):
if type(delay_steps) is not int or delay_steps not in (0, 18):
raise ValueError("delay_steps must be integer 0 or 18")
if type(width) is not int or width <= 0:
raise ValueError("width must be a positive integer")
self.delay_steps = delay_steps
self.width = width
self.steps = 0
self._ring = np.zeros((delay_steps, width), dtype=np.float32)
def push(self, generated, tick=None):
"""Return an owned f32 application row, without changing its bits."""
if tick is not None and (type(tick) is not int or tick != self.steps):
raise ValueError("tick must be the next consecutive integer tick")
if not isinstance(generated, np.ndarray) or generated.dtype != np.float32:
raise ValueError("generated must be a float32 ndarray")
if generated.shape != (self.width,) or not np.isfinite(generated).all():
raise ValueError("generated shape or finiteness invalid")
if np.any(generated < 0):
raise ValueError("generated inhibition must be nonnegative")
if self.delay_steps == 0:
applied = generated.copy()
else:
slot = self.steps % self.delay_steps
applied = self._ring[slot].copy()
self._ring[slot] = generated
self.steps += 1
return applied
def pending(self):
"""Owned rows in next-application order; always shape (D, width)."""
if self.delay_steps == 0:
return self._ring.copy()
head = self.steps % self.delay_steps
return np.concatenate((self._ring[head:], self._ring[:head]), axis=0)
def metadata(self):
return {"apl_delay_steps": self.delay_steps, "steps": self.steps,
"pending_generated_count": min(self.steps, self.delay_steps),
"pending_initial_zero_prefix": max(self.delay_steps - self.steps, 0),
"pending_application_tick_start": self.steps,
"pending_application_tick_stop_exclusive": self.steps + self.delay_steps,
"brain_tail_advanced": False}
def audit_sequence(generated, applied, pending, delay_steps):
"""Bitwise finite-sequence accounting; not a closed-loop integral claim.
Checks concat(applied, pending) == concat(D initial +0 rows, generated).
This preserves signed zeros and every stored sample, without assuming the
generated sequences of two different closed-loop branches are identical.
"""
if type(delay_steps) is not int or delay_steps not in (0, 18):
raise ValueError("delay_steps must be integer 0 or 18")
for name, value in (("generated", generated), ("applied", applied), ("pending", pending)):
if not isinstance(value, np.ndarray) or value.dtype != np.float32 or value.ndim != 2:
raise ValueError(name + " must be a rank-2 float32 ndarray")
if not np.isfinite(value).all() or np.any(value < 0):
raise ValueError(name + " must be finite nonnegative inhibition")
if generated.shape != applied.shape or pending.shape != (delay_steps, generated.shape[1]):
raise ValueError("Sequence shapes disagree")
steps = len(generated)
# Rowwise comparison avoids allocating a second T-by-K trace.
for tick in range(steps + delay_steps):
actual = applied[tick] if tick < steps else pending[tick - steps]
actual_bits = actual.view(np.uint32)
if tick < delay_steps:
ok = np.all(actual_bits == 0)
else:
ok = np.array_equal(actual_bits, generated[tick - delay_steps].view(np.uint32))
if not ok:
raise ValueError("Fixed-delay bitwise accounting failed at application tick " + str(tick))
return {"pass_all": True, "apl_delay_steps": delay_steps, "steps": steps,
"pending_generated_count": min(steps, delay_steps),
"pending_initial_zero_prefix": max(delay_steps - steps, 0),
"initial_padding_positive_zero": True, "sample_bits_preserved": True,
"brain_tail_advanced": False}