{"id":25301616,"url":"https://github.com/p2js/propositional","last_synced_at":"2025-10-28T07:30:46.053Z","repository":{"id":276761861,"uuid":"929953060","full_name":"p2js/propositional","owner":"p2js","description":"Symbolic computation for propositional logic","archived":false,"fork":false,"pushed_at":"2025-02-10T09:05:12.000Z","size":28,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T10:22:27.082Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/p2js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2025-02-09T19:20:28.000Z","updated_at":"2025-02-10T09:05:16.000Z","dependencies_parsed_at":"2025-02-10T10:22:29.559Z","dependency_job_id":"ca34a461-d99b-4d5b-a6f9-846d268ccbbc","html_url":"https://github.com/p2js/propositional","commit_stats":null,"previous_names":["p2js/propositional"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p2js%2Fpropositional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p2js%2Fpropositional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p2js%2Fpropositional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p2js%2Fpropositional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p2js","download_url":"https://codeload.github.com/p2js/propositional/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238610551,"owners_count":19500674,"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":[],"created_at":"2025-02-13T06:48:07.879Z","updated_at":"2025-10-28T07:30:46.040Z","avatar_url":"https://github.com/p2js.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Propositional\n\nPropositional is a TypeScript symbolic computation library for propositional logic. It can parse, simplify, evaluate and otherwise manipulate logical formulae.\n\n## Usage\n\nYou can install propositional using [npm](https://www.npmjs.org/package/propositional):\n\n```sh\nnpm install propositional\n```\n\nOtherwise, you can build the library yourself by cloning into this repository and running `pnpm build`.\n\n### Building Formulas\n\nYou can construct a formula using the provided `Formula` constructor:\n\n```js\nimport * as propositional from \"propositional\"; //esm\nconst propositional = require(\"propositional\"); //commonJS\n\nlet f1 = new propositional.Formula(\"!(a =\u003e (b | c)) \u0026 (b =\u003e (a \u0026 c))\");\n\nf1.toString(); // \"(¬(a ⇒ (b ∨ c)) ∧ (b ⇒ (a ∧ c)))\"\n```\n\nThe constructor will parse a string containing single-letter variables, numbers `0` and `1` as stand-ins for false and true, and the following connectives:\n\n- `!`   for NOT\n- `\u0026`   for AND\n- `|`   for OR\n- `^`   for XOR\n- `=\u003e`  for IF (implies)\n- `\u003c=\u003e` for IFF (equivalent)\n\nArranged as a valid formula.\n\n### Formula Manipulation\n\nFormulae can be manipulated using the following provided methods:\n\n- `substitute` will replace a variable with another variable or a constant (true/false):\n\n```js\nnew propositional.Formula(\"a =\u003e (b \u0026 c)\").substitute(\"a\", \"b\").toString();\n// \"(b ⇒ (b ∧ c))\"\n```\n\n- `simplify` will simplify a formula according to certain equivalences with connectives and constants, including recursive simplifying for syntactically equivalent expressions:\n\n```js\nnew propositional.Formula(\"((a | c) \u0026 (a | !!c)) | (!b \u0026 !!b)\").simplify().toString();\n// \"(a ∨ c)\"\n```\n\n- `evaluate` will evaluate the formula as true or false for a given set of variable values:\n```js\nf1.evaluate({ a: true, b: false, c: false }); // true\n```\n\nAll of these methods return a new `Formula` rather than modifying the original one, so that the methods can be chained.\n\n### Truth Tables\n\nA formula's `truthTable` method can be used to generate its truth table, either in text or HTML format. The truth table will (optionally, and by default) include all intermediate sub-formulae:\n\n```js\nnew propositional.Formula(\"!(a \u0026 (b | c))\").truthTable();\n/*\n+---+---+---+---------+---------------+----------------+\n| a | b | c | (b ∨ c) | (a ∧ (b ∨ c)) | ¬(a ∧ (b ∨ c)) |\n| 0 | 0 | 0 |    0    |       0       |       1        |\n| 1 | 0 | 0 |    0    |       0       |       1        |\n| 0 | 1 | 0 |    1    |       0       |       1        |\n| 1 | 1 | 0 |    1    |       1       |       0        |\n| 0 | 0 | 1 |    1    |       0       |       1        |\n| 1 | 0 | 1 |    1    |       1       |       0        |\n| 0 | 1 | 1 |    1    |       0       |       1        |\n| 1 | 1 | 1 |    1    |       1       |       0        |\n+---+---+---+---------+---------------+----------------+\n*/\n```\n\n### Conjunctive Normal Form \u0026 DPLL\n\nA formula can be converted to CNF using its `cnf` method. This then enables you to use the DPLL algorithm to find a combination of variable values that will satisfy the formula, if any.\n\n```js\nlet cf1 = f1.cnf();\n\ncf1.toString(); // \"((a ∧ (¬b ∧ ¬c)) ∧ ((¬b ∨ a) ∧ (¬b ∨ c)))\"\ncf1.dpll(); // { a: true, b: false, c: false }\n\nnew propositional.Formula(\"a \u0026 !a\").cnf().dpll() // null\n```\n\nthe `dpll` method exists only on formulas converted to CNF to guarantee accuracy at a type-system level.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp2js%2Fpropositional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp2js%2Fpropositional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp2js%2Fpropositional/lists"}