Engine

7.9. Statements of Appending🔗

The exact statements behind the claims on the page Appending.

theorem an_event_is_appended_exactly_when_it_is_valid_expected_and_accepted {acc} {st : State} {e : Event} : (st.appendWith acc e).isSome = true ↔ e.valid st.schema = true ∧ (∀ r, e.expected_revision = some r → (keyHistory st.store e.entity e.key).length = r) ∧ acc (st.rulesAt (st.store.length + 1)) st.store (st.stamp e) = true

proof: spec/Spec/Meaning.lean:293

theorem a_batch_appends_its_first_event_then_the_rest (acc : List (String × Rule) → List Event → Event → Bool) (st : State) (e : Event) (es : List Event) : st.appendAllWith acc (e :: es) = (st.appendWith acc e).bind (·.appendAllWith acc es)

proof: spec/Spec/Concurrency.lean:411

theorem batch_stores_all_or_nothing {acc} : ∀ (es : List Event) {st st' : State}, st.appendAllWith acc es = some st' → ∃ new, st'.store = st.store ++ new ∧ new.length = es.length ∧ st'.schema = st.schema ∧ st'.rules = st.rules

proof: spec/Spec/Facts.lean:43

theorem an_append_only_extends_the_store {acc} {st st' : State} {e : Event} (h : st.appendWith acc e = some st') : st'.store = st.store ++ [st.stamp e] ∧ st'.schema = st.schema ∧ st'.rules = st.rules

proof: spec/Spec/Facts.lean:31

theorem append_rejects_invalid_event {acc} {st : State} {e : Event} (h : e.valid st.schema = false) : st.appendWith acc e = none

proof: spec/Spec/Facts.lean:63

theorem an_event_the_rules_reject_is_rejected {acc} {st : State} {e : Event} (h : acc (st.rulesAt (st.store.length + 1)) st.store (st.stamp e) = false) : st.appendWith acc e = none

proof: spec/Spec/Facts.lean:70

theorem batches_reach_the_same_states_as_single_events {st : State} : ReachableB st ↔ Reachable st

proof: spec/Spec/Proofs.lean:102

theorem Inv.the_fast_check_agrees_with_the_full_check {world : World} {store es : List Event} {i : Inv} (hb : i.holds world store) : i.fastCheck world store es = i.holds world (store ++ es)

proof: spec/Spec/Invariants.lean:114

theorem the_engine_append_is_the_reference_append {st : State} (hr : Reachable st) (es : List Event) : st.engineAppendBatch es = st.appendBatch es

proof: spec/Spec/Proofs.lean:286

theorem invalid_event_is_rejected_for_its_schema {st : State} {e : Event} (h : e.valid st.schema = false) : st.rejectionReason e = some .schema

proof: spec/Spec/Meaning.lean:490

theorem a_valid_event_with_a_wrong_expected_revision_is_rejected_for_that {st : State} {e : Event} {r : Nat} (hv : e.valid st.schema = true) (hr : e.expected_revision = some r) (hne : (keyHistory st.store e.entity e.key).length ≠ r) : st.rejectionReason e = some (.expectedRevision r (keyHistory st.store e.entity e.key).length)

proof: spec/Spec/Meaning.lean:495

theorem active_rules_are_those_of_the_files_in_file_order {st st' : State} {sc : Schema} {fs : List RuleFile} (h : st.deploy sc fs = some st') : (st'.rules.filter (·.toPos.isNone)).map (fun d => (d.entity, d.rule)) = (ruleList fs).eraseDups

proof: spec/Spec/Facts.lean:172

theorem the_append_with_reasons_agrees_with_the_yes_no_append (st : State) (es : List Event) : (st.append es).toOption = st.appendBatch es

proof: spec/Spec/Rejections.lean:67

theorem rules_accept_an_event_exactly_when_none_gives_a_reason (rules : List (String × Rule)) (store : List Event) (e : Event) : rulesAccept rules store e = (rejectionByRules rules store e).isNone

proof: spec/Spec/Rejections.lean:29

theorem an_append_error_names_the_first_rejected_event {st : State} {es : List Event} {rj : Rejection} (h : st.append es = .error rj) : ∃ (hk : rj.index < es.length), ∃ st', st.appendBatch (es.take rj.index) = some st' ∧ st'.rejectionReason es[rj.index] = some rj.reason ∧ rj.position = st'.store.length + 1

proof: spec/Spec/Rejections.lean:100

theorem disjoint_batches_commute {st : State} (hr : Reachable st) {A B : List Event} (hd : (st.footprint A).Disjoint (st.footprint B)) : (∀ sA, st.appendBatch A = some sA → (sA.appendBatch B).isSome = (st.appendBatch B).isSome) ∧ (∀ sB, st.appendBatch B = some sB → (sB.appendBatch A).isSome = (st.appendBatch A).isSome) ∧ (∀ sA sB sAB sBA, st.appendBatch A = some sA → sA.appendBatch B = some sAB → st.appendBatch B = some sB → sB.appendBatch A = some sBA → SameKeyHistories sAB.store sBA.store ∧ sAB.schema = sBA.schema ∧ sAB.rules = sBA.rules)

proof: spec/Spec/Concurrency.lean:601

theorem stores_with_the_same_key_histories_accept_the_same_events {s t : List Event} (h : SameKeyHistories s t) (rules : List (String × Rule)) (e : Event) : rulesAccept rules s e = rulesAccept rules t e

proof: spec/Spec/Concurrency.lean:104