@bramas/simulant-lean 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # @bramas/simulant-lean
2
+
3
+ Lean 4 semantic library for Simulant experiments on mobile entities and
4
+ distributed algorithms. The npm package ships the hand-written semantic core,
5
+ generated standard-library components, Lake configuration and pinned Lean
6
+ toolchain. It does not ship compiled caches or example projects.
7
+
8
+ ## Use from a Simulant project
9
+
10
+ ```sh
11
+ npm create @bramas/simulant@latest my-project
12
+ cd my-project
13
+ npm install
14
+ npx simulant lean
15
+ npx simulant lean --build
16
+ ```
17
+
18
+ Install [elan](https://github.com/leanprover/elan) separately for `--build`.
19
+ The CLI configures the project's Lake dependency and uses the toolchain shipped
20
+ with this library. Generated models go in `lean/Generated/`; write hand-written
21
+ proofs in `lean/Proofs/`, which subsequent generation preserves.
22
+
23
+ ## Library contents
24
+
25
+ - `Simulant.lean` and `Simulant/`: configurations, nondeterminism, topologies,
26
+ rounds, executions, fairness, temporal goals and supporting lemmas.
27
+ - `Simulant/Library/`: generated component definitions.
28
+ - `Simulant/LibraryLemmas/`: hand-written component lemmas.
29
+ - `lakefile.toml` and `lean-toolchain`: build configuration and compiler version.
30
+
31
+ This is a Lean source package, not a JavaScript runtime. The npm package's
32
+ `package.json` subpath lets tooling locate the library. The TypeScript-to-Lean
33
+ generator is distributed separately as `@bramas/simulant-lean-gen`.
34
+
35
+ Building a generated model checks its Lean types; proving the generated
36
+ correctness statement is a separate step. No Mathlib dependency is required.
37
+
38
+ [Lean guarantees and limits](https://github.com/Bramas/simulant/blob/main/docs/architecture.md#lean-guarantees-and-limits)
39
+ · [Source](https://github.com/Bramas/simulant/tree/main/lean)
40
+
41
+ Licensed under CeCILL-B; see `LICENCE.txt`.
@@ -4,7 +4,7 @@ import Simulant.Round
4
4
  # Executions, tasks and non-vacuity (plan, Sections 3.9, 3.10 and 5.2)
5
5
 
6
6
  Every execution permitted by the round is considered (no fairness on the
7
- adversary's choices), except that a semi-synchronous round only admits
7
+ adversary's choices), except that semi-synchronous and sequential rounds only admit
8
8
  scheduler-fair executions: every agent that acts forever is activated
9
9
  infinitely often.
10
10
  -/
@@ -48,7 +48,7 @@ def Fair (e : Execution σ) : Prop :=
48
48
  ∀ n, ∃ j, n ≤ j ∧ a ∈ e.active j
49
49
 
50
50
  def Admissible (e : Execution σ) : Prop :=
51
- m.Valid act0 init e ∧ (m.round = .ssync → Fair e)
51
+ m.Valid act0 init e ∧ (m.round ≠ .fsync → Fair e)
52
52
 
53
53
  /-- The correctness statement: every admissible execution satisfies the goal. -/
54
54
  def Correct (verdict : Config σ → Verdict) (goal : Goal) : Prop :=
@@ -144,7 +144,7 @@ theorem toExecution_valid (m : Model σ) (act0 : σ.A) (init : ND (Config σ)) (
144
144
  theorem hasExecution (m : Model σ) (act0 : σ.A) (init : ND (Config σ)) (l : Lasso σ)
145
145
  (hround : m.round = .fsync) (hv : l.Valid m act0) (hinit : ND.Can init l.start) :
146
146
  m.HasExecution act0 init :=
147
- ⟨l.toExecution hv.1, toExecution_valid m act0 init l hv hinit, fun h => by rw [hround] at h; cases h⟩
147
+ ⟨l.toExecution hv.1, toExecution_valid m act0 init l hv hinit, fun h => False.elim (h hround)⟩
148
148
 
149
149
  end Lasso
150
150
  end Simulant
@@ -65,6 +65,11 @@ theorem activate_total (C : Config σ) : ∃ a, ND.Can (m.activate C) a := by
65
65
  refine ⟨[x], ND.can_choose.2 ?_⟩
66
66
  simp only [nonemptySubsets, List.mem_flatMap, List.mem_range]
67
67
  exact ⟨0, List.length_pos_of_mem hx, by rw [combos_one]; exact List.mem_map_of_mem hx⟩
68
+ · split
69
+ · exact ⟨_, ND.can_pure.2 rfl⟩
70
+ · rename_i h
71
+ obtain ⟨x, hx⟩ := List.exists_mem_of_ne_nil _ (fun he => h (List.isEmpty_iff.2 he))
72
+ exact ⟨[x], ND.can_choose.2 (List.mem_map_of_mem hx)⟩
68
73
 
69
74
  omit [FlagSet σ.F] in
70
75
  theorem frames_ne_nil (a : Agent σ) : m.frames a ≠ [] := by
@@ -127,7 +132,7 @@ theorem hasExecution (init : ND (Config σ)) (hround : m.round = .fsync) (hinit
127
132
  refine ⟨⟨config, fun n => (next (config n)).1, fun n => (next (config n)).2.1⟩, ⟨?_, fun n => ?_⟩, ?_⟩
128
133
  · exact Classical.choose_spec hinit
129
134
  · exact Classical.choose_spec (Classical.choose_spec (Classical.choose_spec (htot (config n))))
130
- · intro h; rw [hround] at h; cases h
135
+ · intro h; exact False.elim (h hround)
131
136
 
132
137
  end Model
133
138
  end Simulant
@@ -140,7 +140,7 @@ inductive FrameModel (σ : Sig) where
140
140
  | persistent (get : σ.X → Bool)
141
141
 
142
142
  inductive RoundKind where
143
- | fsync | ssync
143
+ | fsync | ssync | sequential
144
144
  deriving DecidableEq, Repr
145
145
 
146
146
  structure Model (σ : Sig) where
@@ -196,12 +196,13 @@ namespace Model
196
196
 
197
197
  variable [FlagSet σ.F] (m : Model σ)
198
198
 
199
- /-- FSYNC activates every agent that acts; SSYNC lets the adversary choose a nonempty set of them. -/
199
+ /-- FSYNC: all eligible agents; SSYNC: a nonempty subset; sequential: a singleton. -/
200
200
  def activate (C : Config σ) : ND (List (Fin σ.k)) :=
201
201
  let eligible := (List.finRange σ.k).filter fun i => FlagSet.acts C.agents[i].flags != .never
202
202
  match m.round with
203
203
  | .fsync => pure eligible
204
204
  | .ssync => if eligible.isEmpty then pure eligible else ND.choose "activation" (nonemptySubsets eligible)
205
+ | .sequential => if eligible.isEmpty then pure eligible else ND.choose "activation" (eligible.map ([·]))
205
206
 
206
207
  def frames (a : Agent σ) : List Bool :=
207
208
  match m.frame with
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bramas/simulant-lean",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Lean semantic core and generated component library for Simulant",
5
5
  "license": "CECILL-B",
6
6
  "private": false,