Full text
PhaseBridge: Strict Discrete ↔Phase Mapping as a Foundation for Cognitive Systems Anton Fedotov SynqraTech anvifedoto[email protected] ORCID: 0009-0004-2313-6530 Sergey Efimov SynqraTech se.de.efimo[email protected] October 3, 2025 Abstract Data pipelines increasingly span heterogeneous modalities (time series, images, tokens), storage formats, and processing stacks, which complicates reliable interchange and validation across systems. We present PhaseBridge, a minimal, strict, and lossless interpreter that maps discrete symbols to a continuous phase representation and back, enabling a uniform interchange layer with verifiable round-trip guarantees. The core mapping is n∈ { 0 , . . . , M − 1 } 7→ θ = 2 πn/M with nearest-grid decoding; phases are stored as IEEE-754 float64 and validated by a lightweight schema. We define the Phase Interchange Format (PIF), provide a reference SDK and CLI, and introduce a coherence metric κ as a read-only diagnostic signal available uniformly across modalities. We demonstrate feasibility on time series and 8-bit images, and outline a roadmap for additional adapters. The aim is not to replace domain-specific encodings, but to offer a small, dependable core that supports strict round-trip, integrity checks, and unified diagnostics where a common representational substrate benefits cognitive and data-analysis workflows. 1 Introduction Modern data systems routinely integrate heterogeneous sources—discrete time series, tabular records, images, token streams—each carried by different on-wire formats (e.g., CSV/JSON/Parquet) and processed by modality-specific tooling. While these formats serve storage and transport well, they do not by themselves provide a uniform representational substrate that can support strict round-trip guarantees, lightweight runtime validation, and cross-modal diagnostics in a common space. As pipelines become more compositional and model-centric, the absence of such a substrate introduces friction: fragile adapters, 1
inconsistent semantics, and difficulty verifying that transformations are strictly reversible where required. This work. We introduce PhaseBridge, a minimal lossless interpreter that maps between a discrete alphabet and a continuous phase space. The core mapping is defined by a fixed alphabet size M∈Nand n∈ {0, . . . , M −1}←→θ=2π Mn∈[0,2π), with decoding by nearest grid point, ˆn= roundM 2πθmod M, (2) and phases stored in IEEE-754 float64 wrapped to [0 , 2 π ). On top of this mapping, we define a compact Phase Interchange Format (PIF) with a minimal schema (alphabet and optional metadata), runtime validation, and an integrity hook via SHA-256 of the original raw byte stream. We further expose a modality-agnostic diagnostic signal—the circular coherence metric κ = 1 NPjeiθj∈ [0 , 1] (and its windowed form)—which can be computed uniformly across modalities without altering data. Motivation. The goal is a small, dependable core that can serve as a stable interchange layer in cognitive and data-analysis workflows: strict reversibility when needed; explicit separation of concerns between conversion and any subsequent processing; and a simple, uniform diagnostic available everywhere. This is conceptually akin to how UTF-8 provides a tiny, strict core for textual interchange: not a replacement for all domain encodings, but a common basis that reduces friction and ambiguity across systems. Scope. PhaseBridge targets settings where (i) lossless round-trip is a functional requirement for the declared alphabet; (ii) integrity verification and lightweight runtime validation are valuable; and (iii) a uniform diagnostic signal aids monitoring and analysis. We demonstrate feasibility on time series and 8-bit grayscale images, and outline adapters for additional modalities. Domain-specific encodings and formats remain appropriate for their respective tasks; the proposed layer complements them by offering a strict, verifiable representational bridge. Contributions. • A strict, lossless discrete ↔ phase mapping with nearest-grid decoding and float64 storage, with discussion of numerical considerations. • The Phase Interchange Format (PIF): a minimal schema, runtime validation, and integrity checks via hash_raw. 2
•A reference SDK and CLI (encode/decode/validate/κ), plus conformance tests. • Uniform coherence diagnostics ( κ and windowed κ ) applicable across modalities without modifying data. •Case studies on time series and images, and a roadmap for additional adapters. 2 Mathematical Foundations Alphabet and mapping. Fix an alphabet size M∈N , M≥ 2, and define the discrete alphabet AM={0,1,...,M −1}. The core mapping is f:AM→[0,2π), f(n) = θ=2π Mn, (3) with decoding by nearest grid point on the uniform lattice {2πk/M}M−1 k=0 : g: [0,2π)→ AM, g(θ) = ˆn= roundM 2πθmod M. (4) We also use the wrap operator wrap2π ( · )mapping angles to [0 , 2 π )by modulo 2 π , with the convention that values numerically equal to 2πare set to 0. Lossless round-trip (exact arithmetic). In exact arithmetic, g ( f ( n )) = n for all n∈ AM . Indeed, f ( n ) = 2 πn/M is exactly a lattice point; scaling by M/ (2 π )yields n , and rounding to the nearest integer returns n(ties do not occur). Invariances. Let ∆=2 π/M be the lattice step. For any k∈Z , wrap2π ( θ + k ∆) decodes to ( n + k ) mod M . Moreover, adding multiples of 2 π leaves decoding invariant: g(wrap2π(θ+ 2πℓ))=g(θ)for all ℓ∈Z. 2.1 Finite-precision analysis (IEEE-754 float64) In implementation, θ is stored as IEEE-754 float64. We analyze correctness when (3) – (4) are computed in binary64 with round-to-nearest. We use the standard rounding model [ 2 ]: for a basic operation ◦∈{ + ,−,×, /} , fl ( a◦b )=( a◦b )(1 + δ )with |δ| ≤ u , where u = 2 −53 ≈ 1 . 11 × 10 −16 is machine epsilon (unit roundoff). For a short sequence of k such operations, the accumulated relative error is bounded by γk=ku/(1 −ku). 3
Encoding error. Compute ˜ θ = fl2π Mn . For 0 ≤n≤M− 1,0 ≤θ≤ 2 π . Assuming (2π)is a fixed binary64 constant, and one multiplication and one division, |˜ θ−θ| ≤ γ2θ+|fl(2π)−2π|n M≤C u, (5) for a modest constant C (empirically C < 10 suffices on typical compilers; the absolute error is O(u)uniformly because θ≤2π). Decoding correctness condition. Let ∆=2 π/M . Decoding by (4) is correct provided the absolute error at decode input is less than ∆/2: ˜ θ−θ<∆ 2=π M.(6) Since |˜ θ−θ| ≤ Cu and π/M ≥π/ 2 32 ≈ 7 . 3 × 10 −10 for M≤ 2 32 , while Cu ≲ 10 −15 , inequality (6) holds with a margin exceeding 105for all M≤232. [Binary64 correctness for M≤ 2 32 ] Let ˜ θ = wrap2πfl (2 πn/M ) be computed in IEEE-754 binary64 with round-to-nearest, and let decoding be ˆn = round ( M˜ θ/ (2 π )) mod M computed in binary64. Then for all integers Mwith 2≤M≤232 and for all n∈ {0, . . . , M −1}, ˆn=n. Proof sketch. By the rounding model, the absolute encoding error |˜ θ−θ| is bounded by Cu for a small constant C independent of M and n , since θ≤ 2 π . The nearest-neighbor lattice spacing is ∆ = 2 π/M , so the mid-point gap is ∆ / 2 = π/M . For M≤ 2 32 , π/M ≫Cu ; thus ˜ θ remains within the Voronoi cell of the true lattice point and rounding recovers n . The subsequent scaling by M/ (2 π )preserves classification because it is monotone and computed with comparable (smaller) absolute error. Wrapping convention. We implement wrap2π ( ˜ θ ) = ˜ θmod (2 π )and, for numerical stability, map values numerically equal to 2 π (within machine epsilon) to 0to maintain the half-open interval [0,2π). 2.2 Coherence metric κ Given phases {θj}N j=1 ⊂[0,2π), define the (unweighted) circular coherence κ= 1 N N X j=1 eiθj ∈[0,1].(7) 4
For nonnegative weights wj≥0with S=Pjwj>0, the weighted version is κw= 1 S N X j=1 wjeiθj .(8) We also consider a windowed version along an index axis (e.g., time). For window size W and hop H , define windows Wk = {t : kH ≤t≤kH + W− 1 } for k = 0 , . . . , K − 1where K=(N−W)/H+ 1, centers ck=kH + (W−1)/2, and κ(k)= 1 |Wk|Pt∈Wkeiθt,unweighted, Pt∈Wkwteiθt Pt∈Wkwt ,weighted (if wavailable).(9) If W > N, we define a single window W0={0, . . . , N −1}. 3 Phase Interchange Format (PIF) PIF is a compact, minimally constrained object describing the phase representation and its decoding context. We model a PIF record as a tuple p= (schema, θ, amp,meta), where θ∈RN (stored as float64), amp ∈ {scalar a≥ 0 }∪RN ≥0 (optional weighting), and the remaining fields are JSON objects with the following semantics. 3.1 Schema The schema object declares at least the alphabet: •schema.alphabet.type "uint" (required). •schema.alphabet.M integer, 2≤M≤232 (required). Optional, non-normative fields may be included for downstream use (do not affect lossless conversion), e.g., •schema.sampling.fs number, >0(sampling frequency). •schema.image.{height,width,mode} for image-shaped data. PIF v1 core treats unspecified fields as opaque; producers may include additional metadata that does not alter the conversion semantics. 5
3.2 Numeric representation • Phases θ : stored as IEEE-754 float64, wrapped to [0 , 2 π ), with the wrapping convention of §2.1. • Amplitude amp : either a nonnegative scalar (interpreted as unweighted) or a nonnegative array of length N(used as weights for κw). 3.3 Meta and integrity The meta object includes: •meta.note string, matching "no_processing" or "processed:<ops>" (required). •meta.hash_raw optional string of the form "sha256:<64 hex>" : the SHA-256 of the original raw byte stream (e.g., the discrete input array). •meta.codec optional string naming the codec (e.g., S1_phase_code_M256). •meta.codec_hash optional string "sha256:<64 hex>" identifying the codec payload. When meta.note is "no_processing" , the round-trip invariant must hold for the declared M: decode(encode(x))=x(bit-exact for the alphabet). Consumers can verify integrity by decoding to x and comparing meta.hash_raw to sha256 ( x.bytes ). 3.4 Serialization and validation Normative on-wire format. PIF v1 uses JSON as the normative on-wire representation (numbers as JSON numbers corresponding to float64 in implementations). A MessagePack representation may be provided as an optional, byte-compact mirror; it must be semantically equivalent to the JSON form. Validation. Validation proceeds in two layers: 1. Schema check (optional but recommended): JSON Schema validation of the document shape and basic constraints (e.g., alphabet.type="uint" , bounds on M , nonnegativity of amp). 2. Runtime check: load into a PIF object with strict checks on numeric invariants (float64 phases wrapped to [0,2π), matching lengths of θand array amp, etc.). If meta.hash_raw is present, consumers should verify it after decode. 6
Determinism. Given fixed schema.alphabet.M and meta.note="no_processing" , the encode/decode operations are deterministic; by Lemma 2.1, binary64 computations recover the original symbols for all M≤232. 4 Implementation We release a reference implementation at: https://github.com/synqratech/phasebridge The repository provides a Python SDK, CLI tools, schemas, examples, and conformance tests. 4.1 SDK (Python) The SDK exposes the strict discrete↔phase codec and core utilities: •S1PhaseCodec: lossless mapping n↔θwith nearest-grid decoding; float64 storage. •PIF: a dataclass for Phase Interchange Format records with runtime validation. •kappa_timeseries,kappa_timeseries_windowed: coherence metrics (§2.2). •Utilities: SHA-256 helpers (hash_raw), dtype selection, phase wrapping. A minimal usage example: from phasebridge.codec_s1 import S1PhaseCodec from phasebridge.pif import PIF from phasebridge.kappa import kappa_timeseries codec = S1PhaseCodec(M=256) x = ... # uint array in [0..M-1] schema = {"alphabet": {"type": "uint", "M": 256}} p = codec.encode(x, schema) # -> PIF (theta float64) x_rec = codec.decode(p) # -> original symbols (lossless) k = kappa_timeseries(p) # -> coherence in [0,1] 4.2 CLI tools Command-line utilities support encode/decode/validate and diagnostics: •pb-encode: raw (bin/csv/npy)→PIF (json/msgpack). 7
•pb-decode: PIF →raw (bin/csv/npy). •pb-validate : schema/runtime validation, decode, hash checks; optional raw comparison. •pb-kappa: compute global or windowed κ. Example: # Encode CSV(uint) -> PIF(JSON) pb-encode --in series.csv --in-fmt csv --dtype uint8 --M 256 > series.pif.json # Validate + compare with raw pb-validate --in series.pif.json --raw series.csv --in-fmt csv --dtype uint8 --report json # (windowed) pb-kappa --in series.pif.json --win 256 --hop 128 --fmt csv > kappa_windowed.csv 4.3 Testing and conformance The test suite covers: •Strict round-trip invariants for declared alphabets (§2). •κbounds and windowed profiling on synthetic signals. •Schema/runtime validation (PIF loading, wrapping, type checks). •Property-based tests (Hypothesis) across Mand random arrays. Tests can be reproduced via pytest ; property-based tests are enabled when hypothesis is installed. 5 Experiments and Case Studies We present three compact case studies illustrating lossless round-trip, integrity checks, and uniform diagnostics across modalities. Reproduction scripts are provided in examples/ and notebooks in demo/. 5.1 Time series round-trip and windowed coherence We synthesize a discrete time series in [0 , M − 1], encode to PIF, decode to CSV, and verify bit-exact equality and hash_raw consistency. We also compute windowed κ to illustrate coherence as a simple health indicator. 8
Figure 1: Discrete (quantized) time series used in the round-trip experiment. Left: signal overview; Right: zoomed segment. 9
References [1] K. V. Mardia and P. E. Jupp. Directional Statistics. Wiley, 2000. [2] N. J. Higham. Accuracy and Stability of Numerical Algorithms. SIAM, 2nd edition, 2002. [3] J.-P. Lachaux, E. Rodriguez, J. Martinerie, and F. J. Varela. Measuring phase synchrony in brain signals. Human Brain Mapping, 8(4):194–208, 1999. [4] N. I. Fisher. Statistical Analysis of Circular Data. Cambridge University Press, 1995. [5] T. Bray. The JavaScript Object Notation (JSON) Data Interchange Format. RFC 8259, IETF, 2017. https://www.rfc-editor.org/rfc/rfc8259 [6] F. Yergeau. UTF-8, a transformation format of ISO 10646. RFC 3629, IETF, 2003. https://www.rfc-editor.org/rfc/rfc3629 [7] Apache Parquet. Columnar storage format (project documentation). https://parquet. apache.org/ (accessed 2025). [8] K. Claessen and J. Hughes. QuickCheck: A lightweight tool for random testing of Haskell programs. In Proc. ICFP, pages 268–279. ACM, 2000. 16