Write a class for DFA type
objects. Deterministic Finite Automata are commonly defined as a
quintuple consisting of a set of states, a set of symbals, a
transition function, a start state and a set of accept states
For this implementation let the alphabet be given as a string of symbols, the transition function as list of lists which represent an n by m matrix where the n rows represent the states and the m columns represent the alphabet symbols, and the accept states as a set. The states are integers 0, 1, 2, ..., n-1 and 0 is the start state. The input tape is a string of symbols from the alphabet.
Answer:
CODE:
class DFA:
def __init__(self, alpha, delta, accept):
self.alpha = alpha
self.delta = delta
self.accept =
accept
#transition is a
dictionary storing the transition
self.transition =
{}
for state in
range(len(delta)):
self.transition[state] = {}
for alphabet in range(len(delta[state])):
self.transition[state][alpha[alphabet]] =
delta[state][alphabet]
def __repr__(self):
return "DFA with
alphabet {}, transition {} and accept states
{}".format(self.alpha,self.delta,self.accept)
def accepts(self, tape):
#as per question,
initial state = 0
present_state = 0
for x in tape:
#make a transition for symbol x in tape
present_state = self.transition[present_state][x]
# if we get
present_state as a final state after finishing the tape,
#then return true
othetrwise return false
if present_state in
self.accept:
return True
else:
return False
#In complement of DFA , the final state becomes
non-final and non-final become final state
def comp(self):
new_final_state =
set()
for i in
range(len(self.delta)):
#make those states final which are not final in current DFA
if i not in self.accept:
new_final_state.add(i)
#return complemented
DFA
return DFA(self.alpha,
self.delta, new_final_state)
#odd number of ’a’s
m=DFA("ab",[[1, 0], [0, 1]], {1})
print(m)
t = "aaabaaba"
print(m.accepts(t))
SCREENSHOT OF THE CODE:


OUTPUT:
![>>> DFA with alphabet ab, transition [[1, 0], [0, 1]] and accept states set ([1]) False](http://img.homeworklib.com/questions/df8a6b50-6033-11eb-accc-ad7fd17f72e6.png?x-oss-process=image/resize,w_560)
Thank you.
Write a class for DFA type objects. Deterministic Finite Automata are commonly defined as a quintuple...
Please help me...
5. (a) Consider the deterministic finite automaton M with states S := {80, 81, 82, 83}, start state so, single accepting state $3, and alphabet E = {0,1}. The following table describes the transition function T:S xHS. State 0 1 So So S1 So S1 S2 So $1 82 S3 S3 82 Draw the transition diagram for M. Let U = {01110,011100}. For each u EU describe the run for input u to M. Does M accept...
Python only please, thanks in advance.
Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...
Python only please, thanks in advance.
Type up the GeometricObject class (code given on the back of the paper). Name this file GeometricObjectClass and store it in the folder you made (xxlab14) 1. Design a class named Rectangle as a subclass of the GeometricObject class. Name the file RectangleClass and place it in the folder. 2. The Rectangle class contains Two float data fields named length and width A constructor that creates a rectangle with the specified fields with default...
Problem 3: A Connect Four Player Class In this problem, you will create a Player class to represent a player of the Connect Four game. In combination with the Board class that you wrote in Problem 2 and some code that you will write in the next problem set, this will enable you to play a game of Connect Four with a friend! Getting started Begin by downloading the file ps11pr3.py and opening it in Sypder or your editor of...
Python has the complex class for performing complex number arithmetic. For this assignment, you will design and implement your own Complex class. Note that the complex class in Python is named in lowercase, while our custom Complex class is named with C in uppercase. A complex number is of the form a + bi, where a and b are real numbers and i is √-1. The numbers a and b are known as the real part and the imaginary part...
Python3 : question about object-oriented programming, Please
write program in the template(critter.py),specific information is
on the graphs
the missing words in the 4th line are 'To save an attribute,
attach it to this self keyword'
W11 - Critters Implement the Critter class. Each critter C has attributes species, size, and age The constructor accepts arguments for the attributes above, in the order above. You can expect size and age to be numeric values Each critter C has a can_eat) method,...
It's my python homework. Not Java. Design type 1: # Creating an object of the class "DeAnzaBurger" theOrder = DeAnzaBurger() # calling the main method theOrder.main() # And the class is like: class DeAnzaBurger: # You may need to have a constructor def __init__(self): self._orderDict = {} self._priceBeforeTax = 0 self._priceAfterTax = 0 # you may have the tax rate also as an instance variable. But as I mentioned, you can use your # own deign. .... # That...
can someone write me a wing101 python code for this
please
Question: For a projectile launched with a velocity vIm/s) at an angle to the horizontal 6 Iradl, the horizontal distance travelled (also called the range) is given by where the altitude of the landing position is Δh higher than that of the launch position and g is the gravitational acceleration (use 9.81 m/s^2). Note: θ in theformula is in radians write a Python function that accepts ν, θ and...
Write a class called Course_xxx that represents a course taken at a school. Represent each student using the Student class from the Chapter 7 source files, Student.java. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called roll that prints all students in the course. Create a driver class...
PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a few instance attribute and a few instance methods to support those attributes. In the next assignment, the TripleString class will help us create a more involved application. Before we do that though, we have to thoroughly test our TripleString implementation. Specifications The class TripleString will contain symbolic constants, instance attributes, and instance methods. ▶ Class symbolic constants This class has 3 symbolic constants, which...