{"id":23006377,"url":"https://github.com/syntapy/inferred-memes","last_synced_at":"2026-07-18T15:35:53.773Z","repository":{"id":21638659,"uuid":"24959294","full_name":"syntapy/inferred-memes","owner":"syntapy","description":"Symbolic logical inference","archived":false,"fork":false,"pushed_at":"2021-07-07T21:30:29.000Z","size":150,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"new_head","last_synced_at":"2025-10-25T02:57:24.158Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","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/syntapy.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}},"created_at":"2014-10-08T20:25:30.000Z","updated_at":"2022-07-11T18:33:44.000Z","dependencies_parsed_at":"2022-08-21T07:10:11.902Z","dependency_job_id":null,"html_url":"https://github.com/syntapy/inferred-memes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/syntapy/inferred-memes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntapy%2Finferred-memes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntapy%2Finferred-memes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntapy%2Finferred-memes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntapy%2Finferred-memes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syntapy","download_url":"https://codeload.github.com/syntapy/inferred-memes/tar.gz/refs/heads/new_head","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syntapy%2Finferred-memes/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35622753,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-18T02:00:07.223Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2024-12-15T08:12:21.705Z","updated_at":"2026-07-18T15:35:53.733Z","avatar_url":"https://github.com/syntapy.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"OVERVIEW\n--------\n\nThis is a logical inference engine and associated parser I did for a college class\n\nThe user places the input in the files `PRPS.txt` and `ALPHA.txt` using a simple \nsyntax for relational logic sentences specific to this program as described below\n\nThe software reads both files and deduces whether or not the sentence in `ALPHA.txt` \nis infered from the sentence in `PRPS.txt`.\n\nOnly the 1st line of each input file is read by the program\n\nHOW IT WORKS\n------------\nThe code reads the contents of `PRPS.txt` as one sentence, denoted here as `KB`,\nand the contents of `ALPHA.txt` as another sentence, denoted as `alpha`.\n\nAfter acquiring `KB` and `alpha`, inference is determined by proving whether `KB \u0026 !alpha` \nis a contradictory (i.e. impossible) statement. If it is contradictory, then `alpha` has to be\ntrue if `KB` is true\n\nThe proof is done by converting the sentence `KB \u0026 !alpha` into conjunctive normal form,\nand then reducing disjunctive clauses until a simple statement is reached that is obviously\nimpossible or obviously true\n\nALGORITHM OVERVIEW\n------------------\nSentences in the program are represented as binary trees in memory. Leaf nodes \nare relational logic symbols, and internal nodes are logic operators from the set\n(AND, OR, IMPLIES, EQUALS, FORALL, EXISTS). All nodes can be accompanied by a negate \noperator.\n\nFor instance, the statement `A[a] ^ B[b]` would be converted to a 3 element binary\ntree with the AND operator as the root node, and `A[a]` being the left child, and `B[b]` \nbeing the right child\n\nEach node in the tree is a pointer to a struct, which contains info on whether that node\nis a logic operator or a relational logic symbol, and which of either it is\n\nThe parser recursivively handles subsentences in parantheses as sub-trees\n\nUniversal quantifiers are processed using skolemization. This involves replicating the \nuniversally quantified subtree across all possible combinations of logic functions and \ntheir respective arguments, where the space of all possible symbols is limited to those \nseen during parsing\n\nExistential quantifiers are done by simply generating a new symbol not seen during parsing\n(and not generated yet either)\n\nIt is straightforward to combine both quantifier types in a sentence\n\nThe recursive sentence parsing allows quantifiers to be nested to arbitrary depth\n(as limited by recursive stack size and memory)\n\nThe resolution of each clause in the conjunctive normal form tree is done in a naive\nway, however, making the algorithm very inneficient, and the NP-Complete nature of it\neasily becomes apparent on the following textbook problem where:\n\n`KB = 4 x{ 4 y{Animal[y] -\u003e Loves[x, y]} -\u003e 3 y{Loves[y, x]}} ^ 4 x{3 z{Animal[z] ^ Kills[x, z]} -\u003e 4 y{!Loves[y, x]}} ^ 4 x{Animal[x] -\u003e Loves[jack, x]} ^ Kills[jack, tuna] v Kills[curiosity, tuna] ^ Cat[tuna] ^ 4 x{Cat[x] -\u003e Animal[x]}`\n\nand `alpha = Kills[curiosity, tuna]`\n\nFor this input, a 4GB RAM computer runs out of memory after a few days of computation.\n\nHowever, for more trivial examples, the program runs correctly:\n - `KB = (A[a] -\u003e B[b]) ^ (B[b] -\u003e C[c])` and `alpha = (A[a] -\u003e C[c])`\n - `KB = A[a] ^ 4 x{A[x] -\u003e B[x]}` and `alpha = B[a]`\n\nThe algorithm has been shown to produce correct result in the following cases as well:\n -  `KB = (A[a] -\u003e B[b]) ^ (B[b] -\u003e C[c]) ^ (C[c] -\u003e D[d])` predicts that `alpha = (A[a] -\u003e D[d])` is infered\n -  `KB = (A[a] -\u003e B[b]) ^ (B[b] -\u003e C[c]) ^ (C[c] -\u003e D[d])` predicts that `alpha = !(A[a] -\u003e D[d])` is not infered\n -  `KB = A[a] ^ 4 x{A[x] -\u003e B[x]}` predicts that `alpha = B[a]` is infered\n -  `KB = A[a] ^ 4 x{A[x] -\u003e B[x]}` predicts that `alpha = A[a]` is not infered\n\nINPUT FILES AND THEIR SYNTAX\n----------------------------\n\n*Note: in both `PRPS.txt` and `ALPHA.txt`, only the first line is read. All other lines are ingored.*\n\n**`PRPS.txt`**\n\nThis file contains a relational sentence using a particular basic syntax.\n -  A single character upper case letter followed by any number of a-z characters is a relational symbol / function\n -  Propositional symbols are followd by square brackets with any number of arguments inside them\n -  Each argument consists of a string of a-z lowercase characters of arbitrary length\n -  Each relational symbol takes exactly any number of arguments, each seperated by a comma, and a space after the comma\n\n -  Foral symbols are represented by the numeral 4; existential operators are represented by numeral 3. \n   - Each is followd by one or more argument symbols and then the containing sentence in curly braces\n         For instance: \n\n          - `4 creature, animal{(Eats[animal, creature] ^ Insect[creature]) -\u003e Insectivor[animal]}`\n\n          - `4 boy{3 girl{Teaches[girl, boy]}}`\n\n         The second one says \"For every boy, there is a girl who teaches that boy.\"\n\n   - Operator symbols:\n\n        `^`  -- AND\n\n        `v`  -- OR\n\n        `-\u003e` -- IMPLIES\n\n        `=`  -- TAUTOLOGY\n\n        `!`  -- Negation, i.e. `!Car[object]` or `!(Plane[object])`\n\n\n   - Statements can be put in `(` `)` parentheses. For instance: \n\n        `((Car[vehicle] ^ Belongs[vehicle, ted]) v (B[a] ^ B[b])) = C[c]`\n\n**`ALPHA.txt`**\n\nA single relational sentence with as described in `PRPS.txt` instructions above\nThis statement is the one that the software is supposed to infer about.\nIt can be a single symbol such as `Red[car]` or a full fledged sentence\n\nCOMPILING\n---------\n\nThis was tested on debian-based system\n\nDependencies are just gcc, ctags, and gnu make:\n    \n    `sudo apt install gcc exuberant-ctags make`\n\nTo compile just type:\n\n    `make`\n\n\nUSAGE\n-----\n\nNote: this program was written and tested only in Linux i386 architecture.\n\nSimply write your knowledge base in the first line of `PRPS.txt`\nThe statement you wish to test if it is implied from the knowledge base goes into `ALPHA.txt`\nAfter compiling type in\n    \n    ./resolve\n\nat the prompt\n\nFURTHER WORK\n------------\n    \nThe resolution algorithm is done in a basic manner only, and does not have any intelligent means to select which clauses are compared in any way, thus making it very very innefficient for non-trivial logic sentences.\n\nKNOWN BUGS\n----------\n    \nNone right now. However, it has not been rigorously tested yet.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntapy%2Finferred-memes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyntapy%2Finferred-memes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyntapy%2Finferred-memes/lists"}