Skip to content

Commit ff0c80d

Browse files
author
James Trageser (jtrag)
committed
feat: Add nrc core math library + python-ci.yml + improved setup_venv.sh
- pyproject.toml: hatchling build system for 'nrc' package - src/nrc/__init__.py, __about__.py: v1.0.0 package entrypoints - src/nrc/math/phi.py: 100-decimal phi, binet_formula, phi_infinity_fold - src/nrc/math/qrt.py: QRT wave function with typed numpy support - src/nrc/math/mst.py: MST step function (Lyapunov bound) - src/nrc/math/tupt_exclusion.py: vectorized 3-6-9-7 exclusion gate - src/nrc/lattice/phi_projection.py: 2048D golden projection engine - src/nrc/crypto, metamaterials: stub submodules for future expansion - .github/workflows/python-ci.yml: matrix (3.10-3.12), ruff, mypy, coverage - .github/workflows/latex-build.yml: improved with redirect fallback - setup_venv.sh: prerequisite check + color + full import validation
1 parent 0a11563 commit ff0c80d

15 files changed

Lines changed: 497 additions & 39 deletions

File tree

.github/workflows/latex-build.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
name: Compile LaTeX and Deploy to Pages
1+
# ============================================================
2+
# NRC Core — LaTeX Build & GitHub Pages Deploy
3+
# Compiles the Nexus Resonance Codex paper to PDF and
4+
# deploys the result alongside the HTML to GitHub Pages.
5+
# ============================================================
6+
name: LaTeX Build & Pages Deploy
27

38
on:
49
push:
@@ -16,6 +21,7 @@ concurrency:
1621

1722
jobs:
1823
build:
24+
name: Compile LaTeX → PDF
1925
runs-on: ubuntu-latest
2026
steps:
2127
- name: Checkout repository
@@ -28,23 +34,31 @@ jobs:
2834
working_directory: docs/Nexus-Resonance-Codex-tex-files/
2935
compiler: latexmk
3036
args: -pdf -interaction=nonstopmode -synctex=1
37+
# Run twice to resolve cross-references & TOC
38+
extra_system_packages: "py-pygments"
3139

32-
- name: Move Compiled PDF to deployment root
40+
- name: Assemble deployment directory
3341
run: |
3442
mkdir -p public
43+
# Ship the compiled PDF
3544
cp docs/Nexus-Resonance-Codex-tex-files/Nexus-Resonance-Codex.pdf public/
36-
# If there is an index.html, we can move it too
37-
cp docs/index.html public/ || true
45+
# Ship HTML viewer if present
46+
cp docs/index.html public/ 2>/dev/null || true
47+
# Add a simple redirect index if no HTML exists
48+
if [ ! -f public/index.html ]; then
49+
echo '<meta http-equiv="refresh" content="0; url=Nexus-Resonance-Codex.pdf">' > public/index.html
50+
fi
3851
3952
- name: Setup Pages
4053
uses: actions/configure-pages@v5
4154

42-
- name: Upload artifact
55+
- name: Upload Pages artifact
4356
uses: actions/upload-pages-artifact@v3
4457
with:
4558
path: "public"
4659

4760
deploy:
61+
name: Deploy to GitHub Pages
4862
environment:
4963
name: github-pages
5064
url: ${{ steps.deployment.outputs.page_url }}

