Documentation

CslibFrontier.Computability.Distributed.CRDT.DataTypes

Replicated Counters and Sets (GCounter, PNCounter, TwoPhaseSet, ORSet) & Impossibility #

This module formalizes concrete state-based (CvRDT) and operation-based (CmRDT) data types together with their functional specifications and untagged set impossibility steps toward #7502 (after Shapiro, Preguiça, Baquero, and Zawirski [SPBZ11b], §§4.1–4.2, pp. 11–12, and [SPBZ11a], §§3.1, 3.3, Specifications 6, 7, 11, 12, 15, pp. 14–16, 21–27):

  1. GCounter P (Grow-Only Counter, Specification 6): Per-replica vector counts : P → ℕ with pointwise max semilattice merge and query ∑ p : P, counts p, proving SemilatticeSup / OrderBot, CvRDT and CmRDT instances, monotonicity of GCounter.value, and exact multi-replica global sum convergence (GCounter.value_sup_of_local_counts, avoiding the lost-update anomaly of merging a single scalar counter via max).

  2. PNCounter P (Positive-Negative Counter, Specification 7): Paired (pos, neg) GCounters evaluating to (pos.value : ℤ) - (neg.value : ℤ), proving unconditional commutativity of increments and decrements and exact net-count evaluation.

  3. Grow-Only Set (gsetCvRDT, gsetCmRDT) and TwoPhaseSet α (2P-Set, Specification 12): (added, removed) pair of Finset αs with query added \ removed, proving CvRDT and CmRDT convergence, concurrent remove-wins (TwoPhaseSet.remove_wins_concurrent), and monotonic tombstone permanence (TwoPhaseSet.not_mem_elements_of_le_of_removed: once tombstoned, an element can never re-enter elements at any semilattice successor).

  4. ORSet (Observed-Remove Set with Unique P × ℕ Tags, Specification 15 & Figure 14):

  5. Untagged Set Impossibility (not_exists_untagged_finset_merge, untagged_insert_erase_ne_erase_insert): Proves that no commutative binary merge Finset α → Finset α → Finset α on plain untagged sets ([Nonempty α]) can simultaneously propagate a fresh add to an untouched peer at ∅ (x ∈ merge ∅ (insert x ∅)) and propagate a sequential remove-after-add to a peer still holding {x} (x ∉ merge {x} (({x} : Finset α).erase x)), because both executions present the same unordered pair of untagged states {∅, {x}}, alongside op-based non-commutativity of naïve insert and erase ([SPBZ11a], §3.3 Figure 11, p. 21).

Main definitions #

Main results #

References #

GCounter: Grow-Only Counter #

structure Cslib.Distributed.CRDT.GCounter (P : Type u_1) :
Type u_1

Replicated grow-only counter (G-Counter, [SPBZ11b], §4.1, p. 11; [SPBZ11a], §3.1.2, Specification 6, pp. 14–16) allocating one natural-number slot per replica p : P (avoiding the lost-update anomaly of merging a single scalar counter via max).

  • counts : P → ℕ

    Per-replica increment counts.

