/docs — the short path

Docs

The concept in 60 seconds

Every time an LLM thinks, the reasoning is reconstructed from token statistics. NPCoT replaces that with: think once, cache the program, look it up forever. A library entry is a 5-tuple (init, transform, reduce, post_scale, offset)plus a normalized hidden-state signature. Lookups are cosine similarity, execution is a length-L arithmetic loop. Total cost per reasoning step at inference: ~4 ns.

Use the hosted API

The full nsynth synthesizer runs as a public, scale-to-zero service. Two endpoints, both CORS-open, both deterministic — examples or a prompt go in, a program that was verified against every example comes back, or an honest refusal. No key, no LLM in the loop.

Examples in (synthesize)

curl -s https://ncpu-synthesis-api-274639560572.us-central1.run.app/synthesize \
  -H 'Content-Type: application/json' \
  -d '{"name": "max_two", "examples": [
        {"inputs": [3, 9], "expected": 9},
        {"inputs": [12, 4], "expected": 12},
        {"inputs": [-5, -2], "expected": -2}]}'
# → {"success": true, "method": "search_max2_formula",
#    "code": "fn max_two(a: i64, b: i64) -> i64 { ... }",
#    "transpiled": {"python": "...", "rust": "...", "typescript": "..."},
#    "elapsed_ms": 17.4}

Prompt in (natural language)

curl -s https://ncpu-synthesis-api-274639560572.us-central1.run.app/prompt \
  -H 'Content-Type: application/json' \
  -d '{"prompt": "def add(a, b):\n  \"\"\"Return the sum.\"\"\"\n add(1,2) -> 3\n add(10,-5) -> 5"}'
# A deterministic parser extracts the I/O pairs from asserts, doctests,
# arrow notation, or "returns" prose — then the cascade solves + verifies.
# → {"success": true, "method": "template_match", "entry_point": "add",
#    "io_pairs": 2, "code": "def add(a, b):\n    return a + b", ...}

Supported types: i64, [i64], and string inputs; integer output. GET /health reports the backend; GET /stats reports the three persistent memory banks. First request after idle cold-starts in ~10 s; warm repeats of a solved problem return from the cache in milliseconds. Or skip the network entirely — the same engine runs in your browser on the demo page.

Architecture

1 · Train (one-time, GPU)

from ncpu.self_optimizing.array_executable_thought_head import (
    ArrayExecutableThoughtHead, ArrayExecutableThoughtHeadConfig,
    build_array_thought_smoke_batch, run_array_thought_smoke_train,
)
head = ArrayExecutableThoughtHead(ArrayExecutableThoughtHeadConfig(hidden_dim=16))
hidden, arrays, lengths, targets, _ = build_array_thought_smoke_batch(
    hidden_dim=16, samples_per_op=12, operations=("sum", "min"),
)
run_array_thought_smoke_train(
    head, hidden_state=hidden, array_inputs=arrays,
    lengths=lengths, targets=targets, steps=500,
)

2 · Crystallize into the library (gradient-free)

from ncpu.self_optimizing.program_library_session import (
    ProgramLibrarySession, ProgramLibrarySessionConfig,
)
session = ProgramLibrarySession(
    ProgramLibrarySessionConfig(
        library_path="~/.nCPU_program_library.json",
        convergence_gap_threshold=1.0,
    )
)
session.begin_task("demo")
session.apply_converged_program(head, hidden, arrays, lengths=lengths)
summary = session.end_task()

3 · Consult at inference (CPU, WASM, or embedded)

# Python
from ncpu.self_optimizing.array_program_library import ArrayProgramLibrary
lib = ArrayProgramLibrary.load("my_library.json")
entry = lib.lookup(hidden_state)
result = entry.program.execute(arrays, lengths)

# Rust
let lib = load_library_from_json_bytes(&fs::read(path)?)?;
let result = consult_library_native(&lib.1, &hidden, &array, length);

# Browser (WASM)
const rt = new NpcotRuntime(await (await fetch('/lib.json')).text());
const result = rt.consult(hidden, array, length);

Compliance

Every cached program is run through a static analyzer that proves termination, division safety, overflow bounds, and product stability. The compliance report aggregates to a single safe / warn / highverdict that your CI / release pipeline uses as a deployment gate.

python3 -m scripts.cli.npcot_compliance my_library.json --markdown
python3 -m scripts.cli.npcot_compliance my_library.json --json > audit.json
# Exit codes: 0=safe/warn, 2=missing file, 3=high risk (block deployment).

Privacy

Before publishing a library, a curator can run Gaussian perturbation on every signature to satisfy approximate (ε,δ)-DP:

from ncpu.self_optimizing.library_privacy import dp_perturb_library
perturbed, cert = dp_perturb_library(lib, epsilon=1.0, delta=1e-5)
print(cert)  # DPCertificate(epsilon=1.0, delta=1e-5, sigma=X, sensitivity=2.0, ...)

Federation

Two libraries in the same domain can be merged by a broker. The broker never touches training data — only the libraries themselves.

from ncpu.self_optimizing.array_program_library import merge_libraries
merged = merge_libraries(
    [alice_library, bob_library],
    conflict_resolution="keep_more_hits",
)
print(merged.fingerprint())  # npcot1:<32-hex>

Reference