{"id":14235414,"url":"https://github.com/alexprengere/FormalSystems","last_synced_at":"2025-08-11T00:31:19.132Z","repository":{"id":4260406,"uuid":"5387139","full_name":"alexprengere/FormalSystems","owner":"alexprengere","description":"A Python implementation of Douglas Hofstadter formal systems, from his book \"Gödel, Escher, Bach\"","archived":false,"fork":false,"pushed_at":"2021-03-25T21:38:47.000Z","size":52,"stargazers_count":621,"open_issues_count":3,"forks_count":35,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-06-29T00:49:16.309Z","etag":null,"topics":["python"],"latest_commit_sha":null,"homepage":"http://alexprengere.github.com/FormalSystems/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexprengere.png","metadata":{"files":{"readme":"README.rst","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":"2012-08-12T08:42:37.000Z","updated_at":"2025-06-09T16:12:24.000Z","dependencies_parsed_at":"2022-09-02T11:01:40.987Z","dependency_job_id":null,"html_url":"https://github.com/alexprengere/FormalSystems","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alexprengere/FormalSystems","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2FFormalSystems","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2FFormalSystems/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2FFormalSystems/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2FFormalSystems/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexprengere","download_url":"https://codeload.github.com/alexprengere/FormalSystems/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexprengere%2FFormalSystems/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269813534,"owners_count":24479340,"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","status":"online","status_checked_at":"2025-08-10T02:00:08.965Z","response_time":71,"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":["python"],"created_at":"2024-08-20T21:01:54.103Z","updated_at":"2025-08-11T00:31:18.740Z","avatar_url":"https://github.com/alexprengere.png","language":"Python","readme":"=======================\nFormalSystems |travis|_\n=======================\n\n.. _travis : https://travis-ci.org/alexprengere/FormalSystems\n.. |travis| image:: https://api.travis-ci.org/alexprengere/FormalSystems.png\n\nThis is a Python implementation of *Douglas Hofstadter* formal systems, from his book *Gödel, Escher, Bach: An Eternal Golden Braid* (commonly *GEB*).\n\nIn fact, you may define your *own formal systems* using a quite simple syntax, close to free text.\nExamples for *MIU*, *pg*, *fg* and *NDP* formal systems from the book are implemented in directory *definitions*.\n\nA main Python script gives you possibilities to play with the formal system, including:\n\n- axiom schema support (iteration, decision procedure)\n- theorem step by step generation (using different algorithms)\n- theorem derivation\n\n\n------------------------\nFormal system definition\n------------------------\n\nExamples\n========\n\nThe *MIU* system may be define with:\n\n.. code-block:: yaml\n\n    axioms:\n        - MI\n\n    rules:\n        - x is .*, xI =\u003e xIU\n        - x is .*, Mx =\u003e Mxx\n        - x is .*, y is .*, xIIIy =\u003e xUy\n        - x y  .* , xUUy =\u003e xy\n\nThe underlying syntax is YAML (see raw format). You can define one or several axioms, or even an infinite number of axioms using a schema, as in the *pg* formal system:\n\n.. code-block:: yaml\n\n    axioms:\n        - x is -+, xp-gx-\n\n    rules:\n        - x y z are -+, xpygz =\u003e xpy-gz-\n\n\nSyntax\n======\n\nAxiom definitions should be formatted like this (``[]`` means this is optional):\n\n.. code-block:: bash\n\n [def_1, [def_2, ...]] expr\n\nWhere:\n\n- ``def_i`` is an optional definition of *wildcard*, using a regular expression, for example:\n\n  - \".*\" may be anything including the empty string\n  - \"-+\" is a string composed of \"-\"\n\nThe definitions are written using ``char [is] regexp`` or ``char1 char2 [are] regexp`` if different wildcards have the same definition. Note that you should use only *one character* for wildcard definition.\n\n- ``expr`` is the axiom expression\n\nRules for theorem production should be formatted like this:\n\n.. code-block:: bash\n\n [def_1, [def_2, ...]] cond_1 [and cond_2 [and ...]] =\u003e th_1 [and th_2 [and ...]]\n\nWhere:\n\n- ``def_i`` is the same as before\n- ``cond_i`` is a required theorem, in order to produce new theorems (separated by *and* if several conditions)\n- ``th_i`` is a produced theorems with the rule\n\n------------\nInstallation\n------------\n\nInstall with:\n\n.. code-block:: bash\n\n $ python setup.py install --user\n\nA script should be put in ``~/.local/bin``, make sure this path is in your ``$PATH``:\n\n.. code-block:: bash\n\n $ export PATH=$PATH:~/.local/bin\n\n-----\nTests\n-----\n\nIf installation is successful, run the tests with:\n\n.. code-block:: bash\n\n $ cd tests\n $ python test_formalsystems.py -v\n\n-----------\nMain script\n-----------\n\nAfter installation, you should have the main script ``FormalSystemsMain.py`` deployed somewhere where you ``$PATH`` points to, under the name ``FormalSystems``.\nIf it is not the case, you can always execute the script directly, assuming the dependencies are properly installed (just *pyyaml* and *LEPL*).\n\nUsage of the main script is fully documented in ``--help`` argument.\n\nYou may generate theorems step by step if the number of axioms is finite:\n\n.. code-block:: bash\n\n $ FormalSystems definitions/MIU.yaml --iteration 3 \n \u003e Finite number of axioms, using step algorithm\n\n STEP 1: MI\n\n P  (1) x is .*, xI =\u003e xIU                    for  MI                         gives  MIU\n P  (2) x is .*, Mx =\u003e Mxx                    for  MI                         gives  MII\n .  (3) x is .*, y is .*, xIIIy =\u003e xUy        for  MI                       \n .  (4) x y  .* , xUUy =\u003e xy                  for  MI                       \n\n STEP 2: MIU/MII\n\n P  (1) x is .*, xI =\u003e xIU                    for  MII                        gives  MIIU\n .  (1) x is .*, xI =\u003e xIU                    for  MIU                      \n P  (2) x is .*, Mx =\u003e Mxx                    for  MII                        gives  MIIII\n P  (2) x is .*, Mx =\u003e Mxx                    for  MIU                        gives  MIUIU\n .  (3) x is .*, y is .*, xIIIy =\u003e xUy        for  MII                      \n .  (3) x is .*, y is .*, xIIIy =\u003e xUy        for  MIU                      \n .  (4) x y  .* , xUUy =\u003e xy                  for  MII                      \n .  (4) x y  .* , xUUy =\u003e xy                  for  MIU                      \n\n STEP 3: MIIU/MIIII/MIUIU\n\nOr using a bucket where axioms are thrown and theorems computed iteratively if the number of axioms is infinite:\n\n.. code-block:: bash\n\n $ FormalSystems definitions/pg.yaml --iteration 4\n \u003e Infinite number of axioms, using bucket algorithm\n\n [Adding -p-g-- to bucket]\n\n === BUCKET 1: -p-g--\n\n P  (1) x y z are -+, xpygz =\u003e xpy-gz-        for  -p-g--                     gives  -p--g---\n [Adding --p-g--- to bucket]\n\n === BUCKET 2: -p--g---/--p-g---\n\n P  (1) x y z are -+, xpygz =\u003e xpy-gz-        for  -p--g---                   gives  -p---g----\n P  (1) x y z are -+, xpygz =\u003e xpy-gz-        for  --p-g---                   gives  --p--g----\n [Adding ---p-g---- to bucket]\n\n === BUCKET 3: -p---g----/--p--g----/---p-g----\n\n P  (1) x y z are -+, xpygz =\u003e xpy-gz-        for  -p---g----                 gives  -p----g-----\n P  (1) x y z are -+, xpygz =\u003e xpy-gz-        for  ---p-g----                 gives  ---p--g-----\n P  (1) x y z are -+, xpygz =\u003e xpy-gz-        for  --p--g----                 gives  --p---g-----\n [Adding ----p-g----- to bucket]\n\n === BUCKET 4: -p----g-----/---p--g-----/--p---g-----/----p-g-----\n\nOptions are available to display theorem derivation as well:\n\n.. code-block:: bash\n\n $ FormalSystems definitions/NDP.yaml --quiet --derivation P-----\n \u003e Infinite number of axioms, using bucket algorithm\n \u003e Rule with several parents, using recursivity\n\n === BUCKET 1: --NDP-\n === BUCKET 2: --NDP---/-SD--/P--\n === BUCKET 3: --NDP-----/---SD--/---NDP--\n === BUCKET 4: --NDP-------/---NDP-----/-----SD--/P---/---NDP-\n === BUCKET 5: --NDP---------/---NDP--------/---NDP----/-------SD--/-----SD---/-SD---/----NDP---\n === BUCKET 6: ---NDP-----------/----NDP-------/---NDP-------/--NDP-----------/---------SD--/----NDP-\n === BUCKET 7: ----NDP-----------/----NDP-----/---NDP----------/---NDP--------------/--NDP-------------/-----------SD--/-------SD---/-SD----/----NDP--\n === BUCKET 8: ----NDP---------/----NDP---------------/---NDP-------------/---NDP-----------------/--NDP---------------/----NDP------/-------------SD--/-------SD----/-----SD----/-----------SD---/-----NDP-\n === BUCKET 9: --NDP-----------------/-----NDP------/----NDP-------------/---NDP--------------------/---NDP----------------/----NDP----------/----NDP-------------------/---------------SD--/-SD-----/-------------SD---/-----------SD----/P-----/-----NDP--\n\n === Theorem P----- found, derivation:\n [1 ]  Axiom                                                                     gives  --NDP-              \n [2 ]  (1) x y are -+, xNDPy =\u003e xNDPxy           for  --NDP-                     gives  --NDP---            \n [3 ]  Axiom                                                                     gives  ---NDP--            \n [3 ]  (1) x y are -+, xNDPy =\u003e xNDPxy           for  --NDP---                   gives  --NDP-----          \n [4 ]  Axiom                                                                     gives  ----NDP-            \n [4 ]  (1) x y are -+, xNDPy =\u003e xNDPxy           for  ---NDP--                   gives  ---NDP-----         \n [4 ]  (2) z is -+, --NDPz =\u003e zSD--              for  --NDP-----                 gives  -----SD--           \n [5 ]  (1) x y are -+, xNDPy =\u003e xNDPxy           for  ----NDP-                   gives  ----NDP-----        \n [5 ]  (3) x z are -+, zSDx and x-NDPz =\u003e zSDx-  for  -----SD-- and ---NDP-----  gives  -----SD---          \n [6 ]  (3) x z are -+, zSDx and x-NDPz =\u003e zSDx-  for  -----SD--- and ----NDP-----  gives  -----SD----         \n [7 ]  (4) z is -+, z-SDz =\u003e Pz-                 for  -----SD----                gives  P-----\n\n\n----------\nPython API\n----------\n\nSome tests using *doctests*:\n\n.. code-block:: python\n\n \u003e\u003e\u003e from formalsystems.formalsystems import FormalSystem, Theorem\n\nMIU formal system:\n\n.. code-block:: python\n\n \u003e\u003e\u003e fs = FormalSystem()\n \u003e\u003e\u003e fs.read_formal_system('./definitions/MIU.yaml')\n \u003e\u003e\u003e r = fs.apply_rules_step(fs.iterate_over_schema(), step=4, verbose=False)\n STEP 1: MI\n STEP 2: MIU/MII\n STEP 3: MIIU/MIIII/MIUIU\n STEP 4: MIIIIU/MIIIIIIII/MIIUIIU/MIUIUIUIU/MIU/MUI\n \u003e\u003e\u003e print [str(a) for a in fs.iterate_over_schema()]\n ['MI']\n\npg formal system:\n\n.. code-block:: python\n\n \u003e\u003e\u003e fs = FormalSystem()\n \u003e\u003e\u003e fs.read_formal_system('./definitions/pg.yaml')\n \u003e\u003e\u003e r = fs.apply_rules_bucket_till(fs.iterate_over_schema(), max_turns=4, verbose=False)\n === BUCKET 1: -p-g--\n === BUCKET 2: -p--g---/--p-g---\n === BUCKET 3: -p---g----/--p--g----/---p-g----\n === BUCKET 4: -p----g-----/---p--g-----/--p---g-----/----p-g-----\n \u003e\u003e\u003e r = fs.apply_rules_bucket_till(fs.iterate_over_schema(), min_len=9, verbose=False)\n === BUCKET 1: -p-g--\n === BUCKET 2: -p--g---/--p-g---\n === BUCKET 3: -p---g----/--p--g----/---p-g----\n\nNDP formal system:\n\n.. code-block:: python\n\n \u003e\u003e\u003e fs = FormalSystem()\n \u003e\u003e\u003e fs.read_formal_system('./definitions/NDP.yaml')\n \u003e\u003e\u003e r = fs.apply_rules_bucket_till(fs.iterate_over_schema(), max_turns=2, full=True, verbose=False)\n === BUCKET 1: --NDP-\n === BUCKET 2: --NDP---/-SD--/P--\n\nSuccessful derivation:\n\n.. code-block:: python\n\n \u003e\u003e\u003e fs = FormalSystem()\n \u003e\u003e\u003e fs.read_formal_system('./definitions/NDP.yaml')\n \u003e\u003e\u003e r = fs.derivation_asc(fs.iterate_over_schema(), Theorem('P-----'), full=True, max_turns=10)\n \u003cBLANKLINE\u003e\n ...\n === Theorem P----- found, derivation:\n ...\n\nFailed derivation:\n\n.. code-block:: python\n\n \u003e\u003e\u003e fs = FormalSystem()\n \u003e\u003e\u003e fs.read_formal_system('./definitions/MIU.yaml')\n \u003e\u003e\u003e r = fs.derivation_step(fs.iterate_over_schema(), Theorem('MIUIU'), step=5)\n \u003cBLANKLINE\u003e\n ...\n === Theorem MIUIU found, derivation:\n ...\n \u003e\u003e\u003e r = fs.derivation_step(fs.iterate_over_schema(), Theorem('MU'), step=5)\n \u003cBLANKLINE\u003e\n ...\n === Theorem MU not found\n\n","funding_links":[],"categories":["Python","Philosophy"],"sub_categories":["MacOS"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexprengere%2FFormalSystems","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexprengere%2FFormalSystems","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexprengere%2FFormalSystems/lists"}