Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MS Branicky, 2019-08-30, 2021-02-09 Q = set(['0', q1']) Sigma set(01) = = even parity 3 : , 3 : qi', delta { # FA that
MS Branicky, 2019-08-30, 2021-02-09 Q = set(['0', q1']) Sigma set("01") = = even parity 3 : , 3 : qi', delta { # FA that checks ('0', '0') : '0', ('0', '1') ('qi', '0') ('qi', '1') } qo' F set(['0']) : test_inputs = [*011", "0111"] on S YOU SHOULD NOT HAVE TO CHANGE ANYTHING BELOW HERE # consistency and completeness checks the model aka "input checking" assert in Q, "s must be in QM assert F (= Q, "F must be subset of Q" domain_states, domain_symbols list (zip(*delta. keys())) assert set (domain_states) " + + str (state), end="") for input_string in test_inputs: # check input consistency set(input_string) 20 -1-> ql -1--> 20 Accept Start, input = 0111 20-0> 20-1-> ql -1-> 90 -1-> ql Reject Problem 2.1 [20 points] Purpose: Play with DFA implementations. The python notebook parity.ipynb can be used to specify and then simulate DFAs. Specifically, it has defined in it the specification of a machine that detects even-parity binary strings. a. Study the program, play with it, convince yourself of how it works. There is no need to turn any I/O in. Just report any anomalies you might have found. b. Copy the notebook (File -> Save a Copy in Drive) to a new Colab notebook called 510.ipynb (or cut-and-paste to a .py file if you Python installed on your own machine). Modify the definition section to implement a machine recognizing the language "Strings in {0,1,5}* containing the substring 510" given in lecture. Test it as you see fit. Turn in a printout of the modified code section only. c. Repeat part b, but with the alphabet {0,1,2,3,4,5,6,7,8,9). Use an implicit assignment! For example, in C++ an explicit definition of an array is int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; An implicit definition of the same array is for (i=0; i " +str(state), end=" ") for input_string in test_inputs: # check input consistency assert set(input_string) 20 -1-> ql 5> ql -4-> ql 2-> ql 1> 20 Accept = 9071221346100 Start, input 20 20 -0> 20 -7-> 20 -1-> ql -2-> ql 2-> q1 -1-> 20 -3-> 20-4-> 90-6- 90 ql -0> ql 0> q1 Reject [ ] print (set("01")) print (set("1222333444455555")) {'0', '1'} [2', '3', '5', '4', 'l'} D = [i for i in range(0, 10)] print (D) D_letters = [str(i) for i in range(0, 10)] print (D_letters) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ['o', '1', '2', '3', '4', '5', '6', '7', '8', '9'] MS Branicky, 2019-08-30, 2021-02-09 Q = set(['0', q1']) Sigma set("01") = = even parity 3 : , 3 : qi', delta { # FA that checks ('0', '0') : '0', ('0', '1') ('qi', '0') ('qi', '1') } qo' F set(['0']) : test_inputs = [*011", "0111"] on S YOU SHOULD NOT HAVE TO CHANGE ANYTHING BELOW HERE # consistency and completeness checks the model aka "input checking" assert in Q, "s must be in QM assert F (= Q, "F must be subset of Q" domain_states, domain_symbols list (zip(*delta. keys())) assert set (domain_states) " + + str (state), end="") for input_string in test_inputs: # check input consistency set(input_string) 20 -1-> ql -1--> 20 Accept Start, input = 0111 20-0> 20-1-> ql -1-> 90 -1-> ql Reject Problem 2.1 [20 points] Purpose: Play with DFA implementations. The python notebook parity.ipynb can be used to specify and then simulate DFAs. Specifically, it has defined in it the specification of a machine that detects even-parity binary strings. a. Study the program, play with it, convince yourself of how it works. There is no need to turn any I/O in. Just report any anomalies you might have found. b. Copy the notebook (File -> Save a Copy in Drive) to a new Colab notebook called 510.ipynb (or cut-and-paste to a .py file if you Python installed on your own machine). Modify the definition section to implement a machine recognizing the language "Strings in {0,1,5}* containing the substring 510" given in lecture. Test it as you see fit. Turn in a printout of the modified code section only. c. Repeat part b, but with the alphabet {0,1,2,3,4,5,6,7,8,9). Use an implicit assignment! For example, in C++ an explicit definition of an array is int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; An implicit definition of the same array is for (i=0; i " +str(state), end=" ") for input_string in test_inputs: # check input consistency assert set(input_string) 20 -1-> ql 5> ql -4-> ql 2-> ql 1> 20 Accept = 9071221346100 Start, input 20 20 -0> 20 -7-> 20 -1-> ql -2-> ql 2-> q1 -1-> 20 -3-> 20-4-> 90-6- 90 ql -0> ql 0> q1 Reject [ ] print (set("01")) print (set("1222333444455555")) {'0', '1'} [2', '3', '5', '4', 'l'} D = [i for i in range(0, 10)] print (D) D_letters = [str(i) for i in range(0, 10)] print (D_letters) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] ['o', '1', '2', '3', '4', '5', '6', '7', '8', '9']
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started