Skip to content

Tuple map keys are ordered in the proof model - #1998

Merged
jasisz merged 2 commits into
mainfrom
tuple-map-key-order
Dec 2, 2026
Merged

jasisz merged 2 commits into
mainfrom
tuple-map-key-order

Conversation

@jasisz

@jasisz jasisz commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Closes the Lean half of #1997.

Every backend has ordered tuple keys componentwise since 387c73e, and docs/language.md said the proof model does too. It did not: AverKeyOrder had instances for Int, String and Bool only, a tuple fell to the append-order fallback, and the gate declined every law that reads Map.keys / Map.values / Map.entries of 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, so set_set_comm applies to tuple keys.
  • common.rs: is_modelled_map_key_type accepts a tuple whose components are all modelled, at any depth. Lists, records and variants stay declined.
  • docs/language.md says 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.av gets 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 --check test runs it with sorry and declined budgets of 0, and the law closes by tactic through set_set_comm.
  • The gate's fixtures used Tuple<Int, Int> as their unmodelled key; they now use List<Int>, which orders lexicographically at runtime and is still unmodelled, so they keep testing the gate.
  • New unit test tuples_of_modelled_scalars_are_modelled_map_keys.
  • The map model snapshot gains the two instance lines.

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.entries for any key type, so it does not close these laws for Int keys 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 proof instead of declined.

🤖 Generated with Claude Code

jasisz and others added 2 commits December 2, 2026 09:29
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>
@jasisz
jasisz merged commit c11528f into main Dec 2, 2026
32 checks passed
@jasisz
jasisz deleted the tuple-map-key-order branch December 2, 2026 09:25
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.

1 participant