Skip to content

Commit 27e1d24

Browse files
committed
documentation
1 parent d685fd2 commit 27e1d24

File tree

12 files changed

+493
-44
lines changed

12 files changed

+493
-44
lines changed

LeanMachines/Event/Ordinary.lean

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ import LeanMachines.Algebra.Arrow
1010
1111
This module defines the user-level API for constructing
1212
and manipulating **ordinary deterministic** events.
13+
1314
In LeanMachines, an event is said **ordinary** if it
1415
is not demonstrated anticipated or convergent
1516
(cf. `Event.Convergent` module).
1617
17-
**Remark**: there is an alternative notion of ordinary events
18-
in B-classic.
19-
2018
-/
2119

2220
/-- The internal representation of proof obligations for ordinary

LeanMachines/Refinement/Functional/Basic.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ refinement principles for LeanMachines.
1111
-/
1212

1313
/-!
14-
1514
## Machine refinement
16-
1715
-/
1816

1917
/-- The typeclass definition for the functional refinement
@@ -61,6 +59,8 @@ by
6159
6260
For functional refinement, the event specifications are prefixed with by `FR`.
6361
62+
cf. the module `Refinement.Refinement.Basic` for further documentation.
63+
6464
-/
6565

6666
/-- Specification of ordinary refined events.

LeanMachines/Refinement/Relational/Abstract.lean

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ structure AbstractInitREventSpec (AM) [Machine ACTX AM]
218218
{α β} (abstract : InitEvent AM α β)
219219
extends _AbstractREventSpec AM M α where
220220

221-
/-- Proof obligation: lifting, then unlifting is safe wrt. the `refine` invariant. -/
221+
/-- Proof obligation: unlifting abstract state change is safe wrt. the `refine` invariant. -/
222222
step_ref (x : α):
223223
abstract.guard x
224224
let (_, am') := abstract.init x
@@ -300,7 +300,7 @@ def AbstractInitREventSpec''.toAbstractInitREventSpec [Machine ACTX AM] [Machine
300300
step_safe := fun () => ev.step_safe
301301
}
302302

303-
/-- Variant of `newAbstractREvent` with implicit `Unit` input and output types -/
303+
/-- Variant of `newAbstractInitREvent` with implicit `Unit` input and output types -/
304304
@[simp]
305305
def newAbstractRInitEvent'' [Machine ACTX AM] [Machine CTX M] [Refinement AM M]
306306
(abs : InitEvent AM Unit Unit) (ev : AbstractInitREventSpec'' AM M abs) : InitREvent AM M Unit Unit :=

LeanMachines/Refinement/Relational/Basic.lean

+9-4
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,22 @@ structure REventSpec (AM) [Machine ACTX AM] (M) [Machine CTX M] [instR: Refineme
124124
{α β α' β'} (abs : OrdinaryEvent AM α' β')
125125
extends EventSpec M α β where
126126

127+
/-- Transformation of input parameters: how a concrete parameter must be interpreted
128+
at the abstract level. -/
127129
lift_in : α → α'
130+
131+
/-- Transformation of output value: how a concrete output must be interpreted
132+
at the abstract level. -/
128133
lift_out : β → β'
129134

135+
/-- Proof obligation: guard strengthening. -/
130136
strengthening (m : M) (x : α):
131137
Machine.invariant m
132138
→ guard m x
133139
→ ∀ am, refine am m
134140
→ abs.guard am (lift_in x)
135141

142+
/-- Proof obligation: action simulation. -/
136143
simulation (m : M) (x : α):
137144
Machine.invariant m
138145
→ guard m x
@@ -234,9 +241,7 @@ def newREvent'' [Machine ACTX AM] [Machine CTX M] [Refinement AM M]
234241
newREvent abs ev.toREventSpec
235242

236243
/-!
237-
238244
### Ordinary initialization events
239-
240245
-/
241246

242247
/-- Internal representation of proof obligations for ordinary initialization events. -/
@@ -330,7 +335,7 @@ def newInitREvent [Machine ACTX AM] [Machine CTX M] [Refinement AM M]
330335
}
331336
}
332337

