Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2192cc3
Add prod and unit CMRAs
suhr Jun 23, 2025
7b3836b
fix: add back in validity lemmas
markusdemedeiros Jul 1, 2025
6578dbf
fix: Prod namespace
markusdemedeiros Jul 1, 2025
209f0b1
fix: remove warnings
markusdemedeiros Jul 1, 2025
8a44353
Add Local Updates
suhr Jun 23, 2025
ba9e121
fix: naming and style
oliversoeser Jun 30, 2025
2fc5c28
Add Updates
suhr Jun 25, 2025
825536d
fix: naming and sections
oliversoeser Jun 30, 2025
e708e39
feat: implement frac
markusdemedeiros Jun 22, 2025
9e8fdf1
Initial comit
Shreyas4991 Jun 25, 2025
085df04
Add positive lemma. Why are all the instances failing now
Shreyas4991 Jun 25, 2025
7eed0d8
Add halving axiom
Shreyas4991 Jun 25, 2025
1f2edd0
Remove halving
Shreyas4991 Jun 25, 2025
1b0678a
one sorry down
Shreyas4991 Jun 27, 2025
9c942a7
two sorries down
Shreyas4991 Jun 27, 2025
e312c36
Narrow down error
Shreyas4991 Jun 27, 2025
0a826f8
Narrow down error
Shreyas4991 Jun 27, 2025
62ae882
Turn all non-terminal simps into simp onlys
Shreyas4991 Jun 27, 2025
4adf4cb
Add name to authors list
Shreyas4991 Jun 27, 2025
985050d
factor out the <1 features
markusdemedeiros Jun 27, 2025
258d53c
Fractor out UFractional
markusdemedeiros Jun 27, 2025
d83f8f3
tweak Fractional and Whole definition
markusdemedeiros Jul 1, 2025
a1eef65
more Frac lemmas
markusdemedeiros Jul 1, 2025
61c6597
Relax UFraction typeclass
markusdemedeiros Jul 1, 2025
c0d653f
feat: implement dfrac
markusdemedeiros Jun 23, 2025
949d470
sorry out breaking changes
markusdemedeiros Jun 27, 2025
b84bffd
Update DFractional to alias UFractional
markusdemedeiros Jun 27, 2025
d697fb3
checkpoint
markusdemedeiros Jul 1, 2025
201fa9b
checkpoint
markusdemedeiros Jul 1, 2025
939d0a6
checkpoint
markusdemedeiros Jul 1, 2025
3897b30
checkpoint
markusdemedeiros Jul 1, 2025
35e3752
checkpoint
markusdemedeiros Jul 1, 2025
b88af62
solve all sorrys
markusdemedeiros Jul 1, 2025
723409d
checkpoint: View OFE
markusdemedeiros Jun 23, 2025
dbc225d
checkpoint: need to rebase on top of local_update PR
markusdemedeiros Jun 23, 2025
36a2418
checkpoint: view op and pcore def
markusdemedeiros Jun 24, 2025
f9ba029
feat: view CMRA
markusdemedeiros Jun 24, 2025
23c091a
feat: view UCMRA
markusdemedeiros Jun 24, 2025
95857e7
op lemmas
markusdemedeiros Jun 24, 2025
3cd8f57
sorry out View lemmas
markusdemedeiros Jun 24, 2025
8670c02
Add to view
markusdemedeiros Jun 26, 2025
bbb363e
More View lemmas
markusdemedeiros Jun 26, 2025
7b76fa3
sorry out breaking changes
markusdemedeiros Jun 27, 2025
86bcb18
feat: view CMRA
markusdemedeiros Jun 24, 2025
9b5d4b6
fix build
markusdemedeiros Jul 1, 2025
b2a821e
fix build
markusdemedeiros Jul 1, 2025
20f8bdb
fix
markusdemedeiros Jul 1, 2025
48dc873
sorry-free
markusdemedeiros Jul 1, 2025
4e19afa
Merge branch 'master' into views
markusdemedeiros Jul 9, 2025
0ca15df
merge?
markusdemedeiros Jul 9, 2025
b7dd163
fix sorrys introduced by merge
markusdemedeiros Jul 9, 2025
80a3086
fix bogus definition
markusdemedeiros Jul 18, 2025
a5e3d21
Merge branch 'master' into views
markusdemedeiros Jul 19, 2025
c3049ed
fix build
markusdemedeiros Jul 19, 2025
2771e39
basic view updates
markusdemedeiros Jul 29, 2025
7976c25
View update lemmas
markusdemedeiros Jul 29, 2025
ce8df80
some refactoring
markusdemedeiros Jul 29, 2025
58dc120
some refactoring on agree
markusdemedeiros Sep 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Iris/Algebra.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ import Iris.Algebra.CMRA
import Iris.Algebra.COFESolver
import Iris.Algebra.OFE
import Iris.Algebra.Frac
import Iris.Algebra.View
40 changes: 40 additions & 0 deletions src/Iris/Algebra/Agree.lean
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,41 @@ theorem Agree.includedN {x y : Agree α} : x ≼{n} y ↔ y ≡{n}≡ y • x :=
theorem Agree.included {x y : Agree α} : x ≼ y ↔ y ≡ y • x :=
⟨fun ⟨z, h⟩ n => includedN.mp ⟨z, h n⟩, fun h => ⟨y, h.trans op_comm⟩⟩

