{"id":16937700,"url":"https://github.com/evtn/matlog","last_synced_at":"2025-10-27T20:35:47.685Z","repository":{"id":51143715,"uuid":"259231386","full_name":"evtn/matlog","owner":"evtn","description":"a tiny boolean algebra expressions parser and solver (sometimes it can even simplify expressions)","archived":false,"fork":false,"pushed_at":"2021-05-21T15:38:39.000Z","size":105,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"lord","last_synced_at":"2025-03-25T15:11:13.335Z","etag":null,"topics":["boolean-algebra","truth-tables"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evtn.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":"2020-04-27T06:56:41.000Z","updated_at":"2022-03-09T20:39:03.000Z","dependencies_parsed_at":"2022-09-26T17:20:15.902Z","dependency_job_id":null,"html_url":"https://github.com/evtn/matlog","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evtn%2Fmatlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evtn%2Fmatlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evtn%2Fmatlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evtn%2Fmatlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evtn","download_url":"https://codeload.github.com/evtn/matlog/tar.gz/refs/heads/lord","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248465344,"owners_count":21108244,"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":["boolean-algebra","truth-tables"],"created_at":"2024-10-13T21:00:02.434Z","updated_at":"2025-10-27T20:35:47.620Z","avatar_url":"https://github.com/evtn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# matlog\n\n**This module is well-documented with docstrings and type hints. Use `help(matlog.tokens)` or your editor hints to get familiar with it.**\n\nBasic usage:    \n```python\nfrom matlog import parse\n\nexpr = parse(\"A \u0026 B\")\nprint(expr.solve(A=1, B=0)) # False\nprint(expr.solve(B=0)) # False\nprint(expr.table()) # prints the truth table of expression\n```\n\n## Installation\n\nSimply use `pip install matlog` or clone repo and launch `setup.py`\n\n\n## Contents\n+ [Expression string](#expression-string)\n+ [Using Expression object](#expression)\n  + [Truth tables](#truth-tables)\n  + [Evaluating expression](#evaluating-expression)\n  + [Partial evaluation](#partial-evaluation)\n  + [Simplify](#simplify)\n  + [Equality check](equality-check)\n  + [proposition](proposition)\n\n## Expression string\nAn expression string is a bunch of tokens (atoms, expressions, operators and literals) in a specific order.\nThere's a big example of expression string:    \n`a | (b -\u003e c) == (~a ^ 1) \u003c- ~z`\n\nLet's review in detail:    \n\n### Atoms\n\nAny letter is considered as an atom. Atoms can be only one letter long and must be divided by operators.\n\n### Literals\n\nA literal is `1` or `0` (True and False respectively). Literals are treated like atoms.\n\n### Expressions\n\nAny expression can contain nested expression strings in brackets. Nested expressions are treated like atoms.\n\n### Operators\n\n*matlog* expression syntax supports 6 binary operators and one unary (listed in order of priority, from high to low):\n+ **~** (not / negation) *unary*: turns **True** to **False** and vice versa. \n+ **\u0026** (and / conjunction): **True** if (and only if) both operands are **True**\n+ **|** (or / disjunction): **True** if (and only if) any operand is **True**.\n+ **-\u003e** (implication): **False** if (and only if) the left operand is **True** but the right is **False**\n+ **==** (equality / biconditional): **True** if (and only if) operands are equal to each other\n+ **^** (xor / exclusive disjunction): **False** if (and only if) operands are equal to each other\n+ **\u003c-** (converse implication): **-\u003e** with reversed operands order\n\n## Expression\n\nExpression class is the main class of the module.\nThere are three ways to create an Expression object:\n+ from an [expression string](#expression-string): `matlog.parse(expr_str)`\n+ copying an existing Expression: `expr.copy()` (same as `matlog.Expression(expr.tokens)`)\n+ deep-copying an existing Expression object: `expr.deep_copy()`\n+ constructing an Expression from tokens (**module won't check if it is valid in this case**): `matlog.Expression([token1, token2...])`\n\n### Truth tables \n\nYou can use `expr.table(keep=None)` method to build a truth table for an Expression object.\n`keep` parameter can be either `1` or `0` (to filter rows with corresponding values) or `None` if you need a full table    \n\n### Evaluating expression\n\nIf you need a value for a specific set of values, you can use `.solve()` method like this:\n\n```python\nfrom matlog import parse\n\nexpr = parse(\"A \u0026 B | C\")\nprint(expr.solve(A=1, B=0, C=1)) # prints 1\nprint(expr.solve({\"A\": 1, \"B\": 0, \"C\": 1})) # you can pass a dictionary too\n```\n\nif you need a result value (release version would provide more convenient ways, of course):\n\n```python\nexpr.value(A=1, B=0, C=1) # 1 (raises an exception if there's not enough data to solve expression)\n```\n\n### Partial evaluation\n\nIf you know some (but not all) values, you can also use `.solve()`, providing some values:\n\n```python\nfrom matlog import parse\n\nexpr = parse(\"A \u0026 B | C\")\nprint(expr.solve(B=0)) # prints C\nprint(expr.solve({\"B\": 0})) # prints C too\n``` \n\n### Simplify\n\nSmart (smarter than watermelon!) algorithm, simplifies expressions better than bare `.solve()`.    \nThis method recursively simplifies complex expressions, so expect it to work slower than (again) bare `.solve()`.\n\n```python\nfrom matlog import parse\n\nexpr = parse(\"(A | B | C) \u0026 ~(A | ~B | C)\")\nprint(expr.simplify()) # prints ~(A | ~B | C)\n```\n\n\n### Equality check\n\nIf you're wondering if expressions are equal (producing the same results with any set of values), you can use `Expression.equals(self, other)` method:\n\n```python\nfrom matlog import parse\n\nexpr1 = parse(\"A \u0026 B\")\nexpr2 = parse(\"B \u0026 A\")\nprint(expr1.equals(expr2)) # True\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevtn%2Fmatlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevtn%2Fmatlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevtn%2Fmatlog/lists"}