feat: Add optional variable names to LExpr for better SMT display#496
Draft
MikaelMayer wants to merge 13 commits intomainfrom
Draft
feat: Add optional variable names to LExpr for better SMT display#496MikaelMayer wants to merge 13 commits intomainfrom
MikaelMayer wants to merge 13 commits intomainfrom
Conversation
MikaelMayer
commented
Feb 27, 2026
MikaelMayer
commented
Feb 27, 2026
- Add name parameter (String) to abs and quant constructors - Empty string indicates no name provided - SMT encoder uses names when available, falls back to generated names - Update all pattern matches and constructors throughout codebase
- Fix Translate.lean to use variable names from declarations - Fix StatementEval and StatementSemantics pattern matches - Update all existing tests to use empty string for unnamed quantifiers - Add tests demonstrating named vs unnamed quantifier variables
MikaelMayer
commented
Feb 27, 2026
MikaelMayer
commented
Feb 27, 2026
MikaelMayer
commented
Feb 27, 2026
MikaelMayer
commented
Feb 27, 2026
- Update all quantifier tests to use meaningful names (n, m, i) instead of empty strings - Keep only one test for empty string fallback behavior - Fix StatementSemantics Value inductive to accept abs with any name (not just empty)
- Detect when a quantifier variable name clashes with existing bvars - Automatically disambiguate with @suffix (e.g., x becomes x@1) - Add tests for nested quantifiers with same name - Add test for bvar/fvar name overlap (no clash in SMT since fvars get separate encoding)
- Free variables now use their actual names instead of generated f0, f1, etc. - Bound variables check for clashes with fvars and other bvars, disambiguate with @suffix - Multiple fvars with same name are disambiguated (e.g., f, f@1, f@2) - Improves SMT output readability significantly - Update test expectations to use actual names - Note: Exposes pre-existing 'select' shadowing issue in end-to-end tests
MikaelMayer
commented
Feb 27, 2026
MikaelMayer
commented
Feb 27, 2026
MikaelMayer
commented
Feb 27, 2026
MikaelMayer
commented
Feb 27, 2026
MikaelMayer
commented
Feb 27, 2026
- Extract disambiguateName helper to avoid duplication - Add SMT-LIB reserved keywords list and check in encodeUF - Remove non-stateless comments from tests - Revert test expectations to passing (reserved keywords now handled) - Add test for x, y, x@1 scenario demonstrating suffix disambiguation
MikaelMayer
commented
Feb 27, 2026
When a variable name already has @n suffix (e.g., x@1), extract the base name and numeric suffix, then increment from there. This ensures x, x, x@1 produces x, x@1, x@2 instead of x, x@1, x@1@1. Updated test to demonstrate x, x, x@1 scenario as requested.
MikaelMayer
commented
Feb 27, 2026
Extracted findUniqueName to Encoder.lean as a general helper used by both encodeUF and quantifier encoding. Limit is now based on actual number of existing identifiers rather than hardcoded 1000. Termination proven with omega after establishing remaining ≠ 0.
CI detected that verify depends on sorry axiom (from findUniqueName termination proof). Use #eval! to allow evaluation despite this.
This reverts commit 8914b86.
Free variables now use their actual names (x, xs, tree, intList, etc.) instead of generated names (f0, f1, etc.) in SMT output.
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.
This PR adds optional variable names to LExpr abstractions and quantifiers to improve SMT solver output readability.
Changes
LExpr.absandLExpr.quantconstructors to include aname: Stringparameter$__bv{index}when emptyImplementation
The
nameparameter is placed before thetyparameter to match the order in which they are typically provided explicitly. When no name is provided, an empty string is used.In the SMT encoder, quantifiers now check if the name is empty:
This allows the Core DDM to store meaningful variable names that will be displayed in SMT output.
Testing