Skip to content

library: define core gcd structurally and prove Euclid's step - #6299

Merged
Smotto merged 3 commits into
mainfrom
claude/project-thread-adkdks
Nov 27, 2026
Merged

Smotto merged 3 commits into
mainfrom
claude/project-thread-adkdks

Conversation

@Smotto

@Smotto Smotto commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Requested by Jarod · project thread

Core gcd called itself at the computed mod(a, b), so the compiler defined it on fuel, and no law about it that needs its recursive equation could be proved. It is now structural. gcd(a, b) is gcd_within(b, a, b), which is Euclid's algorithm with an explicit bound on its steps, and it recurses on that bound alone. The divisor is enough of a bound, because each remainder is strictly below its divisor (divide_bounds).

gcd_within_agrees(n, m, a, b) proves, by induction on n, that any two bounds at least b give the same answer. That is the source form of the termination spec's "prove that the counter suffices on every reachable call". From it, the new public law gcd_step(a, b) proves Euclid's step, gcd(a, b) = gcd(b, mod(a, b)), for every positive b. le_trans (transitivity of the order) joins the order lemmas, and gcd becomes public so a program can state laws about it. The remainder inside the helper and the laws is divide_step(a, pb, Zero, pb).remainder, so no law body calls mod with its premise. Core now has no machine defined on fuel.

Fixtures:

  • core_gcd/pass/euclid checks closed gcds: a zero divisor, a zero dividend, coprime numbers and two common factors. It also has a program law euclid_at that restates Euclid's step and proves it by citing gcd_step.
  • Its negative twin core_gcd/fail/euclid_without_its_step differs only in dropping that citation. It is refused, because its two sides are the algorithm at two different bounds.

The TASKS.md bullet is narrowed, not deleted. The compiler's fuel definition remains for a program's own machine with computed descent, whose descent #6267 checks. For those machines, proving the order well-founded once and proving the fuel sufficient are still owed, so their recursive equations are not yet available to a law. The audit records this, and also that the termination spec's "core proves once that this order is well founded" is not yet true of the implementation.

Gate: RC-SOURCE-SEMANTICS | core gcd is structural, proves that every sufficient bound agrees, and states Euclid's step
Spec: wiki/spec/language/termination.md#computed-recursive-arguments-in-proofs
Proof: mbx test -p lowered-program-to-checked-program --lib -- tests::fuel_recursion tests::nat_semiring tests::nested_cases tests::record_law tests::law_premise tests::nat_order tests::polynomial tests::ring_law (41, every law of nat/int/rat/cauchy judged, with le_trans, gcd_within_agrees and gcd_step) and mbx test -p omega --test kernel_judged_laws -- division modulo local_data gcd euclid (7), Clippy --no-deps on both crates | clean

Agent: Claude Code | Model: unavailable | Effort: medium | Steers: 0


Generated by Claude Code

@Smotto Smotto self-assigned this Nov 27, 2026
@Smotto
Smotto merged commit 2812ed1 into main Nov 27, 2026
1 check passed
@Smotto
Smotto deleted the claude/project-thread-adkdks branch November 27, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants