Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ jobs:
- name: Package the binaries, the source bundle, the wasm bundle and the site
run: |
set -euo pipefail
mkdir -p dist site
mkdir -p dist
for target in x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu; do
name="uorc-${TAG}-${target}"
mkdir -p "dist/$name"
Expand All @@ -303,13 +303,12 @@ jobs:
(cd dist && sha256sum "$name.tar.gz" > "$name.tar.gz.sha256")
rm -rf "dist/$name"
done
cp web/* site/
cp build/wasm/uorc.wasm site/uorc.wasm
cp bench/bench.html bench/bench.json bench/bench.md site/
printf '%s\n' "$TAG" > site/version.txt
# The site is a browser closure v2: the page, the brand files, provenance.
node scripts/site.mjs site --wasm build/wasm/uorc.wasm --version "$TAG" --bench bench
name="uorc-${TAG}-wasm"
mkdir -p "dist/$name"
cp site/uorc.wasm site/uorc.js LICENSE-APACHE LICENSE-MIT "dist/$name/"
cp site/uorc_bg.wasm "dist/$name/uorc.wasm"
cp site/uorc.js LICENSE-APACHE LICENSE-MIT "dist/$name/"
tar -C dist -czf "dist/$name.tar.gz" "$name"
rm -rf "dist/$name"
git archive --format=tar.gz --prefix="uorc-${TAG}-src/" -o "dist/uorc-${TAG}-src.tar.gz" HEAD \
Expand Down
7 changes: 7 additions & 0 deletions CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ The three honesty levels (R2):
| --- | --- | --- |
| `UC-MACH-01` | `build` | The client's reference-semantics evaluator decodes program archives, including search-found programs and the ulz kernel graph when the certified fast path declines, to their exact original bytes. |

## neuromorphic-standard

| ID | Level | Statement |
| --- | --- | --- |
| `UC-NEU-01` | `build` | The ncm coder's plasticity is stated as the Prism neuromorphic standard in Uorc.Neuromorphic, with kernel-checked bounds: every mixer weight stays within plus or minus 2^22 under the bounded Hebbian rule, potentiation never lowers and depression never raises a weight, the plasticity lies between 24 and 128 per 65536 (128 at the first byte, 24 in the limit), one bit's weight change is at most 16376 and every product fits a 32-bit lane, a context slot never steps past its gap to the coded bit and consolidates at count 127, and every probability-map point stays within 16 bits; the native coder reads the model's constants. |

## ordered-objects

| ID | Level | Statement |
Expand Down Expand Up @@ -154,3 +160,4 @@ The three honesty levels (R2):
| `UC-INT-03` | `build` | `build_evidence` | `not_measured` | Source-owned checker soundness and constructive finite backward reduction are kernel checked for actual canonical framed messages and shape-valid source-SHA-authenticated traces, without global hash injectivity or an assumed frame codec. The decoder-to-authenticated-trace bridge and full product acceptance remain distinct. |
| `UC-INT-04` | `build` | `build_evidence` | `not_measured` | Source-owned actual-call relations establish ordered hash admissions, drained selected-view EOF and checked cumulative basis/main work; composed generated-model controls reject failed-prefix resets and late corruption. Consumer snapshot preservation, canonical digest refinement and complete archive EOF remain separate obligations. |
| `UC-INT-05` | `build` | `build_evidence` | `not_measured` | Source-owned completed-view and continuous publication proofs derive the actual chosen-profile digest and emitted-image reads, discharging canonical driver termination and OwnedHash control/cleanup lifetime for both explicit format identities and arbitrary finite source input. Initial source-layout correspondence and full product acceptance remain separate consumer obligations. |
| `UC-NEU-01` | `build` | `kernel_theorem` | `not_measured` | The ncm coder's plasticity is stated as the Prism neuromorphic standard in Uorc.Neuromorphic, with kernel-checked bounds: every mixer weight stays within plus or minus 2^22 under the bounded Hebbian rule, potentiation never lowers and depression never raises a weight, the plasticity lies between 24 and 128 per 65536 (128 at the first byte, 24 in the limit), one bit's weight change is at most 16376 and every product fits a 32-bit lane, a context slot never steps past its gap to the coded bit and consolidates at count 127, and every probability-map point stays within 16 bits; the native coder reads the model's constants. |
1 change: 1 addition & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ lint:
# runtimes (tens of minutes) and is its own recipe, `formal-tests`.
test:
cargo test --locked --workspace --exclude xtask
node --test scripts/site.test.mjs

# The xtask suite: product-runtime, integrity, claims and offline harnesses.
formal-tests:
Expand Down
68 changes: 58 additions & 10 deletions crates/uorc/src/ncm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,55 @@
//! probability, which drives a 32-bit binary arithmetic coder.
//!
//! A payload is the input length (4 bytes, big-endian) and the coder output.
//!
//! The plasticity of every learning part (mixer weights, context slots and
//! the probability maps) is the one the Prism model `Uorc.Neuromorphic`
//! (`src/Uorc/Neuromorphic.lex.tex`) states, with its bounds kernel-checked
//! there; [`standard`] holds its constants.

/// ncm's plasticity as `Uorc.Neuromorphic` states it. A test holds every
/// constant here equal to the model's, and the coder reads them from here.
pub mod standard {
/// The mixers.
pub const MIXERS: usize = 3;
/// Inputs per mixer: the hashed contexts, the match model's two, a bias.
pub const MIXER_INPUTS: usize = super::NIN;
/// Hashed contexts, each a slot that adapts toward the coded bit.
pub const CONTEXTS: usize = super::NC;
/// Every mixer weight stays within this bound (`hebbianBoundsHold`).
pub const WEIGHT_LIMIT: i32 = 1 << 22;
/// A fresh weight: 1/4 in 16-bit fixed point.
pub const WEIGHT_INITIAL: i32 = 1 << 14;
/// A mixer input's magnitude bound (stretched probabilities, vote, bias).
pub const INPUT_LIMIT: i32 = 2047;
/// A mixer error's magnitude bound (12-bit probabilities).
pub const ERROR_LIMIT: i32 = 4096;
/// A weight learns `x * err * plasticity / 2^PLASTICITY_SHIFT` per bit.
pub const PLASTICITY_SHIFT: u32 = 16;
/// The plasticity's floor, approached as the input is seen.
pub const PLASTICITY_FLOOR: i64 = 24;
/// The plasticity above the floor at the first byte.
pub const PLASTICITY_GAIN: i64 = 104;
/// Bytes after which the plasticity above the floor has halved.
pub const PLASTICITY_HALF_LIFE: i64 = 4096;
/// A weight's largest change in one bit (`laneFitHolds`).
pub const STEP_LIMIT: i32 = 16376;
/// A slot's count saturates here: the slot is consolidated.
pub const COUNT_LIMIT: u8 = 127;
/// A slot adapts by `RATE_NUMERATOR / (2 * count + 3)` / 65536 of its gap.
pub const RATE_NUMERATOR: i32 = 131_072;
/// A probability map point moves 1/2^REFINEMENT_SHIFT of its gap.
pub const REFINEMENT_SHIFT: i32 = 6;

/// The mixers' plasticity after `pos` coded bytes, in 1/65536 per unit
/// of `x * err`: 128 at the start, decaying toward 24 (`plasticity`).
#[must_use]
pub fn plasticity(pos: u32) -> i32 {
(PLASTICITY_FLOOR
+ PLASTICITY_GAIN * PLASTICITY_HALF_LIFE / (PLASTICITY_HALF_LIFE + i64::from(pos)))
as i32
}
}

const NC: usize = 17;
const NIN: usize = NC + 3;
Expand All @@ -31,10 +80,10 @@ const SQT: [i32; 33] = [
1, 2, 3, 6, 10, 16, 27, 45, 73, 120, 194, 310, 488, 747, 1101, 1546, 2047, 2549, 2994, 3348,
3607, 3785, 3901, 3975, 4022, 4050, 4068, 4079, 4085, 4089, 4092, 4093, 4094,
];
const WEIGHT_LIMIT: i32 = 1 << 22;
const WEIGHT_LIMIT: i32 = standard::WEIGHT_LIMIT;
/// Adaptive probability map rows: 33 interpolation points over the stretch domain.
const APM_ROW: usize = 33;
const APM_RATE: i32 = 6;
const APM_RATE: i32 = standard::REFINEMENT_SHIFT;
const APM2_BITS: u32 = 16;

fn squash(d: i32) -> i32 {
Expand Down Expand Up @@ -68,7 +117,7 @@ fn tables() -> &'static Tables {
}
let mut rate = [0i32; 128];
for (c, r) in rate.iter_mut().enumerate() {
*r = 131_072 / (2 * c as i32 + 3);
*r = standard::RATE_NUMERATOR / (2 * c as i32 + 3);
}
Tables { stretch, rate }
})
Expand Down Expand Up @@ -232,7 +281,7 @@ fn adapt(p: &mut u16, n: &mut u8, y: bool, rate: &[i32; 128]) {
let pv = i32::from(*p);
let t = if y { 65535 } else { 0 };
*p = (pv + (((i64::from(t - pv)) * i64::from(r)) >> 16) as i32) as u16;
if *n < 127 {
if *n < standard::COUNT_LIMIT {
*n += 1;
}
}
Expand Down Expand Up @@ -624,12 +673,11 @@ impl Model {
if self.mlen > 0 {
adapt(&mut self.msp[self.mi], &mut self.msn[self.mi], y, rate);
}
// plasticity: 24 + 104 * 4096 / (4096 + pos), in 1/65536 per unit of x * err
let lr = 24 + (104 * 4096 / (4096 + u64::from(self.pos))) as i64;
let lr = standard::plasticity(self.pos);
let yb = i32::from(y) << 12;
// |err| <= 4096 and lr <= 128, so err * lr < 2^20 and x * err * lr
// (|x| <= 2047) stays inside i32: the kernels learn in 32-bit lanes.
let lr = lr as i32;
// |err| <= 4096 and lr <= 128, so err * lr <= 2^19 and x * err * lr
// (|x| <= 2047) stays inside i32 (`laneFitHolds`): the kernels learn
// in 32-bit lanes.
let e = [
(yb - self.pm1) * lr,
(yb - self.pm2) * lr,
Expand Down Expand Up @@ -678,7 +726,7 @@ impl Model {
fn weights(rows: usize) -> Vec<i32> {
let mut w = vec![0; rows * NINP];
for r in w.chunks_exact_mut(NINP) {
r[..NIN].fill(1 << 14);
r[..NIN].fill(standard::WEIGHT_INITIAL);
}
w
}
Expand Down
152 changes: 152 additions & 0 deletions crates/uorc/tests/neuromorphic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
//! UC-NEU-01: the native ncm coder's plasticity is the one the Prism model
//! `Uorc.Neuromorphic` states. The model's bounds are kernel-checked by
//! `lexlean verify`; this test holds the native constants equal to the
//! model's and the model's theorem inventory complete, so neither can drift.

use std::collections::BTreeMap;
use std::path::PathBuf;
use uorc::ncm::standard;

fn module() -> String {
let path =
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../src/Uorc/Neuromorphic.lex.tex");
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display()))
}

/// The value of each `field: value` pair of a declaration, in either the
/// one-line or the multi-line canonical layout.
fn field<'a>(decl: &'a str, key: &str) -> Option<&'a str> {
let at = decl.find(&format!("{key}: "))? + key.len() + 2;
let rest = &decl[at..];
let end = rest.find([',', '}', '\n']).unwrap_or(rest.len());
Some(rest[..end].trim())
}

/// Every parameterless `Nat` definition whose body is a literal.
fn constants(source: &str) -> BTreeMap<String, i64> {
let mut out = BTreeMap::new();
for decl in source.split("definition{").skip(1) {
// a declaration ends at the blank line before the next
let decl = decl.split("\n\n").next().unwrap_or(decl);
let (Some(name), Some(result), Some(body)) = (
field(decl, "name"),
field(decl, "result"),
field(decl, "body"),
) else {
continue;
};
if decl.contains("parameters: [],") && result == "Nat" {
if let Ok(v) = body.parse() {
out.insert(name.to_string(), v);
}
}
}
out
}

fn theorems(source: &str) -> Vec<String> {
source
.split("theorem{")
.skip(1)
.filter_map(|decl| field(decl, "name").map(str::to_string))
.collect()
}

#[test]
fn native_plasticity_constants_are_the_models_uc_neu_01() {
let c = constants(&module());
let model = |name: &str| {
*c.get(name)
.unwrap_or_else(|| panic!("model constant {name}"))
};
let native: [(&str, i64); 18] = [
("mixerCount", standard::MIXERS as i64),
("mixerInputs", standard::MIXER_INPUTS as i64),
("slotContexts", standard::CONTEXTS as i64),
("weightLimit", standard::WEIGHT_LIMIT.into()),
("weightSpan", (2 * standard::WEIGHT_LIMIT).into()),
("weightInitial", standard::WEIGHT_INITIAL.into()),
("inputLimit", standard::INPUT_LIMIT.into()),
("errorLimit", standard::ERROR_LIMIT.into()),
("plasticityScale", 1 << standard::PLASTICITY_SHIFT),
("plasticityFloor", standard::PLASTICITY_FLOOR),
("plasticityGain", standard::PLASTICITY_GAIN),
("plasticityHalfLife", standard::PLASTICITY_HALF_LIFE),
("plasticityCeiling", standard::plasticity(0).into()),
("stepLimit", standard::STEP_LIMIT.into()),
("countLimit", standard::COUNT_LIMIT.into()),
("rateNumerator", standard::RATE_NUMERATOR.into()),
("refinementShift", standard::REFINEMENT_SHIFT.into()),
// the APM target the coder learns toward: 2^16 + 2^shift - 2
(
"refinementTarget",
(1 << 16) + (1 << standard::REFINEMENT_SHIFT) - 2,
),
];
for (name, value) in native {
assert_eq!(model(name), value, "{name}");
}
// The slot rates the model bounds are the native table's.
let rate = |count: i64| i64::from(standard::RATE_NUMERATOR) / (2 * count + 3);
assert_eq!(model("rateCeiling"), rate(0));
assert_eq!(model("rateFloor"), rate(standard::COUNT_LIMIT.into()));
}

#[test]
fn native_plasticity_meets_the_models_vectors_and_bounds_uc_neu_01() {
// the closed vectors the model proves with `decide`
for (pos, lr) in [
(0, 128),
(4096, 76),
(421_888, 25),
(421_889, 24),
(u32::MAX, 24),
] {
assert_eq!(standard::plasticity(pos), lr, "plasticity({pos})");
}
// The share above the floor is the quotient `plasticityBoundsHold`
// bounds: share * (4096 + pos) <= 104 * 4096, so 24 <= lr <= 128.
let mut pos = 0u32;
loop {
let share = i64::from(standard::plasticity(pos)) - standard::PLASTICITY_FLOOR;
let d = standard::PLASTICITY_HALF_LIFE + i64::from(pos);
assert!(share * d <= standard::PLASTICITY_GAIN * standard::PLASTICITY_HALF_LIFE);
assert!((0..=104).contains(&share));
match pos.checked_add(1 + pos / 64) {
Some(next) => pos = next,
None => break,
}
}
// `laneFitHolds`: the largest product and step, in the native lanes.
let top = i64::from(standard::INPUT_LIMIT)
* i64::from(standard::ERROR_LIMIT)
* i64::from(standard::plasticity(0));
assert_eq!(top, 1_073_217_536);
assert!(top <= i64::from(i32::MAX));
assert_eq!(
(top + (1 << standard::PLASTICITY_SHIFT) - 1) >> standard::PLASTICITY_SHIFT,
i64::from(standard::STEP_LIMIT)
);
}

#[test]
fn the_model_proves_every_stated_bound_uc_neu_01() {
let names = theorems(&module());
for name in [
"scaleIsMultiply",
"hebbianBoundsHold",
"potentiationNeverLowersHolds",
"depressionNeverRaisesHolds",
"plasticityBoundsHold",
"plasticityAt0",
"plasticityAt421889",
"laneFitHolds",
"slotRatesBoundedHolds",
"slotRateAtConsolidation",
"slotCountBoundHolds",
"slotStepWithinGapHolds",
"refinementBoundsHold",
] {
assert!(names.iter().any(|n| n == name), "theorem {name}");
}
}
2 changes: 1 addition & 1 deletion factory/graph.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schema": "uorc/factory-graph/1",
"sets": {
"formal": ["", "!client/", "!crates/uorc/", "!crates/uorc-wasm/", "!generated/", "!web/", "!Cargo.toml", "!Cargo.lock", "!README.md", "!scripts/bench.mjs", "!scripts/client-export.mjs", "!factory/", "!scripts/factory.", "!.github/workflows/release.yml", "!.github/workflows/pages.yml", "!.github/workflows/factory.yml"],
"formal": ["", "!client/", "!crates/uorc/", "!crates/uorc-wasm/", "!generated/", "!web/", "!vendor/hologram-brand/", "!scripts/site.", "!Cargo.toml", "!Cargo.lock", "!README.md", "!scripts/bench.mjs", "!scripts/client-export.mjs", "!factory/", "!scripts/factory.", "!.github/workflows/release.yml", "!.github/workflows/pages.yml", "!.github/workflows/factory.yml"],
"client": ["Cargo.toml", "Cargo.lock", "rust-toolchain.toml", ".cargo/", "crates/uorc/", "generated/rust/", ".github/workflows/release.yml"]
},
"obligations": [
Expand Down
8 changes: 8 additions & 0 deletions features/suites/neuromorphic-standard.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# @generated from src/Uorc/Registry.lex.tex by `cargo xtask check-model --write`.
Feature: neuromorphic-standard

@UC-NEU-01 @build
Scenario: The ncm coder's plasticity is stated as the Prism neuromorphic standard in Uorc.Neuromorphic, with kernel-checked bounds: every mixer weight stays within plus or minus 2^22 under the bounded Hebbian rule, potentiation never lowers and depression never raises a weight, the plasticity lies between 24 and 128 per 65536 (128 at the first byte, 24 in the limit), one bit's weight change is at most 16376 and every product fits a 32-bit lane, a context slot never steps past its gap to the coded bit and consolidates at count 127, and every probability-map point stays within 16 bits; the native coder reads the model's constants.
Given the Uorc.Neuromorphic module and the native ncm coder's plasticity constants
When the locked SDK verifies the module and the native test reads the module's constants and theorem inventory
Then every bound theorem is kernel-checked and every native plasticity constant equals the model's
6 changes: 6 additions & 0 deletions model/ids.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,9 @@ id = "UC-INT-05"
level = "build"
suite = "archive-integrity"
statement = "Source-owned completed-view and continuous publication proofs derive the actual chosen-profile digest and emitted-image reads, discharging canonical driver termination and OwnedHash control/cleanup lifetime for both explicit format identities and arbitrary finite source input. Initial source-layout correspondence and full product acceptance remain separate consumer obligations."

[[id]]
id = "UC-NEU-01"
level = "build"
suite = "neuromorphic-standard"
statement = "The ncm coder's plasticity is stated as the Prism neuromorphic standard in Uorc.Neuromorphic, with kernel-checked bounds: every mixer weight stays within plus or minus 2^22 under the bounded Hebbian rule, potentiation never lowers and depression never raises a weight, the plasticity lies between 24 and 128 per 65536 (128 at the first byte, 24 in the limit), one bit's weight change is at most 16376 and every product fits a 32-bit lane, a context slot never steps past its gap to the coded bit and consolidates at count 127, and every probability-map point stays within 16 bits; the native coder reads the model's constants."
8 changes: 8 additions & 0 deletions model/ledger.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,11 @@ statement = "Source-owned completed-view and continuous publication proofs deriv
evidence_kind = "build_evidence"
research_disposition = "not_measured"
feature = "features/suites/archive-integrity.feature"

[[claim]]
id = "UC-NEU-01"
level = "build"
statement = "The ncm coder's plasticity is stated as the Prism neuromorphic standard in Uorc.Neuromorphic, with kernel-checked bounds: every mixer weight stays within plus or minus 2^22 under the bounded Hebbian rule, potentiation never lowers and depression never raises a weight, the plasticity lies between 24 and 128 per 65536 (128 at the first byte, 24 in the limit), one bit's weight change is at most 16376 and every product fits a 32-bit lane, a context slot never steps past its gap to the coded bit and consolidates at count 127, and every probability-map point stays within 16 bits; the native coder reads the model's constants."
evidence_kind = "kernel_theorem"
research_disposition = "not_measured"
feature = "features/suites/neuromorphic-standard.feature"
Loading
Loading