{"id":18422430,"url":"https://github.com/sri-csl/yices2_python_bindings","last_synced_at":"2025-04-07T14:32:46.731Z","repository":{"id":62590623,"uuid":"149190217","full_name":"SRI-CSL/yices2_python_bindings","owner":"SRI-CSL","description":"Python bindings for yices2","archived":false,"fork":false,"pushed_at":"2024-12-18T06:22:00.000Z","size":702,"stargazers_count":11,"open_issues_count":1,"forks_count":5,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-22T19:45:59.766Z","etag":null,"topics":["python-bindings","smt-solver","yices"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SRI-CSL.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-17T21:27:46.000Z","updated_at":"2025-01-09T18:56:53.000Z","dependencies_parsed_at":"2022-11-04T08:18:21.749Z","dependency_job_id":null,"html_url":"https://github.com/SRI-CSL/yices2_python_bindings","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fyices2_python_bindings","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fyices2_python_bindings/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fyices2_python_bindings/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SRI-CSL%2Fyices2_python_bindings/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SRI-CSL","download_url":"https://codeload.github.com/SRI-CSL/yices2_python_bindings/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247670206,"owners_count":20976525,"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":["python-bindings","smt-solver","yices"],"created_at":"2024-11-06T04:29:58.541Z","updated_at":"2025-04-07T14:32:46.367Z","avatar_url":"https://github.com/SRI-CSL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/badge/License-MIT-blueviolet.svg)](https://opensource.org/licenses/MIT)\n[![PyPI version](https://badge.fury.io/py/yices.svg)](https://badge.fury.io/py/yices)\n[![PyPI Statistics](https://img.shields.io/pypi/dm/yices.svg)](https://pypistats.org/packages/yices)\n\n#  Python Bindings for Yices 2\n\nAs the name indicates, this provides a Python interface to the Yices SMT Solvers.\n\n## Installation\n\nInstall the [Yices SMT Solver](http://yices.csl.sri.com/) first, then, install\nthe python language bindings with:\n```\npip install yices\n```\n\nThis will install two python packages and a binary.\n\n- yices_api\n\n  This gives you access to the low-level Yices API from Python. To use this API, you will need to be familiar\n  with `ctypes`   and know the Yices C API, see [yices.h](https://github.com/SRI-CSL/yices2/blob/master/src/include/yices.h).\n  Unless you really need it, we recommend that you use the Pythonesque API below.\n\n- yices\n\n  This a more Pythonesque API that bridges the gap between the low level yices_api and the python user. It provides\n  Python classes to represent Yices context, models, configurations, etc.\n\n- yices_python_info\n\n  The binary `yices_python_info` prints information about the system:\n\n  ```\n  \u003e yices_python_info\n  Python Yices Bindings. Version 1.1.3\n  Yices library loaded from /usr/local/lib/libyices.dylib\n  Version: 2.6.2\n  Architecture: x86_64-apple-darwin18.7.0 \n  Build mode: debug\n  Build date: 2020-04-27\n  MCSat support: yes\n  Thread safe: no\n  ```\n\n##  Examples\n\nThe following three examples show how to use the yices module.\n\n#### Linear Real Arithmetic\n\n```\nfrom yices import *\n\ncfg = Config()\ncfg.default_config_for_logic('QF_LRA')\nctx = Context(cfg)\n\nreal_t = Types.real_type()\nx = Terms.new_uninterpreted_term(real_t, 'x')\ny = Terms.new_uninterpreted_term(real_t, 'y')\n\nfmla0 = Terms.parse_term('(\u003e (+ x y) 0)')\nfmla1 = Terms.parse_term('(or (\u003c x 0) (\u003c y 0))')\n\nctx.assert_formulas([fmla0, fmla1])\n\nstatus = ctx.check_context()\n\nif status == Status.SAT:\n    model = Model.from_context(ctx, 1)\n    model_string = model.to_string(80, 100, 0)\n    print(model_string)\n    xval = model.get_value(x)\n    yval = model.get_value(y)\n    print('x = {0}, y = {1}'.format(xval, yval))\n```\nThe complete file can be found [here.](https://github.com/SRI-CSL/yices2_python_bindings/blob/master/examples/readme_qf_lra.py)\nRunning this example should show this:\n\n```\n\u003e python examples/readme_qf_lra.py\n(= x 2)\n(= y -1)\nx = 2, y = -1\n```\n\n#### Bit-Vectors\n\n```\nfrom yices import *\n\ncfg = Config()\ncfg.default_config_for_logic('QF_BV')\nctx = Context(cfg)\n\nbv32_t = Types.bv_type(32)\nx = Terms.new_uninterpreted_term(bv32_t, 'x')\ny = Terms.new_uninterpreted_term(bv32_t, 'y')\n\n\nzero = Terms.bvconst_integer(32, 0)\nfmla0 = Terms.bvsgt_atom(x, zero)\nfmla1 = Terms.bvsgt_atom(y, zero)\nfmla2 = Terms.bvslt_atom(Terms.bvadd(x, y), x)\n\nctx.assert_formulas([fmla0, fmla1, fmla2])\n\nstatus = ctx.check_context()\n\nif status == Status.SAT:\n    model = Model.from_context(ctx, 1)\n    model_string = model.to_string(80, 100, 0)\n    print(model_string)\n    xval = model.get_value(x)\n    yval = model.get_value(y)\n    print('x = {0}\\ny = {1}'.format(xval, yval))\n\n```\nThe complete file is [here.](https://github.com/SRI-CSL/yices2_python_bindings/blob/master/examples/readme_qf_bv.py)\n\n#### Non-Linear Real Arithmetic\n\n```\nfrom yices import *\n\ncfg = Config()\ncfg.default_config_for_logic('QF_NRA')\nctx = Context(cfg)\n\nreal_t = Types.real_type()\nx = Terms.new_uninterpreted_term(real_t, 'x')\ny = Terms.new_uninterpreted_term(real_t, 'y')\n\nfmla0 = Terms.parse_term('(= (+ (* x x) (* y y)) 1)')\nfmla1 = Terms.parse_term('(= x (* 2 y))')\nfmla2 = Terms.parse_term('(\u003e x 0)')\n\nctx.assert_formulas([fmla0, fmla1, fmla2])\n\nstatus = ctx.check_context()\n\nif status == Status.SAT:\n    model = Model.from_context(ctx, 1)\n    model_string = model.to_string(80, 100, 0)\n    print(model_string)\n    xval = model.get_value(x)\n    yval = model.get_value(y)\n    print('x = {0}, y = {1}'.format(xval, yval))\n```\nThe complete file is [here.](https://github.com/SRI-CSL/yices2_python_bindings/blob/master/examples/readme_qf_nra.py)\n\n### More Examples\n\nDirectory [test](https://github.com/SRI-CSL/yices2_python_bindings/tree/master/test)\ncontains tests of the API routines.\n\n#### Sudoku\n\nA more advanced example is in directory [sudoku](https://github.com/SRI-CSL/yices2_python_bindings/tree/master/examples/sudoku).\nIt shows three different ways of solving the same sudoku puzzle using Yices:\n\n- `sudoku.ys` is a Yices input file\n\n- `sudoku.py` does the same thing using the Python `yices` API\n\n- `sudoku_api.py` does it using the low-level `yices_api` module and `ctypes`\n\n### SudokuSensei\n\nWe keep a GUI-based Sudoku solver written using the Yices Python API in a separate\n[repository](https://github.com/ianamason/SudokuSensei).\n\n#### MC-SAT\n\nAnother example in [mcsat](https://github.com/SRI-CSL/yices2_python_bindings/tree/master/examples/mcsat)\ndemonstrates simple use of Yices' non-linear capabilites. Because this example requires the libpoly library,\nthe python code uses the low-level API.\n\n\n## Details\n\nThe `yices` Python API introduces different classes to represent Yices objects such as\ncontexts, models, configurations, and search parameters. Term and type constructors are\nimplemented as static methods of the Python classes `Terms` and `Types`, respectively.\nWe do not wrap the Yices notions of terms and types into Python classes. Just as in the C-API,\nterms and types are represented as integer in Python.\n\nTo use the API, it is sufficient to just import the `yices` module:\n```\nfrom yices import *\n```\nThis will automatically load the `libyices` dynamic library.\nYou can also import incrementally if needed:\n```\nfrom yices.Config import Config\nfrom yices.Context import Context\nfrom yices.Constructors import Constructor\nfrom yices.Model import Model\nfrom yices.Parameters import Parameters\nfrom yices.Status import Status\nfrom yices.Types import Types\nfrom yices.Terms import Terms\nfrom yices.YicesException import YicesException\nfrom yices.Yices import Yices\nfrom yices.Yvals import Yval\n```\n\n\nMost functions in the C-API have a corresponding Python method of the same name, except\nwhere this would clash with Python's reserved words. To avoid such a clash, we prepend the\nfunction names with 'y'. Currently, this affects a few functions in the `Terms` class:\n```\nTerms.yand([t0, ...., tN])\nTerms.yor([t0, ...., tN])\nTerms.ynot(t0)\nTerms.ylambda(variables, body)\n```\n\n\n## Incompatibility with the pip yices package version 1.0.8\n\nWe have made incompatible changes to the low-level `yices_api` module. In our previous version\n(pip package version 1.0.8), low-level operations raised exception on error. In the current\nversion (pip package version 1.1.0), we have changed this to return an error code.\n\nWe have also changed the module names. What used to be module `yices` in version 1.0.8 is\nnow called `yices_api`. So to keep using the low-level Python API, you have to change\n```\nimport yices\n```\nto\n```\nimport yices_api\n```\nand similar variations of the `import` statement.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsri-csl%2Fyices2_python_bindings","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsri-csl%2Fyices2_python_bindings","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsri-csl%2Fyices2_python_bindings/lists"}