Repository navigation
psi: read every generic mathematical body the signature can define - #6311
Merged
Merged
Conversation
After #6301 a few generic mathematical bodies were still refused by name. This reads them instead, so every generic body the signature can define is defined: - **A generic machine that calls itself at other machines**, such as `alternate::<Step, Other>` recursing as `alternate::<Other, Step>`. Each branch of a definition by cases already binds the machine parameters, so the recursion passes whichever machines it names. A law's induction hypothesis is the law at those machines, and its premises are owed there. - **Recursion on fuel.** The definition over fuel takes the machine parameters after the fuel and before the formals. A law over fuel counts them among its formals, both in its `Fuel` formal and in the goal it states over the fuel. - **A dispatch on a computed value**, such as `transition (Step(n))`. The dispatch is a definition of its own over everything in scope, and a body read for its value now has the machine parameters in scope too. - **A call of a generic machine with a premise.** It owes the premise, stated over the callee's machine parameters and formals, at the machines and arguments it passes (`owed_at`). - **A citation of a generic machine that states nothing.** It is lowered and read in place, with its machine parameters standing for the machines the citation passes. The callable scope now holds any term, not only a variable. - **Any other generic body** the clause reader cannot read as terms is lowered and read like any other body, which refuses what it cannot read. Two smaller fixes came with this. A generic machine's own `result` in its clauses is now its definition at its machine parameters and formals; the formals were applied without them, which the kernel rejected. And a premise owed in a body read for its value is stated over the machine parameters too. One rule stays as it was. A concrete machine with a premise is still no machine argument, since it is not a total function for the parameter to stand for. Customers, each a positive case with its negative twin: - `generic_machine/pass/alternate_keeps_two_fixed_points` proves `alternate::<succ, id>(2, a) = Succ(a)` and the law by induction at swapped machines. `fail/alternate_keeps_one_fixed_point` gives only `Step(a) = a`, and the hypothesis is refused. - `pass/pick_by_a_computed_value` dispatches on `Step(n)`. `fail/pick_by_a_computed_value_wrong_case` claims the other case's value. - `pass/call_owes_its_premise` calls `apply_fixed::<id>`. `fail/call_without_its_premise` calls it at `succ`, whose premise is refused. - `pass/cited_through_a_generic_helper` cites through `argue_twice::<id>`. `fail/cited_through_a_generic_helper_at_succ` cites it at `succ`. - Inline over `core/nat.omg`: `gcd_then` on fuel proves `gcd_then::<succ>(2, 1) = 2`, and its twin claims 1. `mod_then` proves its law over fuel, and its twin drops the bound and stays unproved. Gate: RC-SOURCE-SEMANTICS | every generic mathematical body the signature can define is read Spec: wiki/spec/language/generics.md#nested-contracts-and-proof-families, wiki/spec/proofs/foundation.md, wiki/spec/language/termination.md#computed-recursive-arguments-in-proofs Proof: `mbx test -p lowered-program-to-checked-program --lib` (1557, including 19 `generic_machine`); `mbx test -p prepared-typed-trees-to-lowered-program` (224 + 3); clippy `--all-targets --no-deps -D warnings` on both crates | clean. Agent: Claude Code | Model: unavailable | Effort: medium | Tokens: 31.0M in (30.8M cached), 98.2k out | Steps: 171 | Time: 1h48m | Steers: 0 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HqP8t5tK2L9aM3g5FQNwtB
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
After #6301 a few generic mathematical bodies were still refused by name. This reads them instead, so every generic body the signature can define is defined:
alternate::<Step, Other>recursing asalternate::<Other, Step>. Each branch of a definition by cases already binds the machine parameters, so the recursion passes whichever machines it names. A law's induction hypothesis is the law at those machines, and its premises are owed there.Fuelformal and in the goal it states over the fuel.transition (Step(n)). The dispatch is a definition of its own over everything in scope, and a body read for its value now has the machine parameters in scope too.owed_at).Two smaller fixes came with this. A generic machine's own
resultin its clauses is now its definition at its machine parameters and formals; the formals were applied without them, which the kernel rejected. And a premise owed in a body read for its value is stated over the machine parameters too.One rule stays as it was. A concrete machine with a premise is still no machine argument, since it is not a total function for the parameter to stand for.
Customers, each a positive case with its negative twin:
generic_machine/pass/alternate_keeps_two_fixed_pointsprovesalternate::<succ, id>(2, a) = Succ(a)and the law by induction at swapped machines.fail/alternate_keeps_one_fixed_pointgives onlyStep(a) = a, and the hypothesis is refused.pass/pick_by_a_computed_valuedispatches onStep(n).fail/pick_by_a_computed_value_wrong_caseclaims the other case's value.pass/call_owes_its_premisecallsapply_fixed::<id>.fail/call_without_its_premisecalls it atsucc, whose premise is refused.pass/cited_through_a_generic_helpercites throughargue_twice::<id>.fail/cited_through_a_generic_helper_at_succcites it atsucc.core/nat.omg:gcd_thenon fuel provesgcd_then::<succ>(2, 1) = 2, and its twin claims 1.mod_thenproves its law over fuel, and its twin drops the bound and stays unproved.Gate: RC-SOURCE-SEMANTICS | every generic mathematical body the signature can define is read
Spec: wiki/spec/language/generics.md#nested-contracts-and-proof-families, wiki/spec/proofs/foundation.md, wiki/spec/language/termination.md#computed-recursive-arguments-in-proofs
Proof:
mbx test -p lowered-program-to-checked-program --lib(1557, including 19generic_machine);mbx test -p prepared-typed-trees-to-lowered-program(224 + 3); clippy--all-targets --no-deps -D warningson both crates | clean.Agent: Claude Code | Model: unavailable | Effort: medium | Tokens: 31.0M in (30.8M cached), 98.2k out | Steps: 171 | Time: 1h48m | Steers: 0
Generated by Claude Code