333-
/-- Variant of `REventSpec'` with implicit `Unit` output type -/
338+
/-- Variant of `InitREventSpec` with implicit `Unit` output type -/
334339
structure InitREventSpec' (AM) [Machine ACTX AM] (M) [Machine CTX M] [instR: Refinement AM M]
335340
{α α'} (abstract : InitEvent AM α' Unit)
336341
extends InitEventSpec' M α where
@@ -365,7 +370,7 @@ def newInitREvent' [Machine ACTX AM] [Machine CTX M] [Refinement AM M]
365370
(ev : InitREventSpec' AM M (α:=α) (α':=α') abs) : InitREvent AM M α Unit α' Unit :=
366371
newInitREvent abs ev.toInitREventSpec
367372

368-
/-- Variant of `REventSpec` with implicit `Unit` input and output types -/
373+
/-- Variant of `InitREventSpec` with implicit `Unit` input and output types -/
369374
structure InitREventSpec'' (AM) [Machine ACTX AM] (M) [Machine CTX M] [instR: Refinement AM M]
370375
(abstract : InitEvent AM Unit Unit)
371376
extends InitEventSpec'' M where

LeanMachines/Refinement/Relational/Convergent.lean

+12-21
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,7 @@ convergent events.
1111
1212
This builds on the well-founded ordering relations of Mathlib4,
1313
which means convergence is not restricted to e.g. natural number
14-
of finite set orderings.
15-
16-
Technically, anticipated and convergence event specifications depend
17-
on a component `variant` of type `v`. For anticipated events, the
18-
type `v` must be instance of Mathlib's `Preorder` typeclass, with
19-
the usual requirements of preordering: reflexivity and transitivity.
20-
For convergent events, the subclass `WellFoundedLT` must also be
21-
instantiated, with the main requirement that the "lower than" relation
22-
(denoted by `LT.lt` or more simply `·<·`) of the preorder is well-founded.
23-
See Mathlib's documentation about these typeclasses for details.
24-
25-
*Remark*: One drawback is that Mathlib4 is then a (rather large) dependency
26-
but building on such a rich mathematical toolkit is more of an
27-
asset than an hindrance.
14+
of finite set orderings (cf. module `Event.Convergent`).
2815
2916
-/
3017

@@ -45,7 +32,7 @@ structure _AnticipatedREventPO (v) [Preorder v] [Machine ACTX AM] [Machine CTX
4532
let (_, m') := ev.action m x
4633
variant m' ≤ variant m
4734

48-
/-- The representation of anticipated events, constructed
35+
/-- The representation of anticipated refined events, constructed
4936
by specifications structures, e.g. `AnticipatedREventSpec`,
5037
and smart constructors, e.g. `newAnticipatedREvent`. -/
5138
structure AnticipatedREvent (v) [Preorder v] (AM) [Machine ACTX AM] (M) [Machine CTX M] [instR: Refinement AM M]
@@ -83,6 +70,7 @@ structure AnticipatedREventSpec (v) [Preorder v] (AM) [Machine ACTX AM] (M) [Mac
8370
{α β α' β'} (abs : OrdinaryEvent AM α' β')
8471
extends _Variant v, REventSpec AM M (α:=α) (β:=β) (α':=α') (β':=β') abs where
8572

73+
/-- Proof obligation: the variant does not increases. -/
8674
nonIncreasing (m : M) (x : α):
8775
Machine.invariant m
8876
→ guard m x
@@ -152,12 +140,13 @@ private def _newAnticipatedREvent' [Preorder v] [Machine ACTX AM] [Machine CTX M
152140
(abs : OrdinaryEvent AM α' Unit) (ev : AnticipatedREventSpec' v AM M (α:=α) (α':=α') abs) : AnticipatedREvent v AM M α Unit α' Unit :=
153141
_newAnticipatedREvent abs ev.toAnticipatedREventSpec
154142

155-
/-- Variant of `newAnticipatedREvent` with implicit `Unit` output type -/
143+
/-- Variant of `newAnticipatedREventFromOrdinary` with implicit `Unit` output type -/
156144
@[simp]
157145
def newAnticipatedREventfromOrdinary' [Preorder v] [Machine ACTX AM] [Machine CTX M] [Refinement AM M]
158146
(abs : OrdinaryEvent AM α' Unit) (ev : AnticipatedREventSpec' v AM M (α:=α) (α':=α') abs) : AnticipatedREvent v AM M α Unit α' Unit :=
159147
_newAnticipatedREvent' abs ev
160148

149+
/-- Variant of `newAnticipatedREventFromAnticipated` with implicit `Unit` output type -/
161150
@[simp]
162151
def newAnticipatedREventfromAnticipated' [Preorder v] [Machine ACTX AM] [Machine CTX M] [Refinement AM M]
163152
(abs : AnticipatedEvent v AM α' Unit) (ev : AnticipatedREventSpec' v AM M (α:=α) (α':=α') abs.toOrdinaryEvent) : AnticipatedREvent v AM M α Unit α' Unit :=
@@ -188,12 +177,13 @@ private def _newAnticipatedREvent'' [Preorder v] [Machine ACTX AM] [Machine CTX
188177
(abs : OrdinaryEvent AM Unit Unit) (ev : AnticipatedREventSpec'' v AM M abs) : AnticipatedREvent v AM M Unit Unit :=
189178
_newAnticipatedREvent abs ev.toAnticipatedREventSpec
190179

191-
/-- Variant of `newAnticipatedREvent` with implicit `Unit` input and output types -/
180+
/-- Variant of `newAnticipatedREventfromOrdinary` with implicit `Unit` input and output types -/
192181
@[simp]
193182
def newAnticipatedREventfromOrdinary'' [Preorder v] [Machine ACTX AM] [Machine CTX M] [Refinement AM M]
194183
(abs : OrdinaryEvent AM Unit Unit) (ev : AnticipatedREventSpec'' v AM M abs) : AnticipatedREvent v AM M Unit Unit :=
195184
_newAnticipatedREvent'' abs ev
196185

186+
/-- Variant of `newAnticipatedREventfromAnticipated` with implicit `Unit` input and output types -/
197187
@[simp]
198188
def newAnticipatedREventfromAnticipated'' [Preorder v] [Machine ACTX AM] [Machine CTX M] [Refinement AM M]
199189
(abs : AnticipatedEvent v AM Unit Unit) (ev : AnticipatedREventSpec'' v AM M abs.toOrdinaryEvent) : AnticipatedREvent v AM M Unit Unit :=
@@ -203,7 +193,7 @@ def newAnticipatedREventfromAnticipated'' [Preorder v] [Machine ACTX AM] [Machin
203193
### Convergent refined events
204194
-/
205195

206-
/-- Internal representation of proof obligations for events -/
196+
/-- Internal representation of proof obligations for convergent refined events -/
207197
structure _ConvergentREventPO (v) [Preorder v] [WellFoundedLT v] [Machine ACTX AM] [Machine CTX M] [instR: Refinement AM M]
208198
(ev : _Event M α β) (kind : EventKind) (α') (β')
209199
extends _AnticipatedREventPO (instR:=instR) v ev kind α' β' where
@@ -214,7 +204,7 @@ structure _ConvergentREventPO (v) [Preorder v] [WellFoundedLT v] [Machine ACTX A
214204
let (_, m') := ev.action m x
215205
variant m' < variant m
216206

217-
/-- The representation of convergent events, constructed
207+
/-- The representation of convergent refined events, constructed
218208
by specifications structures, e.g. `ConvergentREventSpec`,
219209
and smart constructors, e.g. `newConvergentREvent`. -/
220210
structure ConvergentREvent (v) [Preorder v] [WellFoundedLT v] (AM) [Machine ACTX AM] (M) [Machine CTX M] [instR: Refinement AM M]
@@ -234,7 +224,7 @@ def ConvergentREvent.toConvergentEvent [Preorder v] [WellFoundedLT v] [Machine A
234224
}
235225
}
236226

237-
/-- Specification of anticipated refined events.
227+
/-- Specification of convergent refined events.
238228
with: `v` a variant type assumed to be pre-ordered with well-founded less-than relation,
239229
`AM` the abstact machine type, `M` the concrete maching type,
240230
`α` the concrete input parameter type, `α'` the corresponding abstract input type (by default, `α`)
@@ -250,6 +240,7 @@ structure ConvergentREventSpec (v) [Preorder v] [WellFoundedLT v] (AM) [Machine
250240
{α β α' β'} (abs : OrdinaryEvent AM α' β')
251241
extends _Variant v, REventSpec AM M (α:=α) (β:=β) (α':=α') (β':=β') abs where
252242

243+
/-- Proof obligation: the variant strictly decreases. -/
253244
convergence (m : M) (x : α):
254245
Machine.invariant m
255246
→ guard m x
@@ -258,7 +249,7 @@ structure ConvergentREventSpec (v) [Preorder v] [WellFoundedLT v] (AM) [Machine
258249

259250
/-- Smart constructor for convergent refined event,
260251
with: `abs` the event to refine, and
261-
`ev` the refined event specification (cf. `AnticipatedREventSpec`).
252+
`ev` the refined event specification (cf. `ConvergentREventSpec`).
262253
-/
263254
@[simp]
264255
def newConvergentREvent [Preorder v] [WellFoundedLT v] [Machine ACTX AM] [Machine CTX M] [Refinement AM M]

0 commit comments

Comments
 (0)