Issue #1336: The solver as a C library: one call takes an SMT-LIB query, the answer, model and certificate come back into the caller’s buffer (ADR-284)

Open and answer this issue on GitHub.

blocked, solver · opened 2026-11-07 · updated 2026-11-18 · 5 comments

Part of #599 (a standalone proof assistant that other languages can call). ADR-284 (a Nikaia library for other languages is one C artifact), ADR-270 D17 (the solver is a product of its own).

Goal

The solver (crates/nikaia-std/src/tools/sv_*.nika, logic_*.nika) becomes a C library, libnikaia_solver.so/.a with a generated nikaia_solver.h. It is built with artifact = "c-library" (Part III 15.1), as examples/c-library is. The interface is coarse: a whole query crosses in one call, and the answer, the model and the certificate come back into the caller’s buffer. This is the base of the JVM binding (ADR-284 D34, #1337) and of every other host.

To build

  1. Probe first: can a package reach the solver? Can a package under packages/ call sv_check and the SMT-LIB reader (sv_smtlib.nika, logic_smtlib.nika) without copying the files?
    • If it can, the package is packages/solver/ (name = "nikaia-solver", symbol-prefix = "nks").
    • If it cannot, stop. Report Result: blocked, Found: with the probe, Needs: supervisor decision; the question belongs with #478 (the logic layer as a package). Do not copy the solver’s files into the package.
  2. Entry points (pub extern), one crossing per query:
    • pub extern struct Solver (an opaque handle) with Solver() and fn check(ref mut self, query: ref Bytes, budget: i64) -> Verdict sync. The query is SMT-LIB 2 text with one (check-sat). The budget is in the solver’s work units (D14), not in time.
    • pub extern enum Verdict { Unsat, Sat, Unknown } (payload-free). What made an Unknown (overflow, unreadable, outside the logic, budget) is read through fn why(ref self) -> String.
    • fn model(ref self) -> String: after Sat, the model as SMT-LIB (model …) text. fn certificate(ref self) -> String: after Unsat, the Alethe certificate (logic_alethe.nika). Both come back through the caller’s buffer, as ADR-284 D5 says.
    • Every certificate is checked before Unsat is returned, and every model is evaluated before Sat is returned, as scripts/solver.nika run does today. An answer that does not check is Unknown with why = "certificate rejected" or "model rejected".
  3. Tests in Nikaia: packages/solver/tests/*.nika with .stdout files, run by nikaia test. They call check, model, certificate and why on the four files of tests/solver/pre and on one unreadable file. The answers are the ones scripts/solver.nika run tests/solver/pre gives.
  4. A C caller: packages/solver/examples/use.c, as examples/c-library/use.c does. It reads a .smt2 file, calls nks_solver_new, nks_solver_check, the model or certificate (with the size query), then nks_solver_free, and prints the verdict. The package’s README shows how to build and run it, and the issue records its output on tests/solver/pre.
  5. The figure, recorded here: the instructions spent at the boundary for one query (callgrind, docs/measuring.md). That is the C caller on tests/solver/pre/* minus the solver’s own work, as scripts/solver.nika run --stats counts it. The boundary’s share of one query, as a fraction.

Done when

nikaia build in packages/solver/ makes the shared and static library and nikaia_solver.h. The C caller gets the same verdicts as scripts/solver.nika run on tests/solver/pre, with checked certificates and evaluated models. The package tests pass. The boundary figure is recorded here.

Files and limits

Ruled out


Generated by Claude Code

Comments

keywan-ghadami, 2026-11-07

From #1339 (e621704): the refinement lemmas of the non-linear solver are checked by sv_lemma.nika, but the sv log has no Alethe export yet, so a lemma schema’s Alethe counterpart is only named (sv_lemma_alethe), not emitted. The certificate this issue hands back needs that export for logs that contain non-linear lemmas.


Generated by Claude Code

keywan-ghadami, 2026-11-17

Brief queued: issue-1336


agent: builder model: opus max_turns: 200 budget_usd: 30 effort: medium —

Issue #1336

Your work order is issue #1336, inlined below with its comments. There is no brief written around it: plan your own steps from its To build list, build them in order, commit after each finished step, and end when its Done when holds (or at the limits of builder.md, reporting what is left). The facts in your prompt are Core of docs/builder-facts.md; more on a topic: nikaia run scripts/syntax.nika -- KEYWORD, a probe: nikaia run scripts/probe.nika -- SNIPPET.

Measure the issue against docs/issues.md while you work: what it lacked, what was wrong in it. That answer goes into the report’s Issue: field. A finding, a changed plan or a finished item also goes into the issue as a comment (gh api repos/Nikaia-Foundation/Nikaia/issues/1336/comments -F body=@file, ending with the Claude Code footer), rule I13.

Rules (CLAUDE.md; shared checkout)

Report (at most 15 lines, to exactly /home/user/Nikaia/docs/briefs/solver/issue-1336.md.report.md)

Fields: Result, Files, Commit, Body (optional), Fixes, Pushed, Tests, Gate, Deviation, Found, Needs, Changelog, Issue, Owner (a question for the owner), Comment (#N <text>, what to say on another issue; the driver posts it, one line each), Friction, Disk freed, and last Attribution: with your commit trailer lines below it.


Generated by Claude Code

keywan-ghadami, 2026-11-17

Run: issue-1336, Result: blocked

Tokens: input 24, cache read 541855, cache write 43241, output 4108 Cost: 0.57 USD, time 0 min 54 s, turns 12

Report

Result: blocked Files: none Commit: none Pushed: none Tests: item 1 probe only, on target/fast/nikaia (copied to $S/old/nikaia; binary predates only 459d8141c, a bounds change unrelated to manifests or std modules); nothing built or committed Gate: green Deviation: none Found: a package cannot reach the solver without copying its files (#1336 item 1): a scratch package with nikaia.toml [package] name = "solverprobe" version = "0.1.0" plus [dependencies] compiler = { path = "/home/user/Nikaia/crates/nikaia-std/src/compiler" } and src/main.nika use compiler / fn main() throws { let r = compiler::sv_smtlib_read("(assert false)\n(check-sat)\n"); println("read") } fails on nikaia run with Error: reading .../crates/nikaia-std/src/compiler/nikaia.toml: No such file or directory (the compiler dir is not a package); the same main with use std::compiler is error[NK1186]: std has no module called std::compiler ... compiler is the toolchain's own, not std's. ADR-270 D24 decides the logic layer is a package any package may depend on, which is not built yet (#478) Needs: #478 Changelog: none Issue: rules-gap: the probe item 1 orders is a dependency on #478 (ADR-270 D24, logic layer as a package, decided but unbuilt), which the issue should name as Needs #478 so the driver does not start it before then Owner: none Comment: #478 #1336 (the solver as a C library) is blocked on this: a package cannot depend on crates/nikaia-std/src/compiler (no nikaia.toml), and use std::compiler is NK1186; #1336 needs the solver files (sv_, logic_, prover_arena, solver_terms, prove_text) reachable as a package under ADR-270 D24 Friction: none Disk freed: none (target/nikaia-project-tests absent; / 5.1G free of 252G) Attribution: Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com Claude-Session: https://claude.ai/code/session_01UVxJDwk9ubq9teP7QCErff

Debrief

  1. Most cost: finding where the solver lives and how scripts/solver.nika puts it together. The issue gives crates/nikaia-std/src/tools/sv_*.nika, but the files are in crates/nikaia-std/src/compiler/. I also spent two grep turns on the spec’s manifest keys, and their output was too large to read.
  2. Looked up: the [dependencies] path form (Part III), whether std::compiler exists, and ADR-270 D24, which decides the logic layer becomes a package. The brief could have said “#478 / ADR-270 D24 not built; the compiler directory has no nikaia.toml”.
  3. Checks run:
    • Checked the binary’s age against HEAD.
    • Ran two scratch probes: a path dependency on the compiler directory, and use std::compiler.
    • Measured the disk.
    • None was wasted. One gap: the prompt did not give #478’s state, and I never ran git log -400 --grep='Fixes #478' to confirm it is still open. I judged it unbuilt from the refusals alone.
  4. One change that would save the most: the driver should not queue an issue whose step-1 probe is a known gate on an open issue. Better still, builder.md could say: “an issue whose To build item 1 is ‘probe X; if not, stop’ names that probe’s dependency as Needs #N.”
  5. What the issue lacked:
    • rules-gap: it does not name #478 as Needs #478, although its own step 1 depends on it.
    • wrong I3 (file locations): tools/sv_*.nika and logic_*.nika are now in crates/nikaia-std/src/compiler/.
    • rules-gap: no ready-made probe snippet for item 1.
  6. Facts for the next builder:
    • Fact: Core crates/nikaia-std/src/compiler/ is no package (no nikaia.toml) and use std::compiler is NK1186, so no package can call the solver or the logic layer until ADR-270 D24 / #478 is built.
    • Fact: Core The solver runs standalone only as one program that scripts/solver.nika puts together (solver_logic_files, solver_engine_files, solver/sv_rod.nika), reading the files in place.

Generated by Claude Code

keywan-ghadami, 2026-11-17

Driver: not queued, this issue waits for #478, #1946, which is still open (#1819). Set ready again when it is closed.


Generated by Claude Code

keywan-ghadami, 2026-11-18

From the report of the run of issue-2020 (#2020):

the solvers are the package logic now (packages/logic/src), so the blocker the move held is gone


Generated by Claude Code

Back to Open Issues