{"id":21906098,"url":"https://github.com/yakuza8/first-order-predicate-logic-theorem-prover","last_synced_at":"2025-07-19T20:03:12.563Z","repository":{"id":52526603,"uuid":"231799926","full_name":"yakuza8/first-order-predicate-logic-theorem-prover","owner":"yakuza8","description":"Autonomous Theorem Prover for First Order Predicate Logic","archived":false,"fork":false,"pushed_at":"2020-06-29T17:35:27.000Z","size":106,"stargazers_count":8,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-07T13:39:52.117Z","etag":null,"topics":["ai","artificial-intelligence","first-order-logic","first-order-substitution","first-order-unification","most-general-unifier","subsumption","subsumption-elimination","tautology","tautology-checking","theorem-prover","theorem-proving"],"latest_commit_sha":null,"homepage":null,"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/yakuza8.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-01-04T17:12:42.000Z","updated_at":"2022-12-09T07:21:09.000Z","dependencies_parsed_at":"2022-09-23T04:24:57.959Z","dependency_job_id":null,"html_url":"https://github.com/yakuza8/first-order-predicate-logic-theorem-prover","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yakuza8%2Ffirst-order-predicate-logic-theorem-prover","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yakuza8%2Ffirst-order-predicate-logic-theorem-prover/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yakuza8%2Ffirst-order-predicate-logic-theorem-prover/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yakuza8%2Ffirst-order-predicate-logic-theorem-prover/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yakuza8","download_url":"https://codeload.github.com/yakuza8/first-order-predicate-logic-theorem-prover/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226952326,"owners_count":17708606,"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":["ai","artificial-intelligence","first-order-logic","first-order-substitution","first-order-unification","most-general-unifier","subsumption","subsumption-elimination","tautology","tautology-checking","theorem-prover","theorem-proving"],"created_at":"2024-11-28T16:40:43.575Z","updated_at":"2024-11-28T16:40:44.133Z","avatar_url":"https://github.com/yakuza8.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# First Order Predicate Logic Theorem Prover\n\n[![Build Status](https://travis-ci.com/yakuza8/first-order-predicate-logic-theorem-prover.svg?branch=master)](https://travis-ci.com/yakuza8/first-order-predicate-logic-theorem-prover)\n[![codecov](https://codecov.io/gh/yakuza8/first-order-predicate-logic-theorem-prover/branch/master/graph/badge.svg)](https://codecov.io/gh/yakuza8/first-order-predicate-logic-theorem-prover)\n\n## Description\nThe main aim of this project is to implement autonomous theorem prover for **First Order Predicate Logic** where\nproof method is **Proof by Refutation** with **Breadth First Search** strategy.\n\nFor first order predicate logic entities, _Variable_, _Constant_, _Function_ and _Predicate_ are used where\nthere are several semantics and rules on each entity. The mentioned semantics and rules are listed below:\n\n### Domain Information: \nEntity Name | Definition | Rules\n------------|------------|------\nVariable    | The most generic entity (also atomic) which can substitute any other entity | Name of variable should start with lower case \nConstant    | The most specific atomic entity which represents phenomenon in the world | Name of constant should start with upper case \nFunction    | Transformation entities in the world which map several entities to other entities, they can take other functions, variables and constants as its children | Name of function should start with lower case and predicates cannot be child of any function \nPredicate   | Entities which represent facts in the knowledge base, they can be negated for carrying the opposite meaning of itself, and they can take other functions, variables and constants as its children | Name of predicate should start with lower case, negation symbol is '~' symbol and predicates cannot take other predicates as their children\n\n### Most General Unifier - Meaning Formation:\nMeaning fusion is achieved via _Most General Unifier_ method since resolution of predicates will need some base of\nmeaning where resolver predicates can form common meaning and generate new resolvent from the commonly used terms.\n\nUnification may be done in the following entities:\n* Variable - variable: Can be unified in any order\n* Variable - constant: Can be unified by writing constant into where variable exists\n* Variable - function: Can be unified by writing function into where variable exists\n* Constant - variable: Can be unified by writing constant into where variable exists\n* Constant - constant: Can be unified if both constants are the same by EMPTY_SUBSTITUTION\n* Constant - function: Cannot be unified\n* Function - variable: Can be unified by writing function into where variable exists\n* Function - constant: Cannot be unified\n* Function - function: Can be unified if both functions have the same naming and their children can also be unified\n\n#### Example:\nExpression `p(f(h(w)), y, g(k(f(h(w))), x))` and `p(u, k(f(h(w))), g(z, h(w)))` can be unified with the following\nsubstitutions `[f(h(w)) / u, k(f(h(w))) / y, k(f(h(w))) / z, h(w) / x]` where right values will be replaced with\nleft values so that both expression will become the same fact.\n\n### Theorem Prover\nPseudo code for theorem prover is as the following, where my implementation waits for already CNF converted\nclauses in knowledge base and negated state of the target clauses. It will use proof by refutation method and\nthis is why it expects negated versions of the target clauses. Here, the aim is to reach contradiction in knowledge\nbase so that known clauses and negated version of target clauses create contradiction in the world, and that means\ninverse of target clauses should hold. \n\n```\nSymbols:\n    1) KB: Knowledge base\n    2) :math:`{\\\\alpha}`: Predicates to be proved\n\nAim: Prove KB -\u003e :math:`{\\\\alpha}`\n\nCLAUSES \u003c- CONVERT_TO_CNF( KB + :math:`{\\\\alpha}` )\nwhile EMPTY_RESOLVENT not in CLAUSES do\n    select two distinct clauses {c_i} and {c_j} in CLAUSES\n    compute a resolvent {r_ij} of {c_i} and {c_j}\n    CLAUSES \u003c- CLAUSES + {r_ij}\nend while\nreturn satisfaction\n```\n\nBreadth first strategy is used while generating new level clauses until **EMPTY_CLAUSE** is reached or there is\nno new clause to add among already known clauses. Here, **EMPTY_CLAUSE** means we achieved to resolve two opposite\nclause and get contradiction. Let's have a look at simple example for resolution.\n\nAdditionally, removing of tautologies and subsumption eliminations are applied for each layer of the search.\n\n```\n# Here, predicates q(z) and ~q(y) can be unified and resolved. The remaining predicates from both clauses\n# They will be merged into single clause and previously unification substitution will be applied into combined clause\nClause [~p(z,f(B)), q(z)] and clause [~q(y), r(y)] resolved into clause [~p(y,f(B)), r(y)] with substitution [y / z]\n```\n\n#### Input - Output\nIn this section sample inputs and corresponding outputs will be listed. But, before getting deep into examples,\nI want to mention about input format. Knowledge base and negated theorem predicates should be contained in the input\nwhich should have its format as **JSON**. You need to pay attention to key names since parser expects them as \n\"knowledge_base\" and \"negated_theorem_predicates\". Both of these are lists and each item in these list represents\na single clause which may have one or more predicates in it. Negated theorem predicates should be the negated version\nof clauses that you want to prove.\n\n**Important Note:** Your clauses will be interpreted in CNF (Conjunctive normal form) i.e. `q(z),~p(z,f(B))` will be\ninterpreted as `q(z) v ~p(z,f(B))` where symbol **v** means **OR** operator in first order logic.\n\n```json\n{\n    \"knowledge_base\": [\n        \"p(A,f(t))\",\n        \"q(z),~p(z,f(B))\",\n        \"~q(y),r(y)\"\n    ],\n    \"negated_theorem_predicates\": [\n        \"~r(A)\"\n    ]\n}\n```\n\n##### Examples 1\nInput:\n```json\n{\n    \"knowledge_base\": [\n        \"~p(x),q(x)\",\n        \"p(y),r(y)\",\n        \"~q(z),s(z)\",\n        \"~r(t),s(t)\"\n    ],\n    \"negated_theorem_predicates\": [\n        \"~s(A)\"\n    ]\n}\n```\n\nOutput:\n```\nInitial knowledge base clauses are:\nClause 0 \t| [~p(x), q(x)]\nClause 1 \t| [p(y), r(y)]\nClause 2 \t| [~q(z), s(z)]\nClause 3 \t| [~r(t), s(t)]\nClause 4 \t| [~s(A)]\nKnowledge base contradicts, so inverse of the negated target clause is provable.\nProve by refutation resolution order will be shown.\n[p(y), r(y)] | [~r(t), s(t)] -\u003e [p(t), s(t)] with substitution [t / y]\n[~s(A)] | [p(t), s(t)] -\u003e [p(A)] with substitution [A / t]\n[~p(x), q(x)] | [p(A)] -\u003e [q(A)] with substitution [A / x]\n[~q(z), s(z)] | [~s(A)] -\u003e [~q(A)] with substitution [A / z]\n[~q(A)] | [q(A)] -\u003e [] with substitution []\n```\n\n##### Examples 2\nInput:\n```json\n{\n    \"knowledge_base\": [\n        \"p(A,f(t))\",\n        \"q(z),~p(z,f(B))\",\n        \"r(y),~q(y)\"\n    ],\n    \"negated_theorem_predicates\": [\n        \"~r(A)\"\n    ]\n}\n```\n\nOutput:\n```\nInitial knowledge base clauses are:\nClause 0 \t| [p(A,f(t))]\nClause 1 \t| [~p(z,f(B)), q(z)]\nClause 2 \t| [~q(y), r(y)]\nClause 3 \t| [~r(A)]\nKnowledge base contradicts, so inverse of the negated target clause is provable.\nProve by refutation resolution order will be shown.\n[~q(y), r(y)] | [~r(A)] -\u003e [~q(A)] with substitution [A / y]\n[~p(z,f(B)), q(z)] | [~q(A)] -\u003e [~p(A,f(B))] with substitution [A / z]\n[p(A,f(t))] | [~p(A,f(B))] -\u003e [] with substitution [B / t]\n```\n\n## Running\nExample running command is provided below. Script expects file path for the input with _-f_ flag.\n```shell\n$ autonomous_theorem_prover.py -f ../sample_inputs/input3.inp\n``` \n\n## Notes\nThe project is written with **Python3.6** and no external library is used.\n\n## References\n* Russell, Stuart J. (Stuart Jonathan). (2010). Artificial intelligence : a modern approach. Upper Saddle River, N.J. :Prentice Hall, 285-365 \n* http://intrologic.stanford.edu/sections/section_12_09.html\n* http://www.mathcs.duq.edu/simon/Fall04/notes-7-4/node6.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyakuza8%2Ffirst-order-predicate-logic-theorem-prover","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyakuza8%2Ffirst-order-predicate-logic-theorem-prover","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyakuza8%2Ffirst-order-predicate-logic-theorem-prover/lists"}