|
| 1 | +/- |
| 2 | +Copyright (c) 2026 Benjamin Brast-McKie. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Benjamin Brast-McKie |
| 5 | +-/ |
| 6 | + |
| 7 | +module |
| 8 | + |
| 9 | +public import Cslib.Init |
| 10 | +public import Cslib.Foundations.Logic.Connectives |
| 11 | +public import Cslib.Logics.Temporal.Syntax.Formula |
| 12 | + |
| 13 | +/-! # LTL Formula Type |
| 14 | +
|
| 15 | +This module defines the formula type for Linear Temporal Logic with primitives |
| 16 | +`{atom, bot, imp, next, untl}`. The primitive `next` operator is kept separate from |
| 17 | +`untl` following the Burgess convention: in full temporal logic, `next φ` is sometimes |
| 18 | +encoded as `φ U ⊥`, but this encoding does not hold in all models (it relies on |
| 19 | +discreteness and non-triviality). An independent primitive `next` avoids this coupling. |
| 20 | +
|
| 21 | +## Main definitions |
| 22 | +
|
| 23 | +- `Formula` : Inductive type for LTL formulas with constructors |
| 24 | + `atom`, `bot`, `imp`, `next`, `untl` |
| 25 | +- `Formula.someFuture` (𝐅): `φ U ⊤` — φ holds at some future point |
| 26 | +- `Formula.allFuture` (𝐆): `¬𝐅¬φ` — φ holds at all future points |
| 27 | +- `Formula.toTemporal` : Embedding of `LTL.Formula` into `Temporal.Formula` |
| 28 | +
|
| 29 | +## Notation |
| 30 | +
|
| 31 | +Propositional connectives (scoped to `Cslib.Logic.LTL`): |
| 32 | +- `¬` (prefix, 40) : negation (`Formula.neg`) |
| 33 | +- `∧` (infix, 36) : conjunction (`Formula.and`) |
| 34 | +- `∨` (infix, 35) : disjunction (`Formula.or`) |
| 35 | +- `→` (infix, 30) : implication (`Formula.imp`) |
| 36 | +- `↔` (infix, 30) : biconditional (`Formula.iff`) |
| 37 | +
|
| 38 | +Temporal operators (scoped to `Cslib.Logic.LTL`): |
| 39 | +- `U` (infix, 40) : until (`Formula.untl`) |
| 40 | +- `X` (prefix, 40) : next-step (`Formula.next`) |
| 41 | +- `𝐅` (prefix, 40) : some future / eventually (`Formula.someFuture`) |
| 42 | +- `𝐆` (prefix, 40) : all future / globally (`Formula.allFuture`) |
| 43 | +
|
| 44 | +## Derived Operators |
| 45 | +
|
| 46 | +Derived operators follow the Burgess convention: in `untl event guard`, the first argument |
| 47 | +is the **event** (holds at the witness point) and the second is the **guard** (holds at all |
| 48 | +intermediate points). `someFuture φ` is `φ U ⊤` (φ is the event, ⊤ is the trivial guard). |
| 49 | +
|
| 50 | +## References |
| 51 | +
|
| 52 | +* [A. Pnueli, *The Temporal Logic of Programs*][Pnueli1977] |
| 53 | +* [H. Kamp, *Tense Logic and the Theory of Linear Order*][Kamp1968] |
| 54 | +* [J. P. Burgess, *Basic Tense Logic*][Burgess1984] |
| 55 | +* [M. Y. Vardi, P. Wolper, |
| 56 | + *An automata-theoretic approach to automatic program verification*][VardiWolper1986] |
| 57 | +-/ |
| 58 | + |
| 59 | +@[expose] public section |
| 60 | + |
| 61 | +namespace Cslib.Logic.LTL |
| 62 | + |
| 63 | +/-- LTL formula type. Primitives: atoms, falsum, implication, next-step, and until. |
| 64 | +
|
| 65 | +`next` is a primitive constructor and is not derived from `untl`. The encoding |
| 66 | +`next φ = φ U ⊥` holds on discrete non-ending sequences but fails in general temporal |
| 67 | +models; keeping `next` primitive supports broader model classes. -/ |
| 68 | +inductive Formula (Atom : Type u) : Type u where |
| 69 | + /-- Atomic proposition. -/ |
| 70 | + | atom (p : Atom) |
| 71 | + /-- Falsum / bottom. -/ |
| 72 | + | bot |
| 73 | + /-- Implication. -/ |
| 74 | + | imp (φ₁ φ₂ : Formula Atom) |
| 75 | + /-- Next-step operator: Xφ holds at t iff φ holds at t+1. -/ |
| 76 | + | next (φ : Formula Atom) |
| 77 | + /-- Until temporal operator: φ₁ U φ₂ (Burgess: event U guard). -/ |
| 78 | + | untl (φ₁ φ₂ : Formula Atom) |
| 79 | +deriving DecidableEq, BEq |
| 80 | + |
| 81 | +/-- Negation: ¬φ := φ → ⊥ -/ |
| 82 | +abbrev Formula.neg (φ : Formula Atom) : Formula Atom := .imp φ .bot |
| 83 | + |
| 84 | +/-- Verum / top: ⊤ := ⊥ → ⊥ -/ |
| 85 | +abbrev Formula.top : Formula Atom := .imp .bot .bot |
| 86 | + |
| 87 | +/-- Disjunction: φ₁ ∨ φ₂ := ¬φ₁ → φ₂ -/ |
| 88 | +abbrev Formula.or (φ₁ φ₂ : Formula Atom) : Formula Atom := |
| 89 | + .imp (.imp φ₁ .bot) φ₂ |
| 90 | + |
| 91 | +/-- Conjunction: φ₁ ∧ φ₂ := ¬(φ₁ → ¬φ₂) -/ |
| 92 | +abbrev Formula.and (φ₁ φ₂ : Formula Atom) : Formula Atom := |
| 93 | + .imp (.imp φ₁ (.imp φ₂ .bot)) .bot |
| 94 | + |
| 95 | +/-- Biconditional: φ₁ ↔ φ₂ := (φ₁ → φ₂) ∧ (φ₂ → φ₁) -/ |
| 96 | +abbrev Formula.iff (φ₁ φ₂ : Formula Atom) : Formula Atom := |
| 97 | + (φ₁.imp φ₂).and (φ₂.imp φ₁) |
| 98 | + |
| 99 | +/-- Some future (eventually): F φ := φ U ⊤. |
| 100 | + Uses Burgess convention: φ is the event (holds at witness), ⊤ is the trivial guard. -/ |
| 101 | +abbrev Formula.someFuture (φ : Formula Atom) : Formula Atom := |
| 102 | + .untl φ .top |
| 103 | + |
| 104 | +/-- All future (globally): G φ := ¬F ¬φ -/ |
| 105 | +abbrev Formula.allFuture (φ : Formula Atom) : Formula Atom := |
| 106 | + .neg (.someFuture (.neg φ)) |
| 107 | + |
| 108 | +@[inherit_doc] scoped prefix:40 "¬" => Formula.neg |
| 109 | +@[inherit_doc] scoped infix:36 " ∧ " => Formula.and |
| 110 | +@[inherit_doc] scoped infix:35 " ∨ " => Formula.or |
| 111 | +@[inherit_doc] scoped infix:30 " → " => Formula.imp |
| 112 | +@[inherit_doc] scoped infix:30 " ↔ " => Formula.iff |
| 113 | +@[inherit_doc] scoped infix:40 " U " => Formula.untl |
| 114 | +@[inherit_doc] scoped prefix:40 "X" => Formula.next |
| 115 | +@[inherit_doc] scoped prefix:40 "𝐅" => Formula.someFuture |
| 116 | +@[inherit_doc] scoped prefix:40 "𝐆" => Formula.allFuture |
| 117 | + |
| 118 | +/-- Register `LTL.Formula` as an instance of `LTLConnectives`. -/ |
| 119 | +instance : LTLConnectives (Formula Atom) where |
| 120 | + bot := .bot |
| 121 | + imp := .imp |
| 122 | + untl := .untl |
| 123 | + next := .next |
| 124 | + |
| 125 | +instance : Bot (Formula Atom) := ⟨.bot⟩ |
| 126 | +instance : Top (Formula Atom) := ⟨.top⟩ |
| 127 | + |
| 128 | +/-- Embed `LTL.Formula` into `Temporal.Formula`. Translates `next φ` as `φ U ⊥` |
| 129 | +(strict until forces the immediate successor on ℕ) and `untl` as reflexive until. -/ |
| 130 | +def Formula.toTemporal : Formula Atom → Temporal.Formula Atom |
| 131 | + | .atom p => .atom p |
| 132 | + | .bot => .bot |
| 133 | + | .imp φ ψ => .imp (toTemporal φ) (toTemporal ψ) |
| 134 | + | .next φ => .untl (toTemporal φ) .bot |
| 135 | + | .untl φ ψ => (toTemporal φ).reflexiveUntl (toTemporal ψ) |
| 136 | + |
| 137 | +end Cslib.Logic.LTL |
| 138 | + |
| 139 | +end |
0 commit comments