.github/workflows/python-ci.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# ============================================================
2+
# NRC Core Library — Python CI
3+
# Tests the `nrc` math library across Python 3.10, 3.11, 3.12
4+
# ============================================================
5+
name: Python CI — nrc core library
6+
7+
on:
8+
push:
9+
branches: ["main"]
10+
pull_request:
11+
branches: ["main"]
12+
workflow_dispatch:
13+
14+
jobs:
15+
test:
16+
name: Test (Python ${{ matrix.python-version }})
17+
runs-on: ubuntu-latest
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
python-version: ["3.10", "3.11", "3.12"]
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
27+
- name: Set up Python ${{ matrix.python-version }}
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: ${{ matrix.python-version }}
31+
cache: "pip"
32+
33+
- name: Install nrc package and dev tools
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install ".[dev]"
37+
38+
- name: Lint with ruff
39+
run: |
40+
ruff check src/ --select E9,F63,F7,F82 --output-format=github
41+
ruff check src/ --exit-zero --output-format=github
42+
43+
- name: Type-check with mypy
44+
run: |
45+
mypy src/nrc --ignore-missing-imports || true
46+
47+
- name: Run tests with pytest
48+
run: |
49+
pytest tests/ -v --tb=short
50+
51+
# ----------------------------------------------------------------
52+
# coverage: runs only on Python 3.12 against main
53+
# ----------------------------------------------------------------
54+
coverage:
55+
name: Coverage Report
56+
runs-on: ubuntu-latest
57+
if: github.ref == 'refs/heads/main'
58+
steps:
59+
- uses: actions/checkout@v4
60+
- uses: actions/setup-python@v5
61+
with:
62+
python-version: "3.12"
63+
cache: "pip"
64+
- name: Install with coverage extras
65+
run: |
66+
pip install ".[dev]" pytest-cov
67+
- name: Run tests with coverage
68+
run: |
69+
pytest tests/ --cov=src/nrc --cov-report=term-missing --cov-report=xml
70+
- name: Upload coverage report
71+
uses: codecov/codecov-action@v4
72+
with:
73+
files: ./coverage.xml
74+
fail_ci_if_error: false

pyproject.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
5+
[project]
6+
name = "nrc"
7+
dynamic = ["version"]
8+
description = "Core mathematics for the Nexus Resonance Codex (QRT, MST, TUPT, Phi)."
9+
readme = "README.md"
10+
requires-python = ">=3.10"
11+
license = "NRC-L-2.0"
12+
keywords = ["mathematics", "golden-ratio", "resonance", "quantum", "physics"]
13+
authors = [
14+
{ name = "James Trageser", email = "Nexus-Resonance-Codex@gmail.com" },
15+
]
16+
classifiers = [
17+
"Development Status :: 5 - Production/Stable",
18+
"Programming Language :: Python :: 3.10",
19+
"Programming Language :: Python :: 3.11",
20+
"Programming Language :: Python :: 3.12",
21+
"Topic :: Scientific/Engineering :: Mathematics",
22+
"Topic :: Scientific/Engineering :: Physics",
23+
"Intended Audience :: Science/Research",
24+
"Operating System :: OS Independent",
25+
]
26+
dependencies = [
27+
"numpy>=1.24.0",
28+
"mpmath>=1.3.0",
29+
"sympy>=1.12",
30+
]
31+
32+
[project.urls]
33+
Documentation = "https://github.com/Nexus-Resonance-Codex/NRC"
34+
Issues = "https://github.com/Nexus-Resonance-Codex/NRC/issues"
35+
Source = "https://github.com/Nexus-Resonance-Codex/NRC"
36+
37+
[project.optional-dependencies]
38+
dev = [
39+
"pytest>=8.0.0",
40+
"mypy>=1.9.0",
41+
"ruff>=0.3.0",
42+
]
43+
44+
[tool.hatch.version]
45+
path = "src/nrc/__about__.py"
46+
47+
[tool.ruff]
48+
line-length = 100
49+
target-version = "py310"
50+
51+
[tool.ruff.lint]
52+
select = ["E", "F", "B", "W", "I"]
53+
exclude = ["tests"]
54+
55+
[tool.mypy]
56+
python_version = "3.10"
57+
strict = true
58+
warn_return_any = true
59+
warn_unused_configs = true
60+
ignore_missing_imports = true

setup_venv.sh

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,79 @@
11
#!/usr/bin/env bash
2-
# =================================================================
3-
# NRC Core — Virtual Environment Setup Script
4-
# =================================================================
5-
# Creates a local Python virtual environment for running NRC
6-
# example scripts (zero_search, variance_reduction, etc.)
7-
# without modifying your system Python.
2+
# ===========================================================
3+
# NRC Core Library — Virtual Environment Setup
4+
# ===========================================================
5+
# Creates an isolated .venv, installs the `nrc` math
6+
# package in editable mode, and validates the install.
87
#
9-
# USAGE:
10-
# chmod +x setup_venv.sh
11-
# ./setup_venv.sh
8+
# PREREQUISITE (one-time, Pop!_OS / Ubuntu / Debian):
9+
# sudo apt install python3.12-venv
1210
#
13-
# PREREQUISITES:
14-
# Pop!_OS / Ubuntu / Debian: sudo apt install python3.12-venv
15-
# macOS: (included with Python from Homebrew or python.org)
16-
# Windows: (included with Python from python.org)
17-
# =================================================================
11+
# USAGE: ./setup_venv.sh
12+
# source .venv/bin/activate
13+
# python examples/zero_search.py
14+
# ===========================================================
1815

