{"id":18274138,"url":"https://github.com/drknzz/deterministic-finite-automata","last_synced_at":"2026-02-05T23:32:23.133Z","repository":{"id":131252389,"uuid":"498509347","full_name":"drknzz/Deterministic-Finite-Automata","owner":"drknzz","description":"🔄 Deterministic Finite Automata simulator 🔄","archived":false,"fork":false,"pushed_at":"2022-09-04T21:15:28.000Z","size":95,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-18T02:47:49.438Z","etag":null,"topics":["automata","automata-simulator","automata-theory","deterministic-finite-automata","dfa","predicate","prolog","simulator","swipl"],"latest_commit_sha":null,"homepage":"","language":"Prolog","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/drknzz.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,"zenodo":null}},"created_at":"2022-05-31T21:55:18.000Z","updated_at":"2024-08-31T11:26:28.000Z","dependencies_parsed_at":"2023-07-09T02:17:37.423Z","dependency_job_id":null,"html_url":"https://github.com/drknzz/Deterministic-Finite-Automata","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drknzz/Deterministic-Finite-Automata","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drknzz%2FDeterministic-Finite-Automata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drknzz%2FDeterministic-Finite-Automata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drknzz%2FDeterministic-Finite-Automata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drknzz%2FDeterministic-Finite-Automata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drknzz","download_url":"https://codeload.github.com/drknzz/Deterministic-Finite-Automata/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drknzz%2FDeterministic-Finite-Automata/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29138375,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-05T23:14:48.546Z","status":"ssl_error","status_checked_at":"2026-02-05T23:14:35.724Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["automata","automata-simulator","automata-theory","deterministic-finite-automata","dfa","predicate","prolog","simulator","swipl"],"created_at":"2024-11-05T12:08:45.939Z","updated_at":"2026-02-05T23:32:23.121Z","avatar_url":"https://github.com/drknzz.png","language":"Prolog","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eDeterministic Finite Automata\u003c/h2\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/65187002/188329602-69cc62c8-f575-418e-a5ac-d350de35dd0d.png\"\u003e\n\u003c/div\u003e\n\n\u003ca name=\"Description\"\u003e\u003c/a\u003e\n\n# 🔄 Description 🔄\n\n[Deterministic Finite Automata](https://en.wikipedia.org/wiki/Deterministic_finite_automaton) (DFA) simulator written in [Prolog](https://en.wikipedia.org/wiki/Prolog).\n\n### Table of Contents:\n- [Definitions](#Definitions)\n- [Specification](#Specification)\n- [Predicates](#Predicates)\n- [Examples](#Examples)\n- [Example usage](#Example_usage)\n\n\u003cbr\u003e\n\n\u003ca name=\"Definitions\"\u003e\u003c/a\u003e\n\n# 📃 Definitions 📃\n\nWe define a deterministic finite automaton (DFA) as a tuple:\n\n$$ \\langle Q, \\Sigma, \\delta, q_0, F \\rangle $$\n\nwhere:\n- $Q$ is a finite set of states\n- $\\Sigma$ is a finite alphabet\n- $\\delta: Q \\times \\Sigma \\rightarrow Q$ is a transition function\n- $q_0 \\in Q$ is an initial state\n- $F \\subseteq Q$ is a set of accept states\n\nWe say that an automaton *accepts* a word $w = a_1a_2\\dots a_n,\\ n \\geq 0$ if:\n\n$$ \\delta(q_0, a_1) = q_1, \\delta(q_1, a_2) = q_2, \\dots,\\delta(q_{n-1}, a_n) = q_n $$\n\nand state $q_n$ is an accept state.\n\nA language accepted by an automaton $A$ is defined as a set of words accepted by that automaton:\n\n$$ L(A) = \\\\{ w: \\text{automaton} \\ A \\ \\text{accepts the word} \\ w \\\\} $$\n\n\u003cbr\u003e\n\n\u003ca name=\"Specification\"\u003e\u003c/a\u003e\n\n# 🔀 Specification 🔀\n\nA DFA is represented by terms of the form:\n\n`dfa(+TransitionFunction, +InitialState, -AcceptStatesSet)`\n\nwhere:\n- `TransitionFunction` is a list of terms of form `fp(S1, C, S2)` meaning, that $\\delta(S1, C) = S2$\n- `InitialState` is an initial state of automaton\n- `AcceptStatesSet` is a list of all unique accept states of an automaton\n\n\u003cbr\u003e\n\n\u003ca name=\"Predicates\"\u003e\u003c/a\u003e\n\n# ⏺ Predicates ⏺\n\n## `correct(+Automaton, -Representation)`\nTrue $\\iff$ `Automaton` is a term representing a deterministic finite automaton and `Representation` is a non-complex term representing internal automaton structure.\n\n\u003cbr\u003e\n\n## `accept(+Automaton, ?Word)`\nTrue $\\iff$ given `Automaton` accepts the word `Word`.\nThe parameter `Word` can be a non-complex term (a list of elements), as well as a complex term.\n\nIn case when `Word` is a complex term but a closed list, the predicate acts as a generator of words that complies with given pattern and therefore is accepted by the given `Automaton`.\n\nIn case when `Word` is a variable, the predicate acts as a generator of all the words belonging to the language accepted by the `Automaton`.\n\n\u003cbr\u003e\n\n## `empty(+Automaton)`\nTrue $\\iff$ the language accepted by the `Automaton` is empty.\n\n\u003cbr\u003e\n\n## `equal(+Automaton1, +Automaton2)`\nTrue $\\iff$ $L($`Automaton1`$) = L($`Automaton2`$)$ and the alphabets of both automata are equal.\n\n\u003cbr\u003e\n\n## `subsetEq(+Automaton1, +Automaton2)`\nTrue $\\iff$ $L($`Automaton1`$) \\subseteq L($`Automaton2`$)$ and the alphabets of both automata are equal.\n\n\u003cbr\u003e\n\n\u003ca name=\"Examples\"\u003e\u003c/a\u003e\n\n# ✨ Examples ✨\n\n`example(+AutomatonId, +Automaton)`\n\n\n```prolog\nexample(a11, dfa([fp(1,a,1), fp(1,b,2), fp(2,a,2), fp(2,b,1)], 1, [2,1])).\n\nexample(a12, dfa([fp(x,a,y), fp(x,b,x), fp(y,a,x), fp(y,b,x)], x, [x,y])).\n\nexample(a2, dfa([fp(1,a,2), fp(2,b,1), fp(1,b,3), fp(2,a,3), fp(3,b,3), fp(3,a,3)], 1, [1])).\n\nexample(a3, dfa([fp(0,a,1), fp(1,a,0)], 0, [0])).\n\nexample(a4, dfa([fp(x,a,y), fp(y,a,z), fp(z,a,x)], x, [x])).\n\nexample(a5, dfa([fp(x,a,y), fp(y,a,z), fp(z,a,zz), fp(zz,a,x)], x, [x])).\n\nexample(a6, dfa([fp(1,a,1), fp(1,b,2), fp(2,a,2), fp(2,b,1)], 1, [])).\n\nexample(a7, dfa([fp(1,a,1), fp(1,b,2), fp(2,a,2), fp(2,b,1), fp(3,b,3), fp(3,a,3)], 1, [3])).\n```\n\n##\n\nAutomata `a11` and `a12` accept words of form $\\\\{ a, b \\\\}*$, so words over the alphabet $\\Sigma = \\\\{ a, b \\\\}$.\n\nAutomaton `a2` accepts words of form $(ab)^n, \\  n \\geq 0$.\n\nAutomaton `a3` accepts words of form $(aa)^n, \\  n \\geq 0$, automaton `a4` accepts words of form $(aaa)^n, \\  n \\geq 0$ and automaton `a5` accepts words of form $(aaaa)^n, \\  n \\geq 0$.\n\nThe languages accepted by automata `a6` and `a7` are empty, since the set of accept states of automaton `a6` is empty, and the only accept state of automaton `a7` is not reachable from the initial state.\n\n\u003cbr\u003e\n\n\u003ca name=\"Example_usage\"\u003e\u003c/a\u003e\n\n# ⏩ Example usage ⏩\n\n```\nsudo apt-get update \u0026\u0026 sudo apt-get install swi-prolog\nswipl\nconsult('dfa.pl').\nconsult('examples.pl').\n```\n\nThe following predicates should be true:\n\n```prolog\nexample(a11, A), example(a12, B), equal(A, B).\nexample(a2, A), example(a11, B), subsetEq(A, B).\nexample(a5, A), example(a3, B), subsetEq(A, B).\nexample(a6, A), empty(A).\nexample(a7, A), empty(A).\nexample(a2, A), accept(A, []).\nexample(a2, A), accept(A, [a,b]).\nexample(a2, A), accept(A, [a,b,a,b]).\n```\n\nThe following predicates should be false:\n\n```prolog\nexample(a2, A), empty(A).\nexample(a3, A), example(a4, B), equal(A, B).\nexample(a4, A), example(a3, B), subsetEq(A, B).\nexample(a2, A), accept(A, [a]).\n```\n\nPredicate `example(a11, A), accept(A, [X,Y,Z]).` will generate 8 answers corresponding to all 3-letter words over the two-letter alphabet.\n\nPredicate `example(a11, A), accept(A, Var).` will generate every word in the language accepted accepted by the automaton in a finite time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrknzz%2Fdeterministic-finite-automata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrknzz%2Fdeterministic-finite-automata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrknzz%2Fdeterministic-finite-automata/lists"}