Repository navigation
Tuple map keys are ordered in the proof model - #1998
Merged
Merged
Conversation
Every backend has ordered tuple keys componentwise since 387c73e, but the Lean model only had an order for Int, String and Bool keys. A tuple key fell back to append order, so any law reading Map.keys, Map.values or Map.entries of a tuple-keyed map, or comparing two such maps, was declined. The prelude now orders a pair by its first components and, when those are equal, by its second ones, with AverLawfulKeyOrder evidence built from the components'. An Aver tuple of three or more is a right-nested pair, so the same instance covers it. The export gate accepts a tuple whose components are all modelled, at any depth. The gate's fixtures used Tuple<Int, Int> as their unmodelled key type; they now use List<Int>, which the model still does not order. Refs #1997 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Closes the Lean half of #1997.
Every backend has ordered tuple keys componentwise since 387c73e, and
docs/language.mdsaid the proof model does too. It did not:AverKeyOrderhad instances forInt,StringandBoolonly, a tuple fell to the append-order fallback, and the gate declined every law that readsMap.keys/Map.values/Map.entriesof a tuple-keyed map or compares two of them.Change.
prelude.rs:AverKeyOrder (α × β)compares first components and, when they are equal, second ones. A tuple of three or more is a right-nested pair, so it is covered too.prelude/map_order.lean:AverLawfulKeyOrder (α × β)from the components' evidence, soset_set_commapplies to tuple keys.common.rs:is_modelled_map_key_typeaccepts a tuple whose components are all modelled, at any depth. Lists, records and variants stay declined.docs/language.mdsays which key types the proof model orders. The stale comments that said tuples are ordered by their printed form are fixed.Tests.
tests/fixtures/map_iteration_order.avgets a pair-keyed map built out of order (keys, values and equality with a literal) and a law that two writes under distinct pair keys commute. The existing--checktest runs it with sorry and declined budgets of 0, and the law closes by tactic throughset_set_comm.Tuple<Int, Int>as their unmodelled key; they now useList<Int>, which orders lexicographically at runtime and is still unmodelled, so they keep testing the gate.tuples_of_modelled_scalars_are_modelled_map_keys.Locally:
cargo test --test map_iteration_order(32 passed, with lake),cargo test -p aver-lang --lib codegen::(495 passed), clippy, fmt.Effect on the program that found it. On AoC 2026 day 1 nothing is declined any more. The four laws that were declined are now exported and stay open (they need helper laws). That is proof work in the program, not a gap in the model.
Not here. The Aver kernel has no rules for
Map.keys/Map.values/Map.entriesfor any key type, so it does not close these laws forIntkeys either. That is a kernel change and is left for a separate decision.Changelog: A law that reads the keys, values or entries of a map keyed by a tuple of Int, String and Bool, or compares two such maps, is now exported by
aver proofinstead of declined.🤖 Generated with Claude Code