Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/dev/config-and-provenance.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,4 @@ Rows dated before 2026-10-29, with the notes on the selection renames and the va
| 2026-11-18 | `mutation.gate_realizable` | added at `"exchange"` (was `"towards"` before the key existed) | Moves only runs with `direction_gated` on: a realisable parent now takes one step towards the original and weakens one slot still equal to it, instead of only stepping back. A config that sets `direction_gated = true` without the key, such as those of `2026-11-05-fretish-order`, now runs exchange; write `gate_realizable = "towards"` to reproduce it. With the gate off, the default since the key was added, the key is never read and every archive reproduces seed for seed. `mutation.blame_realizable` was added at `true`, which behaves as before. |
| 2026-11-19 | `filters.climb_orders` | re-added at `1` | Restores the hash-priority restarts of the output climb that the 2026-11-18 row removed; `filters.climb_order` stays retired. At 1 the climb runs once per repair in slot order, as it did while the key was retired, so every archive reproduces as before and the determinism goldens did not move. The order of each extra climb draws no random number. |
| 2026-11-19 | `genetic.maximality_removal` | added at `false` | Ported from `feat/demotion-removal` (5e94f6b5), which the 2026-11-17 and 2026-11-18 removal campaigns ran from their own branches. Acts only with `maximality_demotion` on, and is rejected without it. At `false` selection is unchanged, so every archive reproduces seed for seed with the key omitted. |
| 2026-11-24 | — (example) | `examples/ventilator-controller` re-imported with formula modes | The 10 fresh `mode_*` output atoms and their 10 non-weakenable definitions are gone: each of the 11 formula-mode scopes now names its formula, and the spec has 58 guarantees, 53 outputs and 10 modes where it had 68, 63 and 20. Every other guarantee, the assumption and the inputs are unchanged, and each of the 58 remaining guarantees is equivalent under `ltlfilt` to its old form with the `mode_*` atom replaced by its definition. A campaign on `ventilator-controller` before this date ran the old spec, which its recorded commit and provenance tag still check out; a new run on it is not comparable with those. No other example has a formula mode, and the determinism goldens did not move. See "FRETISH scopes" in `docs/dev/fretish-scopes.md`. |
6 changes: 4 additions & 2 deletions docs/dev/fretish-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ The scope field of a FRETISH requirement: its lowering, its validation against t

## FRETISH scopes

`Requirement::m_scope` (`include/requirement.hpp`) is FRET's fifth field, the interval over which a requirement is enforced relative to when a *mode* holds. `ScopeKind` has eight values, every scope FRETISH text can reach: Global (the default), In, NotIn, Before, After, OnlyIn, OnlyBefore and OnlyAfter. The spellings are `in m` (also `during`, `while`), `except in m` (also `unless in`, `when not in`), `before m`, `after m`, `only in m`, `only before m` and `only after m`. A bare `not in` is a parse error, as is a formula mode such as `in (a & b)`.
`Requirement::m_scope` (`include/requirement.hpp`) is FRET's fifth field, the interval over which a requirement is enforced relative to when a *mode* holds. `ScopeKind` has eight values, every scope FRETISH text can reach: Global (the default), In, NotIn, Before, After, OnlyIn, OnlyBefore and OnlyAfter. The spellings are `in m` (also `during`, `while`), `except in m` (also `unless in`, `when not in`), `before m`, `after m`, `only in m`, `only before m` and `only after m`. A bare `not in` is a parse error.

The lowering is in `src/requirement.cpp`. Each scope adds an outer wrapper and a boundary marker `B` that discharges a bounded obligation early: `EoM = (m & X!m)` for In and OnlyAfter, `SoM = (!m & X(m))` for NotIn, Before and OnlyIn, and none for Global, After and OnlyBefore. The operand of `X` is always parenthesised in the rendered text: SPOT reads `Xm` as `X(m)`, but PEREDUR's own parser and black read it as one atom `Xm`, which until this was fixed made the fingerprint prefilter refute true implications on every mode-scoped spec; `test_scope_lowering_parses_to_its_own_atoms` pins it. Under `B`, `G r` becomes `B R r`, `F r` becomes `!B U r`, `X r` becomes `B | X r`, `F[0,n] r` becomes `F[0,n] r | F[0,n-1] B`, `G[0,n] r` becomes `G[0,n] r | (B R r)`, `r W s` (until) becomes `(r W s) | (B R r)`, and `r R !s` (before) becomes `(r | B) R !s`. The continual wrapper `G(c -> body)` becomes `B R (c -> body)`, and the trigger wrapper also conjoins `!B` into its rising edge. The three `only` scopes apply the dual scope's wrapper to the De Morgan dual of the body. For until and before the dual is FRET's pairing, `before s` over `!r` for `until s` and back, which is not the logical complement on an unbounded interval: `!(r W s)` and `(!r) R (!s)` differ.

