Cairn · module

Cairn.Claims.Machine

lean/Cairn/Claims/Machine.lean

A machine is an initial state and the moves that act on it. Its update is derived from the moves by dispatch, so it inherits every guarantee in Cairn.Claims.Move. Flows and invariants are stated against a machine.

A machine may also hear the outside world (docs/effects.md): receive takes the clock, timers, replies and subscription events. An invariant must be kept by receive as well as by every move, so it holds over any interleaving of a person's actions and the host's messages (Invariant.reachableAll), and through the runtime (Cairn.Claims.steps_reachableAll).

Pure, and linked into the host, like Cairn.Claims.Move.

Imports Cairn.Claims.Move, Cairn.App

Order

Structures 5

structure

Cairn.Claims.Machine

lean/Cairn/Claims/Machine.lean:22
Machine (S : Type) : Type
Fields
init : S
moves : List (Move S)
receive : S × List Effect

What the outside world does to the state (App.receive); by default nothing.

structure

Cairn.Claims.Flow

lean/Cairn/Claims/Machine.lean:123
Flow {S : Type} (M : Machine S) : Type

A goal reachable from the machine's initial state, with a witness: a sequence of actions, each answered by an enabled move, after which the goal holds.

Fields
info : ClaimInfo
goal : Prop
witness : List Action
live : M.live M.init self.witness = true
reaches : self.goal (M.run M.init self.witness)
structure

Cairn.Claims.Invariant

lean/Cairn/Claims/Machine.lean:133
Invariant {S : Type} (M : Machine S) : Type

A property of every reachable state: true initially, preserved by every update (so by every move, see Machine.update) and by every message from the world (Machine.receive; for a machine that ignores the world this is immediate).

Fields
info : ClaimInfo
holds : Prop
init : self.holds M.init
step : self.holds (M.update s a).fst
recv : self.holds (M.receive s m).fst
structure

Cairn.Claims.Assumption

lean/Cairn/Claims/Machine.lean:152
Assumption : Type

Something taken as given about the world. statement is recorded, never proved: theorems that rely on it take it as a hypothesis, so it never becomes an axiom.

Fields
info : ClaimInfo
statement : Prop
structure

Cairn.Claims.Place

lean/Cairn/Claims/Machine.lean:157
Place : Type

A region of the view where moves appear.

Fields
info : ClaimInfo

Definitions 9

def

Cairn.Claims.Machine.update

lean/Cairn/Claims/Machine.lean:32
update {S : Type} (M : Machine S) (s : S) (a : Action) :
  S × List Effect

The update an app gets from its moves.

def

Cairn.Claims.Machine.run

lean/Cairn/Claims/Machine.lean:35
run {S : Type} (M : Machine S) (s : S) (as : List Action) : S

The state after a sequence of actions.

def

Cairn.Claims.Machine.live

lean/Cairn/Claims/Machine.lean:38
live {S : Type} (M : Machine S) : S → List Action → Bool

Every action in the sequence is answered by an enabled move, in turn.

def

Cairn.Claims.Machine.Reachable

lean/Cairn/Claims/Machine.lean:43
Reachable {S : Type} (M : Machine S) (s : S) : Prop

States reachable from init.

def

Cairn.Claims.Machine.feed

lean/Cairn/Claims/Machine.lean:46
feed {S : Type} (M : Machine S) (s : S) : Action ⊕ Msg → S

One input: a person's action (update) or a message from the world (receive).

def

Cairn.Claims.Machine.runAll

lean/Cairn/Claims/Machine.lean:51
runAll {S : Type} (M : Machine S) (s : S) (xs : List (Action ⊕ Msg)) :
  S

The state after a sequence of actions and messages.

def

Cairn.Claims.Machine.ReachableAll

lean/Cairn/Claims/Machine.lean:54
ReachableAll {S : Type} (M : Machine S) (s : S) : Prop

States reachable from init by actions and messages.

def

Cairn.Claims.Machine.toApp

lean/Cairn/Claims/Machine.lean:66
toApp {S : Type} (M : Machine S) (surfaces : List (Surface S))
  (claims : List ClaimInfo) (initFocus : Option ControlRef := none) : App S

