Propositional Formula¶
Overview¶
Lightweight propositional (LTL-style) formula objects and a deterministic finite automaton (DFA) whose transitions are guarded by those formulae.
- Core ideas:
A label is an iterable of atomic proposition names (strings).
A
Formulaimplements a satisfaction predicateFormula.sat().A DFA transition from \(q\) to \(q'\) is enabled when the edge guard formula is satisfied by the current label set.
DFACostFnwraps aDFAas a MASACostFnwhere the cost is1.0upon reaching accepting states (after stepping) and0.0otherwise.
This module is intentionally minimal: it does not implement full LTL temporal operators (X, U, F, G). Instead, it provides propositional guards for DFA edges, which is sufficient for DFA-based monitoring and safety cost construction.
API Reference¶
- class masa.common.ltl.Formula[source]¶
Bases:
objectBase class for propositional formulae over atomic proposition labels.
A formula is evaluated against a label set (an iterable of strings), and returns whether the formula is satisfied.
Subclasses must implement
sat(), which defines the satisfaction relation between the formula and a set of labels.Notes
The operators provided here are propositional (Boolean) connectives only. Temporal structure is represented externally via a
DFAthat consumes a trace of label sets.- sat(labels: Iterable[str]) bool[source]¶
Checks whether the formula is satisfied by the given labels.
- Parameters:
labels – Iterable of atomic proposition names that hold at the current step.
- Returns:
Trueif the formula is satisfied under the given labels.- Raises:
NotImplementedError – If the subclass does not implement the satisfaction relation.
- class masa.common.ltl.Atom(atom: str)[source]¶
Bases:
FormulaAtomic proposition.
An
Atomis satisfied iff the stored atomic proposition name appears in the given label set.- Variables:
atom – The atomic proposition name.
- class masa.common.ltl.Truth[source]¶
Bases:
FormulaConstant truth.
Always satisfied, regardless of the labels.
- class masa.common.ltl.And(subformula_1: Formula, subformula_2: Formula)[source]¶
Bases:
FormulaConjunction of two subformulae.
Satisfied iff both subformulae are satisfied.
- Variables:
subformula_1 – Left operand.
subformula_2 – Right operand.
- class masa.common.ltl.Or(subformula_1: Formula, subformula_2: Formula)[source]¶
Bases:
FormulaDisjunction of two subformulae.
Satisfied iff at least one subformula is satisfied.
- Variables:
subformula_1 – Left operand.
subformula_2 – Right operand.
- class masa.common.ltl.Neg(subformula: Formula)[source]¶
Bases:
FormulaNegation of a subformula.
Satisfied iff the subformula is not satisfied.
- Variables:
subformula – The formula being negated.
- class masa.common.ltl.Implies(subformula_1: Formula, subformula_2: Formula)[source]¶
Bases:
FormulaImplication between two subformulae.
Implies(a, b)is satisfied iff eitherais false orbis true under the given labels, i.e. it is equivalent to:\[\neg a \lor b\]- Variables:
subformula_1 – Antecedent (premise).
subformula_2 – Consequent (conclusion).