{"id":21340719,"url":"https://github.com/artainmo/expert-system","last_synced_at":"2025-03-16T02:42:52.747Z","repository":{"id":179565453,"uuid":"657135762","full_name":"artainmo/expert-system","owner":"artainmo","description":"42 school project. Write an expert system in propositional calculus. A type of AI program that can reason on a set of rules and initial facts to deduce other facts.","archived":false,"fork":false,"pushed_at":"2023-07-20T18:42:51.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-22T15:32:12.360Z","etag":null,"topics":["42school","artificial-intelligence","expert-system","propositional-logic","python"],"latest_commit_sha":null,"homepage":"","language":"Python","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/artainmo.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":"2023-06-22T11:51:33.000Z","updated_at":"2023-07-28T06:42:37.000Z","dependencies_parsed_at":"2023-07-22T14:31:14.776Z","dependency_job_id":null,"html_url":"https://github.com/artainmo/expert-system","commit_stats":null,"previous_names":["artainmo/expert-system"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artainmo%2Fexpert-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artainmo%2Fexpert-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artainmo%2Fexpert-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/artainmo%2Fexpert-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/artainmo","download_url":"https://codeload.github.com/artainmo/expert-system/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243817873,"owners_count":20352625,"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":["42school","artificial-intelligence","expert-system","propositional-logic","python"],"created_at":"2024-11-22T00:52:45.007Z","updated_at":"2025-03-16T02:42:52.740Z","avatar_url":"https://github.com/artainmo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# expert-system\n42 school [subject](https://cdn.intra.42.fr/pdf/pdf/81332/en.subject.pdf).\n\nWrite an expert-system in propositional calculus (aka propositional logic).\u003cbr\u003e\nAn expert-system is a type of AI program that can reason on a set of rules and initial facts to deduce other facts. It at least consists of a UI, inference engine and knowledge base. The knowledge base consists of facts and rules, added by an expert, forming the knowledge of the system. While the inference engine is the algorithm that uses those rules to deduce answers to questions received from the UI. Those rules and deductions are often described using _if-then_ statements.\u003cbr\u003e\nPropositional calculus is simply the formal basis of logic dealing with the notion and usage of words such as \"NOT,\" \"OR,\" \"AND,\" and \"implies\". The expert-system uses this convention for its rules and inferences.\n\nInference engines can use two strategies, namely forward- and backward-chaining.\u003cbr\u003e\nWith forward-chaining we first look at the underlying facts and rules to deduce the outcome. While with backward-chaining we first look at the outcome and its rules to deduce the underlying facts.\u003cbr\u003e\nIn this project we have to implement backward-chaining. Here is an example of how it works.\n```\nOutcome (given as input): He is sweating.\nAssociated rule (found in knowledge base): If he is running, he sweats.\nUnderlying fact (deducted by inference engine): He is running.\n```\n\n## Workings\nHere is an example of an input file. The input file represents the knowledge base (facts and rules) and UI (queries).\n```\n# this is a comment\n# input file created from this backward-chaining video example (https://www.youtube.com/watch?v=6DU42so8k48)\n\nF + B -\u003e Z        # F and B implies Z\nC + D -\u003e F        # C and D implies F\nA     -\u003e D        # A implies D\n\n=AEBC             # Initial facts : A, E, B and C are true. All others are false.\n\n?Z                # Queries: Is Z true or false?\n```\nFor this input file the backward-chaining algorithm would work like this:\n* Find the value of Z\n  * Check if part of initial facts else find the Z rule(s). (F + B -\u003e Z)\n  * To decipher this rule find the F value.\n    * Check if part of initial facts else find the F rule(s). (C + D -\u003e F)\n    * To decipher this rule find C value.\n      * Check if part of initial facts. (=AEBC)\n      * Now we know C is true because it is part of initial facts.\n    * To decipher this rule find D value. (C(true) + D -\u003e F)\n      * Check if part of initial facts else find the D rule(s). (A -\u003e D)\n      * To decipher this rule find A value.\n        * Check if part of initial facts. (=AEBC)\n        * Now we know A is true because it is part of initial facts.\n      * Now we know D is true. (A(true) -\u003e D)\n    * Now we know F is true. (C(true) + D(true) -\u003e F)\n  * To decipher this rule find the B value. (F(true) + B -\u003e Z)\n    * Check if part of initial facts. (=AEBC)\n    * Now we know B is true because it is part of initial facts.\n  * Now we know Z is true. (F(true) + B(true) -\u003e Z)\n\n## Use\n```\npython3.7 expert-system.py \u003cflags(optional)\u003e \u003cinput file\u003e\npython3.7 expert-system.py tests/simple1.txt\npython3.7 expert-system.py -v tests/complex.txt # verbose, see explanations\npython3.7 expert-system.py -d tests/simple2.txt # debug, stop algo at specific point\n```\n\n## Documentation\n[youtube - Lecture 11: Rules and Introduction to Expert Systems](https://www.youtube.com/watch?v=BXHcPESoaPY)\u003cbr\u003e\n[youtube - Introduction to Expert Systems](https://www.youtube.com/watch?v=Z-HdPw9fpqI)\u003cbr\u003e\n[youtube - Inference Engines for Expert Systems by Richard Neapolitan](https://www.youtube.com/watch?v=h6zCkrZ8ehE)\u003cbr\u003e\n[youtube - Lecture 12: Rule-based and Other Expert Systems](https://www.youtube.com/watch?v=GXLURYcP33k)\u003cbr\u003e\n[youtube - 3. Reasoning: Goal Trees and Rule-Based Expert Systems](https://www.youtube.com/watch?v=leXa7EKUPFk)\u003cbr\u003e\n[mathworld - Propositional Calculus](https://mathworld.wolfram.com/PropositionalCalculus.html)\u003cbr\u003e\n[javapoint - Propositional logic in Artificial intelligence](https://www.javatpoint.com/propositional-logic-in-artificial-intelligence)\u003cbr\u003e\n[geeksforgeeks - Expert Systems](https://www.geeksforgeeks.org/expert-systems/)\u003cbr\u003e\n[medium - An Introduction to Expert System Shells](https://medium.com/nerd-for-tech/an-introduction-to-expert-system-shells-530043914ec0)\u003cbr\u003e\n[geeksforgeeks - Difference between Backward and Forward Chaining.](https://www.geeksforgeeks.org/difference-between-backward-and-forward-chaining/)\u003cbr\u003e\n[youtube - backward chaining example | Artificial intelligence | Lec-40 | Bhanu Priya](https://www.youtube.com/watch?v=6DU42so8k48)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartainmo%2Fexpert-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fartainmo%2Fexpert-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fartainmo%2Fexpert-system/lists"}