From 3dc721a2d5bd9227b93a6b1f447c9555f817c846 Mon Sep 17 00:00:00 2001 From: Allaun Silverfox <28494262+allaunthefox@users.noreply.github.com> Date: Tue, 23 Jun 2026 06:35:26 -0500 Subject: [PATCH] =?UTF-8?q?feat(engine):=20R1=20token=20normalization=20?= =?UTF-8?q?=E2=80=94=20all=20operands=20to=20V,=20digits=20to=20N.=203-age?= =?UTF-8?q?nt=20verified.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/silversight_engine.py | 41 +++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/python/silversight_engine.py b/python/silversight_engine.py index 44550a2f..2d728610 100644 --- a/python/silversight_engine.py +++ b/python/silversight_engine.py @@ -19,6 +19,7 @@ Usage: print(f"Classified as: {concept.name} (d={distance:.6f})") """ +import re import numpy as np from typing import List, Tuple, Optional, Dict from dataclasses import dataclass, field @@ -35,6 +36,27 @@ PHI = (1 + np.sqrt(5)) / 2 PSI = 2 * np.pi / (PHI ** 2) +# ============================================================ +# R1: TOKEN NORMALIZATION [VERIFIED: all 4 test cases identical] +# ============================================================ + +def normalize(s: str) -> str: + """R1 structural reinforcement: normalize surface variation. + + Rules: + 1. Lowercase everything + 2. Replace all digit sequences with 'N' + 3. Replace all letter names with 'V' + + Verified: "A+B=C", "a+b=c", "foo+bar=baz", "123+456=579" + all produce F = [0, 0.2, 0, 0.2, 0.6, 0, 0, 0] (3 agents). + """ + s = s.lower() + s = re.sub(r'[0-9]+', 'N', s) + s = re.sub(r'[a-z]+', 'V', s) + return s + + # ============================================================ # BYTE CLASSIFICATION # ============================================================ @@ -61,12 +83,14 @@ def byte_class(c: str) -> int: # ============================================================ def F(string: str) -> np.ndarray: - """Byte-frequency probability vector [VERIFIED]. + """Byte-frequency probability vector [VERIFIED: 008, R1]. Maps string → Δ₇ (8-dim probability simplex). + Uses R1 normalization before counting. """ + norm = normalize(string) counts = [0] * 8 - for c in string: + for c in norm: counts[byte_class(c)] += 1 total = sum(counts) return np.array(counts) / total if total > 0 else np.zeros(8) @@ -330,12 +354,13 @@ class SilverSight: return dist > threshold, dist def _detect_operator(self, equation: str) -> str: - """Simple operator detection from equation string.""" - if '+' in equation: return "addition" - if '/' in equation: return "division" - if '*' in equation: return "multiplication" - if '-' in equation: return "subtraction" - if '=' in equation: return "equality" + """Detect dominant operator from equation string.""" + norm = normalize(equation) + if '+' in norm: return "addition" + if '/' in norm: return "division" + if '*' in norm: return "multiplication" + if '-' in norm: return "subtraction" + if '=' in norm: return "equality" return "literal" def summary(self):