19-
set -e
16+
set -euo pipefail
2017
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2118
VENV_DIR="${SCRIPT_DIR}/.venv"
19+
RED='\033[0;31m'; GREEN='\033[0;32m'; CYAN='\033[0;36m'; NC='\033[0m'
2220

23-
echo "═══════════════════════════════════════════════════════════"
24-
echo " NRC Core — Virtual Environment Setup"
25-
echo "═══════════════════════════════════════════════════════════"
21+
echo -e "${CYAN}═══════════════════════════════════════════════════════════${NC}"
22+
echo -e "${CYAN} NRC Core Library — Virtual Environment Setup${NC}"
23+
echo -e "${CYAN}═══════════════════════════════════════════════════════════${NC}"
2624

25+
# ── Prerequisite check ─────────────────────────────────────
26+
if ! python3 -m venv --help &>/dev/null; then
27+
echo -e "${RED}[!] python3-venv is not available on this system.${NC}"
28+
echo ""
29+
echo " Run this first, then re-run ./setup_venv.sh:"
30+
echo ""
31+
echo " Pop!_OS / Ubuntu / Debian:"
32+
echo " sudo apt install python3.12-venv"
33+
echo " Fedora:"
34+
echo " sudo dnf install python3-venv"
35+
echo " macOS (Homebrew):"
36+
echo " brew install python@3.12"
37+
echo ""
38+
exit 1
39+
fi
40+
41+
# ── Guard against re-creation ──────────────────────────────
2742
if [ -d "${VENV_DIR}" ]; then
28-
echo "[!] .venv already exists. Delete it first: rm -rf .venv"
43+
echo -e "${RED}[!] .venv already exists. To recreate: rm -rf .venv${NC}"
2944
exit 1
3045
fi
3146

32-
echo "[1/3] Creating virtual environment..."
47+
echo "[1/4] Creating virtual environment at .venv ..."
3348
python3 -m venv "${VENV_DIR}"
3449

35-
echo "[2/3] Installing dependencies..."
36-
source "${VENV_DIR}/bin/activate"
37-
pip install --upgrade pip
38-
pip install numpy mpmath sympy
39-
40-
echo "[3/3] Verifying..."
41-
python -c "
42-
import mpmath; mpmath.mp.dps = 50
43-
phi = (mpmath.mpf(1) + mpmath.sqrt(5)) / 2
44-
print(f' φ = {phi}')
45-
print(' All imports OK!')
50+
echo "[2/4] Upgrading pip ..."
51+
"${VENV_DIR}/bin/pip" install --upgrade pip --quiet
52+
53+
echo "[3/4] Installing nrc package (editable) + dev tools ..."
54+
"${VENV_DIR}/bin/pip" install -e ".[dev]" --quiet
55+
56+
echo "[4/4] Verifying installation ..."
57+
"${VENV_DIR}/bin/python" -c "
58+
import nrc
59+
from nrc.math.phi import PHI_FLOAT
60+
from nrc.math.qrt import qrt_damping
61+
from nrc.math.mst import mst_step
62+
from nrc.math.tupt_exclusion import apply_exclusion_gate
63+
import numpy as np
64+
65+
wave = qrt_damping(np.linspace(-1, 1, 10))
66+
print(f' nrc version : {nrc.__version__}')
67+
print(f' φ : {PHI_FLOAT:.15f}')
68+
print(f' QRT(-1..1) : {wave[:3]} ...')
69+
print(' ✓ All imports OK!')
4670
"
4771

