@@ -139,6 +139,13 @@ def remove_start_state(self, state: Hashable) -> int:
139139 return 1
140140 return 0
141141
142+ def get_next_state (self , s_from : Hashable , symb_by : Hashable ) \
143+ -> Optional [State ]:
144+ """ Make a call of deterministic transition function """
145+ s_from = to_state (s_from )
146+ symb_by = to_symbol (symb_by )
147+ return self ._transition_function .get_next_state (s_from , symb_by )
148+
142149 def accepts (self , word : Iterable [Hashable ]) -> bool :
143150 """ Checks whether the dfa accepts a given word
144151
@@ -168,8 +175,7 @@ def accepts(self, word: Iterable[Hashable]) -> bool:
168175 for symbol in word :
169176 if current_state is None :
170177 return False
171- current_state = self ._transition_function .get_next_state (
172- current_state , symbol )
178+ current_state = self .get_next_state (current_state , symbol )
173179 return current_state is not None and self .is_final_state (current_state )
174180
175181 def is_deterministic (self ) -> bool :
@@ -213,19 +219,12 @@ def copy(self) -> "DeterministicFiniteAutomaton":
213219 """
214220 return self ._copy_to (DeterministicFiniteAutomaton ())
215221
216- def get_next_state (self , s_from : Hashable , symb_by : Hashable ) \
217- -> Optional [State ]:
218- """ Make a call of deterministic transition function """
219- s_from = to_state (s_from )
220- symb_by = to_symbol (symb_by )
221- return self ._transition_function .get_next_state (s_from , symb_by )
222-
223222 def _get_previous_transitions (self ) -> PreviousTransitions :
224223 previous_transitions = PreviousTransitions (self ._states ,
225224 self ._input_symbols )
226225 for state in self ._states :
227226 for symbol in self ._input_symbols :
228- next0 = self ._transition_function . get_next_state (state , symbol )
227+ next0 = self .get_next_state (state , symbol )
229228 previous_transitions .add (next0 , symbol , state )
230229 return previous_transitions
231230
@@ -276,8 +275,7 @@ def minimize(self) -> "DeterministicFiniteAutomaton":
276275 done = set ()
277276 new_state = to_new_states [state ]
278277 for symbol in self ._input_symbols :
279- next_node = self ._transition_function .get_next_state (
280- state , symbol )
278+ next_node = self .get_next_state (state , symbol )
281279 if next_node and next_node in states :
282280 next_node = to_new_states [next_node ]
283281 if (next_node , symbol ) not in done :
@@ -431,10 +429,8 @@ def _is_equivalent_to_minimal(
431429 matches = {self_minimal .start_state : other_minimal .start_state }
432430 while to_process :
433431 current_self , current_other = to_process .pop ()
434- if (self_minimal .is_final_state (current_self )
435- and not other_minimal .is_final_state (current_other )) or \
436- (not self_minimal .is_final_state (current_self )
437- and other_minimal .is_final_state (current_other )):
432+ if self_minimal .is_final_state (current_self ) != \
433+ other_minimal .is_final_state (current_other ):
438434 return False
439435 next_self = list (self_minimal .get_transitions_from (current_self ))
440436 next_other = list (other_minimal .get_transitions_from (current_other ))
0 commit comments