Research source · python
check_cross_scale_receipts.py
tools/research/check_cross_scale_receipts.py
162 lines. Source is displayed for inspection; it is not executed by this page.
File fingerprint
SHA-256: 8811dda4f47d58d1c65c8024d3c6e69c404ba0fee19ce7552c9a71874f316387
#!/usr/bin/env python3
"""Independent finite controls for a failed unrestricted cross-scale extension.
The symbolic witness concerns only explicit, late-released insertion jobs.
Python sets represent semantic predicates, not a native graph implementation.
"""
import json
import random
def descending_witness(capacity, rate, overhead, final_jobs, contraction):
assert capacity >= 1 and rate >= 1 and overhead >= 0 and final_jobs >= 0 and contraction >= 2
later_symbols = 0
result = []
for _ in range(capacity + 1):
length = rate * later_symbols + final_jobs + 1
input_length = contraction * length
result.append((length, input_length, later_symbols))
later_symbols += input_length + overhead
result.reverse()
assert len({length for length, _, _ in result}) == capacity + 1
for i, (length, input_length, _) in enumerate(result):
available = rate * sum(v + overhead for _, v, _ in result[i + 1:]) + final_jobs
assert length > available
assert input_length >= 2 * length
# The shortest/newest receipt also cannot finish in the generously granted
# final allowance. All B+1 receipts are therefore unfinished simultaneously.
assert result[-1][0] > final_jobs
return result
def symbolic_audit():
cases = 0
largest = 0
for capacity in (1, 2, 4, 8, 16):
for rate in (1, 4, 32):
for overhead in (0, 13):
for final in (0, 7, 100):
for contraction in (2, 17, 1000):
witness = descending_witness(capacity, rate, overhead, final, contraction)
cases += 1
largest = max(largest, witness[0][1])
return cases, len(str(largest)), descending_witness(2, 4, 13, 17, 3)
def empty():
return frozenset(), tuple()
def logical(state):
committed, pending = state
return committed | frozenset(pending)
def transition(state, receipt, alias, budget):
committed, pending = state
# One abstract traversal job per word bit, plus one terminal macro job.
needed = sum(len(w) + 1 for w in pending)
if needed > budget:
return state, False
drained = committed | frozenset(pending)
return (state if alias else (drained, tuple(receipt))), True
def semantic_audit():
rng = random.Random(244)
table = {}
# Literal distinct intermediate names; every target is strictly shorter.
for i in range(100):
name_length = 9 + i % 30
v = format(i, '07b') + '1' + '0' * (name_length - 8)
receipt = []
for _ in range(1 + i % 3):
length = rng.randint(1, name_length - 1)
receipt.append(''.join(rng.choice('01') for _ in range(length)))
table[v] = tuple(dict.fromkeys(receipt))
assert len(table) == 100
states = {s: empty() for s in range(4)}
direct = {s: frozenset() for s in states}
history = []
accepted = rejected = snapshots = reads = 0
names = list(table)
for _ in range(900):
source = rng.randrange(4)
v = rng.choice(names)
alias = rng.randrange(2)
old = states[source]
# Explicit service-admissibility gate on this actual next name.
new, ok = transition(old, table[v], alias, len(v))
if ok:
accepted += 1
if not alias:
direct[source] = direct[source] | frozenset(table[v])
else:
rejected += 1
assert new == old
states[source] = new
assert logical(new) == direct[source]
history.append((new, direct[source]))
for state, expected in rng.sample(history, min(3, len(history))):
assert logical(state) == expected
snapshots += 1
for w in rng.choice(list(table.values())):
assert (w in state[0] or w in state[1]) == (w in expected)
reads += 1
assert accepted and rejected
# A very long pending word can be refuted by a short query immediately;
# backlog does not itself lower-bound exact readout in every representation.
assert '1' != '0' * 1000
return accepted, rejected, snapshots, reads, len(set(w for row in table.values() for w in row))
def late_class_audit():
# Symbolic M=2^J owners. Grant destination knowledge at the *start* of
# their distinguishing k-bit tail, and all tail/final jobs to routing.
# This tests the existing single serial current-window cursor only.
cases = 0
for rate in (1, 4, 16, 64):
for final in (0, 7, 100):
for exponent in range(6, 17):
j = 2 ** exponent
alternatives = j // 2
k = (alternatives - 1).bit_length()
destination = j // 4
distance = j - 1 - destination
budget = rate * k + final
if distance > budget:
assert destination < j / 2
assert distance - budget > 0
cases += 1
assert cases
return cases
def stale_handle_audit():
target = '01'
frozen = frozenset()
current_v0 = frozen
current_v1 = frozen | {target}
assert (target in current_v0) is False
assert (target in current_v1) is True
assert (target in frozen) is False # static target metadata was not updated
return 1
def main():
witnesses, digits, sample = symbolic_audit()
accepted, rejected, snapshots, reads, image = semantic_audit()
print(json.dumps({'seed': 244, 'symbolic_witnesses': witnesses,
'largest_input_length_decimal_digits': digits,
'example_B2_C4_overhead13_H17_Q3': sample,
'service_gate_accepted': accepted,
'service_gate_rejected': rejected,
'snapshot_checks': snapshots, 'membership_checks': reads,
'finite_target_image': image,
'stale_static_handle_controls': stale_handle_audit(),
'late_serial_class_route_cases': late_class_audit(),
'status': 'passed'}, indent=2))
if __name__ == '__main__':
main()