Skip to content

Commit 736c8e0

Browse files
committed
Add Local Updates
1 parent b1c2096 commit 736c8e0

3 files changed

Lines changed: 487 additions & 7 deletions

File tree

src/Iris/Algebra/CMRA.lean

Lines changed: 180 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,20 @@ theorem _root_.Iris.OFE.Equiv.opM {x₁ x₂ : α} {y₁ y₂ : Option α}
169169
(H1 : x₁ ≡ x₂) (H2 : y₁ ≡ y₂) : x₁ •? y₁ ≡ x₂ •? y₂ :=
170170
equiv_dist.2 fun _ => H1.dist.opM H2.dist
171171

172+
theorem opM_left_eqv {x y : α} (z : Option α) (e : x ≡ y) : x •? z ≡ y •? z := e.opM Equiv.rfl
173+
theorem opM_right_eqv (x : α) {y z : Option α} (e : y ≡ z) : x •? y ≡ x •? z := Equiv.rfl.opM e
174+
175+
theorem opM_left_dist {n} {x y : α} (z : Option α) (e : x ≡{n}≡ y) : x •? z ≡{n}≡ y •? z :=
176+
e.opM Dist.rfl
177+
theorem opM_right_dist {n} (x : α) {y z : Option α} (e : y ≡{n}≡ z) : x •? y ≡{n}≡ x •? z :=
178+
Dist.rfl.opM e
179+
172180
theorem op_opM_assoc (x y : α) (mz : Option α) : (x • y) •? mz ≡ x • (y •? mz) := by
173181
unfold op?; cases mz <;> simp [assoc, Equiv.symm]
174182

183+
theorem op_opM_assoc_dist (x y : α) (mz : Option α) : (x • y) •? mz ≡{n}≡ x • (y •? mz) := by
184+
unfold op?; cases mz <;> simp [assoc.dist, Dist.symm]
185+
175186
/-! ## Validity -/
176187

