BioSight/python/equation_dna_encoder.py
allaun 41fcbc3daa feat(init): initial BioSight commit — equation-to-DNA Φ encoding
BioSight encodes mathematical equations as 30-base hachimoji DNA
sequences for Adleman/Lipton-style DNA computing.

4-layer Φ mapping:
  Layer 1: F(E) — byte-class histogram on Δ₇
  Layer 3: τ(E) + δ(E) — parse tree structure
  Layer 4: 6 consistency rules → allele-specific PCR pass/fail

Independent phi/ modules:
  charclass, ast_parse, consistency, embed, output

Build: python3 -m py_compile — all modules clean
2026-06-23 18:27:35 -05:00

43 lines
1.1 KiB
Python

#!/usr/bin/env python3
"""
equation_dna_encoder.py — SilverSight Φ Encoder CLI
Thin CLI wrapper around the phi package modules.
Usage:
echo 'd_F(p,q) = 2*arccos(sum(sqrt(p_i*q_i)))' | python equation_dna_encoder.py
python equation_dna_encoder.py 'E(x) = x^T Q x'
"""
from __future__ import annotations
import sys
from phi import encode_phi, to_fastq
def main():
if len(sys.argv) > 1:
equations = [" ".join(sys.argv[1:])]
else:
equations = [line.strip() for line in sys.stdin if line.strip()]
for eq in equations:
result = encode_phi(eq)
if result is None:
print(f"FAIL: could not parse: {eq!r}", file=sys.stderr)
continue
print(f"# Equation: {result['equation']}")
print(f"# DNA: {result['dna_sequence']} ({result['length']} bases)")
print(f"# PASS: {result['consistency_pass']}")
print(f"# Hash: {result['sha256_prefix']}")
print(f"# F: {result['F']}")
print(f"# τ: {result['tau']}")
print(f"# δ: {result['delta']}")
print(f"# FASTQ: {to_fastq(result).rstrip()}")
print()
if __name__ == "__main__":
main()