{"id":18769145,"url":"https://github.com/thefangbear/sat","last_synced_at":"2025-12-10T12:30:13.075Z","repository":{"id":80822456,"uuid":"137639298","full_name":"thefangbear/SAT","owner":"thefangbear","description":"Boolean expression parser and solver suite","archived":false,"fork":false,"pushed_at":"2018-06-22T10:31:30.000Z","size":121,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T07:24:07.599Z","etag":null,"topics":["c","cpp","parser","sat","solver"],"latest_commit_sha":null,"homepage":null,"language":"C++","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/thefangbear.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-06-17T08:17:00.000Z","updated_at":"2022-10-31T04:56:24.000Z","dependencies_parsed_at":null,"dependency_job_id":"3d207e6c-b389-422a-b9fd-157f0cdd88b5","html_url":"https://github.com/thefangbear/SAT","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefangbear%2FSAT","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefangbear%2FSAT/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefangbear%2FSAT/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thefangbear%2FSAT/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thefangbear","download_url":"https://codeload.github.com/thefangbear/SAT/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239671414,"owners_count":19677873,"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":["c","cpp","parser","sat","solver"],"created_at":"2024-11-07T19:14:57.705Z","updated_at":"2025-12-10T12:30:13.016Z","avatar_url":"https://github.com/thefangbear.png","language":"C++","readme":"# SAT\nThis is an educational repository aims at providing a set of very basic routines for parsing and solving simple boolean expressions in C/C++ and for people who want to implement a very very basic SAT solver for fun.\n\n## Parser\n\nFor simplicity, we parse using a very crude grammar that works most of the time (excuse the sloppiness...).\n\nThe parser is a simple recursive descent parser that parses the input expression to (approximately) a binary expression tree.\n\nParenthesization is handled as having the binary expression tree link to sub-trees using an extra pointer on each level, if necessary.\n\nTo avoid writing a full LL(*k*)-parser we simply define the grammar to recurse at every left-parenthesis (`(`), and return\nat every right-parenthesis (`)`).\n\n[Click here to view the very crude parser with no parenthesization support](https://github.com/thefangbear/SAT/blob/master/sat_parser.cpp);\n\n[Click here to view the parser with parenthesization + eval support](https://github.com/thefangbear/SAT/blob/master/parser.cpp);\n\n[Click here to view the parser template file for SAT solver implementation](https://github.com/thefangbear/SAT/blob/master/constraint_parser.cpp)\n\n## Current solvers\nWe currently have three kinds of solvers, all implementing the basic binary backtrack method.\n\n**Binary-recursive Backtrack Solver**: ([basic_sat.cpp](https://github.com/thefangbear/SAT/blob/master/basic_sat.cpp)) The solver uses the basic binary-recursive backtracking algorithm. Running time is O(N 2^k).\n\n**Binary-iterative Backtrack Solver**: ([sat.cpp](https://github.com/thefangbear/SAT/blob/master/sat.cpp)) This solver uses an iterative approach to generate all 2^k solutions down the tree.\n\n**Binary Stack-recursive Backtrack Solver**: ([iterative_basic_sat.cpp](https://github.com/thefangbear/SAT/blob/master/iterative_basic_sat.cpp)) This solver uses a stack to explicitly handle the recursion.\n\n## Development status\n\nCurrently testing and revising the parser for boolean expressions.\n\n - Step 1: Write a parser that supports parsing non-parenthesized boolean expressions (done, `sat_parser.cpp`)\n - Step 2: Write a parser that supports parenthesized boolean expressions (done, `parser.cpp`)\n - Step 3: Write a parser that evaluates boolean expressions (done, `parser.cpp`)\n - Step 4: Write a parser that handles free-formed expressions (done, `constraint_parser.cpp`)\n - Step 5: Implement a basic backtracking-based SAT solving algorithm (done, `basic_sat.cpp`)\n - Step 5.5: Implement an iterative version of `_backtrack()` in `basic_sat.cpp` to make it prettier (done, `sat.cpp`)\n - Step 6: Implement a more advanced SAT solving algorithm (DPLL; this requires us to write a CNF converter first; see `cnf.txt`)\n\n## Example Usage\nEnter the expected (maximum) length of the input expression on the first line, and the expression on the second line.\n```\n50\na\u0026(b|c^d)\ninput: a\u0026(b|c^d)\nS(): check\nS(): parsing B()\nB(): @a\nS(): parsing OP(), \u0026\nOP(): @\u0026\nS(): parsing S()\nS(): check\nS(): parsing B()\nB(): @(\nS(): check\nS(): parsing B()\nB(): @b\nS(): parsing OP(), |\nOP(): @|\nS(): parsing S()\nS(): check\nS(): parsing B()\nB(): @c\nS(): parsing OP(), ^\nOP(): @^\nS(): parsing S()\nS(): check\nS(): parsing B()\nB(): @d\nT(): return\nB(): S() returned, **prog=='\\0'? 1 [**prog=0]\nT(): return\n(\u0026 a ((| b (^ c d))))\n === solving ===\nsolve: got 4 variables, solving [16 possibilities]...\n:::::: Viable solution :::::\nVariable [a] := T\nVariable [b] := T\nVariable [c] := F\nVariable [d] := F\n............................\n:::::: Viable solution :::::\nVariable [a] := T\nVariable [b] := F\nVariable [c] := T\nVariable [d] := F\n............................\n:::::: Viable solution :::::\nVariable [a] := T\nVariable [b] := T\nVariable [c] := T\nVariable [d] := F\n............................\n:::::: Viable solution :::::\nVariable [a] := T\nVariable [b] := F\nVariable [c] := F\nVariable [d] := T\n............................\n\n```\n\n## Author\nRui-Jie Fang\n\n## License\nThe MIT License.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthefangbear%2Fsat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthefangbear%2Fsat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthefangbear%2Fsat/lists"}