Class: Lernen::Automaton::MooreLike
- Inherits:
-
TransitionSystem
- Object
- TransitionSystem
- Lernen::Automaton::MooreLike
- Defined in:
- lib/lernen/automaton/moore_like.rb
Overview
MooreLike represents a Moore-like transition system.
This transition system has an output value for each configuration (or state). Therefore, the following invariant is required for all ‘conf` and `input`.
“‘ruby step_output, next_conf = self.step(conf, input) step_output == self.output(next_conf) “`
Note that in this class, the initial output of the ‘#run` method is lost. If it is needed, we can use `#run_empty` instead.
Note that this class is abstract. We should implement the following method:
-
‘#type`
-
‘#initial_conf`
-
‘#step_conf(conf, input)`
-
‘#output(conf)`
Class Method Summary collapse
-
.find_separating_word(alphabet, automaton1, automaton2) ⇒ Object
Finds a separating word between ‘automaton1` and `automaton2`.
Instance Method Summary collapse
-
#output(conf) ⇒ Object
Returns the output value for the given configuration.
-
#run_empty ⇒ Object
Runs and returns the output value of the transitions for the empty string.
- #step(conf, input) ⇒ Object
-
#step_conf(conf, input) ⇒ Object
Runs a transition from the given configuration with the given input.
Methods inherited from TransitionSystem
#initial_conf, random_transition_function, #run, #to_dot, #to_graph, #to_mermaid, #type
Class Method Details
.find_separating_word(alphabet, automaton1, automaton2) ⇒ Object
Finds a separating word between ‘automaton1` and `automaton2`.
: [Conf, In, Out] (
Array[In] alphabet,
MooreLike[Conf, In, Out] automaton1,
MooreLike[Conf, In, Out] automaton2
) -> (Array[In] | nil)
72 73 74 75 76 77 78 79 80 |
# File 'lib/lernen/automaton/moore_like.rb', line 72 def self.(alphabet, automaton1, automaton2) unless automaton2.is_a?(automaton1.class) raise ArgumentError, "Cannot find a separating word for different type automata" end return [] if automaton1.run_empty != automaton2.run_empty # steep:ignore super end |
Instance Method Details
#output(conf) ⇒ Object
Returns the output value for the given configuration.
This is an abstract method.
: (Conf conf) -> Out
48 49 50 |
# File 'lib/lernen/automaton/moore_like.rb', line 48 def output(conf) raise TypeError, "abstract method: `output`" end |
#run_empty ⇒ Object
Runs and returns the output value of the transitions for the empty string.
: () -> Out
63 |
# File 'lib/lernen/automaton/moore_like.rb', line 63 def run_empty = output(initial_conf) |
#step(conf, input) ⇒ Object
55 56 57 58 |
# File 'lib/lernen/automaton/moore_like.rb', line 55 def step(conf, input) next_conf = step_conf(conf, input) [output(next_conf), next_conf] end |
#step_conf(conf, input) ⇒ Object
Runs a transition from the given configuration with the given input. It looks like ‘#step`, but it does not return an output value because it can be computed by `#output` in this class.
This is an abstract method.
: (Conf conf, In innput) -> Conf
39 40 41 |
# File 'lib/lernen/automaton/moore_like.rb', line 39 def step_conf(conf, input) raise TypeError, "abstract method: `step_conf`" end |