An app whose update is this machine's, showing surfaces (M1 apps: one window).

abbrev

Cairn.Claims.StateOf

lean/Cairn/Claims/Machine.lean:190
StateOf {S : Type} : Machine S → Type

The state type of a machine. The flow and invariant commands use it to type the bodies they are given without asking for the state type again.

Theorems 11

theorem

Cairn.Claims.Machine.Reachable.all

provedlean/Cairn/Claims/Machine.lean:56
all {S : Type} (M : Machine S) {s : S} (h : M.Reachable s) :
  M.ReachableAll s
theorem

Cairn.Claims.Machine.run_nil

provedlean/Cairn/Claims/Machine.lean:75
run_nil {S : Type} (M : Machine S) (s : S) : M.run s [] = s
theorem

Cairn.Claims.Machine.run_cons

provedlean/Cairn/Claims/Machine.lean:77
run_cons {S : Type} (M : Machine S) (s : S) (a : Action)
  (as : List Action) : M.run s (a :: as) = M.run (M.update s a).fst as
theorem

Cairn.Claims.Machine.run_append

provedlean/Cairn/Claims/Machine.lean:80
run_append {S : Type} (M : Machine S) (s : S) (as bs : List Action) :
  M.run s (as ++ bs) = M.run (M.run s as) bs
theorem

Cairn.Claims.Machine.update_unclaimed

provedlean/Cairn/Claims/Machine.lean:85
update_unclaimed {S : Type} (M : Machine S) {s : S} {a : Action}
  (h : ∀ (m : Move S), m ∈ M.moves → m.id ≠ a.claim) : M.update s a = (s, [])

No behaviour without a claim, for a machine.

theorem

Cairn.Claims.Machine.update_effect

provedlean/Cairn/Claims/Machine.lean:89
update_effect {S : Type} (M : Machine S) {s : S} {a : Action}
  {e : Effect} (he : e ∈ (M.update s a).snd) :
  ∃ m,
    m ∈ M.moves ∧
      ∃ h,
        h ∈ m.handlers ∧
          m.id = a.claim ∧
            h.trigger = a.trigger ∧ m.enabled s a.key = true ∧ e ∈ (h.apply s a).snd

Every effect comes from a move, for a machine.

theorem

Cairn.Claims.Machine.preserves

provedlean/Cairn/Claims/Machine.lean:95
preserves {S : Type} (M : Machine S) {P : S → Prop}
  (hm : ∀ (m : Move S), m ∈ M.moves → m.Preserves P) (s : S) (a : Action) :
  P s → P (M.update s a).fst

Invariants one move at a time, for a machine: if every move keeps P, so does every update. Pair with the name.preserves lemma each move generates.

theorem

Cairn.Claims.Machine.run_preserves

provedlean/Cairn/Claims/Machine.lean:100
run_preserves {S : Type} (M : Machine S) (P : S → Prop)
  (step : ∀ (s : S) (a : Action), P s → P (M.update s a).fst) (as : List Action) (s : S) :
  P s → P (M.run s as)

A property true at s and preserved by every update holds after any sequence.

theorem

Cairn.Claims.Machine.runAll_preserves

provedlean/Cairn/Claims/Machine.lean:107
runAll_preserves {S : Type} (M : Machine S) (P : S → Prop)
  (step : ∀ (s : S) (a : Action), P s → P (M.update s a).fst)
  (recv : ∀ (s : S) (m : Msg), P s → P (M.receive s m).fst) (xs : List (Action ⊕ Msg))
  (s : S) : P s → P (M.runAll s xs)

A property true at s and kept by every update and every message holds after any sequence of both.

theorem

Cairn.Claims.Invariant.reachable

provedlean/Cairn/Claims/Machine.lean:140
reachable {S : Type} {M : Machine S} (i : Invariant M) {s : S}
  (h : M.Reachable s) : i.holds s
theorem

Cairn.Claims.Invariant.reachableAll

provedlean/Cairn/Claims/Machine.lean:145
reachableAll {S : Type} {M : Machine S} (i : Invariant M) {s : S}
  (h : M.ReachableAll s) : i.holds s