177188
theorem Valid.validN : ✓ (x : α) → ✓{n} x := (valid_iff_validN.1 · _)
@@ -194,6 +205,8 @@ theorem _root_.Iris.OFE.Equiv.valid : (x : α) ≡ y → (✓ x ↔ ✓ y) := va
194205
theorem validN_of_le {n n'} {x : α} : n' ≤ n → ✓{n} x → ✓{n'} x :=
195206
fun le => le.recOn id fun _ ih vs => ih (validN_succ vs)
196207

208+
theorem valid0_of_validN {n} {x : α} : ✓{n} x → ✓{0} x := validN_of_le (Nat.zero_le n)
209+
197210
theorem validN_op_right {n} {x y : α} : ✓{n} (x • y) → ✓{n} y :=
198211
fun v => validN_op_left (validN_of_eqv comm v)
199212

@@ -203,6 +216,14 @@ theorem valid_op_right (x y : α) : ✓ (x • y) → ✓ y :=
203216
theorem valid_op_left {x y : α} : ✓ (x • y) → ✓ x :=
204217
fun v => valid_op_right y x (valid_of_eqv comm v)
205218

219+
theorem validN_opM {x: α}{my: Option α}: ✓{n} (x •? my) → ✓{n} x :=
220+
match my with
221+
| none => id | some _ => validN_op_left
222+
223+
theorem valid_opM {x: α}{my: Option α}: ✓ (x •? my) → ✓ x :=
224+
match my with
225+
| none => id | some _ => valid_op_left
226+
206227
/-! ## Core -/
207228

208229
theorem pcore_proper {x y : α} (cx : α) (e : x ≡ y) (ps : pcore x = some cx)
@@ -377,6 +398,7 @@ theorem Included.validN {n} {x y : α} : x ≼ y → ✓{n} y → ✓{n} x := va
377398

378399
theorem incN_of_incN_le {n n'} {x y : α} (l1 : n' ≤ n) : x ≼{n} y → x ≼{n'} y
379400
| ⟨z, hz⟩ => ⟨z, Dist.le hz l1⟩
401+
theorem inc0_of_incN {n} {x y : α} : x ≼{n} y → x ≼{0} y := incN_of_incN_le (Nat.zero_le n)
380402
theorem IncludedN.le {n n'} {x y : α} : n' ≤ n → x ≼{n} y → x ≼{n'} y := incN_of_incN_le
381403

382404
theorem incN_of_incN_succ {n} {x y : α} : x ≼{n.succ} y → x ≼{n} y :=
@@ -470,6 +492,9 @@ theorem pcore_eq_core (x : α) : pcore x = some (core x) := by
470492
theorem op_core (x : α) : x • core x ≡ x := pcore_op_right (pcore_eq_core x)
471493
theorem core_op (x : α) : core x • x ≡ x := comm.trans (op_core x)
472494

495+
theorem op_core_dist {n}(x: α) : x • core x ≡{n}≡ x := (op_core x).dist
496+
theorem core_op_dist {n}(x: α) : core x • x ≡{n}≡ x := (core_op x).dist
497+
473498
theorem core_op_core {x : α} : core x • core x ≡ core x :=
474499
pcore_op_self (pcore_eq_core x)
475500
theorem validN_core {n} {x : α} (v : ✓{n} x) : ✓{n} core x := pcore_validN (pcore_eq_core x) v
@@ -591,6 +616,12 @@ theorem cancelable_iff {x₁ x₂ : α} (e : x₁ ≡ x₂) : Cancelable x₁
591616
theorem _root_.Iris.OFE.Equiv.cancelable {x₁ x₂ : α} : x₁ ≡ x₂ → (Cancelable x₁ ↔ Cancelable x₂) :=
592617
cancelable_iff
593618

619+
theorem op_opM_cancel_dist {x y z: α} [Cancelable x]
620+
(vxy: ✓{n} x • y) (h: x • y ≡{n}≡ (x • z) •? mw): y ≡{n}≡ z •? mw :=
621+
match mw with
622+
| none => cancelableN vxy h
623+
| some _ => cancelableN vxy (h.trans (op_assocN.symm))
624+
594625
end cancelableElements
595626

596627
section idFreeElements
@@ -664,8 +695,12 @@ theorem incN_unit {n} {x : α} : unit ≼{n} x := ⟨x, unit_left_id.symm.dist
664695

665696
theorem inc_unit {x : α} : unit ≼ x := ⟨x, unit_left_id.symm⟩
666697

698+
theorem unit_left_id_dist {n} (x : α) : unit • x ≡{n}≡ x := unit_left_id.dist
699+
667700
theorem unit_right_id {x : α} : x • unit ≡ x := comm.trans unit_left_id
668701

702+
theorem unit_right_id_dist (x : α) : x • unit ≡{n}≡ x := comm.dist.trans (unit_left_id_dist x)
703+
669704
instance unit_CoreId : CoreId (unit : α) where
670705
core_id := pcore_unit
671706

@@ -958,25 +993,25 @@ end DiscreteFunURF
958993

959994
section option
960995

961-
variable [CMRA A]
996+
variable [CMRA α]
962997

963-
def optionCore (x : Option A) : Option A := x.bind CMRA.pcore
998+
def optionCore (x : Option α) : Option α := x.bind CMRA.pcore
964999

965-
def optionOp (x y : Option A) : Option A :=
1000+
def optionOp (x y : Option α) : Option α :=
9661001
match x, y with
9671002
| some x', some y' => some (CMRA.op x' y')
9681003
| none, _ => y
9691004
| _, none => x
9701005

971-
def optionValidN (n : Nat) : Option AProp
1006+
def optionValidN (n : Nat) : Option αProp
9721007
| some x => ✓{n} x
9731008
| none => True
9741009

975-
def optionValid : Option AProp
1010+
def optionValid : Option αProp
9761011
| some x => ✓ x
9771012
| none => True
9781013

979-
instance cmraOption : CMRA (Option A) where
1014+
instance cmraOption : CMRA (Option α) where
9801015
pcore x := some (optionCore x)
9811016
op := optionOp
9821017
ValidN := optionValidN
@@ -1037,14 +1072,152 @@ instance cmraOption : CMRA (Option A) where
10371072
· rcases CMRA.extend Hx Hx' with ⟨mc1, mc2, _, _, _⟩
10381073
exists some mc1, some mc2
10391074

1040-
instance ucmraOption : UCMRA (Option A) where
1075+
instance ucmraOption : UCMRA (Option α) where
10411076
unit := none
10421077
unit_valid := by simp [CMRA.Valid, optionValid]
10431078
unit_left_id := by rintro ⟨⟩ <;> rfl
10441079
pcore_unit := by rfl
10451080

1081+
theorem CMRA.equiv_of_some_equiv_some {x y : α} (h: some x ≡ some y): x ≡ y := h
1082+
theorem CMRA.dist_of_some_dist_some {n} {x y : α} (h: some x ≡{n}≡ some y): x ≡{n}≡ y := h
1083+
1084+
theorem CMRA.op_some_opM_assoc (x y : α) (mz : Option α) : (x • y) •? mz ≡ x •? (some y • mz) :=
1085+
match mz with
1086+
| none => Equiv.rfl
1087+
| some _ => Equiv.symm assoc
1088+
1089+
theorem CMRA.op_some_opM_assoc_dist (x y : α) (mz : Option α) : (x • y) •? mz ≡{n}≡ x •? (some y • mz) :=
1090+
match mz with
1091+
| none => Dist.rfl
1092+
| some _ => Dist.symm assoc.dist
1093+
1094+
theorem CMRA.some_inc_some_of_dist_opM {x y : α} {mz : Option α} (h: x ≡{n}≡ y •? mz)
1095+
: some y ≼{n} some x :=
1096+
match mz with
1097+
| none => ⟨none, h⟩
1098+
| some z => ⟨some z, h⟩
1099+
1100+
theorem CMRA.inc_of_some_inc_some [CMRA.IsTotal α] {x y : α} (h: some y ≼ some x): y ≼ x :=
1101+
let ⟨mz, hmz⟩ := h
1102+
match mz with
1103+
| none => ⟨core y, (CMRA.equiv_of_some_equiv_some hmz).trans (op_core y).symm⟩
1104+
| some z => ⟨z, hmz⟩
1105+
1106+
theorem CMRA.incN_of_some_incN_some [CMRA.IsTotal α] {x y : α} (h: some y ≼{n} some x): y ≼{n} x :=
1107+
let ⟨mz, hmz⟩ := h
1108+
match mz with
1109+
| none => ⟨core y, (CMRA.dist_of_some_dist_some hmz).trans (op_core_dist y).symm⟩
1110+
| some z => ⟨z, hmz⟩
1111+
1112+
theorem CMRA.exists_op_some_eqv_some (x : Option α) (y : α): ∃z, x • some y ≡ some z :=
1113+
match x with
1114+
| .none => ⟨y, Equiv.rfl⟩
1115+
| .some w => ⟨w • y, Equiv.rfl⟩
1116+
1117+
theorem CMRA.exists_op_some_dist_some {n} (x : Option α) (y : α): ∃z, x • some y ≡{n}≡ some z :=
1118+
(CMRA.exists_op_some_eqv_some x y).elim fun z h => ⟨z, h.dist⟩
1119+
1120+
theorem not_valid_some_exclN_op_left {n} {x : α} [CMRA.Exclusive x] {y: α}
1121+
: ¬✓{n} (some x • some y) :=
1122+
fun h =>
1123+
have : ✓{n} x • y := h
1124+
absurd this (by exact CMRA.not_valid_exclN_op_left)
1125+
1126+
theorem validN_op_unit {n} {x : Option α} (vx: ✓{n} x): ✓{n} x • CMRA.unit :=
1127+
match x with
1128+
| .none => vx
1129+
| .some _ => vx
1130+
10461131
end option
10471132

1133+
section unit
1134+
1135+
instance cmraUnit : CMRA Unit where
1136+
pcore _ := some ()
1137+
op _ _ := ()
1138+
ValidN _ _ := True
1139+
Valid _ := True
1140+
op_ne.ne _ _ _ H := H
1141+
pcore_ne {_} _ _ z _ _ := match z with | .unit => ⟨(), rfl, OFE.Dist.rfl⟩
1142+
validN_ne {_} _ _ _ := id
1143+
valid_iff_validN := ⟨fun _ _ => .intro, fun _ => .intro⟩
1144+
validN_succ := id
1145+
validN_op_left := id
1146+
assoc := OFE.Equiv.rfl
1147+
comm := OFE.Equiv.rfl
1148+
pcore_op_left {x _} _ := match x with | .unit => OFE.Equiv.rfl
1149+
pcore_idem {_ cx} _ := match cx with | .unit => OFE.Equiv.rfl
1150+
pcore_op_mono _ _ := ⟨.unit, OFE.Equiv.rfl⟩
1151+
extend {_} x y z _ _ :=
1152+
match x, y, z with
1153+
| .unit, .unit, .unit => ⟨(), (), OFE.Equiv.rfl, OFE.Dist.rfl, OFE.Dist.rfl⟩
1154+
1155+
end unit
1156+
1157+
section prod
1158+
1159+
variable [CMRA α] [CMRA β]
1160+
1161+
instance cmraProd : CMRA (α × β) where
1162+
pcore x := do
1163+
let a <- CMRA.pcore x.fst
1164+
let b <- CMRA.pcore x.snd
1165+
return (a,b)
1166+
op x y := (x.fst • y.fst, x.snd • y.snd)
1167+
ValidN n x := ✓{n} x.fst ∧ ✓{n} x.snd
1168+
Valid x := ✓ x.fst ∧ ✓ x.snd
1169+
op_ne {x} :=
1170+
{ne n y z h := dist_prod_ext (Dist.op_r $ dist_fst h) (Dist.op_r $ dist_snd h)}
1171+
pcore_ne {n x y cx} h ph :=
1172+
have ⟨cx₁, hcx₁, this⟩ := Option.bind_eq_some.mp ph
1173+
have ⟨cx₂, hcx₂, hcx⟩ := Option.bind_eq_some.mp this
1174+
have ⟨cy₁, hcy₁, hxy₁⟩ := CMRA.pcore_ne (dist_fst h) hcx₁
1175+
have ⟨cy₂, hcy₂, hxy₂⟩ := CMRA.pcore_ne (dist_snd h) hcx₂
1176+
suffices g: cx ≡{n}≡ (cy₁, cy₂) by simp [hcy₁, hcy₂, g]
1177+
calc
1178+
cx ≡{n}≡ (cx₁, cx₂) := Dist.of_eq (Option.some.inj hcx).symm
1179+
_ ≡{n}≡ (cy₁, cy₂) := dist_prod_ext hxy₁ hxy₂
1180+
validN_ne {n} x y H := fun ⟨vx1, vx2⟩ =>
1181+
⟨ (Dist.validN $ dist_fst H).mp vx1, (Dist.validN $ dist_snd H).mp vx2 ⟩
1182+
valid_iff_validN {x} :=
1183+
fun ⟨va, vb⟩ n => ⟨CMRA.Valid.validN va, CMRA.Valid.validN vb⟩,
1184+
fun h =>
1185+
⟨ CMRA.valid_iff_validN.mpr fun n => (h n).left,
1186+
CMRA.valid_iff_validN.mpr fun n => (h n).right ⟩ ⟩
1187+
validN_succ {x n} := fun ⟨va, vb⟩ => ⟨CMRA.validN_succ va, CMRA.validN_succ vb⟩
1188+
validN_op_left {n x y} := fun ⟨va, vb⟩ => ⟨CMRA.validN_op_left va, CMRA.validN_op_left vb⟩
1189+
assoc {x y z} := ⟨CMRA.assoc, CMRA.assoc⟩
1190+
comm {x y} := ⟨CMRA.comm, CMRA.comm⟩
1191+
pcore_op_left {x cx} h :=
1192+
let ⟨a, ha, ho⟩ := Option.bind_eq_some.mp h
1193+
let ⟨b, hb, hh⟩ := Option.bind_eq_some.mp ho
1194+
(Option.some.inj hh) ▸ OFE.equiv_prod_ext (CMRA.pcore_op_left ha) (CMRA.pcore_op_left hb)
1195+
pcore_idem {x cx} h :=
1196+
have ⟨cx₁, hcx₁, this⟩ := Option.bind_eq_some.mp h
1197+
have ⟨cx₂, hcx₂, hcx⟩ := Option.bind_eq_some.mp this
1198+
have ⟨a, ha, ea⟩ := equiv_some (CMRA.pcore_idem hcx₁)
1199+
have ⟨b, hb, eb⟩ := equiv_some (CMRA.pcore_idem hcx₂)
1200+
suffices g: (a, b) ≡ (cx₁, cx₂) by
1201+
rw [Option.some.inj hcx.symm]
1202+
simp [ha, hb, g]
1203+
equiv_prod_ext ea eb
1204+
pcore_op_mono {x cx} h y := by
1205+
have ⟨cx₁, hcx₁, this⟩ := Option.bind_eq_some.mp h
1206+
have ⟨cx₂, hcx₂, hcx⟩ := Option.bind_eq_some.mp this
1207+
have ⟨cy₁, hcy₁⟩ := CMRA.pcore_op_mono hcx₁ y.fst
1208+
have ⟨cy₂, hcy₂⟩ := CMRA.pcore_op_mono hcx₂ y.snd
1209+
have ⟨a, ha, ea⟩ := equiv_some hcy₁
1210+
have ⟨b, hb, eb⟩ := equiv_some hcy₂
1211+
rw [Option.some.inj hcx.symm, ha, hb]
1212+
exists (cy₁, cy₂)
1213+
extend {n x y₁ y₂} := fun ⟨vx₁, vx₂⟩ e =>
1214+
let ⟨z₁, w₁, hx₁, hz₁, hw₁⟩ := CMRA.extend vx₁ (OFE.dist_fst e)
1215+
let ⟨z₂, w₂, hx₂, hz₂, hw₂⟩ := CMRA.extend vx₂ (OFE.dist_snd e)
1216+
⟨ (z₁, z₂), (w₁, w₂), OFE.equiv_prod_ext hx₁ hx₂,
1217+
OFE.dist_prod_ext hz₁ hz₂, OFE.dist_prod_ext hw₁ hw₂ ⟩
1218+
1219+
end prod
1220+
10481221
section optionOF
10491222

10501223
variable (F : COFE.OFunctorPre)

0 commit comments

Comments
 (0)