Expand All @@ -16,7 +16,9 @@ The lowering is in `src/requirement.cpp`. Each scope adds an outer wrapper and a

**An output mode gives the system a gutting move.** `G !mode` implies every `In`-scoped guarantee on that mode, and holding the mode at t=0 discharges every `Before`-scoped one. FRET specifications need the output side anyway, since the ventilator's controller sets its own operating mode (`CONT1`, `CONT46`), and there the requirements that drive the mode are what block the move. Nothing in the search stops a repair from weakening those requirements and then exploiting the move, so repairs of a specification with output modes need checking for it.

**A mode is an atom of the lowered formula that sits in no `Formula` field, and the counting path had to be told.** `count_joint_atoms` (`src/fitness/transfer_matrix.cpp`) once left the mode out of `n_total_atoms`, so `free_count` in `count_guard_models` wrapped on `std::size_t` and `mul_pow2` hit the overflow assertion. It is asserted rather than clamped, since a wrong free count is a wrong trace count nothing else catches. Any future field carrying an atom outside `m_condition`/`m_response` meets the same trap.
**A mode is an atom of the lowered formula that sits in no `Formula` field, and the counting path had to be told.** `count_joint_atoms` (`src/fitness/transfer_matrix.cpp`) once left the mode out of `n_total_atoms`, so `free_count` in `count_guard_models` wrapped on `std::size_t` and `mul_pow2` hit the overflow assertion. It is asserted rather than clamped, since a wrong free count is a wrong trace count nothing else catches. Any future field carrying an atom outside `m_condition`/`m_response` meets the same trap, and a formula mode adds each of its atoms through `scope_mode_atoms`.

**A mode may be a propositional formula, such as `in (pcv_mode | psv_mode)`.** `Scope::m_mode` stays a string. A bare mode is one signal name (`is_bare_mode`), must be in `modes`, and lowers, hashes and serialises exactly as before formula modes, so no golden moved. A formula mode is held in `Formula::to_string` spelling, `(pcv_mode) | (psv_mode)`, which `canonical_mode` gives it at load, so one formula has one string however its source was bracketed. Each of its atoms must be in `modes`, `in_atoms` or `out_atoms`, and a temporal or malformed one is rejected at load. The lowering brackets it wherever the templates place the mode (`mode_operand` in `src/requirement.cpp`), so it is the bare-mode lowering with the formula substituted, which `test_formula_mode_lowering_substitutes_the_formula` pins; `add_atom_prefix` tags every atom inside it. A pure mode that occurs only inside formulas is still in `modes`, so `environment_signals()` still puts it on the input side, and a formula mode is never itself in `modes`: no scope move onto a Global requirement draws it, and a move between scoped kinds carries it unchanged, as it carries a bare mode. The similarity scope term and the implication check compare the mode string, so two formula modes are the same mode only when their canonical strings are equal; `scripts/import_fret.py` sorts each chain of `&` and `|`, so `a | b` and `b | a` import as one. On the ventilator's 11 formula-mode requirements, PEREDUR's LTL is equivalent under `ltlfilt` to FRET's `ftExpanded` at ordinal ticks. Before 2026-11-24 the importer named each formula mode by a fresh output atom with a non-weakenable definition `G(atom <-> formula)`; the realisability verdict is the same either way, since the system can always set the atom to the formula's value, but the fresh atoms joined the mutation pool, the similarity term saw a formula mode and its operands as unrelated modes, and the atoms counted as free wherever a count left out the definition.

