{"id":18571849,"url":"https://github.com/iagoabal/haskell-z3","last_synced_at":"2025-04-06T14:11:43.621Z","repository":{"id":42425142,"uuid":"131408629","full_name":"IagoAbal/haskell-z3","owner":"IagoAbal","description":"Haskell bindings to Microsoft's Z3 API (unofficial).","archived":false,"fork":false,"pushed_at":"2024-03-05T02:53:39.000Z","size":844,"stargazers_count":58,"open_issues_count":20,"forks_count":46,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T12:07:52.945Z","etag":null,"topics":["api","haskell","smt","z3"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IagoAbal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-04-28T12:42:27.000Z","updated_at":"2025-02-27T10:28:08.000Z","dependencies_parsed_at":"2025-03-15T18:15:25.165Z","dependency_job_id":null,"html_url":"https://github.com/IagoAbal/haskell-z3","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IagoAbal%2Fhaskell-z3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IagoAbal%2Fhaskell-z3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IagoAbal%2Fhaskell-z3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IagoAbal%2Fhaskell-z3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IagoAbal","download_url":"https://codeload.github.com/IagoAbal/haskell-z3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247492557,"owners_count":20947545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","haskell","smt","z3"],"created_at":"2024-11-06T23:03:58.240Z","updated_at":"2025-04-06T14:11:43.601Z","avatar_url":"https://github.com/IagoAbal.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Haskell bindings for Microsoft's Z3 (unofficial)\n\n![Version](https://img.shields.io/hackage/v/z3)\n![Testsuite workflow](https://github.com/IagoAbal/haskell-z3/actions/workflows/testsuite.yml/badge.svg)\n\nThese are Haskell bindings for the Z3 theorem prover.\nWe don't provide any high-level interface (e.g. in the form of a Haskell eDSL) here,\nthese bindings are targeted to those who want to build verification tools on top of Z3 in Haskell.\n\n[Changelog here.](CHANGES.md)\n\n[Examples here.](examples)\n\n[Do you want to contribute?](HACKING.md)\n\n## State of maintenance\n\nThe library is currently \"maintained\", meaning that I try to be responsive to new\nissues and pull requests.\nUnfortunately I do not have time to investigate issues or to do major work myself.\nI do try to help those who want to contribute.\n\nIf someone demonstrates willingness to maintain the library more actively\nin the long run, then I will be very happy to give the required permissions\nto become a co-maintainer.\nIn the meantime I will do my best to keep it alive.\n\n## Supported versions and version policy\n\nZ3 releases come out often and sometimes introduce backwards incompatible changes.\nIn order to avoid churn and `#ifdef`-ery, we only support recent releases of the latest Z3 minor version.\nWe use semantic versioning to reflect which versions are supported:\n\n    \u003cz3-version\u003e.\u003cbindings-version\u003e[.\u003cpatch-level\u003e]\n\nThe `\u003cz3-version\u003e` indicates which version of Z3 is supported, it is computed as\n_x*100+y_ for Z3 _x.y_. For example, versions _408.y.z_ of these bindings are\nmeant to support versions _4.8.*_ of Z3.\nThis version policy is in line with Haskell's PVP.\nIf you are using an older solver version you can check compatibility with these bindings below:\n\n### Z3-4.8.* compatibility\n\n| Bindings version / Z3 version  | 4.8.12  | 4.8.11  | 4.8.10  | 4.8.9   | 4.8.7   | 4.8.6   | 4.8.5   | 4.8.4   | 4.8.3   | 4.8.1   |\n| ----              | ---    | ---    | ---    | ---    | ---    | ---    | ---    | ---    | ---    | ---    |\n| 408.3             | ✔      | ✔      | ✔      | ✔      | ❌     | ❌     | ❌     | ❌     | ❌     | ❌     |\n| 408.2             | ✔      | ✔      | ✔      | ✔      | ✔      | ✔      | ✔      | ❌     | ❌     | ❌     |\n| 408.1             | ✔      | ✔      | ✔      | ✔      | ✔      | ✔      | ✔      | ✔      | ✔      | ✔      |\n| 408.0             | ❌     | ❌     | ❌     | ❌     | ❌     | ❌     | ❌     | ✔      | ✔      | ✔      |\n\n\n## Installation\n\nPreferably use the [z3](http://hackage.haskell.org/package/z3) package.\n\n* Install a [Z3](https://github.com/Z3Prover/z3) *4.x* release.\n  (Support for Z3 *3.x* is provided by the *0.3.2* version of these bindings.)\n* Just type _cabal install z3_ if you used the standard locations for dynamic libraries (_/usr/lib_) and header files (_/usr/include_).\n\n    * Otherwise use the _--extra-lib-dirs_ and _--extra-include-dirs_ Cabal flags when installing.\n\n## Example\n\nMost people use the `Z3.Monad` interface.\nHere is an example script that solves the 4-queen puzzle:\n\n```haskell\nimport Control.Applicative\nimport Control.Monad ( join )\nimport Data.Maybe\nimport qualified Data.Traversable as T\n\nimport Z3.Monad\n\nscript :: Z3 (Maybe [Integer])\nscript = do\n  q1 \u003c- mkFreshIntVar \"q1\"\n  q2 \u003c- mkFreshIntVar \"q2\"\n  q3 \u003c- mkFreshIntVar \"q3\"\n  q4 \u003c- mkFreshIntVar \"q4\"\n  _1 \u003c- mkInteger 1\n  _4 \u003c- mkInteger 4\n  -- the ith-queen is in the ith-row.\n  -- qi is the column of the ith-queen\n  assert =\u003c\u003c mkAnd =\u003c\u003c T.sequence\n    [ mkLe _1 q1, mkLe q1 _4  -- 1 \u003c= q1 \u003c= 4\n    , mkLe _1 q2, mkLe q2 _4\n    , mkLe _1 q3, mkLe q3 _4\n    , mkLe _1 q4, mkLe q4 _4\n    ]\n  -- different columns\n  assert =\u003c\u003c mkDistinct [q1,q2,q3,q4]\n  -- avoid diagonal attacks\n  assert =\u003c\u003c mkNot =\u003c\u003c mkOr =\u003c\u003c T.sequence\n    [ diagonal 1 q1 q2  -- diagonal line of attack between q1 and q2\n    , diagonal 2 q1 q3\n    , diagonal 3 q1 q4\n    , diagonal 1 q2 q3\n    , diagonal 2 q2 q4\n    , diagonal 1 q3 q4\n    ]\n  -- check and get solution\n  fmap snd $ withModel $ \\m -\u003e\n    catMaybes \u003c$\u003e mapM (evalInt m) [q1,q2,q3,q4]\n  where mkAbs x = do\n          _0 \u003c- mkInteger 0\n          join $ mkIte \u003c$\u003e mkLe _0 x \u003c*\u003e pure x \u003c*\u003e mkUnaryMinus x\n        diagonal d c c' =\n          join $ mkEq \u003c$\u003e (mkAbs =\u003c\u003c mkSub [c',c]) \u003c*\u003e (mkInteger d)\n```\n\nIn order to run this SMT script:\n\n```haskell\nmain :: IO ()\nmain = evalZ3 script \u003e\u003e= \\mbSol -\u003e\n        case mbSol of\n             Nothing  -\u003e error \"No solution found.\"\n             Just sol -\u003e putStr \"Solution: \" \u003e\u003e print sol\n```\n\n## Garbage Collection\n\nThis library automatically garbage collects all C objects created through its API.\n\n## Concurrency\n\nSince version `408.3`, this library implements thread-safety over the C API,\ni.e. API calls are serialized by locking on their `Context` argument.\nTo safely compile for multi-threaded code please upgrade to `\u003e= 408.3`.\n\nOperations and objects in different `Context`s can safely be accessed concurrently\nand are not synchronized by this library.\nTherefore, if you want to achieve real concurrency,\nyou must use a different `Context` in each thread.\nYou can use the `*_translate_*` functions from Z3's API to copy objects between different `Contexts`.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiagoabal%2Fhaskell-z3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiagoabal%2Fhaskell-z3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiagoabal%2Fhaskell-z3/lists"}