3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2026-01-21 09:34:43 +00:00

Add benchmark export to C# and TypeScript APIs (#8228)

* Initial plan

* Add benchmark export functionality to C# and TypeScript APIs

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

* Fix TypeScript build error: remove redundant array length parameter

The Z3 TypeScript wrapper auto-generates array length parameters from the array itself, so passing assumptions.length explicitly causes a parameter count mismatch. Removed the redundant parameter.

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>
This commit is contained in:
Copilot 2026-01-17 13:02:19 -08:00 committed by GitHub
parent 11851c2e4c
commit 1be52d95a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 106 additions and 0 deletions

View file

@ -1899,6 +1899,36 @@ export function createApi(Z3: Z3Core): Z3HighLevel {
return check(Z3.solver_to_string(contextPtr, this.ptr));
}
toSmtlib2(status: string = 'unknown'): string {
const assertionsVec = this.assertions();
const numAssertions = assertionsVec.length();
let formula: Z3_ast;
let assumptions: Z3_ast[];
if (numAssertions > 0) {
// Use last assertion as formula and rest as assumptions
assumptions = [];
for (let i = 0; i < numAssertions - 1; i++) {
assumptions.push(assertionsVec.get(i).ast);
}
formula = assertionsVec.get(numAssertions - 1).ast;
} else {
// No assertions, use true
assumptions = [];
formula = ctx.Bool.val(true).ast;
}
return check(Z3.benchmark_to_smtlib_string(
contextPtr,
'',
'',
status,
'',
assumptions,
formula
));
}
fromString(s: string) {
Z3.solver_from_string(contextPtr, this.ptr, s);
throwIfError();

View file

@ -1172,6 +1172,28 @@ export interface Solver<Name extends string = 'main'> {
*/
fromFile(filename: string): void;
/**
* Convert the solver's assertions to SMT-LIB2 format as a benchmark.
*
* This exports the current set of assertions in the solver as an SMT-LIB2 string,
* which can be used for bug reporting, sharing problems, or benchmarking.
*
* @param status - Status string such as "sat", "unsat", or "unknown" (default: "unknown")
* @returns A string representation of the solver's assertions in SMT-LIB2 format
*
* @example
* ```typescript
* const solver = new Solver();
* const x = Int.const('x');
* const y = Int.const('y');
* solver.add(x.gt(0));
* solver.add(y.eq(x.add(1)));
* const smtlib2 = solver.toSmtlib2('unknown');
* console.log(smtlib2); // Prints SMT-LIB2 formatted problem
* ```
*/
toSmtlib2(status?: string): string;
/**
* Manually decrease the reference count of the solver
* This is automatically done when the solver is garbage collected,