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
2 changes: 1 addition & 1 deletion TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ Find Rust owners in the [compiler map](source-rust/README.md#where-code-belongs)
- **PROOF-KERNEL-CORE.** (covers **PROOF-CONTRACT-MIGRATION**, **QUOTIENT-THEOREM-LIFT**, **PSI-CLAIM-ADMISSION**) Complete [source proofs](wiki/spec/proofs/foundation.md) and [Psi claim admission](wiki/drafts/designs/psi_claim_admission.md). Report [coverage code 36](wiki/spec/build/compiler_request.md) with the obligation identity when the prover lacks a rule for its form.
- Deliver [unified native inductives](wiki/spec/proofs/inductive_profile.md#native-inductive-declarations) from source through Psi. Check indexed `Vector` and a mutual block. Preserve the source indices, reject negative recursion, wrong indices, invalid universes, strict elimination and forged recursors at the responsible checker. Justify the new kernel rules, compare proof costs with the [prototype measurements](wiki/drafts/designs/recursive_data_encoding_experiments.md), and remove the production W/IW encoding after acceptance.
- [Proof kernel core audit](wiki/drafts/designs/proof_kernel_core_audit.md): what #2823 removed, the three general rules still needed, the changes to stage 05's clause readers and the build order.
- Discharge the natural order's well-foundedness once and prove that the fuel a machine with [computed recursive descent](wiki/spec/language/termination.md#computed-recursive-arguments-in-proofs) is defined on suffices for every reachable call, so its laws hold independently of the bound.
- Discharge the natural order's well-foundedness once and prove that the fuel a program's machine with [computed recursive descent](wiki/spec/language/termination.md#computed-recursive-arguments-in-proofs) is defined on suffices for every reachable call, so its recursive equations hold and a law that needs them is provable. Core has no such machine left: `div`, `mod` and `gcd` are structural, and `gcd_within_agrees` is the source-level pattern (every sufficient bound gives the same answer).
- Step 7 reads a quotient of mathematical data, proves equal classes for related representatives, checks `MereEquivalence` (including `IsMere` and Hedberg setness for plain data) and effectivity, and judges `Quotient::lift` and `Quotient::define` by their selected theorems. Ordinary programs store a quotient of custody-free copyable data as its representative. A clause may apply a lifted operation that the kernel's `lift` defines. A lift may compute, leave out or repeat its arguments. Still owed, each refused by name today: generic quotients, and laws over quotients of data that has storage (the signature states a record only of mathematical data, never one with a fixed-width field). [Audit, "Step 7 as built so far"](wiki/drafts/designs/proof_kernel_core_audit.md#plan-order)
- Put the abstract carriers, trait operations and cited laws of a generic machine's Identity goals in the [mathematical signature](source-rust/subsystems/compiler/source-to-psi/representations/lowered-program/README.md#the-mathematical-signature); `equality::discharge` still builds that table per obligation.
- Extend alias-typed theorem parameters to accept evidence projected from bundles, as in `use_step::<U8_LAWS.step>(7u8)`. Stage 05 refuses every `term.member` proof argument by name. A record field typed `step: NonzeroIsPositive` is a structural callable field, so `const U8_LAWS: Laws = Laws { step: nonzero_is_positive }` needs a callable ceiling and then fails constant evaluation ("Terminal result scalar is outside the compiler-owned vocabulary"). Which field type declares mathematical evidence instead is owner question 5 in [OWNER_QUESTIONS.md](OWNER_QUESTIONS.md#bundle-evidence-field-type). [Theorem proof parameters](wiki/spec/proofs/mathematical_bindings.md#logical-hypotheses-and-machine-use)
Expand Down
20 changes: 20 additions & 0 deletions source-rust/application/tests/kernel_judged_laws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,26 @@ fn core_division_by_zero_is_refused_for_its_premise() {
);
}

#[test]
fn core_gcd_computes_and_takes_euclids_step() {
// A zero divisor, a zero dividend, coprime numbers and common factors,
// each checked by computation through `gcd` of `core/nat.omg`, and
// Euclid's step at any positive divisor by citing `gcd_step`.
let (output, report) = check("core_gcd/pass/euclid");
assert_eq!(output.status.code(), Some(0), "{report}");
}

#[test]
fn euclids_step_without_its_law_is_refused() {
let (output, report) = check("core_gcd/fail/euclid_without_its_step");
assert_eq!(output.status.code(), Some(1), "{report}");
assert!(
report.contains("cannot prove ensures contract for `euclid_at`")
&& report.contains(UNPROVED),
"{report}"
);
}

#[test]
fn a_machine_that_recurses_on_a_computed_value_of_local_data_is_refused() {
// `Peano` is the program's own data, so no natural order checks the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,16 @@ pub(super) fn judged_library_files(nat: &str, files: &[(&str, &str)]) -> Vec<Rou
}

#[test]
fn core_division_is_structural_and_gcd_descends_by_the_remainder_bound() {
fn core_division_and_gcd_are_structural() {
// `div` and `mod` of `core/nat.omg` project one structural helper,
// `divide_step`, so neither recurses on fuel nor owes a descent. `mod`
// states its strict bound and `div_mod_reconstruction` the equation
// `div(a, b) * b + mod(a, b) = a`, each from the helper's invariant.
// `gcd` still calls itself at the computed `mod(a, b)`: it owes `mod`'s
// premise at that call and the call's descent, which `mod`'s bound
// proves.
// `gcd` is `gcd_within` at its divisor as the bound on Euclid's steps,
// which recurses on that bound alone. `gcd_within_agrees` proves every
// sufficient bound gives the same answer, and `gcd_step` states
// Euclid's step `gcd(a, b) = gcd(b, mod(a, b))` from it. No machine of
// the file is defined on fuel.
let verdicts = judged_library(&[]);
let judgment = signature(&verdicts);
let judged = |machine: &str| {
Expand All @@ -172,10 +174,15 @@ fn core_division_is_structural_and_gcd_descends_by_the_remainder_bound() {
assert_eq!(judged("div_mod_reconstruction"), 1, "reconstruction");
assert_eq!(judged("divide_reconstructs"), 1, "the helper's invariant");
assert_eq!(judged("divide_bounds"), 1, "the helper's remainder bound");
assert!(
judged("gcd") >= 2,
"the premise of `mod` at its call and the descent"
assert_eq!(judged("gcd"), 0, "no descent: the bound is structural");
assert_eq!(judged("gcd_within"), 0, "no premise owed at its call");
assert_eq!(judged("le_trans"), 1, "transitivity of the order");
assert_eq!(
judged("gcd_within_agrees"),
1,
"every sufficient bound agrees"
);
assert_eq!(judged("gcd_step"), 1, "Euclid's step");
for law in &judgment.laws {
assert!(
matches!(law.decision, MathematicalCoreDecision::Judged(_)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ fn an_operation_outside_the_conformance_gets_no_license_from_it() {
/// judged through a program that reaches it, and most of these lemmas are
/// private, so the file's text is compiled as the program's. Left out are the
/// three ranking primitives only the toolchain may declare. `mod`, `div`,
/// `gcd` and the law relating `div` and `mod` are left out here too:
/// `fuel_recursion` judges the file with them, and the tests that build on
/// this text measure what they add without them.
/// `gcd`, Euclid's step and the law relating `div` and `mod` are left out
/// here too: `fuel_recursion` judges the file with them, and the tests that
/// build on this text measure what they add without them.
/// Every other declaration is the file's, unchanged, the `<=` and `-`
/// operator machines among them.
pub(super) fn library_declarations() -> String {
Expand All @@ -189,7 +189,7 @@ pub(super) fn library_declarations() -> String {
let mut skipping = false;
for line in NAT[start..].lines() {
let declared = line.strip_prefix("public ").unwrap_or(line);
skipping |= ["mod", "div", "gcd", "div_mod_reconstruction"]
skipping |= ["mod", "div", "gcd", "gcd_step", "div_mod_reconstruction"]
.iter()
.any(|name| declared.starts_with(&format!("machine {name}(")));
if !skipping {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Deployable proof canary: every hosted target selects its exact entry.

use main.omg as app;

machine build(builder: @mutable BuildPlan) {
builder.product = BuildProduct::Application { name: "euclid_without_its_step" };
Build::bind(builder, windows_x86_64::ProgramEntry, |app|::entry_start);
Build::bind(builder, linux_x86_64::ProgramEntry, |app|::entry_start);
Build::bind(builder, linux_arm64::ProgramEntry, |app|::entry_start);
Build::bind(builder, macos_arm64::ProgramEntry, |app|::entry_start);
Build::bind(builder, windows_arm64::ProgramEntry, |app|::entry_start);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// The program of `core_gcd/pass` with one change: `euclid_at` does not
// cite `gcd_step`. Its two sides are Euclid's algorithm at two different
// bounds, and without the law that sufficient bounds agree nothing proves
// them equal, so the compiler refuses its ensures.
use {omega}/language/core/foundation.omg as proof;
use {omega}/language/core/nat.omg;

// zero divisor: gcd(5, 0) = 5.
machine gcd_5_0() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } }, |nat|::Nat::Zero)) }
}

// zero dividend: gcd(0, 5) = 5.
machine gcd_0_5() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Zero, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } })) }
}

// coprime: gcd(7, 3) = 1.
machine gcd_7_3() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Zero })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } } } }, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } })) }
}

