From 18a6daba783582868aa41ddfe94507b5255ae95c Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Thu, 19 Jan 2023 05:46:18 +0300 Subject: [PATCH 01/22] bug fixed --- libs/Objects/src/Regex.cpp | 38 +++++++++++++++++------- resources/template/PumpLength-medium.tex | 10 +++++++ 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 resources/template/PumpLength-medium.tex diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index ad1636f8..9d8be856 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1507,6 +1507,7 @@ std::optional Regex::prefix_derevative(std::string respected_str) const { return ans; } // Длина накачки +// Длина накачки int Regex::pump_length(iLogTemplate* log) const { // Logger::init_step("PumpLength"); if (language->pump_length_cached()) { @@ -1531,6 +1532,7 @@ int Regex::pump_length(iLogTemplate* log) const { } return i; } + bool pumped = true; for (auto it = prefs.begin(); it != prefs.end(); it++) { bool was = false; for (int j = 0; j < it->size(); j++) { @@ -1551,30 +1553,44 @@ int Regex::pump_length(iLogTemplate* log) const { Regex b; pumping.regex_union(&a, &b); if (!derevative_with_respect_to_str(*it, this, - *pumping.term_r)) + *pumping.term_r)) { + pumped = false; continue; + } pumping.generate_alphabet(pumping.alphabet); pumping.language = make_shared(pumping.alphabet); // cout << pumped_prefix << " " << pumping.term_r->to_txt(); if (subset(pumping)) { checked_prefixes[*it] = true; - language->set_pump_length(i); - /*cout << *it << "\n"; + cout << *it << "\n"; cout << pumping.to_txt() << "\n"; cout << to_txt() << "\n"; cout << subset(pumping) << "\n"; - Regex pump2; - cout << subset(pump2);*/ - // Logger::log("Длина накачки", to_string(i)); - // Logger::finish_step(); - if (log) { - log->set_parameter("pumplength", i); - } - return i; + //// Logger::log("Длина накачки", to_string(i)); + //// Logger::finish_step(); + // if (log) { + // log->set_parameter("pumplength", i); + //} + } else { + pumped = false; } } } } + std::string ch_prefixes; + for (auto it = checked_prefixes.begin(); it != checked_prefixes.end(); + it++) { + if (it->second) ch_prefixes += it->first + "\n"; + } + if (pumped) { + language->set_pump_length(i); + if (log) { + log->set_parameter("pumplength", i); + log->set_parameter("pumplength2", i); + } + cout << i; + return i; + } } } diff --git a/resources/template/PumpLength-medium.tex b/resources/template/PumpLength-medium.tex new file mode 100644 index 00000000..43e584ec --- /dev/null +++ b/resources/template/PumpLength-medium.tex @@ -0,0 +1,10 @@ +\section{Длина накачки} +\begin{frame}{Пример автомата Антимирова} + \vspace{-5pt} + Длина накачки: + %pumplenght % the initial regexp placeholder + + Накачиваемые префиксы: + %pumplength2 % the Derivative placeholder 1 + +\end{frame} \ No newline at end of file From bbcb55926574de7806862a1885a718ff79e02da7 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Fri, 20 Jan 2023 22:04:05 +0300 Subject: [PATCH 02/22] log template --- libs/Interpreter/src/Interpreter.cpp | 1 + resources/template/PumpLength-medium.tex | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/Interpreter/src/Interpreter.cpp b/libs/Interpreter/src/Interpreter.cpp index 75fd4c47..2944418f 100644 --- a/libs/Interpreter/src/Interpreter.cpp +++ b/libs/Interpreter/src/Interpreter.cpp @@ -329,6 +329,7 @@ optional Interpreter::apply_function( return ObjectBoolean(get_automaton(arguments[0]).semdet(&log_template)); } if (function.name == "PumpLength") { + log_template.load_tex_template("PumpLength"); return ObjectInt( get(arguments[0]).value.pump_length(&log_template)); } diff --git a/resources/template/PumpLength-medium.tex b/resources/template/PumpLength-medium.tex index 43e584ec..817d7d63 100644 --- a/resources/template/PumpLength-medium.tex +++ b/resources/template/PumpLength-medium.tex @@ -2,9 +2,9 @@ \section{Длина накачки} \begin{frame}{Пример автомата Антимирова} \vspace{-5pt} Длина накачки: - %pumplenght % the initial regexp placeholder + %template_pumplenght % founded pump len Накачиваемые префиксы: - %pumplength2 % the Derivative placeholder 1 + %template_pumplength2 % prefixes \end{frame} \ No newline at end of file From fea674bb02802b8b066bdf9d575097021df06ce0 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin <71353456+Robby-the-paladin@users.noreply.github.com> Date: Fri, 20 Jan 2023 22:20:45 +0300 Subject: [PATCH 03/22] Rename PumpLength-medium.tex to PumpLength.tex --- resources/template/{PumpLength-medium.tex => PumpLength.tex} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename resources/template/{PumpLength-medium.tex => PumpLength.tex} (95%) diff --git a/resources/template/PumpLength-medium.tex b/resources/template/PumpLength.tex similarity index 95% rename from resources/template/PumpLength-medium.tex rename to resources/template/PumpLength.tex index 817d7d63..9f727555 100644 --- a/resources/template/PumpLength-medium.tex +++ b/resources/template/PumpLength.tex @@ -7,4 +7,4 @@ \section{Длина накачки} Накачиваемые префиксы: %template_pumplength2 % prefixes -\end{frame} \ No newline at end of file +\end{frame} From cc9c72574cfde5093894fdbced964557f2773ec8 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Sat, 21 Jan 2023 02:47:47 +0300 Subject: [PATCH 04/22] prefix bug fixed --- libs/Objects/src/Regex.cpp | 12 ++++++------ resources/template/PumpLength.tex | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index 5a100e96..8ef84d04 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1216,7 +1216,8 @@ void Regex::get_prefix(int len, std::set* prefs) const { term_r->get_prefix(len - k, prefs2); for (auto i = prefs1->begin(); i != prefs1->end(); i++) { for (auto j = prefs2->begin(); j != prefs2->end(); j++) { - prefs->insert(*i + *j); + if (prefix_derevative(*i + *j)) + prefs->insert(*i + *j); } } prefs1->clear(); @@ -1547,10 +1548,10 @@ int Regex::pump_length(iLogTemplate* log) const { // cout << pumped_prefix << " " << pumping.term_r->to_txt(); if (subset(pumping)) { checked_prefixes[*it] = true; - cout << *it << "\n"; + /*cout << *it << "\n"; cout << pumping.to_txt() << "\n"; cout << to_txt() << "\n"; - cout << subset(pumping) << "\n"; + cout << subset(pumping) << "\n";*/ //// Logger::log("Длина накачки", to_string(i)); //// Logger::finish_step(); // if (log) { @@ -1570,10 +1571,9 @@ int Regex::pump_length(iLogTemplate* log) const { if (pumped) { language->set_pump_length(i); if (log) { - log->set_parameter("pumplength", i); - log->set_parameter("pumplength2", i); + log->set_parameter("pumplength1", i); + log->set_parameter("pumplength2", ch_prefixes); } - cout << i; return i; } } diff --git a/resources/template/PumpLength.tex b/resources/template/PumpLength.tex index 9f727555..072e36c2 100644 --- a/resources/template/PumpLength.tex +++ b/resources/template/PumpLength.tex @@ -2,7 +2,7 @@ \section{Длина накачки} \begin{frame}{Пример автомата Антимирова} \vspace{-5pt} Длина накачки: - %template_pumplenght % founded pump len + %template_pumplength1 % founded pump len Накачиваемые префиксы: %template_pumplength2 % prefixes From ce323957e31f54655dd9117785f438b93a83642b Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Sat, 21 Jan 2023 04:05:09 +0300 Subject: [PATCH 05/22] making pumped regex through Regex constructor --- libs/Objects/src/Regex.cpp | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index 8ef84d04..51901017 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1530,28 +1530,24 @@ int Regex::pump_length(iLogTemplate* log) const { if (was) continue; for (int j = 0; j < it->size(); j++) { for (int k = j + 1; k <= it->size(); k++) { - Regex pumping; std::string pumped_prefix; pumped_prefix += it->substr(0, j); pumped_prefix += "(" + it->substr(j, k - j) + ")*"; pumped_prefix += it->substr(k, it->size() - k + j); - Regex a(pumped_prefix); - Regex b; - pumping.regex_union(&a, &b); - if (!derevative_with_respect_to_str(*it, this, - *pumping.term_r)) { + Regex a; + if (!derevative_with_respect_to_str(*it, this, a)) { pumped = false; continue; } - pumping.generate_alphabet(pumping.alphabet); - pumping.language = make_shared(pumping.alphabet); + pumped_prefix += a.to_txt(); + Regex pumping(pumped_prefix); // cout << pumped_prefix << " " << pumping.term_r->to_txt(); if (subset(pumping)) { checked_prefixes[*it] = true; - /*cout << *it << "\n"; + cout << *it << "\n"; cout << pumping.to_txt() << "\n"; cout << to_txt() << "\n"; - cout << subset(pumping) << "\n";*/ + cout << subset(pumping) << "\n"; //// Logger::log("Длина накачки", to_string(i)); //// Logger::finish_step(); // if (log) { From 355fb49e78a6ac2389420fb2e3b6d260668b6e7c Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Sat, 21 Jan 2023 16:52:49 +0300 Subject: [PATCH 06/22] debug info deleted --- libs/Objects/src/Regex.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index d6b3670e..746a4649 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1495,10 +1495,7 @@ std::optional Regex::prefix_derevative(std::string respected_str) const { // Длина накачки // Длина накачки int Regex::pump_length(iLogTemplate* log) const { - // Logger::init_step("PumpLength"); if (language->pump_length_cached()) { - // Logger::log("Длина накачки", to_string(language->get_pump_length())); - // Logger::finish_step(); if (log) { log->set_parameter("pumplength", language->get_pump_length()); } @@ -1510,9 +1507,6 @@ int Regex::pump_length(iLogTemplate* log) const { get_prefix(i, &prefs); if (prefs.empty()) { language->set_pump_length(i); - /*Logger::log( - "Длина накачки совпадает с длиной регулярного выражения"); - Logger::finish_step();*/ if (log) { log->set_parameter("pumplength", i); } @@ -1541,18 +1535,8 @@ int Regex::pump_length(iLogTemplate* log) const { } pumped_prefix += a.to_txt(); Regex pumping(pumped_prefix); - // cout << pumped_prefix << " " << pumping.term_r->to_txt(); if (subset(pumping)) { checked_prefixes[*it] = true; - cout << *it << "\n"; - cout << pumping.to_txt() << "\n"; - cout << to_txt() << "\n"; - cout << subset(pumping) << "\n"; - //// Logger::log("Длина накачки", to_string(i)); - //// Logger::finish_step(); - // if (log) { - // log->set_parameter("pumplength", i); - //} } else { pumped = false; } From 414c028c953bbd3d7c3afcfffc654282ca07131f Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Wed, 25 Jan 2023 08:12:04 +0300 Subject: [PATCH 07/22] detailed info --- resources/template/PumpLength.tex | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/resources/template/PumpLength.tex b/resources/template/PumpLength.tex index 072e36c2..9d40aaf5 100644 --- a/resources/template/PumpLength.tex +++ b/resources/template/PumpLength.tex @@ -1,5 +1,19 @@ +%begin detailed \section{Длина накачки} -\begin{frame}{Пример автомата Антимирова} +\begin{frame}{Лемма о накачке} + \vspace{-5pt} + Если $G$ — это регулярная грамматика, то существует $n \in \mathbb{N}$, что $\forall w(w \in \Lang(G) \: \& \: |w| > n \Rightarrow \exists w_1, w_2, w_3(|w_2| > 0 \: \& \: |w_1| + |w_3| \leqslant n \: \& \: w = w_1w_2w_3 \: \& \: \forall k(k\geqslant0 \Rightarrow w_1w_2^kw_3 \in \Lang(G))$. Длина накачки $G$ - минимальное из таких $n$. + \begin{block}{\bf Алгоритм поиска длины накачки} + Пусть $R\in\RegExp$. По возрастанию значения $n$: + \begin{itemize} + \item Рассмотреть в $R$ все возможные префиксы $w$ длины $n$ и по каждому из них построить производную Брзозовски. + \item Перебрать инфиксы в пределах $n$-префиксов на предмет возможности накачки: а именно, если префикс $w$ в выражении $w\delta_w(R)$ допускает разбиение на $w_1w_2w_3$, то он накачивается $\Leftrightarrow \: \Lang((w_1(w_2) \star w_3\delta_w(R)) \subseteq \Lang(R)$. + \end{itemize} + Если все $n$-префиксы накачиваются, то $n$ и есть искомая длина накачки. + \end{block} +\end{frame} % descriptive documentation +%end detailed +\begin{frame}{Нахождение длины накачки} \vspace{-5pt} Длина накачки: %template_pumplength1 % founded pump len From acd7c8af0b6a6e2152262780882107a0227db222 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Wed, 25 Jan 2023 09:13:16 +0300 Subject: [PATCH 08/22] infix pumping fixed --- libs/Objects/src/Regex.cpp | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index 746a4649..536a4ba1 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1522,26 +1522,24 @@ int Regex::pump_length(iLogTemplate* log) const { } } if (was) continue; + bool infix_pumped = false; for (int j = 0; j < it->size(); j++) { - for (int k = j + 1; k <= it->size(); k++) { - std::string pumped_prefix; - pumped_prefix += it->substr(0, j); - pumped_prefix += "(" + it->substr(j, k - j) + ")*"; - pumped_prefix += it->substr(k, it->size() - k + j); - Regex a; - if (!derevative_with_respect_to_str(*it, this, a)) { - pumped = false; - continue; - } - pumped_prefix += a.to_txt(); - Regex pumping(pumped_prefix); - if (subset(pumping)) { - checked_prefixes[*it] = true; - } else { - pumped = false; - } + std::string pumped_prefix; + pumped_prefix += it->substr(0, j); + pumped_prefix += "(" + it->substr(j, it->size()) + ")*"; + Regex a; + if (!derevative_with_respect_to_str(*it, this, a)) { + continue; + } + pumped_prefix += a.to_txt(); + Regex pumping(pumped_prefix); + if (subset(pumping)) { + checked_prefixes[*it] = true; + infix_pumped = true; + break; } } + pumped &= infix_pumped; } std::string ch_prefixes; for (auto it = checked_prefixes.begin(); it != checked_prefixes.end(); From 11292f30d027ce3cb1ff9c68cd8f550966b54026 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Thu, 26 Jan 2023 00:20:17 +0300 Subject: [PATCH 09/22] star prefix bugfix --- libs/Objects/src/Regex.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index 536a4ba1..524c4e73 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1238,7 +1238,8 @@ void Regex::get_prefix(int len, std::set* prefs) const { get_prefix(len - k, prefs2); for (auto i = prefs1->begin(); i != prefs1->end(); i++) { for (auto j = prefs2->begin(); j != prefs2->end(); j++) { - prefs->insert(*i + *j); + if (prefix_derevative(*i + *j)) + prefs->insert(*i + *j); } } prefs1->clear(); From 2610e0b5e4ba6913d789b7625fb73af7fe55cd6b Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Thu, 26 Jan 2023 05:54:34 +0300 Subject: [PATCH 10/22] concatenation bug fixed --- libs/Objects/src/Regex.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index 524c4e73..f90d1ddc 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1532,7 +1532,7 @@ int Regex::pump_length(iLogTemplate* log) const { if (!derevative_with_respect_to_str(*it, this, a)) { continue; } - pumped_prefix += a.to_txt(); + pumped_prefix += "(" + a.to_txt() + ")"; Regex pumping(pumped_prefix); if (subset(pumping)) { checked_prefixes[*it] = true; @@ -1631,7 +1631,9 @@ bool Regex::subset(const Regex& r, iLogTemplate* log) const { // Logger::init_step("Subset"); // Logger::log("Первое регулярное выражение", to_txt()); // Logger::log("Второе регулярное выражение", r.to_txt()); - bool result = to_ilieyu().subset(r.to_ilieyu()); + auto il = to_ilieyu(); + auto ril = r.to_ilieyu(); + bool result = il.subset(ril); /*if (result) Logger::log("Результат Subset", "true"); else From ebfdf9598259fbaa15defcd900beb4bbe0c7763a Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Thu, 26 Jan 2023 16:52:43 +0300 Subject: [PATCH 11/22] Works? --- libs/Interpreter/src/Interpreter.cpp | 1 + libs/Objects/src/FiniteAutomaton.cpp | 32 +++++++++++++++++++++++++--- resources/template/SemDet.tex | 25 ++++++++++++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 resources/template/SemDet.tex diff --git a/libs/Interpreter/src/Interpreter.cpp b/libs/Interpreter/src/Interpreter.cpp index 75fd4c47..66209a10 100644 --- a/libs/Interpreter/src/Interpreter.cpp +++ b/libs/Interpreter/src/Interpreter.cpp @@ -326,6 +326,7 @@ optional Interpreter::apply_function( } } if (function.name == "SemDet") { + log_template.load_tex_template("SemDet"); return ObjectBoolean(get_automaton(arguments[0]).semdet(&log_template)); } if (function.name == "PumpLength") { diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index a9c9837b..ce883ec8 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2153,19 +2153,37 @@ bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { state_languages[i] = derevative.value(); // cout << "Derevative: " << state_languages[i].to_txt() << "\n"; // Logger::log("Derevative", state_languages[i].to_txt()); - if (log) { + /*if (log) { log->set_parameter("state", i); log->set_parameter("prefix", prefix.value()); log->set_parameter("regex", reg); log->set_parameter("deverative", state_languages[i]); - } + }*/ + state_languages[i].make_language(); } + auto make_string_transition = [=](int from, alphabet_symbol through, + int to) { + string f = "${q_" + std::to_string(from) + "}"; + string arrow = "{\\xrightarrow{\\text{$" + string(through) + "$}}}"; + string t = "{q_" + std::to_string(to) + "}$"; + return f + arrow + t; + }; + std::string ambiguous_transitions = ""; for (int i = 0; i < states.size(); i++) { for (int j = 0; j < states.size(); j++) { for (auto transition = states[j].transitions.begin(); transition != states[j].transitions.end(); transition++) { bool verified_ambiguity = false; + if (transition->second.size() > 1) { + ambiguous_transitions += "Ambigous: "; + for (auto it = transition->second.begin(); + it != transition->second.end(); it++) { + ambiguous_transitions += + make_string_transition(j, transition->first, *it) + + ","; + } + } for (auto it = transition->second.begin(); it != transition->second.end(); it++) { bool reliability = true; @@ -2178,16 +2196,24 @@ bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { } } verified_ambiguity |= reliability; + if (reliability) { + ambiguous_transitions += + "Reliable:" + + make_string_transition(j, transition->first, *it) + + +"\\\\"; + } } if (!verified_ambiguity) { // Logger::log("Результат SemDet", "false"); // Logger::finish_step(); + ambiguous_transitions += "Reliable: none\\\\"; + log->set_parameter("semdet2", false); return false; } } } } - // Logger::log("Результат SemDet", "true"); + log->set_parameter("semdet2", "true"); return true; } diff --git a/resources/template/SemDet.tex b/resources/template/SemDet.tex new file mode 100644 index 00000000..0d979329 --- /dev/null +++ b/resources/template/SemDet.tex @@ -0,0 +1,25 @@ +\section{Семантический детерминизм} +%begin detailed +\begin{frame}{Семантический детерминизм} + \vspace{-5pt} + Язык состояния $q$ — это $\{w | q \xrightarrow{\text{$w$}} q\}$, где $q_f$ - финальное состояние. НКА $A$ семантически детеминирован, если для всякой неоднозначности $q_i \xrightarrow{\text{$a$}} {q_j__1} , ..., {q_i \xrightarrow{\text{$a$}} q_j__k}$ существует такое состояние $q_j__s$, что языки всех $q_j__t$ $(1 \leqslant t \leqslant k)$ вкладываются в его язык (это означает, что переход $q_i \xrightarrow{\text{$a$}} {q_j__s}$ надёжен: если слово распознаётся автоматом, оно обязательно будет распознано после такого перехода). + Языки состояний при этом строятся с помощью производных: в качестве аргумента производной достаточно взять произвольный префикс $v$, соответствующий переходу $q_0 \xrightarrow{\text{$v$}} q$. +\end{frame} % descriptive documentation +\begin{frame}{Алгоритм проверки семантического детерминизма} + \vspace{-5pt} + \begin{itemize} + \item Разметка автомата + \item Получение языков состояний, с помощью производных + \item Поиск неоднозначностей + \item Поиск состояния с надёжным переходом для каждой неоднозначности + \end{itemize} + +\end{frame} +%end detailed +\begin{frame}{Проверка семантического детерминизма} + \vspace{-5pt} + \\Неоднозначные переходы и надёжные переходы: + %template_semdet1 + \\Семантический детерминизм: + %template_semdet2 +\end{frame} \ No newline at end of file From 1224c350b3eea476607ccb5e2d09fdda5ff2a9bb Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Thu, 26 Jan 2023 17:49:49 +0300 Subject: [PATCH 12/22] log entry fix --- libs/Objects/src/FiniteAutomaton.cpp | 23 +++++++++++++++-------- resources/template/SemDet.tex | 2 +- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index 180d17bc..d2f262d3 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2122,7 +2122,7 @@ std::optional FiniteAutomaton::get_prefix( bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { if (!annoted) { - return annote().semdet_entry(true); + return annote().semdet_entry(true, log); } // Logger::log( //"Получение языка из производной регулярки автомата по префиксу"); @@ -2150,7 +2150,7 @@ bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { // Logger::log("Regex", reg.to_txt()); auto derevative = reg.prefix_derevative(prefix.value()); if (!derevative.has_value()) continue; - state_languages[i] = derevative.value(); + state_languages[i].from_string(derevative.value().to_txt()); // cout << "Derevative: " << state_languages[i].to_txt() << "\n"; // Logger::log("Derevative", state_languages[i].to_txt()); /*if (log) { @@ -2159,8 +2159,6 @@ bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { log->set_parameter("regex", reg); log->set_parameter("deverative", state_languages[i]); }*/ - - state_languages[i].make_language(); } auto make_string_transition = [=](int from, alphabet_symbol through, int to) { @@ -2196,7 +2194,7 @@ bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { } } verified_ambiguity |= reliability; - if (reliability) { + if (reliability && transition->second.size() > 1) { ambiguous_transitions += "Reliable:" + make_string_transition(j, transition->first, *it) + @@ -2207,13 +2205,22 @@ bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { // Logger::log("Результат SemDet", "false"); // Logger::finish_step(); ambiguous_transitions += "Reliable: none\\\\"; - log->set_parameter("semdet2", false); + if (log) { + log->set_parameter("semdet1", ambiguous_transitions); + log->set_parameter("semdet2", false); + } return false; } } } } - log->set_parameter("semdet2", "true"); + if (log) { + if (ambiguous_transitions == "") { + ambiguous_transitions = "None"; + } + log->set_parameter("semdet1", ambiguous_transitions); + log->set_parameter("semdet2", "true"); + } return true; } @@ -2222,7 +2229,7 @@ bool FiniteAutomaton::semdet(iLogTemplate* log) const { if (log) { log->set_parameter("oldautomaton", *this); } - bool result = semdet_entry(log); + bool result = semdet_entry(false, log); if (log) { log->set_parameter("result", result); } diff --git a/resources/template/SemDet.tex b/resources/template/SemDet.tex index 0d979329..4f8dc83e 100644 --- a/resources/template/SemDet.tex +++ b/resources/template/SemDet.tex @@ -19,7 +19,7 @@ \section{Семантический детерминизм} \begin{frame}{Проверка семантического детерминизма} \vspace{-5pt} \\Неоднозначные переходы и надёжные переходы: - %template_semdet1 + \\%template_semdet1 \\Семантический детерминизм: %template_semdet2 \end{frame} \ No newline at end of file From f7724960aed88cc23b1b21c7102e5477354f0b7c Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Thu, 26 Jan 2023 18:56:28 +0300 Subject: [PATCH 13/22] Terrible bugs fixed --- libs/Objects/include/Objects/Regex.h | 3 +++ libs/Objects/src/Regex.cpp | 36 ++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/libs/Objects/include/Objects/Regex.h b/libs/Objects/include/Objects/Regex.h index b481aaac..5c200b00 100644 --- a/libs/Objects/include/Objects/Regex.h +++ b/libs/Objects/include/Objects/Regex.h @@ -99,6 +99,9 @@ class Regex : BaseObject { void pre_order_travers() const; void clear(); + // Получение всех символов из строки + bool get_symbols_from_string(Regex* reg, vector& res); + public: Regex(); Regex(const string&); diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index 1fded0e1..f9ad79c6 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1435,21 +1435,37 @@ bool Regex::partial_derevative_with_respect_to_sym( } } +bool Regex::get_symbols_from_string(Regex* reg, vector& res) { + if (reg->type == Type::symb) { + res.push_back(*reg); + return true; + } + if (reg->type == Regex::conc) { + vector resl, resr; + get_symbols_from_string(reg->term_l, resl); + get_symbols_from_string(reg->term_r, resr); + for (int i = 0; i < resl.size(); i++) { + res.push_back(resl[i]); + } + for (int i = 0; i < resr.size(); i++) { + res.push_back(resr[i]); + } + return true; + } + return false; +} + bool Regex::derevative_with_respect_to_str(std::string str, const Regex* reg_e, Regex& result) const { bool success = true; Regex cur = *reg_e; Regex next = *reg_e; - // cout << "start getting derevative for prefix " << str << " in " - // << reg_e->to_txt() << "\n"; - for (int i = 0; i < str.size(); i++) { - Regex sym; - sym.type = Type::symb; - sym.value.symbol = str[i]; - next.clear(); - success &= derevative_with_respect_to_sym(&sym, &cur, next); - // cout << "derevative for prefix " << sym->to_txt() << " in " - // << cur.to_txt() << " is " << next.to_txt() << "\n"; + Regex symbols; + symbols.from_string(str); + vector syms; + symbols.get_symbols_from_string(&symbols, syms); + for (int i = 0; i < syms.size(); i++) { + success &= derevative_with_respect_to_sym(&syms[i], &cur, next); if (!success) { return false; } From cdcdeda4685ac691549a8fe9db2d02cad41552c5 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Thu, 26 Jan 2023 20:21:02 +0300 Subject: [PATCH 14/22] trap removing magic --- libs/Objects/src/FiniteAutomaton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index d2f262d3..60ec5b88 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2122,7 +2122,7 @@ std::optional FiniteAutomaton::get_prefix( bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { if (!annoted) { - return annote().semdet_entry(true, log); + return annote().remove_trap_states().semdet_entry(true, log); } // Logger::log( //"Получение языка из производной регулярки автомата по префиксу"); From 9bfbad41175e345846f41bcae8ebe7c67f127d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=BD=D0=B0=20=D0=A2=D0=B5=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D1=8C=D0=B5=D0=B2=D0=B0?= <79749959+mathhyyn@users.noreply.github.com> Date: Thu, 26 Jan 2023 22:09:14 +0300 Subject: [PATCH 15/22] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0?= =?UTF-8?q?=D1=87=D0=B0=20=D1=80=D0=B5=D0=B3=D1=83=D0=BB=D1=8F=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B2=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE=D0=BD=20pumple?= =?UTF-8?q?ngth=20#236?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/Objects/src/Regex.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index 7c2066b0..b5d3a87a 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1016,8 +1016,9 @@ FiniteAutomaton Regex::to_glushkov(iLogTemplate* log) const { for (auto& it1 : p) { for (size_t i = 0; i < it1.second.size(); i++) { - str_pair = str_pair + "(" + string(list[it1.first]->value.symbol) + "," + - string(list[it1.second[i]]->value.symbol)+")" + "\\ "; + str_pair = str_pair + "(" + string(list[it1.first]->value.symbol) + + "," + string(list[it1.second[i]]->value.symbol) + ")" + + "\\ "; } } @@ -1221,8 +1222,7 @@ void Regex::get_prefix(int len, std::set* prefs) const { term_r->get_prefix(len - k, prefs2); for (auto i = prefs1->begin(); i != prefs1->end(); i++) { for (auto j = prefs2->begin(); j != prefs2->end(); j++) { - if (prefix_derivative(*i + *j)) - prefs->insert(*i + *j); + if (prefix_derivative(*i + *j)) prefs->insert(*i + *j); } } prefs1->clear(); @@ -1243,8 +1243,7 @@ void Regex::get_prefix(int len, std::set* prefs) const { get_prefix(len - k, prefs2); for (auto i = prefs1->begin(); i != prefs1->end(); i++) { for (auto j = prefs2->begin(); j != prefs2->end(); j++) { - if (prefix_derivative(*i + *j)) - prefs->insert(*i + *j); + if (prefix_derivative(*i + *j)) prefs->insert(*i + *j); } } prefs1->clear(); @@ -1501,6 +1500,7 @@ std::optional Regex::prefix_derivative(std::string respected_str) const { // Длина накачки // Длина накачки int Regex::pump_length(iLogTemplate* log) const { + if (log) log->set_parameter("oldregex", *this); if (language->pump_length_cached()) { if (log) { log->set_parameter("pumplength", language->get_pump_length()); From d597fe58f63805903820de4245457a2ba580ec4e Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Fri, 27 Jan 2023 05:38:12 +0300 Subject: [PATCH 16/22] some eps magic --- libs/Objects/include/Objects/Regex.h | 2 ++ libs/Objects/src/Regex.cpp | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/libs/Objects/include/Objects/Regex.h b/libs/Objects/include/Objects/Regex.h index 557df64d..2e51db92 100644 --- a/libs/Objects/include/Objects/Regex.h +++ b/libs/Objects/include/Objects/Regex.h @@ -102,6 +102,8 @@ class Regex : BaseObject { // Получение всех символов из строки bool get_symbols_from_string(vector& res); + void eps_removing(); + public: Regex(); Regex(const string&); diff --git a/libs/Objects/src/Regex.cpp b/libs/Objects/src/Regex.cpp index 9aded5e1..e9d6c5b2 100644 --- a/libs/Objects/src/Regex.cpp +++ b/libs/Objects/src/Regex.cpp @@ -1364,6 +1364,26 @@ bool Regex::derivative_with_respect_to_sym(Regex* respected_sym, } } +void Regex::eps_removing() { + switch (type) { + case Type::alt: + case Type::conc: + term_l->eps_removing(); + term_r->eps_removing(); + if (term_l->type == Type::eps && term_r->type == Type::eps) { + clear(); + type = Type::eps; + } + break; + case Type::star: + term_l->eps_removing(); + if (term_l->type == Type::eps) { + clear(); + type = Type::eps; + } + } +} + bool Regex::partial_derivative_with_respect_to_sym( Regex* respected_sym, const Regex* reg_e, vector& result) const { Regex cur_result; @@ -1563,6 +1583,7 @@ int Regex::pump_length(iLogTemplate* log) const { if (!derivative_with_respect_to_str(*it, this, a)) { continue; } + a.eps_removing(); if (a.to_txt() != "") pumped_prefix += "(" + a.to_txt() + ")"; Regex pumping(pumped_prefix); From d69727ec351ed1b6d8ccc1c12331c82859967a8d Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Fri, 27 Jan 2023 05:59:05 +0300 Subject: [PATCH 17/22] small returning bug fixed --- libs/Objects/src/FiniteAutomaton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index 931c92ee..cb5631be 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2242,8 +2242,8 @@ std::optional FiniteAutomaton::get_prefix( auto res = get_prefix(*it2, state_end, was); if (res.has_value()) { ans = (string)it->first + (string)res.value(); + return ans; } - return ans; } } } From d8889eecb21caaae2974ff4368e1c7bd892db255 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Fri, 27 Jan 2023 09:42:17 +0300 Subject: [PATCH 18/22] semdet deannote fix --- .../Objects/include/Objects/FiniteAutomaton.h | 5 ++- libs/Objects/src/FiniteAutomaton.cpp | 35 ++++++++----------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/libs/Objects/include/Objects/FiniteAutomaton.h b/libs/Objects/include/Objects/FiniteAutomaton.h index 41667de7..d81e0c89 100644 --- a/libs/Objects/include/Objects/FiniteAutomaton.h +++ b/libs/Objects/include/Objects/FiniteAutomaton.h @@ -74,7 +74,10 @@ class FiniteAutomaton : public BaseObject { map& was) const; // функция проверки на семантическую детерминированность - bool semdet_entry(bool annoted = false, iLogTemplate* log = nullptr) const; + bool semdet_entry(bool traps_removed = false, iLogTemplate* log = nullptr) const; + + // Поиск языков состояний + void get_state_languages(bool annoted, vector& state_languages) const; public: FiniteAutomaton(); diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index cb5631be..53dd0e95 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2250,9 +2250,11 @@ std::optional FiniteAutomaton::get_prefix( return ans; } -bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { +void FiniteAutomaton::get_state_languages(bool annoted, + vector& state_languages) const{ if (!annoted) { - return annote().remove_trap_states().semdet_entry(true, log); + annote().remove_trap_states().get_state_languages(true, state_languages); + return; } // Logger::log( //"Получение языка из производной регулярки автомата по префиксу"); @@ -2261,35 +2263,28 @@ bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { for (int i = 0; i < states.size(); i++) { if (states[i].is_terminal) final_states.push_back(i); } - std::vector state_languages; state_languages.resize(states.size()); for (int i = 0; i < states.size(); i++) { auto prefix = get_prefix(initial_state, i, was); was.clear(); - // cout << "Try " << i << "\n"; if (!prefix.has_value()) continue; Regex reg; // Получение языка из производной регулярки автомата по префиксу: - // this -> reg (arden?) reg = to_regex(); - // cout << "State: " << i << "\n"; - // cout << "Prefix: " << prefix.value() << "\n"; - // cout << "Regex: " << reg.to_txt() << "\n"; - // Logger::log("State", to_string(i)); - // Logger::log("Prefix", prefix.value()); - // Logger::log("Regex", reg.to_txt()); auto derivative = reg.prefix_derivative(prefix.value()); if (!derivative.has_value()) continue; state_languages[i].from_string(derivative.value().to_txt()); - // cout << "Derevative: " << state_languages[i].to_txt() << "\n"; - // Logger::log("Derevative", state_languages[i].to_txt()); - /*if (log) { - log->set_parameter("state", i); - log->set_parameter("prefix", prefix.value()); - log->set_parameter("regex", reg); - log->set_parameter("deverative", state_languages[i]); - }*/ + state_languages[i] = state_languages[i].deannote(); + cout << state_languages[i].to_txt() << "\n"; + } +} + +bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const { + if (!traps_removed) { + return remove_trap_states().semdet_entry(true, log); } + vector state_languages; + get_state_languages(false, state_languages); auto make_string_transition = [=](int from, alphabet_symbol through, int to) { string f = "${q_" + std::to_string(from) + "}"; @@ -2337,7 +2332,7 @@ bool FiniteAutomaton::semdet_entry(bool annoted, iLogTemplate* log) const { ambiguous_transitions += "Reliable: none\\\\"; if (log) { log->set_parameter("semdet1", ambiguous_transitions); - log->set_parameter("semdet2", false); + log->set_parameter("semdet2", "false"); } return false; } From 74a406436738ec56ade1c10afba11acd3c924ab9 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Fri, 27 Jan 2023 10:10:17 +0300 Subject: [PATCH 19/22] template update + useless cycle removed --- libs/Objects/src/FiniteAutomaton.cpp | 78 ++++++++++++++-------------- resources/template/SemDet.tex | 4 +- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index 53dd0e95..7d1b5a42 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2293,49 +2293,47 @@ bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const return f + arrow + t; }; std::string ambiguous_transitions = ""; - for (int i = 0; i < states.size(); i++) { - for (int j = 0; j < states.size(); j++) { - for (auto transition = states[j].transitions.begin(); - transition != states[j].transitions.end(); transition++) { - bool verified_ambiguity = false; - if (transition->second.size() > 1) { - ambiguous_transitions += "Ambigous: "; - for (auto it = transition->second.begin(); - it != transition->second.end(); it++) { - ambiguous_transitions += - make_string_transition(j, transition->first, *it) + - ","; - } - } + for (int j = 0; j < states.size(); j++) { + for (auto transition = states[j].transitions.begin(); + transition != states[j].transitions.end(); transition++) { + bool verified_ambiguity = false; + if (transition->second.size() > 1) { + ambiguous_transitions += "Ambigous: "; for (auto it = transition->second.begin(); - it != transition->second.end(); it++) { - bool reliability = true; - for (auto it2 = transition->second.begin(); - it2 != transition->second.end(); it2++) { - if (!state_languages[*it].subset( - state_languages[*it2])) { - reliability = false; - break; - } - } - verified_ambiguity |= reliability; - if (reliability && transition->second.size() > 1) { - ambiguous_transitions += - "Reliable:" + - make_string_transition(j, transition->first, *it) + - +"\\\\"; - } + it != transition->second.end(); it++) { + ambiguous_transitions += + make_string_transition(j, transition->first, *it) + + ","; } - if (!verified_ambiguity) { - // Logger::log("Результат SemDet", "false"); - // Logger::finish_step(); - ambiguous_transitions += "Reliable: none\\\\"; - if (log) { - log->set_parameter("semdet1", ambiguous_transitions); - log->set_parameter("semdet2", "false"); + } + for (auto it = transition->second.begin(); + it != transition->second.end(); it++) { + bool reliability = true; + for (auto it2 = transition->second.begin(); + it2 != transition->second.end(); it2++) { + if (!state_languages[*it].subset( + state_languages[*it2])) { + reliability = false; + break; } - return false; } + verified_ambiguity |= reliability; + if (reliability && transition->second.size() > 1) { + ambiguous_transitions += + "Reliable:" + + make_string_transition(j, transition->first, *it) + + +"\\\\"; + } + } + if (!verified_ambiguity) { + // Logger::log("Результат SemDet", "false"); + // Logger::finish_step(); + ambiguous_transitions += "Reliable: none\\\\"; + if (log) { + log->set_parameter("semdet1", ambiguous_transitions); + log->set_parameter("semdet2", "false\\\\"); + } + return false; } } } @@ -2344,7 +2342,7 @@ bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const ambiguous_transitions = "None"; } log->set_parameter("semdet1", ambiguous_transitions); - log->set_parameter("semdet2", "true"); + log->set_parameter("semdet2", "true\\\\"); } return true; } diff --git a/resources/template/SemDet.tex b/resources/template/SemDet.tex index 4f8dc83e..2e927f92 100644 --- a/resources/template/SemDet.tex +++ b/resources/template/SemDet.tex @@ -16,8 +16,10 @@ \section{Семантический детерминизм} \end{frame} %end detailed -\begin{frame}{Проверка семантического детерминизма} +\begin{frame}{Предикат $\SemDet\TypeIs\NFATYPE\to\BooleanTYPE$} \vspace{-5pt} + \\oldautomaton: + %template_oldautomaton \\Неоднозначные переходы и надёжные переходы: \\%template_semdet1 \\Семантический детерминизм: From 244fd3e6c9721f066561411ad692ab392acf0872 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Sat, 28 Jan 2023 07:13:06 +0300 Subject: [PATCH 20/22] minor changes --- libs/Objects/include/Objects/FiniteAutomaton.h | 3 ++- libs/Objects/src/FiniteAutomaton.cpp | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libs/Objects/include/Objects/FiniteAutomaton.h b/libs/Objects/include/Objects/FiniteAutomaton.h index d81e0c89..53cc50f9 100644 --- a/libs/Objects/include/Objects/FiniteAutomaton.h +++ b/libs/Objects/include/Objects/FiniteAutomaton.h @@ -77,7 +77,8 @@ class FiniteAutomaton : public BaseObject { bool semdet_entry(bool traps_removed = false, iLogTemplate* log = nullptr) const; // Поиск языков состояний - void get_state_languages(bool annoted, vector& state_languages) const; + void get_state_languages(vector& state_languages, + bool annoted = false) const; public: FiniteAutomaton(); diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index 7d1b5a42..6dc71353 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2250,10 +2250,10 @@ std::optional FiniteAutomaton::get_prefix( return ans; } -void FiniteAutomaton::get_state_languages(bool annoted, - vector& state_languages) const{ +void FiniteAutomaton::get_state_languages(vector& state_languages, + bool annoted) const { if (!annoted) { - annote().remove_trap_states().get_state_languages(true, state_languages); + annote().remove_trap_states().get_state_languages(state_languages, true); return; } // Logger::log( @@ -2272,10 +2272,11 @@ void FiniteAutomaton::get_state_languages(bool annoted, // Получение языка из производной регулярки автомата по префиксу: reg = to_regex(); auto derivative = reg.prefix_derivative(prefix.value()); + //cout << prefix.value() << " " << reg.to_txt() << "\n"; if (!derivative.has_value()) continue; state_languages[i].from_string(derivative.value().to_txt()); state_languages[i] = state_languages[i].deannote(); - cout << state_languages[i].to_txt() << "\n"; + //cout << state_languages[i].to_txt() << "\n"; } } @@ -2284,7 +2285,7 @@ bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const return remove_trap_states().semdet_entry(true, log); } vector state_languages; - get_state_languages(false, state_languages); + get_state_languages(state_languages, false); auto make_string_transition = [=](int from, alphabet_symbol through, int to) { string f = "${q_" + std::to_string(from) + "}"; From cabd7885c3e9ca08e741b05787a407c7eea28c84 Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Sat, 28 Jan 2023 07:40:14 +0300 Subject: [PATCH 21/22] logs changed --- libs/Objects/src/FiniteAutomaton.cpp | 17 +++++++---------- resources/template/SemDet.tex | 14 ++++++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index 6dc71353..c491fad3 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2286,11 +2286,11 @@ bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const } vector state_languages; get_state_languages(state_languages, false); - auto make_string_transition = [=](int from, alphabet_symbol through, - int to) { - string f = "${q_" + std::to_string(from) + "}"; - string arrow = "{\\xrightarrow{\\text{$" + string(through) + "$}}}"; - string t = "{q_" + std::to_string(to) + "}$"; + auto make_string_transition = [=](string from, alphabet_symbol through, + string to) { + string f = from; + string arrow = ">->>{" + string(through) + "}"; + string t = to; return f + arrow + t; }; std::string ambiguous_transitions = ""; @@ -2303,7 +2303,7 @@ bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const for (auto it = transition->second.begin(); it != transition->second.end(); it++) { ambiguous_transitions += - make_string_transition(j, transition->first, *it) + + make_string_transition(states[j].identifier, transition->first, states[*it].identifier) + ","; } } @@ -2322,7 +2322,7 @@ bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const if (reliability && transition->second.size() > 1) { ambiguous_transitions += "Reliable:" + - make_string_transition(j, transition->first, *it) + + make_string_transition(states[j].identifier, transition->first, states[*it].identifier) + +"\\\\"; } } @@ -2354,9 +2354,6 @@ bool FiniteAutomaton::semdet(iLogTemplate* log) const { log->set_parameter("oldautomaton", *this); } bool result = semdet_entry(false, log); - if (log) { - log->set_parameter("result", result); - } return result; // Logger::finish_step(); } diff --git a/resources/template/SemDet.tex b/resources/template/SemDet.tex index 2e927f92..b38dcd57 100644 --- a/resources/template/SemDet.tex +++ b/resources/template/SemDet.tex @@ -18,10 +18,16 @@ \section{Семантический детерминизм} %end detailed \begin{frame}{Предикат $\SemDet\TypeIs\NFATYPE\to\BooleanTYPE$} \vspace{-5pt} - \\oldautomaton: + oldautomaton: + %template_oldautomaton - \\Неоднозначные переходы и надёжные переходы: - \\%template_semdet1 - \\Семантический детерминизм: + + Неоднозначные переходы и надёжные переходы: + + %template_semdet1 + + + Семантический детерминизм: + %template_semdet2 \end{frame} \ No newline at end of file From 22b7275c2cb5b804305c6e02e92b3e7facebf6ff Mon Sep 17 00:00:00 2001 From: Robby-the-paladin Date: Mon, 6 Feb 2023 09:58:21 +0300 Subject: [PATCH 22/22] renaming + Double subscript fix --- libs/Objects/src/FiniteAutomaton.cpp | 8 ++++---- resources/template/SemDet.tex | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/libs/Objects/src/FiniteAutomaton.cpp b/libs/Objects/src/FiniteAutomaton.cpp index c491fad3..9b2641f7 100644 --- a/libs/Objects/src/FiniteAutomaton.cpp +++ b/libs/Objects/src/FiniteAutomaton.cpp @@ -2331,8 +2331,8 @@ bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const // Logger::finish_step(); ambiguous_transitions += "Reliable: none\\\\"; if (log) { - log->set_parameter("semdet1", ambiguous_transitions); - log->set_parameter("semdet2", "false\\\\"); + log->set_parameter("ambiguous transitions", ambiguous_transitions); + log->set_parameter("semdet result", "false\\\\"); } return false; } @@ -2342,8 +2342,8 @@ bool FiniteAutomaton::semdet_entry(bool traps_removed, iLogTemplate* log) const if (ambiguous_transitions == "") { ambiguous_transitions = "None"; } - log->set_parameter("semdet1", ambiguous_transitions); - log->set_parameter("semdet2", "true\\\\"); + log->set_parameter("ambiguous transitions", ambiguous_transitions); + log->set_parameter("semdet result", "true\\\\"); } return true; } diff --git a/resources/template/SemDet.tex b/resources/template/SemDet.tex index b38dcd57..d545bca5 100644 --- a/resources/template/SemDet.tex +++ b/resources/template/SemDet.tex @@ -2,9 +2,9 @@ \section{Семантический детерминизм} %begin detailed \begin{frame}{Семантический детерминизм} \vspace{-5pt} - Язык состояния $q$ — это $\{w | q \xrightarrow{\text{$w$}} q\}$, где $q_f$ - финальное состояние. НКА $A$ семантически детеминирован, если для всякой неоднозначности $q_i \xrightarrow{\text{$a$}} {q_j__1} , ..., {q_i \xrightarrow{\text{$a$}} q_j__k}$ существует такое состояние $q_j__s$, что языки всех $q_j__t$ $(1 \leqslant t \leqslant k)$ вкладываются в его язык (это означает, что переход $q_i \xrightarrow{\text{$a$}} {q_j__s}$ надёжен: если слово распознаётся автоматом, оно обязательно будет распознано после такого перехода). + Язык состояния $q$ — это $\{w | q \xrightarrow{\text{$w$}} q\}$, где $q_f$ - финальное состояние. НКА $A$ семантически детеминирован, если для всякой неоднозначности $q_i \xrightarrow{\text{$a$}} {q_{j_1}} , ..., {q_i \xrightarrow{\text{$a$}} q_{j_k}}$ существует такое состояние $q_{j_s}$, что языки всех $q_{j_t}$ $(1 \leqslant t \leqslant k)$ вкладываются в его язык (это означает, что переход $q_i \xrightarrow{\text{$a$}} {q_{j_s}}$ надёжен: если слово распознаётся автоматом, оно обязательно будет распознано после такого перехода). Языки состояний при этом строятся с помощью производных: в качестве аргумента производной достаточно взять произвольный префикс $v$, соответствующий переходу $q_0 \xrightarrow{\text{$v$}} q$. -\end{frame} % descriptive documentation +\end{frame} \begin{frame}{Алгоритм проверки семантического детерминизма} \vspace{-5pt} \begin{itemize} @@ -24,10 +24,10 @@ \section{Семантический детерминизм} Неоднозначные переходы и надёжные переходы: - %template_semdet1 + %template_ambiguous transitions Семантический детерминизм: - %template_semdet2 + %template_semdet result \end{frame} \ No newline at end of file