@@ -138,6 +138,13 @@ def remove_start_state(self, state: Hashable) -> int:
138138 return 1
139139 return 0
140140
141+ def get_next_state (self , s_from : Hashable , symb_by : Hashable ) \
142+ -> Optional [State ]:
143+ """ Make a call of deterministic transition function """
144+ s_from = to_state (s_from )
145+ symb_by = to_symbol (symb_by )
146+ return self ._transition_function .get_next_state (s_from , symb_by )
147+
141148 def accepts (self , word : Iterable [Hashable ]) -> bool :
142149 """ Checks whether the dfa accepts a given word
143150
@@ -167,8 +174,7 @@ def accepts(self, word: Iterable[Hashable]) -> bool:
167174 for symbol in word :
168175 if current_state is None :
169176 return False
170- current_state = self ._transition_function .get_next_state (
171- current_state , symbol )
177+ current_state = self .get_next_state (current_state , symbol )
172178 return current_state is not None and self .is_final_state (current_state )
173179
174180 def is_deterministic (self ) -> bool :
@@ -212,19 +218,12 @@ def copy(self) -> "DeterministicFiniteAutomaton":
212218 """
213219 return self ._copy_to (DeterministicFiniteAutomaton ())
214220
215- def get_next_state (self , s_from : Hashable , symb_by : Hashable ) \
216- -> Optional [State ]:
217- """ Make a call of deterministic transition function """
218- s_from = to_state (s_from )
219- symb_by = to_symbol (symb_by )
220- return self ._transition_function .get_next_state (s_from , symb_by )
221-
222221 def _get_previous_transitions (self ) -> PreviousTransitions :
223222 previous_transitions = PreviousTransitions (self ._states ,
224223 self ._input_symbols )
225224 for state in self ._states :
226225 for symbol in self ._input_symbols :
227- next0 = self ._transition_function . get_next_state (state , symbol )
226+ next0 = self .get_next_state (state , symbol )
228227 previous_transitions .add (next0 , symbol , state )
229228 return previous_transitions
230229
@@ -275,8 +274,7 @@ def minimize(self) -> "DeterministicFiniteAutomaton":
275274 done = set ()
276275 new_state = to_new_states [state ]
277276 for symbol in self ._input_symbols :
278- next_node = self ._transition_function .get_next_state (
279- state , symbol )
277+ next_node = self .get_next_state (state , symbol )
280278 if next_node and next_node in states :
281279 next_node = to_new_states [next_node ]
282280 if (next_node , symbol ) not in done :
@@ -430,10 +428,8 @@ def _is_equivalent_to_minimal(
430428 matches = {self_minimal .start_state : other_minimal .start_state }
431429 while to_process :
432430 current_self , current_other = to_process .pop ()
433- if (self_minimal .is_final_state (current_self )
434- and not other_minimal .is_final_state (current_other )) or \
435- (not self_minimal .is_final_state (current_self )
436- and other_minimal .is_final_state (current_other )):
431+ if self_minimal .is_final_state (current_self ) != \
432+ other_minimal .is_final_state (current_other ):
437433 return False
438434 next_self = list (self_minimal .get_transitions_from (current_self ))
439435 next_other = list (other_minimal .get_transitions_from (current_other ))
0 commit comments