// common factor: gcd(6, 4) = 2.
machine gcd_6_4() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } } }, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } })) }
}

// common factor: gcd(9, 6) = 3.
machine gcd_9_6() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } } } } } }, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } } })) }
}

// Euclid's step at any positive divisor `b`, from a program.
machine euclid_at(a: |nat|::Nat, b: |nat|::Nat) -> |nat|::Nat
requires
|proof|::Identity::<|nat|::Nat>(|nat|::saturating_sub(|nat|::Nat::Succ { prev: |nat|::Nat::Zero }, b), |nat|::Nat::Zero)
ensures
|proof|::Identity::<|nat|::Nat>(|nat|::gcd(a, b), |nat|::gcd(b, |nat|::mod(a, b)))
{
transition { _ -> |nat|::Nat::Zero }
}

data Main { }

// The entry does nothing: the program is here for its proofs.
machine entry_start() { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Deployable proof canary: every hosted target selects its exact entry.

use main.omg as app;

machine build(builder: @mutable BuildPlan) {
builder.product = BuildProduct::Application { name: "euclid" };
Build::bind(builder, windows_x86_64::ProgramEntry, |app|::entry_start);
Build::bind(builder, linux_x86_64::ProgramEntry, |app|::entry_start);
Build::bind(builder, linux_arm64::ProgramEntry, |app|::entry_start);
Build::bind(builder, macos_arm64::ProgramEntry, |app|::entry_start);
Build::bind(builder, windows_arm64::ProgramEntry, |app|::entry_start);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Core's greatest common divisor: Euclid's algorithm with the divisor as the
// bound on its steps. Each closed machine computes `gcd` of two numbers and
// states the expected result, which the kernel checks by computation:
// a zero divisor, a zero dividend, coprime numbers and a common factor.
// `euclid_at` states Euclid's step, gcd(a, b) = gcd(b, mod(a, b)) for a
// positive `b`, and proves it by citing core's `gcd_step`. The negative
// twin drops that citation.
use {omega}/language/core/foundation.omg as proof;
use {omega}/language/core/nat.omg;

// zero divisor: gcd(5, 0) = 5.
machine gcd_5_0() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } }, |nat|::Nat::Zero)) }
}

