Repository navigation
library: define core gcd structurally and prove Euclid's step - #6299
Merged
Merged
Conversation
…-adkdks # Conflicts: # TASKS.md
…-adkdks # Conflicts: # TASKS.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Jarod · project thread
Core
gcdcalled itself at the computedmod(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)isgcd_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 onn, that any two bounds at leastbgive 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 lawgcd_step(a, b)proves Euclid's step,gcd(a, b) = gcd(b, mod(a, b)), for every positiveb.le_trans(transitivity of the order) joins the order lemmas, andgcdbecomes public so a program can state laws about it. The remainder inside the helper and the laws isdivide_step(a, pb, Zero, pb).remainder, so no law body callsmodwith its premise. Core now has no machine defined on fuel.Fixtures:
core_gcd/pass/euclidchecks closed gcds: a zero divisor, a zero dividend, coprime numbers and two common factors. It also has a program laweuclid_atthat restates Euclid's step and proves it by citinggcd_step.core_gcd/fail/euclid_without_its_stepdiffers only in dropping that citation. It is refused, because its two sides are the algorithm at two different bounds.The
TASKS.mdbullet 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) andmbx test -p omega --test kernel_judged_laws -- division modulo local_data gcd euclid(7), Clippy --no-deps on both crates | cleanAgent: Claude Code | Model: unavailable | Effort: medium | Steers: 0
Generated by Claude Code