theorem Agree.toAgree.is_discrete {a : α} (Ha : OFE.DiscreteE a) : OFE.DiscreteE (toAgree a) := by
refine ⟨fun ⟨Hal, Har⟩ _ => ?_⟩
constructor <;> simp_all [toAgree]
· rcases Hal with ⟨b, Hb1, Hb2⟩
exact ⟨b, ⟨Hb1, Ha.discrete (Har b Hb1) |>.dist⟩⟩
· intro H Hb
exact Ha.discrete (Har H Hb) |>.dist

open OFE OFE.Discrete in
instance [OFE α] [Discrete α] : Discrete (Agree α) where
discrete_0 {x y} H := by
refine fun n => ⟨fun a Ha => ?_, fun b Hb => ?_⟩
· rcases H.1 a Ha with ⟨c, Hc⟩
refine ⟨c, ⟨Hc.1, ?_⟩⟩
apply equiv_dist.mp <| discrete_0 (Hc.2.le <| Nat.zero_le 0)
· rcases H.2 b Hb with ⟨c, Hc⟩
refine ⟨c, ⟨Hc.1, ?_⟩⟩
apply equiv_dist.mp <| discrete_0 (Hc.2.le <| Nat.zero_le 0)

instance toAgree.ne [OFE α] : OFE.NonExpansive (toAgree : α → Agree α) where
ne n x y H := by
refine ⟨?_, ?_⟩
· intro a Ha; exists y; revert Ha
simp [toAgree]; exact (·▸H)
· intro b Hb; exists x; revert Hb
simp [toAgree]; exact (·▸H)

theorem toAgree.inj {a1 a2 : α} {n} (H : toAgree a1 ≡{n}≡ toAgree a2) : a1 ≡{n}≡ a2 := by
have Hinc : a1 ∈ (toAgree a1).car := by simp [toAgree]
rcases H.1 a1 Hinc with ⟨_, ⟨_, _⟩⟩
simp_all [toAgree]

instance : CMRA.IsTotal (Agree α) where
total := by simp [CMRA.pcore]

