Registry / ai-ml / z3js
library0.0.0jsnpmunverified

z3js is a tiny utility library (v0.0.0) for transpiling a small subset of JavaScript expressions to SMT2 format for use with the Z3 solver. It includes a JavaScript parser, a SMT2 code generator, and a minimal S-expression parser for reading Z3 outputs. The library is experimental and limited to simple variable declarations, function definitions, and assertions. It requires an external Z3 solver binary and is intended for prototyping program synthesis and formal verification tools. No releases or update cadence is established; the project appears to be in early development. Key differentiators: focuses on a tight JS→SMT2 bridge, unlike full verification frameworks.

npm install z3js
INSTALL
IMPORT
SIG · Z3JS
Z
z3js
ai-mljavascriptv0.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jsParser
import { jsParser } from 'z3js'
const jsParser = require('z3js').jsParser
No ESM module published; only CommonJS supported.
toSMT2
const { toSMT2 } = require('z3js')
Default export not available; always use named import.
declareDatatypes
const { declareDatatypes } = require('z3js')
import declareDatatypes from 'z3js'
No default export; only named exports.

Transpile a small JS program with function and assertion to SMT2 and pipe to Z3 solver.

const { jsParser, toSMT2, declareDatatypes } = require('z3js'); const JS_CODE = ` var x; function f(args) { return args.one * args.two; } assert(f(x) === 2); check_sat(); get_model(); `; const typeDefs = { x: '(Arg)', y: '(Arg)', f: { args: '(Arg)', return: 'Int' } }; console.log(declareDatatypes('Arg', { one: 'Int', two: 'Int' })); console.log(toSMT2(jsParser.parse(JS_CODE), typeDefs));
Debug
Known issues
breakingThe library is version 0.0.0 and API is unstable. No semVer guarantees.
fix
Pin to exact version and expect future breaking changes.
affects: 0.0.0
gotchaRequires external Z3 binary. Does not bundle or install Z3 automatically.
fix
Install Z3 via 'brew install z3' or 'apt install z3' and ensure it's in PATH.
affects: *
gotchaOnly a tiny subset of JavaScript is supported. For loops, arrays, objects, and closures are not supported.
fix
Refer to project examples for the supported syntax.
affects: *
gotchaNo TypeScript type definitions are provided. All types are lost when using this library.
fix
Use JSDoc or manually declare types if using TypeScript.
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'z3js'
Package not installed or not installed correctly.
fix
Run `npm install z3js` or use a local path like 'require('./path/to/z3js/src')'.
parse error: unexpected token
JavaScript code contains unsupported syntax (e.g., arrow functions, let/const, templates).
fix
Rewrite using only 'var', function declarations, and simple expressions.
z3: command not found
Z3 solver binary is not installed or not in PATH.
fix
Install Z3 via 'brew install z3' (macOS) or 'sudo apt install z3' (Ubuntu) or download from GitHub.
Upgrade
Version history
0.0.0latest on npm
Audit
Dependencies
z3optionalExternal solver binary required for SMT solving (not an npm package). Typically installed via brew/apt.
Agent activity
40 hits · last 30 days
node
36
OpenAI (training)
1
Resources
z3js — npm install z3js · libregistry