Instances For
    theorem Cslib.Distributed.CRDT.GCounter.ext {P : Type u_1} {x y : GCounter P} (counts : x.counts = y.counts) :
    x = y
    @[instance_reducible]
    @[simp]
    theorem Cslib.Distributed.CRDT.GCounter.counts_zero {P : Type u_1} (p : P) :
    (zero P).counts p = 0
    @[simp]
    theorem Cslib.Distributed.CRDT.GCounter.counts_sup {P : Type u_1} (a b : GCounter P) (p : P) :
    (a ⊔ b).counts p = max (a.counts p) (b.counts p)

    Increment replica p's entry by 1.

    Total counter value ∑ p : P, c.counts p.

    theorem Cslib.Distributed.CRDT.GCounter.le_inc {P : Type u_1} [DecidableEq P] (p : P) (c : GCounter P) :
    c ≤ inc p c
    theorem Cslib.Distributed.CRDT.GCounter.inc_comm {P : Type u_1} [DecidableEq P] (p q : P) (c : GCounter P) :
    inc q (inc p c) = inc p (inc q c)
    @[simp]
    theorem Cslib.Distributed.CRDT.GCounter.value_inc {P : Type u_1} [Fintype P] [DecidableEq P] (p : P) (c : GCounter P) :
    (inc p c).value = c.value + 1

    Monotonicity of GCounter.value with respect to the semilattice order.

    State-based CvRDT instance for GCounter P.

    Op-based CmRDT instance for GCounter P where replica p broadcasts p to increment slot p downstream.

    theorem Cslib.Distributed.CRDT.GCounter.value_sup_of_local_counts {P : Type u_1} [Fintype P] [Nonempty P] (rep : P → GCounter P) (k : P → ℕ) (hown : ∀ (p : P), (rep p).counts p = k p) (hle : ∀ (q p : P), (rep q).counts p ≤ k p) :
    (Finset.univ.sup' ⋯ rep).value = ∑ p : P, k p

    Exact multi-replica sum specification step (toward #7502, after [SPBZ11a], §3.1.2, Specification 6, pp. 15–16): when each replica p holds its own originated count (rep p).counts p = k p and no replica over-counts any peer ((rep q).counts p ≤ k p), the global semilattice merge evaluates to ∑ p : P, k p.

    PNCounter: Positive-Negative Counter #

    Update operations on a PNCounter P: increment or decrement at source replica p.

    • inc {P : Type u_1} (p : P) : PNCounterOp P

      Increment originated at replica p.

    • dec {P : Type u_1} (p : P) : PNCounterOp P

      Decrement originated at replica p.

    @[instance_reducible]
    def Cslib.Distributed.CRDT.instDecidableEqPNCounterOp.decEq {P✝ : Type u_1} [DecidableEq P✝] (x✝ x✝¹ : PNCounterOp P✝) :
    Decidable (x✝ = x✝¹)
    structure Cslib.Distributed.CRDT.PNCounter (P : Type u_1) :
    Type u_1

    Replicated increment/decrement counter (PN-Counter, [SPBZ11b], §4.1, p. 11; [SPBZ11a], §3.1.3, Specification 7, pp. 15–16) pairing grow-only pos and neg GCounters.

    • pos : GCounter P

      Per-replica increment totals.

    • neg : GCounter P

      Per-replica decrement totals.

    Instances For
      theorem Cslib.Distributed.CRDT.PNCounter.ext {P : Type u_1} {x y : PNCounter P} (pos : x.pos = y.pos) (neg : x.neg = y.neg) :
      x = y
      @[instance_reducible]

      Increment pos at replica p.

      Increment neg (decrementing net value) at replica p.

      Signed integer value (c.pos.value : ℤ) - (c.neg.value : ℤ).

      theorem Cslib.Distributed.CRDT.PNCounter.applyOp_comm {P : Type u_1} [DecidableEq P] (op₁ op₂ : PNCounterOp P) (c : PNCounter P) :
      applyOp op₂ (applyOp op₁ c) = applyOp op₁ (applyOp op₂ c)
      @[simp]
      theorem Cslib.Distributed.CRDT.PNCounter.value_inc {P : Type u_1} [Fintype P] [DecidableEq P] (p : P) (c : PNCounter P) :
      (inc p c).value = c.value + 1
      @[simp]
      theorem Cslib.Distributed.CRDT.PNCounter.value_dec {P : Type u_1} [Fintype P] [DecidableEq P] (p : P) (c : PNCounter P) :
      (dec p c).value = c.value - 1

      State-based CvRDT instance for PNCounter P.

      theorem Cslib.Distributed.CRDT.PNCounter.value_sup_of_local_counts {P : Type u_1} [Fintype P] [Nonempty P] (rep : P → PNCounter P) (incK decK : P → ℕ) (hpos_own : ∀ (p : P), (rep p).pos.counts p = incK p) (hpos_le : ∀ (q p : P), (rep q).pos.counts p ≤ incK p) (hneg_own : ∀ (p : P), (rep p).neg.counts p = decK p) (hneg_le : ∀ (q p : P), (rep q).neg.counts p ≤ decK p) :
      (Finset.univ.sup' ⋯ rep).value = ↑(∑ p : P, incK p) - ↑(∑ p : P, decK p)

      Exact multi-replica net difference specification step (toward #7502, after [SPBZ11a], §3.1.3, Specification 7, pp. 15–16).

      GSet and TwoPhaseSet (2P-Set) #

      State-based Grow-Only Set (G-Set, [SPBZ11a], §3.3.1, Specification 11, p. 22) over Mathlib's SemilatticeSup (Finset α).

      Op-based Grow-Only Set (G-Set, [SPBZ11a], §3.3.1, pp. 21–22).

      inductive Cslib.Distributed.CRDT.SetOp (α : Type u_1) :
      Type u_1

      Set mutation operations (add and remove).

      • add {α : Type u_1} (x : α) : SetOp α

        Add x to the set.

      • remove {α : Type u_1} (x : α) : SetOp α

        Remove x from the set.

      def Cslib.Distributed.CRDT.instDecidableEqSetOp.decEq {α✝ : Type u_1} [DecidableEq α✝] (x✝ x✝¹ : SetOp α✝) :
      Decidable (x✝ = x✝¹)
      @[instance_reducible]
      structure Cslib.Distributed.CRDT.TwoPhaseSet (α : Type u_1) :
      Type u_1

      State-based Two-Phase Set (2P-Set, [SPBZ11a], §3.3.2, Specification 12, p. 22) combining an added set and a permanent removed tombstone set.

      • added : Finset α

        Elements ever added.

      • removed : Finset α

        Tombstone set of elements ever removed.

      Instances For
        theorem Cslib.Distributed.CRDT.TwoPhaseSet.ext {α : Type u_1} {x y : TwoPhaseSet α} (added : x.added = y.added) (removed : x.removed = y.removed) :
        x = y
        @[instance_reducible]
        def Cslib.Distributed.CRDT.instDecidableEqTwoPhaseSet.decEq {α✝ : Type u_1} [DecidableEq α✝] (x✝ x✝¹ : TwoPhaseSet α✝) :
        Decidable (x✝ = x✝¹)

        Currently visible elements s.added \ s.removed.

        Add x to s.added.

        Tombstone x in s.removed.

        theorem Cslib.Distributed.CRDT.TwoPhaseSet.applyOp_comm {α : Type u_1} [DecidableEq α] (op₁ op₂ : SetOp α) (s : TwoPhaseSet α) :
        applyOp op₂ (applyOp op₁ s) = applyOp op₁ (applyOp op₂ s)

        State-based CvRDT instance for TwoPhaseSet α.

        Op-based CmRDT instance for TwoPhaseSet α.

        theorem Cslib.Distributed.CRDT.TwoPhaseSet.not_mem_elements_of_le_of_removed {α : Type u_1} [DecidableEq α] {s s' : TwoPhaseSet α} {x : α} (hrem : x ∈ s.removed) (hle : s ≤ s') :
        x ∈ s'.removed ∧ x ∉ s'.elements

        Monotonic tombstone permanence step (toward #7502, after [SPBZ11a], §3.3.2, pp. 22–23): once x ∈ s.removed, x remains tombstoned and absent from s'.elements in every semilattice successor s' ≥ s (including after any subsequent add x or merge).

        theorem Cslib.Distributed.CRDT.TwoPhaseSet.remove_wins_concurrent {α : Type u_1} [DecidableEq α] (s₁ s₂ : TwoPhaseSet α) (x : α) :
        x ∉ (add x s₁ ⊔ remove x s₂).elements

        Remove-wins under concurrent add x and remove x in TwoPhaseSet α.

        ORSet: Observed-Remove Set with Unique (P × ℕ) Tags #

        structure Cslib.Distributed.CRDT.TaggedElem (P : Type u_1) (α : Type u_2) :
        Type (max u_1 u_2)

        A uniquely tagged set entry (elem, replica, seq) in an Observed-Remove Set (OR-Set, [SPBZ11a], §3.3.5, Specification 15, p. 26), pairing elem : α with a source-generated (replica, seq) : P × ℕ tag.

        • elem : α

          Added set element.

        • replica : P

          Originating replica identity.

        • seq : ℕ

          Per-replica sequence number uniquely tagging this add.

        theorem Cslib.Distributed.CRDT.TaggedElem.ext {P : Type u_1} {α : Type u_2} {x y : TaggedElem P α} (elem : x.elem = y.elem) (replica : x.replica = y.replica) (seq : x.seq = y.seq) :
        x = y
        theorem Cslib.Distributed.CRDT.TaggedElem.ext_iff {P : Type u_1} {α : Type u_2} {x y : TaggedElem P α} :
        x = y ↔ x.elem = y.elem ∧ x.replica = y.replica ∧ x.seq = y.seq
        def Cslib.Distributed.CRDT.instDecidableEqTaggedElem.decEq {P✝ : Type u_1} {α✝ : Type u_2} [DecidableEq P✝] [DecidableEq α✝] (x✝ x✝¹ : TaggedElem P✝ α✝) :
        Decidable (x✝ = x✝¹)
        @[instance_reducible]
        instance Cslib.Distributed.CRDT.instDecidableEqTaggedElem {P✝ : Type u_1} {α✝ : Type u_2} [DecidableEq P✝] [DecidableEq α✝] :
        DecidableEq (TaggedElem P✝ α✝)
        inductive Cslib.Distributed.CRDT.ORSetOp (P : Type u_1) (α : Type u_2) :
        Type (max u_1 u_2)

        Operations on an Observed-Remove Set: add p seq x (adding x with fresh source tag (p, seq)) and remove x (removing all currently observed tags of x at the source replica).

        • add {P : Type u_1} {α : Type u_2} (p : P) (seq : ℕ) (x : α) : ORSetOp P α

          Add x tagged with fresh (p, seq).

        • remove {P : Type u_1} {α : Type u_2} (x : α) : ORSetOp P α

          Remove all currently observed tags of x.

        @[instance_reducible]
        instance Cslib.Distributed.CRDT.instDecidableEqORSetOp {P✝ : Type u_1} {α✝ : Type u_2} [DecidableEq P✝] [DecidableEq α✝] :
        DecidableEq (ORSetOp P✝ α✝)
        def Cslib.Distributed.CRDT.instDecidableEqORSetOp.decEq {P✝ : Type u_1} {α✝ : Type u_2} [DecidableEq P✝] [DecidableEq α✝] (x✝ x✝¹ : ORSetOp P✝ α✝) :
        Decidable (x✝ = x✝¹)
        structure Cslib.Distributed.CRDT.ORSetCv (P : Type u_1) (α : Type u_2) :
        Type (max u_1 u_2)

        State-based Observed-Remove Set (ORSetCv, [SPBZ11a], §3.3.5, p. 27) maintaining entries and tombstones over TaggedElem P α.

        Instances For
          theorem Cslib.Distributed.CRDT.ORSetCv.ext {P : Type u_1} {α : Type u_2} {x y : ORSetCv P α} (entries : x.entries = y.entries) (tombstones : x.tombstones = y.tombstones) :
          x = y
          @[instance_reducible]
          instance Cslib.Distributed.CRDT.instDecidableEqORSetCv {P✝ : Type u_1} {α✝ : Type u_2} [DecidableEq P✝] [DecidableEq α✝] :
          DecidableEq (ORSetCv P✝ α✝)
          def Cslib.Distributed.CRDT.instDecidableEqORSetCv.decEq {P✝ : Type u_1} {α✝ : Type u_2} [DecidableEq P✝] [DecidableEq α✝] (x✝ x✝¹ : ORSetCv P✝ α✝) :
          Decidable (x✝ = x✝¹)
          @[instance_reducible]

          Initial empty state-based ORSetCv.

          def Cslib.Distributed.CRDT.ORSetCv.elements {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] (s : ORSetCv P α) :

          Visible set elements (s.entries \ s.tombstones).image TaggedElem.elem.

          def Cslib.Distributed.CRDT.ORSetCv.add {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] (p : P) (seq : ℕ) (x : α) (s : ORSetCv P α) :
          ORSetCv P α

          Add x with tag (p, seq) to s.entries.

          def Cslib.Distributed.CRDT.ORSetCv.removeObserved {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] (x : α) (s : ORSetCv P α) :
          ORSetCv P α

          Remove x by tombstoning only the tags of x currently observed in s.entries.

          def Cslib.Distributed.CRDT.ORSetCv.applyOp {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] :
          ORSetOp P α → ORSetCv P α → ORSetCv P α

          Apply ORSetOp to ORSetCv.

          theorem Cslib.Distributed.CRDT.ORSetCv.le_applyOp {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] (op : ORSetOp P α) (s : ORSetCv P α) :
          s ≤ applyOp op s
          def Cslib.Distributed.CRDT.ORSetCv.cvrdt {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] :
          CvRDT (ORSetCv P α) (ORSetOp P α) (Finset α)

          State-based CvRDT instance for ORSetCv P α.

          @[simp]
          theorem Cslib.Distributed.CRDT.ORSetCv.not_mem_removeObserved {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] (s : ORSetCv P α) (x : α) :
          theorem Cslib.Distributed.CRDT.ORSetCv.mem_sup_removeObserved_add {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] {s₁ s₂ : ORSetCv P α} {p : P} {seq : ℕ} {x : α} (hunobs : { elem := x, replica := p, seq := seq } ∉ s₁.entries) (hnot_tomb₁ : { elem := x, replica := p, seq := seq } ∉ s₁.tombstones) (hnot_tomb₂ : { elem := x, replica := p, seq := seq } ∉ s₂.tombstones) :
          x ∈ (removeObserved x s₁ ⊔ add p seq x s₂).elements

          State-based concurrent add-wins step (toward #7502, after [SPBZ11a], §3.3.5, Figure 14, p. 27): if s₂ adds x with a fresh tag ⟨x, p, seq⟩ not observed at s₁ and not already tombstoned, merging s₁.removeObserved x with s₂.add p seq x retains x.

          theorem Cslib.Distributed.CRDT.ORSetCv.mem_add_after_removeObserved {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] {s : ORSetCv P α} {p : P} {seq : ℕ} {x : α} (hfresh_ent : { elem := x, replica := p, seq := seq } ∉ s.entries) (hfresh_tomb : { elem := x, replica := p, seq := seq } ∉ s.tombstones) :
          x ∈ (add p seq x (removeObserved x s)).elements

          State-based sequential re-add after remove: unlike TwoPhaseSet, adding x with a fresh tag ⟨x, p, seq⟩ after s.removeObserved x restores x ∈ elements.

          inductive Cslib.Distributed.CRDT.ORSetEff (P : Type u_1) (α : Type u_2) :
          Type (max u_1 u_2)

          Downstream effect payloads of the op-based Observed-Remove Set (OR-Set, [SPBZ11a], §3.3.5, Specification 15, p. 26).

          • addTag {P : Type u_1} {α : Type u_2} (t : TaggedElem P α) : ORSetEff P α

            Downstream insertion of a uniquely tagged entry t.

          • removeTags {P : Type u_1} {α : Type u_2} (R : Finset (TaggedElem P α)) : ORSetEff P α

            Downstream removal of the finite set R of tagged entries observed at the source replica.

          def Cslib.Distributed.CRDT.instDecidableEqORSetEff.decEq {P✝ : Type u_1} {α✝ : Type u_2} [DecidableEq P✝] [DecidableEq α✝] (x✝ x✝¹ : ORSetEff P✝ α✝) :
          Decidable (x✝ = x✝¹)
          @[instance_reducible]
          instance Cslib.Distributed.CRDT.instDecidableEqORSetEff {P✝ : Type u_1} {α✝ : Type u_2} [DecidableEq P✝] [DecidableEq α✝] :
          DecidableEq (ORSetEff P✝ α✝)
          def Cslib.Distributed.CRDT.orsetEffect {P : Type u_1} {α : Type u_2} [DecidableEq P] [DecidableEq α] :
          ORSetEff P α → Finset (TaggedElem P α) → Finset (TaggedElem P α)

          Downstream state transformer of the op-based OR-Set on Finset (TaggedElem P α).

          def Cslib.Distributed.CRDT.orsetElements {P : Type u_1} {α : Type u_2} [DecidableEq α] (s : Finset (TaggedElem P α)) :

          Query extracting visible α elements from an op-based OR-Set payload.

          def Cslib.Distributed.CRDT.orsetCmRDT (P : Type u_1) (α : Type u_2) [DecidableEq P] [DecidableEq α] :
          CmRDT (Finset (TaggedElem P α)) (ORSetOp P α) (ORSetEff P α) (Finset α)

          Op-based CmRDT instance for the Observed-Remove Set (OR-Set, Specification 15, [SPBZ11a], §3.3.5, p. 26).

          def Cslib.Distributed.CRDT.orsetSurvivingTags {P : Type u_1} {α : Type u_2} {Ev : Type u_3} [DecidableEq P] [DecidableEq α] (prec : Ev → Ev → Prop) [DecidableRel prec] (opOf : Ev → ORSetOp P α) (H : Finset Ev) :

          Set of tagged entries surviving in causal history H under causal precedence prec: tagged entries ⟨x, p, seq⟩ generated by an add p seq x event e ∈ H not causally followed (prec) by any remove x event r ∈ H.

          @[simp]
          theorem Cslib.Distributed.CRDT.mem_orsetSurvivingTags_iff {P : Type u_1} {α : Type u_2} {Ev : Type u_3} [DecidableEq P] [DecidableEq α] {prec : Ev → Ev → Prop} [DecidableRel prec] {opOf : Ev → ORSetOp P α} {H : Finset Ev} {t : TaggedElem P α} :
          t ∈ orsetSurvivingTags prec opOf H ↔ ∃ e ∈ H, opOf e = ORSetOp.add t.replica t.seq t.elem ∧ ¬∃ r ∈ H, opOf r = ORSetOp.remove t.elem ∧ prec e r
          structure Cslib.Distributed.CRDT.ORSetCausalHistory (P : Type u_1) (α : Type u_2) (Ev : Type u_3) [DecidableEq P] [DecidableEq α] [DecidableEq Ev] (prec : Ev → Ev → Prop) [DecidableRel prec] (H : Finset Ev) :
          Type (max (max u_1 u_2) u_3)

          Well-formed finite causally closed OR-Set execution history H : Finset Ev under strict partial order prec ([SPBZ11a], §3.3.5, Specification 15, p. 26):

          1. H is causally closed (IsCausallyClosed prec H);
          2. distinct add events in H allocate distinct (replica, seq) tags (unique_add_tag);
          3. each add p n x prepares .addTag ⟨x, p, n⟩; and
          4. each remove x event e ∈ H prepares .removeTags from the tags of x present in its source replica's state after some causal linearization l_src of e's causal past H.filter (fun u => prec u e).
          theorem Cslib.Distributed.CRDT.ORSetCausalHistory.concurrentCommute {P : Type u_1} {α : Type u_2} {Ev : Type u_3} [DecidableEq P] [DecidableEq α] [DecidableEq Ev] {prec : Ev → Ev → Prop} [IsStrictOrder Ev prec] [DecidableRel prec] {H : Finset Ev} (hH : ORSetCausalHistory P α Ev prec H) :

          Op-based OR-Set concurrent commutativity step (toward #7502, after [SPBZ11a], §3.3.5, Specification 15, pp. 26–27): in any well-formed causal history hH, concurrent downstream OR-Set effects commute.

          theorem Cslib.Distributed.CRDT.ORSetCausalHistory.foldl_eq_survivingTags {P : Type u_1} {α : Type u_2} {Ev : Type u_3} [DecidableEq P] [DecidableEq α] [DecidableEq Ev] {prec : Ev → Ev → Prop} [IsStrictOrder Ev prec] [DecidableRel prec] {H : Finset Ev} (hH : ORSetCausalHistory P α Ev prec H) {l : List Ev} (hl : IsCausalLinearization prec H l) :
          List.foldl (fun (s : Finset (TaggedElem P α)) (e : Ev) => orsetEffect (hH.effOf e) s) ∅ l = orsetSurvivingTags prec hH.opOf H

          Op-based OR-Set exact tag-state evaluation step (toward #7502, after [SPBZ11a], §3.3.5, Specification 15, pp. 26–27): every causal linearization l of H evaluates to orsetSurvivingTags prec hH.opOf H.

          theorem Cslib.Distributed.CRDT.ORSetCausalHistory.mem_elements_iff_causal_add_wins {P : Type u_1} {α : Type u_2} {Ev : Type u_3} [DecidableEq P] [DecidableEq α] [DecidableEq Ev] {prec : Ev → Ev → Prop} [IsStrictOrder Ev prec] [DecidableRel prec] {H : Finset Ev} (hH : ORSetCausalHistory P α Ev prec H) {l : List Ev} (hl : IsCausalLinearization prec H l) (x : α) :
          x ∈ orsetElements (List.foldl (fun (s : Finset (TaggedElem P α)) (e : Ev) => orsetEffect (hH.effOf e) s) ∅ l) ↔ ∃ e_add ∈ H, (∃ (p : P) (n : ℕ), hH.opOf e_add = ORSetOp.add p n x) ∧ ¬∃ e_rem ∈ H, hH.opOf e_rem = ORSetOp.remove x ∧ prec e_add e_rem

          Op-based OR-Set Causal Add-Wins Specification step (toward #7502, after [SPBZ11a], §3.3.5, Specification 15 & Figure 14, pp. 26–27): after any causal linearization l of H, element x belongs to orsetElements iff H contains an add p n x event e_add that is not causally followed (prec) by any remove x event e_rem ∈ H.

          Untagged Set Merge Impossibility and Naïve Op-Based Non-Commutativity #

          theorem Cslib.Distributed.CRDT.not_exists_untagged_finset_merge {α : Type u_1} [DecidableEq α] [Nonempty α] :
          ¬∃ (merge : Finset α → Finset α → Finset α), Std.Commutative merge ∧ (∀ (x : α), x ∈ merge ∅ (insert x ∅)) ∧ ∀ (x : α), x ∉ merge {x} ({x}.erase x)

          Untagged set state-merge impossibility (original to this library, formalizing the untagged add/remove conflict motivation of [SPBZ11a], §3.3, p. 21): over any nonempty element type α, there is no binary commutative merge operation merge : Finset α → Finset α → Finset α on plain untagged sets that simultaneously:

          1. propagates a fresh add (insert x ∅ = {x}) to an untouched peer at ∅ (∀ x, x ∈ merge ∅ (insert x ∅)), and
          2. propagates a sequential remove-after-add (({x} : Finset α).erase x = ∅) to a peer still holding {x} (∀ x, x ∉ merge {x} (({x} : Finset α).erase x)), because without per-addition tags or tombstones both executions yield the same unordered pair of replica states {∅, {x}}.

          Naïve op-based untagged insert/erase non-commutativity step (toward #7502, after [SPBZ11a], §3.3, Figure 11, p. 21).