libmc Package¶
Provides collection of tools for KV Model Checking.
-
libmc.asynchronousComposition(*lts, partialOrderReduction=None)[source]¶ Asynchronous composition of two or more LTS through interleaving (p84).
- performs on-the-fly generation of reachable states
- Partial Order Reduction can be applied by supplying a function partialOrderReduction, selecting the components to expand
Parameters: *lts (variable argument list(LTS)) – list of LTS to interleave Keyword Arguments: partialOrderReduction (optional) – function f: list(index) -> list(index)selecting the local components to expand
-
class
libmc.BDD[source]¶ Bases:
objectBinary Decision Diagram (p149).
-
idx¶ int – node index
-
sign¶ bool – the node’s sign
-
child¶ list(BDD, BDD) – the node’s else and then successors
Note
Operations are carried out using the logical connectives
~,|,&and^.-
-
class
libmc.Boole(formula)[source]¶ Bases:
objectEvaluate and convert propositional formulae given in the Boole format [1].
References
[1] limboole -
evaluate(assignment)[source]¶ Evaluate the formula using a given assignment to it’s variables.
Parameters: assignment (dict) – dictionary mapping variable names to truth values
-
toAIG()[source]¶ Converts the formula to an AIG in the AIGER format.
Returns: AIG representing the formula in the AIGER format Return type: string
-
-
libmc.bfs(queue, successors, **kwargs)[source]¶ Generic breadth-first search.
while queue: current = dequeue(queue) for successor in successors(current): if not cached(successor): cache(successor) enqueue(successor) if quit is not None and quit(current): return
Perform BFS on any given problem by defining:
- the search queue’s initial state
- a function returning the successors to a given object
- (optional) a function for enqueuing objects
- (optional) a function for adding objects to the cache
- (optional) a function checking if a given object has been cached already
- (optional) a function for stopping the search
Parameters: - queue (list) – initial state of the search queue
- successors (function) – function
f: object -> list(object)returning the list of successors to a given object
Keyword Arguments: - enqueue (function) – a function
f: object -> Noneadding objects to the search queue - cache (function) – a function
f: object -> Noneadding a given object to the cache (requires cached) - cached (function) – a function
f: object -> boolchecking if a given object has been cached already (requires cache) - quit (function) – a function
f: object -> boolreturningTrueif the search should stop with the given object
-
libmc.dfs(stack, successors, **kwargs)[source]¶ Generic depth-first search.
while stack: current = dequeue(stack) for successor in successors(current): if not cached(successor): cache(successor) enqueue(successor) if quit is not None and quit(current): return
Perform DFS on any given problem by defining:
- the search queue’s initial state
- a function returning the successors to a given object
- (optional) a function for enqueuing objects
- (optional) a function for adding objects to the cache
- (optional) a function checking if a given object has been cached already
- (optional) a function for stopping the search
Parameters: - queue (list) – initial state of the search queue
- successors (function) – function
f: object -> list(object)returning the list of successors to a given object
Keyword Arguments: - enqueue (function) – a function
f: object -> Noneadding objects to the search queue - cache (function) – a function
f: object -> Noneadding a given object to the cache (requires cached) - cached (function) – a function
f: object -> boolchecking if a given object has been cached already (requires cache) - quit (function) – a function
f: object -> boolreturningTrueif the search should stop with the given object
-
class
libmc.FA(S, I, Σ, T, F)[source]¶ Bases:
libmc.lts.LTSFinite Automaton (p18).
-
S¶ set of states
-
I¶ set of initial states I ⊆ S
-
Σ¶ input alphabet
-
T¶ transition relation T ⊆ SxΣxS
-
F¶ set of final states F ⊆ S
-
accepts(word)[source]¶ Test acceptance of a given word.
Parameters: word (list) – the word to check Returns: True if the word is accepted by the automaton Return type: bool
-
bisimulates(other, τ=[])¶ Bisimulation of LTS (p43).
∀ s ∊ self.I, ∃ t ∊ other.I [ s ≈ t ]
Parameters: - other (LTS) – another LTS
- τ (optional) – set of unobservable internal events
Returns: True if this LTS bisimulates the other
Return type: bool
-
conforms(other, full=False)[source]¶ Conformance test (p24).
- L(self) ⊆ L(other)
- L(self) ∩ L(other) = 0
- self × C(P(other)) contains no reachable final state (implemented)
Parameters: - other (FA) – the other FA to conform to
- full (bool - optional) – create full automaton if True, else only reachable states are included (default)
Returns: a triple containing:
- the result of the conformance test
- the generated checker automaton self × C(P(other))
- all traces from initial to final states
Return type: (bool, FA, list)
-
isComplete()¶ Completeness (p21): True if LTS is complete.
-
isDeterministic()¶ Determinism (p21): True if LTS is deterministic.
-
power(full=False)[source]¶ Create power automaton (p22).
Parameters: full (bool - optional) – create full automaton if True, else only reachable states are included (default)
-
product(other, full=False)[source]¶ Create product automaton (p20).
Parameters: - other (FA) – another FA
- full (bool - optional) – create full automaton if True, else only reachable states are included (default)
-
simulates(other, τ=[])¶ Simulation of LTS (p39).
∀ s ∊ other.I, ∃ t ∊ self.I [ s ≤ t ]
Parameters: - other (LTS) – another LTS
- τ (optional) – set of unobservable internal events
Returns: True if this LTS simulates the other
Return type: bool
-
toDot(highlight=[])[source]¶ Return FA as Graphviz dot language string.
Parameters: highlight (list of transition lists - optional) – highlight the given paths Returns: .dot file tweaked for dot2tex Return type: string
-
toTex(highlight=[])[source]¶ Return LTS as TikZ based LaTeX figure (tikzpicture).
Parameters: highlight (list of transition lists - optional) – highlight the given paths Returns: .tex file (tikzpicture) Return type: string Note
Requires manual positioning!
-
trace(target, sources=None)¶ Tries to compute all traces to the target state (DFS).
If no source states are given, the set of initial states is used.
Parameters: - target – target state
- sources (optional) – set of initial states
Returns: all paths (list of transitions) to the target or an empty list if it is unreachable
Return type: list
-
-
class
libmc.LTS(S, I, Σ, T)[source]¶ Bases:
objectLabelled Transition System (p31).
-
S¶ set of states
-
I¶ set of initial states I ⊆ S
-
Σ¶ input alphabet
-
T¶ transition relation T ⊆ SxΣxS
-
bisimulates(other, τ=[])[source]¶ Bisimulation of LTS (p43).
∀ s ∊ self.I, ∃ t ∊ other.I [ s ≈ t ]
Parameters: - other (LTS) – another LTS
- τ (optional) – set of unobservable internal events
Returns: True if this LTS bisimulates the other
Return type: bool
-
power(full=False)[source]¶ Create power automaton (p22).
Parameters: full (bool - optional) – create full automaton if True, else only reachable states are included (default)
-
product(other, full=False)[source]¶ Create product automaton (p20).
Parameters: - other (LTS) – another LTS
- full (bool - optional) – create full automaton if True, else only reachable states are included (default)
-
simulates(other, τ=[])[source]¶ Simulation of LTS (p39).
∀ s ∊ other.I, ∃ t ∊ self.I [ s ≤ t ]
Parameters: - other (LTS) – another LTS
- τ (optional) – set of unobservable internal events
Returns: True if this LTS simulates the other
Return type: bool
-
toDot(highlight=[])[source]¶ Return LTS as Graphviz dot language string.
Parameters: highlight (list of transition lists - optional) – highlight the given paths Returns: .dot file tweaked for dot2tex Return type: string
-
toTex(highlight=[])[source]¶ Return LTS as TikZ based LaTeX figure (tikzpicture).
Parameters: highlight (list of transition lists - optional) – highlight the given paths Returns: .tex file (tikzpicture) Return type: string Note
Requires manual positioning!
-
trace(target, sources=None)[source]¶ Tries to compute all traces to the target state (DFS).
If no source states are given, the set of initial states is used.
Parameters: - target – target state
- sources (optional) – set of initial states
Returns: all paths (list of transitions) to the target or an empty list if it is unreachable
Return type: list
-
-
libmc.maximumSimulation(A1, A2, R0, τ=[])[source]¶ Constructs the maximum simulation relation A1 ≲ A2 (p36).
To get the full maximum simulation between two LTS A1 and A2 build the union of all possible permutations:
fullSimulationRelation = maximumSimulation(A1, A1, set(product(A1.S, A1.S))) | maximumSimulation(A1, A2, set(product(A1.S, A2.S))) | maximumSimulation(A2, A1, set(product(A2.S, A1.S))) | maximumSimulation(A2, A2, set(product(A2.S, A2.S)))
Parameters: Returns: A1 ≲ A2 ⊆ R0 - the maximum simulation relation
Return type: set
-
libmc.maximumBisimulation(A1, A2, R0, τ=[])[source]¶ Constructs the maximum bisimulation relation A1 ≈ A2 (p43).
Can also be used to minimize a deterministic automaton by constructing the state equivalence relation using:
maximumBisimulation(A, A, (A.FxA.F)∪((A.S\A.F)x(A.S\A.F)))
To get the full maximum bisimulation between two LTS A1 and A2 build the union of all possible permutations:
fullSimulationRelation = maximumBisimulation(A1, A1, set(product(A1.S, A1.S))) | maximumBisimulation(A1, A2, set(product(A1.S, A2.S))) | maximumBisimulation(A2, A1, set(product(A2.S, A1.S))) | maximumBisimulation(A2, A2, set(product(A2.S, A2.S)))
Parameters: Returns: A1 ≈ A2 ⊆ R0 - the maximum simulation relation
Return type: set