lernen 0.1.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 +18 -0
- data/README.md +531 -28
- data/Rakefile +29 -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 -92
- 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 +322 -13
- 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 -61
- data/lib/lernen/kearns_vazirani.rb +0 -199
- data/lib/lernen/lsharp.rb +0 -335
- data/lib/lernen/lstar.rb +0 -169
- data/lib/lernen/oracle.rb +0 -116
- data/lib/lernen/sul.rb +0 -134
@@ -0,0 +1,108 @@
|
|
1
|
+
# Generated from lib/lernen/automaton/transition_system.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Automaton
|
5
|
+
# TransitionSystem represents a labelled transition system.
|
6
|
+
#
|
7
|
+
# We assume that this transition system is *deterministic* and *complete*;
|
8
|
+
# thus, the transition function should be defined for all states and input
|
9
|
+
# characters, and the destination configuration of a transition should be one.
|
10
|
+
#
|
11
|
+
# Also, this transition system has an output value for each transition. From
|
12
|
+
# this point of view, this definition is much like Mealy machines. However,
|
13
|
+
# this class is more generic. Actually, this is a superclass of Moore machines,
|
14
|
+
# DFA, etc.
|
15
|
+
#
|
16
|
+
# Note that this class is *abstract*. We should implement the following method:
|
17
|
+
#
|
18
|
+
# - `#type`
|
19
|
+
# - `#initial_conf`
|
20
|
+
# - `#step(conf, input)`
|
21
|
+
# - `#to_graph`
|
22
|
+
#
|
23
|
+
# @rbs generic Conf -- Type for a configuration of this automaton
|
24
|
+
# @rbs generic In -- Type for input alphabet
|
25
|
+
# @rbs generic Out -- Type for output values
|
26
|
+
class TransitionSystem[Conf, In, Out]
|
27
|
+
# Returns the automaton type.
|
28
|
+
#
|
29
|
+
# This is an abstract method.
|
30
|
+
#
|
31
|
+
# : () -> transition_system_type
|
32
|
+
def type: () -> transition_system_type
|
33
|
+
|
34
|
+
# Returns the initial configuration.
|
35
|
+
#
|
36
|
+
# This is an abstract method.
|
37
|
+
#
|
38
|
+
# : () -> Conf
|
39
|
+
def initial_conf: () -> Conf
|
40
|
+
|
41
|
+
# Runs a transition from the given configuration with the given input.
|
42
|
+
#
|
43
|
+
# It returns a pair of the output value and the next configuration of
|
44
|
+
# this transition.
|
45
|
+
#
|
46
|
+
# This is an abstract method.
|
47
|
+
#
|
48
|
+
# : (Conf conf, In input) -> [Out, Conf]
|
49
|
+
def step: (Conf conf, In input) -> [ Out, Conf ]
|
50
|
+
|
51
|
+
# Returns a graph of this transition system.
|
52
|
+
#
|
53
|
+
# This is an abstract method.
|
54
|
+
#
|
55
|
+
# : () -> Graph
|
56
|
+
def to_graph: () -> Graph
|
57
|
+
|
58
|
+
# Runs transitions from the initial configuration with the given word.
|
59
|
+
#
|
60
|
+
# It returns a pair of the output values and the final configuration of
|
61
|
+
# the transitions.
|
62
|
+
#
|
63
|
+
# : (Array[In] word) -> [Array[Out], Conf]
|
64
|
+
def run: (Array[In] word) -> [ Array[Out], Conf ]
|
65
|
+
|
66
|
+
# Returns a [Mermaid](https://mermaid.js.org) diagram of this transition system.
|
67
|
+
#
|
68
|
+
# : (?direction: Graph::mermaid_direction) -> String
|
69
|
+
def to_mermaid: (?direction: Graph::mermaid_direction) -> String
|
70
|
+
|
71
|
+
# Returns a [GraphViz](https://graphviz.org) DOT diagram of this transition system.
|
72
|
+
#
|
73
|
+
# : () -> String
|
74
|
+
def to_dot: () -> String
|
75
|
+
|
76
|
+
# Finds a separating word between `automaton1` and `automaton2`.
|
77
|
+
#
|
78
|
+
# : [Conf, In, Out] (
|
79
|
+
# Array[In] alphabet,
|
80
|
+
# TransitionSystem[Conf, In, Out] automaton1,
|
81
|
+
# TransitionSystem[Conf, In, Out] automaton2
|
82
|
+
# ) -> (Array[In] | nil)
|
83
|
+
def self.find_separating_word: [Conf, In, Out] (Array[In] alphabet, TransitionSystem[Conf, In, Out] automaton1, TransitionSystem[Conf, In, Out] automaton2) -> (Array[In] | nil)
|
84
|
+
|
85
|
+
# Generates a transition function randomly.
|
86
|
+
#
|
87
|
+
# To make a transition function connected, this method generates
|
88
|
+
# a transition function in the following mannar.
|
89
|
+
#
|
90
|
+
# 1. Decide a number of states within `min_state_size..max_state_size` randomly.
|
91
|
+
# 2. Divides the states into `num_reachable_paths` partitions.
|
92
|
+
# 3. Generate a path from the initial state for each paratition.
|
93
|
+
# 4. Generate transition for all `state` and `input`.
|
94
|
+
#
|
95
|
+
# This method returns a pair of a transition function and an array of reachable paths.
|
96
|
+
# The initial state of the result transition function is `0`.
|
97
|
+
#
|
98
|
+
# : [In] (
|
99
|
+
# alphabet: Array[In],
|
100
|
+
# ?min_state_size: Integer,
|
101
|
+
# ?max_state_size: Integer,
|
102
|
+
# ?num_reachable_paths: Integer,
|
103
|
+
# ?random: Random,
|
104
|
+
# ) -> [Hash[[Integer, In], Integer], Array[Array[Integer]]]
|
105
|
+
def self.random_transition_function: [In] (alphabet: Array[In], ?min_state_size: Integer, ?max_state_size: Integer, ?num_reachable_paths: Integer, ?random: Random) -> [ Hash[[ Integer, In ], Integer], Array[Array[Integer]] ]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# Generated from lib/lernen/automaton/vpa.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Automaton
|
5
|
+
# VPA represents a [visily pushdown automaton](https://en.wikipedia.org/wiki/Nested_word#Visibly_pushdown_automaton).
|
6
|
+
#
|
7
|
+
# Especially, this definition represents 1-SEVPA (1-module single-entry visibly pushdown automaton).
|
8
|
+
#
|
9
|
+
# @rbs generic In -- Type for input alphabet
|
10
|
+
# @rbs generic Call -- Type for call alphabet
|
11
|
+
# @rbs generic Return -- Type for return alphabet
|
12
|
+
class VPA[In, Call, Return] < MooreLike[VPA::Conf[Call] | nil, In | Call | Return, bool]
|
13
|
+
class Conf[Call] < Data
|
14
|
+
attr_reader state: Integer
|
15
|
+
attr_reader stack: Array[[ Integer, Call ]]
|
16
|
+
def self.[]: [Call] (Integer state, Array[[ Integer, Call ]] stack) -> Conf[Call]
|
17
|
+
end
|
18
|
+
|
19
|
+
@return_transition_function: Hash[[ Integer, Return ], Hash[[ Integer, Call ], Integer]]
|
20
|
+
|
21
|
+
@transition_function: Hash[[ Integer, In ], Integer]
|
22
|
+
|
23
|
+
@accept_state_set: Set[Integer]
|
24
|
+
|
25
|
+
@initial_state: Integer
|
26
|
+
|
27
|
+
# : (
|
28
|
+
# Integer initial_state,
|
29
|
+
# Set[Integer] accept_state_set,
|
30
|
+
# Hash[[Integer, In], Integer] transition_function.
|
31
|
+
# Hash[[Integer, Return], Hash[[Integer, Call], Integer]] return_transition_function
|
32
|
+
# ) -> void
|
33
|
+
def initialize: (untyped initial_state, untyped accept_state_set, untyped transition_function, untyped return_transition_function) -> untyped
|
34
|
+
|
35
|
+
attr_reader initial_state: Integer
|
36
|
+
|
37
|
+
attr_reader accept_state_set: Set[Integer]
|
38
|
+
|
39
|
+
attr_reader transition_function: Hash[[ Integer, In ], Integer]
|
40
|
+
|
41
|
+
attr_reader return_transition_function: Hash[[ Integer, Return ], Hash[[ Integer, Call ], Integer]]
|
42
|
+
|
43
|
+
# @rbs return: :vpa
|
44
|
+
def type: () -> :vpa
|
45
|
+
|
46
|
+
# @rbs override
|
47
|
+
def initial_conf: ...
|
48
|
+
|
49
|
+
# @rbs override
|
50
|
+
def step_conf: ...
|
51
|
+
|
52
|
+
# @rbs override
|
53
|
+
def output: ...
|
54
|
+
|
55
|
+
# Checks the structural equality between `self` and `other`.
|
56
|
+
#
|
57
|
+
# : (untyped other) -> bool
|
58
|
+
def ==: (untyped other) -> bool
|
59
|
+
|
60
|
+
# Returns the array of states of this VPA.
|
61
|
+
#
|
62
|
+
# The result array is sorted.
|
63
|
+
#
|
64
|
+
# : () -> Array[Integer]
|
65
|
+
def states: () -> Array[Integer]
|
66
|
+
|
67
|
+
# Returns the error state of this VPA.
|
68
|
+
#
|
69
|
+
# An error state is:
|
70
|
+
#
|
71
|
+
# - neither a initial state nor accepting states, and
|
72
|
+
# - only having self-loops for all `input`.
|
73
|
+
#
|
74
|
+
# If an error state is not found, it returns `nil`.
|
75
|
+
#
|
76
|
+
# : () -> (Integer | nil)
|
77
|
+
def error_state: () -> (Integer | nil)
|
78
|
+
|
79
|
+
# Returns a graph of this VPA.
|
80
|
+
#
|
81
|
+
# (?shows_error_state: bool) -> Graph
|
82
|
+
def to_graph: (?shows_error_state: untyped) -> untyped
|
83
|
+
|
84
|
+
# Finds a separating word between `vpa1` and `vpa2`.
|
85
|
+
#
|
86
|
+
# : [In, Call, Return] (
|
87
|
+
# Array[In] alphabet,
|
88
|
+
# Array[Call] call_alphabet,
|
89
|
+
# Array[Return] return_alphabet,
|
90
|
+
# VPA[In, Call, Return] vpa1,
|
91
|
+
# VPA[In, Call, Return] vpa2
|
92
|
+
# ) -> (Array[In | Call | Return] | nil)
|
93
|
+
def self.find_separating_word: [In, Call, Return] (Array[In] alphabet, Array[Call] call_alphabet, Array[Return] return_alphabet, VPA[In, Call, Return] vpa1, VPA[In, Call, Return] vpa2) -> (Array[In | Call | Return] | nil)
|
94
|
+
|
95
|
+
# Generates a VPA randomly.
|
96
|
+
#
|
97
|
+
# : [In, Call, Return] (
|
98
|
+
# alphabet: Array[In],
|
99
|
+
# call_alphabet: Array[Call],
|
100
|
+
# return_alphabet: Array[Return],
|
101
|
+
# ?min_state_size: Integer,
|
102
|
+
# ?max_state_size: Integer,
|
103
|
+
# ?accept_state_size: Integer,
|
104
|
+
# ?random: Random,
|
105
|
+
# ) -> VPA[In, Call, Return]
|
106
|
+
def self.random: [In, Call, Return] (alphabet: Array[In], call_alphabet: Array[Call], return_alphabet: Array[Return], ?min_state_size: Integer, ?max_state_size: Integer, ?accept_state_size: Integer, ?random: Random) -> VPA[In, Call, Return]
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Generated from lib/lernen/automaton.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
# This is a namespace for types of automata (transition systems).
|
5
|
+
#
|
6
|
+
# In this library, the following transition systems are supported.
|
7
|
+
#
|
8
|
+
# - `DFA` (deterministic finite-state automaton) ([Wikipedia](https://en.wikipedia.org/wiki/Deterministic_finite_automaton))
|
9
|
+
# - `Mealy` machine ([Wikipedia](https://en.wikipedia.org/wiki/Mealy_machine))
|
10
|
+
# - `Moore` machine ([Wikipedia](https://en.wikipedia.org/wiki/Moore_machine))
|
11
|
+
# - `VPA` (visibly pushdown automaton) ([Wikipedia](https://en.wikipedia.org/wiki/Nested_word#Visibly_pushdown_automaton))
|
12
|
+
module Automaton
|
13
|
+
type transition_system_type = :dfa | :moore | :mealy | :vpa | :spa
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/combined_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# CombinedOracle provides an implementation of equivalence query
|
6
|
+
# that find a counterexample by combining multiple oracles.
|
7
|
+
#
|
8
|
+
# This takes two oracle. If the first oracle finds a counterexample, then
|
9
|
+
# this oracle returns it. Otherwise, it tries the second and other oracles.
|
10
|
+
#
|
11
|
+
# @rbs generic In -- Type for input alphabet
|
12
|
+
# @rbs generic Out -- Type for output values
|
13
|
+
class CombinedOracle[In, Out] < Oracle[In, Out]
|
14
|
+
@oracles: Array[Oracle[In, Out]]
|
15
|
+
|
16
|
+
def initialize: (untyped oracles) -> untyped
|
17
|
+
|
18
|
+
attr_reader oracles: Array[Oracle[In, Out]]
|
19
|
+
|
20
|
+
# @rbs override
|
21
|
+
def find_cex: ...
|
22
|
+
|
23
|
+
# @rbs override
|
24
|
+
def stats: ...
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/exhaustive_search_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# ExhaustiveSearchOracle provides an implementation of equivalence query
|
6
|
+
# that finds a counterexample by using exhaustive search to `depth` products
|
7
|
+
# of input alphabet characters.
|
8
|
+
#
|
9
|
+
# For example, with `alphabet = %w[0 1]` and `depth = 3`, this oracle queries
|
10
|
+
# the following 14 words for finding a counterexample.
|
11
|
+
#
|
12
|
+
# ```ruby
|
13
|
+
# 0, 1,
|
14
|
+
# 00, 01, 10, 11,
|
15
|
+
# 000, 001, 010, 011, 100, 101, 110, 111
|
16
|
+
# ```
|
17
|
+
#
|
18
|
+
# As the strategy, this oracle is extremingly slow and we do not recommend to use
|
19
|
+
# this oracle for non-testing purposes.
|
20
|
+
#
|
21
|
+
# @rbs generic In -- Type for input alphabet
|
22
|
+
# @rbs generic Out -- Type for output values
|
23
|
+
class ExhaustiveSearchOracle[In, Out] < Oracle[In, Out]
|
24
|
+
@alphabet: Array[In]
|
25
|
+
|
26
|
+
@depth: Integer
|
27
|
+
|
28
|
+
# @rbs alphabet: Array[In]
|
29
|
+
# @rbs sul: System::SUL[In, Out]
|
30
|
+
# @rbs depth: Integer
|
31
|
+
# @rbs return: void
|
32
|
+
def initialize: (Array[In] alphabet, System::SUL[In, Out] sul, ?depth: Integer) -> void
|
33
|
+
|
34
|
+
# @rbs override
|
35
|
+
def find_cex: ...
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/moore_like_simulator_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# MooreLikeSimulatorOracle provides an implementation of equivalence query
|
6
|
+
# that finds a counterexample by simulating the moore-like transition system.
|
7
|
+
#
|
8
|
+
# @rbs generic Conf -- Type for a configuration of this automaton
|
9
|
+
# @rbs generic In -- Type for input alphabet
|
10
|
+
# @rbs generic Out -- Type for output values
|
11
|
+
class MooreLikeSimulatorOracle[Conf, In, Out] < Oracle[In, Out]
|
12
|
+
@alphabet: Array[In]
|
13
|
+
|
14
|
+
@automaton: Automaton::MooreLike[Conf, In, Out]
|
15
|
+
|
16
|
+
# : (
|
17
|
+
# Array[In] alphabet,
|
18
|
+
# Automaton::MooreLike[Conf, In, Out] spa,
|
19
|
+
# System::SUL[In, Out] sul
|
20
|
+
# ) -> void
|
21
|
+
def initialize: (Array[In] alphabet, Automaton::MooreLike[Conf, In, Out] spa, System::SUL[In, Out] sul) -> void
|
22
|
+
|
23
|
+
# @rbs override
|
24
|
+
def find_cex: ...
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# Oracle is an oracle for answering a equivalence query.
|
6
|
+
#
|
7
|
+
# On running equivalence queries, this records the statistics information.
|
8
|
+
# We can obtain this information by `Oracle#stats`.
|
9
|
+
#
|
10
|
+
# Note that this class is *abstract*. You should implement the following method:
|
11
|
+
#
|
12
|
+
# - `#find_cex(hypothesis)`
|
13
|
+
#
|
14
|
+
# @rbs generic In -- Type for input alphabet
|
15
|
+
# @rbs generic Out -- Type for output values
|
16
|
+
class Oracle[In, Out]
|
17
|
+
@sul: System::SUL[In, Out]
|
18
|
+
|
19
|
+
@num_calls: Integer
|
20
|
+
|
21
|
+
@num_queries: Integer
|
22
|
+
|
23
|
+
@num_steps: Integer
|
24
|
+
|
25
|
+
@current_conf: untyped
|
26
|
+
|
27
|
+
# : (System::SUL[In, Out] sul) -> void
|
28
|
+
def initialize: (System::SUL[In, Out] sul) -> void
|
29
|
+
|
30
|
+
attr_reader sul: System::SUL[In, Out]
|
31
|
+
|
32
|
+
# Finds a conterexample against the given `hypothesis` automaton.
|
33
|
+
# If it is found, it returns the counterexample word, or it returns `nil` otherwise.
|
34
|
+
#
|
35
|
+
# A counterexample means that it separates a sul and a hypothesis automaton on an output
|
36
|
+
# value, i.e., `hypothesis.run(cex)[0].last != sul.query_last(cex)`. We also assume
|
37
|
+
# a counterexample is minimal; that is, there is no `n` (where `0 <= n < cex.size`)
|
38
|
+
# such that `hypothesis.run(cex[0...n])[0].last != sul.query_last(cex[0...n])`.
|
39
|
+
#
|
40
|
+
# : [Conf] (Automaton::TransitionSystem[Conf, In, Out] hypothesis) -> (Array[In] | nil)
|
41
|
+
def find_cex: [Conf] (Automaton::TransitionSystem[Conf, In, Out] hypothesis) -> (Array[In] | nil)
|
42
|
+
|
43
|
+
# Returns the statistics information as a `Hash` object.
|
44
|
+
#
|
45
|
+
# The result hash contains the following values.
|
46
|
+
#
|
47
|
+
# - `num_calls`: The number of calls of `find_cex`.
|
48
|
+
# - `num_queries`: The number of queries.
|
49
|
+
# - `num_steps`: The total number of steps.
|
50
|
+
#
|
51
|
+
# : () -> Hash[Symbol, Integer]
|
52
|
+
def stats: () -> Hash[Symbol, Integer]
|
53
|
+
|
54
|
+
# Combines two oracles.
|
55
|
+
#
|
56
|
+
# : (Oracle[In, Out] other) -> CombinedOracle[In, Out]
|
57
|
+
def +: (Oracle[In, Out] other) -> CombinedOracle[In, Out]
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
# Resets the internal states of this oracle.
|
62
|
+
#
|
63
|
+
# : [Conf] (Automaton::TransitionSystem[Conf, In, Out] hypothesis) -> void
|
64
|
+
def reset_internal: [Conf] (Automaton::TransitionSystem[Conf, In, Out] hypothesis) -> void
|
65
|
+
|
66
|
+
# Runs a transition of both a hypothesis and a SUL.
|
67
|
+
#
|
68
|
+
# : [Conf] (
|
69
|
+
# Automaton::TransitionSystem[Conf, In, Out] hypothesis,
|
70
|
+
# In input
|
71
|
+
# ) -> [Out, Out]
|
72
|
+
def step_internal: [Conf] (Automaton::TransitionSystem[Conf, In, Out] hypothesis, In input) -> [ Out, Out ]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/random_walk_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# RandomWalkOracle provides an implementation of equivalence query
|
6
|
+
# that finds a counterexample by using random walk.
|
7
|
+
#
|
8
|
+
# This takes two important parameters:
|
9
|
+
#
|
10
|
+
# - `max_steps` (default: `1500`): It is a limit of steps of a random walk.
|
11
|
+
# If a random walk is tried up to this value and no counterexample is found,
|
12
|
+
# it returns `nil` finally.
|
13
|
+
# - `reset_prob` (default: `0.09`): It is a probability to reset a random walk.
|
14
|
+
# On resetting a random walk, it resets a word, but it does not reset
|
15
|
+
# a step counter.
|
16
|
+
#
|
17
|
+
# @rbs generic In -- Type for input alphabet
|
18
|
+
# @rbs generic Out -- Type for output values
|
19
|
+
class RandomWalkOracle[In, Out] < Oracle[In, Out]
|
20
|
+
@alphabet: Array[In]
|
21
|
+
|
22
|
+
@max_steps: Integer
|
23
|
+
|
24
|
+
@reset_prob: Float
|
25
|
+
|
26
|
+
@random: Random
|
27
|
+
|
28
|
+
# : (
|
29
|
+
# Array[In] alphabet,
|
30
|
+
# System::SUL[In, Out] sul,
|
31
|
+
# ?max_steps: Integer,
|
32
|
+
# ?reset_prob: Float,
|
33
|
+
# ?random: Random
|
34
|
+
# ) -> void
|
35
|
+
def initialize: (Array[In] alphabet, System::SUL[In, Out] sul, ?max_steps: Integer, ?reset_prob: Float, ?random: Random) -> void
|
36
|
+
|
37
|
+
# @rbs override
|
38
|
+
def find_cex: ...
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/random_well_matched_word_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# RandomWellMatchedWordOracle provides an implementation of equivalence query
|
6
|
+
# that finds a counterexample by using random well-matched word generation.
|
7
|
+
#
|
8
|
+
# This takes three important parameters:
|
9
|
+
#
|
10
|
+
# - `max_words` (default: `100`): It is a limit of number of random words.
|
11
|
+
# If random words is generated and tried up to this value and no counterexample
|
12
|
+
# is found, it returns `nil` finally.
|
13
|
+
# - `min_word_size` (default: `2`): It is the minimal size of randomly generated word.
|
14
|
+
# It should be greater than `0`.
|
15
|
+
# - `max_word_size` (default: `30`): It is the maximal size of randomly generated word.
|
16
|
+
# It should be greater than or equal to `min_word_size`.
|
17
|
+
# - `call_prob` (default: `0.1`): It is a probability to generate call and return subwords.
|
18
|
+
# - `initial_proc` (default `nil`): It is the initial proc character.
|
19
|
+
# If it is specified, the generated words must be started with it.
|
20
|
+
#
|
21
|
+
# @rbs generic In -- Type for input alphabet
|
22
|
+
# @rbs generic Call -- Type for call alphabet
|
23
|
+
# @rbs generic Return -- Type for return alphabet
|
24
|
+
# @rbs generic Out -- Type for output values
|
25
|
+
class RandomWellMatchedWordOracle[In, Call, Return, Out] < Oracle[In | Call | Return, Out]
|
26
|
+
@alphabet: Array[In]
|
27
|
+
|
28
|
+
@call_alphabet: Array[Call]
|
29
|
+
|
30
|
+
@return_alphabet: Array[Return]
|
31
|
+
|
32
|
+
@max_words: Integer
|
33
|
+
|
34
|
+
@min_word_size: Integer
|
35
|
+
|
36
|
+
@max_word_size: Integer
|
37
|
+
|
38
|
+
@call_prob: Float
|
39
|
+
|
40
|
+
@initial_proc: Call | nil
|
41
|
+
|
42
|
+
@random: Random
|
43
|
+
|
44
|
+
# : (
|
45
|
+
# Array[In] alphabet,
|
46
|
+
# Array[Call] call_alphabet,
|
47
|
+
# Array[Return] return_alphabet,
|
48
|
+
# System::SUL[In | Call | Return, Out] sul,
|
49
|
+
# ?max_words: Integer,
|
50
|
+
# ?min_word_size: Integer,
|
51
|
+
# ?max_word_size: Integer,
|
52
|
+
# ?call_prob: Float,
|
53
|
+
# ?initial_proc: Call | nil,
|
54
|
+
# ?random: Random
|
55
|
+
# ) -> void
|
56
|
+
def initialize: (Array[In] alphabet, Array[Call] call_alphabet, Array[Return] return_alphabet, System::SUL[In | Call | Return, Out] sul, ?max_words: Integer, ?min_word_size: Integer, ?max_word_size: Integer, ?call_prob: Float, ?initial_proc: Call | nil, ?random: Random) -> void
|
57
|
+
|
58
|
+
# @rbs override
|
59
|
+
def find_cex: ...
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
# : () -> Array[In | Call | Return]
|
64
|
+
def generate_word: () -> Array[In | Call | Return]
|
65
|
+
|
66
|
+
# : (Array[In | Call | Return] word, Integer word_size) -> void
|
67
|
+
def generate_word_internal: (Array[In | Call | Return] word, Integer word_size) -> void
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/random_word_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# RandomWordOracle provides an implementation of equivalence query
|
6
|
+
# that finds a counterexample by using random word generation.
|
7
|
+
#
|
8
|
+
# This takes three important parameters:
|
9
|
+
#
|
10
|
+
# - `max_words` (default: `100`): It is a limit of number of random words.
|
11
|
+
# If random words is generated and tried up to this value and no counterexample
|
12
|
+
# is found, it returns `nil` finally.
|
13
|
+
# - `min_word_size` (default: `1`): It is the minimal size of randomly generated word.
|
14
|
+
# It should be greater than `0`.
|
15
|
+
# - `max_word_size` (default: `30`): It is the maximal size of randomly generated word.
|
16
|
+
# It should be greater than or equal to `min_word_size`.
|
17
|
+
#
|
18
|
+
# @rbs generic In -- Type for input alphabet
|
19
|
+
# @rbs generic Out -- Type for output values
|
20
|
+
class RandomWordOracle[In, Out] < Oracle[In, Out]
|
21
|
+
@alphabet: Array[In]
|
22
|
+
|
23
|
+
@max_word: Integer
|
24
|
+
|
25
|
+
@min_word_size: Integer
|
26
|
+
|
27
|
+
@max_word_size: Integer
|
28
|
+
|
29
|
+
@random: Random
|
30
|
+
|
31
|
+
# : (
|
32
|
+
# Array[In] alphabet,
|
33
|
+
# System::SUL[In, Out] sul,
|
34
|
+
# ?max_words: Integer,
|
35
|
+
# ?min_word_size: Integer,
|
36
|
+
# ?max_word_size: Integer,
|
37
|
+
# ?random: Random,
|
38
|
+
# ) -> void
|
39
|
+
def initialize: (Array[In] alphabet, System::SUL[In, Out] sul, ?max_words: Integer, ?min_word_size: Integer, ?max_word_size: Integer, ?random: Random) -> void
|
40
|
+
|
41
|
+
# @rbs override
|
42
|
+
def find_cex: ...
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/spa_simulator_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# SPASimulatorOracle provides an implementation of equivalence query
|
6
|
+
# that finds a counterexample by simulating the SPA.
|
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 SPASimulatorOracle[In, Call, Return] < Oracle[In | Call | Return, bool]
|
12
|
+
@alphabet: Array[In]
|
13
|
+
|
14
|
+
@call_alphabet: Array[Call]
|
15
|
+
|
16
|
+
@spa: Automaton::SPA[In, Call, Return]
|
17
|
+
|
18
|
+
# : (
|
19
|
+
# Array[In] alphabet,
|
20
|
+
# Array[Call] call_alphabet,
|
21
|
+
# Automaton::SPA[In, Call, Return] spa,
|
22
|
+
# System::SUL[In | Call | Return, bool] sul
|
23
|
+
# ) -> void
|
24
|
+
def initialize: (Array[In] alphabet, Array[Call] call_alphabet, Automaton::SPA[In, Call, Return] spa, System::SUL[In | Call | Return, bool] sul) -> void
|
25
|
+
|
26
|
+
# @rbs override
|
27
|
+
def find_cex: ...
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/test_words_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# TestWordsOracle provides an implementation of equivalence query
|
6
|
+
# that find a counterexample from the given words.
|
7
|
+
#
|
8
|
+
# @rbs generic In -- Type for input alphabet
|
9
|
+
# @rbs generic Out -- Type for output values
|
10
|
+
class TestWordsOracle[In, Out] < Oracle[In, Out]
|
11
|
+
@words: Array[Array[In]]
|
12
|
+
|
13
|
+
# : (Array[Array[In]] words, System::SUL[In, Out] sul) -> void
|
14
|
+
def initialize: (Array[Array[In]] words, System::SUL[In, Out] sul) -> void
|
15
|
+
|
16
|
+
# @rbs override
|
17
|
+
def find_cex: ...
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/transition_system_simulator_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# TransitionSystemSimulatorOracle provides an implementation of equivalence query
|
6
|
+
# that finds a counterexample by simulating the transition system.
|
7
|
+
#
|
8
|
+
# @rbs generic Conf -- Type for a configuration of this automaton
|
9
|
+
# @rbs generic In -- Type for input alphabet
|
10
|
+
# @rbs generic Out -- Type for output values
|
11
|
+
class TransitionSystemSimulatorOracle[Conf, In, Out] < Oracle[In, Out]
|
12
|
+
@alphabet: Array[In]
|
13
|
+
|
14
|
+
@automaton: Automaton::TransitionSystem[Conf, In, Out]
|
15
|
+
|
16
|
+
# : (
|
17
|
+
# Array[In] alphabet,
|
18
|
+
# Automaton::TransitionSystem[Conf, In, Out] spa,
|
19
|
+
# System::SUL[In, Out] sul
|
20
|
+
# ) -> void
|
21
|
+
def initialize: (Array[In] alphabet, Automaton::TransitionSystem[Conf, In, Out] spa, System::SUL[In, Out] sul) -> void
|
22
|
+
|
23
|
+
# @rbs override
|
24
|
+
def find_cex: ...
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# Generated from lib/lernen/equiv/vpa_simulator_oracle.rb with RBS::Inline
|
2
|
+
|
3
|
+
module Lernen
|
4
|
+
module Equiv
|
5
|
+
# VPASimulatorOracle provides an implementation of equivalence query
|
6
|
+
# that finds a counterexample by simulating the VPA.
|
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 VPASimulatorOracle[In, Call, Return] < Oracle[In | Call | Return, bool]
|
12
|
+
@alphabet: Array[In]
|
13
|
+
|
14
|
+
@call_alphabet: Array[Call]
|
15
|
+
|
16
|
+
@return_alphabet: Array[Return]
|
17
|
+
|
18
|
+
@spa: Automaton::VPA[In, Call, Return]
|
19
|
+
|
20
|
+
# : (
|
21
|
+
# Array[In] alphabet,
|
22
|
+
# Array[Call] call_alphabet,
|
23
|
+
# Array[Return] return_alphabet,
|
24
|
+
# Automaton::VPA[In, Call, Return] vpa,
|
25
|
+
# System::SUL[In | Call | Return, bool] sul
|
26
|
+
# ) -> void
|
27
|
+
def initialize: (Array[In] alphabet, Array[Call] call_alphabet, Array[Return] return_alphabet, Automaton::VPA[In, Call, Return] vpa, System::SUL[In | Call | Return, bool] sul) -> void
|
28
|
+
|
29
|
+
# @rbs override
|
30
|
+
def find_cex: ...
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|