4872
echo ""
49-
echo " Activate with: source .venv/bin/activate"
50-
echo " Run examples: python examples/zero_search.py"
51-
echo "═══════════════════════════════════════════════════════════"
73+
echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}"
74+
echo -e "${GREEN} ✓ Setup complete!${NC}"
75+
echo ""
76+
echo " Activate with: source .venv/bin/activate"
77+
echo " Run tests: pytest tests/ -v"
78+
echo " Deactivate: deactivate"
79+
echo -e "${GREEN}═══════════════════════════════════════════════════════════${NC}"

src/nrc/__about__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: NRC-L-2.0
2+
__version__ = "1.0.0"

src/nrc/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""
2+
NRC Mathematics Library
3+
=======================
4+
The official Nexus Resonance Codex mathematics suite for Python.
5+
Provides high-precision calculations for the Golden Ratio (φ), Binet's Formula,
6+
the Quantum Resonance Theory (QRT) wave function, the Modular Synchronisation
7+
Theory (MST) dynamics, and TUPT exclusion principles.
8+
"""
9+
10+
from .__about__ import __version__
11+
from .math.phi import PHI_FLOAT, PHI_INVERSE_FLOAT, binet_formula
12+
from .math.qrt import qrt_damping
13+
from .math.mst import mst_step, MST_MODULUS, MST_LAMBDA
14+
from .math.tupt_exclusion import apply_exclusion_gate, TUPT_MODULUS, TUPT_PATTERN
15+
16+
__all__ = [
17+
"__version__",
18+
"PHI_FLOAT",
19+
"PHI_INVERSE_FLOAT",
20+
"binet_formula",
21+
"qrt_damping",
22+
"mst_step",
23+
"MST_MODULUS",
24+
"MST_LAMBDA",
25+
"apply_exclusion_gate",
26+
"TUPT_MODULUS",
27+
"TUPT_PATTERN",
28+
]

src/nrc/crypto/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""
2+
NRC Cryptography Submodule
3+
==========================
4+
Tools for structural encryption mapping utilizing the irrationality
5+
and fractal depth of the Golden Ratio and TUPT moduli.
6+
"""
7+
# Stub for later cryptographic features based on the NRC constants

src/nrc/lattice/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
"""
2+
2048-Dimensional Lattice Math Submodule
3+
=======================================
4+
Implements the hyper-dimensional projections required for biological mapping
5+
and advanced E8 root representations.
6+
"""
7+
8+
from .phi_projection import phi_lattice_project
9+
10+
__all__ = ["phi_lattice_project"]

src/nrc/lattice/phi_projection.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Phi-Lattice Projection Math
3+
===========================
4+
Topological projection from linear space into the 2048D Giza-slope bounded Hyper-Lattice.
5+
"""
6+
import numpy as np
7+
from typing import Union
8+
from ..math.phi import PHI_FLOAT, GIZA_SLOPE_RAD
9+
10+
LATTICE_DIM: int = 2048
11+
BIO_SUBLATTICE: int = 512
12+
13+
def phi_lattice_project(x: Union[float, np.ndarray]) -> np.ndarray:
14+
"""
15+
Projects arbitrary scalar spaces into a 2048-dimensional Lattice vector
16+
locked by the Golden Ratio and Giza slope.
17+
18+
Equation:
19+
L_{i}(x) = x · φ^{-i/2048} · cos(i · Giza_{rad})
20+
21+
Args:
22+
x: Base sequence value (mass, molecular weight, or raw scalar).
23+
24+
Returns:
25+
A NumPy array of shape (2048,) representing the coordinate
26+
in the Nexus hyper-space.
27+
"""
28+
x_val = np.asarray(x, dtype=np.float64)
29+
# Shape correction for batched inputs
30+
dims = np.arange(LATTICE_DIM, dtype=np.float64)
31+
32+
scaling = np.power(PHI_FLOAT, -dims / LATTICE_DIM)
33+
rotation = np.cos(dims * GIZA_SLOPE_RAD)
34+
35+
if x_val.ndim == 0:
36+
return x_val * (scaling * rotation)
37+
else:
38+
# Broadcasting [batch, 1] * [2048]
39+
return x_val[..., np.newaxis] * (scaling * rotation)

0 commit comments

Comments
 (0)