Code Monkey home page Code Monkey logo

az3's Introduction

AZ3 - Z3 Binding for Ada

AZ3 is an Ada binding to the Z3 theorem prover.

NOTE: This binding is not complete, yet. If you are missing a feature, feel free to open an issue or contribute through a pull request on GitHub.

Usage

with Ada.Text_IO; use Ada.Text_IO;
with Z3; use Z3;

procedure Use_Z3
is
   S : Solver := Create;
begin
   S.Assert (Int ("X") < Int (3) and Int ("X") > Int (100));
   if S.Check = Result_False then
      Put_Line ("Contradiction found");
   end if;
end Use_Z3;

Background

The thin-binding was extracted from the Z3 sources using

$ gcc -fdump-ada-spec -c z3/z3/src/api/z3.h

GNAT version:

$ gcc --version
gcc (GCC) 9.3.1 20200430 (for GNAT Community 2020 20200429)
Copyright (C) 2019 Free Software Foundation, Inc.

License

MIT License (same as Z3). See LICENSE.txt for details.

az3's People

Contributors

jklmnn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

sauliusg

az3's Issues

Splitting packages

I would suggest to split the Z3 package into multiple ones. As a quick idea I'd propose the following structure:

  • Z3
    • Z3.Solver
    • Z3.Optimize

The reason for that is that our current spec has over 600 lines and the body has over 1300. It becomes more and more difficult to make changes, especially if they apply to both the public and private part of the spec since locating the code that needs to be modified becomes more tedious.

Proper equality check

The "=" operator is currently used with its default implementation. This however seems to lead to wrong results sometimes. Instead Z3_is_eq_ast should be used.

Build with ASAN and check leaks

Build z3 and our test suite with ASAN and enable resource leak checks:

   package Builder is                                                                                                   
      for Global_Compilation_Switches ("Ada") use ("-fsanitize=address", "-fno-omit-frame-pointer");      
   end Builder; 

   package Linker is                                                                                                    
      for Default_Switches ("Ada") use ("-lasan");                                                            
   end Linker; 

Remove default context

The default context is a source of error as it is not used consistently and as other contexts are not used consistently (sometimes an object is only created correctly when it is created in the default context).
Furthermore it becomes a difficulty when making the context a controlled type.

Support Real type

Since z3_mk_pow returns a real type and no integer (since negative powers may cause fractions) we have to support the real type. To keep the effort as low as possible only the functions that are required to properly identify the type and convert it error free to integers will be implemented. Operations using the real type itself are not in the scope of this ticket.

Make Solver and Optimize constrained types

Currently Solver and Optimize are unconstrained types to enforce the usage of the create function. Due to these types being unconstrained we can't use them in records. However this is something we need. If we make these types unconstrained they will call Initialize when declared. Since we need a context for these types to be initialized properly we have to add an initialized property.

Proper reference counting

The Z3 C API uses manual reference counting. We currently do not care about reference counting, which likely results in memory leaks. To provide a usable API (without manual reference counting in Ada) we might have to use controlled objects for most of the types.

Moving contexts

Each context and all its content must be kept in a single thread. To split a set of expressions into multiple threads they have to be moved to the respective context of the thread. This can be done by Z3_translate.

Use Ada.Interfaces instead of custom types

Currently we use Long_Integer and our own custom 64 bit unsigned type. I think we should use Ada.Interfaces and its Integer_n and Unsigned_n types instead since this improves compatibility to other code and prevents some parts of the code using AZ3 from just withing it for the unsigned type.

Iterators

Create iterators for Z3 expressions to allow looping through their terms.

Failing comparisons

In other projects some comparisons, even between simple expressions fail even if those expressions are equal. This happens differently in different Z3 versions.

For Z3 4.4.1 - 4.8.4: 6cadebf016729655fbc4d9434691eb4d91d3dc7e
For Z3 4.8.7+: 6e359057e0fc09afbb364c78b8744d3f20c6ad81

Fix CI

CI has not run since January ;(

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.