mocha-model-checking 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/.github/scripts/smoke_base_install.py +1 -1
- mocha_model_checking-0.2.0/CHANGELOG.md +70 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/PKG-INFO +105 -20
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/README.md +103 -18
- mocha_model_checking-0.2.0/docs/ctl.md +201 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/docs/ltl.md +3 -3
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/examples/typed_usage.py +16 -6
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/pyproject.toml +2 -1
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/__init__.py +39 -4
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/__init__.py +29 -4
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/automata.py +10 -10
- mocha_model_checking-0.2.0/src/mocha/algorithms/ctl_model_checking.py +445 -0
- mocha_model_checking-0.2.0/src/mocha/algorithms/ctl_transformations.py +163 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/invariance.py +10 -10
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl2gnba/transitions.py +15 -8
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl_model_checking.py +21 -20
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/persistence.py +20 -20
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/reachability.py +23 -30
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/io/__init__.py +4 -0
- mocha_model_checking-0.2.0/src/mocha/io/ctl.py +196 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/io/transition_system.py +11 -11
- mocha_model_checking-0.2.0/src/mocha/logic/__init__.py +6 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/logic/_syntax.py +4 -0
- mocha_model_checking-0.2.0/src/mocha/logic/ctl.py +272 -0
- mocha_model_checking-0.2.0/src/mocha/logic/formula.py +16 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/logic/ltl.py +3 -2
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/visualisation/__init__.py +4 -4
- mocha_model_checking-0.2.0/src/mocha/visualisation/invariance.py +112 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/visualisation/persistence.py +3 -3
- mocha_model_checking-0.2.0/src/mocha/visualisation/reachability.py +52 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/visualisation/transition_system.py +80 -45
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha_model_checking.egg-info/PKG-INFO +105 -20
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha_model_checking.egg-info/SOURCES.txt +9 -0
- mocha_model_checking-0.2.0/tests/test_ctl.py +248 -0
- mocha_model_checking-0.2.0/tests/test_ctl_existential_normal_form.py +208 -0
- mocha_model_checking-0.2.0/tests/test_ctl_model_checking.py +324 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_invariance.py +4 -2
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_ltl_model_checking.py +5 -5
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_ltl_transitions.py +6 -6
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_persistence.py +2 -2
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_reachability.py +69 -2
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_transition_system_io.py +1 -1
- mocha_model_checking-0.2.0/tests/test_transition_system_visualisation.py +328 -0
- mocha_model_checking-0.1.0/CHANGELOG.md +0 -30
- mocha_model_checking-0.1.0/src/mocha/logic/__init__.py +0 -5
- mocha_model_checking-0.1.0/src/mocha/visualisation/invariance.py +0 -84
- mocha_model_checking-0.1.0/src/mocha/visualisation/reachability.py +0 -35
- mocha_model_checking-0.1.0/tests/test_transition_system_visualisation.py +0 -140
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/CONTRIBUTING.md +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/LICENCE +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/MANIFEST.in +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/examples/invariant_checking.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/setup.cfg +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl2gnba/__init__.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl2gnba/acceptance.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl2gnba/elementary_set_enumeration.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl2gnba/elementary_set_validation.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl2gnba/initial_states.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl2gnba/pipeline.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl_satisfiability_validity.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/ltl_transformations.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/algorithms/trace.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/io/ltl.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/io/schemas/__init__.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/io/schemas/transition-system.schema.json +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/models/__init__.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/models/automaton.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/models/transition_system.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/py.typed +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/visualisation/automaton.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha/visualisation/overlay.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha_model_checking.egg-info/dependency_links.txt +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha_model_checking.egg-info/requires.txt +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/src/mocha_model_checking.egg-info/top_level.txt +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_automata.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_automaton.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_automaton_visualisation.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_elementary_set_enumeration.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_elementary_set_validation.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_ltl.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_ltl_gnba.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_ltl_satisfiability_validity.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_ltl_trace.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_ltl_visualisation.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_persistence_visualisation.py +0 -0
- {mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/tests/test_transition_system.py +0 -0
{mocha_model_checking-0.1.0 → mocha_model_checking-0.2.0}/.github/scripts/smoke_base_install.py
RENAMED
|
@@ -40,7 +40,7 @@ def main() -> None:
|
|
|
40
40
|
)
|
|
41
41
|
system = from_dict(to_dict(system))
|
|
42
42
|
|
|
43
|
-
assert compute_reachable_states(system)
|
|
43
|
+
assert compute_reachable_states(system) == {"start", "stable"}
|
|
44
44
|
assert check_invariant(system, {"start", "stable"}).satisfies
|
|
45
45
|
invariant = check_invariant(system, {"start"})
|
|
46
46
|
assert not invariant.satisfies
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.2.0
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- CTL parsing with `parse_ctl`, transformation to existential normal form
|
|
10
|
+
with `to_existential_normal_form`, and model checking of ENF formulas with
|
|
11
|
+
`model_check_ctl`. Results include satisfaction sets for each state
|
|
12
|
+
subformula and a verdict over all initial states. Rewrite traces and
|
|
13
|
+
model-checking traces expose normalization steps, successor checks, and
|
|
14
|
+
fixed-point search snapshots through `trace_existential_normal_form` and
|
|
15
|
+
`trace_ctl_model_checking`.
|
|
16
|
+
- Transition-system rendering supports arbitrary hashable states, actions,
|
|
17
|
+
and propositions, including product-state tuples. `to_graphviz`,
|
|
18
|
+
`visualise_overlay`, `visualise_reachability_step`, `visualise_invariant_step`,
|
|
19
|
+
and `visualise_invariant_result` accept `format_state`, `format_action`, and
|
|
20
|
+
`format_proposition` callbacks. Defaults use `str` and preserve existing
|
|
21
|
+
string-valued calls. Formatting preserves state identities and highlighting.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- Renamed `TransitionRelationStep.input` to `valuation`, including its
|
|
26
|
+
constructor keyword. Markdown explanations now label it as "Valuation".
|
|
27
|
+
- Standardized transition-system parameters as `transition_system` across
|
|
28
|
+
algorithms, I/O, and rendering helpers. Replace keyword arguments `ts=`
|
|
29
|
+
and `system=` with `transition_system=`. Positional calls are unchanged.
|
|
30
|
+
- Renamed `trace_check_ltl` to `trace_ltl` in `mocha`, `mocha.algorithms`, and
|
|
31
|
+
`mocha.algorithms.ltl_model_checking`.
|
|
32
|
+
- Renamed `visualise_step` to `visualise_overlay` in `mocha.visualisation`
|
|
33
|
+
and `mocha.visualisation.transition_system`. Its `step` keyword argument
|
|
34
|
+
is now `overlay`. The old function names have been removed; update imports
|
|
35
|
+
and keyword arguments to the new names.
|
|
36
|
+
- `compute_reachable_states` now returns `frozenset[State]` directly, and
|
|
37
|
+
`trace_reachability(...).result` contains that same reachable set.
|
|
38
|
+
- Removed `ReachabilityResult` from the public API. Replace
|
|
39
|
+
`compute_reachable_states(system).reachable_states` with
|
|
40
|
+
`compute_reachable_states(system)`. `ReachabilityStep` still exposes
|
|
41
|
+
`iteration` and `reachable_states` for progress snapshots.
|
|
42
|
+
|
|
43
|
+
## 0.1.0
|
|
44
|
+
|
|
45
|
+
First stable release of MoChA, a teaching library for model checking.
|
|
46
|
+
|
|
47
|
+
- Labelled transition systems and finite, Büchi, and generalized Büchi automata.
|
|
48
|
+
- Reachability, invariant, persistence, and LTL model checking.
|
|
49
|
+
- LTL parsing, normal-form transformations, and automata construction.
|
|
50
|
+
- Algorithm traces exposing intermediate steps for teaching.
|
|
51
|
+
- Validated JSON import and export for string-valued transition systems.
|
|
52
|
+
- Optional Graphviz visualisation for transition systems, automata, and counterexamples.
|
|
53
|
+
- Docker images with JupyterLab, a Python notebook kernel, and Graphviz for
|
|
54
|
+
`linux/amd64` and `linux/arm64`.
|
|
55
|
+
|
|
56
|
+
Requires Python 3.11 or later. Image rendering additionally requires the Graphviz
|
|
57
|
+
executables, which are included in the Docker images.
|
|
58
|
+
|
|
59
|
+
## 0.1.0rc1
|
|
60
|
+
|
|
61
|
+
First release candidate of MoChA, a teaching library for model checking.
|
|
62
|
+
|
|
63
|
+
- Labelled transition systems and finite, Büchi, and generalized Büchi automata.
|
|
64
|
+
- Reachability, invariant, persistence, and LTL model checking.
|
|
65
|
+
- LTL parsing, normal-form transformations, and automata construction.
|
|
66
|
+
- Algorithm traces exposing intermediate steps for teaching.
|
|
67
|
+
- Validated JSON import and export for string-valued transition systems.
|
|
68
|
+
- Optional Graphviz visualisation.
|
|
69
|
+
|
|
70
|
+
Requires Python 3.11 or later. Image rendering additionally requires the Graphviz executables.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mocha-model-checking
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: A teaching library for model checking algorithms for labelled transition systems.
|
|
5
5
|
Author-email: Alexander Bork <alexander.bork@cs.rwth-aachen.de>
|
|
6
6
|
License-Expression: MPL-2.0
|
|
7
7
|
Project-URL: Repository, https://github.com/moves-rwth/mocha
|
|
8
8
|
Project-URL: Issues, https://github.com/moves-rwth/mocha/issues
|
|
9
|
-
Keywords: model-checking,formal-verification,transition-systems,temporal-logic,ltl,teaching
|
|
9
|
+
Keywords: model-checking,formal-verification,transition-systems,temporal-logic,ltl,ctl,teaching
|
|
10
10
|
Classifier: Intended Audience :: Education
|
|
11
11
|
Classifier: Intended Audience :: Science/Research
|
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -33,14 +33,15 @@ Dynamic: license-file
|
|
|
33
33
|
[](https://github.com/moves-rwth/mocha/actions/workflows/ci.yml)
|
|
34
34
|
|
|
35
35
|
MoChA is a small, typed Python library for representing labelled transition
|
|
36
|
-
systems and automata, checking reachability, invariants, persistence, and
|
|
37
|
-
properties, and parsing and transforming
|
|
36
|
+
systems and automata, checking reachability, invariants, persistence, and CTL
|
|
37
|
+
and LTL properties, and parsing and transforming temporal-logic formulas. Algorithm traces expose
|
|
38
38
|
intermediate steps for teaching and worked examples.
|
|
39
39
|
|
|
40
40
|
The public API is available from `mocha`: models, analysis results and traces,
|
|
41
41
|
algorithms, and parsing and JSON helpers. These names are also exported from
|
|
42
|
-
`mocha.models`, `mocha.algorithms`, and `mocha.io`. LTL formula constructors
|
|
43
|
-
live in `mocha.logic.ltl` (also available as `mocha.
|
|
42
|
+
`mocha.models`, `mocha.algorithms`, and `mocha.io`. CTL and LTL formula constructors
|
|
43
|
+
live in `mocha.logic.ctl` and `mocha.logic.ltl` (also available as `mocha.ctl`
|
|
44
|
+
and `mocha.ltl`), and rendering helpers
|
|
44
45
|
are exported from `mocha.visualisation` with the optional `visualization` extra.
|
|
45
46
|
|
|
46
47
|
## Install
|
|
@@ -168,16 +169,17 @@ predecessors with `pre(state, action=None)`, and iterate the relation with
|
|
|
168
169
|
|
|
169
170
|
## Reachability and Invariants
|
|
170
171
|
|
|
171
|
-
`compute_reachable_states`
|
|
172
|
-
including the initial states themselves. `check_invariant`
|
|
173
|
-
every reachable state belongs to a supplied set of allowed
|
|
174
|
-
result contains a path from an initial state to a violating
|
|
172
|
+
`compute_reachable_states` returns a `frozenset` of all states reachable from
|
|
173
|
+
any initial state, including the initial states themselves. `check_invariant`
|
|
174
|
+
checks whether every reachable state belongs to a supplied set of allowed
|
|
175
|
+
states. A failing result contains a path from an initial state to a violating
|
|
176
|
+
state:
|
|
175
177
|
|
|
176
178
|
```python
|
|
177
179
|
from mocha import check_invariant, compute_reachable_states, trace_reachability
|
|
178
180
|
|
|
179
181
|
reachable = compute_reachable_states(system)
|
|
180
|
-
assert reachable
|
|
182
|
+
assert reachable == {"idle", "running", "done"}
|
|
181
183
|
|
|
182
184
|
result = check_invariant(system, {"idle", "running"})
|
|
183
185
|
assert not result.satisfies
|
|
@@ -198,13 +200,16 @@ system remains unchanged; with no initial states, the result has no states.
|
|
|
198
200
|
from mocha import reduce_to_reachable
|
|
199
201
|
|
|
200
202
|
reduced = reduce_to_reachable(system)
|
|
201
|
-
assert reduced.states == reachable
|
|
203
|
+
assert reduced.states == reachable
|
|
202
204
|
```
|
|
203
205
|
|
|
204
206
|
`trace_reachability`, `trace_invariant`, and `trace_persistence` return an
|
|
205
207
|
`AlgorithmTrace` with the final `result` and an immutable tuple of `steps`.
|
|
206
208
|
The direct algorithms also accept an `on_step` callback to stream snapshots.
|
|
207
|
-
|
|
209
|
+
Algorithm-specific result and step classes are exported from `mocha` and
|
|
210
|
+
`mocha.algorithms`.
|
|
211
|
+
For reachability, `trace.result` is the reachable-state `frozenset` directly;
|
|
212
|
+
each `ReachabilityStep` still records its iteration and `reachable_states`.
|
|
208
213
|
|
|
209
214
|
For a complete invariant walkthrough, see
|
|
210
215
|
[examples/invariant_checking.py](https://github.com/moves-rwth/mocha/blob/main/examples/invariant_checking.py).
|
|
@@ -353,6 +358,66 @@ The automaton must declare its complete alphabet $2^{\mathrm{AP}}$, including
|
|
|
353
358
|
valuations that no system state currently uses. This follows the formal product
|
|
354
359
|
definition and makes a mismatched proposition vocabulary explicit.
|
|
355
360
|
|
|
361
|
+
## State and Path Formulas
|
|
362
|
+
|
|
363
|
+
`mocha.logic.StateFormula` and `mocha.logic.PathFormula` distinguish formulas
|
|
364
|
+
evaluated at a state from formulas evaluated along a path. Both inherit from
|
|
365
|
+
`Formula`. LTL syntax trees inherit from `PathFormula`.
|
|
366
|
+
|
|
367
|
+
CTL has separate `CTLStateFormula` and `CTLPathFormula` types in
|
|
368
|
+
`mocha.logic.ctl`, with `CTLFormula` as their common base. Propositions,
|
|
369
|
+
Boolean operations, and path quantifiers are state formulas. Temporal
|
|
370
|
+
operators are path formulas, and their operands must be CTL state formulas:
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
from mocha import parse_ctl
|
|
374
|
+
from mocha.logic.ctl import Exists, Next, Proposition, is_ctl_formula
|
|
375
|
+
|
|
376
|
+
formula = Exists(Next(Proposition("ready")))
|
|
377
|
+
assert formula == parse_ctl('EX "ready"')
|
|
378
|
+
assert is_ctl_formula(formula)
|
|
379
|
+
assert not is_ctl_formula(formula.operand) # A bare path is not a CTL state formula.
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
`Exists` and `ForAll` quantify path formulas built with `Next`, `Always`,
|
|
383
|
+
`Eventually`, `Until`, and `WeakUntil`. Temporal nesting passes through another
|
|
384
|
+
path quantifier: `AG AF "ready"` is valid CTL. Compact source notation such as
|
|
385
|
+
`EX "ready"` and `AG "ready"` is accepted by `parse_ctl`.
|
|
386
|
+
|
|
387
|
+
## CTL Model Checking
|
|
388
|
+
|
|
389
|
+
`model_check_ctl` computes the states satisfying a CTL formula. Parse or
|
|
390
|
+
construct the formula, explicitly rewrite it into existential normal form,
|
|
391
|
+
then check it. For example, every path in this system eventually reaches
|
|
392
|
+
`done`:
|
|
393
|
+
|
|
394
|
+
```python
|
|
395
|
+
from mocha import (
|
|
396
|
+
TransitionSystem, model_check_ctl, parse_ctl,
|
|
397
|
+
to_existential_normal_form,
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
ctl_system = TransitionSystem.from_edges(
|
|
401
|
+
states={"waiting", "done"},
|
|
402
|
+
edges={("waiting", "done"), ("done", "done")},
|
|
403
|
+
action="step", initial_states={"waiting"},
|
|
404
|
+
atomic_propositions={"done"}, labels={"done": {"done"}},
|
|
405
|
+
)
|
|
406
|
+
ctl_formula = parse_ctl('AF "done"')
|
|
407
|
+
ctl_enf = to_existential_normal_form(ctl_formula) # AF done ≡ ¬EG ¬done
|
|
408
|
+
ctl_result = model_check_ctl(ctl_system, ctl_enf)
|
|
409
|
+
assert ctl_result.satisfies
|
|
410
|
+
assert ctl_result.satisfying_states == {"waiting", "done"}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
`satisfies` checks every initial state. CTL checking requires every state,
|
|
414
|
+
including unreachable ones, to have an outgoing transition and every formula
|
|
415
|
+
proposition to be declared in the system. The self-loop at `done` ensures
|
|
416
|
+
that paths continue infinitely.
|
|
417
|
+
|
|
418
|
+
The [CTL guide](https://github.com/moves-rwth/mocha/blob/main/docs/ctl.md)
|
|
419
|
+
explains formula syntax, existential normal form, rewrite traces, satisfaction
|
|
420
|
+
sets, and detailed model-checking traces.
|
|
356
421
|
|
|
357
422
|
## LTL Model Checking
|
|
358
423
|
|
|
@@ -403,10 +468,28 @@ graph = to_graphviz(system, highlighted_states={"running"})
|
|
|
403
468
|
graph.render("system", format="svg", cleanup=True)
|
|
404
469
|
```
|
|
405
470
|
|
|
406
|
-
`to_graphviz`
|
|
407
|
-
states
|
|
408
|
-
|
|
409
|
-
|
|
471
|
+
`to_graphviz` accepts arbitrary hashable states, actions, and propositions,
|
|
472
|
+
including integer states and product-state tuples. Values are displayed with
|
|
473
|
+
`str` by default. Supply `format_state`, `format_action`, and
|
|
474
|
+
`format_proposition` callbacks to customize their labels:
|
|
475
|
+
|
|
476
|
+
```python
|
|
477
|
+
integer_system = TransitionSystem.from_edges(
|
|
478
|
+
states={0, 1}, edges={(0, 1), (1, 1)}, action=2, initial_states={0},
|
|
479
|
+
atomic_propositions={3}, labels={1: {3}},
|
|
480
|
+
)
|
|
481
|
+
graph = to_graphviz(
|
|
482
|
+
integer_system,
|
|
483
|
+
format_state=lambda state: f"s{state}",
|
|
484
|
+
format_action=lambda action: f"a{action}",
|
|
485
|
+
format_proposition=lambda proposition: f"p{proposition}",
|
|
486
|
+
)
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
Formatted labels are literal text. Formatting preserves state identities,
|
|
490
|
+
including distinct states with equal displayed labels. Highlights refer to
|
|
491
|
+
original state and transition values. Actions connecting the same pair of
|
|
492
|
+
states share an edge label, with highlighted actions drawn on a separate edge.
|
|
410
493
|
|
|
411
494
|
The returned graph supports several output workflows:
|
|
412
495
|
|
|
@@ -420,9 +503,11 @@ In a Jupyter notebook, use `display(graph)` to show the graph inline.
|
|
|
420
503
|
Building the graph or saving DOT source requires the Python `graphviz`
|
|
421
504
|
package; rendering an image also needs the Graphviz executables.
|
|
422
505
|
|
|
423
|
-
`
|
|
424
|
-
|
|
425
|
-
|
|
506
|
+
`visualise_overlay` renders selections supplied in a `TransitionSystemOverlay`.
|
|
507
|
+
`visualise_reachability_step`, `visualise_invariant_step`, and
|
|
508
|
+
`visualise_invariant_result` turn analysis snapshots and results into the same
|
|
509
|
+
kind of graph. They accept the same three formatting callbacks and support
|
|
510
|
+
the same generic state, action, and proposition types.
|
|
426
511
|
|
|
427
512
|
```python
|
|
428
513
|
from mocha.visualisation import visualise_reachability_step
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
[](https://github.com/moves-rwth/mocha/actions/workflows/ci.yml)
|
|
4
4
|
|
|
5
5
|
MoChA is a small, typed Python library for representing labelled transition
|
|
6
|
-
systems and automata, checking reachability, invariants, persistence, and
|
|
7
|
-
properties, and parsing and transforming
|
|
6
|
+
systems and automata, checking reachability, invariants, persistence, and CTL
|
|
7
|
+
and LTL properties, and parsing and transforming temporal-logic formulas. Algorithm traces expose
|
|
8
8
|
intermediate steps for teaching and worked examples.
|
|
9
9
|
|
|
10
10
|
The public API is available from `mocha`: models, analysis results and traces,
|
|
11
11
|
algorithms, and parsing and JSON helpers. These names are also exported from
|
|
12
|
-
`mocha.models`, `mocha.algorithms`, and `mocha.io`. LTL formula constructors
|
|
13
|
-
live in `mocha.logic.ltl` (also available as `mocha.
|
|
12
|
+
`mocha.models`, `mocha.algorithms`, and `mocha.io`. CTL and LTL formula constructors
|
|
13
|
+
live in `mocha.logic.ctl` and `mocha.logic.ltl` (also available as `mocha.ctl`
|
|
14
|
+
and `mocha.ltl`), and rendering helpers
|
|
14
15
|
are exported from `mocha.visualisation` with the optional `visualization` extra.
|
|
15
16
|
|
|
16
17
|
## Install
|
|
@@ -138,16 +139,17 @@ predecessors with `pre(state, action=None)`, and iterate the relation with
|
|
|
138
139
|
|
|
139
140
|
## Reachability and Invariants
|
|
140
141
|
|
|
141
|
-
`compute_reachable_states`
|
|
142
|
-
including the initial states themselves. `check_invariant`
|
|
143
|
-
every reachable state belongs to a supplied set of allowed
|
|
144
|
-
result contains a path from an initial state to a violating
|
|
142
|
+
`compute_reachable_states` returns a `frozenset` of all states reachable from
|
|
143
|
+
any initial state, including the initial states themselves. `check_invariant`
|
|
144
|
+
checks whether every reachable state belongs to a supplied set of allowed
|
|
145
|
+
states. A failing result contains a path from an initial state to a violating
|
|
146
|
+
state:
|
|
145
147
|
|
|
146
148
|
```python
|
|
147
149
|
from mocha import check_invariant, compute_reachable_states, trace_reachability
|
|
148
150
|
|
|
149
151
|
reachable = compute_reachable_states(system)
|
|
150
|
-
assert reachable
|
|
152
|
+
assert reachable == {"idle", "running", "done"}
|
|
151
153
|
|
|
152
154
|
result = check_invariant(system, {"idle", "running"})
|
|
153
155
|
assert not result.satisfies
|
|
@@ -168,13 +170,16 @@ system remains unchanged; with no initial states, the result has no states.
|
|
|
168
170
|
from mocha import reduce_to_reachable
|
|
169
171
|
|
|
170
172
|
reduced = reduce_to_reachable(system)
|
|
171
|
-
assert reduced.states == reachable
|
|
173
|
+
assert reduced.states == reachable
|
|
172
174
|
```
|
|
173
175
|
|
|
174
176
|
`trace_reachability`, `trace_invariant`, and `trace_persistence` return an
|
|
175
177
|
`AlgorithmTrace` with the final `result` and an immutable tuple of `steps`.
|
|
176
178
|
The direct algorithms also accept an `on_step` callback to stream snapshots.
|
|
177
|
-
|
|
179
|
+
Algorithm-specific result and step classes are exported from `mocha` and
|
|
180
|
+
`mocha.algorithms`.
|
|
181
|
+
For reachability, `trace.result` is the reachable-state `frozenset` directly;
|
|
182
|
+
each `ReachabilityStep` still records its iteration and `reachable_states`.
|
|
178
183
|
|
|
179
184
|
For a complete invariant walkthrough, see
|
|
180
185
|
[examples/invariant_checking.py](https://github.com/moves-rwth/mocha/blob/main/examples/invariant_checking.py).
|
|
@@ -323,6 +328,66 @@ The automaton must declare its complete alphabet $2^{\mathrm{AP}}$, including
|
|
|
323
328
|
valuations that no system state currently uses. This follows the formal product
|
|
324
329
|
definition and makes a mismatched proposition vocabulary explicit.
|
|
325
330
|
|
|
331
|
+
## State and Path Formulas
|
|
332
|
+
|
|
333
|
+
`mocha.logic.StateFormula` and `mocha.logic.PathFormula` distinguish formulas
|
|
334
|
+
evaluated at a state from formulas evaluated along a path. Both inherit from
|
|
335
|
+
`Formula`. LTL syntax trees inherit from `PathFormula`.
|
|
336
|
+
|
|
337
|
+
CTL has separate `CTLStateFormula` and `CTLPathFormula` types in
|
|
338
|
+
`mocha.logic.ctl`, with `CTLFormula` as their common base. Propositions,
|
|
339
|
+
Boolean operations, and path quantifiers are state formulas. Temporal
|
|
340
|
+
operators are path formulas, and their operands must be CTL state formulas:
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
from mocha import parse_ctl
|
|
344
|
+
from mocha.logic.ctl import Exists, Next, Proposition, is_ctl_formula
|
|
345
|
+
|
|
346
|
+
formula = Exists(Next(Proposition("ready")))
|
|
347
|
+
assert formula == parse_ctl('EX "ready"')
|
|
348
|
+
assert is_ctl_formula(formula)
|
|
349
|
+
assert not is_ctl_formula(formula.operand) # A bare path is not a CTL state formula.
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
`Exists` and `ForAll` quantify path formulas built with `Next`, `Always`,
|
|
353
|
+
`Eventually`, `Until`, and `WeakUntil`. Temporal nesting passes through another
|
|
354
|
+
path quantifier: `AG AF "ready"` is valid CTL. Compact source notation such as
|
|
355
|
+
`EX "ready"` and `AG "ready"` is accepted by `parse_ctl`.
|
|
356
|
+
|
|
357
|
+
## CTL Model Checking
|
|
358
|
+
|
|
359
|
+
`model_check_ctl` computes the states satisfying a CTL formula. Parse or
|
|
360
|
+
construct the formula, explicitly rewrite it into existential normal form,
|
|
361
|
+
then check it. For example, every path in this system eventually reaches
|
|
362
|
+
`done`:
|
|
363
|
+
|
|
364
|
+
```python
|
|
365
|
+
from mocha import (
|
|
366
|
+
TransitionSystem, model_check_ctl, parse_ctl,
|
|
367
|
+
to_existential_normal_form,
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
ctl_system = TransitionSystem.from_edges(
|
|
371
|
+
states={"waiting", "done"},
|
|
372
|
+
edges={("waiting", "done"), ("done", "done")},
|
|
373
|
+
action="step", initial_states={"waiting"},
|
|
374
|
+
atomic_propositions={"done"}, labels={"done": {"done"}},
|
|
375
|
+
)
|
|
376
|
+
ctl_formula = parse_ctl('AF "done"')
|
|
377
|
+
ctl_enf = to_existential_normal_form(ctl_formula) # AF done ≡ ¬EG ¬done
|
|
378
|
+
ctl_result = model_check_ctl(ctl_system, ctl_enf)
|
|
379
|
+
assert ctl_result.satisfies
|
|
380
|
+
assert ctl_result.satisfying_states == {"waiting", "done"}
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
`satisfies` checks every initial state. CTL checking requires every state,
|
|
384
|
+
including unreachable ones, to have an outgoing transition and every formula
|
|
385
|
+
proposition to be declared in the system. The self-loop at `done` ensures
|
|
386
|
+
that paths continue infinitely.
|
|
387
|
+
|
|
388
|
+
The [CTL guide](https://github.com/moves-rwth/mocha/blob/main/docs/ctl.md)
|
|
389
|
+
explains formula syntax, existential normal form, rewrite traces, satisfaction
|
|
390
|
+
sets, and detailed model-checking traces.
|
|
326
391
|
|
|
327
392
|
## LTL Model Checking
|
|
328
393
|
|
|
@@ -373,10 +438,28 @@ graph = to_graphviz(system, highlighted_states={"running"})
|
|
|
373
438
|
graph.render("system", format="svg", cleanup=True)
|
|
374
439
|
```
|
|
375
440
|
|
|
376
|
-
`to_graphviz`
|
|
377
|
-
states
|
|
378
|
-
|
|
379
|
-
|
|
441
|
+
`to_graphviz` accepts arbitrary hashable states, actions, and propositions,
|
|
442
|
+
including integer states and product-state tuples. Values are displayed with
|
|
443
|
+
`str` by default. Supply `format_state`, `format_action`, and
|
|
444
|
+
`format_proposition` callbacks to customize their labels:
|
|
445
|
+
|
|
446
|
+
```python
|
|
447
|
+
integer_system = TransitionSystem.from_edges(
|
|
448
|
+
states={0, 1}, edges={(0, 1), (1, 1)}, action=2, initial_states={0},
|
|
449
|
+
atomic_propositions={3}, labels={1: {3}},
|
|
450
|
+
)
|
|
451
|
+
graph = to_graphviz(
|
|
452
|
+
integer_system,
|
|
453
|
+
format_state=lambda state: f"s{state}",
|
|
454
|
+
format_action=lambda action: f"a{action}",
|
|
455
|
+
format_proposition=lambda proposition: f"p{proposition}",
|
|
456
|
+
)
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
Formatted labels are literal text. Formatting preserves state identities,
|
|
460
|
+
including distinct states with equal displayed labels. Highlights refer to
|
|
461
|
+
original state and transition values. Actions connecting the same pair of
|
|
462
|
+
states share an edge label, with highlighted actions drawn on a separate edge.
|
|
380
463
|
|
|
381
464
|
The returned graph supports several output workflows:
|
|
382
465
|
|
|
@@ -390,9 +473,11 @@ In a Jupyter notebook, use `display(graph)` to show the graph inline.
|
|
|
390
473
|
Building the graph or saving DOT source requires the Python `graphviz`
|
|
391
474
|
package; rendering an image also needs the Graphviz executables.
|
|
392
475
|
|
|
393
|
-
`
|
|
394
|
-
|
|
395
|
-
|
|
476
|
+
`visualise_overlay` renders selections supplied in a `TransitionSystemOverlay`.
|
|
477
|
+
`visualise_reachability_step`, `visualise_invariant_step`, and
|
|
478
|
+
`visualise_invariant_result` turn analysis snapshots and results into the same
|
|
479
|
+
kind of graph. They accept the same three formatting callbacks and support
|
|
480
|
+
the same generic state, action, and proposition types.
|
|
396
481
|
|
|
397
482
|
```python
|
|
398
483
|
from mocha.visualisation import visualise_reachability_step
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# CTL Guide
|
|
2
|
+
|
|
3
|
+
[Back to the README](../README.md)
|
|
4
|
+
|
|
5
|
+
This guide covers parsing and transforming CTL formulas, checking a transition
|
|
6
|
+
system, and interpreting satisfaction sets and algorithm traces. Install MoChA
|
|
7
|
+
using the [README installation instructions](../README.md#install).
|
|
8
|
+
Run the Python snippets in order in the same session; later snippets reuse
|
|
9
|
+
earlier variables.
|
|
10
|
+
|
|
11
|
+
- [Formulas](#formulas)
|
|
12
|
+
- [Existential normal form](#existential-normal-form)
|
|
13
|
+
- [Transformation traces](#transformation-traces)
|
|
14
|
+
- [Model checking](#model-checking)
|
|
15
|
+
- [Satisfaction sets](#satisfaction-sets)
|
|
16
|
+
- [Model-checking traces](#model-checking-traces)
|
|
17
|
+
|
|
18
|
+
## Formulas
|
|
19
|
+
|
|
20
|
+
CTL formulas are immutable syntax trees defined in `mocha.logic.ctl`.
|
|
21
|
+
Parse them with `mocha.io.parse_ctl`; normal forms, model checking, and trace
|
|
22
|
+
helpers live in `mocha.algorithms`. These helpers are also available directly
|
|
23
|
+
from `mocha`.
|
|
24
|
+
|
|
25
|
+
Atomic proposition names require double quotes and use JSON string escaping.
|
|
26
|
+
The unquoted constants `true` and `false` are Boolean values; `"true"` and
|
|
27
|
+
`"false"` are proposition names. An optional vocabulary checks which names
|
|
28
|
+
are allowed:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from mocha import parse_ctl
|
|
32
|
+
from mocha.logic.ctl import Exists, Next, Proposition, is_ctl_formula
|
|
33
|
+
|
|
34
|
+
formula = parse_ctl('EX "ready"', atomic_propositions={"ready"})
|
|
35
|
+
assert formula == Exists(Next(Proposition("ready")))
|
|
36
|
+
assert is_ctl_formula(formula)
|
|
37
|
+
assert not is_ctl_formula(formula.operand) # A bare path is not a state formula.
|
|
38
|
+
assert parse_ctl(formula.to_source()) == formula
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Malformed syntax raises `CTLParseError` with a one-based line and column;
|
|
42
|
+
names outside the supplied vocabulary raise `ValueError`.
|
|
43
|
+
`str(formula)` uses textbook display notation and may omit proposition
|
|
44
|
+
quotes. Use `formula.to_source()` for text that can be parsed again.
|
|
45
|
+
|
|
46
|
+
`CTLStateFormula` represents propositions, Boolean operations, and path
|
|
47
|
+
quantifiers. `CTLPathFormula` represents one temporal operator with state
|
|
48
|
+
formulas as operands. Both inherit from `CTLFormula` and the corresponding
|
|
49
|
+
`mocha.logic.StateFormula` or `mocha.logic.PathFormula` base.
|
|
50
|
+
`Exists` (`E`) and `ForAll` (`A`) quantify each of these path operators:
|
|
51
|
+
|
|
52
|
+
| Path constructor | Meaning | Example source |
|
|
53
|
+
| --- | --- | --- |
|
|
54
|
+
| `Next(p)` | The next state satisfies `p`. | `EX "p"` |
|
|
55
|
+
| `Eventually(p)` | Some state, possibly the current one, satisfies `p`. | `AF "p"` |
|
|
56
|
+
| `Always(p)` | Every state, including the current one, satisfies `p`. | `EG "p"` |
|
|
57
|
+
| `Until(p, q)` | `q` eventually holds, and `p` holds at every earlier state. | `A("p" U "q")` |
|
|
58
|
+
| `WeakUntil(p, q)` | Until, also allowing `p` to hold forever without `q`. | `E("p" W "q")` |
|
|
59
|
+
|
|
60
|
+
Boolean syntax supports `!` (not) and `&`/`&&` (and). Negation and quantified
|
|
61
|
+
temporal operators bind more tightly than conjunction; parentheses group
|
|
62
|
+
state formulas. The parser also accepts `¬`, `∧`, `∃`, `∀`, `◯`/`○`, `◇`,
|
|
63
|
+
and `□`. Adjacent quantifier and temporal symbols are accepted: `EX "p"`
|
|
64
|
+
and `E X "p"` mean the same thing.
|
|
65
|
+
|
|
66
|
+
Temporal nesting passes through another path quantifier: `AG AF "p"` is
|
|
67
|
+
valid CTL. Constructors require state-formula operands, so an unquantified
|
|
68
|
+
nesting such as `Always(Next(p))` is rejected. `is_ctl_formula` checks the
|
|
69
|
+
supported fragment recursively, independently of normal form.
|
|
70
|
+
|
|
71
|
+
## Existential Normal Form
|
|
72
|
+
|
|
73
|
+
`to_existential_normal_form` rewrites a CTL state formula using only `true`,
|
|
74
|
+
propositions, `Not`, `And`, and `Exists` wrapping `Next`, `Until`, or `Always`.
|
|
75
|
+
Negation may apply to any state formula. The transformation eliminates
|
|
76
|
+
`false`, universal quantifiers, existential eventually, and existential weak
|
|
77
|
+
until. For example, `AF p` becomes `!EG !p`, and `EF p` becomes `E(true U p)`.
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from mocha import to_existential_normal_form
|
|
81
|
+
|
|
82
|
+
ctl_formula = parse_ctl('AF "done"')
|
|
83
|
+
ctl_enf = to_existential_normal_form(ctl_formula)
|
|
84
|
+
assert ctl_enf == parse_ctl('!EG !"done"')
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
These rewrites preserve meaning under infinite-path semantics. Parsing and
|
|
88
|
+
transforming a formula do not check a transition system. `model_check_ctl`
|
|
89
|
+
requires the ENF input explicitly; passing a non-ENF formula raises `ValueError`.
|
|
90
|
+
|
|
91
|
+
## Transformation Traces
|
|
92
|
+
|
|
93
|
+
`trace_existential_normal_form` returns an `AlgorithmTrace` with the
|
|
94
|
+
transformed formula in `result` and immutable `CTLRewriteStep` snapshots in
|
|
95
|
+
`steps`:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from mocha import trace_existential_normal_form
|
|
99
|
+
|
|
100
|
+
rewrite_trace = trace_existential_normal_form(ctl_formula)
|
|
101
|
+
assert rewrite_trace.result == ctl_enf
|
|
102
|
+
for step in rewrite_trace.steps:
|
|
103
|
+
print(step.iteration, step.rule, step.formula)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
The first step records the input formula. Each later step records one named
|
|
107
|
+
rewrite, the whole formula after that rewrite, and the changed subformula
|
|
108
|
+
in `before` and `after`. Its `path` identifies the location using `operand`,
|
|
109
|
+
`left`, and `right`. Paths include both the quantifier and temporal levels:
|
|
110
|
+
the proposition in `Exists(Next(p))` is at `("operand", "operand")`.
|
|
111
|
+
`to_existential_normal_form` also accepts an `on_step` callback to stream the
|
|
112
|
+
same snapshots.
|
|
113
|
+
|
|
114
|
+
## Model Checking
|
|
115
|
+
|
|
116
|
+
`model_check_ctl` computes satisfaction sets bottom-up for the ENF formula.
|
|
117
|
+
The transition system must have no terminal states, including unreachable
|
|
118
|
+
ones, and every proposition in the formula must be declared in the system's
|
|
119
|
+
`atomic_propositions`. Either violation raises `ValueError`.
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from mocha import TransitionSystem, model_check_ctl
|
|
123
|
+
|
|
124
|
+
ctl_system = TransitionSystem.from_edges(
|
|
125
|
+
states={"waiting", "done"},
|
|
126
|
+
edges={("waiting", "done"), ("done", "done")},
|
|
127
|
+
action="step", initial_states={"waiting"},
|
|
128
|
+
atomic_propositions={"done"}, labels={"done": {"done"}},
|
|
129
|
+
)
|
|
130
|
+
ctl_result = model_check_ctl(transition_system=ctl_system, formula=ctl_enf)
|
|
131
|
+
assert ctl_result.satisfies
|
|
132
|
+
assert ctl_result.satisfying_states == {"waiting", "done"}
|
|
133
|
+
assert not ctl_result.violating_initial_states
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
The self-loop at `done` ensures that paths continue infinitely.
|
|
137
|
+
`CTLModelCheckingResult.satisfies` is true when **every initial state** belongs
|
|
138
|
+
to `satisfying_states`; with no initial states, it is true vacuously.
|
|
139
|
+
`violating_initial_states` contains the initial states where the property
|
|
140
|
+
fails. Satisfaction sets cover all states, including unreachable ones.
|
|
141
|
+
The result's `formula` is the ENF formula passed to the checker.
|
|
142
|
+
|
|
143
|
+
## Satisfaction Sets
|
|
144
|
+
|
|
145
|
+
`subformula_sets` contains one `CTLSubformulaStep` per structurally distinct
|
|
146
|
+
state subformula of the ENF input, ordered with operands before their parents.
|
|
147
|
+
Each row includes its evaluation `rule`, operand sets in `premises`, and a
|
|
148
|
+
set-theoretic `explanation`:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
assert ctl_result.set_for(parse_ctl('"done"')) == {"done"}
|
|
152
|
+
for row in ctl_result.subformula_sets:
|
|
153
|
+
print(row.formula, row.satisfying_states, row.explanation)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
`set_for(formula)` looks up one of these sets and raises `KeyError` if the
|
|
157
|
+
formula has no row. Rewritten-away source formulas and bare path formulas
|
|
158
|
+
have no separate rows: the quantifier and its temporal operand form one
|
|
159
|
+
evaluation rule.
|
|
160
|
+
|
|
161
|
+
## Model-Checking Traces
|
|
162
|
+
|
|
163
|
+
`trace_ctl_model_checking` returns an `AlgorithmTrace` with the final `result`
|
|
164
|
+
and an immutable tuple of `steps`. Both it and `model_check_ctl` accept
|
|
165
|
+
`detail="sets"` (the default) or `detail="reasoning"`:
|
|
166
|
+
|
|
167
|
+
| Detail | Trace steps |
|
|
168
|
+
| --- | --- |
|
|
169
|
+
| `"sets"` | One `CTLSubformulaStep` for each distinct state subformula; these are also the result's `subformula_sets`. |
|
|
170
|
+
| `"reasoning"` | The same summary rows, plus `CTLPredecessorStep` successor checks for `EX` and `CTLFixedPointStep` search snapshots for `EU` and `EG`. |
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from mocha import CTLFixedPointStep, trace_ctl_model_checking
|
|
174
|
+
|
|
175
|
+
ctl_trace = trace_ctl_model_checking(
|
|
176
|
+
transition_system=ctl_system, formula=ctl_enf, detail="reasoning",
|
|
177
|
+
)
|
|
178
|
+
assert ctl_trace.result == ctl_result
|
|
179
|
+
for step in ctl_trace.steps:
|
|
180
|
+
if isinstance(step, CTLFixedPointStep):
|
|
181
|
+
print(step.iteration, step.approximation, step.pending_states)
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
For `EX`, each `CTLSuccessorCheck.matching_successors` contains the successors
|
|
185
|
+
satisfying the operand; an empty set explains why that state fails the check.
|
|
186
|
+
The `EU` and `EG` searches follow Algorithms 15 and 16 in *Principles of
|
|
187
|
+
Model Checking*. Their snapshots record `approximation` (`T`),
|
|
188
|
+
`pending_states` (`E`), `processed_state`, and added or removed states.
|
|
189
|
+
Iteration zero records initialization with `processed_state=None`; each later
|
|
190
|
+
snapshot follows processing one pending state. Pending states are selected
|
|
191
|
+
in arbitrary order, so intermediate snapshots can vary between runs.
|
|
192
|
+
|
|
193
|
+
For `EG`, `successor_counts` stores `(state, count)` pairs with
|
|
194
|
+
`count[s] = |Post(s) ∩ (T ∪ E)|` for every operand state. Its `checks` instead
|
|
195
|
+
show matching successors in the current `T`, so their sizes can differ from
|
|
196
|
+
the counters. For `EU`, `checks` records the processed successor witnessing
|
|
197
|
+
each newly added state.
|
|
198
|
+
|
|
199
|
+
To stream the same events without collecting a trace, pass an `on_step`
|
|
200
|
+
callback to `model_check_ctl`. Trace helpers retain all snapshots in memory.
|
|
201
|
+
Result and step types are exported from both `mocha` and `mocha.algorithms`.
|
|
@@ -167,14 +167,14 @@ a non-accepting sink for persistence search. `product_counterexample` retains
|
|
|
167
167
|
the automaton component of each path position; `counterexample` projects it
|
|
168
168
|
onto the original system while preserving the cycle boundary.
|
|
169
169
|
|
|
170
|
-
`
|
|
170
|
+
`trace_ltl` collects the steps for negation, GNBA translation, NBA
|
|
171
171
|
conversion, product construction, emptiness search, and the verdict. Detailed
|
|
172
172
|
translation and depth-first-search events are available in each step's `detail`:
|
|
173
173
|
|
|
174
174
|
```python
|
|
175
|
-
from mocha import
|
|
175
|
+
from mocha import trace_ltl
|
|
176
176
|
|
|
177
|
-
ltl_trace =
|
|
177
|
+
ltl_trace = trace_ltl(ltl_system, ltl_property)
|
|
178
178
|
assert not ltl_trace.result.satisfies
|
|
179
179
|
for step in ltl_trace.steps:
|
|
180
180
|
print(step.iteration, step.stage, step.message)
|