lernen 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +15 -0
- data/README.md +534 -48
- data/Rakefile +26 -7
- data/Steepfile +14 -0
- data/examples/ripper_prism.rb +63 -0
- data/examples/uri_parse_regexp.rb +73 -0
- data/lib/lernen/algorithm/cex_processor/acex.rb +43 -0
- data/lib/lernen/algorithm/cex_processor/prefix_transformer_acex.rb +43 -0
- data/lib/lernen/algorithm/cex_processor.rb +115 -0
- data/lib/lernen/algorithm/kearns_vazirani/discrimination_tree.rb +207 -0
- data/lib/lernen/algorithm/kearns_vazirani/kearns_vazirani_learner.rb +100 -0
- data/lib/lernen/algorithm/kearns_vazirani.rb +44 -0
- data/lib/lernen/algorithm/kearns_vazirani_vpa/discrimination_tree_vpa.rb +246 -0
- data/lib/lernen/algorithm/kearns_vazirani_vpa/kearns_vazirani_vpa_learner.rb +89 -0
- data/lib/lernen/algorithm/kearns_vazirani_vpa.rb +35 -0
- data/lib/lernen/algorithm/learner.rb +82 -0
- data/lib/lernen/algorithm/lsharp/lsharp_learner.rb +367 -0
- data/lib/lernen/algorithm/lsharp/observation_tree.rb +115 -0
- data/lib/lernen/algorithm/lsharp.rb +43 -0
- data/lib/lernen/algorithm/lstar/lstar_learner.rb +49 -0
- data/lib/lernen/algorithm/lstar/observation_table.rb +214 -0
- data/lib/lernen/algorithm/lstar.rb +49 -0
- data/lib/lernen/algorithm/procedural/atr_manager.rb +200 -0
- data/lib/lernen/algorithm/procedural/procedural_learner.rb +223 -0
- data/lib/lernen/algorithm/procedural/procedural_sul.rb +47 -0
- data/lib/lernen/algorithm/procedural/return_indices_acex.rb +58 -0
- data/lib/lernen/algorithm/procedural.rb +57 -0
- data/lib/lernen/algorithm.rb +19 -0
- data/lib/lernen/automaton/dfa.rb +204 -0
- data/lib/lernen/automaton/mealy.rb +108 -0
- data/lib/lernen/automaton/moore.rb +122 -0
- data/lib/lernen/automaton/moore_like.rb +83 -0
- data/lib/lernen/automaton/proc_util.rb +93 -0
- data/lib/lernen/automaton/spa.rb +368 -0
- data/lib/lernen/automaton/transition_system.rb +209 -0
- data/lib/lernen/automaton/vpa.rb +300 -0
- data/lib/lernen/automaton.rb +19 -493
- data/lib/lernen/equiv/combined_oracle.rb +57 -0
- data/lib/lernen/equiv/exhaustive_search_oracle.rb +60 -0
- data/lib/lernen/equiv/moore_like_simulator_oracle.rb +36 -0
- data/lib/lernen/equiv/oracle.rb +109 -0
- data/lib/lernen/equiv/random_walk_oracle.rb +69 -0
- data/lib/lernen/equiv/random_well_matched_word_oracle.rb +139 -0
- data/lib/lernen/equiv/random_word_oracle.rb +71 -0
- data/lib/lernen/equiv/spa_simulator_oracle.rb +39 -0
- data/lib/lernen/equiv/test_words_oracle.rb +42 -0
- data/lib/lernen/equiv/transition_system_simulator_oracle.rb +36 -0
- data/lib/lernen/equiv/vpa_simulator_oracle.rb +48 -0
- data/lib/lernen/equiv.rb +25 -0
- data/lib/lernen/graph.rb +215 -0
- data/lib/lernen/system/block_sul.rb +41 -0
- data/lib/lernen/system/moore_like_simulator.rb +45 -0
- data/lib/lernen/system/moore_like_sul.rb +33 -0
- data/lib/lernen/system/sul.rb +126 -0
- data/lib/lernen/system/transition_system_simulator.rb +40 -0
- data/lib/lernen/system.rb +72 -0
- data/lib/lernen/version.rb +2 -1
- data/lib/lernen.rb +284 -34
- data/rbs_collection.lock.yaml +16 -0
- data/rbs_collection.yaml +14 -0
- data/renovate.json +6 -0
- data/sig/generated/lernen/algorithm/cex_processor/acex.rbs +30 -0
- data/sig/generated/lernen/algorithm/cex_processor/prefix_transformer_acex.rbs +27 -0
- data/sig/generated/lernen/algorithm/cex_processor.rbs +59 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani/discrimination_tree.rbs +68 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani/kearns_vazirani_learner.rbs +51 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani.rbs +32 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani_vpa/discrimination_tree_vpa.rbs +73 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani_vpa/kearns_vazirani_vpa_learner.rbs +51 -0
- data/sig/generated/lernen/algorithm/kearns_vazirani_vpa.rbs +20 -0
- data/sig/generated/lernen/algorithm/learner.rbs +53 -0
- data/sig/generated/lernen/algorithm/lsharp/lsharp_learner.rbs +103 -0
- data/sig/generated/lernen/algorithm/lsharp/observation_tree.rbs +53 -0
- data/sig/generated/lernen/algorithm/lsharp.rbs +38 -0
- data/sig/generated/lernen/algorithm/lstar/lstar_learner.rbs +38 -0
- data/sig/generated/lernen/algorithm/lstar/observation_table.rbs +79 -0
- data/sig/generated/lernen/algorithm/lstar.rbs +37 -0
- data/sig/generated/lernen/algorithm/procedural/atr_manager.rbs +80 -0
- data/sig/generated/lernen/algorithm/procedural/procedural_learner.rbs +79 -0
- data/sig/generated/lernen/algorithm/procedural/procedural_sul.rbs +36 -0
- data/sig/generated/lernen/algorithm/procedural/return_indices_acex.rbs +33 -0
- data/sig/generated/lernen/algorithm/procedural.rbs +27 -0
- data/sig/generated/lernen/algorithm.rbs +10 -0
- data/sig/generated/lernen/automaton/dfa.rbs +93 -0
- data/sig/generated/lernen/automaton/mealy.rbs +61 -0
- data/sig/generated/lernen/automaton/moore.rbs +69 -0
- data/sig/generated/lernen/automaton/moore_like.rbs +63 -0
- data/sig/generated/lernen/automaton/proc_util.rbs +38 -0
- data/sig/generated/lernen/automaton/spa.rbs +125 -0
- data/sig/generated/lernen/automaton/transition_system.rbs +108 -0
- data/sig/generated/lernen/automaton/vpa.rbs +109 -0
- data/sig/generated/lernen/automaton.rbs +15 -0
- data/sig/generated/lernen/equiv/combined_oracle.rbs +27 -0
- data/sig/generated/lernen/equiv/exhaustive_search_oracle.rbs +38 -0
- data/sig/generated/lernen/equiv/moore_like_simulator_oracle.rbs +27 -0
- data/sig/generated/lernen/equiv/oracle.rbs +75 -0
- data/sig/generated/lernen/equiv/random_walk_oracle.rbs +41 -0
- data/sig/generated/lernen/equiv/random_well_matched_word_oracle.rbs +70 -0
- data/sig/generated/lernen/equiv/random_word_oracle.rbs +45 -0
- data/sig/generated/lernen/equiv/spa_simulator_oracle.rbs +30 -0
- data/sig/generated/lernen/equiv/test_words_oracle.rbs +20 -0
- data/sig/generated/lernen/equiv/transition_system_simulator_oracle.rbs +27 -0
- data/sig/generated/lernen/equiv/vpa_simulator_oracle.rbs +33 -0
- data/sig/generated/lernen/equiv.rbs +11 -0
- data/sig/generated/lernen/graph.rbs +80 -0
- data/sig/generated/lernen/system/block_sul.rbs +29 -0
- data/sig/generated/lernen/system/moore_like_simulator.rbs +31 -0
- data/sig/generated/lernen/system/moore_like_sul.rbs +28 -0
- data/sig/generated/lernen/system/sul.rbs +87 -0
- data/sig/generated/lernen/system/transition_system_simulator.rbs +28 -0
- data/sig/generated/lernen/system.rbs +62 -0
- data/sig/generated/lernen/version.rbs +6 -0
- data/sig/generated/lernen.rbs +214 -0
- data/sig-test/generated/test/example_test.rbs +14 -0
- data/sig-test/generated/test/lernen/algorithm/kearns_vazirani_test.rbs +16 -0
- data/sig-test/generated/test/lernen/algorithm/kearns_vazirani_vpa_test.rbs +10 -0
- data/sig-test/generated/test/lernen/algorithm/lsharp_test.rbs +16 -0
- data/sig-test/generated/test/lernen/algorithm/lstar_test.rbs +16 -0
- data/sig-test/generated/test/lernen/algorithm/procedural_test.rbs +10 -0
- data/sig-test/generated/test/lernen/automaton/dfa_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/mealy_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/moore_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/proc_util_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/spa_test.rbs +19 -0
- data/sig-test/generated/test/lernen/automaton/vpa_test.rbs +19 -0
- data/sig-test/generated/test/lernen/equiv/exhaustive_search_oracle_test.rbs +10 -0
- data/sig-test/generated/test/lernen/equiv/random_walk_oracle_test.rbs +10 -0
- data/sig-test/generated/test/lernen/equiv/random_word_oracle_test.rbs +10 -0
- data/sig-test/generated/test/lernen/system/block_sul_test.rbs +16 -0
- data/sig-test/generated/test/lernen/system/moore_like_simulator_test.rbs +16 -0
- data/sig-test/generated/test/lernen/system/transition_system_simulator_test.rbs +13 -0
- data/sig-test/generated/test/lernen/system_test.rbs +11 -0
- data/sig-test/generated/test/lernen_test.rbs +13 -0
- metadata +131 -11
- data/.yardopts +0 -3
- data/lib/lernen/cex_processor.rb +0 -92
- data/lib/lernen/kearns_vazirani.rb +0 -310
- data/lib/lernen/lsharp.rb +0 -344
- data/lib/lernen/lstar.rb +0 -170
- data/lib/lernen/oracle.rb +0 -119
- data/lib/lernen/sul.rb +0 -210
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/procedural/procedural_learner.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module Procedural
|
6
|
+
# ProceduralLearner is an implementation of the learning algorithm for SPA.
|
7
|
+
#
|
8
|
+
# This algorithm is described in [Frohme & Seffen (2021) "Compositional
|
9
|
+
# Learning of Mutually Recursive Procedural Systems"](https://link.springer.com/article/10.1007/s10009-021-00634-y).
|
10
|
+
#
|
11
|
+
# @rbs generic In -- Type for input alphabet
|
12
|
+
# @rbs generic Call -- Type for call alphabet
|
13
|
+
# @rbs generic Return -- Type for return alphabet
|
14
|
+
class ProceduralLearner[In, Call, Return] < Learner[In | Call | Return, bool]
|
15
|
+
@cex_processing: cex_processing_method
|
16
|
+
|
17
|
+
@algorithm_params: Hash[Symbol, untyped]
|
18
|
+
|
19
|
+
@algorithm: :lstar | :kearns_vazirani | :lsharp
|
20
|
+
|
21
|
+
@sul: System::SUL[In | Call | Return, bool]
|
22
|
+
|
23
|
+
@return_input: Return
|
24
|
+
|
25
|
+
@call_alphabet: Array[Call]
|
26
|
+
|
27
|
+
@alphabet: Array[In]
|
28
|
+
|
29
|
+
@active_call_alphabet_set: Set[Call]
|
30
|
+
|
31
|
+
@manager: ATRManager[In, Call, Return]
|
32
|
+
|
33
|
+
@proc_to_learner: Hash[Call, Learner[In | Call, bool]]
|
34
|
+
|
35
|
+
@initial_proc: Call | nil
|
36
|
+
|
37
|
+
# : (
|
38
|
+
# Array[In] alphabet,
|
39
|
+
# Array[Call] call_alphabet,
|
40
|
+
# Return return_input,
|
41
|
+
# System::SUL[In | Call | Return, bool] sul,
|
42
|
+
# ?algorithm: :lstar | :kearns_vazirani | :lsharp,
|
43
|
+
# ?algorithm_params: Hash[Symbol, untyped],
|
44
|
+
# ?cex_processing: cex_processing_method,
|
45
|
+
# ?scan_procs: bool
|
46
|
+
# ) -> void
|
47
|
+
def initialize: (Array[In] alphabet, Array[Call] call_alphabet, Return return_input, System::SUL[In | Call | Return, bool] sul, ?algorithm: :lstar | :kearns_vazirani | :lsharp, ?algorithm_params: Hash[Symbol, untyped], ?cex_processing: cex_processing_method, ?scan_procs: bool) -> void
|
48
|
+
|
49
|
+
# : () -> [Automaton::SPA[In, Call, Return], Hash[Call, Hash[Integer, Array[In | Call]]]]
|
50
|
+
def build_hypothesis: () -> [ Automaton::SPA[In, Call, Return], Hash[Call, Hash[Integer, Array[In | Call]]] ]
|
51
|
+
|
52
|
+
# : (
|
53
|
+
# Array[In | Call | Return] cex,
|
54
|
+
# Automaton::SPA[In, Call, Return] _hypothesis,
|
55
|
+
# Hash[Call, Hash[Integer, Array[In | Call]]] _proc_to_state_to_prefix
|
56
|
+
# ) -> void
|
57
|
+
def refine_hypothesis: (Array[In | Call | Return] cex, Automaton::SPA[In, Call, Return] _hypothesis, Hash[Call, Hash[Integer, Array[In | Call]]] _proc_to_state_to_prefix) -> void
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# : () -> Automaton::SPA[In, Call, Return]
|
62
|
+
def build_first_hypothesis: () -> Automaton::SPA[In, Call, Return]
|
63
|
+
|
64
|
+
# : (Array[In | Call | Return] cex) -> void
|
65
|
+
def extract_useful_information_from_cex: (Array[In | Call | Return] cex) -> void
|
66
|
+
|
67
|
+
# : (Array[In | Call | Return] cex) -> bool
|
68
|
+
def refine_hypothesis_internal: (Array[In | Call | Return] cex) -> bool
|
69
|
+
|
70
|
+
# : () -> bool
|
71
|
+
def update_atr_and_check_ts_conformance: () -> bool
|
72
|
+
|
73
|
+
def check_and_ensure_ts_conformance: (untyped hypothesis, untyped proc_to_state_to_prefix) -> untyped
|
74
|
+
|
75
|
+
def check_and_ensure_single_ts_conformance: (untyped ts, untyped hypothesis, untyped proc_to_state_to_prefix) -> untyped
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/procedural/procedural_sul.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module Procedural
|
6
|
+
# ProceduralSUL is a wrapper of SUL for procedural learning.
|
7
|
+
#
|
8
|
+
# @rbs generic In -- Type for input alphabet
|
9
|
+
# @rbs generic Call -- Type for call alphabet
|
10
|
+
# @rbs generic Return -- Type for return alphabet
|
11
|
+
class ProceduralSUL[In, Call, Return] < System::MooreLikeSUL[In | Call, bool]
|
12
|
+
@proc: Call
|
13
|
+
|
14
|
+
@sul: System::SUL[In | Call | Return, bool]
|
15
|
+
|
16
|
+
@manager: ATRManager[In, Call, Return]
|
17
|
+
|
18
|
+
# : (
|
19
|
+
# Call proc,
|
20
|
+
# System::SUL[In | Call | Return, bool] sul,
|
21
|
+
# ATRManager[In, Call, Return] manager
|
22
|
+
# ) -> void
|
23
|
+
def initialize: (Call proc, System::SUL[In | Call | Return, bool] sul, ATRManager[In, Call, Return] manager) -> void
|
24
|
+
|
25
|
+
# @rbs override
|
26
|
+
def query_empty: ...
|
27
|
+
|
28
|
+
# @rbs override
|
29
|
+
def query: ...
|
30
|
+
|
31
|
+
# @rbs override
|
32
|
+
def step: ...
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/procedural/return_indices_acex.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
module Procedural
|
6
|
+
# ReturnIndicesAcex is an acex implementation for finding the return index in procedural learning.
|
7
|
+
#
|
8
|
+
# @rbs generic In -- Type for input alphabet
|
9
|
+
# @rbs generic Call -- Type for call alphabet
|
10
|
+
# @rbs generic Return -- Type for return alphabet
|
11
|
+
class ReturnIndicesAcex[In, Call, Return] < CexProcessor::Acex
|
12
|
+
@cex: Array[In | Call | Return]
|
13
|
+
|
14
|
+
@return_indices: Array[Integer]
|
15
|
+
|
16
|
+
@query: ^(Array[In | Call | Return]) -> bool
|
17
|
+
|
18
|
+
@manager: ATRManager[In, Call, Return]
|
19
|
+
|
20
|
+
# : (
|
21
|
+
# Array[In | Call | Return] cex,
|
22
|
+
# Array[Integer] return_indices,
|
23
|
+
# ^(Array[In | Call | Return]) -> bool query,
|
24
|
+
# ATRManager[In, Call, Return] manager
|
25
|
+
# ) -> void
|
26
|
+
def initialize: (Array[In | Call | Return] cex, Array[Integer] return_indices, ^(Array[In | Call | Return]) -> bool query, ATRManager[In, Call, Return] manager) -> void
|
27
|
+
|
28
|
+
# @rbs override
|
29
|
+
def compute_effect: ...
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm/procedural.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Algorithm
|
5
|
+
# Procedural provides an implementation of the learning algorithm for SPA.
|
6
|
+
#
|
7
|
+
# This algorithm is described in [Frohme & Seffen (2021) "Compositional
|
8
|
+
# Learning of Mutually Recursive Procedural Systems"](https://link.springer.com/article/10.1007/s10009-021-00634-y).
|
9
|
+
module Procedural
|
10
|
+
# Runs the procedural algorithm and returns an inferred SPA.
|
11
|
+
#
|
12
|
+
# : [In, Call, Return] (
|
13
|
+
# Array[In] alphabet,
|
14
|
+
# Array[Call] call_alphabet,
|
15
|
+
# Return return_input,
|
16
|
+
# System::SUL[In | Call | Return, bool] sul,
|
17
|
+
# Equiv::Oracle[In | Call | Return, bool] oracle,
|
18
|
+
# ?algorithm: :lstar | :kearns_vazirani | :lsharp,
|
19
|
+
# ?algorithm_params: Hash[Symbol, untyped],
|
20
|
+
# ?cex_processing: cex_processing_method,
|
21
|
+
# ?scan_procs: bool,
|
22
|
+
# ?max_learning_rounds: Integer | nil
|
23
|
+
# ) -> Automaton::SPA[In, Call, Return]
|
24
|
+
def self.learn: [In, Call, Return] (Array[In] alphabet, Array[Call] call_alphabet, Return return_input, System::SUL[In | Call | Return, bool] sul, Equiv::Oracle[In | Call | Return, bool] oracle, ?algorithm: :lstar | :kearns_vazirani | :lsharp, ?algorithm_params: Hash[Symbol, untyped], ?cex_processing: cex_processing_method, ?scan_procs: bool, ?max_learning_rounds: Integer | nil) -> Automaton::SPA[In, Call, Return]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# Generated from lib/lernen/algorithm.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
# This is a namespace for learning algorithm implementations.
|
5
|
+
#
|
6
|
+
# This namespace also contains data structures and utilities for
|
7
|
+
# learning algorithms.
|
8
|
+
module Algorithm
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# Generated from lib/lernen/automaton/dfa.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Automaton
|
5
|
+
# DFA represents a [deterministic finite-state automaton](https://en.wikipedia.org/wiki/Deterministic_finite_automaton).
|
6
|
+
#
|
7
|
+
# @rbs generic In -- Type for input alphabet
|
8
|
+
class DFA[In] < MooreLike[Integer, In, bool]
|
9
|
+
@transition_function: Hash[[ Integer, In ], Integer]
|
10
|
+
|
11
|
+
@accept_state_set: Set[Integer]
|
12
|
+
|
13
|
+
@initial_state: Integer
|
14
|
+
|
15
|
+
# : (
|
16
|
+
# Integer initial_state,
|
17
|
+
# Set[Integer] accept_state_set,
|
18
|
+
# Hash[[Integer, In], Integer] transition_function
|
19
|
+
# ) -> void
|
20
|
+
def initialize: (Integer initial_state, Set[Integer] accept_state_set, Hash[[ Integer, In ], Integer] transition_function) -> void
|
21
|
+
|
22
|
+
attr_reader initial_state: Integer
|
23
|
+
|
24
|
+
attr_reader accept_state_set: Set[Integer]
|
25
|
+
|
26
|
+
attr_reader transition_function: Hash[[ Integer, In ], Integer]
|
27
|
+
|
28
|
+
# : () -> :dfa
|
29
|
+
def type: () -> :dfa
|
30
|
+
|
31
|
+
# @rbs override
|
32
|
+
def initial_conf: ...
|
33
|
+
|
34
|
+
# @rbs override
|
35
|
+
def step_conf: ...
|
36
|
+
|
37
|
+
# @rbs override
|
38
|
+
def output: ...
|
39
|
+
|
40
|
+
# Checks the structural equality between `self` and `other`.
|
41
|
+
#
|
42
|
+
# : (untyped other) -> bool
|
43
|
+
def ==: (untyped other) -> bool
|
44
|
+
|
45
|
+
# Returns the array of states of this DFA.
|
46
|
+
#
|
47
|
+
# The result array is sorted.
|
48
|
+
#
|
49
|
+
# : () -> Array[Integer]
|
50
|
+
def states: () -> Array[Integer]
|
51
|
+
|
52
|
+
# Returns the error state of this DFA.
|
53
|
+
#
|
54
|
+
# An error state is:
|
55
|
+
#
|
56
|
+
# - neither a initial state nor accepting states, and
|
57
|
+
# - only having self-loops for all `input`.
|
58
|
+
#
|
59
|
+
# If an error state is not found, it returns `nil`.
|
60
|
+
#
|
61
|
+
# : () -> (Integer | nil)
|
62
|
+
def error_state: () -> (Integer | nil)
|
63
|
+
|
64
|
+
# Returns the shortest word accepted by this DFA.
|
65
|
+
#
|
66
|
+
# If it is not found, it returns `nil`.
|
67
|
+
#
|
68
|
+
# : (Array[In] alphabet) -> (Array[In] | nil)
|
69
|
+
def shortest_accept_word: (Array[In] alphabet) -> (Array[In] | nil)
|
70
|
+
|
71
|
+
# Computes the shortest paths between states.
|
72
|
+
#
|
73
|
+
# : (Array[In] alphabet) -> Hash[[Integer, Integer], Array[In]]
|
74
|
+
def compute_shortest_words: (Array[In] alphabet) -> Hash[[ Integer, Integer ], Array[In]]
|
75
|
+
|
76
|
+
# Returns a graph of this DFA.
|
77
|
+
#
|
78
|
+
# (?shows_error_state: bool) -> Graph
|
79
|
+
def to_graph: (?shows_error_state: untyped) -> untyped
|
80
|
+
|
81
|
+
# Generates a DFA randomly.
|
82
|
+
#
|
83
|
+
# : [In] (
|
84
|
+
# alphabet: Array[In],
|
85
|
+
# ?min_state_size: Integer,
|
86
|
+
# ?max_state_size: Integer,
|
87
|
+
# ?accept_state_size: Integer,
|
88
|
+
# ?random: Random,
|
89
|
+
# ) -> DFA[In]
|
90
|
+
def self.random: [In] (alphabet: Array[In], ?min_state_size: Integer, ?max_state_size: Integer, ?accept_state_size: Integer, ?random: Random) -> DFA[In]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated from lib/lernen/automaton/mealy.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Automaton
|
5
|
+
# Mealy represents a [Mealy machine](https://en.wikipedia.org/wiki/Mealy_machine).
|
6
|
+
#
|
7
|
+
# @rbs generic In -- Type for input alphabet
|
8
|
+
# @rbs generic Out -- Type for output values
|
9
|
+
class Mealy[In, Out] < TransitionSystem[Integer, In, Out]
|
10
|
+
@initial_state: Integer
|
11
|
+
|
12
|
+
@transition_function: Hash[[ Integer, In ], [ Out, Integer ]]
|
13
|
+
|
14
|
+
# : (
|
15
|
+
# Integer initial_state,
|
16
|
+
# Hash[[Integer, In], [Out, Integer]] transition_function
|
17
|
+
# ) -> void
|
18
|
+
def initialize: (Integer initial_state, Hash[[ Integer, In ], [ Out, Integer ]] transition_function) -> void
|
19
|
+
|
20
|
+
attr_reader initial_state: Integer
|
21
|
+
|
22
|
+
attr_reader transition_function: Hash[[ Integer, In ], [ Out, Integer ]]
|
23
|
+
|
24
|
+
# : () -> :mealy
|
25
|
+
def type: () -> :mealy
|
26
|
+
|
27
|
+
# @rbs override
|
28
|
+
def initial_conf: ...
|
29
|
+
|
30
|
+
# @rbs override
|
31
|
+
def step: ...
|
32
|
+
|
33
|
+
# Checks the structural equality between `self` and `other`.
|
34
|
+
#
|
35
|
+
# : (untyped other) -> bool
|
36
|
+
def ==: (untyped other) -> bool
|
37
|
+
|
38
|
+
# Returns the array of states of this Mealy machine.
|
39
|
+
#
|
40
|
+
# The result array is sorted.
|
41
|
+
#
|
42
|
+
# : () -> Array[Integer]
|
43
|
+
def states: () -> Array[Integer]
|
44
|
+
|
45
|
+
# @rbs override
|
46
|
+
def to_graph: ...
|
47
|
+
|
48
|
+
# Generates a Mealy machine randomly.
|
49
|
+
#
|
50
|
+
# : [In, Out] (
|
51
|
+
# alphabet: Array[In],
|
52
|
+
# output_alphabet: Array[Out],
|
53
|
+
# ?min_state_size: Integer,
|
54
|
+
# ?max_state_size: Integer,
|
55
|
+
# ?num_reachable_paths: Integer,
|
56
|
+
# ?random: Random,
|
57
|
+
# ) -> Mealy[In, Out]
|
58
|
+
def self.random: [In, Out] (alphabet: Array[In], output_alphabet: Array[Out], ?min_state_size: Integer, ?max_state_size: Integer, ?num_reachable_paths: Integer, ?random: Random) -> Mealy[In, Out]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated from lib/lernen/automaton/moore.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Automaton
|
5
|
+
# Moore represents a [Moore machine](https://en.wikipedia.org/wiki/Moore_machine).
|
6
|
+
#
|
7
|
+
# @rbs generic In -- Type for input alphabet
|
8
|
+
# @rbs generic Out -- Type for output values
|
9
|
+
class Moore[In, Out] < MooreLike[Integer, In, Out]
|
10
|
+
@transition_function: Hash[[ Integer, In ], Integer]
|
11
|
+
|
12
|
+
@output_function: Hash[Integer, Out]
|
13
|
+
|
14
|
+
@initial_state: Integer
|
15
|
+
|
16
|
+
# : (
|
17
|
+
# Integer initial_state,
|
18
|
+
# Hash[Integer, Out] output_function,
|
19
|
+
# Hash[[Integer, In], Integer] transition_function,
|
20
|
+
# ) -> void
|
21
|
+
def initialize: (Integer initial_state, Hash[Integer, Out] output_function, Hash[[ Integer, In ], Integer] transition_function) -> void
|
22
|
+
|
23
|
+
attr_reader initial_state: Integer
|
24
|
+
|
25
|
+
attr_reader output_function: Hash[Integer, Out]
|
26
|
+
|
27
|
+
attr_reader transition_function: Hash[[ Integer, In ], Integer]
|
28
|
+
|
29
|
+
# : () -> :moore
|
30
|
+
def type: () -> :moore
|
31
|
+
|
32
|
+
# @rbs override
|
33
|
+
def initial_conf: ...
|
34
|
+
|
35
|
+
# @rbs override
|
36
|
+
def step_conf: ...
|
37
|
+
|
38
|
+
# @rbs override
|
39
|
+
def output: ...
|
40
|
+
|
41
|
+
# Checks the structural equality between `self` and `other`.
|
42
|
+
#
|
43
|
+
# : (untyped other) -> bool
|
44
|
+
def ==: (untyped other) -> bool
|
45
|
+
|
46
|
+
# Returns the array of states of this Moore machine.
|
47
|
+
#
|
48
|
+
# The result array is sorted.
|
49
|
+
#
|
50
|
+
# : () -> Array[Integer]
|
51
|
+
def states: () -> Array[Integer]
|
52
|
+
|
53
|
+
# @rbs override
|
54
|
+
def to_graph: ...
|
55
|
+
|
56
|
+
# Generates a Moore machine randomly.
|
57
|
+
#
|
58
|
+
# : [In, Out] (
|
59
|
+
# alphabet: Array[In],
|
60
|
+
# output_alphabet: Array[Out],
|
61
|
+
# ?min_state_size: Integer,
|
62
|
+
# ?max_state_size: Integer,
|
63
|
+
# ?num_reachable_paths: Integer,
|
64
|
+
# ?random: Random,
|
65
|
+
# ) -> Moore[In, Out]
|
66
|
+
def self.random: [In, Out] (alphabet: Array[In], output_alphabet: Array[Out], ?min_state_size: Integer, ?max_state_size: Integer, ?num_reachable_paths: Integer, ?random: Random) -> Moore[In, Out]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated from lib/lernen/automaton/moore_like.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Automaton
|
5
|
+
# MooreLike represents a Moore-like transition system.
|
6
|
+
#
|
7
|
+
# This transition system has an output value for each configuration (or state).
|
8
|
+
# Therefore, the following invariant is required for all `conf` and `input`.
|
9
|
+
#
|
10
|
+
# ```ruby
|
11
|
+
# step_output, next_conf = self.step(conf, input)
|
12
|
+
# step_output == self.output(next_conf)
|
13
|
+
# ```
|
14
|
+
#
|
15
|
+
# Note that in this class, the initial output of the `#run` method is lost.
|
16
|
+
# If it is needed, we can use `#run_empty` instead.
|
17
|
+
#
|
18
|
+
# Note that this class is *abstract*. We should implement the following method:
|
19
|
+
#
|
20
|
+
# - `#type`
|
21
|
+
# - `#initial_conf`
|
22
|
+
# - `#step_conf(conf, input)`
|
23
|
+
# - `#output(conf)`
|
24
|
+
#
|
25
|
+
# @rbs generic Conf -- Type for a configuration of this automaton
|
26
|
+
# @rbs generic In -- Type for input alphabet
|
27
|
+
# @rbs generic Out -- Type for output values
|
28
|
+
class MooreLike[Conf, In, Out] < TransitionSystem[Conf, In, Out]
|
29
|
+
# Runs a transition from the given configuration with the given input.
|
30
|
+
# It looks like `#step`, but it does not return an output value because
|
31
|
+
# it can be computed by `#output` in this class.
|
32
|
+
#
|
33
|
+
# This is an abstract method.
|
34
|
+
#
|
35
|
+
# : (Conf conf, In innput) -> Conf
|
36
|
+
def step_conf: (Conf conf, In innput) -> Conf
|
37
|
+
|
38
|
+
# Returns the output value for the given configuration.
|
39
|
+
#
|
40
|
+
# This is an abstract method.
|
41
|
+
#
|
42
|
+
# : (Conf conf) -> Out
|
43
|
+
def output: (Conf conf) -> Out
|
44
|
+
|
45
|
+
# @rbs override
|
46
|
+
def step: ...
|
47
|
+
|
48
|
+
# Runs and returns the output value of the transitions for the empty string.
|
49
|
+
#
|
50
|
+
# : () -> Out
|
51
|
+
def run_empty: () -> Out
|
52
|
+
|
53
|
+
# Finds a separating word between `automaton1` and `automaton2`.
|
54
|
+
#
|
55
|
+
# : [Conf, In, Out] (
|
56
|
+
# Array[In] alphabet,
|
57
|
+
# MooreLike[Conf, In, Out] automaton1,
|
58
|
+
# MooreLike[Conf, In, Out] automaton2
|
59
|
+
# ) -> (Array[In] | nil)
|
60
|
+
def self.find_separating_word: [Conf, In, Out] (Array[In] alphabet, MooreLike[Conf, In, Out] automaton1, MooreLike[Conf, In, Out] automaton2) -> (Array[In] | nil)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Generated from lib/lernen/automaton/proc_util.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Automaton
|
5
|
+
# ProcUtil provides utility functions for words in `SPA`.
|
6
|
+
module ProcUtil
|
7
|
+
# : [In, Call, Return] (
|
8
|
+
# Return return_input,
|
9
|
+
# Array[In | Call] word,
|
10
|
+
# Hash[Call, Array[In | Call | Return]] proc_to_terminating_sequence,
|
11
|
+
# ) -> Array[In | Call | Return]
|
12
|
+
def self.expand: [In, Call, Return] (Return return_input, Array[In | Call] word, Hash[Call, Array[In | Call | Return]] proc_to_terminating_sequence) -> Array[In | Call | Return]
|
13
|
+
|
14
|
+
# : [In, Call, Return] (
|
15
|
+
# Set[Call] call_alphabet_set,
|
16
|
+
# Return return_input,
|
17
|
+
# Array[In | Call | Return] word
|
18
|
+
# ) -> Array[In | Call]
|
19
|
+
def self.project: [In, Call, Return] (Set[Call] call_alphabet_set, Return return_input, Array[In | Call | Return] word) -> Array[In | Call]
|
20
|
+
|
21
|
+
# : [In, Call, Return] (
|
22
|
+
# Set[Call] call_alphabet_set,
|
23
|
+
# Return return_input,
|
24
|
+
# Array[In | Call | Return] word,
|
25
|
+
# Integer index
|
26
|
+
# ) -> (Integer | nil)
|
27
|
+
def self.find_call_index: [In, Call, Return] (Set[Call] call_alphabet_set, Return return_input, Array[In | Call | Return] word, Integer index) -> (Integer | nil)
|
28
|
+
|
29
|
+
# : [In, Call, Return] (
|
30
|
+
# Set[Call] call_alphabet_set,
|
31
|
+
# Return return_input,
|
32
|
+
# Array[In | Call | Return] word,
|
33
|
+
# Integer index
|
34
|
+
# ) -> (Integer | nil)
|
35
|
+
def self.find_return_index: [In, Call, Return] (Set[Call] call_alphabet_set, Return return_input, Array[In | Call | Return] word, Integer index) -> (Integer | nil)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
# Generated from lib/lernen/automaton/spa.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Automaton
|
5
|
+
# SPA represents a system of procedural automata.
|
6
|
+
#
|
7
|
+
# Note that this class takes `return_input` as the return symbol because
|
8
|
+
# this value is necessary to run this kind of automata correctly.
|
9
|
+
#
|
10
|
+
# @rbs generic In -- Type for input alphabet
|
11
|
+
# @rbs generic Call -- Type for call alphabet
|
12
|
+
# @rbs generic Return -- Type for return alphabet
|
13
|
+
class SPA[In, Call, Return] < MooreLike[SPA::conf[Call], In | Call | Return, bool]
|
14
|
+
class Conf[Call] < Data
|
15
|
+
attr_reader prev: conf[Call]
|
16
|
+
attr_reader proc: Call
|
17
|
+
attr_reader state: Integer
|
18
|
+
def self.[]: [Call] (conf[Call] prev, Call proc, Integer state) -> Conf[Call]
|
19
|
+
end
|
20
|
+
|
21
|
+
type conf[Call] = Conf[Call] | :init | :term | :sink
|
22
|
+
|
23
|
+
@proc_to_dfa: Hash[Call, DFA[In | Call]]
|
24
|
+
|
25
|
+
@initial_proc: Call
|
26
|
+
|
27
|
+
# : (
|
28
|
+
# Call initial_proc,
|
29
|
+
# Return return_input,
|
30
|
+
# Hash[Call, DFA[In | Call]] proc_to_dfa
|
31
|
+
# ) -> void
|
32
|
+
def initialize: (Call initial_proc, Return return_input, Hash[Call, DFA[In | Call]] proc_to_dfa) -> void
|
33
|
+
|
34
|
+
attr_reader initial_proc: Call
|
35
|
+
|
36
|
+
attr_reader return_input: Return
|
37
|
+
|
38
|
+
attr_reader proc_to_dfa: Hash[Call, DFA[In | Call]]
|
39
|
+
|
40
|
+
# : () -> :spa
|
41
|
+
def type: () -> :spa
|
42
|
+
|
43
|
+
# @rbs override
|
44
|
+
def initial_conf: ...
|
45
|
+
|
46
|
+
# @rbs override
|
47
|
+
def step_conf: ...
|
48
|
+
|
49
|
+
# @rbs override
|
50
|
+
def output: ...
|
51
|
+
|
52
|
+
# Checks the structural equality between `self` and `other`.
|
53
|
+
#
|
54
|
+
# : (untyped other) -> bool
|
55
|
+
def ==: (untyped other) -> bool
|
56
|
+
|
57
|
+
# @rbs override
|
58
|
+
def to_graph: ...
|
59
|
+
|
60
|
+
# Returns the mapping from procedure names to access/terminating/return sequences.
|
61
|
+
#
|
62
|
+
# : (
|
63
|
+
# Array[In] alphabet,
|
64
|
+
# Array[Call] call_alphabet
|
65
|
+
# ) -> [
|
66
|
+
# Hash[Call, Array[In | Call | Return]],
|
67
|
+
# Hash[Call, Array[In | Call | Return]],
|
68
|
+
# Hash[Call, Array[In | Call | Return]]
|
69
|
+
# ]
|
70
|
+
def proc_to_atr_sequence: (Array[In] alphabet, Array[Call] call_alphabet) -> [ Hash[Call, Array[In | Call | Return]], Hash[Call, Array[In | Call | Return]], Hash[Call, Array[In | Call | Return]] ]
|
71
|
+
|
72
|
+
# Finds a separating word between `spa1` and `spa2`.
|
73
|
+
#
|
74
|
+
# This method assume return symbols for two SPAs are the same.
|
75
|
+
# If they are not, this raises `ArgumentError`.
|
76
|
+
#
|
77
|
+
# : [In, Call, Return] (
|
78
|
+
# Array[In] alphabet,
|
79
|
+
# Array[Call] call_alphabet,
|
80
|
+
# SPA[In, Call, Return] spa1,
|
81
|
+
# SPA[In, Call, Return] spa2
|
82
|
+
# ) -> (Array[In | Call | Return] | nil)
|
83
|
+
def self.find_separating_word: [In, Call, Return] (Array[In] alphabet, Array[Call] call_alphabet, SPA[In, Call, Return] spa1, SPA[In, Call, Return] spa2) -> (Array[In | Call | Return] | nil)
|
84
|
+
|
85
|
+
# Generates a SPA randomly.
|
86
|
+
#
|
87
|
+
# : [In, Call, Return] (
|
88
|
+
# alphabet: Array[In],
|
89
|
+
# call_alphabet: Array[Call],
|
90
|
+
# return_input: Return,
|
91
|
+
# ?min_proc_size: Integer,
|
92
|
+
# ?max_proc_size: Integer,
|
93
|
+
# ?dfa_min_state_size: Integer,
|
94
|
+
# ?dfa_max_state_size: Integer,
|
95
|
+
# ?dfa_accept_state_size: Integer,
|
96
|
+
# ?random: Random,
|
97
|
+
# ) -> SPA[In, Call, Return]
|
98
|
+
def self.random: [In, Call, Return] (alphabet: Array[In], call_alphabet: Array[Call], return_input: Return, ?min_proc_size: Integer, ?max_proc_size: Integer, ?dfa_min_state_size: Integer, ?dfa_max_state_size: Integer, ?dfa_accept_state_size: Integer, ?random: Random) -> SPA[In, Call, Return]
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
# Returns the mapping from procedure names to terminating sequences.
|
103
|
+
#
|
104
|
+
# : (Array[In] alphabet, Array[Call] call_alphabet) -> Hash[Call, Array[In | Call | Return]]
|
105
|
+
def compute_proc_to_terminating_sequence: (Array[In] alphabet, Array[Call] call_alphabet) -> Hash[Call, Array[In | Call | Return]]
|
106
|
+
|
107
|
+
# Returns the mapping from procedure names to access and return sequences.
|
108
|
+
#
|
109
|
+
# : (
|
110
|
+
# Array[In] alphabet,
|
111
|
+
# Array[Call] call_alphabet,
|
112
|
+
# Hash[Call, Array[In | Call | Return]] proc_to_terminating_sequence
|
113
|
+
# ) -> [Hash[Call, Array[In | Call | Return]], Hash[Call, Array[In | Call | Return]]]
|
114
|
+
def compute_proc_to_access_and_return_sequences: (Array[In] alphabet, Array[Call] call_alphabet, Hash[Call, Array[In | Call | Return]] proc_to_terminating_sequence) -> [ Hash[Call, Array[In | Call | Return]], Hash[Call, Array[In | Call | Return]] ]
|
115
|
+
|
116
|
+
# : (
|
117
|
+
# DFA[In | Call] dfa,
|
118
|
+
# Array[In] alphabet,
|
119
|
+
# Array[Call] found_call_alphabet,
|
120
|
+
# Set[Call] unfound_call_alphabet_set
|
121
|
+
# ) -> Hash[Call, [Array[In | Call], Array[In | Call]]]
|
122
|
+
def explore_proc_to_access_and_return_word: (DFA[In | Call] dfa, Array[In] alphabet, Array[Call] found_call_alphabet, Set[Call] unfound_call_alphabet_set) -> Hash[Call, [ Array[In | Call], Array[In | Call] ]]
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|