Research-Stack/5-Applications/tools-scripts/utils/generate_diat_tables.py
Devin AI e5f04ee6c3 refactor(infra): extract shared utilities from duplicated code patterns
Create 4-Infrastructure/lib/ with canonical implementations of:
- hashing.py: sha256_bytes, sha256_text, sha256_file
- q16.py: Q16_16 fixed-point constants and arithmetic
- jsonl.py: load_json, load_jsonl, write_jsonl, stable_json, canonical_json_bytes
- fraction_utils.py: Fraction serialization helpers for hardware probes

Refactor 66 files across 4-Infrastructure/{hardware,shim,infra} and
5-Applications/{scripts,tools-scripts,hutter_prize,text-to-cad} to import
from the shared library instead of maintaining local copies.

4-Infrastructure/auto/lib/q16.py now re-exports from lib.q16.

Net: -743 lines (490 added, 1233 removed)

Build: not applicable (Python-only change, py_compile verified on all 71 files)
Co-Authored-By: Allaun Silverfox <bigdataiscoming+9i37y6j2@protonmail.com>
2026-06-15 02:26:45 +00:00

28 lines
922 B
Python

import math
import sys
sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "4-Infrastructure"))
from lib.q16 import to_q16
def generate_mem_files():
# 256 entries, x = index / 16.0 (if we use ray_t[19:12] as addr)
# However, to avoid 1/0, we'll use x = max(0.0625, index / 16.0)
with open("0-Core-Formalism/core/hw/diat_inv_table.mem", "w") as f_inv, \
open("0-Core-Formalism/core/hw/diat_sqrt_table.mem", "w") as f_sqrt:
for i in range(256):
x = i / 16.0
if x == 0:
x = 1/16.0 # Smallest non-zero
y_inv = 1.0 / math.sqrt(x)
y_sqrt = math.sqrt(x)
f_inv.write(f"{to_q16(y_inv):08x}\n")
f_sqrt.write(f"{to_q16(y_sqrt):08x}\n")
print("Success: Generated diat_inv_table.mem and diat_sqrt_table.mem")
if __name__ == "__main__":
generate_mem_files()