Git Product home page Git Product logo

z3js's Introduction

z3js

A tiny utility library for building z3-powered JavaScript.

The main features are:

  • A transpiler for converting a tiny subset of JavaScript programs to smt2 to use z3 solver.
  • A tiny s-expression parser for reading z3 outputs in smt2 to JavaScript objects.

Examples

Create a file demo.js and add:

const { jsParser, toSMT2, declareDatatypes } = require("z3js"); // or "path/to/z3js/src"

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" })}
${toSMT2(jsParser.parse(JS_CODE), typeDefs)}
`);

and run node demo.js | z3 -in. You'll need z3, which you can install by running brew install z3 or sudo apt install z3 on Mac or Ubuntu, respectively.

Reading Z3 outputs

Try

node examples/synth.js | z3 -in | node examples/parseSynthZ3Output.js

and check out ./examples/parseSynthZ3Output.js.

Program Synthesis demo

Check out ./examples/synth.js! The demo code is loosely based on Adrian Sampson's program synthesis blog post.

Inspired by

z3js's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

z3js's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.