// zero dividend: gcd(0, 5) = 5.
machine gcd_0_5() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Zero, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } })) }
}

// coprime: gcd(7, 3) = 1.
machine gcd_7_3() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Zero })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } } } }, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } })) }
}

// common factor: gcd(6, 4) = 2.
machine gcd_6_4() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } } }, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } })) }
}

// common factor: gcd(9, 6) = 3.
machine gcd_9_6() -> |nat|::Nat
ensures
|proof|::Identity::<|nat|::Nat>(result, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } })
{
transition { _ -> (|nat|::gcd(|nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } } } } } }, |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Succ { prev: |nat|::Nat::Zero } } } } } })) }
}

// Euclid's step at any positive divisor `b`, from a program.
machine euclid_at(a: |nat|::Nat, b: |nat|::Nat) -> |nat|::Nat
requires
|proof|::Identity::<|nat|::Nat>(|nat|::saturating_sub(|nat|::Nat::Succ { prev: |nat|::Nat::Zero }, b), |nat|::Nat::Zero)
ensures
|proof|::Identity::<|nat|::Nat>(|nat|::gcd(a, b), |nat|::gcd(b, |nat|::mod(a, b)))
{
_ = |nat|::gcd_step(a, b);
transition { _ -> |nat|::Nat::Zero }
}

data Main { }

// The entry does nothing: the program is here for its proofs.
machine entry_start() { }
Loading
Loading