Engine

7.12. Statements of Views🔗

The exact statements behind the claims on the page Views.

theorem a_kept_view_gives_the_same_rows_at_any_read_time_and_when_computed (v : View) (c : Bool) (done : List (String × Table)) (store : List Event) (t t' : Rat) (hk : v.keptOk (done.lookup v.source).isSome = true) : ({ v with computed := c }).table done store t' = v.table done store t

proof: spec/Spec/Views.lean:369

theorem an_append_changes_only_the_row_of_its_own_key {v : View} (hk : v.keptOk false = true) (store : List Event) (e : Event) (t : Rat) {k : String} (hne : e.key ≠ k) : v.rowFor (store ++ [e]) t k = v.rowFor store t k

proof: spec/Spec/Views.lean:401

theorem an_event_of_another_entity_changes_no_row_of_a_view_of_an_entity {v : View} (hk : v.keptOk false = true) (store : List Event) (e : Event) (t : Rat) (hne : e.entity ≠ v.source) : v.ofEntity (store ++ [e]) t = v.ofEntity store t

proof: spec/Spec/Views.lean:409

theorem a_kept_view_of_a_view_depends_only_on_its_source_rows {v : View} (hk : v.keptOk true = true) (src : Table) (w w' : World) (t t' : Rat) : v.ofView src w' t' = v.ofView src w t

proof: spec/Spec/Views.lean:421

theorem a_kept_selector_picks_from_an_appended_history_what_it_picked_before_and_the_new_event (ctx : Ctx) {src : List Event} {e : Event} (hn : e ∉ src) : ∀ s : Selector, s.kept → evalSelector ctx (src ++ [e]) s = evalSelector ctx src s ++ evalSelector ctx [e] s

proof: spec/Spec/Views.lean:442

theorem count_after_an_append_is_the_count_before_plus_the_new_event (ctx : Ctx) {h : List Event} {e : Event} (hn : e ∉ h) {s : Selector} (hs : s.kept) : evalValueExpr { ctx with hist := h ++ [e] } (.count s) = Value.arith .add (evalValueExpr { ctx with hist := h } (.count s)) (evalValueExpr { ctx with hist := [e] } (.count s))

proof: spec/Spec/Views.lean:486

theorem sum_after_an_append_is_the_sum_before_plus_the_new_event (ctx : Ctx) {h : List Event} {e : Event} (hn : e ∉ h) {s : Selector} (hs : s.kept) (f : String) : evalValueExpr { ctx with hist := h ++ [e] } (.sum s f) = Value.arith .add (evalValueExpr { ctx with hist := h } (.sum s f)) (evalValueExpr { ctx with hist := [e] } (.sum s f))

proof: spec/Spec/Views.lean:504

theorem last_of_after_an_append_is_the_new_event_if_picked (ctx : Ctx) {h : List Event} {e : Event} (hn : e ∉ h) {s : Selector} (hs : s.kept) (f : String) : evalValueExpr { ctx with hist := h ++ [e] } (.lastField s f) = if (evalSelector ctx [e] s).isEmpty then evalValueExpr { ctx with hist := h } (.lastField s f) else e.get f

proof: spec/Spec/Views.lean:516

theorem ever_after_an_append_is_ever_before_or_the_new_event (ctx : Ctx) {h : List Event} {e : Event} (hn : e ∉ h) {s : Selector} (hs : s.kept) : evalCondExpr { ctx with hist := h ++ [e] } (.ever s) = (evalCondExpr { ctx with hist := h } (.ever s) || evalCondExpr { ctx with hist := [e] } (.ever s))

proof: spec/Spec/Views.lean:541

theorem min_and_max_after_an_append_are_one_step_from_the_value_before (ctx : Ctx) {h : List Event} {e : Event} (hn : e ∉ h) {s : Selector} (hs : s.kept) (f : String) : evalValueExpr { ctx with hist := h ++ [e] } (.min s f) = ((evalSelector ctx [e] s).foldl (fun acc x => Value.extreme .lt acc (x.get f)) (evalValueExpr { ctx with hist := h } (.min s f))) ∧ evalValueExpr { ctx with hist := h ++ [e] } (.max s f) = ((evalSelector ctx [e] s).foldl (fun acc x => Value.extreme .gt acc (x.get f)) (evalValueExpr { ctx with hist := h } (.max s f)))

proof: spec/Spec/Views.lean:550

theorem the_deploy_orders_the_views_so_that_each_reads_only_views_before_it {vs o : List View} (h : sortViews vs = some o) : (∀ w, w ∈ o ↔ w ∈ vs) ∧ ReadsOnlyEarlier o

proof: spec/Spec/Views.lean:621

theorem views_that_read_each_other_in_a_cycle_are_rejected {vs C : List View} (hne : C ≠ []) (hsub : ∀ v ∈ C, v ∈ vs) (hC : ∀ v ∈ C, ∃ w ∈ C, w.name = v.source) : sortViews vs = none

proof: spec/Spec/Views.lean:645

theorem the_shift_views_file_loads : loadFile shiftViewsText = .ok { views := shiftViews }

proof: spec/Spec/Examples/ShiftViews.lean:53

theorem the_open_slots_are_evaluated_after_the_overview_they_read : (sortViews shiftViews).map (·.map (·.name)) = some ["shift_overview", "shift_activity", "open_slots_per_role"]

proof: spec/Spec/Examples/ShiftViews.lean:78

theorem the_overview_has_one_row_per_shift : (shiftTablesAt 0).lookup "shift_overview" = some [ ⟨[.str "s1"], [("role", .str "cook"), ("staffed", .num 1), ("open", .num 0), ("cancelled", .bool false)]⟩, ⟨[.str "s2"], [("role", .str "cook"), ("staffed", .num 0), ("open", .num 2), ("cancelled", .bool true)]⟩]

proof: spec/Spec/Examples/ShiftViews.lean:100

theorem a_cancelled_shift_is_left_out_of_the_open_slots_per_role : (shiftTablesAt 0).lookup "open_slots_per_role" = some [ ⟨[.str "cook"], [("role", .str "cook"), ("shifts", .num 1), ("open_slots", .num 0)]⟩]

proof: spec/Spec/Examples/ShiftViews.lean:108

theorem the_assignments_of_today_count_on_the_day_and_not_on_the_next : ((shiftTablesAt 0).lookup "shift_activity").map (·.map (·.cols.lookup "assigned_today")) = some [some (.num 1), some (.num 0)] ∧ ((shiftTablesAt usPerDay).lookup "shift_activity").map (·.map (·.cols.lookup "assigned_today")) = some [some (.num 0), some (.num 0)]

proof: spec/Spec/Examples/ShiftViews.lean:115

theorem a_kept_view_with_a_window_is_rejected_and_names_the_column : loadErrorOf? (withViews shiftDefs [{ name := "shift_activity", source := "shift", columns := [ ("assigned_today", .val (.count (.window (.type "EmployeeAssigned") .today)))] }]) = some (.notKept "shift_activity" "assigned_today")

proof: spec/Spec/Examples/ShiftViews.lean:128

theorem two_views_that_read_each_other_are_rejected : loadErrorOf? (withViews shiftDefs [ { name := "a", source := "b", columns := [("n", .val (.count .any))] }, { name := "b", source := "a", columns := [("n", .val (.count .any))] }]) = some .viewCycle

proof: spec/Spec/Examples/ShiftViews.lean:135

theorem a_view_named_like_an_entity_is_rejected : loadErrorOf? (withViews shiftDefs [{ name := "shift", source := "shift", columns := [("n", .val (.count .any))] }]) = some (.nameTaken "shift")

proof: spec/Spec/Examples/ShiftViews.lean:142