Skip to content

Add missing C# API functions for solver introspection and congruence closure - #8126

Merged
Nikolaj Bjorner (NikolajBjorner) merged 3 commits into
masterfrom
copilot/add-missing-api-functions-csharp
Jan 9, 2026
Merged

Nikolaj Bjorner (NikolajBjorner) merged 3 commits into
masterfrom
copilot/add-missing-api-functions-csharp

Conversation

Copilot AI commented Jan 8, 2026 •

Copy link
Copy Markdown
Contributor

Per discussion #8121, the C# API was missing several solver introspection functions available in Python and C++.

Added APIs

Solver introspection:

  • NonUnits property - Returns non-unit literals in solver state
  • Trail property - Returns solver decision trail (requires SimpleSolver)

Congruence closure:

  • CongruenceRoot(Expr) - Returns congruence closure root of term
  • CongruenceNext(Expr) - Returns congruence closure sibling of term
  • CongruenceExplain(Expr, Expr) - Returns proof of term congruence

Implementation

Added wrapper methods to Solver.cs and NativeSolver.cs. The underlying C API functions (Z3_solver_get_non_units, Z3_solver_get_trail, Z3_solver_congruence_*) already existed; Native.cs bindings are auto-generated during build.

Example usage:

using (var ctx = new Context())
{
    var solver = ctx.MkSimpleSolver();
    var x = ctx.MkIntConst("x");
    
    solver.Add(ctx.MkGt(x, ctx.MkInt(0)));
    solver.Check();
    
    // New APIs
    BoolExpr[] trail = solver.Trail;
    BoolExpr[] nonUnits = solver.NonUnits;
    Expr root = solver.CongruenceRoot(x);
}

This brings C# to parity with Python for these functions.

Original prompt

Based on the discusssion #8121
Add missing API functions for the C# API.

Custom agent used: debug-agentic-workflow
Debug and refine agentic workflows using gh-aw CLI tools - analyze logs, audit runs, and improve workflow performance


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
@NikolajBjorner
Nikolaj Bjorner (NikolajBjorner) marked this pull request as ready for review January 8, 2026 23:31
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
Copilot AI changed the title [WIP] Add missing API functions for the C# API Add missing C# API functions for solver introspection and congruence closure Jan 8, 2026
@NikolajBjorner
Nikolaj Bjorner (NikolajBjorner) merged commit bc4f587 into master Jan 9, 2026
30 of 43 checks passed
@nunoplopes
Nuno Lopes (nunoplopes) deleted the copilot/add-missing-api-functions-csharp branch January 13, 2026 09:18
Nikolaj Bjorner (NikolajBjorner) added a commit that referenced this pull request Feb 19, 2026
…closure (#8126)

* Initial plan

* Add missing C# API functions for NonUnits, Trail, and Congruence methods

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

* Fix formatting: remove extra blank lines in new properties

Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: NikolajBjorner <3085284+NikolajBjorner@users.noreply.github.com>
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.

2 participants