From 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:55:17 -0700 Subject: Init --- Homework/cs5000/hw02/CS5000_F23_EH_HW02.org | 65 +++++++++++++ Homework/cs5000/hw02/CS5000_F23_EH_HW02.pdf | Bin 0 -> 447863 bytes Homework/cs5000/hw02/CS5000_F23_EH_HW02.tex | 102 +++++++++++++++++++++ Homework/cs5000/hw02/CS5000_F23_HW02.pdf | Bin 0 -> 151939 bytes Homework/cs5000/hw02/cs5000_f23_hw02_uts.py | 45 +++++++++ Homework/cs5000/hw02/hw02.zip | Bin 0 -> 397965 bytes Homework/cs5000/hw02/hw02/Mod3DFA.py | 50 ++++++++++ Homework/cs5000/hw02/hw02/Mod7DFA.py | 50 ++++++++++ .../hw02/hw02/__pycache__/Mod3DFA.cpython-311.pyc | Bin 0 -> 2534 bytes .../hw02/hw02/__pycache__/Mod7DFA.cpython-311.pyc | Bin 0 -> 2158 bytes Homework/cs5000/hw02/hw02/cs5000_f23_hw02_uts.py | 45 +++++++++ Homework/cs5000/hw02/hw02/hw02.pdf | Bin 0 -> 445390 bytes Homework/cs5000/hw02/img/p01_02.png | Bin 0 -> 285758 bytes Homework/cs5000/hw02/img/p02.png | Bin 0 -> 247543 bytes 14 files changed, 357 insertions(+) create mode 100644 Homework/cs5000/hw02/CS5000_F23_EH_HW02.org create mode 100644 Homework/cs5000/hw02/CS5000_F23_EH_HW02.pdf create mode 100644 Homework/cs5000/hw02/CS5000_F23_EH_HW02.tex create mode 100644 Homework/cs5000/hw02/CS5000_F23_HW02.pdf create mode 100644 Homework/cs5000/hw02/cs5000_f23_hw02_uts.py create mode 100644 Homework/cs5000/hw02/hw02.zip create mode 100644 Homework/cs5000/hw02/hw02/Mod3DFA.py create mode 100644 Homework/cs5000/hw02/hw02/Mod7DFA.py create mode 100644 Homework/cs5000/hw02/hw02/__pycache__/Mod3DFA.cpython-311.pyc create mode 100644 Homework/cs5000/hw02/hw02/__pycache__/Mod7DFA.cpython-311.pyc create mode 100644 Homework/cs5000/hw02/hw02/cs5000_f23_hw02_uts.py create mode 100644 Homework/cs5000/hw02/hw02/hw02.pdf create mode 100644 Homework/cs5000/hw02/img/p01_02.png create mode 100644 Homework/cs5000/hw02/img/p02.png (limited to 'Homework/cs5000/hw02') diff --git a/Homework/cs5000/hw02/CS5000_F23_EH_HW02.org b/Homework/cs5000/hw02/CS5000_F23_EH_HW02.org new file mode 100644 index 0000000..5fd935c --- /dev/null +++ b/Homework/cs5000/hw02/CS5000_F23_EH_HW02.org @@ -0,0 +1,65 @@ +#+TITLE: HW 02 +#+AUTHOR: Elizabeth Hunt +#+STARTUP: entitiespretty fold inlineimages +#+LATEX_HEADER: \notindent \notag \usepackage{amsmath} \usepackage[a4paper,margin=1in,portrait]{geometry} +#+LATEX: \setlength\parindent{0pt} +#+OPTIONS: toc:nil + +* Problem 1 +** Part 1 +$L(M) = \{ x | x \in \{ a \}^{*} \} \cup \{ x | x \in \{ b \}^{*} \} \cup \{ x | x \in \{ c \}^{*} \}$ + +** Part 2 + +#+attr_latex: :width 300px +[[./img/p01_02.png]] + +$Q = {q_0, q_1, q_2, q_3}$ + +$\Sigma = {a, b, c}$ + +$F = {q_1, q_2, q_3}$ + +$\delta(q_0, a) = {q_1}, \delta(q_1, a) = {q_1}, \delta(q_0, b) = {q_2}, \delta(q_2, b) = {q_2}, \delta(q_0, c) = {q_3}, \delta(q_3, c) = c$ + +* Problem 2 +** Work +| subset | 0 | 1 | +| {q_0} | {q_0, q_1} | {q_1} | +| {q_1} | {q_2} | {q_2} | +| {q_2} | {q_2} | {q_2} | +| {q_0, q_1} | {q_0, q_1} \cup {q_2} | {q_1} \cup {q_2} | +| {q_0, q_1, q_2} | {q_0, q_1} \cup {q_2} \cup {q_2} | {q_1} \cup {q_2} \cup {q_2} | +| {q_1, q_2} | {q_2} \cup {q_2} | {q_2} \cup {q_2} | + + +** Solution +#+attr_latex: :width 300px +[[./img/p02.png]] + +$Q_D = \{q_0, q_1, q_2, q_3, q_4, q_5\}$ + +$\Sigma = \{0, 1\}$ + +$F_D = \{q_1, q_2, q_4, q_5\}$ + +$\delta_D(q_0, 0) = q_1$ + +$\delta_D(q_0, 1) = q_2$ + +$\delta_D(q_1, 0) = q_5$ + +$\delta_D(q_1, q) = q_4$ + +$\delta_D(q_2, 0) = \delta_D(q_2, 1) = q_3$ + +$\delta_D(q_3, 0) = \delta_D(q_3, 1) = q_3$ + +$\delta_D(q_4, 0) = \delta_D(q_4, 1) = q_4$ + +$\delta_D(q_5, 0) = q_5$ + +$\delta_D(q_5, 1} = q_4$ + +* Problem 3 +See attached python diff --git a/Homework/cs5000/hw02/CS5000_F23_EH_HW02.pdf b/Homework/cs5000/hw02/CS5000_F23_EH_HW02.pdf new file mode 100644 index 0000000..5344c34 Binary files /dev/null and b/Homework/cs5000/hw02/CS5000_F23_EH_HW02.pdf differ diff --git a/Homework/cs5000/hw02/CS5000_F23_EH_HW02.tex b/Homework/cs5000/hw02/CS5000_F23_EH_HW02.tex new file mode 100644 index 0000000..f578070 --- /dev/null +++ b/Homework/cs5000/hw02/CS5000_F23_EH_HW02.tex @@ -0,0 +1,102 @@ +% Created 2023-10-07 Sat 14:51 +% Intended LaTeX compiler: pdflatex +\documentclass[11pt]{article} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{wrapfig} +\usepackage{rotating} +\usepackage[normalem]{ulem} +\usepackage{amsmath} +\usepackage{amssymb} +\usepackage{capt-of} +\usepackage{hyperref} +\notindent \notag \usepackage{amsmath} \usepackage[a4paper,margin=1in,portrait]{geometry} +\author{Elizabeth Hunt} +\date{\today} +\title{HW 02} +\hypersetup{ + pdfauthor={Elizabeth Hunt}, + pdftitle={HW 02}, + pdfkeywords={}, + pdfsubject={}, + pdfcreator={Emacs 28.2 (Org mode 9.7-pre)}, + pdflang={English}} +\begin{document} + +\maketitle +\setlength\parindent{0pt} + +\section{Problem 1} +\label{sec:org41ad199} +\subsection{Part 1} +\label{sec:orgabe730c} +\(L(M) = \{ x | x \in \{ a \}^{*} \} \cup \{ x | x \in \{ b \}^{*} \} \cup \{ x | x \in \{ c \}^{*} \}\) + +\subsection{Part 2} +\label{sec:orgb60fdea} + +\begin{center} +\includegraphics[width=300px]{./img/p01_02.png} +\end{center} + +\(Q = {q_0, q_1, q_2, q_3}\) + +\(\Sigma = {a, b, c}\) + +\(F = {q_1, q_2, q_3}\) + +\(\delta(q_0, a) = {q_1}, \delta(q_1, a) = {q_1}, \delta(q_0, b) = {q_2}, \delta(q_2, b) = {q_2}, \delta(q_0, c) = {q_3}, \delta(q_3, c) = c\) + +\section{Problem 2} +\label{sec:org9cf81d0} +\subsection{Work} +\label{sec:org2daff9f} +\begin{center} +\begin{tabular}{lll} +subset & 0 & 1\\[0pt] +\{q\textsubscript{0}\} & \{q\textsubscript{0}, q\textsubscript{1}\} & \{q\textsubscript{1}\}\\[0pt] +\{q\textsubscript{1}\} & \{q\textsubscript{2}\} & \{q\textsubscript{2}\}\\[0pt] +\{q\textsubscript{2}\} & \{q\textsubscript{2}\} & \{q\textsubscript{2}\}\\[0pt] +\{q\textsubscript{0}, q\textsubscript{1}\} & \{q\textsubscript{0}, q\textsubscript{1}\} \(\cup\) \{q\textsubscript{2}\} & \{q\textsubscript{1}\} \(\cup\) \{q\textsubscript{2}\}\\[0pt] +\{q\textsubscript{0}, q\textsubscript{1}, q\textsubscript{2}\} & \{q\textsubscript{0}, q\textsubscript{1}\} \(\cup\) \{q\textsubscript{2}\} \(\cup\) \{q\textsubscript{2}\} & \{q\textsubscript{1}\} \(\cup\) \{q\textsubscript{2}\} \(\cup\) \{q\textsubscript{2}\}\\[0pt] +\{q\textsubscript{1}, q\textsubscript{2}\} & \{q\textsubscript{2}\} \(\cup\) \{q\textsubscript{2}\} & \{q\textsubscript{2}\} \(\cup\) \{q\textsubscript{2}\}\\[0pt] +\end{tabular} +\end{center} + + +\subsection{Solution} +\label{sec:org7701586} +\begin{center} +\includegraphics[width=300px]{./img/p02.png} +\end{center} + +\(Q_D = \{q_0, q_1, q_2, q_3, q_4, q_5\}\) + +\(\Sigma = \{0, 1\}\) + +\(F_D = \{q_1, q_2, q_4, q_5\}\) + +\(\delta_D(q_0, 0) = q_1\) + +\(\delta_D(q_0, 1) = q_2\) + +\(\delta_D(q_1, 0) = q_5\) + +\(\delta_D(q_1, q) = q_4\) + +\(\delta_D(q_2, 0) = \delta_D(q_2, 1) = q_3\) + +\(\delta_D(q_3, 0) = \delta_D(q_3, 1) = q_3\) + +\(\delta_D(q_4, 0) = \delta_D(q_4, 1) = q_4\) + +\(\delta_D(q_5, 0) = q_5\) + +\(\delta_D(q_5, 1} = q_4\) + +\section{Problem 3} +\label{sec:orge1c9402} +See attached python +\end{document} \ No newline at end of file diff --git a/Homework/cs5000/hw02/CS5000_F23_HW02.pdf b/Homework/cs5000/hw02/CS5000_F23_HW02.pdf new file mode 100644 index 0000000..60b4d50 Binary files /dev/null and b/Homework/cs5000/hw02/CS5000_F23_HW02.pdf differ diff --git a/Homework/cs5000/hw02/cs5000_f23_hw02_uts.py b/Homework/cs5000/hw02/cs5000_f23_hw02_uts.py new file mode 100644 index 0000000..a45fba6 --- /dev/null +++ b/Homework/cs5000/hw02/cs5000_f23_hw02_uts.py @@ -0,0 +1,45 @@ +#################################################### +# CS 5000: F23: Assignment 2: Unit Tests +# bugs to vladimir kulyukin in canvas +##################################################### + +import numpy as np +from Mod3DFA import Mod3DFA +from Mod7DFA import Mod7DFA +import unittest + + +class cs5000_f23_hw02_uts(unittest.TestCase): + def test_assgn_02_ut_01(self): + print("\n***** Testing Mod3DFA: Hw02: UT01 ************") + lower, upper = 0, 10001 + dfa = Mod3DFA() + for i in range(lower, upper): + bstr = "{0:b}".format(i) + if i % 3 == 0: + assert dfa.processString(bstr) == True + # print('assertion passed on {}'.format(i)) + else: + assert dfa.processString(bstr) == False + # print('assertion passed on {}'.format(i)) + print("Mod7DFA: HW02: UT01 passed...") + + def test_assgn_02_ut_02(self): + print("\n***** Mod7DFA: HW03: UT02 ************") + lower, upper = 0, 1000001 + dfa = Mod7DFA() + for i in range(lower, upper): + bstr = "{0:b}".format(i) + if i % 7 == 0: + assert dfa.processString(bstr) == True + # print('assertion passed on {}'.format(i)) + else: + assert dfa.processString(bstr) == False + # print('assertion passed on {}'.format(i)) + print("Mod7DFA: HW02: UT02: passed...") + + +### ================ Unit Tests ==================== + +if __name__ == "__main__": + unittest.main() diff --git a/Homework/cs5000/hw02/hw02.zip b/Homework/cs5000/hw02/hw02.zip new file mode 100644 index 0000000..604aa07 Binary files /dev/null and b/Homework/cs5000/hw02/hw02.zip differ diff --git a/Homework/cs5000/hw02/hw02/Mod3DFA.py b/Homework/cs5000/hw02/hw02/Mod3DFA.py new file mode 100644 index 0000000..93a7c5c --- /dev/null +++ b/Homework/cs5000/hw02/hw02/Mod3DFA.py @@ -0,0 +1,50 @@ +######################################### +## Mod3DFA.py +## bugs to vladimir kulyukin in canvas +######################################### + +class Mod3DFA: + + def __q0(self, s, pos): + if len(s) == pos: + return True + elif s[pos] == '0': + return self.__q0(s, pos+1) + elif s[pos] == '1': + return self.__q1(s, pos+1) + else: + return self.__q3(s, pos+1) + + def __q1(self, s, pos): + if len(s) == pos: + return False + elif s[pos] == '0': + return self.__q2(s, pos+1) + elif s[pos] == '1': + return self.__q0(s, pos+1) + else: + return self.__q3(s, pos+1) + + def __q2(self, s, pos): + if len(s) == pos: + return False + elif s[pos] == '0': + return self.__q1(s, pos+1) + elif s[pos] == '1': + return self.__q2(s, pos+1) + else: + return self.__q3(s, pos+1) + + def __q3(self, s, pos): + if (len(s) == pos): + return False + else: + return self.__q3(s, pos+1) + + def processString(self, s): + if s[0] == '0': + return self.__q0(s, 1) + elif s[0] == '1': + return self.__q1(s, 1) + else: + return self.__q3(s, pos+1) diff --git a/Homework/cs5000/hw02/hw02/Mod7DFA.py b/Homework/cs5000/hw02/hw02/Mod7DFA.py new file mode 100644 index 0000000..32cea44 --- /dev/null +++ b/Homework/cs5000/hw02/hw02/Mod7DFA.py @@ -0,0 +1,50 @@ +######################################### +## Mod7DFA.py +## Elizabeth Hunt +## A02364151 +######################################### + + +class DFA: + def __init__( + self, + alphabet: set[str], + initial_state: str, + error_state: str, + final_states: set[str], + delta: dict[dict[str, str]], + ): + self.alphabet = alphabet + self.initial_state = initial_state + self.error_state = error_state + self.final_states = final_states + self.delta = delta + + def processString(self, s): + state = self.initial_state + for i in s: + if i not in self.alphabet or state == self.error_state: + state = self.error_state + continue + state = self.delta[state][i] + return state in self.final_states + + +# ramblings: https://excalidraw.com/#json=YUK684eVJcffkGuAAG3rr,K__bSFw7kGK3dLQggSh_qA +class Mod7DFA(DFA): + def __init__(self): + super().__init__( + set(["1", "0"]), + "7m + 0", + "err", + set(["7m + 0"]), + { + "7m + 0": {"0": "7m + 0", "1": "7m + 1"}, + "7m + 1": {"0": "7m + 2", "1": "7m + 3"}, + "7m + 2": {"0": "7m + 4", "1": "7m + 5"}, + "7m + 3": {"0": "7m + 6", "1": "7m + 0"}, + "7m + 4": {"0": "7m + 1", "1": "7m + 2"}, + "7m + 5": {"0": "7m + 3", "1": "7m + 4"}, + "7m + 6": {"0": "7m + 5", "1": "7m + 6"}, + }, + ) diff --git a/Homework/cs5000/hw02/hw02/__pycache__/Mod3DFA.cpython-311.pyc b/Homework/cs5000/hw02/hw02/__pycache__/Mod3DFA.cpython-311.pyc new file mode 100644 index 0000000..7b6a27a Binary files /dev/null and b/Homework/cs5000/hw02/hw02/__pycache__/Mod3DFA.cpython-311.pyc differ diff --git a/Homework/cs5000/hw02/hw02/__pycache__/Mod7DFA.cpython-311.pyc b/Homework/cs5000/hw02/hw02/__pycache__/Mod7DFA.cpython-311.pyc new file mode 100644 index 0000000..9faf32a Binary files /dev/null and b/Homework/cs5000/hw02/hw02/__pycache__/Mod7DFA.cpython-311.pyc differ diff --git a/Homework/cs5000/hw02/hw02/cs5000_f23_hw02_uts.py b/Homework/cs5000/hw02/hw02/cs5000_f23_hw02_uts.py new file mode 100644 index 0000000..e2093d4 --- /dev/null +++ b/Homework/cs5000/hw02/hw02/cs5000_f23_hw02_uts.py @@ -0,0 +1,45 @@ +#################################################### +# CS 5000: F23: Assignment 2: Unit Tests +# bugs to vladimir kulyukin in canvas +##################################################### + +import numpy as np +from Mod3DFA import Mod3DFA +from Mod7DFA import Mod7DFA +import unittest + + +class cs5000_f23_hw02_uts(unittest.TestCase): + def test_assgn_02_ut_01(self): + print("\n***** Testing Mod3DFA: Hw02: UT01 ************") + lower, upper = 0, 1000001 + dfa = Mod3DFA() + for i in range(lower, upper): + bstr = "{0:b}".format(i) + if i % 3 == 0: + assert dfa.processString(bstr) == True + # print('assertion passed on {}'.format(i)) + else: + assert dfa.processString(bstr) == False + # print('assertion passed on {}'.format(i)) + print("Mod7DFA: HW02: UT01 passed...") + + def test_assgn_02_ut_02(self): + print("\n***** Mod7DFA: HW02: UT02 ************") + lower, upper = 0, 1000001 + dfa = Mod7DFA() + for i in range(lower, upper): + bstr = "{0:b}".format(i) + if i % 7 == 0: + assert dfa.processString(bstr) == True + # print('assertion passed on {}'.format(i)) + else: + assert dfa.processString(bstr) == False + # print('assertion passed on {}'.format(i)) + print("Mod7DFA: HW02: UT02: passed...") + + +### ================ Unit Tests ==================== + +if __name__ == "__main__": + unittest.main() diff --git a/Homework/cs5000/hw02/hw02/hw02.pdf b/Homework/cs5000/hw02/hw02/hw02.pdf new file mode 100644 index 0000000..c33b60f Binary files /dev/null and b/Homework/cs5000/hw02/hw02/hw02.pdf differ diff --git a/Homework/cs5000/hw02/img/p01_02.png b/Homework/cs5000/hw02/img/p01_02.png new file mode 100644 index 0000000..ce2a732 Binary files /dev/null and b/Homework/cs5000/hw02/img/p01_02.png differ diff --git a/Homework/cs5000/hw02/img/p02.png b/Homework/cs5000/hw02/img/p02.png new file mode 100644 index 0000000..f649e12 Binary files /dev/null and b/Homework/cs5000/hw02/img/p02.png differ -- cgit v1.3