**No mode axiom is generated.** FRET keeps mode exclusivity in variable definitions the `formalize` path never sees, so it is written as an ordinary non-weakenable requirement, as in `examples/fsm-combined/spec.json`.

Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ Some ideals in `fixes/` are the reference repairs from the AuRUS repository, and
| `liquid-mixer` | The liquid mixer of Mavridou et al. (FM 2021), Table 1. |
| `rad` | The Robot-Assisted Dressing case study of the CRADLE project ([cradlerobotics/RAD](https://github.com/cradlerobotics/RAD), commit `5ab8545`), from Chakraborty, Rafiq, Taylor and Farrell, "Plenty to FRET About: From Hazard Analysis to Formal Requirements for Robot-Assisted Dressing" (FMAS 2026), which formalises the requirements of Taylor et al., "All Dressed Up: Requirements for Human-Robot Teamwork" (ISoLA 2026). Five of its six FRET project exports are imported. |
| `valu3s-uc6` | The FRET project "VALU3S Use Case 6" (an agricultural robot), built to demonstrate Mu-FRET (Luckcuck, Sheridan, Farrell and Monahan, "Mu-FRET: A Catalogue and Tool for Requirement Refactoring", SoSyM 2026). It was imported from a private copy; the same set is public as `UseCase6.json` in [valu3s-mu/FRETISH-requirements](https://github.com/valu3s-mu/FRETISH-requirements). |
| `ventilator-controller` | The Controller component of the FRET project "Ventilator v0.6.1", from Farrell, Luckcuck, Monahan, Reynolds and Sheridan, "FRETting and Formal Modelling: A Mechanical Lung Ventilator" (ABZ 2024). |
| `ventilator-controller` | The Controller component of the FRET project "Ventilator v0.6.1", from Farrell, Luckcuck, Monahan, Reynolds and Sheridan, "FRETting and Formal Modelling: A Mechanical Lung Ventilator" (ABZ 2024). Its 11 formula-mode scopes, such as `in (PCVMode \| PSVMode)`, are formula modes; before 2026-11-24 each was a fresh `mode_*` output atom with a definition guarantee, which gave 68 guarantees and 63 outputs where there are now 58 and 53. |

The FRET exports were converted with `scripts/import_fret.py`, whose docstring lists every conversion rule.
132 changes: 11 additions & 121 deletions examples/ventilator-controller/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
},
"scope": {
"type": "In",
"mode": "mode_psv_mode_and_inspiratory_pause_button"
"mode": "(inspiratory_pause_button) & (psv_mode)"
}
},
{
Expand All @@ -127,7 +127,7 @@
},
"scope": {
"type": "In",
"mode": "mode_start_up_mode_or_standby_mode"
"mode": "(standby_mode) | (start_up_mode)"
}
},
{
Expand All @@ -139,7 +139,7 @@
},
"scope": {
"type": "In",
"mode": "mode_pcv_mode_or_psv_mode"
"mode": "(pcv_mode) | (psv_mode)"
}
},
{
Expand Down Expand Up @@ -209,7 +209,7 @@
},
"scope": {
"type": "In",
"mode": "mode_psv_mode_and_rm_button"
"mode": "(psv_mode) & (rm_button)"
}
},
{
Expand All @@ -235,7 +235,7 @@
},
"scope": {
"type": "In",
"mode": "mode_pcv_mode_and_inspiratory_pause_button"
"mode": "(inspiratory_pause_button) & (pcv_mode)"
}
},
{
Expand Down Expand Up @@ -268,7 +268,7 @@
},
"scope": {
"type": "In",
"mode": "mode_pcv_mode_or_psv_mode"
"mode": "(pcv_mode) | (psv_mode)"
}
},
{
Expand Down Expand Up @@ -316,7 +316,7 @@
},
"scope": {
"type": "In",
"mode": "mode_pcv_mode_or_psv_mode_and_rm_button_and_not_inspiratory_pause_button"
"mode": "((!(inspiratory_pause_button)) & ((pcv_mode) | (psv_mode))) & (rm_button)"
}
},
{
Expand All @@ -340,7 +340,7 @@
},
"scope": {
"type": "In",
"mode": "mode_pcv_mode_and_rm_button"
"mode": "(pcv_mode) & (rm_button)"
}
},
{
Expand All @@ -352,7 +352,7 @@
},
"scope": {
"type": "In",
"mode": "mode_pcv_mode_or_psv_mode_and_expiratory_pause_button"
"mode": "((pcv_mode) | (psv_mode)) & (expiratory_pause_button)"
}
},
{
Expand Down Expand Up @@ -388,7 +388,7 @@
},
"scope": {
"type": "In",
"mode": "mode_pcv_mode_or_psv_mode_and_inspiratory_pause_button"
"mode": "((pcv_mode) | (psv_mode)) & (inspiratory_pause_button)"
}
},
{
Expand Down Expand Up @@ -595,7 +595,7 @@
},
"scope": {
"type": "In",
"mode": "mode_psv_mode_and_expiratory_phase"
"mode": "(expiratory_phase) & (psv_mode)"
}
},
{
Expand Down Expand Up @@ -662,96 +662,6 @@
"mode": "final_state"
}
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_pcv_mode_and_inspiratory_pause_button <-> (pcv_mode & inspiratory_pause_button)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_pcv_mode_and_rm_button <-> (pcv_mode & rm_button)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_pcv_mode_or_psv_mode <-> (pcv_mode | psv_mode)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_pcv_mode_or_psv_mode_and_expiratory_pause_button <-> (( pcv_mode | psv_mode ) & expiratory_pause_button)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_pcv_mode_or_psv_mode_and_inspiratory_pause_button <-> (( pcv_mode | psv_mode ) & inspiratory_pause_button)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_pcv_mode_or_psv_mode_and_rm_button_and_not_inspiratory_pause_button <-> (( pcv_mode | psv_mode ) & rm_button & ! inspiratory_pause_button)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_psv_mode_and_expiratory_phase <-> (psv_mode & expiratory_phase)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_psv_mode_and_inspiratory_pause_button <-> (psv_mode & inspiratory_pause_button)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_psv_mode_and_rm_button <-> (psv_mode & rm_button)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
"response": "mode_start_up_mode_or_standby_mode <-> (start_up_mode | standby_mode)",
"timing": {
"type": "Always"
},
"weakenable": false
},
{
"condition": "true",
"condition-type": "continual",
Expand Down Expand Up @@ -829,16 +739,6 @@
"min_expiratory_time_eq_insp_clock_div_2",
"min_expiratory_time_ge_0p4",
"min_expiratory_time_le_2",
"mode_pcv_mode_and_inspiratory_pause_button",
"mode_pcv_mode_and_rm_button",
"mode_pcv_mode_or_psv_mode",
"mode_pcv_mode_or_psv_mode_and_expiratory_pause_button",
"mode_pcv_mode_or_psv_mode_and_inspiratory_pause_button",
"mode_pcv_mode_or_psv_mode_and_rm_button_and_not_inspiratory_pause_button",
"mode_psv_mode_and_expiratory_phase",
"mode_psv_mode_and_inspiratory_pause_button",
"mode_psv_mode_and_rm_button",
"mode_start_up_mode_or_standby_mode",
"monitor_inhale_trigger",
"off",
"out_of_service_warning",
Expand Down Expand Up @@ -869,16 +769,6 @@
"fail_safe_mode",
"final_state",
"inspiratory_phase",
"mode_pcv_mode_and_inspiratory_pause_button",
"mode_pcv_mode_and_rm_button",
"mode_pcv_mode_or_psv_mode",
"mode_pcv_mode_or_psv_mode_and_expiratory_pause_button",
"mode_pcv_mode_or_psv_mode_and_inspiratory_pause_button",
"mode_pcv_mode_or_psv_mode_and_rm_button_and_not_inspiratory_pause_button",
"mode_psv_mode_and_expiratory_phase",
"mode_psv_mode_and_inspiratory_pause_button",
"mode_psv_mode_and_rm_button",
"mode_start_up_mode_or_standby_mode",
"pcv_mode",
"psv_mode",
"rm",
Expand Down
25 changes: 22 additions & 3 deletions include/requirement.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,15 @@ enum class ScopeKind : std::uint8_t {
};

/// A scope kind together with the mode it is relative to. `Global` carries an
/// empty mode; every other kind requires one, and that mode must be declared in
/// `Specification::m_modes`.
/// empty mode; every other kind requires one. A bare mode is one signal name,
/// which must be declared in `Specification::m_modes`. A formula mode such as
/// `(a) | (b)` is a propositional formula over declared signals, each in
/// `m_modes`, `m_in_atoms` or `m_out_atoms`, held in `Formula::to_string`
/// spelling (see `canonical_mode`).
struct Scope {
ScopeKind m_kind = ScopeKind::Global;
/// Name of the mode. Empty exactly when `m_kind` is `Global`.
/// The mode: a signal name or a formula. Empty exactly when `m_kind` is
/// `Global`.
std::string m_mode;

friend bool operator<(const Scope& lhs, const Scope& rhs);
Expand All @@ -145,6 +149,21 @@ struct Scope {
[[nodiscard]] bool is_global() const { return m_kind == ScopeKind::Global; }
};

/// True when @p mode is a single signal name, the only form a mode took before
/// formula modes. Every bare mode lowers, hashes and serialises as it did then.
bool is_bare_mode(const std::string& mode);

/// The stored spelling of the mode @p mode: a bare name unchanged, a formula
/// in `Formula::to_string` form, so one formula has one spelling however its
/// source was bracketed.
/// @throws std::invalid_argument when @p mode is neither a name nor a
/// propositional formula.
std::string canonical_mode(const std::string& mode);

/// Every signal the scope's mode mentions, without the constants: the mode
/// itself when bare, nothing for `Global`.
std::vector<std::string> scope_mode_atoms(const Scope& scope);

/// True for the three "only" scopes, whose lowering negates the requirement's
/// obligation and applies it outside the named interval.
bool is_only_scope(ScopeKind kind);
Expand Down
Loading
Loading