Skip to content

Embed functions over Fin n with a symbolic bound - #4

Open
Qubut wants to merge 2 commits into
verse-lab:v4.35.0-veil-no-mathlibfrom
Qubut:fin-symbolic-bound
Open

Qubut wants to merge 2 commits into
verse-lab:v4.35.0-veil-no-mathlibfrom
Qubut:fin-symbolic-bound

Conversation

@Qubut

@Qubut Qubut commented Nov 11, 2026

Copy link
Copy Markdown

Fixes the SMT preprocessing failure in verse-lab/veil#173 for functions over Fin n when n is a variable, as in a Veil module with param maxId : Nat and function coverage : Fin maxId → Nat.

What changes

  1. Port of Fin embeddings in preprocessing ufmg-smite/lean-smt#229 (George Pîrlea's Fin embedding) onto this branch. Conflicts with the branch's module system and EmbeddingConfig were resolved as follows:

    • kept the branch's config;
    • the PR's isFinType is gated by embedNat;
    • the new files became modules.
  2. Symbolic bounds. The Fin input rules require [NeZero n]. For a variable n that instance is not found, so a function f : Fin n → β keeps its Fin n argument. Two errors follow:

    • its applications reach the solver as ofIntFin n x h, whose proof argument is cast through Int.toNat_of_nonneg and mentions the Nat embedding's n ≥ 0 hypothesis. implies_congr_ctx then rejects it ("Application type mismatch … expected f ≥ 0 → ?q₁ = ?q₂");
    • cvc5 reports "Symbol 'n' not declared as a type".

    forall_fin_in_as_int_inh₁ to ₅ rewrite such functions to functions over Int under [Inhabited β] instead. extFin f b is f (ofIntFin n b hb) for 0 ≤ b < n and default elsewhere, and extFin_cast turns it back on embedded arguments. The rules hold for every n, including 0, and the NeZero rules are unchanged. No sorry, no native_decide.

Tests

  • Test/Fin.lean adds six cases, each over a symbolic bound:
    • five must pass: a quantifier, a function input, a Nat-valued field, two arguments, and an update that preserves an invariant (Veil-shaped);
    • one must fail.
  • The suite was run one test at a time with lean --plugin=libcvc5_cvc5.so, comparing against .expected:
    • 98 of 107 pass;
    • 7 failures are the same at the base revision 293dab6: Rat/linarith, Unit/Rat and the five Solver tests (possibly my runner, which differs from lake script run test);
    • Bool/Assoc and Bool/Comm print the same counterexample in a different order, and their .expected files are updated, as in Fin embeddings in preprocessing ufmg-smite/lean-smt#229.
  • A Veil module with four actions and four invariants over Fin maxId (the one in SMT preprocessing throws on Nat-valued fields over a Fin n domain veil#173):

Not covered

  • Trivially true goals over a symbolic bound, such as ∀ i : Fin n, p i = p i, still fail in reconstruction with assumption on ⊢ n ≥ 0. That is a separate step.
  • Functions returning Fin n for a variable n are not tested.
  • Not tried on ufmg-smite/lean-smt main.

dranov and others added 2 commits November 11, 2026 23:05
Embed Fin n values as bounded Ints during preprocessing, including quantifiers
and function input/output positions. Translate Nat casts to Int so embedded Fin
values can be emitted as SMT integer terms. Add focused Fin regression tests
and the expected output file for the intentional failures.
The Fin input rules rewrite `∀ f : … → Fin n → β, P f` only under
`[NeZero n]`. For a symbolic `n` the instance cannot be synthesised, so
the function keeps its `Fin n` argument; its applications then reach
the solver as `ofIntFin n x h`, whose proof argument is cast through
`Int.toNat_of_nonneg` and mentions the nonnegativity hypothesis that the
Nat embedding introduces. `implies_congr_ctx` rejects that, and the
solver sees an undeclared sort `n`.

`forall_fin_in_as_int_inh₁` to `₅` rewrite such functions to functions
over Int under `[Inhabited β]` instead: `extFin f b` is `f (ofIntFin n b
hb)` where `0 ≤ b < n` and `default` elsewhere, and `extFin_cast` turns
it back on embedded arguments. They hold for every `n`, including 0, and
leave the `NeZero` rules in place.

Test/Fin.lean adds five goals over a symbolic bound (a quantifier, a
function input, a Nat-valued field, two arguments, an update preserving
an invariant) and one that must fail. Assoc and Comm list the same
counterexample in a different order.
Copilot AI balanced review requested due to automatic review settings November 11, 2026 22:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

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.

3 participants