Repository navigation
feat: resurrect CollectionHandling — wire Constants mode end-to-end - #1
Merged
Merged
Conversation
The CollectionHandling enum { Constants, Array } and the MultipleEnvironment
class were defined but never referenced — dead code. The library hardcoded the
Array mode (Z3 array theory via MkArrayConst + Select/Store, incl. nested
int[][]). This commit resurrects the Constants mode (one Z3 constant per
element, lazily created on index access) as a selectable alternative, while
preserving Array as the default so existing behavior is unchanged.
Library (solutions/Z3.Linq/):
- Theorem.DefaultCollectionHandling property (default = Array, anti-regression).
- GetEnvironment switches on the mode: Constants -> MultipleEnvironment,
Array -> existing MkArrayConst branch (nested-array Object branch preserved).
- ExtractCollection reads Constants-mode collections from SubEnvironments
(incl. nested int[][] via per-row MultipleEnvironment recursion). Scalar
conversion factored into ConvertScalarExpr, shared by both modes.
- ExpressionVisitor: new VisitArrayIndex resolves Cells[i] (and nested
Cells[i][j] recursively) against a MultipleEnvironment, materializing one
Z3 constant per element (Cells_i, Cells_i_j). ResolveMemberEnvironment /
GetMemberHierarchy factored out of VisitMember to support this. Array mode
unchanged (falls back to MkSelect).
- Z3Context.DefaultCollectionHandling propagated to NewTheorem<T>().
- Theorem<T>.Where propagates the mode across constraint chains.
Tests (new solutions/Z3.Linq.Tests/, xUnit):
- Sudoku 4x4 (int[][]) solvable in BOTH modes (Array = array theory,
Constants = per-element constants) — keystone proving both paths work
end-to-end for nested arrays.
- Flat int[] in Constants mode (Triple: three cells == 7).
- Hint honored in both modes.
- Default = Array guard (anti-regression).
dotnet test: 6/6 PASS. Array mode unchanged (nested int[][] Sudoku green).
Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Aug 13, 2026
jsboige
added a commit
that referenced
this pull request
Nov 4, 2026
The CollectionHandling enum { Constants, Array } and the MultipleEnvironment
class were defined but never referenced — dead code. The library hardcoded the
Array mode (Z3 array theory via MkArrayConst + Select/Store, incl. nested
int[][]). This commit resurrects the Constants mode (one Z3 constant per
element, lazily created on index access) as a selectable alternative, while
preserving Array as the default so existing behavior is unchanged.
Library (solutions/Z3.Linq/):
- Theorem.DefaultCollectionHandling property (default = Array, anti-regression).
- GetEnvironment switches on the mode: Constants -> MultipleEnvironment,
Array -> existing MkArrayConst branch (nested-array Object branch preserved).
- ExtractCollection reads Constants-mode collections from SubEnvironments
(incl. nested int[][] via per-row MultipleEnvironment recursion). Scalar
conversion factored into ConvertScalarExpr, shared by both modes.
- ExpressionVisitor: new VisitArrayIndex resolves Cells[i] (and nested
Cells[i][j] recursively) against a MultipleEnvironment, materializing one
Z3 constant per element (Cells_i, Cells_i_j). ResolveMemberEnvironment /
GetMemberHierarchy factored out of VisitMember to support this. Array mode
unchanged (falls back to MkSelect).
- Z3Context.DefaultCollectionHandling propagated to NewTheorem<T>().
- Theorem<T>.Where propagates the mode across constraint chains.
Tests (new solutions/Z3.Linq.Tests/, xUnit):
- Sudoku 4x4 (int[][]) solvable in BOTH modes (Array = array theory,
Constants = per-element constants) — keystone proving both paths work
end-to-end for nested arrays.
- Flat int[] in Constants mode (Triple: three cells == 7).
- Hint honored in both modes.
- Default = Array guard (anti-regression).
dotnet test: 6/6 PASS. Array mode unchanged (nested int[][] Sudoku green).
Co-authored-by: jsboigeEpita <jean-sylvain.boige@epita.fr>
Co-authored-by: Claude <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.
What
Resurrects the previously-dead
CollectionHandlingenum{ Constants, Array }. Until this PR, the enum and theMultipleEnvironmentclass were defined but never wired — pure dead code. This PR wires the Constants mode end-to-end (environment construction → constraint visiting → model extraction), alongside the existing Array mode.Why
North (user, via ai-01 2026-06-14): "il faudrait réparer cette enum pour que tout soit correctement pris en charge (...) basculer sur notre fork z3.Linq partout (...) on le ressuscite !". The goal is to make the fork the single source of truth for the CoursIA Z3 notebook series, with both collection modes genuinely functional.
Changes
Library (
Z3.Linq/):Theorem.cs:DefaultCollectionHandlingproperty (defaultArray— anti-régression);GetEnvironmentConstants branch (MultipleEnvironment);ExtractCollectionConstants branch readingSubEnvironments.ExpressionVisitor.cs: refactoredVisitMember(extractedGetMemberHierarchy/ResolveMemberEnvironment); newVisitArrayIndexthat resolves viaMultipleEnvironmentin Constants mode, falls back toMkSelectin Array mode; recursiveTryResolveArrayEnvironmenthandling bothMemberExpression(Cells[i]) and nestedBinaryExpression ArrayIndex(Cells[i][j]).Theorem{T}.cs:WherepropagatesDefaultCollectionHandling.Z3Context.cs:DefaultCollectionHandlingproperty, propagated to created theorems.Tests (
Z3.Linq.Tests/— new xUnit project):CollectionHandlingTests: 6 tests — Sudoku 4x4 in both modes (Array + Constants), flatint[]Triple in Constants, hint honored both modes, default=Array anti-regression guard.Anti-régression (HARD)
Array= behavior unchanged. The user's hand-typed nestedint[][]support (commit096a638) is preserved byte-identical.GetEnvironment/ExtractCollectionare untouched.Verification
dotnet build solutions/Z3.Linq.sln -c Release→ SUCCESS (lib + tests + examples)dotnet test solutions/Z3.Linq.Tests/Z3.Linq.Tests.csproj→ 6/6 PASS (Array + Constants modes)See #1206 (CoursIA epic — co-évolution lib+notebook).
🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com