theorem Agree.valid_includedN {x y : Agree α} : ✓{n} y → x ≼{n} y → x ≡{n}≡ y := by
intro hval ⟨z, heq⟩
have : ✓{n} (x • z) := heq.validN.mp hval
Expand Down Expand Up @@ -354,4 +389,9 @@ theorem Agree.agree_map_ext {g : α → β} [OFE.NonExpansive g] (heq : ∀ a, f
· exact ⟨g a, ⟨a, ha, rfl⟩, (heq a).dist⟩
· exact ⟨f a, ⟨a, ha, rfl⟩, (heq a).dist⟩

theorem toAgree.incN {a b : α} {n} : toAgree a ≼{n} toAgree b ↔ a ≡{n}≡ b := by
refine ⟨?_, fun H => (CMRA.incN_iff_right <| toAgree.ne.ne H).mp <| CMRA.incN_refl _⟩
intro H
apply toAgree.inj
exact Agree.valid_includedN trivial H
end agree_map
4 changes: 2 additions & 2 deletions src/Iris/Algebra/CMRA.lean
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ theorem valid_opM {x : α} {my : Option α} : ✓ (x •? my) → ✓ x :=
match my with
| none => id | some _ => valid_op_left

theorem validN_op_opM_left {mz : Option α} : ✓{n} (x • y) •? mz → ✓{n} x •? mz :=
theorem validN_op_opM_left {mz : Option α} : ✓{n} (x • y : α) •? mz → ✓{n} x •? mz :=
match mz with
| .none => validN_op_left
| .some z => fun h =>
Expand All @@ -234,7 +234,7 @@ theorem validN_op_opM_left {mz : Option α} : ✓{n} (x • y) •? mz → ✓{n
_ ≡{n}≡ (x • z) • y := op_assocN
validN_op_left ((Dist.validN this).mp h)

theorem validN_op_opM_right {mz : Option α} (h : ✓{n} (x • y) •? mz) : ✓{n} y •? mz :=
theorem validN_op_opM_right {mz : Option α} (h : ✓{n} (x • y : α) •? mz) : ✓{n} y •? mz :=
validN_op_opM_left (validN_ne (opM_left_dist mz op_commN) h)

/-! ## Core -/
Expand Down
59 changes: 59 additions & 0 deletions src/Iris/Algebra/DFrac.lean
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Authors: Markus de Medeiros, Mario Carneiro
import Iris.Algebra.CMRA
import Iris.Algebra.OFE
import Iris.Algebra.Frac
import Iris.Algebra.Updates
import Iris.Algebra.LocalUpdates

namespace Iris

Expand Down Expand Up @@ -138,4 +140,61 @@ theorem valid_discard : ✓ (discard : DFrac F) := by simp [CMRA.Valid, valid]
theorem valid_own_op_discard {q : F} : ✓ own q • discard ↔ Fractional q := by
simp [CMRA.op, op, CMRA.Valid, valid]

instance : CMRA.Discrete (DFrac F) where
discrete_valid {x} := by simp [CMRA.Valid, CMRA.ValidN]

theorem dfrac.is_discrete {q : DFrac F} : OFE.DiscreteE q := ⟨congrArg id⟩

instance : CMRA.Discrete (DFrac F) where
discrete_valid {x} := by simp [CMRA.Valid, CMRA.ValidN]

theorem dfrac_discard_update {dq : DFrac F} : dq ~~> .discard := by
rintro n (_|⟨q|_|q⟩) H <;>
have H' := (CMRA.valid_iff_validN' n).mpr H <;>
apply (CMRA.valid_iff_validN' n).mp <;>
simp [CMRA.op?] at H' ⊢
· simp [CMRA.Valid, valid]
· cases dq
· exact valid_op_own H
· exact H
· exact valid_op_own H
· simp [CMRA.Valid, valid, CMRA.op, op]
· cases dq
· exact CMRA.valid_op_right _ _ H
· exact H
· exact CMRA.valid_op_right _ _ H

theorem dfrac_undiscard_update [IsSplitFraction F] :
(.discard : DFrac F) ~~>: fun k => ∃ q, k = .own q := by
apply UpdateP.discrete.mpr
rintro (_|⟨q|_|q⟩)
· rintro _
exists (.own One.one)
refine ⟨⟨One.one, rfl⟩, ?_⟩
simp [CMRA.op?, CMRA.op, op, CMRA.Valid, valid, add_comm]
apply UFraction.one_whole.1
· rintro ⟨q', HP⟩
exists (.own q')
refine ⟨⟨q', rfl⟩, ?_⟩
simp [CMRA.op?, CMRA.op, op, CMRA.Valid, valid, add_comm]
exact HP
· intro _
let q' : F := (IsSplitFraction.split One.one).1
exists (.own q')
refine ⟨⟨q', rfl⟩, ?_⟩
simp [CMRA.op?, CMRA.op, op, CMRA.Valid, valid]
exists (IsSplitFraction.split One.one).2
rw [IsSplitFraction.split_add]
apply UFraction.one_whole.1
· rintro ⟨q', HP⟩
let q'' : F := (IsSplitFraction.split q').1
exists (.own q'')
refine ⟨⟨q'', rfl⟩, ?_⟩
simp [CMRA.op?, CMRA.op, op, CMRA.Valid, valid]
rw [add_comm]
exists (IsSplitFraction.split q').2
rw [← add_assoc]
rw [IsSplitFraction.split_add]
exact HP

end dfrac
4 changes: 4 additions & 0 deletions src/Iris/Algebra/Frac.lean
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class Fraction (α : Type _) extends Add α where
add_ne : ∀ {a b : α}, a ≠ b + a
proper_add_mono_left : ∀ {a b : α}, Proper (a + b) → Proper a

class IsSplitFraction (α : Type _) [Fraction α] where
split : α → α × α
split_add {a : α} : (split a).1 + (split a).2 = a

namespace Fraction

/-- A fraction does not represent the entire resource.
Expand Down
31 changes: 31 additions & 0 deletions src/Iris/Algebra/OFE.lean
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,24 @@ instance [OFE α] [Leibniz α] : Leibniz (Option α) where
| none, none, _ => rfl
| some _, some _, h => congrArg some (Leibniz.eq_of_eqv h)

instance [OFE α] [Discrete α] : Discrete (Option α) where
discrete_0 {x y} H :=
match x, y with
| none, none => H
| some _, some _ => some_eqv_some.mpr (discrete_0 H)

instance OFE.Option.some.ne [OFE α] : OFE.NonExpansive (some : α → Option α) := ⟨fun _ _ _ => id⟩

theorem Option.some_is_discrete [OFE α] {a : α} (Ha : DiscreteE a) : DiscreteE (some a) := by
constructor
intro y H; cases y
· exact H
· exact Ha.discrete H

theorem Option.none_is_discrete [OFE α] : DiscreteE (none : Option α) := by
constructor
intro y; cases y <;> simp

abbrev OFEFun {α : Type _} (β : α → Type _) := ∀ a, OFE (β a)

instance [OFEFun (β : α → _)] : OFE ((x : α) → β x) where
Expand Down Expand Up @@ -349,6 +367,19 @@ theorem dist_snd {n} [OFE α] [OFE β] {x y : α × β} (h : x ≡{n}≡ y) : x.
theorem dist_prod_ext {n} [OFE α] [OFE β] {x₁ x₂ : α} {y₁ y₂ : β}
(ex : x₁ ≡{n}≡ x₂) (ey : y₁ ≡{n}≡ y₂) : (x₁, y₁) ≡{n}≡ (x₂, y₂) := ⟨ex, ey⟩

theorem prod.is_discrete [OFE α] [OFE β] {a : α} {b : β} (Ha : DiscreteE a) (Hb : DiscreteE b) :
DiscreteE (a, b) := by
constructor
intro y H; refine ⟨Ha.discrete H.1, Hb.discrete H.2⟩

instance [OFE α] [OFE β] [Discrete α] [Discrete β] : Discrete (α × β) where
discrete_0 H := by
constructor
· apply Discrete.discrete_0
apply H.1
· apply Discrete.discrete_0
apply H.2

/-- An isomorphism between two OFEs is a pair of morphisms whose composition is equivalent to the
identity morphism. -/
@[ext] structure Iso (α β : Type _) [OFE α] [OFE β] where
Expand Down
2 changes: 1 addition & 1 deletion src/Iris/Algebra/Updates.lean
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ theorem UpdateP.op {P Q R : α → Prop} {x y}
exact ⟨z • w, pqr z w pz pw, CMRA.validN_ne (CMRA.op_opM_assoc_dist z w mz).symm vz⟩

theorem UpdateP.op' {P Q : α → Prop} {x y : α} (uxp : x ~~>: P) (uyq : y ~~>: Q) :
x • y ~~>: λ t ↦ ∃ z w, t = z • w ∧ P z ∧ Q w :=
(x • y : α) ~~>: λ t ↦ ∃ z w, t = (z • w : α) ∧ P z ∧ Q w :=
.op uxp uyq fun z w pz qw => ⟨z, w, rfl, pz, qw⟩

theorem Update.op {x₁ x₂ y₁ y₂ : α} (xy₁ : x₁ ~~> y₁) (xy₂ : x₂ ~~> y₂) : x₁ • x₂ ~~> y₁ • y₂ :=
Expand Down
Loading