From 1e369681512c3b8af82cbedf0a4345aafc8d486b Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Tue, 28 Jul 2026 11:51:00 +0200 Subject: [PATCH 01/33] Towards parametrised step-indexing in `OFE.lean`, add `SIdx` instance for `Nat` in `StepIndexFinite.lean` --- Iris/Iris/Algebra/OFE.lean | 632 +++++++++++++------------ Iris/Iris/Algebra/StepIndexFinite.lean | 66 +++ 2 files changed, 402 insertions(+), 296 deletions(-) create mode 100644 Iris/Iris/Algebra/StepIndexFinite.lean diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 82175557a..9d0f48e60 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -5,6 +5,7 @@ Authors: Mario Carneiro, Sebastian Graf, Sergei Stepanenko -/ module +public meta import Iris.Algebra.StepIndex public meta import Iris.Std.RocqPorting @[expose] public section @@ -13,8 +14,8 @@ namespace Iris /-- Ordered family of equivalences -/ @[rocq_alias ofe] -class OFE (α : Type _) where - Dist : Nat → α → α → Prop +class OFE (SI : outParam <| Type _) [SIdx SI] (α : Type _) where + Dist : SI → α → α → Prop dist_eqv : Equivalence (Dist n) eq_dist : x = y ↔ ∀ n, Dist n x y dist_lt : Dist n x y → m < n → Dist m x y @@ -29,100 +30,102 @@ class OFE (α : Type _) where open OFE -scoped notation:40 x " ≡{" n "}≡ " y:41 => OFE.Dist n x y +scoped notation:40 x " ≡{" n "}≡ " y:41 => Dist n x y namespace OFE +variable [instSI : SIdx SI] + @[rocq_alias dist_equivalence] -theorem dist_equivalence [OFE α] {n} : Equivalence (Dist (α := α) n) := dist_eqv +theorem dist_equivalence [OFE SI α] {n : SI} : Equivalence (Dist (α := α) n) := dist_eqv @[rocq_alias dist_lt] -theorem Dist.lt [OFE α] {m n} {x y : α} : x ≡{n}≡ y → m < n → x ≡{m}≡ y := dist_lt +theorem Dist.lt [OFE SI α] {m n : SI} {x y : α} : x ≡{n}≡ y → m < n → x ≡{m}≡ y := dist_lt @[rocq_alias dist_le] -theorem Dist.le [OFE α] {m n} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := +theorem Dist.le [OFE SI α] {m n : SI} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := if hm : m = n then hm ▸ h else h.lt (Nat.lt_of_le_of_ne h' hm) #rocq_ignore dist_le' "Use Dist.le" #rocq_ignore dist_S "Subsumed by `Dist.lt`/`Dist.le`." -@[simp, refl] theorem Dist.rfl [OFE α] {n} {x : α} : x ≡{n}≡ x := dist_eqv.1 _ -@[symm] theorem Dist.symm [OFE α] {n} {x : α} : x ≡{n}≡ y → y ≡{n}≡ x := dist_eqv.2 -theorem Dist.trans [OFE α] {n} {x : α} : x ≡{n}≡ y → y ≡{n}≡ z → x ≡{n}≡ z := dist_eqv.3 -theorem Dist.of_eq [OFE α] {x y : α} : x = y → x ≡{n}≡ y := (· ▸ .rfl) +@[simp, refl] theorem Dist.rfl [OFE SI α] {n : SI} {x : α} : x ≡{n}≡ x := dist_eqv.1 _ +@[symm] theorem Dist.symm [OFE SI α] {n : SI} {x : α} : x ≡{n}≡ y → y ≡{n}≡ x := dist_eqv.2 +theorem Dist.trans [OFE SI α] {n : SI} {x : α} : x ≡{n}≡ y → y ≡{n}≡ z → x ≡{n}≡ z := dist_eqv.3 +theorem Dist.of_eq [OFE SI α] {x y : α} : x = y → x ≡{n}≡ y := (· ▸ .rfl) #rocq_ignore ofe_equivalence "OFE is Leibniz; use equality" -theorem _root_.Eq.dist [OFE α] {x y : α} (h : x = y) : x ≡{n}≡ y := h ▸ .rfl +theorem _root_.Eq.dist [OFE SI α] {x y : α} (h : x = y) : x ≡{n}≡ y := h ▸ .rfl -instance [OFE α] {n : Nat} : Trans (OFE.Dist n) (OFE.Dist n) (OFE.Dist n : α → α → Prop) where +instance [OFE SI α] {n : SI} : Trans (OFE.Dist n) (OFE.Dist n) (OFE.Dist n : α → α → Prop) where trans := Dist.trans /-- A function `f : α → β` is non-expansive if it preserves `n`-equivalence. -/ -class NonExpansive [OFE α] [OFE β] (f : α → β) where +class NonExpansive [OFE SI α] [OFE SI β] (f : α → β) where ne : ∀ ⦃n x₁ x₂⦄, x₁ ≡{n}≡ x₂ → f x₁ ≡{n}≡ f x₂ -instance id_ne [OFE α] : NonExpansive (@id α) := ⟨fun _ _ _ h => h⟩ +instance id_ne [OFE SI α] : NonExpansive (@id α) := ⟨fun _ _ _ h => h⟩ -instance const_ne [OFE α] [OFE β] {x : α} : NonExpansive (Function.const β x) := ⟨fun _ _ _ _ => .rfl⟩ +instance const_ne [OFE SI α] [OFE SI β] {x : α} : NonExpansive (Function.const β x) := ⟨fun _ _ _ _ => .rfl⟩ /-- Note: Not an instance, as any function can be decomposed as a composition in multiple ways. -/ -theorem NonExpansive.comp [OFE α] [OFE β] [OFE γ] {g : β → γ} {f : α → β} +theorem NonExpansive.comp [OFE SI α] [OFE SI β] [OFE SI γ] {g : β → γ} {f : α → β} (hg : NonExpansive g) (hf : NonExpansive f) : NonExpansive (g ∘ f) := ⟨fun {_ _ _} h => hg.ne (hf.ne h)⟩ #rocq_ignore ne_proper "OFE is Leibniz; use equality" /-- A function `f : α → β → γ` is non-expansive if it preserves `n`-equivalence in each argument. -/ -class NonExpansive₂ [OFE α] [OFE β] [OFE γ] (f : α → β → γ) where +class NonExpansive₂ [OFE SI α] [OFE SI β] [OFE SI γ] (f : α → β → γ) where ne : ∀ ⦃n x₁ x₂⦄, x₁ ≡{n}≡ x₂ → ∀ ⦃y₁ y₂⦄, y₁ ≡{n}≡ y₂ → f x₁ y₁ ≡{n}≡ f x₂ y₂ #rocq_ignore ne_proper_2 "OFE is Leibniz; use equality" /-- Note: Not an instance, for symmetry with NonExpansive₂.ne_left, which cannot be an instance. -/ -theorem NonExpansive₂.ne_right [OFE α] [OFE β] [OFE γ] (f : α → β → γ) [NonExpansive₂ f] +theorem NonExpansive₂.ne_right [OFE SI α] [OFE SI β] [OFE SI γ] (f : α → β → γ) [NonExpansive₂ f] (a : α) : NonExpansive (f a) := ⟨fun {_ _ _} h => ne Dist.rfl h⟩ /-- Note: Not an instance, due to instance coherence problems. -/ -theorem NonExpansive₂.ne_left [OFE α] [OFE β] [OFE γ] (f : α → β → γ) [NonExpansive₂ f] +theorem NonExpansive₂.ne_left [OFE SI α] [OFE SI β] [OFE SI γ] (f : α → β → γ) [NonExpansive₂ f] (b : β) : NonExpansive (f · b) := ⟨fun {_ _ _} h => ne h Dist.rfl⟩ /-- `DistLater n x y` means that `x` and `y` are `m`-equivalent for all `m < n`. -/ @[rocq_alias dist_later] -def DistLater [OFE α] (n : Nat) (x y : α) : Prop := ∀ m, m < n → x ≡{m}≡ y +def DistLater [OFE SI α] (n : SI) (x y : α) : Prop := ∀ m, m < n → x ≡{m}≡ y -@[simp, refl] theorem DistLater.rfl [OFE α] {n} {x : α} : DistLater n x x := fun _ _ => .rfl -@[symm] theorem DistLater.symm [OFE α] {n} {x : α} (h : DistLater n x y) : DistLater n y x := +@[simp, refl] theorem DistLater.rfl [OFE SI α] {n : SI} {x : α} : DistLater n x x := fun _ _ => .rfl +@[symm] theorem DistLater.symm [OFE SI α] {n : SI} {x : α} (h : DistLater n x y) : DistLater n y x := fun _ hm => (h _ hm).symm -theorem DistLater.trans [OFE α] {n} {x : α} (h1 : DistLater n x y) (h2 : DistLater n y z) : +theorem DistLater.trans [OFE SI α] {n : SI} {x : α} (h1 : DistLater n x y) (h2 : DistLater n y z) : DistLater n x z := fun _ hm => (h1 _ hm).trans (h2 _ hm) /-- `DistLater n`-equivalence is an equivalence relation. -/ @[rocq_alias dist_later_equivalence] -theorem distLater_eqv [OFE α] {n} : Equivalence (α := α) (DistLater n) where +theorem distLater_eqv [OFE SI α] {n : SI} : Equivalence (α := α) (DistLater n) where refl _ := DistLater.rfl symm h := h.symm trans h1 := h1.trans /-- `n`-equivalence implies `DistLater n`-equivalence. -/ @[rocq_alias dist_dist_later] -theorem Dist.distLater [OFE α] {n} {x y : α} (h : x ≡{n}≡ y) : DistLater n x y := +theorem Dist.distLater [OFE SI α] {n : SI} {x y : α} (h : x ≡{n}≡ y) : DistLater n x y := fun _ => dist_lt h /-- `DistLater n`-equivalence implies `m`-equivalence for all `m < n`. -/ @[rocq_alias dist_later_dist_lt] -theorem DistLater.dist_lt [OFE α] {m n} {x y : α} (h : DistLater n x y) (hm : m < n) : x ≡{m}≡ y := +theorem DistLater.dist_lt [OFE SI α] {m n : SI} {x y : α} (h : DistLater n x y) (hm : m < n) : x ≡{m}≡ y := h _ hm /-- `DistLater 0`-equivalence is trivial. -/ -@[simp, rocq_alias dist_later_0] theorem distLater_zero [OFE α] {x y : α} : DistLater 0 x y := nofun +@[simp, rocq_alias dist_later_0] theorem distLater_zero [OFE SI α] {x y : α} : DistLater 0 x y := nofun /-- `DistLater n`-equivalence is equivalent to `(n + 1)`-equivalence. -/ @[rocq_alias dist_later_S] -theorem distLater_succ [OFE α] {n} {x y : α} : DistLater n.succ x y ↔ x ≡{n}≡ y := +theorem distLater_succ [OFE SI α] {n : SI} {x y : α} : DistLater (SIdx.succ n) x y ↔ x ≡{n}≡ y := ⟨(·.dist_lt (Nat.lt_succ_self _)), fun h1 _ h2 => h1.le (Nat.le_of_lt_succ h2)⟩ -theorem distLater_soundness [OFE α] {x y : α} (H : ∀ n, DistLater n x y → x ≡{n}≡ y) : x = y := by +theorem distLater_soundness [OFE SI α] {x y : α} (H : ∀ n, DistLater n x y → x ≡{n}≡ y) : x = y := by refine eq_dist.mpr fun n => ?_ induction n with | zero => exact H 0 distLater_zero @@ -130,32 +133,32 @@ theorem distLater_soundness [OFE α] {x y : α} (H : ∀ n, DistLater n x y → /-- A function `f : α → β` is contractive if it sends `DistLater n`-equivalent inputs to `n`-equivalent outputs. -/ -class Contractive [OFE α] [OFE β] (f : α → β) where +class Contractive [OFE SI α] [OFE SI β] (f : α → β) where distLater_dist : DistLater n x y → f x ≡{n}≡ f y -@[simp, rocq_alias contractive_0] theorem Contractive.zero [OFE α] [OFE β] (f : α → β) +@[simp, rocq_alias contractive_0] theorem Contractive.zero [OFE SI α] [OFE SI β] (f : α → β) [Contractive f] {x y} : f x ≡{0}≡ f y := Contractive.distLater_dist distLater_zero @[rocq_alias contractive_S] -theorem Contractive.succ [OFE α] [OFE β] (f : α → β) [Contractive f] {n x y} - (h : x ≡{n}≡ y) : f x ≡{n.succ}≡ f y := +theorem Contractive.succ [OFE SI α] [OFE SI β] (f : α → β) [Contractive f] {n x y} + (h : x ≡{n}≡ y) : f x ≡{SIdx.succ n}≡ f y := Contractive.distLater_dist (distLater_succ.2 h) /-- A contractive function is non-expansive. -/ @[rocq_alias contractive_ne] -instance ne_of_contractive [OFE α] [OFE β] (f : α → β) [Contractive f] : NonExpansive f where +instance ne_of_contractive [OFE SI α] [OFE SI β] (f : α → β) [Contractive f] : NonExpansive f where ne := fun _ _ _ h => Contractive.distLater_dist (Dist.distLater h) #rocq_ignore contractive_proper "OFE is Leibniz; use equality" /-- Constant functions are contractive. -/ @[rocq_alias const_contractive] -instance [OFE α] [OFE β] {x : β} : Contractive (fun _ : α => x) where +instance [OFE SI α] [OFE SI β] {x : β} : Contractive (fun _ : α => x) where distLater_dist := fun _ => Dist.rfl /-- The discrete OFE obtained from an equivalence relation `Equiv` -/ @[reducible, rocq_alias discrete_ofe_mixin] -def ofDiscrete (α : Type _) : OFE α where +def ofDiscrete (α : Type _) : OFE SI α where Dist _ := Eq dist_eqv := ⟨congrFun rfl, (Eq.symm ·), (· ▸ ·)⟩ eq_dist := (forall_const _).symm @@ -163,40 +166,40 @@ def ofDiscrete (α : Type _) : OFE α where /-- A discrete element in an OFE -/ @[rocq_alias Discrete] -class DiscreteE {α : Type _} [OFE α] (x : α) : Prop where +class DiscreteE {α : Type _} [OFE SI α] (x : α) : Prop where discrete : x ≡{0}≡ y → x = y /-- A discrete OFE is one where equivalence is implied by `0`-equivalence. -/ @[rocq_alias OfeDiscrete] -class Discrete (α : Type _) [OFE α] where +class Discrete (α : Type _) [OFE SI α] where discrete_0 {x y : α} : x ≡{0}≡ y → x = y export OFE.Discrete (discrete_0) @[rocq_alias Discrete_proper] -theorem discreteE_eqv [OFE α] {x y : α} (h : x = y) : DiscreteE x ↔ DiscreteE y := h ▸ Iff.rfl +theorem discreteE_eqv [OFE SI α] {x y : α} (h : x = y) : DiscreteE x ↔ DiscreteE y := h ▸ Iff.rfl #rocq_ignore ofe_discrete_subrelation "Not needed" #rocq_ignore discrete_ofe_discrete "Not needed" /-- For discrete OFEs, `n`-equivalence implies equivalence for any `n`. -/ @[rocq_alias discrete] -theorem Discrete.discrete [OFE α] [Discrete α] {n} {x y : α} (h : x ≡{n}≡ y) : x = y := +theorem Discrete.discrete [OFE SI α] [Discrete α] {n : SI} {x y : α} (h : x ≡{n}≡ y) : x = y := discrete_0 (h.le (Nat.zero_le _)) export OFE.Discrete (discrete) -instance Discrete.toDiscreteE [OFE α] [Discrete α] (x : α) : DiscreteE x := ⟨discrete_0⟩ +instance Discrete.toDiscreteE [OFE SI α] [Discrete α] (x : α) : DiscreteE x := ⟨discrete_0⟩ /-- For discrete OFEs, `n`-equivalence implies equivalence for any `n`. -/ -theorem Discrete.discrete_n [OFE α] [Discrete α] {n} {x y : α} (h : x ≡{0}≡ y) : x ≡{n}≡ y := +theorem Discrete.discrete_n [OFE SI α] [Discrete α] {n : SI} {x y : α} (h : x ≡{0}≡ y) : x ≡{n}≡ y := (discrete h).dist export OFE.Discrete (discrete_n) @[rocq_alias discrete_iff] -theorem Discrete.discrete_iff [OFE α] [Discrete α] (n) {x y : α} : x = y ↔ x ≡{n}≡ y := +theorem Discrete.discrete_iff [OFE SI α] [Discrete α] (n) {x y : α} : x = y ↔ x ≡{n}≡ y := ⟨Eq.dist, discrete⟩ @[rocq_alias discrete_iff_0] -theorem Discrete.discrete_iff_0 [OFE α] [Discrete α] (n) {x y : α} : x ≡{0}≡ y ↔ x ≡{n}≡ y := +theorem Discrete.discrete_iff_0 [OFE SI α] [Discrete α] (n) {x y : α} : x ≡{0}≡ y ↔ x ≡{n}≡ y := ⟨discrete_n, fun h => h.le (Nat.zero_le _)⟩ #rocq_ignore boolO "Canonical Leibniz OFE on `bool`; Lean uses `ofDiscrete Bool`." @@ -211,7 +214,7 @@ theorem Discrete.discrete_iff_0 [OFE α] [Discrete α] (n) {x y : α} : x ≡{0} /-- The setoid on `X` identifying points that agree at every step index: `x ≈ y ↔ ∀ n, dist n x y`. -/ @[reducible] -def QuotientO {X : Type u} (dist : Nat → X → X → Prop) (heqv : ∀ {n}, Equivalence (dist n)) : +def QuotientO {X : Type u} (dist : SI → X → X → Prop) (heqv : ∀ {n}, Equivalence (dist n)) : Setoid X where r x y := ∀ n, dist n x y iseqv := @@ -226,11 +229,11 @@ https://leanprover.zulipchat.com/#narrow/channel/490604-iris-lean/topic/Evaluati Build a `Leibniz` OFE from a step-indexed distance `dist` satisfying the OFE distance axioms by quotienting the carrier `X` by the OFE equivalence `fun x y => ∀ n, dist n x y`. -/ -@[reducible] def mkQuotient {X : Type u} (dist : Nat → X → X → Prop) +@[reducible] def mkQuotient {X : Type u} (dist : SI → X → X → Prop) (heqv : ∀ {n}, Equivalence (dist n)) - (hlt : ∀ {n m : Nat} {x y : X}, dist n x y → m < n → dist m x y) : - OFE (Quotient (QuotientO dist heqv)) := - letI D : Nat → Quotient (QuotientO dist heqv) → Quotient (QuotientO dist heqv) → Prop := + (hlt : ∀ {n m : SI} {x y : X}, dist n x y → m < n → dist m x y) : + OFE SI (Quotient (QuotientO dist heqv)) := + letI D : SI → Quotient (QuotientO dist heqv) → Quotient (QuotientO dist heqv) → Prop := fun n => Quotient.lift₂ (dist n) fun _ _ _ _ hac hbd => propext ⟨fun h => heqv.trans (heqv.trans (heqv.symm (hac n)) h) (hbd n), fun h => heqv.trans (heqv.trans (hac n) h) (heqv.symm (hbd n))⟩ @@ -248,7 +251,9 @@ by quotienting the carrier `X` by the OFE equivalence `fun x y => ∀ n, dist n namespace mkQuotient -variable {X : Type u} {dist : Nat → X → X → Prop} {heqv : ∀ {n}, Equivalence (dist n)} +omit instSI in section + +variable {X : Type u} {dist : SI → X → X → Prop} {heqv : ∀ {n}, Equivalence (dist n)} @[reducible] def mk (x : X) : Quotient (QuotientO dist heqv) := Quotient.mk _ x @@ -277,23 +282,26 @@ theorem mk_eq {x y : X} : @[simp] theorem lift₂_mk {β : Sort v} (f : X → X → β) (resp) (x y : X) : lift₂ (dist := dist) (heqv := heqv) f resp (mk x) (mk y) = f x y := rfl -@[reducible] def map {X' : Type u'} {dist' : Nat → X' → X' → Prop} {heqv' : ∀ {n}, Equivalence (dist' n)} +@[reducible] def map {X' : Type u'} {dist' : SI → X' → X' → Prop} {heqv' : ∀ {n}, Equivalence (dist' n)} (f : X → X') (hf : ∀ n x y, dist n x y → dist' n (f x) (f y)) : Quotient (QuotientO dist heqv) → Quotient (QuotientO dist' heqv') := Quotient.lift (fun x => mk (f x)) (fun _ _ h => Quotient.sound fun n => hf n _ _ (h n)) -@[simp] theorem map_mk {X' : Type u'} {dist' : Nat → X' → X' → Prop} +@[simp] theorem map_mk {X' : Type u'} {dist' : SI → X' → X' → Prop} {heqv' : ∀ {n}, Equivalence (dist' n)} (f : X → X') (hf) (x : X) : map (dist := dist) (heqv := heqv) (dist' := dist') (heqv' := heqv') f hf (mk x) = mk (f x) := rfl -theorem dist_mk {hlt : ∀ {n m : Nat} {x y : X}, dist n x y → m < n → dist m x y} - {n} {x y : X} : (mkQuotient dist heqv hlt).Dist n (mk x) (mk y) ↔ dist n x y := Iff.rfl +include instSI in +theorem dist_mk {hlt : ∀ {n m : SI} {x y : X}, dist n x y → m < n → dist m x y} + {n : SI} {x y : X} : (mkQuotient dist heqv hlt).Dist n (mk x) (mk y) ↔ dist n x y := Iff.rfl + +end end mkQuotient /-- A morphism between OFEs, written `α -n> β`, is defined to be a function that is non-expansive. -/ -@[ext, rocq_alias ofe_mor] structure Hom (α β : Type _) [OFE α] [OFE β] where +@[ext, rocq_alias ofe_mor] structure Hom (α β : Type _) [OFE SI α] [OFE SI β] where f : α → β ne : NonExpansive f #rocq_ignore ofe_mor_proper "Derived from nonexpansivity" @@ -302,51 +310,51 @@ non-expansive. -/ @[inherit_doc] infixr:25 " -n> " => Hom -instance [OFE α] [OFE β] : CoeFun (α -n> β) (fun _ => α → β) := ⟨Hom.f⟩ -instance [OFE α] [OFE β] (f : α -n> β) : NonExpansive f := f.ne +instance [OFE SI α] [OFE SI β] : CoeFun (α -n> β) (fun _ => α → β) := ⟨Hom.f⟩ +instance [OFE SI α] [OFE SI β] (f : α -n> β) : NonExpansive f := f.ne /-- The identity morphism on an OFE. -/ @[rocq_alias cid] -protected def Hom.id [OFE α] : α -n> α where +protected def Hom.id [OFE SI α] : α -n> α where f := id ne.ne _ _ _ := id /-- The composition of two morphisms between OFEs. -/ @[rocq_alias ccompose] -protected def Hom.comp [OFE α] [OFE β] [OFE γ] (g : β -n> γ) (f : α -n> β) : α -n> γ where +protected def Hom.comp [OFE SI α] [OFE SI β] [OFE SI γ] (g : β -n> γ) (f : α -n> β) : α -n> γ where f := g.f ∘ f.f ne.1 _ _ _ h := g.ne.1 (f.ne.1 h) #rocq_ignore ccompose_ne "Implicit in type of ccompose" #rocq_ignore ccompose_proper "Derived from nonexpansivity" -@[simp] theorem Hom.id_apply [OFE α] {x} : (Hom.id : α -n> α) x = x := rfl -@[simp] theorem Hom.comp_apply [OFE α] [OFE β] [OFE γ] {g : β -n> γ} {f : α -n> β} {x} : +@[simp] theorem Hom.id_apply [OFE SI α] {x} : (Hom.id : α -n> α) x = x := rfl +@[simp] theorem Hom.comp_apply [OFE SI α] [OFE SI β] [OFE SI γ] {g : β -n> γ} {f : α -n> β} {x} : (g.comp f) x = g (f x) := rfl -@[simp] theorem Hom.id_comp [OFE α] [OFE β] {f : α -n> β} : Hom.id.comp f = f := rfl -@[simp] theorem Hom.comp_id [OFE α] [OFE β] {f : α -n> β} : f.comp Hom.id = f := rfl +@[simp] theorem Hom.id_comp [OFE SI α] [OFE SI β] {f : α -n> β} : Hom.id.comp f = f := rfl +@[simp] theorem Hom.comp_id [OFE SI α] [OFE SI β] {f : α -n> β} : f.comp Hom.id = f := rfl -theorem Hom.comp_assoc [OFE α] [OFE β] [OFE γ] [OFE δ] +theorem Hom.comp_assoc [OFE SI α] [OFE SI β] [OFE SI γ] [OFE SI δ] (h : γ -n> δ) (g : β -n> γ) (f : α -n> β) : (h.comp g).comp f = h.comp (g.comp f) := rfl /-- Construct a `Hom` from a subtype bundling a function with its nonexpansiveness proof. -/ -def Hom.ofSubtype [OFE α] [OFE β] (f : { f : α → β // NonExpansive f }) : α -n> β := +def Hom.ofSubtype [OFE SI α] [OFE SI β] (f : { f : α → β // NonExpansive f }) : α -n> β := ⟨f.val, f.property⟩ -@[ext] structure ContractiveHom (α β : Type _) [OFE α] [OFE β] extends Hom α β where +@[ext] structure ContractiveHom (α β : Type _) [OFE SI α] [OFE SI β] extends Hom α β where [contractive : Contractive f] ne := ne_of_contractive f infixr:25 " -c> " => ContractiveHom -instance [OFE α] [OFE β] : CoeFun (α -c> β) (fun _ => α → β) := ⟨fun x => x.toHom.f⟩ -instance [OFE α] [OFE β] (f : α -c> β) : Contractive f := f.contractive +instance [OFE SI α] [OFE SI β] : CoeFun (α -c> β) (fun _ => α → β) := ⟨fun x => x.toHom.f⟩ +instance [OFE SI α] [OFE SI β] (f : α -c> β) : Contractive f := f.contractive -def _root_.Function.toContractiveHom (f : α → β) [OFE α] [OFE β] [ι : OFE.Contractive f] : α -c> β where +def _root_.Function.toContractiveHom (f : α → β) [OFE SI α] [OFE SI β] [ι : OFE.Contractive f] : α -c> β where f := f contractive := ι -@[simp] theorem _root_.Function.toContractiveHom_apply {f : α → β} [OFE α] [OFE β] [ι : OFE.Contractive f] {x} : +@[simp] theorem _root_.Function.toContractiveHom_apply {f : α → β} [OFE SI α] [OFE SI β] [ι : OFE.Contractive f] {x} : f.toContractiveHom x = f x := by rfl theorem InvImage.equivalence {α : Sort u} {β : Sort v} @@ -355,8 +363,8 @@ theorem InvImage.equivalence {α : Sort u} {β : Sort v} symm := H.symm trans := H.trans -@[rocq_alias unit_ofe_mixin] -instance : OFE Unit where +@[reducible, rocq_alias unit_ofe_mixin] +def unitOFE : OFE SI Unit where Dist _ _ _ := True dist_eqv := ⟨fun _ => ⟨⟩, id, fun _ => id⟩ eq_dist := by simp @@ -364,19 +372,21 @@ instance : OFE Unit where #rocq_ignore unitO "Use the unit type" #rocq_ignore unit_dist "Local Dist instance; folded into Lean's OFE Unit instance." -instance : DiscreteE (() : Unit) := ⟨fun _ => Subsingleton.elim _ _⟩ +-- set_option trace.Meta.synthInstance true in +instance : @DiscreteE SI _ Unit unitOFE (() : Unit) := + ⟨fun _ => Subsingleton.elim _ _⟩ -instance [OFE α] : OFE (ULift α) where +instance [OFE SI α] : OFE SI (ULift α) where Dist n x y := x.down ≡{n}≡ y.down dist_eqv := InvImage.equivalence dist_eqv eq_dist {x y} := by cases x; cases y; rw [ULift.up.injEq]; exact eq_dist dist_lt := dist_lt -def uliftUpHom [OFE α] : α -n> ULift α where +def uliftUpHom [OFE SI α] : α -n> ULift α where f := .up ne.1 _ _ _ := id -def uliftDownHom [OFE α] : ULift α -n> α where +def uliftDownHom [OFE SI α] : ULift α -n> α where f := ULift.down ne.1 _ _ _ := id @@ -392,7 +402,7 @@ theorem _root_.Option.Forall₂.equivalence {R : α → α → Prop} trans {x y z} := by cases x <;> cases y <;> cases z <;> simp [Option.Forall₂]; apply H.3 @[rocq_alias option_ofe_mixin] -instance [OFE α] : OFE (Option α) where +instance [OFE SI α] : OFE SI (Option α) where Dist n := Option.Forall₂ (Dist n) dist_eqv := Option.Forall₂.equivalence dist_eqv eq_dist {x y} := by cases x <;> cases y <;> simp [Option.Forall₂, eq_dist] @@ -402,7 +412,7 @@ instance [OFE α] : OFE (Option α) where #rocq_ignore option_dist_Forall2 "Local Dist unfolding lemma; trivial in Lean." @[rocq_alias option_ofe_discrete] -instance [OFE α] [OFE.Discrete α] : OFE.Discrete (Option α) where +instance [OFE SI α] [OFE.Discrete α] : OFE.Discrete (Option α) where discrete_0 {mx my} e := match mx, my with | none, none => rfl @@ -410,27 +420,27 @@ instance [OFE α] [OFE.Discrete α] : OFE.Discrete (Option α) where | some _, none => e.elim | some _, some _ => congrArg some (discrete_0 e) -@[simp] theorem some_eqv_some [OFE α] {x y : α} : (some x = some y) ↔ x = y := +@[simp] theorem some_eqv_some [OFE SI α] {x y : α} : (some x = some y) ↔ x = y := ⟨Option.some.inj, congrArg some⟩ -@[simp] theorem not_some_eqv_none [OFE α] {x : α} : ¬some x = none := Option.some_ne_none x -@[simp] theorem not_none_eqv_some [OFE α] {x : α} : ¬none = some x := fun h => Option.some_ne_none x h.symm +@[simp] theorem not_some_eqv_none [OFE SI α] {x : α} : ¬some x = none := Option.some_ne_none x +@[simp] theorem not_none_eqv_some [OFE SI α] {x : α} : ¬none = some x := fun h => Option.some_ne_none x h.symm @[simp, rocq_alias dist_Some] -theorem some_dist_some [OFE α] {n} {x y : α} : (some x ≡{n}≡ some y) ↔ x ≡{n}≡ y := .rfl -@[simp] theorem not_some_dist_none [OFE α] {n} {x : α} : ¬some x ≡{n}≡ none := id -@[simp] theorem not_none_dist_some [OFE α] {n} {x : α} : ¬none ≡{n}≡ some x := id +theorem some_dist_some [OFE SI α] {n : SI} {x y : α} : (some x ≡{n}≡ some y) ↔ x ≡{n}≡ y := .rfl +@[simp] theorem not_some_dist_none [OFE SI α] {n : SI} {x : α} : ¬some x ≡{n}≡ none := id +@[simp] theorem not_none_dist_some [OFE SI α] {n : SI} {x : α} : ¬none ≡{n}≡ some x := id -theorem equiv_some [OFE α] {o : Option α} {y : α} (e : o = some y) : +theorem equiv_some [OFE SI α] {o : Option α} {y : α} (e : o = some y) : ∃ z, o = some z ∧ z = y := ⟨y, e, rfl⟩ -theorem equiv_none [OFE α] {o : Option α} : o = none ↔ o = none := Iff.rfl +theorem equiv_none [OFE SI α] {o : Option α} : o = none ↔ o = none := Iff.rfl @[rocq_alias dist_None] -theorem dist_none [OFE α] {o : Option α} : o ≡{n}≡ none ↔ o = none := +theorem dist_none [OFE SI α] {o : Option α} : o ≡{n}≡ none ↔ o = none := ⟨fun h => by cases o with | none => rfl | some _ => exact h.elim, (· ▸ .rfl)⟩ @[rocq_alias dist_Some_inv_r'] -theorem dist_some [OFE α] {n mx y} (h : mx ≡{n}≡ some y) : +theorem dist_some [OFE SI α] {n mx y} (h : mx ≡{n}≡ some y) : ∃ z : α, mx = some z ∧ y ≡{n}≡ z := suffices hh : ∀ mx my y, mx ≡{n}≡ my → my = some y → ∃ t, mx = some t ∧ t ≡{n}≡ y from (hh mx (some y) _ h rfl).elim (fun t h => ⟨t, h.left, h.right.symm⟩) @@ -439,7 +449,7 @@ theorem dist_some [OFE α] {n mx y} (h : mx ≡{n}≡ some y) : | some t => ⟨t, rfl, (e2 ▸ e1 : some t ≡{n}≡ some y)⟩ | none => False.elim (e2 ▸ e1 : none ≡{n}≡ some y) -instance [OFE α] [Discrete α] : Discrete (Option α) where +instance [OFE SI α] [Discrete α] : Discrete (Option α) where discrete_0 {x y} H := match x, y with | none, none => rfl @@ -448,51 +458,51 @@ instance [OFE α] [Discrete α] : Discrete (Option α) where | some _, none => H.elim @[rocq_alias Some_ne] -instance OFE.Option.some.ne [OFE α] : OFE.NonExpansive (some : α → Option α) := ⟨fun _ _ _ => id⟩ +instance OFE.Option.some.ne [OFE SI α] : OFE.NonExpansive (some : α → Option α) := ⟨fun _ _ _ => id⟩ @[rocq_alias Some_discrete] -instance Option.some_is_discrete [OFE α] {e : α} [OFE.DiscreteE e] : OFE.DiscreteE (some e) where +instance Option.some_is_discrete [OFE SI α] {e : α} [OFE.DiscreteE e] : OFE.DiscreteE (some e) where discrete {y} h := match y with | .none => absurd h not_some_dist_none | .some _ => congrArg some (DiscreteE.discrete h) /-- Note: Not an instance, due to instance coherence problems. -/ -theorem Option.ne_match [OFE α] {B : Type _} [OFE B] +theorem Option.ne_match [OFE SI α] {B : Type _} [OFE SI B] (f : α → B) (hf : NonExpansive f) (g : B) : NonExpansive (fun x : Option α => match x with | some a => f a | none => g) := ⟨fun {n x' y'} (h : Option.Forall₂ (Dist n) x' y') => match x', y', h with | some _, some _, h => hf.ne h | none, none, _ => Dist.rfl⟩ @[rocq_alias None_discrete] -instance Option.none_is_discrete [OFE α] : DiscreteE (none : Option α) := by +instance Option.none_is_discrete [OFE SI α] : DiscreteE (none : Option α) := by constructor; rintro (_|_) <;> simp -instance Option.merge_ne [OFE α] {op : α → α → α} [NonExpansive₂ op] : +instance Option.merge_ne [OFE SI α] {op : α → α → α} [NonExpansive₂ op] : NonExpansive₂ (Option.merge op) where ne n x1 x2 Hx y1 y2 Hy := by rcases x1, x2, y1, y2 with ⟨_|_, _|_, _|_, _|_⟩ <;> simp_all exact NonExpansive₂.ne Hx Hy -instance Option.bind_fun_ne [OFE α] [OFE β] (f : α → Option β) [NonExpansive f] : NonExpansive (flip Option.bind f) where +instance Option.bind_fun_ne [OFE SI α] [OFE SI β] (f : α → Option β) [NonExpansive f] : NonExpansive (flip Option.bind f) where ne _ _ x2 Hx := match x2 with | some _ => (dist_some Hx).choose_spec.left ▸ (NonExpansive.ne (f := f) (dist_some Hx).choose_spec.right.symm) | none => (dist_none.mp Hx).symm ▸ .rfl -theorem Option.bind_dist [OFE α] [OFE β] {x : Option α} {f g : α → Option β} (H : ∀ x, f x ≡{n}≡ g x) : Option.bind x f ≡{n}≡ Option.bind x g := +theorem Option.bind_dist [OFE SI α] [OFE SI β] {x : Option α} {f g : α → Option β} (H : ∀ x, f x ≡{n}≡ g x) : Option.bind x f ≡{n}≡ Option.bind x g := match x with | some _ => H _ | none => .rfl -theorem Option.bind_equiv [OFE α] [OFE β] {x : Option α} {f g : α → Option β} (H : ∀ x, f x = g x) : Option.bind x f = Option.bind x g := +theorem Option.bind_equiv [OFE SI α] [OFE SI β] {x : Option α} {f g : α → Option β} (H : ∀ x, f x = g x) : Option.bind x f = Option.bind x g := match x with | some _ => H _ | none => rfl -abbrev OFEFun {α : Type _} (β : α → Type _) := ∀ a, OFE (β a) +abbrev OFEFun {α : Type _} (β : α → Type _) := ∀ a, OFE SI (β a) @[rocq_alias discrete_fun_ofe_mixin] -instance [OFEFun (β : α → _)] : OFE ((x : α) → β x) where +instance [OFEFun (SI := SI) (β : α → _)] : OFE SI ((x : α) → β x) where Dist n f g := ∀ x, f x ≡{n}≡ g x dist_eqv := { refl _ _ := dist_eqv.refl _ @@ -507,7 +517,7 @@ instance [OFEFun (β : α → _)] : OFE ((x : α) → β x) where #rocq_ignore discrete_fun_dist "Local Dist instance; folded into Lean's instance." @[rocq_alias ofe_mor_ofe_mixin] -instance [OFE α] [OFE β] : OFE (α -n> β) where +instance [OFE SI α] [OFE SI β] : OFE SI (α -n> β) where Dist n f g := f.f ≡{n}≡ g.f dist_eqv := { refl _ := dist_eqv.refl _ @@ -522,20 +532,20 @@ instance [OFE α] [OFE β] : OFE (α -n> β) where #rocq_ignore ofe_mor_chain "Inlined in IsCOFE instance" @[rocq_alias ofe_mor_car_ne] -instance ofe_mor_car_ne [OFE α] [OFE β] : +instance ofe_mor_car_ne [OFE SI α] [OFE SI β] : NonExpansive₂ (fun (f : α -n> β) (x : α) => f x) where ne _ _ _ hf _ _ hx := dist_eqv.trans (hf _) (NonExpansive.ne hx) @[rocq_alias ofe_mor_car_proper] -theorem ofe_mor_car_proper [OFE α] [OFE β] ⦃f g : α -n> β⦄ (hfg : f = g) +theorem ofe_mor_car_proper [OFE SI α] [OFE SI β] ⦃f g : α -n> β⦄ (hfg : f = g) ⦃x y : α⦄ (hxy : x = y) : f x = g y := by subst hfg; subst hxy; rfl @[rocq_alias ofe_mor_inhabited] -instance [OFE α] [OFE β] [Inhabited β] : Inhabited (α -n> β) where +instance [OFE SI α] [OFE SI β] [Inhabited β] : Inhabited (α -n> β) where default := { f := Function.const α default, ne := const_ne } -instance [OFE α] [OFE β] : OFE (α -c> β) where +instance [OFE SI α] [OFE SI β] : OFE SI (α -c> β) where Dist n f g := Dist n f.toHom g.toHom dist_eqv := { refl _ := dist_eqv.refl _ @@ -545,19 +555,19 @@ instance [OFE α] [OFE β] : OFE (α -c> β) where eq_dist {_ _} := ContractiveHom.ext_iff.trans eq_dist dist_lt := dist_lt -def applyHom [OFEFun (β : α → _)] (x : α) : ((x : α) → β x) -n> β x where +def applyHom [OFEFun (SI := SI) (β : α → _)] (x : α) : ((x : α) → β x) -n> β x where f f := f x ne.1 _ _ _ H := H x -def applyNe [OFE α] [OFE β] (x : α) : (α -n> β) -n> β where +def applyNe [OFE SI α] [OFE SI β] (x : α) : (α -n> β) -n> β where f f := f x ne.1 _ _ _ H := H x -instance [OFE α] [OFE β] : NonExpansive (applyNe (α := α) (β := β)) where +instance [OFE SI α] [OFE SI β] : NonExpansive (applyNe (α := α) (β := β)) where ne _ _ _ H f := f.ne.1 H @[rocq_alias discrete_funO_map] -def mapCodHom [OFEFun (β₁ : α → _)] [OFEFun β₂] +def mapCodHom [OFEFun (β₁ : α → _)] [OFEFun (SI := SI) β₂] (F : ∀ x, β₁ x -n> β₂ x) : ((x : α) → β₁ x) -n> ((x : α) → β₂ x) where f f x := F x (f x) ne.1 _ _ _ H x := (F x).ne.1 (H x) @@ -568,7 +578,7 @@ def mapCodHom [OFEFun (β₁ : α → _)] [OFEFun β₂] #rocq_ignore discrete_funO_map_ne "Implicit in type of mapCodHom" @[rocq_alias prod_ofe_mixin] -instance [OFE α] [OFE β] : OFE (α × β) where +instance [OFE SI α] [OFE SI β] : OFE SI (α × β) where Dist n a b := a.1 ≡{n}≡ b.1 ∧ a.2 ≡{n}≡ b.2 dist_eqv := { refl _ := ⟨dist_eqv.refl _, dist_eqv.refl _⟩ @@ -580,51 +590,51 @@ instance [OFE α] [OFE β] : OFE (α × β) where #rocq_ignore prodO "Use product type" #rocq_ignore prod_dist "Implicit in Prod OFE" -theorem equiv_fst [OFE α] [OFE β] {x y : α × β} (h : x = y) : x.fst = y.fst := congrArg Prod.fst h -theorem equiv_snd [OFE α] [OFE β] {x y : α × β} (h : x = y) : x.snd = y.snd := congrArg Prod.snd h -theorem equiv_prod_ext [OFE α] [OFE β] {x₁ x₂ : α} {y₁ y₂ : β} +theorem equiv_fst [OFE SI α] [OFE SI β] {x y : α × β} (h : x = y) : x.fst = y.fst := congrArg Prod.fst h +theorem equiv_snd [OFE SI α] [OFE SI β] {x y : α × β} (h : x = y) : x.snd = y.snd := congrArg Prod.snd h +theorem equiv_prod_ext [OFE SI α] [OFE SI β] {x₁ x₂ : α} {y₁ y₂ : β} (ex : x₁ = x₂) (ey : y₁ = y₂) : (x₁, y₁) = (x₂, y₂) := by subst ex; subst ey; rfl -theorem dist_fst {n} [OFE α] [OFE β] {x y : α × β} (h : x ≡{n}≡ y) : x.fst ≡{n}≡ y.fst := h.left -theorem dist_snd {n} [OFE α] [OFE β] {x y : α × β} (h : x ≡{n}≡ y) : x.snd ≡{n}≡ y.snd := h.right +theorem dist_fst {n : SI} [OFE SI α] [OFE SI β] {x y : α × β} (h : x ≡{n}≡ y) : x.fst ≡{n}≡ y.fst := h.left +theorem dist_snd {n : SI} [OFE SI α] [OFE SI β] {x y : α × β} (h : x ≡{n}≡ y) : x.snd ≡{n}≡ y.snd := h.right @[rocq_alias pair_dist] -theorem dist_prod_ext {n} [OFE α] [OFE β] {x₁ x₂ : α} {y₁ y₂ : β} +theorem dist_prod_ext {n : SI} [OFE SI α] [OFE SI β] {x₁ x₂ : α} {y₁ y₂ : β} (ex : x₁ ≡{n}≡ x₂) (ey : y₁ ≡{n}≡ y₂) : (x₁, y₁) ≡{n}≡ (x₂, y₂) := ⟨ex, ey⟩ @[rocq_alias pair_ne] -instance Prod.mk_ne [OFE α] [OFE β] : NonExpansive₂ (Prod.mk (α := α) (β := β)) where +instance Prod.mk_ne [OFE SI α] [OFE SI β] : NonExpansive₂ (Prod.mk (α := α) (β := β)) where ne _ _ _ hx _ _ hy := dist_prod_ext hx hy /-- Note: Not an instance, due to instance coherence problems. -/ -theorem prod_mk_ne_left [OFE α] [OFE β] (b : β) : NonExpansive (β := α × β) (·, b) := +theorem prod_mk_ne_left [OFE SI α] [OFE SI β] (b : β) : NonExpansive (β := α × β) (·, b) := ⟨fun {_ _ _} h => dist_prod_ext h Dist.rfl⟩ /-- Note: Not an instance, due to instance coherence problems. -/ -theorem prod_mk_ne_right [OFE α] [OFE β] (a : α) : NonExpansive (β := α × β) (a, ·) := +theorem prod_mk_ne_right [OFE SI α] [OFE SI β] (a : α) : NonExpansive (β := α × β) (a, ·) := ⟨fun {_ _ _} h => dist_prod_ext Dist.rfl h⟩ @[rocq_alias fst_ne] -instance [OFE α] [OFE β] : NonExpansive (Prod.fst (α := α) (β := β)) := +instance [OFE SI α] [OFE SI β] : NonExpansive (Prod.fst (α := α) (β := β)) := ⟨fun {_ _ _} h => dist_fst h⟩ @[rocq_alias snd_ne] -instance [OFE α] [OFE β] : NonExpansive (Prod.snd (α := α) (β := β)) := +instance [OFE SI α] [OFE SI β] : NonExpansive (Prod.snd (α := α) (β := β)) := ⟨fun {_ _ _} h => dist_snd h⟩ /-- Note: Not an instance, due to instance coherence problems. -/ -theorem NonExpansive₂.uncurry [OFE α] [OFE β] [OFE γ] {f : α → β → γ} (hf : NonExpansive₂ f) : +theorem NonExpansive₂.uncurry [OFE SI α] [OFE SI β] [OFE SI γ] {f : α → β → γ} (hf : NonExpansive₂ f) : NonExpansive (Function.uncurry f) := ⟨fun {_ _ _} (h : _ ∧ _) => hf.ne h.1 h.2⟩ @[rocq_alias prod_discrete] -instance prod.is_discrete [OFE α] [OFE β] {a : α} {b : β} [DiscreteE a] [DiscreteE b] : +instance prod.is_discrete [OFE SI α] [OFE SI β] {a : α} {b : β} [DiscreteE a] [DiscreteE b] : DiscreteE (a, b) := by constructor intro y H; exact Prod.ext (DiscreteE.discrete H.1) (DiscreteE.discrete H.2) @[rocq_alias prod_ofe_discrete] -instance instDiscreteProd [OFE α] [OFE β] [Discrete α] [Discrete β] : Discrete (α × β) where +instance instDiscreteProd [OFE SI α] [OFE SI β] [Discrete α] [Discrete β] : Discrete (α × β) where discrete_0 H := Prod.ext (discrete_0 H.1) (discrete_0 H.2) section sum @@ -634,10 +644,10 @@ theorem equiv_inr {x y : β} (h : x = y) : (.inr x : α ⊕ β) = .inr y := cong theorem equiv_ext_left {x y : α} (h : (.inl x : α ⊕ β) = .inl y) : x = y := Sum.inl.inj h theorem equiv_ext_right {x y : β} (h : (.inr x : α ⊕ β) = .inr y) : x = y := Sum.inr.inj h -variable [OFE α] [OFE β] +variable [OFE SI α] [OFE SI β] @[rocq_alias sum_ofe_mixin] -instance : OFE (α ⊕ β) where +instance : OFE SI (α ⊕ β) where Dist n | .inl a, .inl b => a ≡{n}≡ b | .inr a, .inr b => a ≡{n}≡ b @@ -685,7 +695,7 @@ instance instNonExpansiveInl: NonExpansive (Sum.inl (α := α) (β := β)) where instance instNonExpansiveInr : NonExpansive (Sum.inr (α := α) (β := β)) where ne {_ _ _} H := dist_inr H -instance instNonExpansiveElim [OFE γ] {f₁ : α → γ} {f₂ : β → γ} [NonExpansive f₁] [NonExpansive f₂] : +instance instNonExpansiveElim [OFE SI γ] {f₁ : α → γ} {f₂ : β → γ} [NonExpansive f₁] [NonExpansive f₂] : NonExpansive (Sum.elim f₁ f₂) where ne {_ x y} := match x, y with | .inl _, .inl _ => (NonExpansive.ne (f := f₁) <| dist_ext_left ·) @@ -718,7 +728,7 @@ instance instDiscreteSum [Discrete α] [Discrete β] : Discrete (α ⊕ β) wher end sum @[rocq_alias sig_ofe_mixin] -instance [OFE α] (P : α → Prop) : OFE (Subtype P) where +instance [OFE SI α] (P : α → Prop) : OFE SI (Subtype P) where Dist n x y := x.val ≡{n}≡ y.val dist_eqv := ⟨fun _ => .rfl, Dist.symm, Dist.trans⟩ eq_dist {_ _} := Subtype.ext_iff.trans eq_dist @@ -730,25 +740,25 @@ instance [OFE α] (P : α → Prop) : OFE (Subtype P) where #rocq_ignore sig_dist_def "Trivial unfolding lemma; definitional in Lean." @[rocq_alias sig_discrete] -instance [OFE α] [Discrete α] (P : α → Prop) : Discrete (Subtype P) where +instance [OFE SI α] [Discrete α] (P : α → Prop) : Discrete (Subtype P) where discrete_0 h := Subtype.ext (@Discrete.discrete_0 α _ _ _ _ h) @[rocq_alias proj1_sig_ne] -instance [OFE α] (P : α → Prop) : NonExpansive (Subtype.val : Subtype P → α) where +instance [OFE SI α] (P : α → Prop) : NonExpansive (Subtype.val : Subtype P → α) where ne {_ _ _} := id -instance Hom.ofSubtype_ne [OFE α] [OFE β] : NonExpansive (Hom.ofSubtype (α := α) (β := β)) := +instance Hom.ofSubtype_ne [OFE SI α] [OFE SI β] : NonExpansive (Hom.ofSubtype (α := α) (β := β)) := ⟨fun {_ _ _} h => h⟩ /-- Extract the underlying subtype from a `Hom`. -/ -def Hom.toSubtype [OFE α] [OFE β] (f : α -n> β) : { f : α → β // NonExpansive f } := +def Hom.toSubtype [OFE SI α] [OFE SI β] (f : α -n> β) : { f : α → β // NonExpansive f } := ⟨f.f, f.ne⟩ -instance Hom.toSubtype_ne [OFE α] [OFE β] : NonExpansive (Hom.toSubtype (α := α) (β := β)) := +instance Hom.toSubtype_ne [OFE SI α] [OFE SI β] : NonExpansive (Hom.toSubtype (α := α) (β := β)) := ⟨fun {_ _ _} h => h⟩ @[rocq_alias sigT_ofe_mixin] -instance instOFESigma (P : α → Type _) [∀ x, OFE (P x)] : OFE (Sigma P) where +instance instOFESigma (P : α → Type _) [∀ x, OFE SI (P x)] : OFE SI (Sigma P) where Dist n x y := ∃ heq : x.fst = y.fst, heq ▸ x.snd ≡{n}≡ y.snd dist_eqv := { refl _ := ⟨rfl, .rfl⟩ @@ -774,7 +784,7 @@ instance instOFESigma (P : α → Type _) [∀ x, OFE (P x)] : OFE (Sigma P) whe #rocq_ignore sigT_equiv "Local Equiv instance; folded into Lean's OFE (Sigma P) instance." @[rocq_alias sigT_discrete] -instance instDiscreteESigma {P : α → Type _} [∀ x, OFE (P x)] {x : Sigma P} [inst : DiscreteE x.snd] : +instance instDiscreteESigma {P : α → Type _} [∀ x, OFE SI (P x)] {x : Sigma P} [inst : DiscreteE x.snd] : DiscreteE x where discrete {y} := by rcases x, y with ⟨⟨x, xH⟩, ⟨y, yH⟩⟩; rintro ⟨heq, H⟩ @@ -782,51 +792,51 @@ instance instDiscreteESigma {P : α → Type _} [∀ x, OFE (P x)] {x : Sigma P} exact congrArg _ (inst.discrete H) @[rocq_alias sigT_ofe_discrete] -instance instDiscreteSigma {P : α → Type _} [∀ x, OFE (P x)] [∀ x, Discrete (P x)] : +instance instDiscreteSigma {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, Discrete (P x)] : Discrete (Sigma P) where discrete_0 {x y} H := match x, y, H with | ⟨x, xH⟩, ⟨y, yH⟩, ⟨heq, H⟩ => by simp only at heq; subst heq; exact congrArg _ (discrete_0 H) @[rocq_alias sigT_equiv_eq_alt] -theorem Sigma.equiv_eq_alt {P : α → Type _} [∀ x, OFE (P x)] {x1 x2 : Sigma P} : +theorem Sigma.equiv_eq_alt {P : α → Type _} [∀ x, OFE SI (P x)] {x1 x2 : Sigma P} : x1 = x2 ↔ ∃ heq : x1.fst = x2.fst, heq ▸ x1.snd = x2.snd := by refine ⟨fun h => h ▸ ⟨rfl, rfl⟩, fun ⟨heq, h⟩ => ?_⟩ obtain ⟨x1f, x1s⟩ := x1; obtain ⟨x2f, x2s⟩ := x2 simp only at heq; subst heq; simp only at h; subst h; rfl @[rocq_alias projT1_ne] -instance Sigma.fst_ne {P : α → Type _} [OFE α] [∀ x, OFE (P x)] : +instance Sigma.fst_ne {P : α → Type _} [OFE SI α] [∀ x, OFE SI (P x)] : NonExpansive (Sigma.fst : Sigma P → α) where ne {_ _ _} h := Dist.of_eq h.1 #rocq_ignore projT1_proper "Derived from nonexpansivity." @[rocq_alias projT2_ne] -theorem Sigma.dist_snd {P : α → Type _} [∀ x, OFE (P x)] {n} {x y : Sigma P} +theorem Sigma.dist_snd {P : α → Type _} [∀ x, OFE SI (P x)] {n : SI} {x y : Sigma P} (h : x ≡{n}≡ y) : h.1 ▸ x.snd ≡{n}≡ y.snd := h.2 @[rocq_alias projT2_proper] -theorem Sigma.equiv_snd {P : α → Type _} [∀ x, OFE (P x)] {x y : Sigma P} +theorem Sigma.equiv_snd {P : α → Type _} [∀ x, OFE SI (P x)] {x y : Sigma P} (h : x = y) : congrArg Sigma.fst h ▸ x.snd = y.snd := by subst h; rfl @[rocq_alias existT_ne] -theorem Sigma.mk_dist {P : α → Type _} [∀ x, OFE (P x)] {n} {i1 i2 : α} {v1 : P i1} {v2 : P i2} +theorem Sigma.mk_dist {P : α → Type _} [∀ x, OFE SI (P x)] {n : SI} {i1 i2 : α} {v1 : P i1} {v2 : P i2} (heq : i1 = i2) (h : heq ▸ v1 ≡{n}≡ v2) : Sigma.mk i1 v1 ≡{n}≡ Sigma.mk i2 v2 := ⟨heq, h⟩ @[rocq_alias existT_proper] -theorem Sigma.mk_equiv {P : α → Type _} [∀ x, OFE (P x)] {i1 i2 : α} {v1 : P i1} {v2 : P i2} +theorem Sigma.mk_equiv {P : α → Type _} [∀ x, OFE SI (P x)] {i1 i2 : α} {v1 : P i1} {v2 : P i2} (heq : i1 = i2) (h : heq ▸ v1 = v2) : Sigma.mk i1 v1 = Sigma.mk i2 v2 := by subst heq; subst h; rfl @[rocq_alias existT_ne_2] -instance Sigma.mk_ne {P : α → Type _} [∀ x, OFE (P x)] (a : α) : +instance Sigma.mk_ne {P : α → Type _} [∀ x, OFE SI (P x)] (a : α) : NonExpansive (Sigma.mk a : P a → Sigma P) where ne {_ _ _} h := ⟨rfl, h⟩ /-- An isomorphism between two OFEs is a pair of morphisms whose composition is equivalent to the identity morphism. -/ -@[ext, rocq_alias ofe_iso] structure Iso (α β : Type _) [OFE α] [OFE β] where +@[ext, rocq_alias ofe_iso] structure Iso (α β : Type _) [OFE SI α] [OFE SI β] where hom : α -n> β inv : β -n> α hom_inv : hom (inv x) = x @@ -837,55 +847,55 @@ identity morphism. -/ attribute [simp] Iso.hom_inv Iso.inv_hom -instance [OFE α] [OFE β] : CoeFun (Iso α β) (fun _ => α -n> β) := ⟨Iso.hom⟩ -instance [OFE α] [OFE β] (iso : Iso α β) : NonExpansive iso.hom := iso.hom.ne -instance [OFE α] [OFE β] (iso : Iso α β) : NonExpansive iso.inv := iso.inv.ne +instance [OFE SI α] [OFE SI β] : CoeFun (Iso α β) (fun _ => α -n> β) := ⟨Iso.hom⟩ +instance [OFE SI α] [OFE SI β] (iso : Iso α β) : NonExpansive iso.hom := iso.hom.ne +instance [OFE SI α] [OFE SI β] (iso : Iso α β) : NonExpansive iso.inv := iso.inv.ne -@[simp] theorem Iso.hom_inv_dist [OFE α] [OFE β] (iso : Iso α β) {n} {x} : +@[simp] theorem Iso.hom_inv_dist [OFE SI α] [OFE SI β] (iso : Iso α β) {n : SI} {x} : iso.hom (iso.inv x) ≡{n}≡ x := (Iso.hom_inv iso).dist -@[simp] theorem Iso.inv_hom_dist [OFE α] [OFE β] (iso : Iso α β) {n} {x} : +@[simp] theorem Iso.inv_hom_dist [OFE SI α] [OFE SI β] (iso : Iso α β) {n : SI} {x} : iso.inv (iso.hom x) ≡{n}≡ x := (Iso.inv_hom iso).dist /-- OFE isomorphisms preserve equivalence. -/ -theorem Iso.hom_eqv [OFE α] [OFE β] (iso : Iso α β) ⦃x y⦄ : +theorem Iso.hom_eqv [OFE SI α] [OFE SI β] (iso : Iso α β) ⦃x y⦄ : x = y ↔ iso.hom x = iso.hom y := ⟨fun h => h ▸ rfl, fun h => iso.inv_hom.symm.trans ((congrArg iso.inv h).trans iso.inv_hom)⟩ /-- The inverse of an OFE isomorphism preserves equivalence. -/ -theorem Iso.inv_eqv [OFE α] [OFE β] (iso : Iso α β) ⦃x y⦄ : +theorem Iso.inv_eqv [OFE SI α] [OFE SI β] (iso : Iso α β) ⦃x y⦄ : x = y ↔ iso.inv x = iso.inv y := ⟨fun h => h ▸ rfl, fun h => iso.hom_inv.symm.trans ((congrArg iso.hom h).trans iso.hom_inv)⟩ /-- OFE isomorphisms preserve `n`-equivalence. -/ -theorem Iso.hom_dist [OFE α] [OFE β] (iso : Iso α β) {n} ⦃x y⦄ : +theorem Iso.hom_dist [OFE SI α] [OFE SI β] (iso : Iso α β) {n : SI} ⦃x y⦄ : x ≡{n}≡ y ↔ iso.hom x ≡{n}≡ iso.hom y := ⟨fun h => NonExpansive.ne h, fun h => Dist.trans (Dist.symm iso.inv_hom_dist) <| Dist.trans (NonExpansive.ne h) (iso.inv_hom_dist)⟩ /-- The inverse of an OFE isomorphism preserves `n`-equivalence. -/ -theorem Iso.inv_dist [OFE α] [OFE β] (iso : Iso α β) {n} ⦃x y⦄ : +theorem Iso.inv_dist [OFE SI α] [OFE SI β] (iso : Iso α β) {n : SI} ⦃x y⦄ : x ≡{n}≡ y ↔ iso.inv x ≡{n}≡ iso.inv y := ⟨fun h => NonExpansive.ne h, fun h => Dist.trans (Dist.symm iso.hom_inv_dist) <| Dist.trans (NonExpansive.ne h) (iso.hom_inv_dist)⟩ /-- The identity OFE isomorphism -/ @[rocq_alias iso_ofe_refl] -def Iso.id [OFE α] : Iso α α where +def Iso.id [OFE SI α] : Iso α α where hom := Hom.id inv := Hom.id hom_inv := by intro x; simp inv_hom := by intro x; simp -@[simp] theorem Iso.id_apply [OFE α] {x} : ((Iso.id : Iso α α) : α -n> α) x = x := rfl +@[simp] theorem Iso.id_apply [OFE SI α] {x} : ((Iso.id : Iso α α) : α -n> α) x = x := rfl /-- The inverse of an OFE isomorphism -/ @[rocq_alias iso_ofe_sym] -def Iso.symm [OFE α] [OFE β] (iso : Iso α β) : Iso β α where +def Iso.symm [OFE SI α] [OFE SI β] (iso : Iso α β) : Iso β α where hom := iso.inv inv := iso.hom hom_inv := by intro x; simp @@ -895,7 +905,7 @@ def Iso.symm [OFE α] [OFE β] (iso : Iso α β) : Iso β α where /-- Composition of OFE isomorphisms -/ @[rocq_alias iso_ofe_trans] -def Iso.comp [OFE α] [OFE β] [OFE γ] (iso1 : Iso β γ) (iso2 : Iso α β) : Iso α γ where +def Iso.comp [OFE SI α] [OFE SI β] [OFE SI γ] (iso1 : Iso β γ) (iso2 : Iso α β) : Iso α γ where hom := iso1.hom.comp iso2.hom inv := iso2.inv.comp iso1.inv hom_inv := by intro x; simp @@ -905,42 +915,44 @@ end OFE /-- A chain in an OFE is a `Nat`-indexed sequence of elements that is upward-closed in terms of `n`-equivalence. -/ -@[rocq_alias chain] structure Chain (α : Type _) [OFE α] where - chain : Nat → α +@[rocq_alias chain] structure Chain (α : Type _) [SIdx SI] [OFE SI α] where + chain : SI → α cauchy : n ≤ i → chain i ≡{n}≡ chain n -instance [OFE α] : CoeFun (Chain α) (fun _ => Nat → α) := ⟨Chain.chain⟩ +instance [SIdx SI] [OFE SI α] : CoeFun (Chain α) (fun _ => SI → α) := ⟨Chain.chain⟩ namespace Chain +variable {SI : Type _} [SIdx SI] + /-- The constant chain. -/ @[rocq_alias chain_const] -def const [OFE α] (a : α) : Chain α where +def const [OFE SI α] (a : α) : Chain α where chain := fun _ => a cauchy _ := OFE.Dist.rfl -@[simp] theorem const_apply [OFE α] {a : α} {n} : const a n = a := rfl +@[simp] theorem const_apply [OFE SI α] {a : α} {n : SI} : const a n = a := rfl /-- Mapping a chain through a non-expansive function. -/ @[rocq_alias chain_map] -def map [OFE α] [OFE β] (f : α -n> β) (c : Chain α) : Chain β where +def map [OFE SI α] [OFE SI β] (f : α -n> β) (c : Chain α) : Chain β where chain n := f (c n) cauchy h := f.ne.1 (c.cauchy h) -@[simp] theorem map_apply [OFE α] [OFE β] {f : α -n> β} {c : Chain α} {n} : +@[simp] theorem map_apply [OFE SI α] [OFE SI β] {f : α -n> β} {c : Chain α} {n : SI} : map f c n = f (c n) := rfl -@[simp] theorem map_id [OFE α] {c : Chain α} : map (Hom.id : α -n> α) c = c := by +@[simp] theorem map_id [OFE SI α] {c : Chain α} : map (Hom.id : α -n> α) c = c := by simp [map] -theorem map_comp [OFE α] [OFE β] [OFE γ] {f : α -n> β} {g : β -n> γ} {c : Chain α} : +theorem map_comp [OFE SI α] [OFE SI β] [OFE SI γ] {f : α -n> β} {g : β -n> γ} {c : Chain α} : map (g.comp f) c = map g (map f c) := by simp [map] end Chain /-- If a chain of Option is ever none, is the constant none chain. -/ -theorem chain_none_const [OFE V] {c : Chain (Option V)} (H : c n = none) : +theorem chain_none_const [SIdx SI] [OFE SI V] {c : Chain (Option V)} (H : c n = none) : c = Chain.const none := by rcases c with ⟨c, Hc⟩ congr 1; refine funext (fun k => ?_) @@ -951,7 +963,7 @@ theorem chain_none_const [OFE V] {c : Chain (Option V)} (H : c n = none) : exact (Hc Hnk).symm /-- If a chain of Option is ever some, it is the lift a chain by some. -/ -theorem chain_option_some [OFE V] {c : Chain (Option V)} (H : c n = some v) : +theorem chain_option_some [SIdx SI] [OFE SI V] {c : Chain (Option V)} (H : c n = some v) : ∃ c' : Chain V, c = Chain.map ⟨some, OFE.Option.some.ne⟩ c' := by have HVc (k) : ∃ v', c k = some v' := by rcases h : c.chain k with (_|v') @@ -975,59 +987,61 @@ theorem chain_option_some [OFE V] {c : Chain (Option V)} (H : c n = some v) : /-- Complete ordered family of equivalences -/ @[rocq_alias Cofe] -class IsCOFE (α : Type _) [OFE α] where +class IsCOFE (SI : outParam <| Type _) (α : Type _) [SIdx SI] [OFE SI α] where compl : Chain α → α conv_compl {c : Chain α} : compl c ≡{n}≡ c n /-- Complete ordered family of equivalences -/ -class abbrev COFE (α : Type _) := OFE α, IsCOFE α +class abbrev COFE (SI : outParam <| Type _) [SIdx SI] (α : Type _) := OFE SI α, IsCOFE SI α namespace COFE export IsCOFE (compl conv_compl) +variable {SI : Type _} [SIdx SI] + @[rocq_alias conv_compl_le] -theorem conv_compl' [COFE α] {c : Chain α} {n i} (h : n ≤ i) : compl c ≡{n}≡ c i := +theorem conv_compl' [COFE SI α] {c : Chain α} {n i} (h : n ≤ i) : compl c ≡{n}≡ c i := conv_compl.trans (c.cauchy h).symm /-- Chain maps commute with completion. -/ @[rocq_alias compl_chain_map] -theorem compl_map [COFE α] [COFE β] (f : α -n> β) (c : Chain α) : +theorem compl_map [COFE SI α] [COFE SI β] (f : α -n> β) (c : Chain α) : compl (Chain.map f c) = f (compl c) := by refine OFE.eq_dist.mpr (fun n => ?_) exact Dist.trans conv_compl (NonExpansive.ne (Dist.symm conv_compl)) /-- Constant chains complete to their constant value -/ @[simp, rocq_alias compl_chain_const] -theorem compl_const [COFE α] (a : α) : compl (Chain.const a) = a := +theorem compl_const [COFE SI α] (a : α) : compl (Chain.const a) = a := OFE.eq_dist.mpr (fun _ => conv_compl) /-- Completion of discrete COFEs is the constant value. -/ -@[simp] theorem discrete_cofe_compl [COFE α] [OFE.Discrete α] (c : Chain α) : compl c = c 0 := +@[simp] theorem discrete_cofe_compl [COFE SI α] [OFE.Discrete α] (c : Chain α) : compl c = c 0 := Discrete.discrete_0 conv_compl /-- The discrete COFE obtained from an equivalence relation `Equiv` -/ @[reducible, rocq_alias discrete_cofe] -def ofDiscrete (α : Type _) : COFE α := +def ofDiscrete (α : Type _) : COFE SI α := let _ := OFE.ofDiscrete α { compl := fun c => c 0 conv_compl := fun {n c} => (c.cauchy (Nat.zero_le n)).symm } -instance [COFE α] : COFE (ULift α) where +instance [COFE SI α] : COFE SI (ULift α) where compl c := ⟨compl (c.map uliftDownHom)⟩ conv_compl := conv_compl @[rocq_alias unit_ofe_discrete] -instance : Discrete Unit where +instance : @Discrete SI _ Unit unitOFE where discrete_0 _ := Subsingleton.elim _ _ -@[rocq_alias unit_cofe] -instance : COFE Unit where +@[reducible, rocq_alias unit_cofe] +def unitCOFE [SIdx SI] : @COFE SI _ Unit where compl _ := () conv_compl := ⟨⟩ -abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun β] := ∀ x : α, IsCOFE (β x) +abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun (SI := SI) β] := ∀ x : α, IsCOFE SI (β x) -instance instIsCOFEOption [OFE α] [IsCOFE α] : IsCOFE (Option α) where +instance instIsCOFEOption [OFE SI α] [IsCOFE SI α] : IsCOFE SI (Option α) where compl c := match c 0 with | .some seed => .some <| compl <| c.map ⟨_, Option.ne_match id inferInstance seed⟩ | .none => none @@ -1045,13 +1059,13 @@ instance instIsCOFEOption [OFE α] [IsCOFE α] : IsCOFE (Option α) where #rocq_ignore option_compl "Local Compl definition; folded into Lean's IsCOFE instance." @[rocq_alias discrete_fun_cofe] -instance {α : Type _} (β : α → Type _) [∀ x, COFE (β x)] : COFE ((x : α) → β x) where +instance {α : Type _} (β : α → Type _) [∀ x, COFE SI (β x)] : COFE SI ((x : α) → β x) where compl c x := compl (c.map (applyHom x)) conv_compl _ := IsCOFE.conv_compl #rocq_ignore discrete_fun_chain "Local helper; folded into Lean's IsCOFE instance." @[rocq_alias ofe_mor_cofe] -instance instIsCOFEHom [OFE α] [OFE β] [IsCOFE β] : IsCOFE (α -n> β) where +instance instIsCOFEHom [OFE SI α] [OFE SI β] [IsCOFE SI β] : IsCOFE SI (α -n> β) where compl c := by refine ⟨(compl <| c.map <| applyNe ·), ⟨fun n _ _ H => ?_⟩⟩ refine conv_compl.trans (.trans ?_ conv_compl.symm) @@ -1060,12 +1074,12 @@ instance instIsCOFEHom [OFE α] [OFE β] [IsCOFE β] : IsCOFE (α -n> β) where #rocq_ignore ofe_mor_compl "Inlined in IsCOFE instance" @[rocq_alias prod_cofe] -instance instIsCOFEProd [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (α × β) where +instance instIsCOFEProd [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : IsCOFE SI (α × β) where compl c := ⟨compl (c.map ⟨Prod.fst, inferInstance⟩), compl (c.map ⟨Prod.snd, inferInstance⟩)⟩ conv_compl := ⟨conv_compl, conv_compl⟩ @[rocq_alias sum_cofe] -instance instIsCOFESum [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (α ⊕ β) where +instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : IsCOFE SI (α ⊕ β) where compl c := match c 0 with | .inl seed => .inl (compl (c.map ⟨Sum.elim id (Function.const _ seed), inferInstance⟩)) | .inr seed => .inr (compl (c.map ⟨Sum.elim (Function.const _ seed) id, inferInstance⟩)) @@ -1088,11 +1102,11 @@ instance instIsCOFESum [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (α #rocq_ignore sum_compl "Local Compl definition; folded into Lean's IsCOFE instance." @[rocq_alias sigT_chain_const_proj1] -theorem Sigma.chain_const_proj1 {P : α → Type _} [∀ x, OFE (P x)] [∀ x, IsCOFE (P x)] +theorem Sigma.chain_const_proj1 {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] (c : Chain (Sigma P)) n : (c n).fst = (c 0).fst := (c.cauchy (by omega : 0 ≤ n)).choose @[rocq_alias chain_map_snd] -def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE (P x)] [∀ x, IsCOFE (P x)] (c : Chain (Sigma P)) : +def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] (c : Chain (Sigma P)) : Chain (P (c 0).fst) where chain n := Sigma.chain_const_proj1 c n ▸ (c n).snd cauchy {n i} hle := by @@ -1105,7 +1119,7 @@ def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE (P x)] [∀ x, IsCOFE (P exact hequiv @[rocq_alias sigT_cofe] -instance {P : α → Type _} [∀ x, OFE (P x)] [∀ x, IsCOFE (P x)] : IsCOFE (Sigma P) where +instance {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] : IsCOFE SI (Sigma P) where compl c := ⟨(c 0).fst, compl (Sigma.chain_map_snd c)⟩ conv_compl {n c} := by refine ⟨(Sigma.chain_const_proj1 c n).symm, ?_⟩ @@ -1119,24 +1133,24 @@ instance {P : α → Type _} [∀ x, OFE (P x)] [∀ x, IsCOFE (P x)] : IsCOFE ( #rocq_ignore sigT_compl "Local Compl definition; folded into Lean's IsCOFE instance." set_option linter.checkUnivs false in -abbrev OFunctorPre := ∀ α β [COFE α] [COFE β], Type _ +abbrev OFunctorPre (SI : outParam <| Type _) [SIdx SI] := ∀ α β [COFE SI α] [COFE SI β], Type _ #rocq_ignore oFunctor_apply "Definition for application of an `oFunctor`; subsumed by `OFunctorPre` in Lean." @[rocq_alias oFunctor] -class OFunctor (F : OFunctorPre) where - ofe [COFE α] [COFE β] : OFE (F α β) - map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : +class OFunctor (SI) [SIdx SI] (F : OFunctorPre SI) where + ofe [COFE SI α] [COFE SI β] : OFE SI (F α β) + map [COFE SI α₁] [COFE SI α₂] [COFE SI β₁] [COFE SI β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -n> F α₂ β₂ - map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : + map_ne [COFE SI α₁] [COFE SI α₂] [COFE SI β₁] [COFE SI β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - map_id [COFE α] [COFE β] (x : F α β) : map (@Hom.id α _) (@Hom.id β _) x = x - map_comp [COFE α₁] [COFE α₂] [COFE α₃] [COFE β₁] [COFE β₂] [COFE β₃] + map_id [COFE SI α] [COFE SI β] (x : F α β) : map (Hom.id (α := α)) (Hom.id (α := β)) x = x + map_comp [COFE SI α₁] [COFE SI α₂] [COFE SI α₃] [COFE SI β₁] [COFE SI β₂] [COFE SI β₃] (f : α₂ -n> α₁) (g : α₃ -n> α₂) (f' : β₁ -n> β₂) (g' : β₂ -n> β₃) (x : F α₁ β₁) : map (f.comp g) (g'.comp f') x = map g g' (map f f' x) @[rocq_alias oFunctorContractive] -class OFunctorContractive (F : OFunctorPre) extends OFunctor F where - map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : +class OFunctorContractive SI [SIdx SI] (F : OFunctorPre SI) extends OFunctor SI F where + map_contractive [COFE SI α₁] [COFE SI α₂] [COFE SI β₁] [COFE SI β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) attribute [reducible, instance] OFunctor.ofe @@ -1147,27 +1161,36 @@ end COFE @[ext] structure DiscreteO (α : Type _) where car : α -instance : COFE (DiscreteO α) := COFE.ofDiscrete _ +@[reducible] +def DiscreteO.instCOFE [SIdx SI] {α : Type _} : COFE SI (DiscreteO α) := COFE.ofDiscrete _ -instance {α : Type _} : OFE.Discrete (DiscreteO α) := ⟨fun h => h⟩ +@[reducible] +def DiscreteO.OFE [SIdx SI] {α : Type _} : + @OFE.Discrete SI _ (DiscreteO α) (OFE.ofDiscrete _) := + ⟨fun h => h⟩ #rocq_ignore leibnizO_leibniz "Not needed" theorem DiscreteO.eqv_inj {x y : α} (H : DiscreteO.mk x = DiscreteO.mk y) : x = y := congrArg DiscreteO.car H -theorem DiscreteO.dist_inj {x y : α} {n} (H : DiscreteO.mk x ≡{n}≡ DiscreteO.mk y) : x = y := - DiscreteO.eqv_inj <| discrete H +theorem DiscreteO.dist_inj [SIdx SI] {α : Type _} {x y : α} {n : SI} : + letI := DiscreteO.instCOFE (SI := SI) (α := α) + DiscreteO.mk x ≡{n}≡ DiscreteO.mk y → x = y := by + letI := DiscreteO.instCOFE (SI := SI) (α := α) + exact DiscreteO.eqv_inj <| discrete H section DiscreteFunOF open COFE -abbrev DiscreteFunOF {C : Type _} (F : C → OFunctorPre) : OFunctorPre := +variable [SIdx SI] + +abbrev DiscreteFunOF {C : Type _} (F : C → OFunctorPre SI) : OFunctorPre SI := fun A B _ _ => (c : C) → F c A B @[rocq_alias discrete_funOF] -instance oFunctor_discreteFunOF {C} (F : C → OFunctorPre) [∀ c, OFunctor (F c)] : - OFunctor (DiscreteFunOF F) where +instance oFunctor_discreteFunOF {C} (F : C → OFunctorPre SI) [∀ c, OFunctor SI (F c)] : + OFunctor SI (DiscreteFunOF F) where ofe := _ map f₁ f₂ := mapCodHom fun _ => OFunctor.map f₁ f₂ map_ne.ne _ _ _ Hx _ _ Hy _ _ := OFunctor.map_ne.ne Hx Hy .. @@ -1175,14 +1198,15 @@ instance oFunctor_discreteFunOF {C} (F : C → OFunctorPre) [∀ c, OFunctor (F map_comp f g f' g' x := funext fun c => OFunctor.map_comp f g f' g' (x c) @[rocq_alias discrete_funOF_contractive] -instance oFunctor_discreteFunOF_contractive {C} (F : C → OFunctorPre) - [∀ c, OFunctorContractive (F c)] : OFunctorContractive (DiscreteFunOF F) where +instance oFunctor_discreteFunOF_contractive {C} (F : C → OFunctorPre SI) + [∀ c, OFunctorContractive SI (F c)] : OFunctorContractive SI (DiscreteFunOF F) where map_contractive.1 h _ _ := OFunctorContractive.map_contractive.distLater_dist h _ end DiscreteFunOF section Option -variable [OFE α] + +variable [SIdx SI] [OFE SI α] @[rocq_alias option_chain] def optionChain (c : Chain (Option α)) (x : α) : Chain α := by @@ -1191,46 +1215,46 @@ def optionChain (c : Chain (Option α)) (x : α) : Chain α := by cases c.chain i <;> cases c.chain n <;> simp [Dist, Option.Forall₂] @[rocq_alias option_cofe] -instance isCOFE_option [IsCOFE α] : IsCOFE (Option α) where +instance isCOFE_option [IsCOFE SI α] : IsCOFE SI (Option α) where compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x) - conv_compl {n} c := by + conv_compl {n : SI} c := by have := c.cauchy (Nat.zero_le n); revert this rcases c.chain 0 with _|x' <;> rcases e : c.chain n with _|y' <;> simp [Dist, Option.Forall₂] refine fun _ => OFE.dist_eqv.trans IsCOFE.conv_compl ?_ simp [optionChain, e] @[rocq_alias optionO_map] -def optionMap {α β : Type _} [OFE α] [OFE β] (f : α -n> β) : Option α -n> Option β := by +def optionMap {α β : Type _} [OFE SI α] [OFE SI β] (f : α -n> β) : Option α -n> Option β := by refine ⟨Option.map f, ⟨?_⟩⟩ rintro _ ⟨⟩ ⟨⟩ H <;> simp_all [Dist, Option.Forall₂] exact f.ne.ne H @[rocq_alias option_fmap_ne] -theorem Option.map_ne [OFE β] {f g : α → β} {x y : Option α} {n} : +theorem Option.map_ne [OFE SI β] {f g : α → β} {x y : Option α} {n : SI} : (∀ x y, x ≡{n}≡ y → f x ≡{n}≡ g y) → x ≡{n}≡ y → Option.map f x ≡{n}≡ Option.map g y := by intro hf hxy cases x <;> cases y <;> simp_all [Dist, Option.Forall₂] -theorem Option.map_forall₂ {α β : Type _} [OFE α] [OFE β] (f : α → β) +theorem Option.map_forall₂ {α β : Type _} [OFE SI α] [OFE SI β] (f : α → β) {o1 o2 : Option α} (h : o1 = o2) : o1.map f = o2.map f := congrArg (Option.map f) h @[rocq_alias optionO_map_ne] -instance optionMap_ne [OFE β] : NonExpansive (optionMap (α := α) (β := β)) where +instance optionMap_ne [OFE SI β] : NonExpansive (optionMap (α := α) (β := β)) where ne _ f _ h o := Option.map_ne (fun _ _ hab => dist_eqv.trans (f.ne.ne hab) (h _)) (dist_eqv.refl o) @[rocq_alias option_mbind_ne] -theorem Option.bind_ne [OFE β] {f g : α → Option β} {x y : Option α} {n} +theorem Option.bind_ne [OFE SI β] {f g : α → Option β} {x y : Option α} {n} (hf : ∀ x y, x ≡{n}≡ y → f x ≡{n}≡ g y) (hxy : x ≡{n}≡ y) : x.bind f ≡{n}≡ y.bind g := by cases x <;> cases y <;> simp_all [Dist, Option.Forall₂] @[rocq_alias option_mjoin_ne] -theorem Option.join_ne {x y : Option (Option α)} {n} (hxy : x ≡{n}≡ y) : x.join ≡{n}≡ y.join := by +theorem Option.join_ne {x y : Option (Option α)} {n : SI} (hxy : x ≡{n}≡ y) : x.join ≡{n}≡ y.join := by cases x <;> cases y <;> simp_all [Dist, Option.Forall₂] @[rocq_alias from_option_ne] theorem Option.elim_ne {β : Type _} (R : β → β → Prop) {f g : α → β} {d d' : β} - {x y : Option α} {n} (hf : ∀ x y, x ≡{n}≡ y → R (f x) (g y)) (hd : R d d') + {x y : Option α} {n : SI} (hf : ∀ x y, x ≡{n}≡ y → R (f x) (g y)) (hd : R d d') (hxy : x ≡{n}≡ y) : R (x.elim d f) (y.elim d' g) := by cases x <;> cases y <;> simp_all [Dist, Option.Forall₂] @@ -1239,13 +1263,15 @@ end Option section OptionOF open COFE -abbrev OptionOF (F : OFunctorPre) : OFunctorPre := +variable [SIdx SI] + +abbrev OptionOF (F : OFunctorPre SI) : OFunctorPre SI := fun A B _ _ => Option (F A B) -variable (F : OFunctorPre) +variable (F : OFunctorPre SI) @[rocq_alias optionOF] -instance oFunctorOption [OFunctor F] : OFunctor (OptionOF F) where +instance oFunctorOption [OFunctor SI F] : OFunctor SI (OptionOF F) where ofe := _ map f g := optionMap (OFunctor.map f g) map_ne.ne _ _ _ Hx _ _ Hy z := by @@ -1261,7 +1287,7 @@ instance oFunctorOption [OFunctor F] : OFunctor (OptionOF F) where | some c => exact some_eqv_some.mpr (OFunctor.map_comp f g f' g' c) @[rocq_alias optionOF_contractive] -instance [OFunctorContractive F] : OFunctorContractive (OptionOF F) where +instance [OFunctorContractive SI F] : OFunctorContractive SI (OptionOF F) where map_contractive.1 H z := by have := (OFunctorContractive.map_contractive (F := F)).distLater_dist H cases z <;> simp_all [optionMap, Dist, Option.Forall₂, Function.uncurry, OFunctor.map] @@ -1272,7 +1298,7 @@ section ProdOF open COFE -variable [OFE A] [OFE A'] [OFE B] [OFE B'] +variable [SIdx SI] [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] @[rocq_alias prod_map_ne] instance instNonExpansiveProdMap (f : A → A') (g : B → B') [NonExpansive f] [NonExpansive g] : @@ -1284,12 +1310,12 @@ instance instNonExpansiveProdMap (f : A → A') (g : B → B') [NonExpansive f] · rw [Prod.map_snd] exact NonExpansive.ne H.2 -omit [OFE A] [OFE A'] [OFE B] [OFE B'] in +omit [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] in theorem Prod.map_ext {f f' : A → A'} {g g' : B → B'} (Hf : ∀ a, f a = f' a) (Hg : ∀ a, g a = g' a) : Prod.map f g x = Prod.map f' g' x := Prod.ext (Hf x.fst) (Hg x.snd) -omit [OFE A] [OFE B] in +omit [OFE SI A] [OFE SI B] in theorem Prod.map_ne {f f' : A → A'} {g g' : B → B'} (Hf : ∀ a, f a ≡{n}≡ f' a) (Hg : ∀ a, g a ≡{n}≡ g' a) : Prod.map f g x ≡{n}≡ Prod.map f' g' x := ⟨Hf x.fst, Hg x.snd⟩ @@ -1303,11 +1329,11 @@ def Prod.mapO (f : A -n> A') (g : B -n> B') : A × B -n> A' × B' where instance Prod.mapO_ne : NonExpansive₂ (Prod.mapO (A := A) (A' := A') (B := B) (B' := B')) where ne _ _ _ Hf _ _ Hg _ := Prod.map_ne Hf Hg -abbrev ProdOF (F1 F2 : OFunctorPre) : OFunctorPre := fun A B => (F1 A B) × (F2 A B) +abbrev ProdOF SI [SIdx SI] (F1 F2 : OFunctorPre SI) : OFunctorPre SI := fun A B => (F1 A B) × (F2 A B) open OFunctor in @[rocq_alias prodOF] -instance instOFunctorProdOF [OFunctor F1] [OFunctor F2] : OFunctor (ProdOF F1 F2) where +instance instOFunctorProdOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (ProdOF SI F1 F2) where ofe := inferInstance map f g := Prod.mapO (map f g) (map f g) map_ne.ne _ _ _ Hx _ _ Hy _ := ⟨map_ne.ne Hx Hy _, map_ne.ne Hx Hy _⟩ @@ -1316,8 +1342,8 @@ instance instOFunctorProdOF [OFunctor F1] [OFunctor F2] : OFunctor (ProdOF F1 F2 open OFunctorContractive in @[rocq_alias prodOF_contractive] -instance instOFunctorContractiveProdOF [OFunctorContractive F1] [OFunctorContractive F2] : - OFunctorContractive (ProdOF F1 F2) where +instance instOFunctorContractiveProdOF [OFunctorContractive SI F1] [OFunctorContractive SI F2] : + OFunctorContractive SI (ProdOF SI F1 F2) where map_contractive.1 H _ := Prod.map_ne (fun _ => map_contractive.1 H _) (fun _ => map_contractive.1 H _) @@ -1327,7 +1353,7 @@ section SumOF open COFE -variable [OFE A] [OFE A'] [OFE B] [OFE B'] +variable [SIdx SI] [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] @[rocq_alias sum_map_ne] instance instNonExpansiveSumMap (f : A → A') (g : B → B') [NonExpansive f] [NonExpansive g] : @@ -1336,14 +1362,14 @@ instance instNonExpansiveSumMap (f : A → A') (g : B → B') [NonExpansive f] [ | .inl _, .inl _ => NonExpansive.ne (f := Sum.inl) (NonExpansive.ne (dist_ext_left H)) | .inr _, .inr _ => NonExpansive.ne (f := Sum.inr) (NonExpansive.ne (dist_ext_right H)) -omit [OFE A] [OFE A'] [OFE B] [OFE B'] in +omit [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] in theorem Sum.map_ext {f f' : A → A'} {g g' : B → B'} (Hf : ∀ a, f a = f' a) (Hg : ∀ a, g a = g' a) : Sum.map f g x = Sum.map f' g' x := match x with | .inl _ => equiv_inl (Hf _) | .inr _ => equiv_inr (Hg _) -omit [OFE A] [OFE B] in +omit [OFE SI A] [OFE SI B] in theorem Sum.map_ne {f f' : A → A'} {g g' : B → B'} (Hf : ∀ a, f a ≡{n}≡ f' a) (Hg : ∀ a, g a ≡{n}≡ g' a) : Sum.map f g x ≡{n}≡ Sum.map f' g' x := match x with @@ -1359,11 +1385,11 @@ def Sum.mapO (f : A -n> A') (g : B -n> B') : A ⊕ B -n> A' ⊕ B' where instance Sum.mapO_ne : NonExpansive₂ (Sum.mapO (A := A) (A' := A') (B := B) (B' := B')) where ne _ _ _ Hf _ _ Hg _ := Sum.map_ne Hf Hg -abbrev SumOF (F1 F2 : OFunctorPre) : OFunctorPre := fun A B => (F1 A B) ⊕ (F2 A B) +abbrev SumOF SI [SIdx SI] (F1 F2 : OFunctorPre SI) : OFunctorPre SI := fun A B => (F1 A B) ⊕ (F2 A B) open OFunctor in @[rocq_alias sumOF] -instance instOFunctorSumOF [OFunctor F1] [OFunctor F2] : OFunctor (SumOF F1 F2) where +instance instOFunctorSumOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (SumOF SI F1 F2) where ofe := inferInstance map f g := Sum.mapO (map f g) (map f g) map_ne.ne _ _ _ Hx _ _ Hy x := match x with @@ -1378,8 +1404,8 @@ instance instOFunctorSumOF [OFunctor F1] [OFunctor F2] : OFunctor (SumOF F1 F2) open OFunctorContractive in @[rocq_alias sumOF_contractive] -instance instOFunctorContractiveSumOF [OFunctorContractive F1] [OFunctorContractive F2] : - OFunctorContractive (SumOF F1 F2) where +instance instOFunctorContractiveSumOF [OFunctorContractive SI F1] [OFunctorContractive SI F2] : + OFunctorContractive SI (SumOF SI F1 F2) where map_contractive.1 H _ := Sum.map_ne (fun _ => map_contractive.1 H _) (fun _ => map_contractive.1 H _) @@ -1389,19 +1415,21 @@ section SigmaOF open COFE +variable [SIdx SI] + @[rocq_alias sigT_map] -def Sigma.mapO {P1 P2 : A → Type _} [∀ x, OFE (P1 x)] [∀ x, OFE (P2 x)] : +def Sigma.mapO {P1 P2 : A → Type _} [∀ x, OFE SI (P1 x)] [∀ x, OFE SI (P2 x)] : ((a : A) → P1 a -n> P2 a) -n> Sigma P1 -n> Sigma P2 where f g := ⟨fun x => ⟨_, g x.fst x.snd⟩, ⟨by rintro n ⟨x, xH⟩ ⟨y, yH⟩ ⟨⟨⟩, hdist⟩; exact ⟨rfl, (g x).ne.ne hdist⟩⟩⟩ ne := ⟨fun n f g hdist x => ⟨rfl, hdist _ _⟩⟩ open OFunctor in -abbrev SigmaOF (F : A → OFunctorPre) : OFunctorPre := +abbrev SigmaOF (F : A → OFunctorPre SI) : OFunctorPre SI := fun B C => Sigma (fun (a : A) => (F a) B C) open OFunctor in @[rocq_alias sigTOF] -instance instOFunctorSigmaOF {F : A → OFunctorPre} [∀ a, OFunctor (F a)] : OFunctor (SigmaOF F) where +instance instOFunctorSigmaOF {F : A → OFunctorPre SI} [∀ a, OFunctor SI (F a)] : OFunctor SI (SigmaOF F) where ofe := inferInstance map f g := Sigma.mapO (fun _ => map f g) map_ne.ne _ _ _ Hx _ _ Hy := NonExpansive.ne (fun _ => map_ne.ne Hx Hy) @@ -1411,8 +1439,8 @@ instance instOFunctorSigmaOF {F : A → OFunctorPre} [∀ a, OFunctor (F a)] : O open OFunctorContractive in @[rocq_alias sigTOF_contractive] -instance instOFunctorContractiveSigmaOF [∀ a, OFunctorContractive (F a)] : - OFunctorContractive (SigmaOF F) where +instance instOFunctorContractiveSigmaOF [∀ a, OFunctorContractive SI (F a)] : + OFunctorContractive SI (SigmaOF F) where map_contractive.1 H := Sigma.mapO.ne.ne (fun _ => map_contractive.1 H) end SigmaOF @@ -1421,10 +1449,12 @@ section constOF open COFE -abbrev constOF (B : Type) : OFunctorPre := fun _ _ _ _ => B +variable [SIdx SI] + +abbrev constOF (B : Type) : OFunctorPre SI := fun _ _ _ _ => B @[rocq_alias constOF] -instance oFunctorConstOF [COFE B] : OFunctor (constOF B) where +instance oFunctorConstOF [COFE SI B] : OFunctor SI (constOF B) where ofe := _ map _ _ := ⟨id, id_ne⟩ map_ne := by intros; constructor; simp @@ -1432,7 +1462,7 @@ instance oFunctorConstOF [COFE B] : OFunctor (constOF B) where map_comp := by simp @[rocq_alias constOF_contractive] -instance OFunctor.constOF_contractive [COFE B] : OFunctorContractive (constOF B) where +instance OFunctor.constOF_contractive [COFE SI B] : OFunctorContractive SI (constOF B) where map_contractive.1 := by simp [OFunctor.map] end constOF @@ -1441,11 +1471,13 @@ section IdOF open COFE -abbrev IdOF : OFunctorPre := fun (_ : Type _) (B : Type _) (_ : COFE _) (_ : COFE B) => B +variable [SIdx SI] + +abbrev IdOF : OFunctorPre SI := fun (_ : Type _) (B : Type _) (_ : COFE SI _) (_ : COFE SI B) => B open OFunctor in @[rocq_alias idOF] -instance : OFunctor IdOF where +instance : OFunctor SI IdOF where ofe := inferInstance map _ g := g map_ne.ne _ _ _ _ _ _ Hy := Hy @@ -1458,7 +1490,7 @@ section HomOF open COFE -variable [OFE A] [OFE A'] [OFE B] [OFE B'] +variable [SIdx SI] [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] @[rocq_alias ofe_morO_map] def Hom.map (pre : A' -n> A) (post : B -n> B') : (A -n> B) -n> (A' -n> B') where @@ -1473,12 +1505,12 @@ instance instNonExpansive₂HomMap : ne {_ _ _} Hx {y₁ _} Hy f g := (NonExpansive.ne (f := y₁) (NonExpansive.ne (f := f) (Hx g))).trans (Hy _) -abbrev HomOF (F1 F2 : OFunctorPre) [OFunctor F1] [OFunctor F2] : OFunctorPre := - fun (A : Type _) (B : Type _) (_ : COFE A) (_ : COFE B) => @F1 B A _ _ -n> @F2 A B _ _ +abbrev HomOF (F1 F2 : OFunctorPre SI) [OFunctor SI F1] [OFunctor SI F2] : OFunctorPre SI := + fun (A : Type _) (B : Type _) (_ : COFE SI A) (_ : COFE SI B) => @F1 B A _ _ -n> @F2 A B _ _ open OFunctor in @[rocq_alias ofe_morOF] -instance instOFunctorHomOF [OFunctor F1] [OFunctor F2] : OFunctor (HomOF F1 F2) where +instance instOFunctorHomOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (HomOF F1 F2) where ofe := inferInstance map f g := Hom.map (map (F := F1) g f) (map (F := F2) f g) map_ne.ne _ _ _ Hf _ _ Hg := NonExpansive₂.ne (map_ne.ne Hg Hf) (map_ne.ne Hf Hg) @@ -1488,9 +1520,9 @@ instance instOFunctorHomOF [OFunctor F1] [OFunctor F2] : OFunctor (HomOF F1 F2) open OFunctorContractive in @[rocq_alias ofe_morOF_contractive] -instance instOFunctorContractiveHomOF [OFunctorContractive F1] [OFunctorContractive F2] : - OFunctorContractive (HomOF F1 F2) where - map_contractive.1 {n} ab ab' h := match ab, ab' with +instance instOFunctorContractiveHomOF [OFunctorContractive SI F1] [OFunctorContractive SI F2] : + OFunctorContractive SI (HomOF F1 F2) where + map_contractive.1 {n : SI} ab ab' h := match ab, ab' with | ⟨a, b⟩, ⟨a', b'⟩ => by simp only [Function.uncurry_apply_pair, OFunctor.map] have h' : DistLater n (b, a) (b', a') := @@ -1505,38 +1537,40 @@ end HomOF section Fixpoint +variable [SIdx SI] + @[rocq_alias LimitPreserving] -def LimitPreserving [COFE α] (P : α → Prop) : Prop := +def LimitPreserving [COFE SI α] (P : α → Prop) : Prop := ∀ (c : Chain α), (∀ n, P (c n)) → P (COFE.compl c) @[rocq_alias limit_preserving_const] -theorem LimitPreserving.const [COFE α] {P : Prop} : LimitPreserving fun (_ : α) => P := by +theorem LimitPreserving.const [COFE SI α] {P : Prop} : LimitPreserving fun (_ : α) => P := by simp [LimitPreserving] @[rocq_alias limit_preserving_discrete] -theorem LimitPreserving.discrete [COFE α] {P : α → Prop} : +theorem LimitPreserving.discrete [COFE SI α] {P : α → Prop} : (∀ {x y : α}, x ≡{0}≡ y → (P x → P y)) → LimitPreserving P := fun Hdisc _ H => Hdisc COFE.conv_compl.symm (H _) @[rocq_alias limit_preserving_and] -theorem LimitPreserving.and [COFE α] {P Q : α → Prop} (HP : LimitPreserving P) +theorem LimitPreserving.and [COFE SI α] {P Q : α → Prop} (HP : LimitPreserving P) (HQ : LimitPreserving Q) : LimitPreserving fun a => P a ∧ Q a := fun _ HPQ => ⟨HP _ (fun n => (HPQ n).left), HQ _ (fun n => (HPQ n).right)⟩ @[rocq_alias limit_preserving_forall] -theorem LimitPreserving.forall [COFE α] (P : β → α → Prop) (Hlim : ∀ y, LimitPreserving (P y)) : +theorem LimitPreserving.forall [COFE SI α] (P : β → α → Prop) (Hlim : ∀ y, LimitPreserving (P y)) : LimitPreserving (∀ y, P y ·) := fun c H y => Hlim y c (H · y) @[rocq_alias limit_preserving_impl] -theorem LimitPreserving.impl [COFE α] (P1 P2 : α → Prop) +theorem LimitPreserving.impl [COFE SI α] (P1 P2 : α → Prop) (HP1 : ∀ {x y : α}, x ≡{0}≡ y → P1 x → P1 y) (Hcompl : LimitPreserving P2) : LimitPreserving (fun x => P1 x → P2 x) := fun _ Hc HP1c => Hcompl _ <| fun n => Hc _ (HP1 (COFE.conv_compl' (Nat.zero_le n)) HP1c) @[rocq_alias limit_preserving_equiv] -theorem LimitPreserving.equiv [COFE α] [COFE β] (f g : α -n> β) : +theorem LimitPreserving.equiv [COFE SI α] [COFE SI β] (f g : α -n> β) : LimitPreserving (fun x => f x = g x) := by intro c Hfg refine eq_dist.mpr fun n => ?_ @@ -1546,12 +1580,12 @@ theorem LimitPreserving.equiv [COFE α] [COFE β] (f g : α -n> β) : exact g.ne.ne COFE.conv_compl.symm @[rocq_alias limit_preserving_ext] -theorem LimitPreserving.ext {α}[COFE α] {P Q : α -> Prop} (he : ∀ {x}, (P x ↔ Q x)) +theorem LimitPreserving.ext {α} [COFE SI α] {P Q : α -> Prop} (he : ∀ {x}, (P x ↔ Q x)) (hp : LimitPreserving P) : LimitPreserving Q := fun _ => (he.1 <| hp _ <| fun _ => he.2 <| · _) -def Fixpoint.chain [OFE α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where +def Fixpoint.chain [OFE SI α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where chain n := Nat.repeat f (n + 1) default - cauchy {n} := by + cauchy {n : SI} := by induction n with simp [Nat.repeat] | succ n IH rintro (_|i) <;> simp intro H @@ -1561,10 +1595,10 @@ def Fixpoint.chain [OFE α] [Inhabited α] (f : α → α) [Contractive f] : Cha /-- The chain construction of the Banach fixpoint. `fixpointP` packages it, together with its unfolding equation, behind an opaque constant. -/ -def fixpointAux [COFE α] [Inhabited α] (f : α → α) [Contractive f] : α := +def fixpointAux [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : α := COFE.compl <| Fixpoint.chain f -theorem fixpointAux_unfold [COFE α] [Inhabited α] (f : α -c> α) : +theorem fixpointAux_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : fixpointAux f = f (fixpointAux f) := by refine eq_dist.mpr fun n => ?_ apply COFE.conv_compl.trans @@ -1576,26 +1610,26 @@ theorem fixpointAux_unfold [COFE α] [Inhabited α] (f : α -c> α) : /-- The Banach fixpoint packed together with its unfolding equation as a single opaque value. Being opaque, it is a stuck constant for definitional-equality checks in both the elaborator and the kernel, which keeps the approximation chain of `fixpointAux` sealed. -/ -opaque fixpointP [COFE α] [Inhabited α] (f : α → α) [Contractive f] : { x : α // x = f x } := +opaque fixpointP [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : { x : α // x = f x } := ⟨fixpointAux f, fixpointAux_unfold f.toContractiveHom⟩ /-- Fixpoints inside of a COFE -/ @[rocq_alias fixpoint] -def fixpoint [COFE α] [Inhabited α] (f : α → α) [Contractive f] : α := +def fixpoint [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : α := (fixpointP f).val #rocq_ignore fixpoint_def "Use fixpoint" #rocq_ignore fixpoint_aux "Use fixpoint" #rocq_ignore fixpoint_unseal "fixpoint is unsealed by default" -nonrec abbrev OFE.ContractiveHom.fixpoint [COFE α] [Inhabited α] (f : α -c> α) : α := fixpoint f.f +nonrec abbrev OFE.ContractiveHom.fixpoint [COFE SI α] [Inhabited α] (f : α -c> α) : α := fixpoint f.f @[rocq_alias fixpoint_unfold] -theorem fixpoint_unfold [COFE α] [Inhabited α] (f : α -c> α) : +theorem fixpoint_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : fixpoint f = f (fixpoint f) := (fixpointP f).property @[rocq_alias fixpoint_unique] -theorem fixpoint_unique [COFE α] [Inhabited α] {f : α -c> α} {x : α} (H : x = f x) : +theorem fixpoint_unique [COFE SI α] [Inhabited α] {f : α -c> α} {x : α} (H : x = f x) : x = fixpoint f := by refine eq_dist.mpr fun n => ?_ induction n with refine H.dist.trans <| .trans ?_ (fixpoint_unfold f).dist.symm @@ -1603,7 +1637,7 @@ theorem fixpoint_unique [COFE α] [Inhabited α] {f : α -c> α} {x : α} (H : x | succ _ IH => exact Contractive.succ f.f IH @[rocq_alias fixpoint_ne] -instance OFE.ContractiveHom.fixpoint_ne [COFE α] [Inhabited α] : +instance OFE.ContractiveHom.fixpoint_ne [COFE SI α] [Inhabited α] : NonExpansive (ContractiveHom.fixpoint (α := α)) where ne n f1 f2 H := by induction n with @@ -1613,7 +1647,7 @@ instance OFE.ContractiveHom.fixpoint_ne [COFE α] [Inhabited α] : | succ _ IH => exact Contractive.succ f2.f <| IH <| Dist.lt H (Nat.lt_add_one _) @[elab_as_elim, rocq_alias fixpoint_ind] -theorem OFE.ContractiveHom.fixpoint_ind [COFE α] [Inhabited α] (f : α -c> α) +theorem OFE.ContractiveHom.fixpoint_ind [COFE SI α] [Inhabited α] (f : α -c> α) (P : α → Prop) (HProper : ∀ A B : α, A = B → P A → P B) (x : α) (Hbase : P x) (Hind : ∀ x, P x → P (f x)) (Hlim : LimitPreserving P) : P f.fixpoint := by @@ -1642,23 +1676,25 @@ section FixpointAB open OFE -instance [OFE α] [OFE β] [OFE γ] : CoeFun (α -c> β -n> γ) (fun _ => α → β → γ) := ⟨fun f x => (f.f x).f⟩ -instance [OFE α] [OFE β] [OFE γ] : CoeFun (α -c> β -c> γ) (fun _ => α → β → γ) := ⟨fun f x => (f.f x).f⟩ +variable [SIdx SI] + +instance [OFE SI α] [OFE SI β] [OFE SI γ] : CoeFun (α -c> β -n> γ) (fun _ => α → β → γ) := ⟨fun f x => (f.f x).f⟩ +instance [OFE SI α] [OFE SI β] [OFE SI γ] : CoeFun (α -c> β -c> γ) (fun _ => α → β → γ) := ⟨fun f x => (f.f x).f⟩ /-- A Contractive function with NonExpansive function codomain is NonExpansive₂. -/ -instance ne₂_of_contractive_ne [OFE α] [OFE β] [OFE γ] (fA : α -c> β -n> γ) : NonExpansive₂ fA where +instance ne₂_of_contractive_ne [OFE SI α] [OFE SI β] [OFE SI γ] (fA : α -c> β -n> γ) : NonExpansive₂ fA where ne n x₁ x₂ Hx y₁ y₂ Hy := by refine .trans ?_ ((fA.f x₂).ne.ne Hy) apply fA.ne.ne Hx /-- A Contractive function with Contractive function codomain is NonExpansive₂. -/ -instance ne₂_of_contractive [OFE α] [OFE β] [OFE γ] (fB : α -c> β -c> γ) : NonExpansive₂ fB where +instance ne₂_of_contractive [OFE SI α] [OFE SI β] [OFE SI γ] (fB : α -c> β -c> γ) : NonExpansive₂ fB where ne n x₁ x₂ Hx y₁ y₂ Hy := by refine .trans ?_ ((fB.f x₂).ne.ne Hy) apply fB.ne.ne Hx @[rocq_alias fixpoint_AB] -def fixpointAB [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fB : α -c> β -c> β) (x : α) : β := by +def fixpointAB [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fB : α -c> β -c> β) (x : α) : β := by let con_hom : β -c> β := { f := fB x, contractive := ⟨fB.f x |>.contractive.distLater_dist⟩ @@ -1666,7 +1702,7 @@ def fixpointAB [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fB : α -c> β exact con_hom.fixpoint @[rocq_alias fixpoint_AB_contractive] -theorem fixpointAB_contractive [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fB : α -c> β -c> β) : +theorem fixpointAB_contractive [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fB : α -c> β -c> β) : Contractive (fixpointAB fB) where distLater_dist {n _ _} Dl := by apply ContractiveHom.fixpoint_ne.ne @@ -1674,12 +1710,12 @@ theorem fixpointAB_contractive [COFE α] [COFE β] [Inhabited α] [Inhabited β] exact Dl @[rocq_alias fixpoint_AA] -def fixpointAA [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) +def fixpointAA [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) (x : α) : α := fA x (fixpointAB fB x) @[rocq_alias fixpoint_AA_contractive] -theorem fixpointAA_contractive [COFE α] [COFE β] [Inhabited α] [Inhabited β] +theorem fixpointAA_contractive [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) : Contractive (fixpointAA fA fB) where distLater_dist {_ _ x₂} Dl := by refine .trans ?_ ((fA.f x₂).ne.ne ((fixpointAB_contractive fB).distLater_dist Dl)) @@ -1687,7 +1723,7 @@ theorem fixpointAA_contractive [COFE α] [COFE β] [Inhabited α] [Inhabited β] exact Dl @[rocq_alias fixpoint_A] -def fixpointA [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) +def fixpointA [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) : α := by let con_hom : α -c> α := { f := fixpointAA fA fB, @@ -1696,37 +1732,37 @@ def fixpointA [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fA : α -c> β exact con_hom.fixpoint @[rocq_alias fixpoint_B] -def fixpointB [COFE α] [COFE β] [Inhabited α] [Inhabited β] +def fixpointB [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) : β := fixpointAB fB <| fixpointA fA fB @[rocq_alias fixpoint_A_unfold] -theorem fixpointA_unfold [COFE α] [COFE β] [Inhabited α] [Inhabited β] +theorem fixpointA_unfold [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) : fA (fixpointA fA fB) (fixpointB fA fB) = (fixpointA fA fB) := by exact .symm (fixpoint_unfold _) @[rocq_alias fixpoint_B_unfold] -theorem fixpointB_unfold [COFE α] [COFE β] [Inhabited α] [Inhabited β] +theorem fixpointB_unfold [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) : fB (fixpointA fA fB) (fixpointB fA fB) = (fixpointB fA fB) := by exact .symm (fixpoint_unfold _) @[rocq_alias fixpoint_A_unique] -theorem fixpointA_unique [COFE α] [COFE β] [Inhabited α] [Inhabited β] +theorem fixpointA_unique [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) (Hp : fA p q = p) (Hq : fB p q = q) : p = (fixpointA fA fB) := fixpoint_unique <| Hp.symm.trans <| congrArg (fA p) (fixpoint_unique Hq.symm) @[rocq_alias fixpoint_B_unique] -theorem fixpointB_unique [COFE α] [COFE β] [Inhabited α] [Inhabited β] +theorem fixpointB_unique [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) (Hp : fA p q = p) (Hq : fB p q = q) : q = (fixpointB fA fB) := by apply fixpoint_unique exact Hq.symm.trans (congrArg (fun z => fB z q) (fixpointA_unique fA fB Hp Hq)) @[rocq_alias fixpoint_A_ne] -instance fixpointA_ne [COFE α] [COFE β] [Inhabited α] [Inhabited β] : +instance fixpointA_ne [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] : NonExpansive₂ (fixpointA (α := α) (β := β)) where ne n fA fA' HfA fB fB' HfB := by apply OFE.ContractiveHom.fixpoint_ne.ne @@ -1735,7 +1771,7 @@ instance fixpointA_ne [COFE α] [COFE β] [Inhabited α] [Inhabited β] : exact ContractiveHom.fixpoint_ne.ne (HfB z₁) @[rocq_alias fixpoint_B_ne] -instance fixpointB_ne [COFE α] [COFE β] [Inhabited α] [Inhabited β] : +instance fixpointB_ne [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] : NonExpansive₂ (fixpointB (α := α) (β := β)) where ne n fA fA' HfA fB fB' HfB := by apply ContractiveHom.fixpoint_ne.ne @@ -1747,11 +1783,13 @@ end FixpointAB section Later +variable [SIdx SI] + @[rocq_alias later] structure Later (A : Type u) : Type u where next :: car : A @[rocq_alias later_ofe_mixin] -instance isOFE_later [OFE A] : OFE (Later A) where +instance isOFE_later [OFE SI A] : OFE SI (Later A) where Dist n x y := DistLater n x.car y.car dist_eqv := ⟨fun _ => .rfl, .symm, .trans⟩ eq_dist {x y} := by @@ -1766,25 +1804,25 @@ instance isOFE_later [OFE A] : OFE (Later A) where @[rocq_alias Next_contractive] -instance NextContractive {A : Type _} [OFE A] : Contractive (@Later.next A) where +instance NextContractive {A : Type _} [OFE SI A] : Contractive (@Later.next A) where distLater_dist := id @[rocq_alias later_chain] -def laterChain [OFE A] (c : Chain (Later A)) : Chain A where +def laterChain [OFE SI A] (c : Chain (Later A)) : Chain A where chain n := (c (Nat.succ n)).car cauchy Hle := c.cauchy (Nat.succ_le_succ Hle) _ (Nat.lt_succ_self _) @[rocq_alias later_cofe] -instance isCOFE_later [OFE A] [IsCOFE A] : IsCOFE (Later A) where +instance isCOFE_later [OFE SI A] [IsCOFE SI A] : IsCOFE SI (Later A) where compl c := Later.next (IsCOFE.compl (laterChain c)) - conv_compl {n} c := by + conv_compl {n : SI} c := by rcases n with _|n' <;> simp [Dist, DistLater] intros m Hlt exact (IsCOFE.conv_compl (n := n') (c := laterChain c)).le (Nat.le_of_lt_succ Hlt) @[rocq_alias laterO_map] -def laterMap [OFE A] [OFE B] (f : A -n> B) : Later A -n> Later B := by +def laterMap [OFE SI A] [OFE SI B] (f : A -n> B) : Later A -n> Later B := by refine ⟨fun x => Later.next (f x.car), ⟨?_⟩⟩ rintro _ ⟨⟩ ⟨⟩ H <;> simp_all only [Dist, DistLater] intros m Hlt; exact f.ne.ne (H m Hlt) @@ -1799,13 +1837,15 @@ end Later section LaterOF open COFE -abbrev LaterOF (F : OFunctorPre) : OFunctorPre := +variable [SIdx SI] + +abbrev LaterOF (F : OFunctorPre SI) : OFunctorPre SI := fun A B _ _ => Later (F A B) -variable (F : OFunctorPre) +variable (F : OFunctorPre SI) @[rocq_alias laterOF] -instance instOFunctorLater [OFunctor F] : OFunctor (LaterOF F) where +instance instOFunctorLater [OFunctor SI F] : OFunctor SI (LaterOF F) where ofe := _ map f g := laterMap (OFunctor.map f g) map_ne.ne _ _ _ Hx _ _ Hy _ _ := (OFunctor.map_ne.ne Hx Hy _).lt @@ -1813,13 +1853,13 @@ instance instOFunctorLater [OFunctor F] : OFunctor (LaterOF F) where map_comp f g f' g' x := congrArg Later.next (OFunctor.map_comp f g f' g' x.car) @[rocq_alias laterOF_contractive] -instance instOFunctorContractiveLater [OFunctor F] : OFunctorContractive (LaterOF F) where +instance instOFunctorContractiveLater [OFunctor SI F] : OFunctorContractive SI (LaterOF F) where map_contractive.1 H _ _ hlt := OFunctor.map_ne.ne (DistLater.dist_lt H hlt).1 (DistLater.dist_lt H hlt).2 _ end LaterOF -theorem OFE.cast_dist [Iα : OFE α] [Iβ : OFE β] {x y : α} +theorem OFE.cast_dist [SIdx SI] [Iα : OFE SI α] [Iβ : OFE SI β] {x y : α} (Ht : α = β) (HIt : Iα = Ht ▸ Iβ) (H : x ≡{n}≡ y) : (Ht ▸ x) ≡{n}≡ (Ht ▸ y) := by subst Ht; subst HIt; exact H diff --git a/Iris/Iris/Algebra/StepIndexFinite.lean b/Iris/Iris/Algebra/StepIndexFinite.lean new file mode 100644 index 000000000..98b962a4a --- /dev/null +++ b/Iris/Iris/Algebra/StepIndexFinite.lean @@ -0,0 +1,66 @@ +/- +Copyright (c) 2026 Alvin Tang. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Alvin Tang +-/ +module + +public import Iris.Algebra.StepIndex +public import Iris.Algebra.OFE +public import Iris.Std.Classes +public meta import Iris.Std.RocqPorting + +@[expose] public section + +namespace Iris + +@[rocq_alias natSI, rocq_alias nat_sidx_mixin] +instance natSIdx : SIdx Nat where + toLT := instLTNat + toLE := instLENat + zero := 0 + succ := Nat.succ + lt_trans := Nat.lt_trans + lt_wf := Nat.lt_wfRel.wf + lt_trichotomyT n m := + if h : n < m then by left; exact h + else if he : n = m then by right; left; exact he + else by + right; right; apply Nat.lt_of_not_ge + change ¬n ≤ m + rw [Nat.le_iff_lt_or_eq] + intro h' + exact h'.elim h he + le_lteq {n m} := Nat.le_iff_lt_or_eq + not_lt_zero n := by simp + lt_succ_self n := by simp + succ_le_of_lt h := h + weak_case n := + match n with + | 0 => by right; intro m h; exact absurd h (Nat.not_lt_zero m) + | m + 1 => by left; constructor; rfl + +@[rocq_alias nat_sidx_finite] +instance natSIdxFinite : SIdxFinite Nat where + finite_index := by + intro n + cases n with + | zero => left; rfl + | succ n => right; exists n + +namespace OFE + +variable {α : Type _} [OFE Nat α] + +@[rocq_alias dist_le] +theorem Dist.le [OFE α] {m n} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := + if hm : m = n then hm ▸ h else h.lt (Nat.lt_of_le_of_ne h' hm) + +@[rocq_alias contractive_S] +theorem Contractive.succ [OFE α] [OFE β] (f : α → β) [Contractive f] {n x y} + (h : x ≡{n}≡ y) : f x ≡{n.succ}≡ f y := + Contractive.distLater_dist (distLater_succ.2 h) + +#rocq_ignore dist_S "Subsumed by `Dist.lt`/`Dist.le`." + +end OFE From 9e9cd3acdcd37ac904bc08cb292a2205f2592666 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Tue, 28 Jul 2026 11:56:38 +0200 Subject: [PATCH 02/33] Remove redundant change --- Iris/Iris/Algebra/OFE.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 9d0f48e60..1fce92cfc 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -30,7 +30,7 @@ class OFE (SI : outParam <| Type _) [SIdx SI] (α : Type _) where open OFE -scoped notation:40 x " ≡{" n "}≡ " y:41 => Dist n x y +scoped notation:40 x " ≡{" n "}≡ " y:41 => OFE.Dist n x y namespace OFE From acbccb8d034cddec6aa01db63bb289c0ba4584df Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 10:06:21 +0200 Subject: [PATCH 03/33] Update proofs in `OFE.lean` --- Iris/Iris/Algebra/OFE.lean | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 1fce92cfc..05b125faa 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -44,7 +44,7 @@ theorem Dist.lt [OFE SI α] {m n : SI} {x y : α} : x ≡{n}≡ y → m < n → @[rocq_alias dist_le] theorem Dist.le [OFE SI α] {m n : SI} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := - if hm : m = n then hm ▸ h else h.lt (Nat.lt_of_le_of_ne h' hm) + if hm : m = n then hm ▸ h else h.lt (SIdx.le_neq.mpr ⟨h', hm⟩) #rocq_ignore dist_le' "Use Dist.le" #rocq_ignore dist_S "Subsumed by `Dist.lt`/`Dist.le`." @@ -123,7 +123,7 @@ theorem DistLater.dist_lt [OFE SI α] {m n : SI} {x y : α} (h : DistLater n x y /-- `DistLater n`-equivalence is equivalent to `(n + 1)`-equivalence. -/ @[rocq_alias dist_later_S] theorem distLater_succ [OFE SI α] {n : SI} {x y : α} : DistLater (SIdx.succ n) x y ↔ x ≡{n}≡ y := - ⟨(·.dist_lt (Nat.lt_succ_self _)), fun h1 _ h2 => h1.le (Nat.le_of_lt_succ h2)⟩ + ⟨(·.dist_lt (SIdx.lt_succ_self _)), fun h1 _ h2 => h1.le (SIdx.lt_succ_r.mp h2)⟩ theorem distLater_soundness [OFE SI α] {x y : α} (H : ∀ n, DistLater n x y → x ≡{n}≡ y) : x = y := by refine eq_dist.mpr fun n => ?_ @@ -184,7 +184,7 @@ theorem discreteE_eqv [OFE SI α] {x y : α} (h : x = y) : DiscreteE x ↔ Discr /-- For discrete OFEs, `n`-equivalence implies equivalence for any `n`. -/ @[rocq_alias discrete] theorem Discrete.discrete [OFE SI α] [Discrete α] {n : SI} {x y : α} (h : x ≡{n}≡ y) : x = y := - discrete_0 (h.le (Nat.zero_le _)) + discrete_0 (h.le SIdx.le_0_l) export OFE.Discrete (discrete) instance Discrete.toDiscreteE [OFE SI α] [Discrete α] (x : α) : DiscreteE x := ⟨discrete_0⟩ @@ -200,7 +200,7 @@ theorem Discrete.discrete_iff [OFE SI α] [Discrete α] (n) {x y : α} : x = y @[rocq_alias discrete_iff_0] theorem Discrete.discrete_iff_0 [OFE SI α] [Discrete α] (n) {x y : α} : x ≡{0}≡ y ↔ x ≡{n}≡ y := - ⟨discrete_n, fun h => h.le (Nat.zero_le _)⟩ + ⟨discrete_n, fun h => h.le SIdx.le_0_l⟩ #rocq_ignore boolO "Canonical Leibniz OFE on `bool`; Lean uses `ofDiscrete Bool`." #rocq_ignore natO "Canonical Leibniz OFE on `nat`; Lean uses `ofDiscrete Nat`." @@ -956,7 +956,7 @@ theorem chain_none_const [SIdx SI] [OFE SI V] {c : Chain (Option V)} (H : c n = c = Chain.const none := by rcases c with ⟨c, Hc⟩ congr 1; refine funext (fun k => ?_) - rcases Nat.le_or_ge n k with (Hnk|Hnk) + rcases SIdx.le_total (I := SI) with (Hnk|Hnk) · suffices c k ≡{n}≡ c n by cases _ : c k <;> simp_all exact Hc Hnk · suffices c k ≡{k}≡ c n by cases _ : c k <;> simp_all @@ -1054,7 +1054,7 @@ instance instIsCOFEOption [OFE SI α] [IsCOFE SI α] : IsCOFE SI (Option α) whe refine (some_dist_some.mpr conv_compl).trans ?_ dsimp only [Chain.map_apply] cases h2 : c.chain n with - | none => exact (h1 ▸ h2 ▸ c.cauchy (by omega : 0 ≤ n)).elim + | none => exact (h1 ▸ h2 ▸ c.cauchy SIdx.le_0_l).elim | some _ => rfl #rocq_ignore option_compl "Local Compl definition; folded into Lean's IsCOFE instance." @@ -1090,12 +1090,12 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : dsimp only [Chain.map_apply] cases h2 : c.chain n with | inl _ => simp - | inr _ => exact (h1 ▸ h2 ▸ c.cauchy (by omega : 0 ≤ n)).elim + | inr _ => exact (h1 ▸ h2 ▸ c.cauchy SIdx.le_0_l).elim | inr seed => refine (dist_inr conv_compl).trans ?_ dsimp only [Chain.map_apply] cases h2 : c.chain n with - | inl _ => exact (h1 ▸ h2 ▸ c.cauchy (by omega : 0 ≤ n)).elim + | inl _ => exact (h1 ▸ h2 ▸ c.cauchy SIdx.le_0_l).elim | inr _ => simp #rocq_ignore inl_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." #rocq_ignore inr_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." @@ -1103,7 +1103,7 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : @[rocq_alias sigT_chain_const_proj1] theorem Sigma.chain_const_proj1 {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] - (c : Chain (Sigma P)) n : (c n).fst = (c 0).fst := (c.cauchy (by omega : 0 ≤ n)).choose + (c : Chain (Sigma P)) n : (c n).fst = (c 0).fst := (c.cauchy SIdx.le_0_l).choose @[rocq_alias chain_map_snd] def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] (c : Chain (Sigma P)) : @@ -1218,7 +1218,7 @@ def optionChain (c : Chain (Option α)) (x : α) : Chain α := by instance isCOFE_option [IsCOFE SI α] : IsCOFE SI (Option α) where compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x) conv_compl {n : SI} c := by - have := c.cauchy (Nat.zero_le n); revert this + have := c.cauchy (SIdx.le_0_l (n := n)); revert this rcases c.chain 0 with _|x' <;> rcases e : c.chain n with _|y' <;> simp [Dist, Option.Forall₂] refine fun _ => OFE.dist_eqv.trans IsCOFE.conv_compl ?_ simp [optionChain, e] @@ -1795,8 +1795,8 @@ instance isOFE_later [OFE SI A] : OFE SI (Later A) where eq_dist {x y} := by obtain ⟨a⟩ := x; obtain ⟨b⟩ := y simp only [Later.next.injEq, eq_dist] - exact ⟨fun H n => (H n).distLater, fun H n => (H (n+1)).dist_lt (Nat.lt_succ_self n)⟩ - dist_lt Hxy Hmn _ Hkm := Hxy _ (Nat.lt_trans Hkm Hmn) + exact ⟨fun H n => (H n).distLater, fun H n => (H (SIdx.succ n)).dist_lt (SIdx.lt_succ_self n)⟩ + dist_lt Hxy Hmn _ Hkm := Hxy _ (SIdx.lt_trans Hkm Hmn) #rocq_ignore laterO "Use the later type" #rocq_ignore later_equiv "Local Equiv instance; folded into Lean's OFE (Later A) instance." @@ -1810,8 +1810,8 @@ instance NextContractive {A : Type _} [OFE SI A] : Contractive (@Later.next A) w @[rocq_alias later_chain] def laterChain [OFE SI A] (c : Chain (Later A)) : Chain A where - chain n := (c (Nat.succ n)).car - cauchy Hle := c.cauchy (Nat.succ_le_succ Hle) _ (Nat.lt_succ_self _) + chain n := (c (SIdx.succ n)).car + cauchy Hle := c.cauchy (SIdx.succ_le_mono.mp Hle) _ (SIdx.lt_succ_self _) @[rocq_alias later_cofe] instance isCOFE_later [OFE SI A] [IsCOFE SI A] : IsCOFE SI (Later A) where From 3d88a76b957e5db95a793ff733aa673cbb3edef7 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 10:25:43 +0200 Subject: [PATCH 04/33] More proof updates in `OFE.lean` --- Iris/Iris/Algebra/OFE.lean | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 05b125faa..52f21d29d 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -118,7 +118,8 @@ theorem DistLater.dist_lt [OFE SI α] {m n : SI} {x y : α} (h : DistLater n x y h _ hm /-- `DistLater 0`-equivalence is trivial. -/ -@[simp, rocq_alias dist_later_0] theorem distLater_zero [OFE SI α] {x y : α} : DistLater 0 x y := nofun +@[simp, rocq_alias dist_later_0] theorem distLater_zero [OFE SI α] {x y : α} : DistLater 0 x y := + fun m hm => absurd hm (SIdx.not_lt_zero m) /-- `DistLater n`-equivalence is equivalent to `(n + 1)`-equivalence. -/ @[rocq_alias dist_later_S] @@ -127,9 +128,8 @@ theorem distLater_succ [OFE SI α] {n : SI} {x y : α} : DistLater (SIdx.succ n) theorem distLater_soundness [OFE SI α] {x y : α} (H : ∀ n, DistLater n x y → x ≡{n}≡ y) : x = y := by refine eq_dist.mpr fun n => ?_ - induction n with - | zero => exact H 0 distLater_zero - | succ n IH => exact H (n + 1) (distLater_succ.mpr IH) + induction n using instSI.lt_wf.induction with + | _ n IH => exact H n IH /-- A function `f : α → β` is contractive if it sends `DistLater n`-equivalent inputs to `n`-equivalent outputs. -/ @@ -374,6 +374,7 @@ def unitOFE : OFE SI Unit where -- set_option trace.Meta.synthInstance true in instance : @DiscreteE SI _ Unit unitOFE (() : Unit) := + letI := unitOFE ⟨fun _ => Subsingleton.elim _ _⟩ instance [OFE SI α] : OFE SI (ULift α) where @@ -741,7 +742,7 @@ instance [OFE SI α] (P : α → Prop) : OFE SI (Subtype P) where @[rocq_alias sig_discrete] instance [OFE SI α] [Discrete α] (P : α → Prop) : Discrete (Subtype P) where - discrete_0 h := Subtype.ext (@Discrete.discrete_0 α _ _ _ _ h) + discrete_0 h := Subtype.ext <| Discrete.discrete_0 (α := α) h @[rocq_alias proj1_sig_ne] instance [OFE SI α] (P : α → Prop) : NonExpansive (Subtype.val : Subtype P → α) where @@ -1024,7 +1025,7 @@ theorem compl_const [COFE SI α] (a : α) : compl (Chain.const a) = a := def ofDiscrete (α : Type _) : COFE SI α := let _ := OFE.ofDiscrete α { compl := fun c => c 0 - conv_compl := fun {n c} => (c.cauchy (Nat.zero_le n)).symm } + conv_compl := fun {_ c} => (c.cauchy SIdx.le_0_l).symm } instance [COFE SI α] : COFE SI (ULift α) where compl c := ⟨compl (c.map uliftDownHom)⟩ @@ -1049,7 +1050,7 @@ instance instIsCOFEOption [OFE SI α] [IsCOFE SI α] : IsCOFE SI (Option α) whe cases h1 : c.chain 0 with | none => refine Eq.dist <| Option.none_is_discrete.discrete ?_ - exact h1 ▸ c.cauchy (Nat.zero_le n) |>.symm + exact h1 ▸ c.cauchy (SIdx.le_0_l (n := n)) |>.symm | some seed => refine (some_dist_some.mpr conv_compl).trans ?_ dsimp only [Chain.map_apply] @@ -1525,10 +1526,7 @@ instance instOFunctorContractiveHomOF [OFunctorContractive SI F1] [OFunctorContr map_contractive.1 {n : SI} ab ab' h := match ab, ab' with | ⟨a, b⟩, ⟨a', b'⟩ => by simp only [Function.uncurry_apply_pair, OFunctor.map] - have h' : DistLater n (b, a) (b', a') := - match n with - | 0 => distLater_zero - | _ + 1 => distLater_succ.mpr ⟨(distLater_succ.mp h).2, (distLater_succ.mp h).1⟩ + have h' : DistLater n (b, a) (b', a') := fun m hm => ⟨(h m hm).2, (h m hm).1⟩ refine NonExpansive₂.ne ?_ ?_ · exact (map_contractive (F := F1)).1 h' · exact (map_contractive (F := F2)).1 h From ee7e8cf26fbd54f96149e222a558cd46234b16a0 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 10:46:44 +0200 Subject: [PATCH 05/33] Update proof of `isCOFE_later` --- Iris/Iris/Algebra/OFE.lean | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 52f21d29d..c5a0185ed 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1815,9 +1815,10 @@ def laterChain [OFE SI A] (c : Chain (Later A)) : Chain A where instance isCOFE_later [OFE SI A] [IsCOFE SI A] : IsCOFE SI (Later A) where compl c := Later.next (IsCOFE.compl (laterChain c)) conv_compl {n : SI} c := by - rcases n with _|n' <;> simp [Dist, DistLater] + simp [Dist, DistLater] intros m Hlt - exact (IsCOFE.conv_compl (n := n') (c := laterChain c)).le (Nat.le_of_lt_succ Hlt) + refine (IsCOFE.conv_compl (n := m) (c := laterChain c)).trans ?_ + exact ((c.cauchy <| SIdx.succ_le_of_lt Hlt) m (SIdx.lt_succ_self m)).symm @[rocq_alias laterO_map] def laterMap [OFE SI A] [OFE SI B] (f : A -n> B) : Later A -n> Later B := by From f5e71e5797a527b0b6420c7fedc8d895d5f7007d Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 10:51:11 +0200 Subject: [PATCH 06/33] Update proof for `DiscreteO.dist_inj` --- Iris/Iris/Algebra/OFE.lean | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index c5a0185ed..edcab55e8 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1176,10 +1176,9 @@ theorem DiscreteO.eqv_inj {x y : α} (H : DiscreteO.mk x = DiscreteO.mk y) : x = congrArg DiscreteO.car H theorem DiscreteO.dist_inj [SIdx SI] {α : Type _} {x y : α} {n : SI} : - letI := DiscreteO.instCOFE (SI := SI) (α := α) - DiscreteO.mk x ≡{n}≡ DiscreteO.mk y → x = y := by - letI := DiscreteO.instCOFE (SI := SI) (α := α) - exact DiscreteO.eqv_inj <| discrete H + letI := DiscreteO.instCOFE (α := α) + DiscreteO.mk x ≡{n}≡ DiscreteO.mk y → x = y := + fun H => DiscreteO.eqv_inj H section DiscreteFunOF open COFE From 2feacf255695d662abcea39d60d287dd70aa1b36 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 10:56:52 +0200 Subject: [PATCH 07/33] Update proofs that involve `letI`/`haveI` --- Iris/Iris/Algebra/OFE.lean | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index edcab55e8..4e5a2d52c 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1032,13 +1032,15 @@ instance [COFE SI α] : COFE SI (ULift α) where conv_compl := conv_compl @[rocq_alias unit_ofe_discrete] -instance : @Discrete SI _ Unit unitOFE where - discrete_0 _ := Subsingleton.elim _ _ +instance : @Discrete SI _ Unit unitOFE := + letI := unitOFE + { discrete_0 _ := Subsingleton.elim _ _ } @[reducible, rocq_alias unit_cofe] -def unitCOFE [SIdx SI] : @COFE SI _ Unit where - compl _ := () - conv_compl := ⟨⟩ +def unitCOFE [SIdx SI] : COFE SI Unit := + letI := unitOFE + { compl _ := () + conv_compl := ⟨⟩ } abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun (SI := SI) β] := ∀ x : α, IsCOFE SI (β x) @@ -1165,10 +1167,10 @@ end COFE @[reducible] def DiscreteO.instCOFE [SIdx SI] {α : Type _} : COFE SI (DiscreteO α) := COFE.ofDiscrete _ -@[reducible] -def DiscreteO.OFE [SIdx SI] {α : Type _} : +theorem DiscreteO.OFE [SIdx SI] {α : Type _} : @OFE.Discrete SI _ (DiscreteO α) (OFE.ofDiscrete _) := - ⟨fun h => h⟩ + letI := OFE.ofDiscrete + ⟨id⟩ #rocq_ignore leibnizO_leibniz "Not needed" From f59dcf04e7fc9930292b946febf8fd6654d1632a Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 11:07:32 +0200 Subject: [PATCH 08/33] Two more minor proof updates --- Iris/Iris/Algebra/OFE.lean | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 4e5a2d52c..bca4ad138 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1566,7 +1566,7 @@ theorem LimitPreserving.impl [COFE SI α] (P1 P2 : α → Prop) (HP1 : ∀ {x y : α}, x ≡{0}≡ y → P1 x → P1 y) (Hcompl : LimitPreserving P2) : LimitPreserving (fun x => P1 x → P2 x) := - fun _ Hc HP1c => Hcompl _ <| fun n => Hc _ (HP1 (COFE.conv_compl' (Nat.zero_le n)) HP1c) + fun _ Hc HP1c => Hcompl _ <| fun _ => Hc _ (HP1 (COFE.conv_compl' SIdx.le_0_l) HP1c) @[rocq_alias limit_preserving_equiv] theorem LimitPreserving.equiv [COFE SI α] [COFE SI β] (f g : α -n> β) : @@ -1574,7 +1574,7 @@ theorem LimitPreserving.equiv [COFE SI α] [COFE SI β] (f g : α -n> β) : intro c Hfg refine eq_dist.mpr fun n => ?_ apply (COFE.compl_map _ _).symm.dist.trans - apply (COFE.conv_compl' (Nat.le_refl n)).trans + apply (COFE.conv_compl' SIdx.le_refl).trans apply (Hfg _).dist.trans exact g.ne.ne COFE.conv_compl.symm From a6baad5b3881a048a8528458fac3245a3b7b9063 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 14:57:58 +0200 Subject: [PATCH 09/33] Port `bchain` as `BChain` --- Iris/Iris/Algebra/OFE.lean | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index bca4ad138..8a402952e 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -986,6 +986,28 @@ theorem chain_option_some [SIdx SI] [OFE SI V] {c : Chain (Option V)} (H : c n = rw [← Hchoose] simp [hcc] +@[rocq_alias bchain] +structure BChain (α : Type _) [SIdx SI] [OFE SI α] (n : SI) where + bchain m : m < n → α + bcauchy {m p} (hm : m < n) (hp : p < n) (h : m ≤ p) : bchain p hp ≡{m}≡ bchain m hm + +namespace BChain +variable [SIdx SI] [OFE SI α] [OFE SI β] + +def map (f : α -n> β) {n : SI} (c : BChain α n) : BChain β n where + bchain m hm := f <| c.bchain m hm + bcauchy hm hp h := f.ne.ne <| c.bcauchy hm hp h + +def const (a : α) (n : SI) : BChain α n where + bchain _ _ := a + bcauchy _ _ _ := .rfl + +def le {n : SI} (c : BChain α n) {m : SI} (hm : m ≤ n) : BChain α m where + bchain m' hm' := c.bchain m' (SIdx.lt_le_trans hm' hm) + bcauchy _ _ h := c.bcauchy _ _ h + +end BChain + /-- Complete ordered family of equivalences -/ @[rocq_alias Cofe] class IsCOFE (SI : outParam <| Type _) (α : Type _) [SIdx SI] [OFE SI α] where From d5ae9fd3c35167b6e900eaf145ff56657837820f Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 15:22:59 +0200 Subject: [PATCH 10/33] Extend `IsCOFE` with bounded completion fields, proofs of `IsCOFE` instances not yet complete --- Iris/Iris/Algebra/OFE.lean | 53 ++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 8a402952e..eff2262d0 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1013,6 +1013,12 @@ end BChain class IsCOFE (SI : outParam <| Type _) (α : Type _) [SIdx SI] [OFE SI α] where compl : Chain α → α conv_compl {c : Chain α} : compl c ≡{n}≡ c n + lbcompl {n : SI} : SIdx.Limit n → BChain α n → α + conv_lbcompl {n : SI} (Hn : SIdx.Limit n) (c : BChain α n) {m} (hm : m < n) : + lbcompl Hn c ≡{m}≡ c.bchain m hm + lbcompl_ne {n : SI} (hn : SIdx.Limit n) (c1 c2 : BChain α n) {m : SI} : + (∀ p (Hp : p < n), c1.bchain p Hp ≡{m}≡ c2.bchain p Hp) → + lbcompl hn c1 ≡{m}≡ lbcompl hn c2 /-- Complete ordered family of equivalences -/ class abbrev COFE (SI : outParam <| Type _) [SIdx SI] (α : Type _) := OFE SI α, IsCOFE SI α @@ -1045,13 +1051,21 @@ theorem compl_const [COFE SI α] (a : α) : compl (Chain.const a) = a := /-- The discrete COFE obtained from an equivalence relation `Equiv` -/ @[reducible, rocq_alias discrete_cofe] def ofDiscrete (α : Type _) : COFE SI α := - let _ := OFE.ofDiscrete α - { compl := fun c => c 0 - conv_compl := fun {_ c} => (c.cauchy SIdx.le_0_l).symm } + letI := OFE.ofDiscrete α + { + compl := fun c => c 0 + conv_compl := fun {_ c} => (c.cauchy SIdx.le_0_l).symm + lbcompl := fun hn c => c.bchain 0 hn.limit_lt_0 + conv_lbcompl := fun hn c _ hm => (c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).symm + lbcompl_ne := fun hn _ _ _ hc => hc 0 hn.limit_lt_0 + } instance [COFE SI α] : COFE SI (ULift α) where compl c := ⟨compl (c.map uliftDownHom)⟩ conv_compl := conv_compl + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry @[rocq_alias unit_ofe_discrete] instance : @Discrete SI _ Unit unitOFE := @@ -1061,8 +1075,13 @@ instance : @Discrete SI _ Unit unitOFE := @[reducible, rocq_alias unit_cofe] def unitCOFE [SIdx SI] : COFE SI Unit := letI := unitOFE - { compl _ := () - conv_compl := ⟨⟩ } + { + compl _ := () + conv_compl := ⟨⟩ + lbcompl := fun _ _ => () + conv_lbcompl := sorry + lbcompl_ne := sorry + } abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun (SI := SI) β] := ∀ x : α, IsCOFE SI (β x) @@ -1081,12 +1100,18 @@ instance instIsCOFEOption [OFE SI α] [IsCOFE SI α] : IsCOFE SI (Option α) whe cases h2 : c.chain n with | none => exact (h1 ▸ h2 ▸ c.cauchy SIdx.le_0_l).elim | some _ => rfl + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore option_compl "Local Compl definition; folded into Lean's IsCOFE instance." @[rocq_alias discrete_fun_cofe] instance {α : Type _} (β : α → Type _) [∀ x, COFE SI (β x)] : COFE SI ((x : α) → β x) where compl c x := compl (c.map (applyHom x)) conv_compl _ := IsCOFE.conv_compl + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore discrete_fun_chain "Local helper; folded into Lean's IsCOFE instance." @[rocq_alias ofe_mor_cofe] @@ -1096,12 +1121,18 @@ instance instIsCOFEHom [OFE SI α] [OFE SI β] [IsCOFE SI β] : IsCOFE SI (α -n refine conv_compl.trans (.trans ?_ conv_compl.symm) exact NonExpansive.ne (f := c.chain n) H conv_compl _ := IsCOFE.conv_compl + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore ofe_mor_compl "Inlined in IsCOFE instance" @[rocq_alias prod_cofe] instance instIsCOFEProd [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : IsCOFE SI (α × β) where compl c := ⟨compl (c.map ⟨Prod.fst, inferInstance⟩), compl (c.map ⟨Prod.snd, inferInstance⟩)⟩ conv_compl := ⟨conv_compl, conv_compl⟩ + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry @[rocq_alias sum_cofe] instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : IsCOFE SI (α ⊕ β) where @@ -1122,6 +1153,9 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : cases h2 : c.chain n with | inl _ => exact (h1 ▸ h2 ▸ c.cauchy SIdx.le_0_l).elim | inr _ => simp + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore inl_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." #rocq_ignore inr_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." #rocq_ignore sum_compl "Local Compl definition; folded into Lean's IsCOFE instance." @@ -1155,6 +1189,9 @@ instance {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] : Is revert heq; cases c.chain n rintro ⟨⟩ hequiv exact hequiv + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore sigT_compl "Local Compl definition; folded into Lean's IsCOFE instance." set_option linter.checkUnivs false in @@ -1246,6 +1283,9 @@ instance isCOFE_option [IsCOFE SI α] : IsCOFE SI (Option α) where rcases c.chain 0 with _|x' <;> rcases e : c.chain n with _|y' <;> simp [Dist, Option.Forall₂] refine fun _ => OFE.dist_eqv.trans IsCOFE.conv_compl ?_ simp [optionChain, e] + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry @[rocq_alias optionO_map] def optionMap {α β : Type _} [OFE SI α] [OFE SI β] (f : α -n> β) : Option α -n> Option β := by @@ -1842,6 +1882,9 @@ instance isCOFE_later [OFE SI A] [IsCOFE SI A] : IsCOFE SI (Later A) where intros m Hlt refine (IsCOFE.conv_compl (n := m) (c := laterChain c)).trans ?_ exact ((c.cauchy <| SIdx.succ_le_of_lt Hlt) m (SIdx.lt_succ_self m)).symm + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry @[rocq_alias laterO_map] def laterMap [OFE SI A] [OFE SI B] (f : A -n> B) : Later A -n> Later B := by From 858fb80c9504f1e4fb6ad451be88c8270411c20a Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 15:32:28 +0200 Subject: [PATCH 11/33] Port `bcompl`-related theorems, proofs not complete --- Iris/Iris/Algebra/OFE.lean | 61 ++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 15 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index eff2262d0..cdf2fdfa0 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -5,7 +5,7 @@ Authors: Mario Carneiro, Sebastian Graf, Sergei Stepanenko -/ module -public meta import Iris.Algebra.StepIndex +public import Iris.Algebra.StepIndex public meta import Iris.Std.RocqPorting @[expose] public section @@ -1601,48 +1601,79 @@ section Fixpoint variable [SIdx SI] @[rocq_alias LimitPreserving] -def LimitPreserving [COFE SI α] (P : α → Prop) : Prop := - ∀ (c : Chain α), (∀ n, P (c n)) → P (COFE.compl c) +structure LimitPreserving [COFE SI α] (P : α → Prop) : Prop where + compl (c : Chain α) : (∀ n, P (c n)) → P (COFE.compl c) + lbcompl {n : SI} (hn : SIdx.Limit n) (c : BChain α n) : + (∀ m (hm : m < n), P (c.bchain m hm)) → P (IsCOFE.lbcompl hn c) @[rocq_alias limit_preserving_const] theorem LimitPreserving.const [COFE SI α] {P : Prop} : LimitPreserving fun (_ : α) => P := by - simp [LimitPreserving] + sorry -- simp [LimitPreserving] @[rocq_alias limit_preserving_discrete] theorem LimitPreserving.discrete [COFE SI α] {P : α → Prop} : (∀ {x y : α}, x ≡{0}≡ y → (P x → P y)) → LimitPreserving P := - fun Hdisc _ H => Hdisc COFE.conv_compl.symm (H _) + sorry -- fun Hdisc _ H => Hdisc COFE.conv_compl.symm (H _) @[rocq_alias limit_preserving_and] theorem LimitPreserving.and [COFE SI α] {P Q : α → Prop} (HP : LimitPreserving P) (HQ : LimitPreserving Q) : LimitPreserving fun a => P a ∧ Q a := - fun _ HPQ => ⟨HP _ (fun n => (HPQ n).left), HQ _ (fun n => (HPQ n).right)⟩ + sorry -- fun _ HPQ => ⟨HP _ (fun n => (HPQ n).left), HQ _ (fun n => (HPQ n).right)⟩ @[rocq_alias limit_preserving_forall] theorem LimitPreserving.forall [COFE SI α] (P : β → α → Prop) (Hlim : ∀ y, LimitPreserving (P y)) : LimitPreserving (∀ y, P y ·) := - fun c H y => Hlim y c (H · y) + sorry -- fun c H y => Hlim y c (H · y) @[rocq_alias limit_preserving_impl] theorem LimitPreserving.impl [COFE SI α] (P1 P2 : α → Prop) (HP1 : ∀ {x y : α}, x ≡{0}≡ y → P1 x → P1 y) (Hcompl : LimitPreserving P2) : LimitPreserving (fun x => P1 x → P2 x) := - fun _ Hc HP1c => Hcompl _ <| fun _ => Hc _ (HP1 (COFE.conv_compl' SIdx.le_0_l) HP1c) + sorry -- fun _ Hc HP1c => Hcompl _ <| fun _ => Hc _ (HP1 (COFE.conv_compl' SIdx.le_0_l) HP1c) @[rocq_alias limit_preserving_equiv] theorem LimitPreserving.equiv [COFE SI α] [COFE SI β] (f g : α -n> β) : LimitPreserving (fun x => f x = g x) := by - intro c Hfg - refine eq_dist.mpr fun n => ?_ - apply (COFE.compl_map _ _).symm.dist.trans - apply (COFE.conv_compl' SIdx.le_refl).trans - apply (Hfg _).dist.trans - exact g.ne.ne COFE.conv_compl.symm + sorry + -- intro c Hfg + -- refine eq_dist.mpr fun n => ?_ + -- apply (COFE.compl_map _ _).symm.dist.trans + -- apply (COFE.conv_compl' SIdx.le_refl).trans + -- apply (Hfg _).dist.trans + -- exact g.ne.ne COFE.conv_compl.symm @[rocq_alias limit_preserving_ext] theorem LimitPreserving.ext {α} [COFE SI α] {P Q : α -> Prop} (he : ∀ {x}, (P x ↔ Q x)) - (hp : LimitPreserving P) : LimitPreserving Q := fun _ => (he.1 <| hp _ <| fun _ => he.2 <| · _) + (hp : LimitPreserving P) : LimitPreserving Q := + sorry -- fun _ => (he.1 <| hp _ <| fun _ => he.2 <| · _) + +section BCompl + +variable [SIdx SI] [COFE SI α] [Inhabited α] + +@[rocq_alias bcompl] +def bcompl (n : SI) (c : BChain α n) : α := + match SIdx.case n with + | .inl _ => default + | .inr (.inl ⟨m, hm⟩) => c.bchain m (SIdx.lt_succ_diag_r' hm) + | .inr (.inr hlim) => IsCOFE.lbcompl hlim c + +@[rocq_alias conv_bcompl] +theorem conv_bcompl {n : SI} (c : BChain α n) {m} (hm : m < n) : + bcompl n c ≡{m}≡ c.bchain m hm := sorry + +@[rocq_alias bcompl_ne] +theorem bcompl_ne {n : SI} (c1 c2 : BChain α n) {m : SI} + (Hc : ∀ p (hp : p < n), c1.bchain p hp ≡{m}≡ c2.bchain p hp) : + bcompl n c1 ≡{m}≡ bcompl n c2 := sorry + +@[rocq_alias limit_preserving_bcompl] +theorem LimitPreserving.bcompl {P : α → Prop} (n : SI) (c : BChain α n) + (H0 : n ≠ 0 ∨ P default) (HP : LimitPreserving P) + (Hc : ∀ m (hm : m < n), P (c.bchain m hm)) : P (bcompl n c) := sorry + +end BCompl def Fixpoint.chain [OFE SI α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where chain n := Nat.repeat f (n + 1) default From 3efce59e69b746e564be7a9b38d6d1f5b978e9a5 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 15:46:58 +0200 Subject: [PATCH 12/33] Introduce `BFChain` definitions with `sorry` for proofs Replace all proofs in section `Fixpoint`, all requires rewrite --- Iris/Iris/Algebra/OFE.lean | 75 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index cdf2fdfa0..21758dc62 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1675,15 +1675,39 @@ theorem LimitPreserving.bcompl {P : α → Prop} (n : SI) (c : BChain α n) end BCompl -def Fixpoint.chain [OFE SI α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where - chain n := Nat.repeat f (n + 1) default - cauchy {n : SI} := by - induction n with simp [Nat.repeat] | succ n IH - rintro (_|i) <;> simp - intro H - apply Contractive.distLater_dist - intro _ Hm - exact (IH H).le (Nat.le_of_lt_succ Hm) +section BFChain + +variable [instSI : SIdx SI] [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] + +@[rocq_alias bfchain] +structure BFChain (n : SI) where + car : BChain α n + fixpoint : ∀ p, p < n → f (bcompl n car) ≡{p}≡ bcompl n car + +@[rocq_alias bfchain_chain_unique] +theorem BFChain.unique {n m : SI} (c1 : BFChain f n) (c2 : BFChain f m) : + ∀ p, p < n → p < m → bcompl n c1.car ≡{p}≡ bcompl m c2.car := sorry + +@[rocq_alias fixpoint_bchain_go] +def BFChain.go (n : SI) (rec : ∀ m, m < n → BFChain f m) : BFChain f n where + car := + { bchain := fun m Hm => f (bcompl m (rec m Hm).car) + bcauchy := fun {m p} Hm Hp Hmp => + Contractive.distLater_dist fun q Hq => + BFChain.unique f (rec p Hp) (rec m Hm) q (SIdx.lt_le_trans Hq Hmp) Hq } + fixpoint p Hp := sorry + +def fixpointBFChain (n : SI) : BFChain f n := instSI.lt_wf.fix (BFChain.go f) n + +theorem fixpointBFChain_unfold (n : SI) : + fixpointBFChain f n = BFChain.go f n (fun m _ => fixpointBFChain f m) := + sorry + +end BFChain + +def Fixpoint.chain [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where + chain n := f (bcompl n (fixpointBFChain f n).car) + cauchy {n i : SI} H := sorry /-- The chain construction of the Banach fixpoint. `fixpointP` packages it, together with its unfolding equation, behind an opaque constant. -/ @@ -1695,9 +1719,7 @@ theorem fixpointAux_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : refine eq_dist.mpr fun n => ?_ apply COFE.conv_compl.trans refine .trans ?_ (NonExpansive.ne COFE.conv_compl.symm) - induction n with - | zero => exact Contractive.zero f.f - | succ _ IH => exact (Contractive.succ f.f IH.symm).symm + sorry /-- The Banach fixpoint packed together with its unfolding equation as a single opaque value. Being opaque, it is a stuck constant for definitional-equality checks in both the @@ -1724,43 +1746,20 @@ theorem fixpoint_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : theorem fixpoint_unique [COFE SI α] [Inhabited α] {f : α -c> α} {x : α} (H : x = f x) : x = fixpoint f := by refine eq_dist.mpr fun n => ?_ - induction n with refine H.dist.trans <| .trans ?_ (fixpoint_unfold f).dist.symm - | zero => exact Contractive.zero f.f - | succ _ IH => exact Contractive.succ f.f IH + sorry @[rocq_alias fixpoint_ne] instance OFE.ContractiveHom.fixpoint_ne [COFE SI α] [Inhabited α] : NonExpansive (ContractiveHom.fixpoint (α := α)) where ne n f1 f2 H := by - induction n with - refine (fixpoint_unfold f1).dist.trans <| - ((H _).trans ?_).trans (fixpoint_unfold f2).dist.symm - | zero => exact Contractive.zero f2.f - | succ _ IH => exact Contractive.succ f2.f <| IH <| Dist.lt H (Nat.lt_add_one _) + sorry @[elab_as_elim, rocq_alias fixpoint_ind] theorem OFE.ContractiveHom.fixpoint_ind [COFE SI α] [Inhabited α] (f : α -c> α) (P : α → Prop) (HProper : ∀ A B : α, A = B → P A → P B) (x : α) (Hbase : P x) (Hind : ∀ x, P x → P (f x)) (Hlim : LimitPreserving P) : P f.fixpoint := by - let chain : Chain α := by - refine ⟨fun i => Nat.repeat f (i + 1) x, fun {n i} H => ?_⟩ - induction n generalizing i with - | zero => simp [Nat.repeat] - | succ _ IH => - cases i <;> simp at H - exact Contractive.succ _ <| IH H - refine HProper _ _ (fixpoint_unique (f := f) (x := COFE.compl chain) ?_) ?_ - · refine eq_dist.mpr fun n => ?_ - apply COFE.conv_compl.trans - refine .trans ?_ (f.ne.ne COFE.conv_compl).symm - induction n - · exact Contractive.zero f.f - · rename_i IH; apply Contractive.succ _ IH - · apply Hlim; intro n - induction n with - | zero => exact Hind (Nat.repeat f.f 0 x) Hbase - | succ _ IH => apply Hind (Nat.repeat f.f _ x) IH + sorry end Fixpoint From b7565a944f5e6707f523d35c91dd4ed069dd369f Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 15:50:14 +0200 Subject: [PATCH 13/33] Fix `StepIndexFinite.lean`: `Nat`-specific formulations of `Dist.le` and `Contractive.succ` --- Iris/Iris/Algebra/StepIndexFinite.lean | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Iris/Iris/Algebra/StepIndexFinite.lean b/Iris/Iris/Algebra/StepIndexFinite.lean index 98b962a4a..4bb619e77 100644 --- a/Iris/Iris/Algebra/StepIndexFinite.lean +++ b/Iris/Iris/Algebra/StepIndexFinite.lean @@ -50,17 +50,11 @@ instance natSIdxFinite : SIdxFinite Nat where namespace OFE -variable {α : Type _} [OFE Nat α] +theorem Dist.leNat [OFE Nat α] {m n} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := + if hm : m = n then hm ▸ h else h.lt <| Nat.lt_of_le_of_ne h' hm -@[rocq_alias dist_le] -theorem Dist.le [OFE α] {m n} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := - if hm : m = n then hm ▸ h else h.lt (Nat.lt_of_le_of_ne h' hm) - -@[rocq_alias contractive_S] -theorem Contractive.succ [OFE α] [OFE β] (f : α → β) [Contractive f] {n x y} +theorem Contractive.succNat [OFE Nat α] [OFE Nat β] (f : α → β) [Contractive f] {n x y} (h : x ≡{n}≡ y) : f x ≡{n.succ}≡ f y := - Contractive.distLater_dist (distLater_succ.2 h) - -#rocq_ignore dist_S "Subsumed by `Dist.lt`/`Dist.le`." + Contractive.distLater_dist <| distLater_succ.mpr h end OFE From a952ca9dcf94e77bd760ce7bd52b6deed3c91f6e Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 16:22:40 +0200 Subject: [PATCH 14/33] =?UTF-8?q?`CMRA.lean`:=20`CMRA=20=CE=B1`=20extends?= =?UTF-8?q?=20`OFE=20Nat=20=CE=B1`=20Parametrisation=20of=20`CMRA`=20to=20?= =?UTF-8?q?be=20done=20in=20a=20future=20PR?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Iris/Iris/Algebra/CMRA.lean | 98 ++++++++++++++++++----------------- Iris/Iris/Algebra/Monoid.lean | 10 ++-- 2 files changed, 57 insertions(+), 51 deletions(-) diff --git a/Iris/Iris/Algebra/CMRA.lean b/Iris/Iris/Algebra/CMRA.lean index cf238df17..b14a1bcfa 100644 --- a/Iris/Iris/Algebra/CMRA.lean +++ b/Iris/Iris/Algebra/CMRA.lean @@ -7,6 +7,7 @@ module public import Iris.Algebra.OFE public import Iris.Algebra.Monoid +public import Iris.Algebra.StepIndexFinite meta import Iris.Std.RocqPorting @[expose] public section @@ -15,7 +16,7 @@ namespace Iris open OFE @[rocq_alias cmra] -class CMRA (α : Type _) extends OFE α where +class CMRA (α : Type _) extends OFE Nat α where pcore : α → Option α op : α → α → α ValidN : Nat → α → Prop @@ -49,7 +50,7 @@ class CMRA (α : Type _) extends OFE α where #rocq_ignore cmra_ofeO "Not needed." /-- Reduction of `pcore_op_mono` to regular monotonicity -/ -theorem pcore_op_mono_of_core_op_mono [OFE α] (op : α → α → α) (pcore : α → Option α) +theorem pcore_op_mono_of_core_op_mono [OFE Nat α] (op : α → α → α) (pcore : α → Option α) (h : (∀ x cx y : α, (∃ z, y = op x z) → pcore x = some cx → ∃ cy, pcore y = some cy ∧ ∃ z, cy = op cx z)) (x cx) (e : pcore x = some cx) (y) : ∃ cy, pcore (op x y) = some (op cx cy) := @@ -759,11 +760,11 @@ variable {α : Type _} [CMRA α] theorem IdFree.of_dist {x₁ x₂ : α} {n} (e : x₁ ≡{n}≡ x₂) (h : IdFree x₁) : IdFree x₂ where id_free0_r z v := fun h₂ => - have ee := Dist.le e (Nat.zero_le _) + have ee := Dist.le e (SIdx.le_0_l) have := calc - x₁ • z ≡{0}≡ x₂ • z := op_left_dist z ee + x₁ • z ≡{(0 : Nat)}≡ x₂ • z := op_left_dist z ee _ ≡{0}≡ x₂ := h₂ - _ ≡{0}≡ x₁ := ee.symm + _ ≡{(0 : Nat)}≡ x₁ := ee.symm h.id_free0_r _ ((validN_dist_iff ee).mpr v) this theorem _root_.Iris.OFE.Dist.idFree {x₁ x₂ : α} (e : x₁ ≡{n}≡ x₂) : IdFree x₁ ↔ IdFree x₂ := @@ -773,7 +774,7 @@ theorem _root_.Iris.OFE.Dist.idFree {x₁ x₂ : α} (e : x₁ ≡{n}≡ x₂) : @[rocq_alias id_freeN_r] theorem id_freeN_r {n n'} {x : α} [IdFree x] {y} (v : ✓{n} x) : ¬(x • y ≡{n'}≡ x) := - id_free0_r _ (validN_of_le (Nat.zero_le _) v) |>.imp (·.le (Nat.zero_le _)) + id_free0_r _ (validN_of_le (SIdx.le_0_l) v) |>.imp (·.le (SIdx.le_0_l)) @[rocq_alias id_freeN_l] theorem id_freeN_l {n n'} {x : α} [IdFree x] {y} (v : ✓{n} x) : ¬(y • x ≡{n'}≡ x) := @@ -953,7 +954,7 @@ infixr:25 " -C> " => Hom instance [CMRA β] : CoeFun (α -C> β) (fun _ => α → β) := ⟨fun F => F.f⟩ -instance [CMRA β] : OFE (α -C> β) where +instance [CMRA β] : OFE Nat (α -C> β) where Dist n f g := f.toHom ≡{n}≡ g.toHom dist_eqv := { refl _ := dist_eqv.refl _ @@ -1004,27 +1005,27 @@ end CMRA section rFunctor @[rocq_alias rFunctor] -class RFunctor (F : COFE.OFunctorPre) where - [cmra [COFE α] [COFE β] : CMRA (F α β)] - map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : +class RFunctor (F : COFE.OFunctorPre Nat) where + [cmra [COFE Nat α] [COFE Nat β] : CMRA (F α β)] + map [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -C> F α₂ β₂ - map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : + map_ne [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - map_id [COFE α] [COFE β] (x : F α β) : map (@Hom.id α _) (@Hom.id β _) x = x - map_comp [COFE α₁] [COFE α₂] [COFE α₃] [COFE β₁] [COFE β₂] [COFE β₃] + map_id [COFE Nat α] [COFE Nat β] (x : F α β) : map (Hom.id (α := α)) (Hom.id (α := β)) x = x + map_comp [COFE Nat α₁] [COFE Nat α₂] [COFE Nat α₃] [COFE Nat β₁] [COFE Nat β₂] [COFE Nat β₃] (f : α₂ -n> α₁) (g : α₃ -n> α₂) (f' : β₁ -n> β₂) (g' : β₂ -n> β₃) (x : F α₁ β₁) : map (f.comp g) (g'.comp f') x = map g g' (map f f' x) @[rocq_alias rFunctorContractive] -class RFunctorContractive (F : COFE.OFunctorPre) extends (RFunctor F) where - map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : +class RFunctorContractive (F : COFE.OFunctorPre Nat) extends (RFunctor F) where + map_contractive [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) attribute [reducible, instance] RFunctor.cmra @[rocq_alias rFunctor_to_oFunctor] -instance RFunctor.toOFunctor [R : RFunctor F] : COFE.OFunctor F where +instance RFunctor.toOFunctor [R : RFunctor F] : COFE.OFunctor Nat F where ofe := RFunctor.cmra.toOFE map a b := (RFunctor.map a b).toHom map_ne.ne := RFunctor.map_ne.ne @@ -1033,7 +1034,7 @@ instance RFunctor.toOFunctor [R : RFunctor F] : COFE.OFunctor F where @[rocq_alias rFunctor_to_oFunctor_contractive] instance RFunctorContractive.toOFunctorContractive - [RFunctorContractive F] : COFE.OFunctorContractive F where + [RFunctorContractive F] : COFE.OFunctorContractive Nat F where map_contractive.1 := map_contractive.1 end rFunctor @@ -1041,20 +1042,20 @@ end rFunctor section urFunctor @[rocq_alias urFunctor] -class URFunctor (F : COFE.OFunctorPre) where - [cmra [COFE α] [COFE β] : UCMRA (F α β)] - map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : +class URFunctor (F : COFE.OFunctorPre Nat) where + [cmra [COFE Nat α] [COFE Nat β] : UCMRA (F α β)] + map [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -C> F α₂ β₂ - map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : + map_ne [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - map_id [COFE α] [COFE β] (x : F α β) : map (@Hom.id α _) (@Hom.id β _) x = x - map_comp [COFE α₁] [COFE α₂] [COFE α₃] [COFE β₁] [COFE β₂] [COFE β₃] + map_id [COFE Nat α] [COFE Nat β] (x : F α β) : map (Hom.id (α := α)) (Hom.id (α := β)) x = x + map_comp [COFE Nat α₁] [COFE Nat α₂] [COFE Nat α₃] [COFE Nat β₁] [COFE Nat β₂] [COFE Nat β₃] (f : α₂ -n> α₁) (g : α₃ -n> α₂) (f' : β₁ -n> β₂) (g' : β₂ -n> β₃) (x : F α₁ β₁) : map (f.comp g) (g'.comp f') x = map g g' (map f f' x) @[rocq_alias urFunctorContractive] -class URFunctorContractive (F : COFE.OFunctorPre) extends URFunctor F where - map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : +class URFunctorContractive (F : COFE.OFunctorPre Nat) extends URFunctor F where + map_contractive [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) attribute [reducible, instance] URFunctor.cmra @@ -1153,7 +1154,7 @@ end DiscreteFunO section DiscreteFunURF @[rocq_alias discrete_funURF] -instance urFunctorDiscreteFunOF {C} (F : C → COFE.OFunctorPre) [∀ c, URFunctor (F c)] : +instance urFunctorDiscreteFunOF {C} (F : C → COFE.OFunctorPre Nat) [∀ c, URFunctor (F c)] : URFunctor (DiscreteFunOF F) where map f g := { toHom := COFE.OFunctor.map f g @@ -1168,7 +1169,7 @@ instance urFunctorDiscreteFunOF {C} (F : C → COFE.OFunctorPre) [∀ c, URFunct map_comp f g f' g' x := COFE.OFunctor.map_comp f g f' g' x @[rocq_alias discrete_funURF_contractive] -instance DiscreteFunOF_URFC {C} (F : C → COFE.OFunctorPre) [HURF : ∀ c, URFunctorContractive (F c)] : +instance DiscreteFunOF_URFC {C} (F : C → COFE.OFunctorPre Nat) [HURF : ∀ c, URFunctorContractive (F c)] : URFunctorContractive (DiscreteFunOF F) where map_contractive.1 h _ _ := URFunctorContractive.map_contractive.distLater_dist h _ @@ -1556,23 +1557,26 @@ section unit #rocq_ignore unit_core_id "Subsumed by unit_CoreId" @[rocq_alias unitR, rocq_alias unit_cmra_mixin] -instance cmraUnit : CMRA Unit where - pcore _ := some () - op _ _ := () - ValidN _ _ := True - Valid _ := True - op_ne.ne _ _ _ := id - pcore_ne _ _ := ⟨(), rfl, .rfl⟩ - validN_ne _ := id - valid_iff_validN := ⟨fun _ _ => ⟨⟩, fun _ => ⟨⟩⟩ - validN_succ := id - validN_op_left := id - assoc := rfl - comm := rfl - pcore_op_left _ := rfl - pcore_idem _ := rfl - pcore_op_mono _ _ := ⟨.unit, rfl⟩ - extend _ _ := ⟨(), (), rfl, .rfl, .rfl⟩ +instance cmraUnit : CMRA Unit := + letI : OFE Nat Unit := unitOFE + { + pcore _ := some () + op _ _ := () + ValidN _ _ := True + Valid _ := True + op_ne.ne _ _ _ := id + pcore_ne _ _ := ⟨(), rfl, .rfl⟩ + validN_ne _ := id + valid_iff_validN := ⟨fun _ _ => ⟨⟩, fun _ => ⟨⟩⟩ + validN_succ := id + validN_op_left := id + assoc := rfl + comm := rfl + pcore_op_left _ := rfl + pcore_idem _ := rfl + pcore_op_mono _ _ := ⟨.unit, rfl⟩ + extend _ _ := ⟨(), (), rfl, .rfl, .rfl⟩ + } end unit @@ -1721,7 +1725,7 @@ section ProdRF open RFunctor @[rocq_alias prodRF] -instance instRFunctorProdOF [RFunctor F1] [RFunctor F2] : RFunctor (ProdOF F1 F2) where +instance instRFunctorProdOF [RFunctor F1] [RFunctor F2] : RFunctor (ProdOF Nat F1 F2) where map f g := Prod.mapC (map f g) (map f g) map_ne.ne _ _ _ Hx _ _ Hy _ := Prod.map_ne (fun _ => map_ne.ne Hx Hy _) (fun _ => map_ne.ne Hx Hy _) @@ -1732,7 +1736,7 @@ instance instRFunctorProdOF [RFunctor F1] [RFunctor F2] : RFunctor (ProdOF F1 F2 @[rocq_alias prodRF_contractive] instance instRFunctorContractiveProdOF [RFunctorContractive F1] [RFunctorContractive F2] : - RFunctorContractive (ProdOF F1 F2) where + RFunctorContractive (ProdOF Nat F1 F2) where map_contractive.1 H _ := Prod.map_ne (fun _ => RFunctorContractive.map_contractive.1 H _) (fun _ => RFunctorContractive.map_contractive.1 H _) @@ -1741,7 +1745,7 @@ end ProdRF section optionOF -variable {F : COFE.OFunctorPre} +variable {F : COFE.OFunctorPre Nat} @[rocq_alias optionURF] instance urFunctorOptionOF [RFunctor F] : URFunctor (OptionOF F) where diff --git a/Iris/Iris/Algebra/Monoid.lean b/Iris/Iris/Algebra/Monoid.lean index e70bf9f38..887103d48 100644 --- a/Iris/Iris/Algebra/Monoid.lean +++ b/Iris/Iris/Algebra/Monoid.lean @@ -20,10 +20,12 @@ namespace Iris.Algebra open OFE +variable {SI : outParam <| Type _} [SIdx SI] + /-- A commutative monoid on an OFE, used for big operators. The operation must be non-expansive, associative, commutative, and have a left identity. -/ @[rocq_alias Monoid] -class MonoidOps {M : Type u} [OFE M] (op : M → M → M) (unit : outParam M) where +class MonoidOps {M : Type u} [OFE SI M] (op : M → M → M) (unit : outParam M) where /-- The operation is non-expansive in both arguments -/ op_ne : NonExpansive₂ op /-- Associativity -/ @@ -40,7 +42,7 @@ namespace MonoidOps attribute [instance] op_ne -variable {M : Type u} [OFE M] {unit : M} {op : M → M → M} +variable {M : Type u} [OFE SI M] {unit : M} {op : M → M → M} #rocq_ignore monoid_proper "OFE is Leibniz; use equality" @@ -77,7 +79,7 @@ end MonoidOps /-- A weak monoid homomorphism preserves the operation but not necessarily the unit. -/ @[rocq_alias WeakMonoidHomomorphism] -class WeakMonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE M₂] +class WeakMonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE SI M₁] [OFE SI M₂] (op₁ : M₁ → M₁ → M₁) (op₂ : M₂ → M₂ → M₂) (unit₁ : M₁) (unit₂ : M₂) [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] (R : M₂ → M₂ → Prop) (f : M₁ → M₂) where @@ -96,7 +98,7 @@ class WeakMonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE M /-- A monoid homomorphism preserves both the operation and the unit. -/ @[rocq_alias MonoidHomomorphism] -class MonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE M₂] +class MonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE SI M₁] [OFE SI M₂] (op₁ : M₁ → M₁ → M₁) (op₂ : M₂ → M₂ → M₂) (unit₁ : M₁) (unit₂ : M₂) [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] (R : M₂ → M₂ → Prop) (f : M₁ → M₂) From 15ac195a03efb228b056e419a3746b4eebb8f29f Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 17:03:50 +0200 Subject: [PATCH 15/33] `COFESolver.lean`: `OFE Nat ...`, some proofs with `sorry` --- Iris/Iris/Algebra/COFESolver.lean | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/Iris/Iris/Algebra/COFESolver.lean b/Iris/Iris/Algebra/COFESolver.lean index 5706bb01d..382e8e4f3 100644 --- a/Iris/Iris/Algebra/COFESolver.lean +++ b/Iris/Iris/Algebra/COFESolver.lean @@ -6,6 +6,7 @@ Authors: Mario Carneiro, Sebastian Graf module public import Iris.Algebra.OFE +public import Iris.Algebra.StepIndexFinite meta import Iris.Std.RocqPorting @[expose] public section @@ -15,23 +16,26 @@ meta import Iris.Std.RocqPorting namespace Iris.COFE.OFunctor open OFE -variable {F : ∀ α β [COFE α] [COFE β], Type u} [OFunctorContractive F] -variable [∀ α [COFE α], IsCOFE (F α α)] +variable [SIdx SI] + +variable {F : ∀ α β [COFE Nat α] [COFE Nat β], Type u} [OFunctorContractive Nat F] +variable [∀ α [COFE Nat α], IsCOFE Nat (F α α)] +local instance : COFE Nat Unit := unitCOFE variable [inh : Inhabited (F (ULift Unit) (ULift Unit))] namespace Fix.Impl variable (F) in @[rocq_alias solver.A'] -def A' : Nat → Σ α : Type u, COFE α +def A' : Nat → Σ α : Type u, COFE Nat α | 0 => ⟨ULift Unit, inferInstance⟩ | n+1 => let ⟨A, _⟩ := A' n; ⟨F A A, inferInstance⟩ variable (F) in def A (n : Nat) : Type u := (A' F n).1 -instance instA' (n) : COFE (A' F n).1 := (A' F n).2 -instance instA (n) : COFE (A F n) := (A' F n).2 +instance instA' (n) : COFE Nat (A' F n).1 := (A' F n).2 +instance instA (n) : COFE Nat (A F n) := (A' F n).2 #rocq_ignore solver.A_cofe "Inference succeeds automatically via `instA`/`instA'`" variable (F) in @@ -77,7 +81,7 @@ structure Tower : Type u where instance : CoeFun (Tower F) (fun _ => ∀ k, A F k) := ⟨Tower.val⟩ @[rocq_alias solver.T] -instance : OFE (Tower F) where +instance : OFE Nat (Tower F) where Dist n f g := ∀ k, f k ≡{n}≡ g k dist_eqv := { refl _ _ := dist_eqv.refl _ @@ -92,17 +96,20 @@ instance : OFE (Tower F) where #rocq_ignore solver.tower_ofe_mixin "Not needed" @[rocq_alias solver.tower_chain] -def towerChain (c : Chain (Tower F)) (k : Nat) : Chain (A F k) where +def towerChain (c : Chain (SI := Nat) (Tower F)) (k : Nat) : Chain (A F k) where chain i := c.1 i k cauchy h := c.cauchy h k -instance : COFE (Tower F) where +instance : COFE Nat (Tower F) where compl c := by refine ⟨fun k => compl ⟨fun i => c.1 i k, fun h => c.cauchy h k⟩, ?_⟩ refine OFE.eq_dist.mpr (fun n => ?_) refine ((down ..).ne.1 conv_compl).trans <| .trans ?_ conv_compl.symm exact (c.chain n).down.dist conv_compl _ := conv_compl + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore solver.tower_cofe "Use IsCOFE instance" #rocq_ignore solver.tower_compl "Use IsCOFE instance" @@ -318,7 +325,7 @@ variable (F) in def Fix : Type u := Tower F instance : Inhabited (Fix F) := inferInstanceAs (Inhabited (Tower F)) -instance : COFE (Fix F) := inferInstanceAs (COFE (Tower F)) +instance : COFE Nat (Fix F) := inferInstanceAs (COFE Nat (Tower F)) def Fix.iso : OFE.Iso (F (Fix F) (Fix F)) (Fix F) := Tower.iso From 04cc2c7747064d571f81f5f64736285be806129e Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Wed, 29 Jul 2026 17:40:02 +0200 Subject: [PATCH 16/33] Replace `OFE ...` with `OFE Nat ...`, `COFE ...` with `COFE Nat ...`, and so on --- Iris/Iris/Algebra/Agree.lean | 18 ++-- Iris/Iris/Algebra/Auth.lean | 14 +-- Iris/Iris/Algebra/BigOp.lean | 30 +++---- Iris/Iris/Algebra/Csum.lean | 45 +++++----- Iris/Iris/Algebra/DFrac.lean | 2 +- Iris/Iris/Algebra/DynReservationMap.lean | 4 +- Iris/Iris/Algebra/Excl.lean | 63 +++++++------- Iris/Iris/Algebra/Frac.lean | 2 +- Iris/Iris/Algebra/GenMap.lean | 28 +++--- Iris/Iris/Algebra/Heap.lean | 45 +++++----- Iris/Iris/Algebra/HeapView.lean | 5 +- Iris/Iris/Algebra/IProp.lean | 6 +- Iris/Iris/Algebra/LeibnizSet.lean | 4 +- Iris/Iris/Algebra/Lib/DFracAgree.lean | 14 +-- Iris/Iris/Algebra/Lib/ExclAuth.lean | 6 +- Iris/Iris/Algebra/Lib/FracAuth.lean | 8 +- Iris/Iris/Algebra/Lib/MonoNat.lean | 2 +- Iris/Iris/Algebra/Monoid.lean | 11 ++- Iris/Iris/Algebra/Numbers.lean | 6 +- Iris/Iris/Algebra/ReservationMap.lean | 4 +- Iris/Iris/Algebra/StepIndexFinite.lean | 4 + Iris/Iris/Algebra/UFrac.lean | 2 +- Iris/Iris/Algebra/UPred.lean | 13 +-- Iris/Iris/Algebra/View.lean | 22 ++--- Iris/Iris/BI/Algebra.lean | 4 +- Iris/Iris/BI/BI.lean | 3 +- Iris/Iris/BI/BigOp/BigOp.lean | 4 +- Iris/Iris/BI/BigOp/BigSepList.lean | 4 +- Iris/Iris/BI/DerivedLaws.lean | 30 +++---- Iris/Iris/BI/Embedding.lean | 2 +- Iris/Iris/BI/InternalEq.lean | 92 ++++++++++---------- Iris/Iris/BI/Lib/Fixpoint.lean | 14 +-- Iris/Iris/BI/Lib/MonoNat.lean | 4 +- Iris/Iris/BI/MonPred.lean | 15 ++-- Iris/Iris/BI/Plainly.lean | 10 +-- Iris/Iris/BI/SIProp.lean | 27 +++--- Iris/Iris/Examples/Fix.lean | 10 +-- Iris/Iris/Examples/IProp.lean | 10 ++- Iris/Iris/Instances/Classical/Instance.lean | 2 +- Iris/Iris/Instances/IProp/Instance.lean | 30 +++---- Iris/Iris/Instances/Lib/Boxes.lean | 6 +- Iris/Iris/Instances/Lib/CInvariants.lean | 4 +- Iris/Iris/Instances/Lib/GhostMap.lean | 2 +- Iris/Iris/Instances/Lib/LaterCredits.lean | 2 +- Iris/Iris/Instances/Lib/NaInvariants.lean | 4 +- Iris/Iris/Instances/Lib/SavedProp.lean | 6 +- Iris/Iris/Instances/Lib/Token.lean | 2 +- Iris/Iris/Instances/UPred/Instance.lean | 2 +- Iris/Iris/ProofMode/Classes.lean | 2 +- Iris/Iris/ProofMode/InstancesInternalEq.lean | 22 ++--- Iris/Iris/ProofMode/Tactics/Rewrite.lean | 6 +- Iris/Iris/Tests/Tactics.lean | 2 +- 52 files changed, 353 insertions(+), 326 deletions(-) diff --git a/Iris/Iris/Algebra/Agree.lean b/Iris/Iris/Algebra/Agree.lean index 6d317f47c..aaf303ce3 100644 --- a/Iris/Iris/Algebra/Agree.lean +++ b/Iris/Iris/Algebra/Agree.lean @@ -80,7 +80,7 @@ theorem map'_sameElems {f : α → β} {x y : Raw α} (h : SameElems x y) : obtain ⟨b, hb, rfl⟩ := ha exact ⟨b, by first | exact h.1 _ hb | exact h.2 _ hb, rfl⟩ -variable [OFE α] +variable [OFE Nat α] def dist (n : Nat) (x y : Raw α) : Prop := (∀ a ∈ x.car, ∃ b ∈ y.car, a ≡{n}≡ b) ∧ @@ -227,7 +227,7 @@ theorem toAgree_uninj {x : Raw α} : x.valid → ∃ a, ∀ n, dist n (toAgree a · exists a; simp_all [toAgree] · simp_all [toAgree] -variable [OFE β] {f : α → β} +variable [OFE Nat β] {f : α → β} theorem map'_ne [OFE.NonExpansive f] {x₁ x₂ : Raw α} (h : dist n x₁ x₂) : dist n (map' f x₁) (map' f x₂) := by @@ -347,14 +347,14 @@ end Agree namespace Agree -variable [OFE α] [OFE β] +variable [OFE Nat α] [OFE Nat β] @[rocq_alias agree_dist] def dist (n : Nat) : Agree α → Agree α → Prop := lift₂ (Raw.dist n) (fun _ _ _ _ hac hbd => propext (Raw.dist_congr hac hbd)) @[rocq_alias agree_ofe_mixin] -instance instOFE : OFE (Agree α) where +instance instOFE : OFE Nat (Agree α) where Dist := dist dist_eqv := by refine ⟨Quotient.ind fun a => Raw.dist_equiv.refl a, fun {x y} h => ?_, fun {x y z} h₁ h₂ => ?_⟩ @@ -524,7 +524,7 @@ theorem toAgree_def {a : α} : toAgree a = Agree.mk (Agree.Raw.toAgree a) := rfl section -variable [OFE α] +variable [OFE Nat α] @[rocq_alias to_agree_ne] instance instNonExpansive_toAgree : OFE.NonExpansive (@toAgree α) where @@ -640,7 +640,7 @@ theorem Agree.map'_compose {f : α → β} {g : β → γ} (x : Agree α) : Agree.map' (g ∘ f) x = Agree.map' g (Agree.map' f x) := x.ind fun _ => congrArg mk (Raw.ext (by simp [Raw.map'_car, List.map_map])) -variable {α β γ : Type _} [OFE α] [OFE β] [OFE γ] {f : α → β} [hne : OFE.NonExpansive f] +variable {α β γ : Type _} [OFE Nat α] [OFE Nat β] [OFE Nat γ] {f : α → β} [hne : OFE.NonExpansive f] @[rocq_alias agree_map_ne] instance instNonExpansive_AgreeMap' : OFE.NonExpansive (Agree.map' f) where @@ -694,10 +694,10 @@ end agree_map section agree_rfunctor @[rocq_alias agreeRF] -abbrev AgreeRF (F : COFE.OFunctorPre) : COFE.OFunctorPre := +abbrev AgreeRF (F : COFE.OFunctorPre Nat) : COFE.OFunctorPre Nat := fun A B _ _ => Agree (F A B) -instance {F} [COFE.OFunctor F] : RFunctor (AgreeRF F) where +instance {F} [COFE.OFunctor Nat F] : RFunctor (AgreeRF F) where map f g := Agree.map (COFE.OFunctor.map f g) map_ne.ne _ _ _ Hx _ _ Hy _ := Agree.map_ne <| COFE.OFunctor.map_ne.ne Hx Hy map_id x := by @@ -708,7 +708,7 @@ instance {F} [COFE.OFunctor F] : RFunctor (AgreeRF F) where exact Agree.agree_map_ext (fun a => COFE.OFunctor.map_comp f g f' g' a) @[rocq_alias agreeRF_contractive] -instance {F} [COFE.OFunctorContractive F] : RFunctorContractive (AgreeRF F) where +instance {F} [COFE.OFunctorContractive Nat F] : RFunctorContractive (AgreeRF F) where map_contractive.1 H _ := Agree.map_ne (COFE.OFunctorContractive.map_contractive.1 H) end agree_rfunctor diff --git a/Iris/Iris/Algebra/Auth.lean b/Iris/Iris/Algebra/Auth.lean index 2d2f8d031..e59e9dd1a 100644 --- a/Iris/Iris/Algebra/Auth.lean +++ b/Iris/Iris/Algebra/Auth.lean @@ -71,7 +71,7 @@ abbrev Auth (A : Type _) [UCMRA A] := namespace Auth variable [UCMRA A] -instance : OFE (Auth A) := View.instOFE +instance : OFE Nat (Auth A) := View.instOFE instance : CMRA (Auth A) := View.instCMRA instance : UCMRA (Auth A) := View.instUCMRA @@ -464,10 +464,10 @@ theorem authViewRel_map [UCMRA A'] [UCMRA B'] (g : A' -C> B') (n : Nat) (a : A') fun ⟨hinc, hv⟩ => ⟨CMRA.Hom.monoN g n hinc, CMRA.Hom.validN g hv⟩ @[rocq_alias authURF] -abbrev AuthURF (T : COFE.OFunctorPre) [URFunctor T] : COFE.OFunctorPre := +abbrev AuthURF (T : COFE.OFunctorPre Nat) [URFunctor T] : COFE.OFunctorPre Nat := fun A B _ _ => Auth (T A B) -instance instURFunctorAuthURF {T : COFE.OFunctorPre} [URFunctor T] : +instance instURFunctorAuthURF {T : COFE.OFunctorPre Nat} [URFunctor T] : URFunctor (AuthURF T) where map {A A'} {B B'} _ _ _ _ f g := mapC @@ -487,16 +487,16 @@ instance instURFunctorAuthURF {T : COFE.OFunctorPre} [URFunctor T] : (congrArg (View.map _ _ · _) (funext fun _ => URFunctor.map_comp f g f' g' _)) @[rocq_alias authURF_contractive] -instance instURFunctorContractiveAuthURF {T : COFE.OFunctorPre} [URFunctorContractive T] : +instance instURFunctorContractiveAuthURF {T : COFE.OFunctorPre Nat} [URFunctorContractive T] : URFunctorContractive (AuthURF T) where map_contractive.1 h x := by apply map_ne <;> apply URFunctorContractive.map_contractive.1 h @[rocq_alias authRF] -abbrev AuthRF (T : COFE.OFunctorPre) [URFunctor T] : COFE.OFunctorPre := +abbrev AuthRF (T : COFE.OFunctorPre Nat) [URFunctor T] : COFE.OFunctorPre Nat := fun A B _ _ => Auth (T A B) -instance instRFunctorAuthRF {T : COFE.OFunctorPre} [URFunctor T] : +instance instRFunctorAuthRF {T : COFE.OFunctorPre Nat} [URFunctor T] : RFunctor (AuthRF T) where map {A A'} {B B'} _ _ _ _ f g := mapC @@ -516,7 +516,7 @@ instance instRFunctorAuthRF {T : COFE.OFunctorPre} [URFunctor T] : (congrArg (View.map _ _ · _) (funext fun _ => URFunctor.map_comp f g f' g' _)) @[rocq_alias authRF_contractive] -instance instRFunctorContractiveAuthRF {T : COFE.OFunctorPre} [URFunctorContractive T] : +instance instRFunctorContractiveAuthRF {T : COFE.OFunctorPre Nat} [URFunctorContractive T] : RFunctorContractive (AuthRF T) where map_contractive.1 h x := by apply View.map_ne <;> apply URFunctorContractive.map_contractive.1 h diff --git a/Iris/Iris/Algebra/BigOp.lean b/Iris/Iris/Algebra/BigOp.lean index 20642200c..166197f42 100644 --- a/Iris/Iris/Algebra/BigOp.lean +++ b/Iris/Iris/Algebra/BigOp.lean @@ -26,13 +26,13 @@ These are parameterized by a monoid operation and include theorems about their p open OFE Iris.Std -@[rocq_alias big_opL, expose] public def bigOpL {M : Type u} {A : Type v} [OFE M] (op : M → M → M) {unit : M} [MonoidOps op unit] +@[rocq_alias big_opL, expose] public def bigOpL {M : Type u} {A : Type v} [OFE Nat M] (op : M → M → M) {unit : M} [MonoidOps op unit] (Φ : Nat → A → M) (l : List A) : M := match l with | [] => unit | x :: xs => op (Φ 0 x) (bigOpL op (fun n => Φ (n + 1)) xs) -@[rocq_alias big_opM, expose] public def bigOpM {M : Type u} [OFE M] (op : M → M → M) {unit : M} [MonoidOps op unit] {K : Type _} +@[rocq_alias big_opM, expose] public def bigOpM {M : Type u} [OFE Nat M] (op : M → M → M) {unit : M} [MonoidOps op unit] {K : Type _} {V : Type _} (Φ : K → V → M) {M' : Type _ → Type _} [LawfulFiniteMap M' K] (m : M' V) : M := bigOpL op (fun _ kv => Φ kv.1 kv.2) (toList m) @@ -40,7 +40,7 @@ open OFE Iris.Std #rocq_ignore big_opM_def "Not needed" #rocq_ignore big_opM_unseal "Not needed" -@[rocq_alias big_opS, expose] public def bigOpS {M : Type u} [OFE M] (op : M → M → M) {unit : M} [MonoidOps op unit] +@[rocq_alias big_opS, expose] public def bigOpS {M : Type u} [OFE Nat M] (op : M → M → M) {unit : M} [MonoidOps op unit] {A : Type _} {S : Type _} [FiniteSet S A] (Φ : A → M) (m : S) : M := bigOpL op (fun _ x => Φ x) (toList m) @@ -48,7 +48,7 @@ open OFE Iris.Std #rocq_ignore big_opS_def "Not needed" #rocq_ignore big_opS_unseal "Not needed" -@[rocq_alias big_opMS, expose] public def bigOpMS {M : Type u} [OFE M] (op : M → M → M) +@[rocq_alias big_opMS, expose] public def bigOpMS {M : Type u} [OFE Nat M] (op : M → M → M) {unit : M} [MonoidOps op unit] {A : Type _} {MS : Type _} [FiniteMultiSet MS A] (Φ : A → M) (X : MS) : M := bigOpL op (fun _ x => Φ x) (FiniteMultiSet.toList X) @@ -84,7 +84,7 @@ scoped macro_rules public section namespace BigOpL -variable {M : Type _} {A : Type _} [OFE M] {op : M → M → M} {unit : M} [MonoidOps op unit] +variable {M : Type _} {A : Type _} [OFE Nat M] {op : M → M → M} {unit : M} [MonoidOps op unit] open MonoidOps @@ -216,7 +216,7 @@ theorem bigOpL_gen_proper (R : M → M → Prop) {Φ Ψ : Nat → A → M} {l : #rocq_ignore big_opL_ext "Merged into bigOpL_eq" @[rocq_alias big_opL_proper_2] -theorem bigOpL_proper_2 [OFE A] {Φ Ψ : Nat → A → M} {l₁ l₂ : List A} (hlen : l₁.length = l₂.length) +theorem bigOpL_proper_2 [OFE Nat A] {Φ Ψ : Nat → A → M} {l₁ l₂ : List A} (hlen : l₁.length = l₂.length) (hf : ∀ {k y₁ y₂}, l₁[k]? = some y₁ → l₂[k]? = some y₂ → Φ k y₁ = Ψ k y₂) : ([^ op list] k ↦ x ∈ l₁, Φ k x) = ([^ op list] k ↦ x ∈ l₂, Ψ k x) := bigOpL_gen_proper_2 (· = ·) rfl (· ▸ · ▸ rfl) hlen hf @@ -287,7 +287,7 @@ end CMRA section Hom -variable {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE M₂] +variable {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] variable {op₁ : M₁ → M₁ → M₁} {op₂ : M₂ → M₂ → M₂} {unit₁ : M₁} {unit₂ : M₂} variable [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] variable {B : Type w} {R : M₂ → M₂ → Prop} {f : M₁ → M₂} @@ -319,7 +319,7 @@ namespace BigOpM open scoped PartialMap -variable {M : Type u} [OFE M] {op : M → M → M} {unit : M} [MonoidOps op unit] +variable {M : Type u} [OFE Nat M] {op : M → M → M} {unit : M} [MonoidOps op unit] variable {M' : Type _ → Type _} {K : Type _} {V : Type _} variable [LawfulFiniteMap M' K] @@ -401,7 +401,7 @@ theorem bigOpM_eq {Φ Ψ : K → V → M} {m : M' V} (hf : ∀ {k x}, get? m k = bigOpM_gen_proper rfl (· ▸ · ▸ rfl) hf @[rocq_alias big_opM_proper_2] -theorem bigOpM_eq_strong [OFE A] {Φ Ψ : K → A → M} {m1 m2 : M' A} (hm : ∀ k, get? m1 k = get? m2 k) +theorem bigOpM_eq_strong [OFE Nat A] {Φ Ψ : K → A → M} {m1 m2 : M' A} (hm : ∀ k, get? m1 k = get? m2 k) (hf : ∀ {k y1 y2}, get? m1 k = some y1 → get? m2 k = some y2 → y1 = y2 → Φ k y1 = Ψ k y2) : ([^ op map] k ↦ x ∈ m1, Φ k x) = ([^ op map] k ↦ x ∈ m2, Ψ k x) := bigOpM_gen_proper_2 id equivalence_eq (· ▸ · ▸ rfl) (fun k => by rw [hm k]) @@ -577,8 +577,8 @@ theorem bigOpM_none {f : K → V → Option M} {m : M' V} : end CMRA -variable {M₁} [OFE M₁] -variable {M₂} [OFE M₂] +variable {M₁} [OFE Nat M₁] +variable {M₂} [OFE Nat M₂] variable {op₁ : M₁ → M₁ → M₁} {op₂ : M₂ → M₂ → M₂} {unit₁ : M₁} {unit₂ : M₂} variable [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] @@ -604,7 +604,7 @@ end BigOpM namespace BigOpS -variable {M : Type _} {A : Type _} {S : Type _} [OFE M] {op : M → M → M} {unit : M} +variable {M : Type _} {A : Type _} {S : Type _} [OFE Nat M] {op : M → M → M} {unit : M} [MonoidOps op unit] [LawfulFiniteSet S A] open BigOpL MonoidOps LawfulSet FiniteSet @@ -717,7 +717,7 @@ end CMRA section Homomorphism -variable {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE M₂] +variable {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] variable {op₁ : M₁ → M₁ → M₁} {op₂ : M₂ → M₂ → M₂} {unit₁ : M₁} {unit₂ : M₂} variable [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] @@ -747,7 +747,7 @@ end BigOpS namespace BigOpMS -variable {M : Type _} {A : Type _} {MS : Type _} [OFE M] {op : M → M → M} {unit : M} +variable {M : Type _} {A : Type _} {MS : Type _} [OFE Nat M] {op : M → M → M} {unit : M} [MonoidOps op unit] [LawfulFiniteMultiSet MS A] open BigOpL MonoidOps @@ -856,7 +856,7 @@ end CMRA section Homomorphism -variable {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE M₂] +variable {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] variable {op₁ : M₁ → M₁ → M₁} {op₂ : M₂ → M₂ → M₂} {unit₁ : M₁} {unit₂ : M₂} variable [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] diff --git a/Iris/Iris/Algebra/Csum.lean b/Iris/Iris/Algebra/Csum.lean index 294bf395c..c963a67b4 100644 --- a/Iris/Iris/Algebra/Csum.lean +++ b/Iris/Iris/Algebra/Csum.lean @@ -28,13 +28,13 @@ namespace Csum #rocq_ignore csum_equiv "OFE is Leibniz; use equality" -@[simp, rocq_alias csum_dist] def Dist [OFE α] [OFE β] (n : Nat) : Csum α β → Csum α β → Prop +@[simp, rocq_alias csum_dist] def Dist [OFE Nat α] [OFE Nat β] (n : Nat) : Csum α β → Csum α β → Prop | inl a, inl a' => a ≡{n}≡ a' | inr b, inr b' => b ≡{n}≡ b' | invalid, invalid => True | _, _ => False -theorem dist_eqv [OFE α] [OFE β] {n} : Equivalence (Csum.Dist (α := α) (β := β) n) where +theorem dist_eqv [OFE Nat α] [OFE Nat β] {n} : Equivalence (Csum.Dist (α := α) (β := β) n) where refl {x} := by cases x with | inl => exact Dist.rfl | inr => exact Dist.rfl @@ -45,7 +45,7 @@ theorem dist_eqv [OFE α] [OFE β] {n} : Equivalence (Csum.Dist (α := α) (β : first | trivial | exact h₁.trans h₂ | exact h₂.elim | exact h₁.elim @[rocq_alias csumO] -instance [OFE α] [OFE β] : OFE (Csum α β) where +instance [OFE Nat α] [OFE Nat β] : OFE Nat (Csum α β) where Dist := Csum.Dist dist_eqv := dist_eqv eq_dist {x y} := by @@ -56,33 +56,33 @@ instance [OFE α] [OFE β] : OFE (Csum α β) where #rocq_ignore csum_ofe_mixin "Not needed" @[rocq_alias Cinl_ne] -instance [OFE α] [OFE β] : NonExpansive (inl (α := α) (β := β)) where +instance [OFE Nat α] [OFE Nat β] : NonExpansive (inl (α := α) (β := β)) where ne _ _ _ := id #rocq_ignore Cinl_proper "Derivable using NonExpansive.eqv" @[rocq_alias Cinr_ne] -instance [OFE α] [OFE β] : NonExpansive (inr (α := α) (β := β)) where +instance [OFE Nat α] [OFE Nat β] : NonExpansive (inr (α := α) (β := β)) where ne _ _ _ := id #rocq_ignore Cinr_proper "Derivable using NonExpansive.eqv" @[rocq_alias Cinl_inj] -theorem inl_inj [OFE α] [OFE β] {a a' : α} (h : (inl (β := β) a) = inl a') : a = a' := +theorem inl_inj [OFE Nat α] [OFE Nat β] {a a' : α} (h : (inl (β := β) a) = inl a') : a = a' := Csum.inl.inj h @[rocq_alias Cinl_inj_dist] -theorem inl_injN [OFE α] [OFE β] {a a' : α} (h : inl (β := β) a ≡{n}≡ inl a') : a ≡{n}≡ a' := h +theorem inl_injN [OFE Nat α] [OFE Nat β] {a a' : α} (h : inl (β := β) a ≡{n}≡ inl a') : a ≡{n}≡ a' := h @[rocq_alias Cinr_inj] -theorem inr_inj [OFE α] [OFE β] {b b' : β} (h : (inr (α := α) b) = inr b') : b = b' := +theorem inr_inj [OFE Nat α] [OFE Nat β] {b b' : β} (h : (inr (α := α) b) = inr b') : b = b' := Csum.inr.inj h @[rocq_alias Cinr_inj_dist] -theorem inr_injN [OFE α] [OFE β] {b b' : β} (h : inr (α := α) b ≡{n}≡ inr b') : b ≡{n}≡ b' := h +theorem inr_injN [OFE Nat α] [OFE Nat β] {b b' : β} (h : inr (α := α) b ≡{n}≡ inr b') : b ≡{n}≡ b' := h @[rocq_alias csum_ofe_discrete] -instance [OFE α] [OFE β] [OFE.Discrete α] [OFE.Discrete β] : OFE.Discrete (Csum α β) where +instance [OFE Nat α] [OFE Nat β] [OFE.Discrete α] [OFE.Discrete β] : OFE.Discrete (Csum α β) where discrete_0 {x y} h := by cases x <;> cases y <;> first | exact congrArg inl (discrete_0 (α := α) h) @@ -90,7 +90,7 @@ instance [OFE α] [OFE β] [OFE.Discrete α] [OFE.Discrete β] : OFE.Discrete (C | exact h.elim | trivial @[rocq_alias Cinl_discrete] -instance [OFE α] [OFE β] {a : α} [DiscreteE a] : DiscreteE (inl (β := β) a) where +instance [OFE Nat α] [OFE Nat β] {a : α} [DiscreteE a] : DiscreteE (inl (β := β) a) where discrete {x} h := by cases x with | inl => exact congrArg inl (DiscreteE.discrete (x := a) h) @@ -98,14 +98,14 @@ instance [OFE α] [OFE β] {a : α} [DiscreteE a] : DiscreteE (inl (β := β) a) | invalid => exact h.elim @[rocq_alias Cinr_discrete] -instance [OFE α] [OFE β] {b : β} [DiscreteE b] : DiscreteE (inr (α := α) b) where +instance [OFE Nat α] [OFE Nat β] {b : β} [DiscreteE b] : DiscreteE (inr (α := α) b) where discrete {x} h := by cases x with | inl => exact h.elim | inr => exact congrArg inr (DiscreteE.discrete (x := b) h) | invalid => exact h.elim -instance [OFE α] [OFE β] : DiscreteE (@invalid α β) where +instance [OFE Nat α] [OFE Nat β] : DiscreteE (@invalid α β) where discrete {x} h := by cases x with | inl => exact h.elim @@ -121,21 +121,21 @@ instance [OFE α] [OFE β] : DiscreteE (@invalid α β) where match x with | inr b => b | _ => d @[rocq_alias csum_chain_l] -def chainL [OFE α] [OFE β] (c : Chain (Csum α β)) (a : α) : Chain α where +def chainL [OFE Nat α] [OFE Nat β] (c : Chain (Csum α β)) (a : α) : Chain α where chain n := (c n).getInlD a cauchy {n i} h := by have hc := c.cauchy h; revert hc cases c.chain i <;> cases c.chain n <;> simp [OFE.Dist] @[rocq_alias csum_chain_r] -def chainR [OFE α] [OFE β] (c : Chain (Csum α β)) (b : β) : Chain β where +def chainR [OFE Nat α] [OFE Nat β] (c : Chain (Csum α β)) (b : β) : Chain β where chain n := (c n).getInrD b cauchy {n i} h := by have hc := c.cauchy h; revert hc cases c.chain i <;> cases c.chain n <;> simp [OFE.Dist] @[rocq_alias csum_cofe] -instance [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (Csum α β) where +instance [OFE Nat α] [OFE Nat β] [IsCOFE Nat α] [IsCOFE Nat β] : IsCOFE Nat (Csum α β) where compl c := match c 0 with | inl a => inl (IsCOFE.compl (chainL c a)) @@ -153,6 +153,9 @@ instance [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (Csum α β) where show IsCOFE.compl (chainR c b) ≡{n}≡ b' refine OFE.Dist.trans COFE.conv_compl ?_ simp [chainR, en] + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore csum_compl "Included in IsCOFE instance" @@ -507,7 +510,7 @@ theorem map_compose (f : α → α') (f' : α' → α'') (g : β → β') (g' : cases x <;> simp @[rocq_alias csum_map_ext] -theorem map_ext [OFE α] [OFE α'] [OFE β] [OFE β'] (f f' : α → α') (g g' : β → β') +theorem map_ext [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] (f f' : α → α') (g g' : β → β') (hf : ∀ x, f x = f' x) (hg : ∀ x, g x = g' x) (x : Csum α β) : map f g x = map f' g' x := by cases x with @@ -516,7 +519,7 @@ theorem map_ext [OFE α] [OFE α'] [OFE β] [OFE β'] (f f' : α → α') (g g' | invalid => trivial @[rocq_alias csum_map_cmra_ne] -theorem map_ne [OFE α] [OFE α'] [OFE β] [OFE β'] {n} +theorem map_ne [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] {n} {f f' : α → α'} (hf : ∀ ⦃x₁ x₂⦄, x₁ ≡{n}≡ x₂ → f x₁ ≡{n}≡ f' x₂) {g g' : β → β'} (hg : ∀ ⦃x₁ x₂⦄, x₁ ≡{n}≡ x₂ → g x₁ ≡{n}≡ g' x₂) {x y : Csum α β} (hxy : x ≡{n}≡ y) : @@ -527,14 +530,14 @@ theorem map_ne [OFE α] [OFE α'] [OFE β] [OFE β'] {n} | invalid => cases y with | invalid => trivial | _ => exact hxy @[rocq_alias csumO_map] -def oMap [OFE α] [OFE α'] [OFE β] [OFE β'] (f : α -n> α') (g : β -n> β') : +def oMap [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] (f : α -n> α') (g : β -n> β') : Csum α β -n> Csum α' β' where f := map f g ne := ⟨fun {_n} {_x₁} {_x₂} hxy => map_ne (fun _ _ h => f.ne.1 h) (fun _ _ h => g.ne.1 h) hxy⟩ @[rocq_alias csumO_map_ne] -theorem oMap_ne [OFE α] [OFE α'] [OFE β] [OFE β'] : +theorem oMap_ne [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] : NonExpansive₂ (oMap (α := α) (α' := α') (β := β) (β' := β')) where ne _ _ _ hf _ _ hg x := by cases x with @@ -543,7 +546,7 @@ theorem oMap_ne [OFE α] [OFE α'] [OFE β] [OFE β'] : | invalid => trivial @[rocq_alias csumRF] -abbrev OF (Fa Fb : COFE.OFunctorPre) : COFE.OFunctorPre := +abbrev OF (Fa Fb : COFE.OFunctorPre Nat) : COFE.OFunctorPre Nat := fun A B _ _ => Csum (Fa A B) (Fb A B) @[rocq_alias csum_map_cmra_morphism] diff --git a/Iris/Iris/Algebra/DFrac.lean b/Iris/Iris/Algebra/DFrac.lean index ea8bc26b9..8727555ab 100644 --- a/Iris/Iris/Algebra/DFrac.lean +++ b/Iris/Iris/Algebra/DFrac.lean @@ -30,7 +30,7 @@ inductive DFrac where #rocq_ignore DfracOwn_inj "Not needed" #rocq_ignore DfracBoth_inj "Not needed" -@[simp] instance : COFE DFrac := COFE.ofDiscrete _ +@[simp] instance : COFE Nat DFrac := COFE.ofDiscrete _ instance : OFE.Discrete DFrac := ⟨fun h => h⟩ #rocq_ignore dfracO "Use DFrac type with typeclass inference" diff --git a/Iris/Iris/Algebra/DynReservationMap.lean b/Iris/Iris/Algebra/DynReservationMap.lean index 085c95d13..90c08dd10 100644 --- a/Iris/Iris/Algebra/DynReservationMap.lean +++ b/Iris/Iris/Algebra/DynReservationMap.lean @@ -52,12 +52,12 @@ section OFE open OFE -variable [LawfulPartialMap H Pos] [OFE A] +variable [LawfulPartialMap H Pos] [OFE Nat A] #rocq_ignore dyn_reservation_map_ofe_mixin "Not needed" @[rocq_alias dyn_reservation_mapO] -instance : OFE (DynReservationMap A H) where +instance : OFE Nat (DynReservationMap A H) where Dist n x y := x.data ≡{n}≡ y.data ∧ x.token ≡{n}≡ y.token dist_eqv := { refl _ := ⟨.rfl, rfl⟩, diff --git a/Iris/Iris/Algebra/Excl.lean b/Iris/Iris/Algebra/Excl.lean index 8decf0908..6b10e19e2 100644 --- a/Iris/Iris/Algebra/Excl.lean +++ b/Iris/Iris/Algebra/Excl.lean @@ -26,12 +26,12 @@ open OFE #rocq_ignore excl_equiv "OFE is Leibniz; use equality" -@[simp, rocq_alias excl_dist] protected def Dist [OFE α] (n : Nat) : Excl α → Excl α → Prop +@[simp, rocq_alias excl_dist] protected def Dist [OFE Nat α] (n : Nat) : Excl α → Excl α → Prop | excl a, excl b => a ≡{n}≡ b | invalid, invalid => True | _, _ => False -theorem dist_eqv [OFE α] {n} : Equivalence (Excl.Dist (α := α) n) where +theorem dist_eqv [OFE Nat α] {n} : Equivalence (Excl.Dist (α := α) n) where refl {x} := by cases x with | excl a => exact Dist.of_eq rfl @@ -46,7 +46,7 @@ theorem dist_eqv [OFE α] {n} : Equivalence (Excl.Dist (α := α) n) where #rocq_ignore excl_ofe_mixin "Not needed" @[rocq_alias exclO] -instance [OFE α] : OFE (Excl α) where +instance [OFE Nat α] : OFE Nat (Excl α) where Dist := Excl.Dist dist_eqv eq_dist {x y} := by @@ -56,11 +56,11 @@ instance [OFE α] : OFE (Excl α) where exact Dist.lt hn hlt @[rocq_alias Excl_ne] -instance [OFE α] : NonExpansive excl (α := α) where +instance [OFE Nat α] : NonExpansive excl (α := α) where ne _ _ _ a := a /-- Note: Not an instance, due to instance coherence problems. -/ -theorem ne_match [OFE α] {B : Type _} [OFE B] +theorem ne_match [OFE Nat α] {B : Type _} [OFE Nat B] (f : α → B) (hf : NonExpansive f) (g : B) : NonExpansive (fun x : Excl α => match x with | .excl a => f a | .invalid => g) := ⟨fun {n x' y'} (h : Excl.Dist n x' y') => @@ -71,7 +71,7 @@ theorem ne_match [OFE α] {B : Type _} [OFE B] | .invalid, .invalid, _ => Dist.rfl⟩ @[rocq_alias excl_ofe_discrete] -instance [OFE α] [Discrete α] : Discrete (Excl α) where +instance [OFE Nat α] [Discrete α] : Discrete (Excl α) where discrete_0 {x y} h' := by cases x <;> cases y · exact congrArg excl (discrete_0 (α := α) h') @@ -82,14 +82,14 @@ instance [OFE α] [Discrete α] : Discrete (Excl α) where #rocq_ignore excl_leibniz "Not needed" @[rocq_alias Excl_discrete] -instance [OFE α] {a : α} [h : DiscreteE a] : DiscreteE (excl a) where +instance [OFE Nat α] {a : α} [h : DiscreteE a] : DiscreteE (excl a) where discrete {x} h' := by cases x · exact congrArg excl (h.discrete h') · exact h'.elim @[rocq_alias ExclInvalid_discrete] -instance [OFE α] : DiscreteE (@invalid α) where +instance [OFE Nat α] : DiscreteE (@invalid α) where discrete {x} h := by cases x · exact h.elim @@ -106,19 +106,22 @@ instance [OFE α] : DiscreteE (@invalid α) where | excl a => excl (f a) | invalid => invalid -def exclChain [OFE α] (c : Chain (Excl α)) (a : α) : Chain α := by +def exclChain [OFE Nat α] (c : Chain (Excl α)) (a : α) : Chain α := by refine ⟨fun n => (c n).getD a, fun {n i} H => ?_⟩ dsimp; have := c.cauchy H; revert this cases c.chain i <;> cases c.chain n <;> simp [Dist] @[rocq_alias excl_cofe] -instance [OFE α] [IsCOFE α] : IsCOFE (Excl α) where +instance [OFE Nat α] [IsCOFE Nat α] : IsCOFE Nat (Excl α) where compl c := (c 0).map fun x => IsCOFE.compl (exclChain c x) conv_compl {n} c := by have := c.cauchy (Nat.zero_le n); revert this obtain _|x' := c.chain 0 <;> rcases e : c.chain n with _|y' <;> simp [Dist] refine fun _ => .trans IsCOFE.conv_compl ?_ simp [exclChain, e] + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry /-! ## CMRA -/ @[simp] def Valid : Excl α → Prop @@ -132,7 +135,7 @@ instance [OFE α] [IsCOFE α] : IsCOFE (Excl α) where #rocq_ignore excl_cmra_mixin "Not needed" @[rocq_alias exclR] -instance [OFE α] : CMRA (Excl α) where +instance [OFE Nat α] : CMRA (Excl α) where pcore _ := none op _ _ := invalid ValidN _ := Valid @@ -154,7 +157,7 @@ instance [OFE α] : CMRA (Excl α) where extend {n x y₁ y₂} h₁ h₂ := by cases x <;> trivial @[rocq_alias excl_included] -theorem inc_iff [OFE α] {x y : Excl α} : x ≼ y ↔ y = invalid := by +theorem inc_iff [OFE Nat α] {x y : Excl α} : x ≼ y ↔ y = invalid := by constructor · rintro ⟨z, hz⟩ exact hz @@ -162,22 +165,22 @@ theorem inc_iff [OFE α] {x y : Excl α} : x ≼ y ↔ y = invalid := by exact ⟨invalid, h⟩ @[rocq_alias excl_includedN] -theorem incN_iff [OFE α] {x y : Excl α} (n) : x ≼{n} y ↔ y = invalid := by +theorem incN_iff [OFE Nat α] {x y : Excl α} (n) : x ≼{n} y ↔ y = invalid := by constructor · intro ⟨z, hz⟩; cases x <;> cases y <;> first | rfl | exact hz.elim · rintro rfl; exists invalid @[rocq_alias Excl_inj] -theorem excl_inj [OFE α] {a b : α} (h : (some (excl a) : Option (Excl α)) = some (excl b)) : +theorem excl_inj [OFE Nat α] {a b : α} (h : (some (excl a) : Option (Excl α)) = some (excl b)) : a = b := Excl.excl.inj (Option.some.inj h) @[rocq_alias Excl_dist_inj] -theorem excl_dist_inj [OFE α] {a b : α} {n} +theorem excl_dist_inj [OFE Nat α] {a b : α} {n} (h : (some (excl a) : Option (Excl α)) ≡{n}≡ some (excl b)) : a ≡{n}≡ b := OFE.some_dist_some.mp h @[rocq_alias Excl_included] -theorem excl_included [OFE α] {a b : α} : +theorem excl_included [OFE Nat α] {a b : α} : (some (excl a) : Option (Excl α)) ≼ some (excl b) ↔ a = b := by refine ⟨fun ⟨z, hz⟩ => ?_, fun h => ⟨none, congrArg (fun x => some (excl x)) h.symm⟩⟩ @@ -186,7 +189,7 @@ theorem excl_included [OFE α] {a b : α} : · exact (hz.dist (n := 0)).elim @[rocq_alias Excl_includedN] -theorem excl_includedN [OFE α] {a b : α} {n} : +theorem excl_includedN [OFE Nat α] {a b : α} {n} : (some (excl a) : Option (Excl α)) ≼{n} some (excl b) ↔ a ≡{n}≡ b := by refine ⟨fun ⟨z, hz⟩ => ?_, fun h => ⟨none, OFE.some_dist_some.mpr (show excl b ≡{n}≡ excl a from h.symm)⟩⟩ rcases z with _|z @@ -194,28 +197,28 @@ theorem excl_includedN [OFE α] {a b : α} {n} : · exact (OFE.some_dist_some.mp hz : excl b ≡{n}≡ invalid).elim @[rocq_alias excl_validN_inv_l] -theorem validN_inv_some_l [OFE α] {n} {mx : Option (Excl α)} {a : α} +theorem validN_inv_some_l [OFE Nat α] {n} {mx : Option (Excl α)} {a : α} (h : ✓{n} (some (excl a) • mx)) : mx = none := by cases mx with | none => rfl | some _ => exact h.elim @[rocq_alias excl_validN_inv_r] -theorem validN_inv_some_r [OFE α] {n} {mx : Option (Excl α)} {a : α} +theorem validN_inv_some_r [OFE Nat α] {n} {mx : Option (Excl α)} {a : α} (h : ✓{n} (mx • some (excl a))) : mx = none := by cases mx with | none => rfl | some _ => exact h.elim @[rocq_alias excl_exclusive] -instance [OFE α] {x : Excl α} : CMRA.Exclusive x where exclusive0_l := fun _ a => a +instance [OFE Nat α] {x : Excl α} : CMRA.Exclusive x where exclusive0_l := fun _ a => a @[rocq_alias excl_cmra_discrete] -instance [OFE α] [OFE.Discrete α] : CMRA.Discrete (Excl α) where +instance [OFE Nat α] [OFE.Discrete α] : CMRA.Discrete (Excl α) where discrete_valid a := a @[rocq_alias ExclInvalid_included] -theorem invalid_inc [OFE α] (ea : Excl α) : ea ≼ invalid := by exists invalid +theorem invalid_inc [OFE Nat α] (ea : Excl α) : ea ≼ invalid := by exists invalid /-! ## Functors -/ @[rocq_alias excl_map_id] @@ -228,11 +231,11 @@ theorem map_comp (f : α → β) (g : β → γ) : cases x <;> simp @[rocq_alias excl_map_ext] -theorem map_ext [OFE α] [OFE β] (f g : α → β) (h : ∀ x, f x = g x) : map f x = map g x := by +theorem map_ext [OFE Nat α] [OFE Nat β] (f g : α → β) (h : ∀ x, f x = g x) : map f x = map g x := by cases x <;> simp [h] @[rocq_alias excl_map_ne] -theorem map_ne [OFE α] [OFE β] (f : α -n> β) : NonExpansive (map f) where +theorem map_ne [OFE Nat α] [OFE Nat β] (f : α -n> β) : NonExpansive (map f) where ne n x₁ x₂ h := by cases x₁ <;> cases x₂ <;> try trivial have ⟨hne⟩ := f.ne @@ -241,26 +244,26 @@ theorem map_ne [OFE α] [OFE β] (f : α -n> β) : NonExpansive (map f) where #rocq_ignore Excl_proper "Derivable from NonExpansive.eqv" @[rocq_alias excl_map_cmra_morphism] -def hom [OFE α] [OFE β] (f : α -n> β) : Excl α -C> Excl β := by +def hom [OFE Nat α] [OFE Nat β] (f : α -n> β) : Excl α -C> Excl β := by refine ⟨⟨map f, map_ne f⟩, ?_, ?_, ?_⟩ · intro n x h; cases x <;> trivial · intro x; trivial · intro x y; trivial @[rocq_alias exclO_map] -def oMap [OFE α] [OFE β] (f : α -n> β) : Excl α -n> Excl β := ⟨map f, map_ne f⟩ +def oMap [OFE Nat α] [OFE Nat β] (f : α -n> β) : Excl α -n> Excl β := ⟨map f, map_ne f⟩ @[rocq_alias exclO_map_ne] -instance oMap_ne [OFE α] [OFE β] : NonExpansive (oMap (α := α) (β := β)) where +instance oMap_ne [OFE Nat α] [OFE Nat β] : NonExpansive (oMap (α := α) (β := β)) where ne _ _ _ h x := by cases x with | excl _ => exact h _ | invalid => exact .rfl @[rocq_alias exclRF] -abbrev ExclOF (F : COFE.OFunctorPre) : COFE.OFunctorPre := +abbrev ExclOF (F : COFE.OFunctorPre Nat) : COFE.OFunctorPre Nat := fun A B _ _ => Excl (F A B) -instance {F} [COFE.OFunctor F] : RFunctor (ExclOF F) where +instance {F} [COFE.OFunctor Nat F] : RFunctor (ExclOF F) where cmra := inferInstance map f g := hom (COFE.OFunctor.map f g) map_ne.ne := by @@ -281,7 +284,7 @@ instance {F} [COFE.OFunctor F] : RFunctor (ExclOF F) where · trivial @[rocq_alias exclRF_contractive] -instance {F} [COFE.OFunctorContractive F] : RFunctorContractive (ExclOF F) where +instance {F} [COFE.OFunctorContractive Nat F] : RFunctorContractive (ExclOF F) where map_contractive.1 {n x y} HKL z := by rewrite [RFunctor.map] cases z diff --git a/Iris/Iris/Algebra/Frac.lean b/Iris/Iris/Algebra/Frac.lean index 1910dc332..e842a183d 100644 --- a/Iris/Iris/Algebra/Frac.lean +++ b/Iris/Iris/Algebra/Frac.lean @@ -62,7 +62,7 @@ instance instHDivQpQpQp : HDiv Qp Qp Qp where def Qp.divide_even (q : Qp) (n : Nat) (hn : 0 < n) : Qp := ⟨q.val / n, Rat.div_pos q.2 (by exact_mod_cast hn)⟩ -instance instCOFEQp : COFE Qp := COFE.ofDiscrete _ +instance instCOFEQp : COFE Nat Qp := COFE.ofDiscrete _ instance instCMRAQp : CMRA Qp where pcore _ := none diff --git a/Iris/Iris/Algebra/GenMap.lean b/Iris/Iris/Algebra/GenMap.lean index 7c23adeea..b54657064 100644 --- a/Iris/Iris/Algebra/GenMap.lean +++ b/Iris/Iris/Algebra/GenMap.lean @@ -89,9 +89,9 @@ def IsFree {β : α → Type _} (f : (a : α) → Option (β a)) : α → Prop : /-! ## OFE -/ section OFE -variable (β : Type _) [OFE β] +variable (β : Type _) [OFE Nat β] -instance instOFE_GenMap : OFE (GenMap β) where +instance instOFE_GenMap : OFE Nat (GenMap β) where Dist n := (·.car ≡{n}≡ ·.car) dist_eqv.refl _ := Dist.of_eq rfl dist_eqv.symm := Dist.symm @@ -104,7 +104,7 @@ instance instOFE_GenMap : OFE (GenMap β) where dist_lt := Dist.lt end OFE -theorem GenMap.singleton_discreteE {v : β} [OFE β] [DiscreteE v] : +theorem GenMap.singleton_discreteE {v : β} [OFE Nat β] [DiscreteE v] : DiscreteE (GenMap.singleton (β := β) k v) where discrete {y} H := OFE.eq_dist.mpr <| by intro n γ' @@ -114,7 +114,7 @@ theorem GenMap.singleton_discreteE {v : β} [OFE β] [DiscreteE v] : · next heq => simp only [heq, ite_true] at H ⊢; exact (Option.some_is_discrete.discrete H).dist · next hne => simp only [hne, ite_false] at H ⊢; exact (Option.none_is_discrete.discrete H).dist -theorem GenMap.empty_discreteE [OFE β] : DiscreteE (GenMap.empty (β := β)) where +theorem GenMap.empty_discreteE [OFE Nat β] : DiscreteE (GenMap.empty (β := β)) where discrete {y} H := OFE.eq_dist.mpr <| by intro n γ' specialize H γ' @@ -297,10 +297,10 @@ theorem GenMap.op_singleton_comm {mf : GenMap β} {x : Nat} (y : β) by_cases heq : k = x · subst heq simp only [CMRA.op, optionOp, alter, Iris.alter, singleton, empty, ↓reduceIte] - rw [H_free] + simp [H_free] · simp only [CMRA.op, optionOp, alter, Iris.alter, singleton, empty] have : x ≠ k := Ne.symm heq - rw [if_neg this, if_neg this] + simp [if_neg this] theorem GenMap.validN_op_comm {m mf : GenMap β} (x : Nat) (y : β) (H : IsFree mf.car x) : ✓{n} m.alter x (some y) • mf ↔ ✓{n} (m • mf).alter x (some y) := by @@ -310,10 +310,10 @@ theorem GenMap.validN_op_comm {m mf : GenMap β} (x : Nat) (y : β) (H : IsFree by_cases heq : k = x · subst heq simp only [CMRA.op, alter, Iris.alter, ↓reduceIte, optionOp] - rw [H] + simp [H] · simp only [CMRA.op, alter, Iris.alter] have : x ≠ k := Ne.symm heq - rw [if_neg this, if_neg this] + simp [if_neg this] end CMRA @@ -322,10 +322,10 @@ end CMRA section OFunctors open COFE CMRA -abbrev GenMapOF (F : OFunctorPre) : OFunctorPre := +abbrev GenMapOF (F : OFunctorPre Nat) : OFunctorPre Nat := fun A B _ _ => GenMap (F A B) -abbrev GenMap.lift [OFE α] [OFE β] (f : α -n> β) : GenMap α -n> GenMap β where +abbrev GenMap.lift [OFE Nat α] [OFE Nat β] (f : α -n> β) : GenMap α -n> GenMap β where f g := ⟨fun t => Option.map f (g.car t), by obtain ⟨N, hN⟩ := g.bound exact ⟨N, fun k hk => by simp [Option.map, hN k hk]⟩⟩ @@ -335,8 +335,8 @@ abbrev GenMap.lift [OFE α] [OFE β] (f : α -n> β) : GenMap α -n> GenMap β w split <;> split <;> simp_all exact NonExpansive.ne H -instance instOFunctor_GenMapOF (F : OFunctorPre) [OFunctor F] : - OFunctor (GenMapOF F) where +instance instOFunctor_GenMapOF (F : OFunctorPre Nat) [OFunctor Nat F] : + OFunctor Nat (GenMapOF F) where ofe {A B _ _} := instOFE_GenMap (F A B) map f₁ f₂ := GenMap.lift <| OFunctor.map (F := F) f₁ f₂ map_ne.ne {n x1 x2} Hx {y1 y2} Hy k γ := by @@ -352,7 +352,7 @@ instance instOFunctor_GenMapOF (F : OFunctorPre) [OFunctor F] : simp only [Option.map]; cases _ : x.car γ <;> simp exact (OFunctor.map_comp _ _ _ _ _).dist -instance instURFunctor_GenMapOF (F : COFE.OFunctorPre) [RFunctor F] : +instance instURFunctor_GenMapOF (F : COFE.OFunctorPre Nat) [RFunctor F] : URFunctor (GenMapOF F) where map f g := { toHom := GenMap.lift <| OFunctor.map f g @@ -388,7 +388,7 @@ instance instURFunctor_GenMapOF (F : COFE.OFunctorPre) [RFunctor F] : map_id x := OFunctor.map_id x map_comp f g f' g' x := OFunctor.map_comp f g f' g' x -instance instURFunctorContractive_GenMapOF (F : COFE.OFunctorPre) [RFunctorContractive F] : +instance instURFunctorContractive_GenMapOF (F : COFE.OFunctorPre Nat) [RFunctorContractive F] : URFunctorContractive (GenMapOF F) where map_contractive.1 h x γ := by next n x' y' => diff --git a/Iris/Iris/Algebra/Heap.lean b/Iris/Iris/Algebra/Heap.lean index 6dd4ca9d5..7841f2ac5 100644 --- a/Iris/Iris/Algebra/Heap.lean +++ b/Iris/Iris/Algebra/Heap.lean @@ -20,7 +20,7 @@ open OFE namespace PartialMap -instance instOFE [LawfulPartialMap M K] [OFE V] : OFE (M V) where +instance instOFE [LawfulPartialMap M K] [OFE Nat V] : OFE Nat (M V) where Dist n s0 s1 := get? s0 ≡{n}≡ get? s1 dist_eqv := ⟨fun _ => .of_eq rfl, (·.symm), (·.trans ·)⟩ eq_dist {s0 s1} := by @@ -28,54 +28,57 @@ instance instOFE [LawfulPartialMap M K] [OFE V] : OFE (M V) where exact ⟨fun h n k => Dist.of_eq (h k), fun h k => eq_dist.mpr fun n => h n k⟩ dist_lt := dist_lt -@[simp] def toMap [LawfulPartialMap M K] [OFE V] : (M V) -n> (K → Option V) where +@[simp] def toMap [LawfulPartialMap M K] [OFE Nat V] : (M V) -n> (K → Option V) where f x := get? x ne.1 {_ _ _} H k := H k -@[simp] def ofMap [LawfulPartialMap M K] [R : RepFunMap M K] [OFE V] : (K → Option V) -n> (M V) where +@[simp] def ofMap [LawfulPartialMap M K] [R : RepFunMap M K] [OFE Nat V] : (K → Option V) -n> (M V) where f x := of_fun x ne.1 {_ _ _} H k := by simp only [get_of_fun, H k] -instance get?_ne [LawfulPartialMap M K] [OFE V] (k : K) : NonExpansive (get? · k : M V → Option V) where +instance get?_ne [LawfulPartialMap M K] [OFE Nat V] (k : K) : NonExpansive (get? · k : M V → Option V) where ne {_ _ _} Ht := Ht k -instance [LawfulPartialMap M K] [OFE V] (k : K) : NonExpansive₂ (insert · k · : M V → V → M V) where +instance [LawfulPartialMap M K] [OFE Nat V] (k : K) : NonExpansive₂ (insert · k · : M V → V → M V) where ne {_ _ _} Hv {_ _} Ht k' := by by_cases h : k = k' · simp [get?_insert_eq h, Ht] · simp [get?_insert_ne h, Hv k'] -theorem eqv_of_Equiv [OFE V] [LawfulPartialMap M K] {t1 t2 : M V} (H : PartialMap.equiv t1 t2) : t1 = t2 := +theorem eqv_of_Equiv [OFE Nat V] [LawfulPartialMap M K] {t1 t2 : M V} (H : PartialMap.equiv t1 t2) : t1 = t2 := eq_dist.mpr fun _ k => Dist.of_eq (H k) -instance [LawfulPartialMap M K] [OFE V] (op : K → V → V → V) [∀ k, NonExpansive₂ (op k)] : +instance [LawfulPartialMap M K] [OFE Nat V] (op : K → V → V → V) [∀ k, NonExpansive₂ (op k)] : NonExpansive₂ (merge (M := M) op) where ne _ {_ _} Ht {_ _} Hs k := by simp only [get?_merge]; exact NonExpansive₂.ne (Ht k) (Hs k) /-- Project a chain of stores through its kth coordinate to a chain of values. -/ -def chain [LawfulPartialMap M K] [OFE V] (k : K) (c : Chain (M V)) : Chain (Option V) where +def chain [LawfulPartialMap M K] [OFE Nat V] (k : K) (c : Chain (M V)) : Chain (Option V) where chain i := get? (c i) k cauchy Hni := c.cauchy Hni k -theorem chain_get [LawfulPartialMap M K] [OFE V] (k : K) (c : Chain (M V)) : +theorem chain_get [LawfulPartialMap M K] [OFE Nat V] (k : K) (c : Chain (M V)) : (chain k c) i = get? (c i) k := by simp [chain] end PartialMap -instance Heap.instCOFE [LawfulPartialMap M K] [COFE V] : COFE (M V) where +instance Heap.instCOFE [LawfulPartialMap M K] [COFE Nat V] : COFE Nat (M V) where compl c := bindAlter (fun _ => COFE.compl <| c.map ⟨_, PartialMap.get?_ne ·⟩) (c 0) conv_compl {_ c} k := by rw [get?_bindAlter] rcases H : get? (c.chain 0) k · simp [← PartialMap.chain_get, chain_none_const (c := PartialMap.chain k c) (n := 0) (H▸rfl)] · exact IsCOFE.conv_compl + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry -instance instDiscreteHeap [LawfulPartialMap M K] [OFE V] [Discrete V] : Discrete (M V) where +instance instDiscreteHeap [LawfulPartialMap M K] [OFE Nat V] [Discrete V] : Discrete (M V) where discrete_0 h := OFE.eq_dist.mpr <| by intro _ k exact (Discrete.discrete_0 (h k)).dist -instance instDiscreteESingleton [LawfulPartialMap M K] [DecidableEq K] [OFE V] {v : V} +instance instDiscreteESingleton [LawfulPartialMap M K] [DecidableEq K] [OFE Nat V] {v : V} [ha : DiscreteE v] {k : K} : DiscreteE (PartialMap.singleton (M := M) k v) where discrete {y} h := OFE.eq_dist.mpr <| by intro n k' @@ -87,14 +90,14 @@ instance instDiscreteESingleton [LawfulPartialMap M K] [DecidableEq K] [OFE V] { refine (Option.none_is_discrete.discrete (.trans ?_ (h k'))).dist simp [LawfulPartialMap.get?_singleton, hh, ↓reduceIte] -instance instDiscreteEEmpty [LawfulPartialMap M K] [OFE V] : DiscreteE (∅ : M V) where +instance instDiscreteEEmpty [LawfulPartialMap M K] [OFE Nat V] : DiscreteE (∅ : M V) where discrete {y} h := OFE.eq_dist.mpr <| by intro n k simp only [LawfulPartialMap.get?_empty] refine (DiscreteE.discrete (.trans ?_ (h k))).dist simp [LawfulPartialMap.get?_empty] -theorem singleton_dist [LawfulPartialMap M K] [DecidableEq K] [OFE V] {n : Nat} {x y : V} +theorem singleton_dist [LawfulPartialMap M K] [DecidableEq K] [OFE Nat V] {n : Nat} {x y : V} (h : x ≡{n}≡ y) (k : K) : PartialMap.singleton (M := M) k x ≡{n}≡ PartialMap.singleton k y := by intro k' simp only [LawfulPartialMap.get?_singleton] @@ -573,30 +576,30 @@ namespace PartialMap def map (f : α → β) : H α → H β := PartialMap.bindAlter (fun _ a => some <| f a) -instance [OFE α] [OFE β] {f : α → β} [hne : OFE.NonExpansive f] : OFE.NonExpansive (map H f) where +instance [OFE Nat α] [OFE Nat β] {f : α → β} [hne : OFE.NonExpansive f] : OFE.NonExpansive (map H f) where ne := by simp only [OFE.Dist, Option.Forall₂, map, get?_bindAlter, Option.bind] refine fun n m1 m2 => forall_imp fun k => ?_ cases get? m1 k <;> cases get? m2 k <;> simp apply OFE.NonExpansive.ne -theorem map_id [OFE α] (a : H α) : +theorem map_id [OFE Nat α] (a : H α) : PartialMap.map H id a = a := OFE.eq_dist.mpr <| by intro n x simp [PartialMap.map, get?_bindAlter, Option.bind] rcases get? a x <;> simp -def mapO [OFE α] [OFE β] (f : α -n> β) : OFE.Hom (H α) (H β) where +def mapO [OFE Nat α] [OFE Nat β] (f : α -n> β) : OFE.Hom (H α) (H β) where f := map H f ne := inferInstance -theorem map_ne [OFE α] [OFE β] (f g : α -> β) {heq : f ≡{n}≡ g} : map H f m ≡{n}≡ map H g m := by +theorem map_ne [OFE Nat α] [OFE Nat β] (f g : α -> β) {heq : f ≡{n}≡ g} : map H f m ≡{n}≡ map H g m := by simp [OFE.Dist, Option.Forall₂, map, get?_bindAlter] intro k cases get? m k <;> simp exact heq _ -theorem map_compose [OFE α] [OFE β] [OFE γ] (f : α -> β) (g : β -> γ) m : +theorem map_compose [OFE Nat α] [OFE Nat β] [OFE Nat γ] (f : α -> β) (g : β -> γ) m : map H (g.comp f) m = map H g (map H f m) := OFE.eq_dist.mpr <| by intro n k simp [map, get?_bindAlter] @@ -627,10 +630,10 @@ def mapC [CMRA α] [CMRA β] (f : α -C> β) : CMRA.Hom (H α) (H β) where cases get? m1 k <;> cases get? m2 k <;> simp exact (CMRA.Hom.op f _ _).dist -abbrev PartialMapOF (F : COFE.OFunctorPre) : COFE.OFunctorPre := +abbrev PartialMapOF (F : COFE.OFunctorPre Nat) : COFE.OFunctorPre Nat := fun A B _ _ => H (F A B) -instance {F} [COFE.OFunctor F] : COFE.OFunctor (PartialMapOF H F) where +instance {F} [COFE.OFunctor Nat F] : COFE.OFunctor Nat (PartialMapOF H F) where ofe := inferInstance map f g := mapO H (COFE.OFunctor.map f g) map_ne {_} _ _ _ _ _ _ _ := by diff --git a/Iris/Iris/Algebra/HeapView.lean b/Iris/Iris/Algebra/HeapView.lean index 1610a221e..cb53c2edf 100644 --- a/Iris/Iris/Algebra/HeapView.lean +++ b/Iris/Iris/Algebra/HeapView.lean @@ -143,6 +143,7 @@ instance : NonExpansive (Frag k dq : _ → HeapView K V H) where · rw [Std.PartialMap.singleton, get?_insert_eq h, get?_singleton_eq h] exact dist_prod_ext rfl Hx · rw [Std.PartialMap.singleton, get?_insert_ne h, get?_empty, get?_singleton_ne h] + rfl variable {dp dq : DFrac} {n : Nat} {m1 m2 : H V} {k : K} {v1 v2 : V} @@ -496,7 +497,7 @@ section heapViewFunctor open Iris.Std PartialMap -theorem heapR_map_eq [COFE A] [COFE B] [COFE A'] [COFE B'] [RFunctor T] (f : A' -n> A) (g : B -n> B') +theorem heapR_map_eq [COFE Nat A] [COFE Nat B] [COFE Nat A'] [COFE Nat B'] [RFunctor T] (f : A' -n> A) (g : B -n> B') (n : Nat) (m : H (T A B)) (mv : H (DFrac × T A B)) : HeapR K (T A B) H n m mv → HeapR K (T A' B') H n @@ -528,7 +529,7 @@ theorem heapR_map_eq [COFE A] [COFE B] [COFE A'] [COFE B'] [RFunctor T] (f : A' · simp_all · exact (Hom.monoN _ _ he) -abbrev HeapViewURF T [RFunctor T] : COFE.OFunctorPre := +abbrev HeapViewURF T [RFunctor T] : COFE.OFunctorPre Nat := fun A B _ _ => HeapView K (T A B) H instance {T} [RFunctor T] : URFunctor (HeapViewURF (H := H) T) where diff --git a/Iris/Iris/Algebra/IProp.lean b/Iris/Iris/Algebra/IProp.lean index 368000934..30da51f26 100644 --- a/Iris/Iris/Algebra/IProp.lean +++ b/Iris/Iris/Algebra/IProp.lean @@ -22,7 +22,7 @@ abbrev GType := Nat set_option linter.checkUnivs false in @[rocq_alias gFunctor] -abbrev GFunctor := Σ F : OFunctorPre, RFunctorContractive F +abbrev GFunctor := Σ F : OFunctorPre Nat, RFunctorContractive F set_option linter.checkUnivs false in @[rocq_alias gFunctors] @@ -45,7 +45,7 @@ abbrev GName := Nat #rocq_ignore gnameO "Use `LeibnizO GName`." @[rocq_alias iResF] -abbrev IResF (GF : BundledGFunctors) : OFunctorPre := +abbrev IResF (GF : BundledGFunctors) : OFunctorPre Nat := DiscreteFunOF (fun i => GenMapOF (GF i).fst) #rocq_ignore subG "Superseded by `ElemG`." @@ -64,7 +64,7 @@ variable (GF : BundledGFunctors) def IPre : Type _ := OFunctor.Fix (UPredOF (IResF GF)) @[rocq_alias iProp_solution.iPreProp_cofe] -instance : COFE (IPre GF) := inferInstanceAs (COFE (OFunctor.Fix _)) +instance : COFE Nat (IPre GF) := inferInstanceAs (COFE Nat (OFunctor.Fix _)) @[rocq_alias iProp_solution.iResUR] def IResUR.{u} : Type u := (i : GType) → GenMap (GF i |>.fst (IPre GF) (IPre GF)) diff --git a/Iris/Iris/Algebra/LeibnizSet.lean b/Iris/Iris/Algebra/LeibnizSet.lean index 23cf2fc84..018427e2c 100644 --- a/Iris/Iris/Algebra/LeibnizSet.lean +++ b/Iris/Iris/Algebra/LeibnizSet.lean @@ -29,7 +29,7 @@ inductive DisjointLeibnizSet (S : Type _) where | valid : S → DisjointLeibnizSet S | error : DisjointLeibnizSet S -instance : COFE (DisjointLeibnizSet S) := COFE.ofDiscrete _ +instance : COFE Nat (DisjointLeibnizSet S) := COFE.ofDiscrete _ instance inst_disjointLeibnizSet_DiscreteE {S : Type _} (x : DisjointLeibnizSet S) : DiscreteE x := ⟨fun h => h⟩ @@ -300,7 +300,7 @@ end DisjointLeibnizSet inductive LeibnizSet (S : Type _) where | valid (s : S) -instance : COFE (LeibnizSet S) := COFE.ofDiscrete _ +instance : COFE Nat (LeibnizSet S) := COFE.ofDiscrete _ namespace LeibnizSet diff --git a/Iris/Iris/Algebra/Lib/DFracAgree.lean b/Iris/Iris/Algebra/Lib/DFracAgree.lean index e1a3665b1..660a438fb 100644 --- a/Iris/Iris/Algebra/Lib/DFracAgree.lean +++ b/Iris/Iris/Algebra/Lib/DFracAgree.lean @@ -25,12 +25,12 @@ open OFE CMRA DFrac namespace DFracAgree @[rocq_alias dfrac_agreeR] -abbrev DFracAgreeR (A : Type _) [OFE A] := DFrac × Agree A +abbrev DFracAgreeR (A : Type _) [OFE Nat A] := DFrac × Agree A @[rocq_alias to_dfrac_agree] -def mk [OFE A] (d : DFrac) (a : A) : DFracAgreeR A := (d, toAgree a) +def mk [OFE Nat A] (d : DFrac) (a : A) : DFracAgreeR A := (d, toAgree a) -variable {A : Type _} [OFE A] +variable {A : Type _} [OFE Nat A] instance mk_discarded_coreId {a : A} : CoreId (mk .discard a) := inferInstanceAs (CoreId (DFrac.discard, toAgree a)) @@ -133,9 +133,9 @@ theorem unpersist {a : A} : namespace Frac @[rocq_alias to_frac_agree] -def mk [OFE A] (q : Qp) (a : A) : DFracAgreeR A := DFracAgree.mk (.own q) a +def mk [OFE Nat A] (q : Qp) (a : A) : DFracAgreeR A := DFracAgree.mk (.own q) a -variable {A : Type _} [OFE A] +variable {A : Type _} [OFE Nat A] @[rocq_alias frac_agree_op] theorem mk_op {q₁ q₂ : Qp} {a : A} : mk (q₁ + q₂) a = mk q₁ a • mk q₂ a := @@ -172,8 +172,8 @@ end Frac /-! ## Functors -/ @[rocq_alias dfrac_agreeRF] -abbrev DFracAgreeRF (T : COFE.OFunctorPre) [COFE.OFunctor T] : COFE.OFunctorPre := - ProdOF (constOF DFrac) (AgreeRF T) +abbrev DFracAgreeRF (T : COFE.OFunctorPre Nat) [COFE.OFunctor Nat T] : COFE.OFunctorPre Nat := + ProdOF Nat (constOF DFrac) (AgreeRF T) end DFracAgree diff --git a/Iris/Iris/Algebra/Lib/ExclAuth.lean b/Iris/Iris/Algebra/Lib/ExclAuth.lean index f08dc11ee..01ad2d36f 100644 --- a/Iris/Iris/Algebra/Lib/ExclAuth.lean +++ b/Iris/Iris/Algebra/Lib/ExclAuth.lean @@ -25,7 +25,7 @@ open OFE CMRA Auth Excl Option namespace ExclAuth -variable [OFE A] +variable [OFE Nat A] @[rocq_alias excl_authR] abbrev ExclAuthR := Auth (Option (Excl A)) @@ -107,11 +107,11 @@ theorem update {a b a' : A} : ((●E a) • ◯E b) ~~> ((●E a') • ◯E a') /-! ## Functors -/ @[rocq_alias excl_authURF] -abbrev ExclAuthURF (T : COFE.OFunctorPre) [URFunctor T] : COFE.OFunctorPre := +abbrev ExclAuthURF (T : COFE.OFunctorPre Nat) [URFunctor T] : COFE.OFunctorPre Nat := AuthURF (OptionOF (ExclOF T)) @[rocq_alias excl_authRF] -abbrev ExclAuthRF (T : COFE.OFunctorPre) [URFunctor T] : COFE.OFunctorPre := +abbrev ExclAuthRF (T : COFE.OFunctorPre Nat) [URFunctor T] : COFE.OFunctorPre Nat := AuthRF (OptionOF (ExclOF T)) end ExclAuth diff --git a/Iris/Iris/Algebra/Lib/FracAuth.lean b/Iris/Iris/Algebra/Lib/FracAuth.lean index 6e8c7a4cc..8dff2e53b 100644 --- a/Iris/Iris/Algebra/Lib/FracAuth.lean +++ b/Iris/Iris/Algebra/Lib/FracAuth.lean @@ -271,11 +271,11 @@ theorem updateP_both_unpersist {q : Qp} {a b : A} : /-! ## Functors -/ @[rocq_alias frac_authURF] -abbrev FracAuthURF (T : COFE.OFunctorPre) [RFunctor T] : COFE.OFunctorPre := - AuthURF (OptionOF (ProdOF (constOF (Qp)) T)) +abbrev FracAuthURF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := + AuthURF (OptionOF (ProdOF Nat (constOF (Qp)) T)) @[rocq_alias frac_authRF] -abbrev FracAuthF (T : COFE.OFunctorPre) [RFunctor T] : COFE.OFunctorPre := - AuthRF (OptionOF (ProdOF (constOF (Qp)) T)) +abbrev FracAuthF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := + AuthRF (OptionOF (ProdOF Nat (constOF (Qp)) T)) end FracAuth diff --git a/Iris/Iris/Algebra/Lib/MonoNat.lean b/Iris/Iris/Algebra/Lib/MonoNat.lean index 31cc5078c..75163c6e7 100644 --- a/Iris/Iris/Algebra/Lib/MonoNat.lean +++ b/Iris/Iris/Algebra/Lib/MonoNat.lean @@ -28,7 +28,7 @@ scoped instance : LawfulLeftIdentity (Add.add (α := MaxNat)) (0 : MaxNat) where left_id := Nat.zero_max scoped instance : Std.IdempotentOp (Add.add (α := MaxNat)) where idempotent x := by simp [Add.add] -scoped instance : COFE MaxNat := COFE.ofDiscrete _ +scoped instance : COFE Nat MaxNat := COFE.ofDiscrete _ scoped instance : OFE.Discrete MaxNat := ⟨fun h => h⟩ scoped instance : UCMRA MaxNat := OrdCommMonoidLike.instUCMRAOfLawfulLeftIdentityAddZero scoped instance : CMRA.Discrete MaxNat := OrdCommMonoidLike.instDiscrete diff --git a/Iris/Iris/Algebra/Monoid.lean b/Iris/Iris/Algebra/Monoid.lean index 887103d48..a73acbd16 100644 --- a/Iris/Iris/Algebra/Monoid.lean +++ b/Iris/Iris/Algebra/Monoid.lean @@ -6,6 +6,7 @@ Authors: Zongyuan Liu module public import Iris.Algebra.OFE +public import Iris.Algebra.StepIndexFinite meta import Iris.Std.RocqPorting public section @@ -20,12 +21,10 @@ namespace Iris.Algebra open OFE -variable {SI : outParam <| Type _} [SIdx SI] - /-- A commutative monoid on an OFE, used for big operators. The operation must be non-expansive, associative, commutative, and have a left identity. -/ @[rocq_alias Monoid] -class MonoidOps {M : Type u} [OFE SI M] (op : M → M → M) (unit : outParam M) where +class MonoidOps {M : Type u} [OFE Nat M] (op : M → M → M) (unit : outParam M) where /-- The operation is non-expansive in both arguments -/ op_ne : NonExpansive₂ op /-- Associativity -/ @@ -42,7 +41,7 @@ namespace MonoidOps attribute [instance] op_ne -variable {M : Type u} [OFE SI M] {unit : M} {op : M → M → M} +variable {M : Type u} [OFE Nat M] {unit : M} {op : M → M → M} #rocq_ignore monoid_proper "OFE is Leibniz; use equality" @@ -79,7 +78,7 @@ end MonoidOps /-- A weak monoid homomorphism preserves the operation but not necessarily the unit. -/ @[rocq_alias WeakMonoidHomomorphism] -class WeakMonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE SI M₁] [OFE SI M₂] +class WeakMonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] (op₁ : M₁ → M₁ → M₁) (op₂ : M₂ → M₂ → M₂) (unit₁ : M₁) (unit₂ : M₂) [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] (R : M₂ → M₂ → Prop) (f : M₁ → M₂) where @@ -98,7 +97,7 @@ class WeakMonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE SI M₁] [OFE /-- A monoid homomorphism preserves both the operation and the unit. -/ @[rocq_alias MonoidHomomorphism] -class MonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE SI M₁] [OFE SI M₂] +class MonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] (op₁ : M₁ → M₁ → M₁) (op₂ : M₂ → M₂ → M₂) (unit₁ : M₁) (unit₂ : M₂) [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] (R : M₂ → M₂ → Prop) (f : M₁ → M₂) diff --git a/Iris/Iris/Algebra/Numbers.lean b/Iris/Iris/Algebra/Numbers.lean index 915a2722f..787aae38d 100644 --- a/Iris/Iris/Algebra/Numbers.lean +++ b/Iris/Iris/Algebra/Numbers.lean @@ -40,7 +40,7 @@ namespace CommMonoidLike open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA -variable [OFE α] [Discrete α] +variable [OFE Nat α] [Discrete α] variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))] variable [Zero α] [LawfulLeftIdentity (add (α := α)) zero] variable {x y x' y' : α} @@ -132,7 +132,7 @@ namespace OrdCommMonoidLike open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA IdempotentOp -variable [OFE α] [OFE.Discrete α] +variable [OFE Nat α] [OFE.Discrete α] variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))] variable [IdempotentOp (add (α := α))] variable [Zero α] @@ -226,7 +226,7 @@ namespace PosCommMonoidLike open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA IdempotentOp -variable [OFE α] [Discrete α] +variable [OFE Nat α] [Discrete α] variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))] variable [IdempotentOp (add (α := α))] diff --git a/Iris/Iris/Algebra/ReservationMap.lean b/Iris/Iris/Algebra/ReservationMap.lean index 2bfc7bc0a..9a8e38d2b 100644 --- a/Iris/Iris/Algebra/ReservationMap.lean +++ b/Iris/Iris/Algebra/ReservationMap.lean @@ -56,12 +56,12 @@ section OFE open OFE -variable [LawfulPartialMap H Pos] [OFE A] +variable [LawfulPartialMap H Pos] [OFE Nat A] #rocq_ignore reservation_map_ofe_mixin "Not needed" @[rocq_alias reservation_mapO] -instance : OFE (ReservationMap A H) where +instance : OFE Nat (ReservationMap A H) where Dist n x y := x.data ≡{n}≡ y.data ∧ x.token ≡{n}≡ y.token dist_eqv := { refl _ := ⟨.rfl, rfl⟩, diff --git a/Iris/Iris/Algebra/StepIndexFinite.lean b/Iris/Iris/Algebra/StepIndexFinite.lean index 4bb619e77..5c9e87b3b 100644 --- a/Iris/Iris/Algebra/StepIndexFinite.lean +++ b/Iris/Iris/Algebra/StepIndexFinite.lean @@ -57,4 +57,8 @@ theorem Contractive.succNat [OFE Nat α] [OFE Nat β] (f : α → β) [Contracti (h : x ≡{n}≡ y) : f x ≡{n.succ}≡ f y := Contractive.distLater_dist <| distLater_succ.mpr h +instance DiscreteO.instCOFE_Nat {α : Type _} : COFE Nat (DiscreteO α) := DiscreteO.instCOFE +instance DiscreteO.discrete_Nat {α : Type _} : OFE.Discrete (SI := Nat) (DiscreteO α) := DiscreteO.OFE +instance unitCOFE_Nat : COFE Nat Unit := COFE.unitCOFE + end OFE diff --git a/Iris/Iris/Algebra/UFrac.lean b/Iris/Iris/Algebra/UFrac.lean index 6ee7910e8..8035932af 100644 --- a/Iris/Iris/Algebra/UFrac.lean +++ b/Iris/Iris/Algebra/UFrac.lean @@ -36,7 +36,7 @@ namespace UFrac #rocq_ignore ufrac_pcore_instance "Use CMRA instance" #rocq_ignore ufrac_valid_instance "Use CMRA instance" -@[simp] instance : COFE UFrac := COFE.ofDiscrete _ +@[simp] instance : COFE Nat UFrac := COFE.ofDiscrete _ instance : OFE.Discrete UFrac := ⟨fun h => h⟩ @[simp] theorem dist_iff {n} {x y : UFrac} : x ≡{n}≡ y ↔ x = y := Iff.rfl diff --git a/Iris/Iris/Algebra/UPred.lean b/Iris/Iris/Algebra/UPred.lean index 3adf78773..eff13556a 100644 --- a/Iris/Iris/Algebra/UPred.lean +++ b/Iris/Iris/Algebra/UPred.lean @@ -63,7 +63,7 @@ variable [UCMRA M] open UPred @[rocq_alias uPredO] -instance : OFE (UPred M) where +instance : OFE Nat (UPred M) where Dist n P Q := ∀ n' (x : M), n' ≤ n → (p : ✓{n'} x) → (P n' ⟨x, p⟩ ↔ Q n' ⟨x, p⟩) dist_eqv := { refl _ _ _ _ _ := .rfl @@ -95,7 +95,7 @@ theorem uPred_holds_ne {P Q : UPred M} {n₁ n₂} {x : M} (HPQ _ _ .refl Hx).mpr (Q.mono HQ .rfl Hn) @[rocq_alias uPred_cofe] -instance : IsCOFE (UPred M) where +instance : IsCOFE Nat (UPred M) where compl c := { holds n x := ∀ n', (Hle : n' ≤ n) → (c n') n' (x.le Hle) mono {n1 n2 x1 x2 HP Hx12 Hn12 n3 Hn23} := by @@ -106,10 +106,13 @@ instance : IsCOFE (UPred M) where refine .trans ?_ (c.cauchy Hin _ _ .refl Hv).symm refine ⟨fun H => H _ .refl, fun H n' Hn' => ?_⟩ exact (c.cauchy Hn' _ _ .refl _).mp (mono _ H .rfl Hn') + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore uPred_compl "Inlined in the `IsCOFE` construction" -abbrev UPredOF (F : COFE.OFunctorPre) [URFunctor F] : COFE.OFunctorPre := +abbrev UPredOF (F : COFE.OFunctorPre Nat) [URFunctor F] : COFE.OFunctorPre Nat := fun A B _ _ => UPred (F B A) @[rocq_alias uPredO_map] @@ -123,7 +126,7 @@ def uPred_map [UCMRA α] [UCMRA β] (f : β -C> α) : UPred α -n> UPred β := b #rocq_ignore uPred_map "Inlined in `uPred_map`" @[rocq_alias uPredOF] -instance [URFunctor F] : COFE.OFunctor (UPredOF F) where +instance [URFunctor F] : COFE.OFunctor Nat (UPredOF F) where ofe := inferInstance map f g := uPred_map (URFunctor.map (F := F) g f) map_ne.ne _ _ _ Hx _ _ Hy _ _ z2 Hn _ := by @@ -139,7 +142,7 @@ instance [URFunctor F] : COFE.OFunctor (UPredOF F) where simp only [URFunctor.map_comp] @[rocq_alias uPredOF_contractive] -instance instUPredOFunctorContractive [URFunctorContractive F] : COFE.OFunctorContractive (UPredOF F) where +instance instUPredOFunctorContractive [URFunctorContractive F] : COFE.OFunctorContractive Nat (UPredOF F) where map_contractive.1 {n x y} HKL P m a Hmn Ha := by refine uPred_ne (P := P) <| ((URFunctorContractive.map_contractive.1 (x := (x.snd, x.fst)) (y := (y.snd, y.fst))) ?_ a).le Hmn diff --git a/Iris/Iris/Algebra/View.lean b/Iris/Iris/Algebra/View.lean index d1a0c555c..90d695f54 100644 --- a/Iris/Iris/Algebra/View.lean +++ b/Iris/Iris/Algebra/View.lean @@ -21,19 +21,19 @@ open Iris abbrev ViewRel (A B : Type _) := Nat → A → B → Prop @[rocq_alias view_rel] -class IsViewRel [OFE A] [UCMRA B] (R : ViewRel A B) where +class IsViewRel [OFE Nat A] [UCMRA B] (R : ViewRel A B) where mono : R n1 a1 b1 → a1 ≡{n2}≡ a2 → b2 ≼{n2} b1 → n2 ≤ n1 → R n2 a2 b2 rel_validN n a b : R n a b → ✓{n} b rel_unit n : ∃ a, R n a UCMRA.unit @[rocq_alias ViewRelDiscrete] -class IsViewRelDiscrete [OFE A] [UCMRA B] (R : ViewRel A B) extends IsViewRel R where +class IsViewRelDiscrete [OFE Nat A] [UCMRA B] (R : ViewRel A B) extends IsViewRel R where discrete n a b : R 0 a b → R n a b namespace ViewRel open IsViewRel DFrac -variable [OFE A] [UCMRA B] {R : ViewRel A B} [IsViewRel R] +variable [OFE Nat A] [UCMRA B] {R : ViewRel A B} [IsViewRel R] @[rocq_alias view_rel_ne] theorem iff_of_dist (Ha : a1 ≡{n}≡ a2) (Hb : b1 ≡{n}≡ b2) : R n a1 b1 ↔ R n a2 b2 := @@ -62,7 +62,7 @@ notation "◯V " b => View.Frag b namespace View section OFE open OFE UCMRA -variable [OFE A] [OFE B] {R : ViewRel A B} +variable [OFE Nat A] [OFE Nat B] {R : ViewRel A B} #rocq_ignore view_equiv "OFE is Leibniz; use equality" @@ -70,7 +70,7 @@ variable [OFE A] [OFE B] {R : ViewRel A B} def dist (n : Nat) (x y : View R) : Prop := x.auth ≡{n}≡ y.auth ∧ x.frag ≡{n}≡ y.frag @[rocq_alias view_ofe_mixin] -instance : OFE (View R) where +instance instOFE : OFE Nat (View R) where Dist := dist dist_eqv := { refl _ := ⟨.of_eq rfl, .of_eq rfl⟩ @@ -151,7 +151,7 @@ end OFE section CMRA open IsViewRel toAgree OFE DFrac -variable [OFE A] [UCMRA B] {R : ViewRel A B} [IsViewRel R] +variable [OFE Nat A] [UCMRA B] {R : ViewRel A B} [IsViewRel R] theorem IsViewRel.of_agree_dist_iff (Hb : b' ≡{n}≡ b) : (∃ a', toAgree a ≡{n}≡ toAgree a' ∧ R n a' b') ↔ R n a b := by @@ -628,7 +628,7 @@ end CMRA section Updates -variable [OFE A] [IB : UCMRA B] {R : ViewRel A B} [IsViewRel R] +variable [OFE Nat A] [IB : UCMRA B] {R : ViewRel A B} [IsViewRel R] open CMRA DFrac @@ -822,16 +822,16 @@ theorem map_compose {R : ViewRel A B} {R' : ViewRel A' B'} {R'' : ViewRel A'' B' section mapO -variable [OFE A] [OFE B] [OFE A'] [OFE B'] {R : ViewRel A B} {R' : ViewRel A' B'} +variable [OFE Nat A] [OFE Nat B] [OFE Nat A'] [OFE Nat B'] {R : ViewRel A B} {R' : ViewRel A' B'} -theorem map_compose' [OFE A''] [OFE B''] {R'' : ViewRel A'' B''} +theorem map_compose' [OFE Nat A''] [OFE Nat B''] {R'' : ViewRel A'' B''} f g (f' : A' -n> A'') (g' : B' -n> B'') (v : View R) : View.map R'' (f'.comp f) (g'.comp g) v = View.map R'' f' g' (View.map R' f g v) := map_compose f.f g.f f'.f g'.f v #rocq_ignore view_map_ext "OFE is Leibniz; use equality" -omit [OFE B] in +omit [OFE Nat B] in theorem map_ne {f1 f2 : A → A'} {g1 g2 : B → B'} [OFE.NonExpansive f1] [OFE.NonExpansive f2] (v : View R) (h1 : ∀ a, f1 a ≡{n}≡ f2 a) (h2 : ∀ b, g1 b ≡{n}≡ g2 b) : View.map R' f1 g1 v ≡{n}≡ View.map R' f2 g2 v := by @@ -859,7 +859,7 @@ def mapO (f : A -n> A') (g : B -n> B') : View R -n> View R' where end mapO @[rocq_alias view_map_cmra_morphism] -def mapC [OFE A] [UCMRA B] [OFE A'] [UCMRA B'] +def mapC [OFE Nat A] [UCMRA B] [OFE Nat A'] [UCMRA B'] {R : ViewRel A B} [IsViewRel R] {R' : ViewRel A' B'} [IsViewRel R'] (f : A -n> A') (g : B -C> B') (H : ∀ n a b, R n a b → R' n (f a) (g b)) : View R -C> View R' where diff --git a/Iris/Iris/BI/Algebra.lean b/Iris/Iris/BI/Algebra.lean index fc6806e3a..3386357e1 100644 --- a/Iris/Iris/BI/Algebra.lean +++ b/Iris/Iris/BI/Algebra.lean @@ -207,7 +207,7 @@ section agree_inclusion open Iris BI Agree OFE -variable [Sbi PROP] [OFE A] +variable [Sbi PROP] [OFE Nat A] @[rocq_alias agree_equivI] theorem agree_equivI {a b : A} : toAgree a ≡ toAgree b ⊣⊢@{PROP} a ≡ b := by @@ -351,7 +351,7 @@ theorem auth_both_validI (a b : A) : end auth section dfrac_agree -variable [Sbi PROP] {A : Type _} [OFE A] +variable [Sbi PROP] {A : Type _} [OFE Nat A] open BI diff --git a/Iris/Iris/BI/BI.lean b/Iris/Iris/BI/BI.lean index 353cfe7e8..469c1595b 100644 --- a/Iris/Iris/BI/BI.lean +++ b/Iris/Iris/BI/BI.lean @@ -6,6 +6,7 @@ Authors: Lars König, Mario Carneiro module public import Iris.Algebra.OFE +public import Iris.Algebra.StepIndexFinite public import Iris.BI.BIBase @[expose] public section @@ -21,7 +22,7 @@ theorem liftRel_eq : liftRel (@Eq α) A B ↔ A = B := by simp [liftRel, forall_and, iff_def, funext_iff] /-- Require that a separation logic with carrier type `PROP` fulfills all necessary axioms. -/ -class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where +class BI (PROP : Type _) extends COFE Nat PROP, BI.BIBase PROP where entails_refl {P : PROP} : P ⊢ P entails_trans {P Q R : PROP} : (P ⊢ Q) → (Q ⊢ R) → P ⊢ R equiv_iff {P Q : PROP} : (P = Q) ↔ P ⊣⊢ Q := by rw [OFE.eq_dist]; simp diff --git a/Iris/Iris/BI/BigOp/BigOp.lean b/Iris/Iris/BI/BigOp/BigOp.lean index 00ed9a6eb..13a7270fb 100644 --- a/Iris/Iris/BI/BigOp/BigOp.lean +++ b/Iris/Iris/BI/BigOp/BigOp.lean @@ -39,7 +39,7 @@ instance orMonoidOps [BI PROP] : MonoidOps (or (PROP := PROP)) iprop(False) wher /-! ## Homomorphism helpers for OFE equivalence -/ /-- Build a `MonoidHomomorphism` for Leibniz equality from just the essential fields. -/ -theorem MonoidHomomorphism.ofEq [OFE PROP] {op₁ op₂ : PROP → PROP → PROP} +theorem MonoidHomomorphism.ofEq [OFE Nat PROP] {op₁ op₂ : PROP → PROP → PROP} {u₁ u₂ : PROP} [MonoidOps op₁ u₁] [MonoidOps op₂ u₂] {f : PROP → PROP} (hne : NonExpansive f) (hop : ∀ {x y}, f (op₁ x y) = op₂ (f x) (f y)) (hunit : f u₁ = u₂) : MonoidHomomorphism op₁ op₂ u₁ u₂ (· = ·) f where @@ -51,7 +51,7 @@ theorem MonoidHomomorphism.ofEq [OFE PROP] {op₁ op₂ : PROP → PROP → PROP map_unit := hunit /-- Build a `WeakMonoidHomomorphism` for Leibniz equality from just the essential fields. -/ -theorem WeakMonoidHomomorphism.ofEq [OFE PROP] {op₁ op₂ : PROP → PROP → PROP} +theorem WeakMonoidHomomorphism.ofEq [OFE Nat PROP] {op₁ op₂ : PROP → PROP → PROP} {u₁ u₂ : PROP} [MonoidOps op₁ u₁] [MonoidOps op₂ u₂] {f : PROP → PROP} (hne : NonExpansive f) (hop : ∀ {x y}, f (op₁ x y) = op₂ (f x) (f y)) : WeakMonoidHomomorphism op₁ op₂ u₁ u₂ (· = ·) f where diff --git a/Iris/Iris/BI/BigOp/BigSepList.lean b/Iris/Iris/BI/BigOp/BigSepList.lean index ad57deb0d..28e9f7c60 100644 --- a/Iris/Iris/BI/BigOp/BigSepList.lean +++ b/Iris/Iris/BI/BigOp/BigSepList.lean @@ -1193,7 +1193,7 @@ theorem bigSepL2_lookup_acc_impl {Φ : Nat → A → B → PROP} {l1 : List A} { (and_intro (pure_intro hki) .rfl).trans imp_elim_right @[rocq_alias big_sepL2_ne_2] -theorem bigSepL2_dist_2 [OFE A] [OFE B] +theorem bigSepL2_dist_2 [OFE Nat A] [OFE Nat B] {Φ Ψ : Nat → A → B → PROP} {l1 l1' : List A} {l2 l2' : List B} {n : Nat} (hl1 : l1.length = l1'.length) (hl2 : l2.length = l2'.length) (hel1 : ∀ {k : Nat} {x x' : A}, l1[k]? = some x → l1'[k]? = some x' → x ≡{n}≡ x') @@ -1210,7 +1210,7 @@ theorem bigSepL2_dist_2 [OFE A] [OFE B] (fun {k} => @hel1 (k + 1)) (fun {k} => @hel2 (k + 1)) (fun {k} => @hf (k + 1)) @[rocq_alias big_sepL2_proper_2] -theorem bigSepL2_proper_2 [OFE A] [OFE B] +theorem bigSepL2_proper_2 [OFE Nat A] [OFE Nat B] {Φ Ψ : Nat → A → B → PROP} {l1 l1' : List A} {l2 l2' : List B} (hl1 : l1.length = l1'.length) (hl2 : l2.length = l2'.length) (hel1 : ∀ {k : Nat} {x x' : A}, l1[k]? = some x → l1'[k]? = some x' → x = x') diff --git a/Iris/Iris/BI/DerivedLaws.lean b/Iris/Iris/BI/DerivedLaws.lean index 41e49dc7a..b523f8b83 100644 --- a/Iris/Iris/BI/DerivedLaws.lean +++ b/Iris/Iris/BI/DerivedLaws.lean @@ -2182,7 +2182,7 @@ theorem bigOp_and_cons [BI PROP] {P : PROP} {Ps : List PROP} : /-! # Limits -/ @[rocq_alias bi.limit_preserving_entails] -theorem LimitPreserving.entails [BI PROP] [COFE A] (Φ Ψ : A → PROP) [Φne : OFE.NonExpansive Φ] +theorem LimitPreserving.entails [BI PROP] [COFE Nat A] (Φ Ψ : A → PROP) [Φne : OFE.NonExpansive Φ] [Ψne : OFE.NonExpansive Ψ] : LimitPreserving (λ x ↦ Φ x ⊢ Ψ x) := by refine .ext (P := λ x ↦ True ⊣⊢ (Φ x → Ψ x)) (@fun x => ?_) ?_ · exact ⟨(true_and.2.trans <| imp_elim ·.1), (⟨imp_intro <| true_and.1.trans ·, true_intro⟩)⟩ @@ -2191,29 +2191,29 @@ theorem LimitPreserving.entails [BI PROP] [COFE A] (Φ Ψ : A → PROP) [Φne : f x := iprop(Φ x → Ψ x), ne.ne _ {_ _} x := imp_ne.ne (Φne.ne x) (Ψne.ne x) } - refine fun c h' => ?_ - refine BIBase.BiEntails.of_eq (LimitPreserving.equiv f g _ ?_) + refine ⟨fun c h' => ?_, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ + refine BIBase.BiEntails.of_eq ((LimitPreserving.equiv f g).compl _ ?_) exact fun n => (h' n).to_eq @[rocq_alias bi.limit_preserving_Persistent] -instance limitPreserving_persistent [BI PROP] [COFE A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : - LimitPreserving (fun x => Persistent (Φ x)) := by +theorem limitPreserving_persistent [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : + LimitPreserving (fun x => Persistent (Φ x)) := by letI _ : OFE.NonExpansive fun x => iprop( Φ x) := .comp persistently_ne Φne - refine fun c h => ⟨?_⟩ - refine LimitPreserving.entails _ (fun x => iprop( (Φ x))) _ ?_ + refine ⟨fun c h => ⟨?_⟩, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ + refine (LimitPreserving.entails _ (fun x => iprop( (Φ x)))).compl _ ?_ exact (fun n => h n |>.persistent) -instance limitPreserving_absorbing [BI PROP] [COFE A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : - LimitPreserving (fun x => Absorbing (Φ x)) := by +theorem limitPreserving_absorbing [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : + LimitPreserving (fun x => Absorbing (Φ x)) := by letI _ : OFE.NonExpansive fun x => iprop( Φ x) := .comp absorbingly_ne Φne - refine fun c h => ⟨?_⟩ - refine LimitPreserving.entails (fun x => iprop( (Φ x))) _ _ ?_ + refine ⟨fun c h => ⟨?_⟩, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ + refine (LimitPreserving.entails (fun x => iprop( (Φ x))) _).compl _ ?_ exact (fun n => h n |>.absorbing) -instance limitPreserving_affine [BI PROP] [COFE A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : - LimitPreserving (fun x => Affine (Φ x)) := by - refine fun c h => ⟨?_⟩ - refine LimitPreserving.entails (fun x => iprop((Φ x))) (fun _ => iprop(emp)) _ ?_ +theorem limitPreserving_affine [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : + LimitPreserving (fun x => Affine (Φ x)) := by + refine ⟨fun c h => ⟨?_⟩, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ + refine (LimitPreserving.entails (fun x => iprop((Φ x))) (fun _ => iprop(emp))).compl _ ?_ exact (fun n => h n |>.affine) @[rocq_alias bi.iter_modal_intro] diff --git a/Iris/Iris/BI/Embedding.lean b/Iris/Iris/BI/Embedding.lean index f20eaba10..99eb6daab 100644 --- a/Iris/Iris/BI/Embedding.lean +++ b/Iris/Iris/BI/Embedding.lean @@ -428,7 +428,7 @@ theorem embed_si_pure (Pi : SiProp) : siPure_siEmpValid_elim⟩ @[rocq_alias embed_internal_eq] -theorem embed_internal_eq {A : Type _} [OFE A] (x y : A) : +theorem embed_internal_eq {A : Type _} [OFE Nat A] (x y : A) : (embed (iprop(x ≡ y) : P1) : P2) ⊣⊢ x ≡ y := embed_si_pure (SiProp.internalEq x y) diff --git a/Iris/Iris/BI/InternalEq.lean b/Iris/Iris/BI/InternalEq.lean index 0a449a954..00d7eb9df 100644 --- a/Iris/Iris/BI/InternalEq.lean +++ b/Iris/Iris/BI/InternalEq.lean @@ -17,7 +17,7 @@ open BI OFE Iris.Std /-- Internal equality in a BI with step-indexed structure, defined as `siPure (SiProp.internalEq a b)`. -/ @[rocq_alias internal_eq] -def internalEq [Sbi PROP] {A : Type _} [OFE A] (a b : A) : PROP := +def internalEq [Sbi PROP] {A : Type _} [OFE Nat A] (a b : A) : PROP := iprop( (SiProp.internalEq a b)) syntax:40 term:40 " ≡ " term:41 : term @@ -36,35 +36,35 @@ variable {PROP : Type u} [Sbi PROP] {P Q : PROP} namespace internalEq @[rocq_alias internal_eq_ne] -instance instInternalEq_ne (A : Type _) [OFE A] : +instance instInternalEq_ne (A : Type _) [OFE Nat A] : NonExpansive₂ (internalEq (PROP := PROP) (A := A)) where ne _ _ _ h₁ _ _ h₂ := Sbi.siPure_ne.ne (SiProp.instNonExpansive₂InternalEq.ne h₁ h₂) #rocq_ignore internal_eq_proper "Derivable from internal_eq_ne with NonExpansive.eqv" -theorem ne_l {A : Type _} [OFE A] (a : A) : +theorem ne_l {A : Type _} [OFE Nat A] (a : A) : NonExpansive (internalEq (PROP := PROP) · a) := NonExpansive₂.ne_left internalEq a -theorem ne_r {A : Type _} [OFE A] (a : A) : +theorem ne_r {A : Type _} [OFE Nat A] (a : A) : NonExpansive (internalEq (PROP := PROP) a ·) := NonExpansive₂.ne_right internalEq a @[rocq_alias internal_eq_refl] -theorem refl {A : Type _} [OFE A] {P : PROP} {a : A} : P ⊢ a ≡ a := +theorem refl {A : Type _} [OFE Nat A] {P : PROP} {a : A} : P ⊢ a ≡ a := true_intro.trans <| siPure_pure.mpr.trans <| siPure_mono (SiProp.internalEq_refl _ _) @[rocq_alias equiv_internal_eq] -theorem of_equiv {A : Type _} [OFE A] {P : PROP} {a b : A} (h : a = b) : +theorem of_equiv {A : Type _} [OFE Nat A] {P : PROP} {a b : A} (h : a = b) : P ⊢ a ≡ b := h ▸ refl @[rocq_alias pure_internal_eq] -theorem of_pure {A : Type _} [OFE A] {x y : A} : ⌜x = y⌝ ⊢@{PROP} iprop(x ≡ y) := +theorem of_pure {A : Type _} [OFE Nat A] {x y : A} : ⌜x = y⌝ ⊢@{PROP} iprop(x ≡ y) := pure_elim' of_equiv @[rocq_alias internal_eq_rewrite] -theorem rewrite {A : Type _} [OFE A] {a b : A} (Ψ : A → PROP) [hΨ : NonExpansive Ψ] : +theorem rewrite {A : Type _} [OFE Nat A] {a b : A} (Ψ : A → PROP) [hΨ : NonExpansive Ψ] : a ≡ b ⊢ Ψ a → Ψ b := by let Φ : A → SiProp := fun a' => iprop( (True -∗ Ψ a → Ψ a')) letI _ : NonExpansive Φ := @@ -81,23 +81,23 @@ theorem rewrite {A : Type _} [OFE A] {a b : A} (Ψ : A → PROP) [hΨ : NonExpan _ ⊢ Ψ a → Ψ b := emp_sep.2.trans <| (sep_mono_left true_intro).trans wand_elim_right @[rocq_alias internal_eq_rewrite'] -theorem rewrite' {A : Type _} [OFE A] {a b : A} (Ψ : A → PROP) [NonExpansive Ψ] +theorem rewrite' {A : Type _} [OFE Nat A] {a b : A} (Ψ : A → PROP) [NonExpansive Ψ] (Heq : P ⊢ a ≡ b) (HΨa : P ⊢ Ψ a) : P ⊢ Ψ b := (and_intro .rfl HΨa).trans <| (and_mono_left Heq).trans <| imp_elim (rewrite Ψ) @[rocq_alias internal_eq_sym] -theorem symm {A : Type _} [OFE A] {a b : A} : a ≡ b ⊢@{PROP} b ≡ a := +theorem symm {A : Type _} [OFE Nat A] {a b : A} : a ≡ b ⊢@{PROP} b ≡ a := letI _ := ne_l (PROP := PROP) a rewrite' (internalEq · a) .rfl refl @[rocq_alias internal_eq_trans] -theorem trans {A : Type _} [OFE A] {a b c : A} : +theorem trans {A : Type _} [OFE Nat A] {a b c : A} : a ≡ b ∧ b ≡ c ⊢@{PROP} a ≡ c := letI _ := ne_l (PROP := PROP) c rewrite' (internalEq · c) (and_elim_l.trans symm) and_elim_r @[rocq_alias f_equivI] -theorem of_internalEquiv_ne {A B : Type _} [OFE A] [OFE B] (f : A → B) [hf : NonExpansive f] {x y : A} : +theorem of_internalEquiv_ne {A B : Type _} [OFE Nat A] [OFE Nat B] (f : A → B) [hf : NonExpansive f] {x y : A} : x ≡ y ⊢@{PROP} f x ≡ f y := letI _ : NonExpansive (fun y => (iprop(f x ≡ f y) : PROP)) := (ne_r (f x)).comp hf rewrite' (fun y => iprop(f x ≡ f y)) .rfl refl @@ -109,12 +109,12 @@ section datatypes open internalEq @[rocq_alias discrete_eq_1] -theorem discrete_eq_mp {A : Type _} [OFE A] {a b : A} [TCOr (DiscreteE a) (DiscreteE b)] : +theorem discrete_eq_mp {A : Type _} [OFE Nat A] {a b : A} [TCOr (DiscreteE a) (DiscreteE b)] : a ≡ b ⊢@{PROP} ⌜a = b⌝ := siPure_mono (SiProp.discrete_eq_internalEq _ _)|>.trans siPure_pure.mp @[rocq_alias discrete_eq] -theorem discrete_eq {A : Type _} [OFE A] {a b : A} [TCOr (DiscreteE a) (DiscreteE b)] : +theorem discrete_eq {A : Type _} [OFE Nat A] {a b : A} [TCOr (DiscreteE a) (DiscreteE b)] : a ≡ b ⊣⊢@{PROP} ⌜a = b⌝ := ⟨discrete_eq_mp, of_pure⟩ @@ -124,12 +124,12 @@ theorem fun_extI {A : Type _} {B : A → Type _} [OFEFun B] {f g : (x : A) → B siPure_forall_mpr.trans <| siPure_mono (SiProp.fun_ext_internalEq f g) @[rocq_alias sig_equivI_1] -theorem sig_equivI_mp {A : Type _} [OFE A] {P : A → Prop} {x y : Subtype P} : +theorem sig_equivI_mp {A : Type _} [OFE Nat A] {P : A → Prop} {x y : Subtype P} : x.val ≡ y.val ⊢@{PROP} x ≡ y := siPure_mono (SiProp.sig_equiv_internalEq P x y) @[rocq_alias sig_equivI] -theorem sig_equivI {A : Type _} [OFE A] (P : A → Prop) (x y : Subtype P) : +theorem sig_equivI {A : Type _} [OFE Nat A] (P : A → Prop) (x y : Subtype P) : x.val ≡ y.val ⊣⊢@{PROP} x ≡ y := ⟨sig_equivI_mp, of_internalEquiv_ne Subtype.val⟩ @@ -137,7 +137,7 @@ theorem sig_equivI {A : Type _} [OFE A] (P : A → Prop) (x y : Subtype P) : -- TODO: sigT_equivI (requires SigmaT OFE) @[rocq_alias prod_equivI] -theorem prod_equivI {A B : Type _} [OFE A] [OFE B] (x y : A × B) : +theorem prod_equivI {A B : Type _} [OFE Nat A] [OFE Nat B] (x y : A × B) : x ≡ y ⊣⊢@{PROP} x.1 ≡ y.1 ∧ x.2 ≡ y.2 := by constructor · exact and_intro (of_internalEquiv_ne Prod.fst) (of_internalEquiv_ne Prod.snd) @@ -149,7 +149,7 @@ theorem prod_equivI {A B : Type _} [OFE A] [OFE B] (x y : A × B) : exact rewrite' (fun b => iprop(x ≡ (x.1, b))) and_elim_r refl @[rocq_alias option_equivI] -theorem option_some_equivI {A : Type _} [OFE A] (a b : A) : +theorem option_some_equivI {A : Type _} [OFE Nat A] (a b : A) : some a ≡ some b ⊣⊢@{PROP} a ≡ b := by refine ⟨?_, of_internalEquiv_ne some⟩ let Ψ : Option A → PROP := fun y => @@ -157,11 +157,11 @@ theorem option_some_equivI {A : Type _} [OFE A] (a b : A) : have : NonExpansive Ψ := Option.ne_match _ (ne_r a) _ exact rewrite' Ψ .rfl refl -theorem option_none_equivI (A : Type _) [OFE A] : +theorem option_none_equivI (A : Type _) [OFE Nat A] : (none : Option A) ≡ none ⊣⊢@{PROP} True := ⟨true_intro, refl⟩ -theorem option_some_none_equivI {A : Type _} [OFE A] (a : A) : +theorem option_some_none_equivI {A : Type _} [OFE Nat A] (a : A) : some a ≡ (none : Option A) ⊣⊢@{PROP} False := by refine ⟨?_, false_elim⟩ let Ψ : Option A → PROP := fun y => @@ -169,12 +169,12 @@ theorem option_some_none_equivI {A : Type _} [OFE A] (a : A) : have : NonExpansive Ψ := Option.ne_match _ ⟨fun {_ _ _} _ => Dist.rfl⟩ _ exact rewrite' Ψ .rfl true_intro -theorem option_none_some_equivI {A : Type _} [OFE A] (a : A) : +theorem option_none_some_equivI {A : Type _} [OFE Nat A] (a : A) : (none : Option A) ≡ some a ⊣⊢@{PROP} False := ⟨symm.trans (option_some_none_equivI a).1, false_elim⟩ @[rocq_alias excl_equivI] -theorem excl_equivI_excl {O : Type _} [OFE O] (a b : O) : +theorem excl_equivI_excl {O : Type _} [OFE Nat O] (a b : O) : Excl.excl a ≡ Excl.excl b ⊣⊢@{PROP} a ≡ b := by refine ⟨?_, of_internalEquiv_ne Excl.excl⟩ let Ψ : Excl O → PROP := fun y => @@ -182,11 +182,11 @@ theorem excl_equivI_excl {O : Type _} [OFE O] (a b : O) : have : NonExpansive Ψ := Excl.ne_match _ (ne_r a) _ exact rewrite' Ψ .rfl refl -theorem excl_equivI_invalid (O : Type _) [OFE O] : +theorem excl_equivI_invalid (O : Type _) [OFE Nat O] : (Excl.invalid : Excl O) ≡ Excl.invalid ⊣⊢@{PROP} True := ⟨true_intro, refl⟩ -theorem excl_equivI_excl_invalid {O : Type _} [OFE O] (a : O) : +theorem excl_equivI_excl_invalid {O : Type _} [OFE Nat O] (a : O) : Excl.excl a ≡ (Excl.invalid : Excl O) ⊣⊢@{PROP} False := by refine ⟨?_, false_elim⟩ let Ψ : Excl O → PROP := fun y => @@ -194,12 +194,12 @@ theorem excl_equivI_excl_invalid {O : Type _} [OFE O] (a : O) : have : NonExpansive Ψ := Excl.ne_match _ ⟨fun {_ _ _} _ => Dist.rfl⟩ _ exact rewrite' Ψ .rfl true_intro -theorem excl_equivI_invalid_excl {O : Type _} [OFE O] (a : O) : +theorem excl_equivI_invalid_excl {O : Type _} [OFE Nat O] (a : O) : (Excl.invalid : Excl O) ≡ Excl.excl a ⊣⊢@{PROP} False := ⟨symm.trans (excl_equivI_excl_invalid a).1, false_elim⟩ @[rocq_alias csum_equivI] -theorem csum_equivI {A B : Type _} [OFE A] [OFE B] (sx sy : Csum A B) : +theorem csum_equivI {A B : Type _} [OFE Nat A] [OFE Nat B] (sx sy : Csum A B) : sx ≡ sy ⊣⊢@{PROP} match sx, sy with | .inl x, .inl y => iprop(x ≡ y) @@ -239,7 +239,7 @@ theorem discreteFun_equivI {A : Type _} {B : A → Type _} [OFEFun B] (f g : (x f ≡ g ⊣⊢@{PROP} ∀ x, f x ≡ g x := ⟨discreteFun_equivI_mp f g, fun_extI⟩ -theorem ofeMorO_equivI_mp {A B : Type _} [OFE A] [OFE B] (f g : A -n> B) : +theorem ofeMorO_equivI_mp {A B : Type _} [OFE Nat A] [OFE Nat B] (f g : A -n> B) : f ≡ g ⊢@{PROP} ∀ x, f x ≡ g x := by let Ψ : (A -n> B) → PROP := fun g => iprop(∀ x, f x ≡ g x) have : NonExpansive Ψ := ⟨fun {_ _ _} h => sForall_ne ⟨ @@ -247,76 +247,76 @@ theorem ofeMorO_equivI_mp {A B : Type _} [OFE A] [OFE B] (f g : A -n> B) : fun p ⟨a, ha⟩ => ⟨_, ⟨a, rfl⟩, ha ▸ (ne_r (f a)).ne (h a)⟩⟩⟩ exact rewrite' Ψ .rfl (forall_intro fun _ => refl) -theorem ofeMorO_equivI_mpr {A B : Type _} [OFE A] [OFE B] (f g : A -n> B) : +theorem ofeMorO_equivI_mpr {A B : Type _} [OFE Nat A] [OFE Nat B] (f g : A -n> B) : (∀ x, f x ≡ g x) ⊢@{PROP} f ≡ g := by refine (discreteFun_equivI (PROP := PROP) f.f g.f).2 |>.trans ?_ refine (sig_equivI_mp (x := f.toSubtype) (y := g.toSubtype)).trans ?_ exact of_internalEquiv_ne Hom.ofSubtype @[rocq_alias ofe_morO_equivI] -theorem ofeMorO_equivI {A B : Type _} [OFE A] [OFE B] (f g : A -n> B) : +theorem ofeMorO_equivI {A B : Type _} [OFE Nat A] [OFE Nat B] (f g : A -n> B) : f ≡ g ⊣⊢@{PROP} ∀ x, f x ≡ g x := ⟨ofeMorO_equivI_mp f g, ofeMorO_equivI_mpr f g⟩ /-! ## Modalities -/ @[rocq_alias absorbingly_internal_eq] -theorem absorbingly_internalEq {A : Type _} [OFE A] (x y : A) : +theorem absorbingly_internalEq {A : Type _} [OFE Nat A] (x y : A) : x ≡ y ⊣⊢@{PROP} x ≡ y := absorbingly_siPure @[rocq_alias persistently_internal_eq] -theorem persistently_internalEq {A : Type _} [OFE A] (a b : A) : +theorem persistently_internalEq {A : Type _} [OFE Nat A] (a b : A) : a ≡ b ⊣⊢@{PROP} a ≡ b := persistently_siPure @[rocq_alias internal_eq_absorbing] -instance internalEq_absorbing {A : Type _} [OFE A] (x y : A) : +instance internalEq_absorbing {A : Type _} [OFE Nat A] (x y : A) : Absorbing (PROP := PROP) iprop(x ≡ y) where absorbing := (absorbingly_internalEq x y).1 @[rocq_alias internal_eq_persistent] -instance internalEq_persistent {A : Type _} [OFE A] (a b : A) : +instance internalEq_persistent {A : Type _} [OFE Nat A] (a b : A) : Persistent (PROP := PROP) iprop(a ≡ b) where persistent := (persistently_internalEq a b).2 /-! ## Equality under a later -/ @[rocq_alias later_equivI_1] -theorem later_equivI_mp {A : Type _} [OFE A] (x y : A) : +theorem later_equivI_mp {A : Type _} [OFE Nat A] (x y : A) : Later.next x ≡ Later.next y ⊢@{PROP} ▷ x ≡ y := (siPure_mono (SiProp.later_equiv_internalEq_mp x y)).trans siPure_later.mp @[rocq_alias later_equivI_2] -theorem later_equivI_mpr {A : Type _} [OFE A] (x y : A) : +theorem later_equivI_mpr {A : Type _} [OFE Nat A] (x y : A) : ▷ x ≡ y ⊢@{PROP} Later.next x ≡ Later.next y := siPure_later.mpr.trans (siPure_mono (SiProp.later_equiv_internalEq_mpr x y)) @[rocq_alias later_equivI] -theorem later_equivI {A : Type _} [OFE A] (x y : A) : +theorem later_equivI {A : Type _} [OFE Nat A] (x y : A) : Later.next x ≡ Later.next y ⊣⊢@{PROP} ▷ x ≡ y := ⟨later_equivI_mp x y, later_equivI_mpr x y⟩ @[rocq_alias f_equivI_contractive] -theorem f_equivI_contractive {A B : Type _} [OFE A] [OFE B] (f : A → B) [hf : Contractive f] +theorem f_equivI_contractive {A B : Type _} [OFE Nat A] [OFE Nat B] (f : A → B) [hf : Contractive f] (x y : A) : ▷ x ≡ y ⊢@{PROP} f x ≡ f y := by letI _ : NonExpansive (f ∘ Later.car) := ⟨fun {_ _ _} h => hf.distLater_dist h⟩ exact (later_equivI_mpr x y).trans <| of_internalEquiv_ne (f ∘ Later.car) @[rocq_alias internal_eq_rewrite_contractive] -theorem internalEq_rewrite_contractive {A : Type _} [OFE A] (a b : A) (Ψ : A → PROP) +theorem internalEq_rewrite_contractive {A : Type _} [OFE Nat A] (a b : A) (Ψ : A → PROP) [Contractive Ψ] : ▷ a ≡ b ⊢ Ψ a → Ψ b := (f_equivI_contractive Ψ a b).trans (rewrite id) @[rocq_alias internal_eq_rewrite_contractive'] -theorem internalEq_rewrite_contractive' {A : Type _} [OFE A] (a b : A) (Ψ : A → PROP) +theorem internalEq_rewrite_contractive' {A : Type _} [OFE Nat A] (a b : A) (Ψ : A → PROP) [Contractive Ψ] (Heq : P ⊢ ▷ a ≡ b) (HΨa : P ⊢ Ψ a) : P ⊢ Ψ b := (and_intro .rfl HΨa).trans <| (and_mono_left Heq).trans <| imp_elim (internalEq_rewrite_contractive a b Ψ) @[rocq_alias eq_timeless] -instance eq_timeless {A : Type _} [OFE A] (a b : A) [TCOr (DiscreteE a) (DiscreteE b)] : +instance eq_timeless {A : Type _} [OFE Nat A] (a b : A) [TCOr (DiscreteE a) (DiscreteE b)] : Timeless (PROP := PROP) iprop(a ≡ b) where timeless := calc iprop(▷ a ≡ b) @@ -341,7 +341,7 @@ theorem internalEq_wandIff (P Q : PROP) : P ≡ Q ⊢ (P ∗-∗ Q) := absorbingly_affinely_intro_of_persistent.trans (absorbingly_mono (affinely_internalEq_wandIff P Q)) @[rocq_alias si_pure_internal_eq] -theorem siPure_internalEq {A : Type _} [OFE A] (x y : A) : +theorem siPure_internalEq {A : Type _} [OFE Nat A] (x y : A) : SiProp.internalEq x y ⊣⊢@{PROP} x ≡ y := .rfl @[rocq_alias prop_ext_si_emp_valid_2] @@ -376,25 +376,25 @@ theorem later_equivI_prop_mpr (P Q : PROP) : siPure_mono (prop_ext_siEmpValid_equiv _ _).mpr @[rocq_alias internal_eq_soundness] -theorem internalEq_soundness {A : Type _} [OFE A] (x y : A) : +theorem internalEq_soundness {A : Type _} [OFE Nat A] (x y : A) : (⊢@{PROP} x ≡ y) → x = y := (SiProp.internalEq_soundness <| siPure_emp_valid.mp ·) /-! ## Derive NonExpansive/Contractive from internal statements -/ @[rocq_alias internal_eq_entails] -theorem internalEq_entails {A B : Type _} [OFE A] [OFE B] {a₁ a₂ : A} {b₁ b₂ : B} : +theorem internalEq_entails {A B : Type _} [OFE Nat A] [OFE Nat B] {a₁ a₂ : A} {b₁ b₂ : B} : (a₁ ≡ a₂ ⊢@{PROP} b₁ ≡ b₂) ↔ (∀ n, a₁ ≡{n}≡ a₂ → b₁ ≡{n}≡ b₂) := siPure_entails.trans (SiProp.internalEq_entails ..) @[rocq_alias ne_internal_eq] -theorem ne_internalEq {A B : Type _} [OFE A] [OFE B] (f : A → B) : +theorem ne_internalEq {A B : Type _} [OFE Nat A] [OFE Nat B] (f : A → B) : NonExpansive f ↔ (∀ {x₁ x₂}, x₁ ≡ x₂ ⊢@{PROP} (f x₁) ≡ (f x₂)) := ⟨fun ⟨hne⟩ _ _ => internalEq_entails.mpr (fun _ h => hne h), fun h => ⟨fun {_ _ _} hx => internalEq_entails.mp h _ hx⟩⟩ @[rocq_alias ne_2_internal_eq] -theorem ne_2_internalEq {A B C : Type _} [OFE A] [OFE B] [OFE C] (f : A → B → C) : +theorem ne_2_internalEq {A B C : Type _} [OFE Nat A] [OFE Nat B] [OFE Nat C] (f : A → B → C) : NonExpansive₂ f ↔ (∀ x₁ x₂ y₁ y₂, x₁ ≡ x₂ ∧ y₁ ≡ y₂ ⊢@{PROP} f x₁ y₁ ≡ f x₂ y₂) := by constructor @@ -406,7 +406,7 @@ theorem ne_2_internalEq {A B C : Type _} [OFE A] [OFE B] [OFE C] (f : A → B internalEq_entails.mp (prod_equivI _ _ |>.1 |>.trans (hf ..)) _ (dist_prod_ext hx hy)⟩ @[rocq_alias contractive_internal_eq] -theorem contractive_internalEq {A B : Type _} [OFE A] [OFE B] (f : A → B) : +theorem contractive_internalEq {A B : Type _} [OFE Nat A] [OFE Nat B] (f : A → B) : Contractive f ↔ (∀ x₁ x₂, ▷ (x₁ ≡ x₂) ⊢@{PROP} f x₁ ≡ f x₂) := ⟨fun _ x₁ x₂ => f_equivI_contractive f x₁ x₂, fun hf => ⟨fun {n x y} h => internalEq_entails.mp ((later_equivI_mp x y).trans (hf x y)) n h⟩⟩ diff --git a/Iris/Iris/BI/Lib/Fixpoint.lean b/Iris/Iris/BI/Lib/Fixpoint.lean index 5ce180e82..105b63667 100644 --- a/Iris/Iris/BI/Lib/Fixpoint.lean +++ b/Iris/Iris/BI/Lib/Fixpoint.lean @@ -15,7 +15,7 @@ open Iris.Std BI OFE @[rocq_alias BiMonoPred] -class BIMonoPred [BI PROP] [OFE A] (F : (A → PROP) → (A → PROP)) where +class BIMonoPred [BI PROP] [OFE Nat A] (F : (A → PROP) → (A → PROP)) where mono_pred {Φ Ψ : A → PROP} [NonExpansive Φ] [NonExpansive Ψ] : ⊢ □ (∀ x, Φ x -∗ Ψ x) -∗ ∀ x, F Φ x -∗ F Ψ x mono_pred_ne {Φ : A → PROP} [NonExpansive Φ] : NonExpansive (F Φ) @@ -24,17 +24,17 @@ attribute [instance] mono_pred_ne -- PORTING NOTE: This is an `abbrev` because of typeclass inference @[rocq_alias bi_least_fixpoint] -abbrev bi_least_fixpoint [BI PROP] [OFE A] (F : (A → PROP) → (A → PROP)) (x : A) : PROP := +abbrev bi_least_fixpoint [BI PROP] [OFE Nat A] (F : (A → PROP) → (A → PROP)) (x : A) : PROP := iprop(∀ (Φ : A -n> PROP), □ (∀ x, F Φ x -∗ Φ x) -∗ Φ x) @[rocq_alias bi_greatest_fixpoint] -abbrev bi_greatest_fixpoint [BI PROP] [OFE A] (F : (A → PROP) → (A → PROP)) (x : A) : PROP := +abbrev bi_greatest_fixpoint [BI PROP] [OFE Nat A] (F : (A → PROP) → (A → PROP)) (x : A) : PROP := iprop(∃ (Φ : A -n> PROP), □ (∀ x, Φ x -∗ F Φ x) ∗ Φ x) /-- Porting note: The Rocq version of this theorem has an additional `∀ Φ, NonExpansive Φ → NonExpansive (F Φ)` hypothesis. Not sure why! -/ @[rocq_alias least_fixpoint_ne'] -instance [BI PROP] [OFE A] {F : (A → PROP) → (A → PROP)} : +instance [BI PROP] [OFE Nat A] {F : (A → PROP) → (A → PROP)} : NonExpansive (bi_least_fixpoint F) where ne {_ _ _} Hx := by refine forall_ne fun _ => ?_ @@ -42,7 +42,7 @@ instance [BI PROP] [OFE A] {F : (A → PROP) → (A → PROP)} : exact NonExpansive.ne Hx @[rocq_alias greatest_fixpoint_ne'] -instance [BI PROP] [OFE A] {F : (A → PROP) → (A → PROP)} : +instance [BI PROP] [OFE Nat A] {F : (A → PROP) → (A → PROP)} : NonExpansive (bi_greatest_fixpoint F) where ne {_ _ _} Hx := by refine exists_ne fun _ => ?_ @@ -51,7 +51,7 @@ instance [BI PROP] [OFE A] {F : (A → PROP) → (A → PROP)} : section LeastFixpoint -variable [BI PROP] [OFE A] (F : (A → PROP) → (A → PROP)) +variable [BI PROP] [OFE Nat A] (F : (A → PROP) → (A → PROP)) @[rocq_alias least_fixpoint_unfold_2] theorem least_fixpoint_unfold_mpr [BIMonoPred F] {x} : @@ -224,7 +224,7 @@ end LeastFixpoint section GreatestFixpoint -variable [BI PROP] [OFE A] (F : (A → PROP) → (A → PROP)) +variable [BI PROP] [OFE Nat A] (F : (A → PROP) → (A → PROP)) @[rocq_alias greatest_fixpoint_ne_outer] theorem greatest_fixpoint_ne_outer {F1 F2 : (A → PROP) → (A → PROP)} diff --git a/Iris/Iris/BI/Lib/MonoNat.lean b/Iris/Iris/BI/Lib/MonoNat.lean index 99f510fbd..ee883240d 100644 --- a/Iris/Iris/BI/Lib/MonoNat.lean +++ b/Iris/Iris/BI/Lib/MonoNat.lean @@ -16,7 +16,7 @@ public import Iris.Instances.IProp namespace Iris open Auth BI MonoNat -abbrev MonoNatRF : COFE.OFunctorPre := +abbrev MonoNatRF : COFE.OFunctorPre Nat := AuthURF (constOF MaxNat) @[rocq_alias mono_natG] @@ -139,7 +139,7 @@ theorem own_alloc_strong (P : Nat → Prop) n theorem own_alloc {GF : BundledGFunctors} [MonoNatG GF] (n : MaxNat) : ⊢@{IProp GF} |==> (∃ γ, (γ ↪●MN n) ∗ (γ ↪◯MN n)) := by imod (own_alloc_strong (λ _ => True) n) with ⟨%γ, ⟨-, H⟩⟩ - · intro n; exists n; simp + · intro n; exists n · iexists γ imodintro iframe diff --git a/Iris/Iris/BI/MonPred.lean b/Iris/Iris/BI/MonPred.lean index da9067ee7..c4eb4ddfe 100644 --- a/Iris/Iris/BI/MonPred.lean +++ b/Iris/Iris/BI/MonPred.lean @@ -95,7 +95,7 @@ variable {I : BiIndex} {PROP : Type _} [BI PROP] /-- Pointwise OFE: `P ≡ Q := ∀ i, P i ≡ Q i`, `P ≡{n}≡ Q := ∀ i, P i ≡{n}≡ Q i` (Rocq `monPredO`). -/ @[rocq_alias monPredO] -instance : OFE (MonPred I PROP) where +instance : OFE Nat (MonPred I PROP) where Dist n P Q := ∀ i, P.monPred_at i ≡{n}≡ Q.monPred_at i dist_eqv := { refl _ _ := dist_eqv.refl _ @@ -150,15 +150,18 @@ theorem toSig_ofSig (P : { f : I.car → PROP // ∀ {i j : I.car}, I.rel.le i j end MonPred @[rocq_alias monPred_cofe] -instance : IsCOFE (MonPred I PROP) where +instance : IsCOFE Nat (MonPred I PROP) where compl c := let cf := c.map ((⟨Subtype.val, inferInstance⟩ : _ -n> (I.car → PROP)).comp MonPred.toSig) { monPred_at := fun i => COFE.compl cf i monPred_mono := fun {i j} h => - LimitPreserving.entails (applyHom i) (applyHom j) cf (fun n => (c n).monPred_mono h) } + (LimitPreserving.entails (applyHom i) (applyHom j)).compl cf (fun n => (c n).monPred_mono h) } conv_compl {n c} := IsCOFE.conv_compl (n := n) (c := c.map ((⟨Subtype.val, inferInstance⟩ : _ -n> (I.car → PROP)).comp MonPred.toSig)) + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry end OFE @@ -1477,12 +1480,12 @@ instance instSbiMonPred : Sbi (MonPred I PROP) where /-! ### Internal equality and the plainly modality on `MonPred` -/ @[rocq_alias monPred_internal_eq_unfold] -theorem monPred_internal_eq_unfold {A : Type _} [OFE A] : +theorem monPred_internal_eq_unfold {A : Type _} [OFE Nat A] : (internalEq : A → A → MonPred I PROP) = fun x y => (iprop(⎡(x ≡ y : PROP)⎤) : MonPred I PROP) := rfl @[rocq_alias monPred_at_internal_eq] -theorem monPred_at_internal_eq {A : Type _} [OFE A] (i : I.car) (a b : A) : +theorem monPred_at_internal_eq {A : Type _} [OFE Nat A] (i : I.car) (a b : A) : (iprop(a ≡ b) : MonPred I PROP).monPred_at i ⊣⊢ a ≡ b := .rfl @@ -1518,7 +1521,7 @@ instance si_pure_objective (Pi : SiProp) : Objective (iprop( Pi) : MonP objective_at _ _ := .rfl @[rocq_alias internal_eq_objective] -instance internal_eq_objective {A : Type _} [OFE A] (x y : A) : +instance internal_eq_objective {A : Type _} [OFE Nat A] (x y : A) : Objective (iprop(x ≡ y) : MonPred I PROP) where objective_at _ _ := .rfl diff --git a/Iris/Iris/BI/Plainly.lean b/Iris/Iris/BI/Plainly.lean index 0a547cb18..add7ca38b 100644 --- a/Iris/Iris/BI/Plainly.lean +++ b/Iris/Iris/BI/Plainly.lean @@ -417,11 +417,11 @@ instance wand_persistent [Plain P] [Persistent Q] [Absorbing Q] : _ ⊢ (P -∗ Q) := persistently_mono (wand_mono plain .rfl) @[rocq_alias limit_preserving_Plain] -instance limitPreserving_plain {A} [COFE A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : +theorem limitPreserving_plain {A} [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : LimitPreserving (fun x => Plain (Φ x)) := by letI _ : OFE.NonExpansive fun x => iprop(■ Φ x) := .comp inferInstance Φne - refine fun c h => ⟨?_⟩ - refine LimitPreserving.entails _ (fun x => iprop(■ (Φ x))) _ ?_ + refine ⟨fun c h => ⟨?_⟩, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ + refine (LimitPreserving.entails _ (fun x => iprop(■ (Φ x)))).compl _ ?_ exact (fun n => h n |>.plain) section BigOp @@ -722,7 +722,7 @@ instance plainly_timeless (P : PROP) [Timeless P] : Timeless iprop(■ P) := inferInstanceAs (Timeless iprop( P)) @[rocq_alias plainly_internal_eq] -theorem plainly_internalEq {A} [OFE A] {a b : A} : +theorem plainly_internalEq {A} [OFE Nat A] {a b : A} : iprop(■ (a ≡ b) ⊣⊢@{PROP} a ≡ b) := by refine ⟨plainly_elim, ?_⟩ have : OFE.NonExpansive (β := PROP) (λ x ↦ iprop(■ (a ≡ x))) := { @@ -736,7 +736,7 @@ theorem plainly_internalEq {A} [OFE A] {a b : A} : _ ⊢ ■ (a ≡ a) := plainly_mono internalEq.refl @[rocq_alias internal_eq_plain] -instance internalEq_plain {A} [OFE A] (a b : A) : Plain (PROP := PROP) iprop(a ≡ b) where +instance internalEq_plain {A} [OFE Nat A] (a b : A) : Plain (PROP := PROP) iprop(a ≡ b) where plain := plainly_internalEq |>.2 @[rocq_alias prop_ext] diff --git a/Iris/Iris/BI/SIProp.lean b/Iris/Iris/BI/SIProp.lean index b22b0230f..09a46681e 100644 --- a/Iris/Iris/BI/SIProp.lean +++ b/Iris/Iris/BI/SIProp.lean @@ -109,7 +109,7 @@ def later (P : SiProp) : SiProp where @[rocq_alias siProp_entails] def entails (P Q : SiProp) : Prop := ∀ n, P.holds n → Q.holds n -instance : OFE SiProp where +instance : OFE Nat SiProp where Dist n P Q := ∀ {m}, m ≤ n → (P.holds m ↔ Q.holds m) dist_eqv.refl _ _ _ := Iff.rfl dist_eqv.symm h _ hle := (h hle).symm @@ -125,12 +125,15 @@ instance : OFE SiProp where #rocq_ignore siProp_ofe_mixin "Not needed in Lean." @[rocq_alias siProp_cofe] -instance : IsCOFE SiProp where +instance : IsCOFE Nat SiProp where compl c := { holds n := (c n).holds n closed {n₁ _} h hle := (c.cauchy hle .refl).mp (c n₁ |>.closed h hle) } conv_compl {_ c} _ hle := c.cauchy hle .refl |>.symm + lbcompl := sorry + conv_lbcompl := sorry + lbcompl_ne := sorry #rocq_ignore siProp_compl "Included in IsCOFE instance." @@ -284,7 +287,7 @@ instance instPersistent (P : SiProp) : Persistent P where /-! ## Internal equality -/ @[rocq_alias siProp_internal_eq] -def internalEq [OFE A] (a₁ a₂ : A) : SiProp where +def internalEq [OFE Nat A] (a₁ a₂ : A) : SiProp where holds n := a₁ ≡{n}≡ a₂ closed h hle := Dist.le h hle @@ -293,17 +296,17 @@ def internalEq [OFE A] (a₁ a₂ : A) : SiProp where #rocq_ignore siProp_internal_eq_unseal "Not needed in Lean." @[rocq_alias siProp_primitive.internal_eq_ne] -instance instNonExpansive₂InternalEq [OFE A] : NonExpansive₂ (internalEq (A := A)) where +instance instNonExpansive₂InternalEq [OFE Nat A] : NonExpansive₂ (internalEq (A := A)) where ne _ _ _ h₁ _ _ h₂ _ hle := ⟨fun heq => (Dist.le h₁ hle).symm.trans (heq.trans (Dist.le h₂ hle)), fun heq => (Dist.le h₁ hle).trans (heq.trans (Dist.le h₂ hle).symm)⟩ @[rocq_alias siProp_primitive.internal_eq_refl] -theorem internalEq_refl [OFE A] (P : SiProp) (a : A) : P ⊢ internalEq a a := +theorem internalEq_refl [OFE Nat A] (P : SiProp) (a : A) : P ⊢ internalEq a a := fun _ _ => Dist.rfl @[rocq_alias siProp_primitive.internal_eq_rewrite] -theorem internalEq_rewrite [OFE A] (a b : A) (Ψ : A → SiProp) [HΨ : NonExpansive Ψ] : +theorem internalEq_rewrite [OFE Nat A] (a b : A) (Ψ : A → SiProp) [HΨ : NonExpansive Ψ] : internalEq a b ⊢ Ψ a → Ψ b := fun _ hab _ hle => (HΨ.ne (.le hab hle) .refl).mp @@ -312,7 +315,7 @@ theorem prop_ext (P Q : SiProp) : (P → Q) ∧ (Q → P) ⊢ internalEq P Q := fun _ ⟨hPQ, hQP⟩ n' hle => ⟨hPQ n' hle, hQP n' hle⟩ @[rocq_alias siProp_primitive.internal_eq_entails] -theorem internalEq_entails [OFE A] [OFE B] (a₁ a₂ : A) (b₁ b₂ : B) : +theorem internalEq_entails [OFE Nat A] [OFE Nat B] (a₁ a₂ : A) (b₁ b₂ : B) : (internalEq a₁ a₂ ⊢ internalEq b₁ b₂) ↔ (∀ n, a₁ ≡{n}≡ a₂ → b₁ ≡{n}≡ b₂) := Iff.rfl @@ -322,24 +325,24 @@ theorem fun_ext_internalEq [OFEFun (B : A → _)] (g₁ g₂ : (x : A) → B x) fun _ h x => h _ ⟨x, rfl⟩ @[rocq_alias siProp_primitive.sig_equivI_1] -theorem sig_equiv_internalEq [OFE A] (P : A → Prop) (x y : { a : A // P a }) : +theorem sig_equiv_internalEq [OFE Nat A] (P : A → Prop) (x y : { a : A // P a }) : internalEq x.val y.val ⊢ internalEq x y := fun _ => id @[rocq_alias siProp_primitive.discrete_eq_1] -theorem discrete_eq_internalEq [OFE A] (a b : A) [Idisc : Std.TCOr (DiscreteE a) (DiscreteE b)] : +theorem discrete_eq_internalEq [OFE Nat A] (a b : A) [Idisc : Std.TCOr (DiscreteE a) (DiscreteE b)] : internalEq a b ⊢ ⌜a = b⌝ := by cases Idisc with | l => exact fun _ hab => DiscreteE.discrete (hab.le (Nat.zero_le _)) | r => exact fun _ hab => (DiscreteE.discrete (hab.le (Nat.zero_le _)).symm).symm @[rocq_alias siProp_primitive.later_equivI_1] -theorem later_equiv_internalEq_mp [OFE A] (x y : A) : +theorem later_equiv_internalEq_mp [OFE Nat A] (x y : A) : internalEq (Later.next x) (Later.next y) ⊢ ▷ internalEq x y := fun n h => match n with | .zero => trivial | .succ n => h n n.lt_succ_self @[rocq_alias siProp_primitive.later_equivI_2] -theorem later_equiv_internalEq_mpr [OFE A] (x y : A) : +theorem later_equiv_internalEq_mpr [OFE Nat A] (x y : A) : ▷ internalEq x y ⊢ internalEq (Later.next x) (Later.next y) := by intro n hP m hlt cases n with @@ -394,7 +397,7 @@ instance cmraValid_timeless [CMRA A] [CMRA.Discrete A] {a : A} : theorem pure_soundness {φ : Prop} (h : True ⊢@{SiProp} ⌜φ⌝) : φ := h 0 trivial @[rocq_alias siProp_primitive.internal_eq_soundness] -theorem internalEq_soundness [OFE A] {x y : A} (h : True ⊢@{SiProp} internalEq x y) : x = y := +theorem internalEq_soundness [OFE Nat A] {x y : A} (h : True ⊢@{SiProp} internalEq x y) : x = y := OFE.eq_dist.mpr fun n => h n trivial @[rocq_alias siProp_primitive.later_soundness] diff --git a/Iris/Iris/Examples/Fix.lean b/Iris/Iris/Examples/Fix.lean index d814de9cd..c7ca47f69 100644 --- a/Iris/Iris/Examples/Fix.lean +++ b/Iris/Iris/Examples/Fix.lean @@ -25,10 +25,10 @@ tactics for simplification/rewriting. section Fix open Iris OFE COFE -variable [OFE Val] [OFE Err] [IsCOFE Val] [IsCOFE Err] [Inhabited Err] +variable [OFE Nat Val] [OFE Nat Err] [IsCOFE Nat Val] [IsCOFE Nat Err] [Inhabited Err] -abbrev DomF : OFunctorPre := - SumOF (constOF Val) (SumOF (constOF Err) (SumOF (LaterOF IdOF) (LaterOF (HomOF IdOF IdOF)))) +abbrev DomF : OFunctorPre Nat := + SumOF Nat (constOF Val) (SumOF Nat (constOF Err) (SumOF Nat (LaterOF IdOF) (LaterOF (HomOF IdOF IdOF)))) instance : Inhabited (DomF (Val := Val) (Err := Err) (ULift Unit) (ULift Unit)) := ⟨.inr (.inr (.inr ⟨id, inferInstance⟩))⟩ @@ -36,13 +36,13 @@ instance : Inhabited (DomF (Val := Val) (Err := Err) (ULift Unit) (ULift Unit)) end Fix open Iris OFE COFE in -abbrev Dom (Val : Type _) (Err : Type _) [OFE Val] [OFE Err] [IsCOFE Val] [IsCOFE Err] [Inhabited Err] := +abbrev Dom (Val : Type _) (Err : Type _) [OFE Nat Val] [OFE Nat Err] [IsCOFE Nat Val] [IsCOFE Nat Err] [Inhabited Err] := OFunctor.Fix (DomF (Val := Val) (Err := Err)) namespace Dom open Iris OFE COFE -variable [OFE V] [OFE E] [IsCOFE V] [IsCOFE E] [Inhabited E] +variable [OFE Nat V] [OFE Nat E] [IsCOFE Nat V] [IsCOFE Nat E] [Inhabited E] def fold : V ⊕ E ⊕ Later (Dom V E) ⊕ Later (Dom V E -n> Dom V E) -n> Dom V E := OFunctor.Fix.fold (F := DomF (Val := V) (Err := E)) diff --git a/Iris/Iris/Examples/IProp.lean b/Iris/Iris/Examples/IProp.lean index 87984805c..e320ea4b3 100644 --- a/Iris/Iris/Examples/IProp.lean +++ b/Iris/Iris/Examples/IProp.lean @@ -18,7 +18,9 @@ open Iris.BI COFE section Example1 -abbrev F0 : OFunctorPre := constOF (Agree (DiscreteO String)) +abbrev F0 : OFunctorPre Nat := constOF (Agree (DiscreteO String)) +instance discreteO_cofe {α : Type _} : COFE Nat (DiscreteO α) := DiscreteO.instCOFE +instance discreteO_discrete {α : Type _} : OFE.Discrete (SI := Nat) (DiscreteO α) := DiscreteO.OFE variable {GF} [E0 : ElemG GF F0] @@ -52,7 +54,7 @@ section Example2 open HeapView One DFrac Agree DiscreteO /- Define an OFunctor for the heap. Fractions are concretely `Qp`. -/ -abbrev F1 : OFunctorPre := +abbrev F1 : OFunctorPre Nat := constOF <| HeapView Nat (Agree (DiscreteO String)) (Std.ExtTreeMap Nat · compare) /- Our OFunctor is present in the global list of OFunctors. -/ @@ -98,7 +100,7 @@ variable (Expr State Value : Type _) [OperationalSemantics Expr State Value] /- Let's say that we are also given two OFunctors, and an interpretation of the state into state using these resources. -/ -variable (F3 F4 : OFunctorPre) [RFunctorContractive F3] [RFunctorContractive F4] +variable (F3 F4 : OFunctorPre Nat) [RFunctorContractive F3] [RFunctorContractive F4] variable {GF} [ElemG GF F3] [ElemG GF F4] class StateInterpretation (State : Type _) (GF : BundledGFunctors) where state_interp : State → IProp GF @@ -142,7 +144,7 @@ theorem wp_unfold (e : Expr) (Φ : Value → IProp GF) : ∃ e' s', ⌜@step _ _ Value _ (e, s) = (e', s') ⌝ ∗ ▷ |==> (@state_interp _ _ _ s' ∗ wp e' Φ)) := by exact OFE.eq_dist.mpr fun _n => (fixpoint_unfold (f := ⟨(@wp_F Expr State Value _ GF _), - @OFE.ne_of_contractive _ _ _ _ (@wp_F Expr State Value _ GF _) _⟩)).dist e Φ + @OFE.ne_of_contractive _ _ _ _ _ _ (@wp_F Expr State Value _ GF _) _⟩)).dist e Φ /- Now, we can derive some example proof rules. First let's prove a rule for pure deterministic steps: -/ example (e e' : Expr) Φ (Hstep : ∀ {s : State}, @step _ _ Value _ (e, s) = (e', s)) : diff --git a/Iris/Iris/Instances/Classical/Instance.lean b/Iris/Iris/Instances/Classical/Instance.lean index b0d75ef87..995d6584b 100644 --- a/Iris/Iris/Instances/Classical/Instance.lean +++ b/Iris/Iris/Instances/Classical/Instance.lean @@ -42,7 +42,7 @@ instance heapPropPreorder : Std.IsPreorder (HeapProp Val) where apply h_xy σ exact h_x -instance : COFE (HeapProp Val) := COFE.ofDiscrete _ +instance : COFE Nat (HeapProp Val) := COFE.ofDiscrete _ instance : BI (HeapProp Val) where entails_refl := heapPropPreorder.le_refl _ diff --git a/Iris/Iris/Instances/IProp/Instance.lean b/Iris/Iris/Instances/IProp/Instance.lean index c70d83395..f9b469be7 100644 --- a/Iris/Iris/Instances/IProp/Instance.lean +++ b/Iris/Iris/Instances/IProp/Instance.lean @@ -18,20 +18,20 @@ namespace Iris open COFE Std CMRA /-- Apply an OFunctor at a fixed type -/ -abbrev COFE.OFunctorPre.ap (F : OFunctorPre) (T : Type _) [COFE T] := +abbrev COFE.OFunctorPre.ap (F : OFunctorPre Nat) (T : Type _) [COFE Nat T] := F T T /-- Apply a list of OFunctors at a fixed type and index -/ -abbrev BundledGFunctors.api (FF : BundledGFunctors) (τ : GType) (T : Type _) [COFE T] := +abbrev BundledGFunctors.api (FF : BundledGFunctors) (τ : GType) (T : Type _) [COFE Nat T] := FF τ |>.fst |>.ap T /-- Transport an OFunctorPre application along equality of the OFunctorPre. -/ -theorem transpAp {F1 F2 : OFunctorPre} (H : F1 = F2) {T} [COFE T] : F1.ap T = F2.ap T := +theorem transpAp {F1 F2 : OFunctorPre Nat} (H : F1 = F2) {T} [COFE Nat T] : F1.ap T = F2.ap T := congrArg (OFunctorPre.ap · T) H section TranspAp -variable [RF₁ : RFunctorContractive F₁] [RF₂ : RFunctorContractive F₂] [COFE T] +variable [RF₁ : RFunctorContractive F₁] [RF₂ : RFunctorContractive F₂] [COFE Nat T] theorem OFE.transpAp_eqv_mp (h_fun : F₁ = F₂) (h_inst : HEq RF₁ RF₂) {x y : F₁.ap T} (H : x ≡{n}≡ y) : (transpAp h_fun).mp x ≡{n}≡ (transpAp h_fun).mp y := by @@ -61,7 +61,7 @@ section ElemG /-- `ElemG` takes functors instead of CMRAs -/ @[rocq_alias inG] -class ElemG (FF : BundledGFunctors) (F : OFunctorPre) [RFunctorContractive F] where +class ElemG (FF : BundledGFunctors) (F : OFunctorPre Nat) [RFunctorContractive F] where τ : GType transp : FF τ = ⟨F, ‹_›⟩ @@ -71,29 +71,29 @@ open OFE variable [I : RFunctorContractive F] -theorem ElemG.transpMap (E : ElemG GF F) T [OFE T] : (GF E.τ).fst = F := +theorem ElemG.transpMap (E : ElemG GF F) T [OFE Nat T] : (GF E.τ).fst = F := Sigma.mk.inj E.transp |>.1 -theorem ElemG.transpClass (E : ElemG GF F) T [OFE T] : (GF E.τ).snd ≍ I := +theorem ElemG.transpClass (E : ElemG GF F) T [OFE Nat T] : (GF E.τ).snd ≍ I := Sigma.mk.inj E.transp |>.2 -def ElemG.bundle (E : ElemG GF F) [COFE T] : F.ap T → GF.api E.τ T := +def ElemG.bundle (E : ElemG GF F) [COFE Nat T] : F.ap T → GF.api E.τ T := transpAp (E.transpMap T) |>.mpr -def ElemG.unbundle (E : ElemG GF F) [COFE T] : GF.api E.τ T → F.ap T := +def ElemG.unbundle (E : ElemG GF F) [COFE Nat T] : GF.api E.τ T → F.ap T := transpAp (E.transpMap T) |>.mp -theorem ElemG.bundle_unbundle (E : ElemG GF F) [COFE T] (x : GF.api E.τ T) : +theorem ElemG.bundle_unbundle (E : ElemG GF F) [COFE Nat T] (x : GF.api E.τ T) : E.bundle (E.unbundle x) = x := by simp [bundle, unbundle] -theorem ElemG.unbundle_bundle (E : ElemG GF F) [COFE T] (x : F.ap T) : +theorem ElemG.unbundle_bundle (E : ElemG GF F) [COFE Nat T] (x : F.ap T) : E.unbundle (E.bundle x) = x := by simp [bundle, unbundle] -instance ElemG.bundle.ne {E : ElemG GF F} [COFE T] : +instance ElemG.bundle.ne {E : ElemG GF F} [COFE Nat T] : OFE.NonExpansive (E.bundle (T := T)) where ne {_ _ _} := OFE.transpAp_eqv_mp (E.transpMap T).symm (E.transpClass T).symm -instance ElemG.unbundle.ne {E : ElemG GF F} [COFE T] : +instance ElemG.unbundle.ne {E : ElemG GF F} [COFE Nat T] : OFE.NonExpansive (E.unbundle (T := T)) where ne {_ _ _} H := OFE.transpAp_eqv_mp (E.transpMap T) (E.transpClass T) H @@ -443,7 +443,7 @@ theorem iSingleton_op_validN_at_γ {a : F.ap (IProp GF)} (Hv : ✓{n} mf) : · simp; exact extract_frame_validN (Hv E.τ) h_at @[rocq_alias iRes_singleton_discrete] -instance iSingleton_discreteE {v : F.ap (IProp GF)} [OFE.DiscreteE v] : +instance iSingleton_discreteE {v : F.ap (IProp GF)} [inst : OFE.DiscreteE v] : OFE.DiscreteE (iSingleton F γ v) where discrete {w} H := by refine OFE.eq_dist.mpr fun n τ => ?_ @@ -460,7 +460,7 @@ instance iSingleton_discreteE {v : F.ap (IProp GF)} [OFE.DiscreteE v] : · refine some_dist_some.mpr (Eq.dist ?_) refine (congrArg unfoldi.f ?_).trans (IProp.unfoldi_foldi x) refine (congrArg E.bundle ?_).trans (ElemG.bundle_unbundle E _) - refine OFE.DiscreteE.discrete ?_ + refine inst.discrete ?_ refine (ElemG.unbundle_bundle E v).dist.symm.trans ?_ refine NonExpansive.ne <| (IProp.foldi_unfoldi _).dist.symm.trans (NonExpansive.ne Hk) · rw [GenMap.singleton_map_none hk] at Hk ⊢ diff --git a/Iris/Iris/Instances/Lib/Boxes.lean b/Iris/Iris/Instances/Lib/Boxes.lean index 9362f07c1..0eb502018 100644 --- a/Iris/Iris/Instances/Lib/Boxes.lean +++ b/Iris/Iris/Instances/Lib/Boxes.lean @@ -23,8 +23,10 @@ abbrev BoolO := DiscreteO Bool variable (GF : BundledGFunctors) -abbrev BoxF : OFunctorPre := - ProdOF (AuthURF (OptionOF (ExclOF (constOF BoolO)))) +local instance discreteO_cofe {α : Type _} : COFE Nat (DiscreteO α) := DiscreteO.instCOFE + +abbrev BoxF : OFunctorPre Nat := + ProdOF Nat (AuthURF (OptionOF (ExclOF (constOF BoolO)))) (OptionOF (AgreeRF (LaterOF IdOF))) @[rocq_alias boxG] diff --git a/Iris/Iris/Instances/Lib/CInvariants.lean b/Iris/Iris/Instances/Lib/CInvariants.lean index bec1f22c9..bd6ccd2ed 100644 --- a/Iris/Iris/Instances/Lib/CInvariants.lean +++ b/Iris/Iris/Instances/Lib/CInvariants.lean @@ -24,8 +24,8 @@ open BI CMRA OFE Iris Std LawfulSet Excl COFE ProofMode /-! # Cancelable Invariants -/ -abbrev CInvF : OFunctorPre := - ProdOF (constOF (Option (Excl Unit))) (constOF (Option Qp)) +abbrev CInvF : OFunctorPre Nat := + ProdOF Nat (constOF (Option (Excl Unit))) (constOF (Option Qp)) @[rocq_alias cinvG] class CInvG (GF : BundledGFunctors) where diff --git a/Iris/Iris/Instances/Lib/GhostMap.lean b/Iris/Iris/Instances/Lib/GhostMap.lean index 955b663f3..1b8bb1eea 100644 --- a/Iris/Iris/Instances/Lib/GhostMap.lean +++ b/Iris/Iris/Instances/Lib/GhostMap.lean @@ -228,7 +228,7 @@ theorem ghost_map_alloc_strong_empty [DecidableEq K] (P : GName → Prop) theorem ghost_map_alloc [DecidableEq K] (m : H V) : ⊢@{IProp GF} |==> ∃ γ, (γ ↪●MAP m) ∗ [∗map] k ↦ v ∈ m, γ ↪◯MAP[k] v := by imod (ghost_map_alloc_strong (fun _ => True) m) with ⟨%γ, -, H1, H2⟩ - · intro N; exists N; simp + · intro N; exists N -- ; simp · iexists γ iframe H1 H2 diff --git a/Iris/Iris/Instances/Lib/LaterCredits.lean b/Iris/Iris/Instances/Lib/LaterCredits.lean index 1f1847af6..294e1511a 100644 --- a/Iris/Iris/Instances/Lib/LaterCredits.lean +++ b/Iris/Iris/Instances/Lib/LaterCredits.lean @@ -37,7 +37,7 @@ scoped instance : LeftIdentity (Add.add (α := Credit)) (0 : Credit) where scoped instance : LawfulLeftIdentity (Add.add (α := Credit)) (0 : Credit) := ⟨Nat.zero_add⟩ scoped instance : LeftCancelAdd Credit := ⟨Nat.add_left_cancel⟩ -scoped instance : COFE Credit := COFE.ofDiscrete _ +scoped instance : COFE Nat Credit := COFE.ofDiscrete _ scoped instance : Discrete Credit := ⟨fun h => h⟩ scoped instance : UCMRA Credit := CommMonoidLike.instUCMRA scoped instance : CMRA.Discrete Credit := CommMonoidLike.instDiscrete diff --git a/Iris/Iris/Instances/Lib/NaInvariants.lean b/Iris/Iris/Instances/Lib/NaInvariants.lean index f3ff10010..fd6e50653 100644 --- a/Iris/Iris/Instances/Lib/NaInvariants.lean +++ b/Iris/Iris/Instances/Lib/NaInvariants.lean @@ -19,8 +19,8 @@ namespace Iris open BI CMRA OFE Iris Std LawfulSet DisjointLeibnizSet COFE ProofMode -abbrev NaInvF : OFunctorPre := - ProdOF (constOF CoPsetDisjL) (constOF (DisjointLeibnizSet PosSet)) +abbrev NaInvF : OFunctorPre Nat := + ProdOF Nat (constOF CoPsetDisjL) (constOF (DisjointLeibnizSet PosSet)) @[rocq_alias na_invG] class NaInvG (GF : BundledGFunctors) where diff --git a/Iris/Iris/Instances/Lib/SavedProp.lean b/Iris/Iris/Instances/Lib/SavedProp.lean index 76a0c4acf..ac54bd7d8 100644 --- a/Iris/Iris/Instances/Lib/SavedProp.lean +++ b/Iris/Iris/Instances/Lib/SavedProp.lean @@ -21,7 +21,7 @@ open BI CMRA Agree OFE UPred IProp Std ProofMode COFE /-! ## Saved anything -/ @[rocq_alias savedAnythingG] -class SavedAnythingG (GF : BundledGFunctors) (F : OFunctorPre) [OFunctorContractive F] where +class SavedAnythingG (GF : BundledGFunctors) (F : OFunctorPre Nat) [OFunctorContractive Nat F] where [elemG : ElemG GF (DFracAgree.DFracAgreeRF F)] attribute [reducible, instance] SavedAnythingG.elemG @@ -30,13 +30,13 @@ attribute [reducible, instance] SavedAnythingG.elemG #rocq_ignore «subG_savedAnythingΣ» "Subsumed by BundledGFunctors typeclass synthesis" @[rocq_alias saved_anything_own] -def saved_anything_own {GF : BundledGFunctors} {F : OFunctorPre} [OFunctorContractive F] +def saved_anything_own {GF : BundledGFunctors} {F : OFunctorPre Nat} [OFunctorContractive Nat F] [SavedAnythingG GF F] (γ : GName) (dq : DFrac) (x : F.ap (IProp GF)) : IProp GF := iOwn (F := DFracAgree.DFracAgreeRF F) γ (DFracAgree.mk dq x) section saved_anything -variable {GF : BundledGFunctors} {F : OFunctorPre} [OFunctorContractive F] [SavedAnythingG GF F] +variable {GF : BundledGFunctors} {F : OFunctorPre Nat} [OFunctorContractive Nat F] [SavedAnythingG GF F] @[rocq_alias saved_anything_discarded_persistent] instance saved_anything_discarded_persistent (γ : GName) (x : F.ap (IProp GF)) : diff --git a/Iris/Iris/Instances/Lib/Token.lean b/Iris/Iris/Instances/Lib/Token.lean index 6965cf409..1fa767354 100644 --- a/Iris/Iris/Instances/Lib/Token.lean +++ b/Iris/Iris/Instances/Lib/Token.lean @@ -21,7 +21,7 @@ The `token γ` assertion provides ownership of the token named `γ`, and the key lemma `token_exclusive` proves only one token exists. -/ -abbrev TokenF : COFE.OFunctorPre := constOF (Excl Unit) +abbrev TokenF : COFE.OFunctorPre Nat := constOF (Excl Unit) @[rocq_alias tokenG] class TokenG (GF : BundledGFunctors) where [elemG : ElemG GF TokenF] diff --git a/Iris/Iris/Instances/UPred/Instance.lean b/Iris/Iris/Instances/UPred/Instance.lean index 680a027d9..f4f085b39 100644 --- a/Iris/Iris/Instances/UPred/Instance.lean +++ b/Iris/Iris/Instances/UPred/Instance.lean @@ -93,7 +93,7 @@ protected def sExists (Ψ : UPred M → Prop) : UPred M where #rocq_ignore uPred_exist_def "`UPred.sExists` is defined directly without `seal`/`unseal`." #rocq_ignore uPred_exist_aux "`UPred.sExists` is defined directly without `seal`/`unseal`." -protected def eq [OFE O] (o1 o2 : O) : UPred M where +protected def eq [OFE Nat O] (o1 o2 : O) : UPred M where holds n _ := o1 ≡{n}≡ o2 mono H1 _ H2 := H1.le H2 diff --git a/Iris/Iris/ProofMode/Classes.lean b/Iris/Iris/ProofMode/Classes.lean index a777b4531..e9c0b3176 100644 --- a/Iris/Iris/ProofMode/Classes.lean +++ b/Iris/Iris/ProofMode/Classes.lean @@ -138,7 +138,7 @@ class IntoOr {PROP} [BI PROP] (P : PROP) (Q1 Q2 : outParam $ PROP) where export IntoOr (into_or) @[ipm_class, rocq_alias IntoInternalEq] -class IntoInternalEq {PROP} [BI PROP] [Sbi PROP] {A : outParam $ Type _} [ofe : outParam $ OFE A] (P : PROP) (x y : outParam A) where +class IntoInternalEq {PROP} [BI PROP] [Sbi PROP] {A : outParam $ Type _} [ofe : outParam $ OFE Nat A] (P : PROP) (x y : outParam A) where into_internal_eq : P ⊢@{PROP} x ≡ y export IntoInternalEq (into_internal_eq) diff --git a/Iris/Iris/ProofMode/InstancesInternalEq.lean b/Iris/Iris/ProofMode/InstancesInternalEq.lean index 990addc76..73ea4e2dc 100644 --- a/Iris/Iris/ProofMode/InstancesInternalEq.lean +++ b/Iris/Iris/ProofMode/InstancesInternalEq.lean @@ -20,30 +20,30 @@ section internalEq variable {PROP} [Sbi PROP] @[rocq_alias from_pure_internal_eq] -instance fromPure_internalEq [Sbi PROP] [OFE A] (a b : A) : +instance fromPure_internalEq [Sbi PROP] [OFE Nat A] (a b : A) : FromPure (PROP := PROP) false iprop(a ≡ b) io (a = b) where from_pure := internalEq.of_pure @[ipm_backtrack, rocq_alias into_pure_eq] -instance intoPure_internalEq [Sbi PROP] [OFE A] (a b : A) +instance intoPure_internalEq [Sbi PROP] [OFE Nat A] (a b : A) [TCOr (OFE.DiscreteE a) (OFE.DiscreteE b)] : IntoPure (PROP := PROP) iprop(a ≡ b) (a = b) where into_pure := discrete_eq_mp @[ipm_backtrack] -instance (priority := default + 10) intoPure_internalEq_leibniz [Sbi PROP] [OFE A] +instance (priority := default + 10) intoPure_internalEq_leibniz [Sbi PROP] [OFE Nat A] (a b : A) [TCOr (OFE.DiscreteE a) (OFE.DiscreteE b)] : IntoPure (PROP := PROP) iprop(a ≡ b) (a = b) where into_pure := discrete_eq_mp @[rocq_alias from_modal_Next] -instance fromModal_internalEq_next [Sbi PROP] [OFE A] (x y : A) : +instance fromModal_internalEq_next [Sbi PROP] [OFE Nat A] (x y : A) : FromModal (PROP1 := PROP) (PROP2 := PROP) True (modality_laterN 1) iprop(▷ (x ≡ y) : PROP) iprop(Later.next x ≡ Later.next y) iprop(x ≡ y) where from_modal _ := later_equivI_mpr x y @[rocq_alias into_laterN_Next] -instance intoLaterN_internalEq_next [Sbi PROP] [OFE A] (x y : A) +instance intoLaterN_internalEq_next [Sbi PROP] [OFE Nat A] (x y : A) only_head n n' [h : NatCancel n 1 n' 0] : IntoLaterN (PROP := PROP) only_head n iprop(Later.next x ≡ Later.next y) iprop(x ≡ y) where @@ -54,36 +54,36 @@ instance intoLaterN_internalEq_next [Sbi PROP] [OFE A] (x y : A) -- IntoInternalEq @[rocq_alias into_internal_eq_internal_eq] -instance intoInternalEq_internalEq [Sbi PROP] [OFE A] (x y : A) : +instance intoInternalEq_internalEq [Sbi PROP] [OFE Nat A] (x y : A) : IntoInternalEq (PROP := PROP) iprop(x ≡ y) x y where into_internal_eq := .rfl @[rocq_alias into_internal_eq_affinely] -instance intoInternalEq_affinely [Sbi PROP] [OFE A] (x y : A) (P : PROP) +instance intoInternalEq_affinely [Sbi PROP] [OFE Nat A] (x y : A) (P : PROP) [h : IntoInternalEq P x y] : IntoInternalEq iprop( P) x y where into_internal_eq := affinely_elim.trans h.into_internal_eq @[rocq_alias into_internal_eq_intuitionistically] -instance intoInternalEq_intuitionistically [Sbi PROP] [OFE A] (x y : A) (P : PROP) +instance intoInternalEq_intuitionistically [Sbi PROP] [OFE Nat A] (x y : A) (P : PROP) [h : IntoInternalEq P x y] : IntoInternalEq iprop(□ P) x y where into_internal_eq := intuitionistically_elim.trans h.into_internal_eq @[rocq_alias into_internal_eq_absorbingly] -instance intoInternalEq_absorbingly [Sbi PROP] [OFE A] (x y : A) (P : PROP) +instance intoInternalEq_absorbingly [Sbi PROP] [OFE Nat A] (x y : A) (P : PROP) [h : IntoInternalEq P x y] : IntoInternalEq iprop( P) x y where into_internal_eq := (absorbingly_mono h.into_internal_eq).trans (absorbingly_internalEq x y).1 @[rocq_alias into_internal_eq_plainly] -instance intoInternalEq_plainly [Sbi PROP] [OFE A] (x y : A) (P : PROP) +instance intoInternalEq_plainly [Sbi PROP] [OFE Nat A] (x y : A) (P : PROP) [h : IntoInternalEq P x y] : IntoInternalEq iprop(■ P) x y where into_internal_eq := (plainly_mono h.into_internal_eq).trans (plainly_internalEq).1 @[rocq_alias into_internal_eq_persistently] -instance intoInternalEq_persistently [Sbi PROP] [OFE A] (x y : A) (P : PROP) +instance intoInternalEq_persistently [Sbi PROP] [OFE Nat A] (x y : A) (P : PROP) [h : IntoInternalEq P x y] : IntoInternalEq iprop( P) x y where into_internal_eq := (persistently_mono h.into_internal_eq).trans (persistently_internalEq x y).1 diff --git a/Iris/Iris/ProofMode/Tactics/Rewrite.lean b/Iris/Iris/ProofMode/Tactics/Rewrite.lean index 000ac373d..03bdfb20a 100644 --- a/Iris/Iris/ProofMode/Tactics/Rewrite.lean +++ b/Iris/Iris/ProofMode/Tactics/Rewrite.lean @@ -18,7 +18,7 @@ namespace Iris.ProofMode public section open BI Std -theorem rewrite_tac [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE A] {a b : A} {p} +theorem rewrite_tac [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE Nat A] {a b : A} {p} (Ψ : A → PROP) [ne : OFE.NonExpansive Ψ] [heq : IntoInternalEq Q a b] (h1 : P ⊢ P' ∗ □?p Q) : P ⊢ (Ψ a ∗-∗ Ψ b) := @@ -30,7 +30,7 @@ theorem rewrite_tac [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE A] {a b : A} {p _ ⊢ Ψ a ≡ Ψ b := persistently_affinely.2 _ ⊢ (Ψ a ∗-∗ Ψ b) := persistently_mono (affinely_internalEq_wandIff _ _) -theorem rewrite_tac_symm [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE A] {a b : A} {p} +theorem rewrite_tac_symm [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE Nat A] {a b : A} {p} (Ψ : A → PROP) [ne : OFE.NonExpansive Ψ] [IntoInternalEq Q a b] (h_eq : P ⊢ P' ∗ □?p Q) : P ⊢ (Ψ b ∗-∗ Ψ a) := @@ -128,7 +128,7 @@ private def iRewriteCore {prop : Q(Type u)} {bi : Q(BI $prop)} let A : Q(Type v) ← mkFreshExprMVarQ q(Type v) let a : Q($A) ← mkFreshExprMVarQ q($A) let b : Q($A) ← mkFreshExprMVarQ q($A) - let _ofe : Q(OFE $A) ← mkFreshExprMVarQ q(OFE $A) + let _ofe : Q(OFE Nat $A) ← mkFreshExprMVarQ q(OFE Nat $A) let .some _ ← ProofModeM.trySynthInstanceQ q(IntoInternalEq (PROP := $prop) $eq $a $b) | throwError "irewrite: {eq} is not an internal equality" diff --git a/Iris/Iris/Tests/Tactics.lean b/Iris/Iris/Tests/Tactics.lean index cfc94ffc7..250194766 100644 --- a/Iris/Iris/Tests/Tactics.lean +++ b/Iris/Iris/Tests/Tactics.lean @@ -2189,7 +2189,7 @@ end inext section irewrite variable {PROP : Type _} [Sbi PROP] -variable {A B : Type _} [OFE A] [OFE B] +variable {A B : Type _} [OFE Nat A] [OFE Nat B] /- Tests `irewrite` rewriting in goal -/ example (a b : A) (P : A → PROP) [OFE.NonExpansive P] [Absorbing (P a)] : From fd1b3417270bfffa9a14bdebde4950f3fed78ac3 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Sat, 1 Aug 2026 16:03:20 +0200 Subject: [PATCH 17/33] Update `limitPreserving_emp_valid` --- Iris/Iris/BI/DerivedLaws.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Iris/Iris/BI/DerivedLaws.lean b/Iris/Iris/BI/DerivedLaws.lean index 7d07dcf0c..4c8ea0fe5 100644 --- a/Iris/Iris/BI/DerivedLaws.lean +++ b/Iris/Iris/BI/DerivedLaws.lean @@ -2396,7 +2396,7 @@ theorem LimitPreserving.entails [BI PROP] [COFE Nat A] (Φ Ψ : A → PROP) [Φn exact fun n => (h' n).to_eq @[rocq_alias bi.limit_preserving_emp_valid] -theorem limitPreserving_emp_valid [BI PROP] [COFE A] (Φ : A → PROP) +theorem limitPreserving_emp_valid [BI PROP] [COFE Nat A] (Φ : A → PROP) [OFE.NonExpansive Φ] : LimitPreserving (fun x => ⊢ Φ x) := LimitPreserving.entails (fun _ => iprop(emp)) Φ From 86d0e37c592f2302bc51287ebce08c13f52349ed Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Sun, 2 Aug 2026 16:11:47 +0200 Subject: [PATCH 18/33] Update `Algebra/Lib/UFracAuth.lean` and `Algebra/Functions.lean` --- Iris/Iris/Algebra/Functions.lean | 2 +- Iris/Iris/Algebra/Lib/UFracAuth.lean | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Iris/Iris/Algebra/Functions.lean b/Iris/Iris/Algebra/Functions.lean index cb237c378..a69901757 100644 --- a/Iris/Iris/Algebra/Functions.lean +++ b/Iris/Iris/Algebra/Functions.lean @@ -49,7 +49,7 @@ end insert section OFE -variable {ι : Type _} [DecidableEq ι] {β : ι → Type _} [∀ i, OFE (β i)] +variable {ι : Type _} [DecidableEq ι] {β : ι → Type _} [∀ i, OFE Nat (β i)] @[rocq_alias discrete_funO_ofe_discrete] instance instDiscreteFunOfeDiscrete [∀ i, OFE.Discrete (β i)] : diff --git a/Iris/Iris/Algebra/Lib/UFracAuth.lean b/Iris/Iris/Algebra/Lib/UFracAuth.lean index 136e84709..444769c83 100644 --- a/Iris/Iris/Algebra/Lib/UFracAuth.lean +++ b/Iris/Iris/Algebra/Lib/UFracAuth.lean @@ -213,14 +213,14 @@ theorem update_surplus_cancel {p q : Qp} {a b : A} [CMRA.Cancelable b] : /-! ## Functors -/ @[rocq_alias ufrac_authURF] -abbrev UFracAuthURF (T : COFE.OFunctorPre) [RFunctor T] : COFE.OFunctorPre := - AuthURF (OptionOF (ProdOF (constOF UFrac) T)) +abbrev UFracAuthURF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := + AuthURF (OptionOF (ProdOF Nat (constOF UFrac) T)) #rocq_ignore ufrac_authURF_contractive "Contractiveness is bundled into Lean's RFunctor class" @[rocq_alias ufrac_authRF] -abbrev UFracAuthRF (T : COFE.OFunctorPre) [RFunctor T] : COFE.OFunctorPre := - AuthRF (OptionOF (ProdOF (constOF UFrac) T)) +abbrev UFracAuthRF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := + AuthRF (OptionOF (ProdOF Nat (constOF UFrac) T)) #rocq_ignore ufrac_authRF_contractive "Contractiveness is bundled into Lean's RFunctor class" From cb0943ea1ac11f1a3c7f7c5cdd0a7138a9d763a6 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Sun, 2 Aug 2026 16:23:24 +0200 Subject: [PATCH 19/33] Fill in proofs for the new `IsCOFE` fields --- Iris/Iris/Algebra/OFE.lean | 206 ++++++++++++++++++++++++++++++++----- 1 file changed, 179 insertions(+), 27 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 21758dc62..e2c957aa5 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -992,6 +992,7 @@ structure BChain (α : Type _) [SIdx SI] [OFE SI α] (n : SI) where bcauchy {m p} (hm : m < n) (hp : p < n) (h : m ≤ p) : bchain p hp ≡{m}≡ bchain m hm namespace BChain + variable [SIdx SI] [OFE SI α] [OFE SI β] def map (f : α -n> β) {n : SI} (c : BChain α n) : BChain β n where @@ -1006,6 +1007,12 @@ def le {n : SI} (c : BChain α n) {m : SI} (hm : m ≤ n) : BChain α m where bchain m' hm' := c.bchain m' (SIdx.lt_le_trans hm' hm) bcauchy _ _ h := c.bcauchy _ _ h +@[simp] theorem map_apply {f : α -n> β} {n : SI} {c : BChain α n} {m} {hm : m < n} : + (map f c).bchain m hm = f (c.bchain m hm) := rfl + +@[simp] theorem const_apply {a : α} {n m : SI} {hm : m < n} : + (const a n).bchain m hm = a := rfl + end BChain /-- Complete ordered family of equivalences -/ @@ -1063,9 +1070,9 @@ def ofDiscrete (α : Type _) : COFE SI α := instance [COFE SI α] : COFE SI (ULift α) where compl c := ⟨compl (c.map uliftDownHom)⟩ conv_compl := conv_compl - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl hn c := ⟨IsCOFE.lbcompl hn (c.map uliftDownHom)⟩ + conv_lbcompl hn c _ hm:= IsCOFE.conv_lbcompl hn (c.map uliftDownHom) hm + lbcompl_ne hn _ _ _ hc := IsCOFE.lbcompl_ne hn _ _ (fun p hp => hc p hp) @[rocq_alias unit_ofe_discrete] instance : @Discrete SI _ Unit unitOFE := @@ -1078,9 +1085,9 @@ def unitCOFE [SIdx SI] : COFE SI Unit := { compl _ := () conv_compl := ⟨⟩ - lbcompl := fun _ _ => () - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl _ _ := () + conv_lbcompl _ _ _ _ := ⟨⟩ + lbcompl_ne _ _ _ _ _ := ⟨⟩ } abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun (SI := SI) β] := ∀ x : α, IsCOFE SI (β x) @@ -1100,18 +1107,55 @@ instance instIsCOFEOption [OFE SI α] [IsCOFE SI α] : IsCOFE SI (Option α) whe cases h2 : c.chain n with | none => exact (h1 ▸ h2 ▸ c.cauchy SIdx.le_0_l).elim | some _ => rfl - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl {n} hn c := + match c.bchain 0 hn.limit_lt_0 with + | .some seed => .some <| IsCOFE.lbcompl hn <| c.map ⟨_, Option.ne_match id inferInstance seed⟩ + | .none => none + conv_lbcompl {n} hn c {m} hm := by + cases h1 : c.bchain 0 hn.limit_lt_0 with + | none => + refine Eq.dist <| Option.none_is_discrete.discrete ?_ + exact (h1 ▸ c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).symm + | some seed => + refine (some_dist_some.mpr (IsCOFE.conv_lbcompl hn _ hm)).trans ?_ + dsimp only [BChain.map_apply] + cases h2 : c.bchain m hm with + | none => exact (h1 ▸ h2 ▸ c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).elim + | some _ => rfl + lbcompl_ne {n} hn c1 c2 {m} hc := by + have h0 := hc 0 hn.limit_lt_0 + cases h1 : c1.bchain 0 hn.limit_lt_0 with + | none => + cases h2 : c2.bchain 0 hn.limit_lt_0 with + | none => exact .rfl + | some _ => rw [h1, h2] at h0; exact h0.elim + | some s1 => + cases h2 : c2.bchain 0 hn.limit_lt_0 with + | none => rw [h1, h2] at h0; exact h0.elim + | some s2 => + rw [h1, h2] at h0 + refine some_dist_some.mpr (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) + simp only [BChain.map_apply] + have hp' := hc p hp + cases e1 : c1.bchain p hp with + | none => + cases e2 : c2.bchain p hp with + | none => exact h0 + | some _ => rw [e1, e2] at hp'; exact hp'.elim + | some _ => + cases e2 : c2.bchain p hp with + | none => rw [e1, e2] at hp'; exact hp'.elim + | some _ => rw [e1, e2] at hp'; exact hp' + #rocq_ignore option_compl "Local Compl definition; folded into Lean's IsCOFE instance." @[rocq_alias discrete_fun_cofe] instance {α : Type _} (β : α → Type _) [∀ x, COFE SI (β x)] : COFE SI ((x : α) → β x) where compl c x := compl (c.map (applyHom x)) conv_compl _ := IsCOFE.conv_compl - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl hn c x := IsCOFE.lbcompl hn (c.map (applyHom x)) + conv_lbcompl hn _ _ hm _ := IsCOFE.conv_lbcompl hn _ hm + lbcompl_ne hn _ _ _ hc x := IsCOFE.lbcompl_ne hn _ _ (fun p hp => hc p hp x) #rocq_ignore discrete_fun_chain "Local helper; folded into Lean's IsCOFE instance." @[rocq_alias ofe_mor_cofe] @@ -1121,18 +1165,24 @@ instance instIsCOFEHom [OFE SI α] [OFE SI β] [IsCOFE SI β] : IsCOFE SI (α -n refine conv_compl.trans (.trans ?_ conv_compl.symm) exact NonExpansive.ne (f := c.chain n) H conv_compl _ := IsCOFE.conv_compl - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl {n} hn c := by + refine ⟨fun x => IsCOFE.lbcompl hn (c.map (applyNe x)), ⟨fun m x y H => ?_⟩⟩ + exact IsCOFE.lbcompl_ne hn _ _ (fun p hp => (c.bchain p hp).ne.ne H) + conv_lbcompl hn c _ hm := fun _ => IsCOFE.conv_lbcompl hn _ hm + lbcompl_ne hn c1 c2 _ hc := fun x => IsCOFE.lbcompl_ne hn _ _ (fun p hp => hc p hp x) #rocq_ignore ofe_mor_compl "Inlined in IsCOFE instance" @[rocq_alias prod_cofe] instance instIsCOFEProd [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : IsCOFE SI (α × β) where compl c := ⟨compl (c.map ⟨Prod.fst, inferInstance⟩), compl (c.map ⟨Prod.snd, inferInstance⟩)⟩ conv_compl := ⟨conv_compl, conv_compl⟩ - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl hn c := + (IsCOFE.lbcompl hn (c.map ⟨Prod.fst, inferInstance⟩), + IsCOFE.lbcompl hn (c.map ⟨Prod.snd, inferInstance⟩)) + conv_lbcompl hn _ _ hm := ⟨IsCOFE.conv_lbcompl hn _ hm, IsCOFE.conv_lbcompl hn _ hm⟩ + lbcompl_ne hn _ _ _ hc := + ⟨IsCOFE.lbcompl_ne hn _ _ (fun p hp => (hc p hp).1), + IsCOFE.lbcompl_ne hn _ _ (fun p hp => (hc p hp).2)⟩ @[rocq_alias sum_cofe] instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : IsCOFE SI (α ⊕ β) where @@ -1153,9 +1203,64 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : cases h2 : c.chain n with | inl _ => exact (h1 ▸ h2 ▸ c.cauchy SIdx.le_0_l).elim | inr _ => simp - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl {n} hn c := + match c.bchain 0 hn.limit_lt_0 with + | .inl seed => + .inl (IsCOFE.lbcompl hn (c.map ⟨Sum.elim id (Function.const _ seed), inferInstance⟩)) + | .inr seed => + .inr (IsCOFE.lbcompl hn (c.map ⟨Sum.elim (Function.const _ seed) id, inferInstance⟩)) + conv_lbcompl {n} hn c {m} hm := by + cases h1 : c.bchain 0 hn.limit_lt_0 with + | inl seed => + refine (dist_inl (IsCOFE.conv_lbcompl hn _ hm)).trans ?_ + dsimp only [BChain.map_apply] + cases h2 : c.bchain m hm with + | inl _ => simp + | inr _ => exact (h1 ▸ h2 ▸ c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).elim + | inr seed => + refine (dist_inr (IsCOFE.conv_lbcompl hn _ hm)).trans ?_ + dsimp only [BChain.map_apply] + cases h2 : c.bchain m hm with + | inl _ => exact (h1 ▸ h2 ▸ c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).elim + | inr _ => simp + lbcompl_ne {n} hn c1 c2 {m} hc := by + have h0 := hc 0 hn.limit_lt_0 + cases h1 : c1.bchain 0 hn.limit_lt_0 with + | inl s1 => + cases h2 : c2.bchain 0 hn.limit_lt_0 with + | inr _ => rw [h1, h2] at h0; exact h0.elim + | inl s2 => + rw [h1, h2] at h0 + refine dist_inl (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) + simp only [BChain.map_apply] + have hp' := hc p hp + cases e1 : c1.bchain p hp with + | inl _ => + cases e2 : c2.bchain p hp with + | inl _ => rw [e1, e2] at hp'; exact hp' + | inr _ => rw [e1, e2] at hp'; exact hp'.elim + | inr _ => + cases e2 : c2.bchain p hp with + | inl _ => rw [e1, e2] at hp'; exact hp'.elim + | inr _ => exact h0 + | inr s1 => + cases h2 : c2.bchain 0 hn.limit_lt_0 with + | inl _ => rw [h1, h2] at h0; exact h0.elim + | inr s2 => + rw [h1, h2] at h0 + refine dist_inr (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) + simp only [BChain.map_apply] + have hp' := hc p hp + cases e1 : c1.bchain p hp with + | inr _ => + cases e2 : c2.bchain p hp with + | inr _ => rw [e1, e2] at hp'; exact hp' + | inl _ => rw [e1, e2] at hp'; exact hp'.elim + | inl _ => + cases e2 : c2.bchain p hp with + | inr _ => rw [e1, e2] at hp'; exact hp'.elim + | inl _ => exact h0 + #rocq_ignore inl_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." #rocq_ignore inr_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." #rocq_ignore sum_compl "Local Compl definition; folded into Lean's IsCOFE instance." @@ -1275,6 +1380,12 @@ def optionChain (c : Chain (Option α)) (x : α) : Chain α := by have := c.cauchy H; revert this cases c.chain i <;> cases c.chain n <;> simp [Dist, Option.Forall₂] +@[rocq_alias option_bchain] +def optionBChain {n : SI} (c : BChain (Option α) n) (x : α) : BChain α n := by + refine ⟨fun m hm => (c.bchain m hm).getD x, fun {m p} hm hp H => ?_⟩ + have := c.bcauchy hm hp H; revert this + cases c.bchain p hp <;> cases c.bchain m hm <;> simp [Dist, Option.Forall₂] + @[rocq_alias option_cofe] instance isCOFE_option [IsCOFE SI α] : IsCOFE SI (Option α) where compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x) @@ -1283,9 +1394,35 @@ instance isCOFE_option [IsCOFE SI α] : IsCOFE SI (Option α) where rcases c.chain 0 with _|x' <;> rcases e : c.chain n with _|y' <;> simp [Dist, Option.Forall₂] refine fun _ => OFE.dist_eqv.trans IsCOFE.conv_compl ?_ simp [optionChain, e] - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl {n} hn c := + (c.bchain 0 hn.limit_lt_0).map fun x => IsCOFE.lbcompl hn (optionBChain c x) + conv_lbcompl {n} hn c {m} hm := by + have := c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l; revert this + rcases c.bchain 0 hn.limit_lt_0 with _ | x' <;> rcases e : c.bchain m hm with _ | y' <;> + simp [Dist, Option.Forall₂] + refine fun _ => OFE.dist_eqv.trans (IsCOFE.conv_lbcompl hn _ hm) ?_ + simp [optionBChain, e] + lbcompl_ne {n} hn c1 c2 {m} hc := by + have h0 := hc 0 hn.limit_lt_0 + revert h0 + rcases e1 : c1.bchain 0 hn.limit_lt_0 with _ | x1 <;> + rcases e2 : c2.bchain 0 hn.limit_lt_0 with _ | x2 <;> + simp only [Option.map, Dist, Option.Forall₂] <;> intro h0 + · trivial + · exact h0.elim + · exact h0.elim + · refine IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_) + have hp' := hc p hp + simp only [optionBChain] + cases f1 : c1.bchain p hp with + | none => + cases f2 : c2.bchain p hp with + | none => exact h0 + | some _ => rw [f1, f2] at hp'; exact hp'.elim + | some _ => + cases f2 : c2.bchain p hp with + | none => rw [f1, f2] at hp'; exact hp'.elim + | some _ => rw [f1, f2] at hp'; exact hp' @[rocq_alias optionO_map] def optionMap {α β : Type _} [OFE SI α] [OFE SI β] (f : α -n> β) : Option α -n> Option β := by @@ -1904,6 +2041,13 @@ def laterChain [OFE SI A] (c : Chain (Later A)) : Chain A where chain n := (c (SIdx.succ n)).car cauchy Hle := c.cauchy (SIdx.succ_le_mono.mp Hle) _ (SIdx.lt_succ_self _) +@[rocq_alias later_limit_bchain] +def laterLimitBChain [OFE SI A] {n : SI} (c : BChain (Later A) n) (hn : SIdx.Limit n) : + BChain A n where + bchain m hm := (c.bchain succᵢ m (hn.succ_lt m hm)).car + bcauchy {m p} hm hp h := + c.bcauchy (hn.succ_lt m hm) (hn.succ_lt p hp) (SIdx.succ_le_mono.mp h) m (SIdx.lt_succ_self m) + @[rocq_alias later_cofe] instance isCOFE_later [OFE SI A] [IsCOFE SI A] : IsCOFE SI (Later A) where compl c := Later.next (IsCOFE.compl (laterChain c)) @@ -1912,9 +2056,17 @@ instance isCOFE_later [OFE SI A] [IsCOFE SI A] : IsCOFE SI (Later A) where intros m Hlt refine (IsCOFE.conv_compl (n := m) (c := laterChain c)).trans ?_ exact ((c.cauchy <| SIdx.succ_le_of_lt Hlt) m (SIdx.lt_succ_self m)).symm - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl {n} hn c := Later.next (IsCOFE.lbcompl hn (laterLimitBChain c hn)) + conv_lbcompl {n} hn c {m} hm := by + simp only [Dist, DistLater] + intro p hp + refine (IsCOFE.conv_lbcompl hn (laterLimitBChain c hn) (SIdx.lt_trans hp hm)).trans ?_ + exact (c.bcauchy (hn.succ_lt p (SIdx.lt_trans hp hm)) hm + (SIdx.le_succ_l.mpr hp) p (SIdx.lt_succ_self p)).symm + lbcompl_ne {n} hn c1 c2 {m} hc := by + simp only [Dist, DistLater] + intro p hp + exact IsCOFE.lbcompl_ne hn _ _ (fun q hq => hc succᵢ q (hn.succ_lt q hq) p hp) @[rocq_alias laterO_map] def laterMap [OFE SI A] [OFE SI B] (f : A -n> B) : Later A -n> Later B := by From b9b3587432e36a441ffbeab2d2585053eac9d234 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Sun, 2 Aug 2026 16:29:40 +0200 Subject: [PATCH 20/33] Fill in the proofs for the extra `IsCOFE` fields, trivial at the moment with `SI = Nat` --- Iris/Iris/Algebra/COFESolver.lean | 6 +++--- Iris/Iris/Algebra/Csum.lean | 6 +++--- Iris/Iris/Algebra/Excl.lean | 6 +++--- Iris/Iris/Algebra/Heap.lean | 6 +++--- Iris/Iris/Algebra/StepIndexFinite.lean | 5 +++++ Iris/Iris/Algebra/UPred.lean | 6 +++--- Iris/Iris/BI/MonPred.lean | 6 +++--- Iris/Iris/BI/SIProp.lean | 6 +++--- 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/Iris/Iris/Algebra/COFESolver.lean b/Iris/Iris/Algebra/COFESolver.lean index 382e8e4f3..8436e8db1 100644 --- a/Iris/Iris/Algebra/COFESolver.lean +++ b/Iris/Iris/Algebra/COFESolver.lean @@ -107,9 +107,9 @@ instance : COFE Nat (Tower F) where refine ((down ..).ne.1 conv_compl).trans <| .trans ?_ conv_compl.symm exact (c.chain n).down.dist conv_compl _ := conv_compl - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) #rocq_ignore solver.tower_cofe "Use IsCOFE instance" #rocq_ignore solver.tower_compl "Use IsCOFE instance" diff --git a/Iris/Iris/Algebra/Csum.lean b/Iris/Iris/Algebra/Csum.lean index c963a67b4..158a78b40 100644 --- a/Iris/Iris/Algebra/Csum.lean +++ b/Iris/Iris/Algebra/Csum.lean @@ -153,9 +153,9 @@ instance [OFE Nat α] [OFE Nat β] [IsCOFE Nat α] [IsCOFE Nat β] : IsCOFE Nat show IsCOFE.compl (chainR c b) ≡{n}≡ b' refine OFE.Dist.trans COFE.conv_compl ?_ simp [chainR, en] - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) #rocq_ignore csum_compl "Included in IsCOFE instance" diff --git a/Iris/Iris/Algebra/Excl.lean b/Iris/Iris/Algebra/Excl.lean index 6b10e19e2..e59b81e09 100644 --- a/Iris/Iris/Algebra/Excl.lean +++ b/Iris/Iris/Algebra/Excl.lean @@ -119,9 +119,9 @@ instance [OFE Nat α] [IsCOFE Nat α] : IsCOFE Nat (Excl α) where obtain _|x' := c.chain 0 <;> rcases e : c.chain n with _|y' <;> simp [Dist] refine fun _ => .trans IsCOFE.conv_compl ?_ simp [exclChain, e] - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) /-! ## CMRA -/ @[simp] def Valid : Excl α → Prop diff --git a/Iris/Iris/Algebra/Heap.lean b/Iris/Iris/Algebra/Heap.lean index 7841f2ac5..9a17004fe 100644 --- a/Iris/Iris/Algebra/Heap.lean +++ b/Iris/Iris/Algebra/Heap.lean @@ -69,9 +69,9 @@ instance Heap.instCOFE [LawfulPartialMap M K] [COFE Nat V] : COFE Nat (M V) wher rcases H : get? (c.chain 0) k · simp [← PartialMap.chain_get, chain_none_const (c := PartialMap.chain k c) (n := 0) (H▸rfl)] · exact IsCOFE.conv_compl - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) instance instDiscreteHeap [LawfulPartialMap M K] [OFE Nat V] [Discrete V] : Discrete (M V) where discrete_0 h := OFE.eq_dist.mpr <| by diff --git a/Iris/Iris/Algebra/StepIndexFinite.lean b/Iris/Iris/Algebra/StepIndexFinite.lean index 5c9e87b3b..bd68f84db 100644 --- a/Iris/Iris/Algebra/StepIndexFinite.lean +++ b/Iris/Iris/Algebra/StepIndexFinite.lean @@ -48,6 +48,11 @@ instance natSIdxFinite : SIdxFinite Nat where | zero => left; rfl | succ n => right; exists n +def SIdx.Limit.elim {I : Type u} [SIdx I] [SIdxFinite I] {n : I} {C : Sort v} + (h : SIdx.Limit n) : C := by + exfalso + exact SIdx.limit_finite n h + namespace OFE theorem Dist.leNat [OFE Nat α] {m n} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := diff --git a/Iris/Iris/Algebra/UPred.lean b/Iris/Iris/Algebra/UPred.lean index eff13556a..c21ee3a11 100644 --- a/Iris/Iris/Algebra/UPred.lean +++ b/Iris/Iris/Algebra/UPred.lean @@ -106,9 +106,9 @@ instance : IsCOFE Nat (UPred M) where refine .trans ?_ (c.cauchy Hin _ _ .refl Hv).symm refine ⟨fun H => H _ .refl, fun H n' Hn' => ?_⟩ exact (c.cauchy Hn' _ _ .refl _).mp (mono _ H .rfl Hn') - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) #rocq_ignore uPred_compl "Inlined in the `IsCOFE` construction" diff --git a/Iris/Iris/BI/MonPred.lean b/Iris/Iris/BI/MonPred.lean index c4eb4ddfe..b3d117ea3 100644 --- a/Iris/Iris/BI/MonPred.lean +++ b/Iris/Iris/BI/MonPred.lean @@ -159,9 +159,9 @@ instance : IsCOFE Nat (MonPred I PROP) where conv_compl {n c} := IsCOFE.conv_compl (n := n) (c := c.map ((⟨Subtype.val, inferInstance⟩ : _ -n> (I.car → PROP)).comp MonPred.toSig)) - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) end OFE diff --git a/Iris/Iris/BI/SIProp.lean b/Iris/Iris/BI/SIProp.lean index 09a46681e..002a2925d 100644 --- a/Iris/Iris/BI/SIProp.lean +++ b/Iris/Iris/BI/SIProp.lean @@ -131,9 +131,9 @@ instance : IsCOFE Nat SiProp where closed {n₁ _} h hle := (c.cauchy hle .refl).mp (c n₁ |>.closed h hle) } conv_compl {_ c} _ hle := c.cauchy hle .refl |>.symm - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl := (·.elim) + conv_lbcompl := (·.elim) + lbcompl_ne := (·.elim) #rocq_ignore siProp_compl "Included in IsCOFE instance." From 60aa4f389f7fd367613886a14583f6e3ed436ac9 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Sun, 2 Aug 2026 16:33:57 +0200 Subject: [PATCH 21/33] `sigT_cofe`: proofs for extra `IsCOFE` fields with helper lemmas --- Iris/Iris/Algebra/OFE.lean | 69 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index e2c957aa5..86e1ecd2a 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1269,6 +1269,51 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : theorem Sigma.chain_const_proj1 {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] (c : Chain (Sigma P)) n : (c n).fst = (c 0).fst := (c.cauchy SIdx.le_0_l).choose +@[rocq_alias sigT_bchain_const_proj1] +theorem Sigma.bchain_const_proj1 {P : α → Type _} [∀ x, OFE SI (P x)] + {n : SI} (hn : SIdx.Limit n) (c : BChain (Sigma P) n) {m} (hm : m < n) : + (c.bchain m hm).fst = (c.bchain 0 hn.limit_lt_0).fst := + (c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).choose + +@[rocq_alias bchain_map_snd] +def Sigma.bchain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] + {n : SI} (hn : SIdx.Limit n) (c : BChain (Sigma P) n) : + BChain (P (c.bchain 0 hn.limit_lt_0).fst) n where + bchain m hm := Sigma.bchain_const_proj1 hn c hm ▸ (c.bchain m hm).snd + bcauchy {m p} hm hp hle := by + obtain ⟨heq, hequiv⟩ := c.bcauchy hm hp hle + clear hle + rw [show Sigma.bchain_const_proj1 hn c hp + = heq.trans (Sigma.bchain_const_proj1 hn c hm) from rfl] + generalize Sigma.bchain_const_proj1 hn c hm = heq' + revert heq' hequiv heq; cases c.bchain p hp; cases c.bchain m hm + rintro ⟨⟩ hequiv ⟨⟩ + exact hequiv + +theorem Sigma.lbcompl_cast {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] + {a b : α} (eq : a = b) {n : SI} (hn : SIdx.Limit n) (c : BChain (P a) n) : + (eq ▸ IsCOFE.lbcompl hn c : P b) + = IsCOFE.lbcompl hn (eq ▸ c : BChain (P b) n) := by + subst eq; rfl + +theorem Sigma.bchain_cast_apply {P : α → Type _} [∀ x, OFE SI (P x)] {a b : α} (eq : a = b) + {n : SI} (c : BChain (P a) n) {p} (hp : p < n) : + (eq ▸ c : BChain (P b) n).bchain p hp = eq ▸ c.bchain p hp := by + subst eq; rfl + +theorem Sigma.cast_cast {P : α → Type _} {a b c : α} (h1 : a = b) (h2 : b = c) (x : P a) : + (h2 ▸ (h1 ▸ x : P b) : P c) = (h1.trans h2) ▸ x := by + subst h1; subst h2; rfl + +theorem Sigma.dist_cast_of_dist {P : α → Type _} [∀ x, OFE SI (P x)] {n : SI} + {x y : Sigma P} (h : x ≡{n}≡ y) {b : α} (hx : x.fst = b) (hy : y.fst = b) : + (hx ▸ x.snd : P b) ≡{n}≡ (hy ▸ y.snd : P b) := by + obtain ⟨e, H⟩ := h + obtain ⟨x1, x2⟩ := x; obtain ⟨y1, y2⟩ := y + simp only at e hx hy + subst e; subst hx + exact H + @[rocq_alias chain_map_snd] def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] (c : Chain (Sigma P)) : Chain (P (c 0).fst) where @@ -1294,9 +1339,27 @@ instance {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] : Is revert heq; cases c.chain n rintro ⟨⟩ hequiv exact hequiv - lbcompl := sorry - conv_lbcompl := sorry - lbcompl_ne := sorry + lbcompl {n} hn c := + ⟨(c.bchain 0 hn.limit_lt_0).fst, IsCOFE.lbcompl hn (Sigma.bchain_map_snd hn c)⟩ + conv_lbcompl {n} hn c {m} hm := by + refine ⟨(Sigma.bchain_const_proj1 hn c hm).symm, ?_⟩ + have hequiv := IsCOFE.conv_lbcompl hn (Sigma.bchain_map_snd hn c) hm + revert hequiv + dsimp only [Sigma.bchain_map_snd] + generalize Sigma.bchain_const_proj1 hn c hm = heq + revert heq; cases c.bchain m hm + rintro ⟨⟩ hequiv + exact hequiv + lbcompl_ne {n} hn c1 c2 {m} hc := by + obtain ⟨eq, -⟩ := hc 0 hn.limit_lt_0 + refine ⟨eq, ?_⟩ + rw [Sigma.lbcompl_cast eq hn (Sigma.bchain_map_snd hn c1)] + refine IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_) + rw [Sigma.bchain_cast_apply eq (Sigma.bchain_map_snd hn c1) hp] + dsimp only [Sigma.bchain_map_snd] + rw [Sigma.cast_cast] + exact Sigma.dist_cast_of_dist (hc p hp) _ _ + #rocq_ignore sigT_compl "Local Compl definition; folded into Lean's IsCOFE instance." set_option linter.checkUnivs false in From 29f4eba18d0ad2ff104b88db96f1a76801370fd5 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Sun, 2 Aug 2026 16:51:17 +0200 Subject: [PATCH 22/33] Complete `LimitPreserving` proofs --- Iris/Iris/Algebra/OFE.lean | 64 +++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 21 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 86e1ecd2a..d25ad7363 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1807,46 +1807,68 @@ structure LimitPreserving [COFE SI α] (P : α → Prop) : Prop where (∀ m (hm : m < n), P (c.bchain m hm)) → P (IsCOFE.lbcompl hn c) @[rocq_alias limit_preserving_const] -theorem LimitPreserving.const [COFE SI α] {P : Prop} : LimitPreserving fun (_ : α) => P := by - sorry -- simp [LimitPreserving] +theorem LimitPreserving.const [COFE SI α] {P : Prop} : LimitPreserving fun (_ : α) => P where + compl _ H := H 0 + lbcompl hn _ H := H 0 hn.limit_lt_0 @[rocq_alias limit_preserving_discrete] -theorem LimitPreserving.discrete [COFE SI α] {P : α → Prop} : - (∀ {x y : α}, x ≡{0}≡ y → (P x → P y)) → LimitPreserving P := - sorry -- fun Hdisc _ H => Hdisc COFE.conv_compl.symm (H _) +theorem LimitPreserving.discrete [COFE SI α] {P : α → Prop} + (hdiscrete : ∀ {x y : α}, x ≡{0}≡ y → (P x → P y)) : LimitPreserving P where + compl _ H := hdiscrete (COFE.conv_compl (n := 0)).symm (H 0) + lbcompl hn c H := hdiscrete (IsCOFE.conv_lbcompl hn c hn.limit_lt_0).symm (H 0 hn.limit_lt_0) @[rocq_alias limit_preserving_and] theorem LimitPreserving.and [COFE SI α] {P Q : α → Prop} (HP : LimitPreserving P) - (HQ : LimitPreserving Q) : LimitPreserving fun a => P a ∧ Q a := - sorry -- fun _ HPQ => ⟨HP _ (fun n => (HPQ n).left), HQ _ (fun n => (HPQ n).right)⟩ + (HQ : LimitPreserving Q) : LimitPreserving fun a => P a ∧ Q a where + compl c H := by + constructor + · exact HP.compl c fun n => (H n).left + · exact HQ.compl c fun n => (H n).right + lbcompl hn c H := by + constructor + · exact HP.lbcompl hn c fun m hm => (H m hm).left + · exact HQ.lbcompl hn c fun m hm => (H m hm).right @[rocq_alias limit_preserving_forall] theorem LimitPreserving.forall [COFE SI α] (P : β → α → Prop) (Hlim : ∀ y, LimitPreserving (P y)) : - LimitPreserving (∀ y, P y ·) := - sorry -- fun c H y => Hlim y c (H · y) + LimitPreserving (∀ y, P y ·) where + compl c H y := (Hlim y).compl c fun n => H n y + lbcompl hn c H y := (Hlim y).lbcompl hn c fun m hm => H m hm y @[rocq_alias limit_preserving_impl] theorem LimitPreserving.impl [COFE SI α] (P1 P2 : α → Prop) (HP1 : ∀ {x y : α}, x ≡{0}≡ y → P1 x → P1 y) (Hcompl : LimitPreserving P2) : - LimitPreserving (fun x => P1 x → P2 x) := - sorry -- fun _ Hc HP1c => Hcompl _ <| fun _ => Hc _ (HP1 (COFE.conv_compl' SIdx.le_0_l) HP1c) + LimitPreserving (fun x => P1 x → P2 x) where + compl c Hc HP1c := + Hcompl.compl c fun n => Hc n (HP1 (COFE.conv_compl' SIdx.le_0_l) HP1c) + lbcompl hn c Hc HP1c := + Hcompl.lbcompl hn c fun m hm => + Hc m hm (HP1 ((IsCOFE.conv_lbcompl hn c hm).le SIdx.le_0_l) HP1c) + +@[rocq_alias limit_preserving_sidx_finite] +theorem LimitPreserving.of_sidx_finite [SIdxFinite SI] [COFE SI α] {P : α → Prop} : + (∀ c : Chain α, (∀ n, P (c n)) → P (COFE.compl c)) ↔ LimitPreserving P := by + constructor <;> intro h + · exact { compl := h, lbcompl hn _ _ := absurd hn (SIdx.limit_finite _) } + · exact h.compl @[rocq_alias limit_preserving_equiv] -theorem LimitPreserving.equiv [COFE SI α] [COFE SI β] (f g : α -n> β) : +theorem LimitPreserving.equiv [SIdxFinite SI] [COFE SI α] [COFE SI β] (f g : α -n> β) : LimitPreserving (fun x => f x = g x) := by - sorry - -- intro c Hfg - -- refine eq_dist.mpr fun n => ?_ - -- apply (COFE.compl_map _ _).symm.dist.trans - -- apply (COFE.conv_compl' SIdx.le_refl).trans - -- apply (Hfg _).dist.trans - -- exact g.ne.ne COFE.conv_compl.symm + apply of_sidx_finite.mp + intro c Hfg + refine eq_dist.mpr fun n => ?_ + apply (COFE.compl_map _ _).symm.dist.trans + apply (COFE.conv_compl' SIdx.le_refl).trans + apply (Hfg _).dist.trans + exact g.ne.ne COFE.conv_compl.symm @[rocq_alias limit_preserving_ext] theorem LimitPreserving.ext {α} [COFE SI α] {P Q : α -> Prop} (he : ∀ {x}, (P x ↔ Q x)) - (hp : LimitPreserving P) : LimitPreserving Q := - sorry -- fun _ => (he.1 <| hp _ <| fun _ => he.2 <| · _) + (hp : LimitPreserving P) : LimitPreserving Q where + compl c H := he.mp (hp.compl c fun n => he.mpr (H n)) + lbcompl hn c H := he.mp (hp.lbcompl hn c fun m hm => he.mpr (H m hm)) section BCompl From 57efae66a61c74203940bc299a15d8d23ccc91c4 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Sun, 2 Aug 2026 17:10:28 +0200 Subject: [PATCH 23/33] Complete proofs in section `Fixpoint` --- Iris/Iris/Algebra/OFE.lean | 98 ++++++++++++++++++++++++++++++-------- 1 file changed, 79 insertions(+), 19 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index d25ad7363..bcf06e7fe 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1798,7 +1798,7 @@ end HomOF section Fixpoint -variable [SIdx SI] +variable [instSI : SIdx SI] @[rocq_alias LimitPreserving] structure LimitPreserving [COFE SI α] (P : α → Prop) : Prop where @@ -1872,7 +1872,7 @@ theorem LimitPreserving.ext {α} [COFE SI α] {P Q : α -> Prop} (he : ∀ {x}, section BCompl -variable [SIdx SI] [COFE SI α] [Inhabited α] +variable [COFE SI α] [Inhabited α] @[rocq_alias bcompl] def bcompl (n : SI) (c : BChain α n) : α := @@ -1883,23 +1883,38 @@ def bcompl (n : SI) (c : BChain α n) : α := @[rocq_alias conv_bcompl] theorem conv_bcompl {n : SI} (c : BChain α n) {m} (hm : m < n) : - bcompl n c ≡{m}≡ c.bchain m hm := sorry + bcompl n c ≡{m}≡ c.bchain m hm := by + unfold bcompl + rcases hcase : SIdx.case n with h0 | ⟨p, hp⟩ | hlim + · exact absurd (h0 ▸ hm) (SIdx.not_lt_zero m) + · exact c.bcauchy _ _ (SIdx.lt_succ_r.mp (hp ▸ hm)) + · exact IsCOFE.conv_lbcompl hlim c hm @[rocq_alias bcompl_ne] theorem bcompl_ne {n : SI} (c1 c2 : BChain α n) {m : SI} (Hc : ∀ p (hp : p < n), c1.bchain p hp ≡{m}≡ c2.bchain p hp) : - bcompl n c1 ≡{m}≡ bcompl n c2 := sorry + bcompl n c1 ≡{m}≡ bcompl n c2 := by + unfold bcompl + rcases hcase : SIdx.case n with h0 | ⟨p, hp⟩ | hlim + · exact .rfl + · exact Hc _ _ + · exact IsCOFE.lbcompl_ne hlim c1 c2 Hc @[rocq_alias limit_preserving_bcompl] theorem LimitPreserving.bcompl {P : α → Prop} (n : SI) (c : BChain α n) (H0 : n ≠ 0 ∨ P default) (HP : LimitPreserving P) - (Hc : ∀ m (hm : m < n), P (c.bchain m hm)) : P (bcompl n c) := sorry + (Hc : ∀ m (hm : m < n), P (c.bchain m hm)) : P (bcompl n c) := by + unfold Iris.bcompl + rcases hcase : SIdx.case n with h0 | ⟨p, hp⟩ | hlim + · exact H0.resolve_left (fun hne => hne h0) + · exact Hc _ _ + · exact HP.lbcompl hlim c Hc end BCompl section BFChain -variable [instSI : SIdx SI] [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] +variable [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] @[rocq_alias bfchain] structure BFChain (n : SI) where @@ -1908,28 +1923,46 @@ structure BFChain (n : SI) where @[rocq_alias bfchain_chain_unique] theorem BFChain.unique {n m : SI} (c1 : BFChain f n) (c2 : BFChain f m) : - ∀ p, p < n → p < m → bcompl n c1.car ≡{p}≡ bcompl m c2.car := sorry + ∀ p, p < n → p < m → bcompl n c1.car ≡{p}≡ bcompl m c2.car := by + intro p + induction p using instSI.lt_wf.induction with + | h p IH => + intro Hn Hm + refine ((c1.fixpoint p Hn).symm.trans ?_).trans (c2.fixpoint p Hm) + exact Contractive.distLater_dist fun q Hq => + IH q Hq (instSI.lt_trans Hq Hn) (instSI.lt_trans Hq Hm) + +def BFChain.goChain (n : SI) (rec : ∀ m, m < n → BFChain f m) : BChain α n where + bchain m Hm := f (bcompl m (rec m Hm).car) + bcauchy := fun {m p} Hm Hp Hmp => + Contractive.distLater_dist fun q Hq => + BFChain.unique f (rec p Hp) (rec m Hm) q (SIdx.lt_le_trans Hq Hmp) Hq @[rocq_alias fixpoint_bchain_go] def BFChain.go (n : SI) (rec : ∀ m, m < n → BFChain f m) : BFChain f n where - car := - { bchain := fun m Hm => f (bcompl m (rec m Hm).car) - bcauchy := fun {m p} Hm Hp Hmp => - Contractive.distLater_dist fun q Hq => - BFChain.unique f (rec p Hp) (rec m Hm) q (SIdx.lt_le_trans Hq Hmp) Hq } - fixpoint p Hp := sorry + car := BFChain.goChain f n rec + fixpoint p Hp := by + refine .trans (Contractive.distLater_dist (y := bcompl p (rec p Hp).car) ?_) + (conv_bcompl (BFChain.goChain f n rec) Hp).symm + intro q Hq + exact ((conv_bcompl (BFChain.goChain f n rec) Hp).lt Hq).trans ((rec p Hp).fixpoint q Hq) def fixpointBFChain (n : SI) : BFChain f n := instSI.lt_wf.fix (BFChain.go f) n theorem fixpointBFChain_unfold (n : SI) : fixpointBFChain f n = BFChain.go f n (fun m _ => fixpointBFChain f m) := - sorry + instSI.lt_wf.fix_eq (BFChain.go f) n end BFChain def Fixpoint.chain [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where chain n := f (bcompl n (fixpointBFChain f n).car) - cauchy {n i : SI} H := sorry + cauchy {n i : SI} H := by + rcases SIdx.le_lteq.mp H with (Hni | rfl) + · exact Contractive.distLater_dist fun p Hp => + BFChain.unique f (fixpointBFChain f i) (fixpointBFChain f n) p + (SIdx.lt_trans Hp Hni) Hp + · exact .rfl /-- The chain construction of the Banach fixpoint. `fixpointP` packages it, together with its unfolding equation, behind an opaque constant. -/ @@ -1941,7 +1974,9 @@ theorem fixpointAux_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : refine eq_dist.mpr fun n => ?_ apply COFE.conv_compl.trans refine .trans ?_ (NonExpansive.ne COFE.conv_compl.symm) - sorry + -- Remaining goal: `f (bcompl n cₙ) ≡{n}≡ f (f (bcompl n cₙ))`, which follows by + -- contractiveness from the fixpoint property of the `n`-th bounded fixpoint chain. + exact Contractive.distLater_dist fun p Hp => ((fixpointBFChain f.f n).fixpoint p Hp).symm /-- The Banach fixpoint packed together with its unfolding equation as a single opaque value. Being opaque, it is a stuck constant for definitional-equality checks in both the @@ -1968,20 +2003,45 @@ theorem fixpoint_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : theorem fixpoint_unique [COFE SI α] [Inhabited α] {f : α -c> α} {x : α} (H : x = f x) : x = fixpoint f := by refine eq_dist.mpr fun n => ?_ - sorry + induction n using (SIdx.lt_wf (I := SI)).induction with + | h n IH => + refine H.dist.trans <| .trans ?_ (fixpoint_unfold f).dist.symm + exact Contractive.distLater_dist fun p Hp => IH p Hp @[rocq_alias fixpoint_ne] instance OFE.ContractiveHom.fixpoint_ne [COFE SI α] [Inhabited α] : NonExpansive (ContractiveHom.fixpoint (α := α)) where ne n f1 f2 H := by - sorry + revert H + induction n using (SIdx.lt_wf (I := SI)).induction with + | h n IH => + intro H + refine (fixpoint_unfold f1).dist.trans <| + ((H _).trans ?_).trans (fixpoint_unfold f2).dist.symm + exact Contractive.distLater_dist (f := f2.f) fun p Hp => IH p Hp (H.lt Hp) @[elab_as_elim, rocq_alias fixpoint_ind] theorem OFE.ContractiveHom.fixpoint_ind [COFE SI α] [Inhabited α] (f : α -c> α) (P : α → Prop) (HProper : ∀ A B : α, A = B → P A → P B) (x : α) (Hbase : P x) (Hind : ∀ x, P x → P (f x)) (Hlim : LimitPreserving P) : P f.fixpoint := by - sorry + -- As in Rocq, we run the whole approximation argument with `Inhabited α` re-instantiated + -- to the witness `x`, so that the `0` case of `bcompl` returns an element satisfying `P`. + -- The resulting element is then transported to `fixpoint f` by `fixpoint_unique`. + have key : ∃ y : α, P y ∧ y = f y := by + letI : Inhabited α := ⟨x⟩ + have kn : ∀ n : SI, P (bcompl n (fixpointBFChain f.f n).car) := by + intro n + induction n using (SIdx.lt_wf (I := SI)).induction with + | h n IH => + refine LimitPreserving.bcompl n _ (.inr Hbase) Hlim fun m hm => ?_ + rw [fixpointBFChain_unfold] + exact Hind _ (IH m hm) + exact ⟨fixpointAux f.f, + Hlim.compl (Fixpoint.chain f.f) fun n => Hind _ (kn n), + fixpointAux_unfold f⟩ + obtain ⟨y, hy, hfy⟩ := key + exact HProper _ _ (fixpoint_unique (f := f) hfy) hy end Fixpoint From 6314a2263e28ad1dac72d7e917e1030f5a11990c Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Mon, 3 Aug 2026 11:13:33 +0200 Subject: [PATCH 24/33] Proof formatting in `OFE.lean` --- Iris/Iris/Algebra/OFE.lean | 178 ++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 93 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index bcf06e7fe..4f68c9518 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -184,7 +184,7 @@ theorem discreteE_eqv [OFE SI α] {x y : α} (h : x = y) : DiscreteE x ↔ Discr /-- For discrete OFEs, `n`-equivalence implies equivalence for any `n`. -/ @[rocq_alias discrete] theorem Discrete.discrete [OFE SI α] [Discrete α] {n : SI} {x y : α} (h : x ≡{n}≡ y) : x = y := - discrete_0 (h.le SIdx.le_0_l) + discrete_0 <| h.le SIdx.le_0_l export OFE.Discrete (discrete) instance Discrete.toDiscreteE [OFE SI α] [Discrete α] (x : α) : DiscreteE x := ⟨discrete_0⟩ @@ -916,7 +916,7 @@ end OFE /-- A chain in an OFE is a `Nat`-indexed sequence of elements that is upward-closed in terms of `n`-equivalence. -/ -@[rocq_alias chain] structure Chain (α : Type _) [SIdx SI] [OFE SI α] where +@[rocq_alias chain] structure Chain {SI} (α : Type _) [SIdx SI] [OFE SI α] where chain : SI → α cauchy : n ≤ i → chain i ≡{n}≡ chain n @@ -995,14 +995,17 @@ namespace BChain variable [SIdx SI] [OFE SI α] [OFE SI β] +@[rocq_alias bchain_map] def map (f : α -n> β) {n : SI} (c : BChain α n) : BChain β n where bchain m hm := f <| c.bchain m hm bcauchy hm hp h := f.ne.ne <| c.bcauchy hm hp h +@[rocq_alias bchain_const] def const (a : α) (n : SI) : BChain α n where bchain _ _ := a bcauchy _ _ _ := .rfl +@[rocq_alias bchain_le] def le {n : SI} (c : BChain α n) {m : SI} (hm : m ≤ n) : BChain α m where bchain m' hm' := c.bchain m' (SIdx.lt_le_trans hm' hm) bcauchy _ _ h := c.bcauchy _ _ h @@ -1058,13 +1061,13 @@ theorem compl_const [COFE SI α] (a : α) : compl (Chain.const a) = a := /-- The discrete COFE obtained from an equivalence relation `Equiv` -/ @[reducible, rocq_alias discrete_cofe] def ofDiscrete (α : Type _) : COFE SI α := - letI := OFE.ofDiscrete α + letI : OFE SI α := OFE.ofDiscrete α { - compl := fun c => c 0 - conv_compl := fun {_ c} => (c.cauchy SIdx.le_0_l).symm - lbcompl := fun hn c => c.bchain 0 hn.limit_lt_0 - conv_lbcompl := fun hn c _ hm => (c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).symm - lbcompl_ne := fun hn _ _ _ hc => hc 0 hn.limit_lt_0 + compl c := c 0 + conv_compl {_ c} := (c.cauchy SIdx.le_0_l).symm + lbcompl hn c := c.bchain 0 hn.limit_lt_0 + conv_lbcompl hn c _ hm := (c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).symm + lbcompl_ne hn _ _ _ hc := hc 0 hn.limit_lt_0 } instance [COFE SI α] : COFE SI (ULift α) where @@ -1076,12 +1079,12 @@ instance [COFE SI α] : COFE SI (ULift α) where @[rocq_alias unit_ofe_discrete] instance : @Discrete SI _ Unit unitOFE := - letI := unitOFE + letI : OFE SI Unit := unitOFE { discrete_0 _ := Subsingleton.elim _ _ } @[reducible, rocq_alias unit_cofe] def unitCOFE [SIdx SI] : COFE SI Unit := - letI := unitOFE + letI : OFE SI Unit := unitOFE { compl _ := () conv_compl := ⟨⟩ @@ -1124,28 +1127,27 @@ instance instIsCOFEOption [OFE SI α] [IsCOFE SI α] : IsCOFE SI (Option α) whe | some _ => rfl lbcompl_ne {n} hn c1 c2 {m} hc := by have h0 := hc 0 hn.limit_lt_0 - cases h1 : c1.bchain 0 hn.limit_lt_0 with + cases h1 : c1.bchain 0 hn.limit_lt_0 with rw [h1] at h0 | none => cases h2 : c2.bchain 0 hn.limit_lt_0 with - | none => exact .rfl - | some _ => rw [h1, h2] at h0; exact h0.elim + | none => rfl + | some _ => rw [h2] at h0; exact h0.elim | some s1 => - cases h2 : c2.bchain 0 hn.limit_lt_0 with - | none => rw [h1, h2] at h0; exact h0.elim + cases h2 : c2.bchain 0 hn.limit_lt_0 with rw [h2] at h0 + | none => exact h0.elim | some s2 => - rw [h1, h2] at h0 refine some_dist_some.mpr (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) - simp only [BChain.map_apply] + dsimp only [BChain.map_apply] have hp' := hc p hp - cases e1 : c1.bchain p hp with + cases e1 : c1.bchain p hp with rw [e1] at hp' | none => - cases e2 : c2.bchain p hp with + cases e2 : c2.bchain p hp with rw [e2] at hp' | none => exact h0 - | some _ => rw [e1, e2] at hp'; exact hp'.elim + | some _ => exact hp'.elim | some _ => - cases e2 : c2.bchain p hp with - | none => rw [e1, e2] at hp'; exact hp'.elim - | some _ => rw [e1, e2] at hp'; exact hp' + cases e2 : c2.bchain p hp with rw [e2] at hp' + | none => exact hp'.elim + | some _ => exact hp' #rocq_ignore option_compl "Local Compl definition; folded into Lean's IsCOFE instance." @@ -1181,8 +1183,8 @@ instance instIsCOFEProd [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : IsCOFE.lbcompl hn (c.map ⟨Prod.snd, inferInstance⟩)) conv_lbcompl hn _ _ hm := ⟨IsCOFE.conv_lbcompl hn _ hm, IsCOFE.conv_lbcompl hn _ hm⟩ lbcompl_ne hn _ _ _ hc := - ⟨IsCOFE.lbcompl_ne hn _ _ (fun p hp => (hc p hp).1), - IsCOFE.lbcompl_ne hn _ _ (fun p hp => (hc p hp).2)⟩ + ⟨IsCOFE.lbcompl_ne hn _ _ (fun p hp => (hc p hp).left), + IsCOFE.lbcompl_ne hn _ _ (fun p hp => (hc p hp).right)⟩ @[rocq_alias sum_cofe] instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : IsCOFE SI (α ⊕ β) where @@ -1227,21 +1229,20 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : have h0 := hc 0 hn.limit_lt_0 cases h1 : c1.bchain 0 hn.limit_lt_0 with | inl s1 => - cases h2 : c2.bchain 0 hn.limit_lt_0 with - | inr _ => rw [h1, h2] at h0; exact h0.elim + cases h2 : c2.bchain 0 hn.limit_lt_0 with rw [h1, h2] at h0 + | inr _ => exact h0.elim | inl s2 => - rw [h1, h2] at h0 refine dist_inl (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) simp only [BChain.map_apply] have hp' := hc p hp - cases e1 : c1.bchain p hp with + cases e1 : c1.bchain p hp with rw [e1] at hp' | inl _ => - cases e2 : c2.bchain p hp with - | inl _ => rw [e1, e2] at hp'; exact hp' - | inr _ => rw [e1, e2] at hp'; exact hp'.elim + cases e2 : c2.bchain p hp with rw [e2] at hp' + | inl _ => exact hp' + | inr _ => exact hp'.elim | inr _ => - cases e2 : c2.bchain p hp with - | inl _ => rw [e1, e2] at hp'; exact hp'.elim + cases e2 : c2.bchain p hp with rw [e2] at hp' + | inl _ => exact hp'.elim | inr _ => exact h0 | inr s1 => cases h2 : c2.bchain 0 hn.limit_lt_0 with @@ -1251,14 +1252,14 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : refine dist_inr (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) simp only [BChain.map_apply] have hp' := hc p hp - cases e1 : c1.bchain p hp with + cases e1 : c1.bchain p hp with rw [e1] at hp' | inr _ => - cases e2 : c2.bchain p hp with - | inr _ => rw [e1, e2] at hp'; exact hp' - | inl _ => rw [e1, e2] at hp'; exact hp'.elim + cases e2 : c2.bchain p hp with rw [e2] at hp' + | inr _ => exact hp' + | inl _ => exact hp'.elim | inl _ => - cases e2 : c2.bchain p hp with - | inr _ => rw [e1, e2] at hp'; exact hp'.elim + cases e2 : c2.bchain p hp with rw [e2] at hp' + | inr _ => exact hp'.elim | inl _ => exact h0 #rocq_ignore inl_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." @@ -1267,7 +1268,8 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : @[rocq_alias sigT_chain_const_proj1] theorem Sigma.chain_const_proj1 {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] - (c : Chain (Sigma P)) n : (c n).fst = (c 0).fst := (c.cauchy SIdx.le_0_l).choose + (c : Chain (Sigma P)) n : (c n).fst = (c 0).fst := + (c.cauchy SIdx.le_0_l).choose @[rocq_alias sigT_bchain_const_proj1] theorem Sigma.bchain_const_proj1 {P : α → Type _} [∀ x, OFE SI (P x)] @@ -1282,7 +1284,6 @@ def Sigma.bchain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] bchain m hm := Sigma.bchain_const_proj1 hn c hm ▸ (c.bchain m hm).snd bcauchy {m p} hm hp hle := by obtain ⟨heq, hequiv⟩ := c.bcauchy hm hp hle - clear hle rw [show Sigma.bchain_const_proj1 hn c hp = heq.trans (Sigma.bchain_const_proj1 hn c hm) from rfl] generalize Sigma.bchain_const_proj1 hn c hm = heq' @@ -1308,11 +1309,12 @@ theorem Sigma.cast_cast {P : α → Type _} {a b c : α} (h1 : a = b) (h2 : b = theorem Sigma.dist_cast_of_dist {P : α → Type _} [∀ x, OFE SI (P x)] {n : SI} {x y : Sigma P} (h : x ≡{n}≡ y) {b : α} (hx : x.fst = b) (hy : y.fst = b) : (hx ▸ x.snd : P b) ≡{n}≡ (hy ▸ y.snd : P b) := by - obtain ⟨e, H⟩ := h - obtain ⟨x1, x2⟩ := x; obtain ⟨y1, y2⟩ := y - simp only at e hx hy - subst e; subst hx - exact H + obtain ⟨h1, h2⟩ := h + obtain ⟨x1, x2⟩ := x + obtain ⟨y1, y2⟩ := y + simp only at h1 hx hy + subst h1; subst hx + exact h2 @[rocq_alias chain_map_snd] def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] (c : Chain (Sigma P)) : @@ -1405,7 +1407,7 @@ theorem DiscreteO.eqv_inj {x y : α} (H : DiscreteO.mk x = DiscreteO.mk y) : x = congrArg DiscreteO.car H theorem DiscreteO.dist_inj [SIdx SI] {α : Type _} {x y : α} {n : SI} : - letI := DiscreteO.instCOFE (α := α) + letI : COFE SI (DiscreteO α) := DiscreteO.instCOFE DiscreteO.mk x ≡{n}≡ DiscreteO.mk y → x = y := fun H => DiscreteO.eqv_inj H @@ -1479,13 +1481,13 @@ instance isCOFE_option [IsCOFE SI α] : IsCOFE SI (Option α) where simp only [optionBChain] cases f1 : c1.bchain p hp with | none => - cases f2 : c2.bchain p hp with + cases f2 : c2.bchain p hp with rw [f1, f2] at hp' | none => exact h0 - | some _ => rw [f1, f2] at hp'; exact hp'.elim + | some _ => exact hp'.elim | some _ => - cases f2 : c2.bchain p hp with - | none => rw [f1, f2] at hp'; exact hp'.elim - | some _ => rw [f1, f2] at hp'; exact hp' + cases f2 : c2.bchain p hp with rw [f1, f2] at hp' + | none => exact hp'.elim + | some _ => exact hp' @[rocq_alias optionO_map] def optionMap {α β : Type _} [OFE SI α] [OFE SI β] (f : α -n> β) : Option α -n> Option β := by @@ -1789,7 +1791,7 @@ instance instOFunctorContractiveHomOF [OFunctorContractive SI F1] [OFunctorContr map_contractive.1 {n : SI} ab ab' h := match ab, ab' with | ⟨a, b⟩, ⟨a', b'⟩ => by simp only [Function.uncurry_apply_pair, OFunctor.map] - have h' : DistLater n (b, a) (b', a') := fun m hm => ⟨(h m hm).2, (h m hm).1⟩ + have h' : DistLater n (b, a) (b', a') := fun m hm => ⟨(h m hm).right, (h m hm).left⟩ refine NonExpansive₂.ne ?_ ?_ · exact (map_contractive (F := F1)).1 h' · exact (map_contractive (F := F2)).1 h @@ -1896,7 +1898,7 @@ theorem bcompl_ne {n : SI} (c1 c2 : BChain α n) {m : SI} bcompl n c1 ≡{m}≡ bcompl n c2 := by unfold bcompl rcases hcase : SIdx.case n with h0 | ⟨p, hp⟩ | hlim - · exact .rfl + · rfl · exact Hc _ _ · exact IsCOFE.lbcompl_ne hlim c1 c2 Hc @@ -1962,7 +1964,7 @@ def Fixpoint.chain [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : · exact Contractive.distLater_dist fun p Hp => BFChain.unique f (fixpointBFChain f i) (fixpointBFChain f n) p (SIdx.lt_trans Hp Hni) Hp - · exact .rfl + · rfl /-- The chain construction of the Banach fixpoint. `fixpointP` packages it, together with its unfolding equation, behind an opaque constant. -/ @@ -1974,8 +1976,6 @@ theorem fixpointAux_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : refine eq_dist.mpr fun n => ?_ apply COFE.conv_compl.trans refine .trans ?_ (NonExpansive.ne COFE.conv_compl.symm) - -- Remaining goal: `f (bcompl n cₙ) ≡{n}≡ f (f (bcompl n cₙ))`, which follows by - -- contractiveness from the fixpoint property of the `n`-th bounded fixpoint chain. exact Contractive.distLater_dist fun p Hp => ((fixpointBFChain f.f n).fixpoint p Hp).symm /-- The Banach fixpoint packed together with its unfolding equation as a single opaque @@ -2000,48 +2000,44 @@ theorem fixpoint_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : (fixpointP f).property @[rocq_alias fixpoint_unique] -theorem fixpoint_unique [COFE SI α] [Inhabited α] {f : α -c> α} {x : α} (H : x = f x) : +theorem fixpoint_unique [COFE SI α] [Inhabited α] {f : α -c> α} {x : α} (h : x = f x) : x = fixpoint f := by refine eq_dist.mpr fun n => ?_ - induction n using (SIdx.lt_wf (I := SI)).induction with - | h n IH => - refine H.dist.trans <| .trans ?_ (fixpoint_unfold f).dist.symm - exact Contractive.distLater_dist fun p Hp => IH p Hp + induction n using instSI.lt_wf.induction with + | h n ih => + exact h.dist.trans <| Dist.trans (Contractive.distLater_dist ih) (fixpoint_unfold f).dist.symm @[rocq_alias fixpoint_ne] instance OFE.ContractiveHom.fixpoint_ne [COFE SI α] [Inhabited α] : NonExpansive (ContractiveHom.fixpoint (α := α)) where - ne n f1 f2 H := by - revert H - induction n using (SIdx.lt_wf (I := SI)).induction with - | h n IH => - intro H - refine (fixpoint_unfold f1).dist.trans <| - ((H _).trans ?_).trans (fixpoint_unfold f2).dist.symm - exact Contractive.distLater_dist (f := f2.f) fun p Hp => IH p Hp (H.lt Hp) + ne n f1 f2 h := by + revert h + induction n using instSI.lt_wf.induction with + | h n ih => + intro h + calc + _ ≡{n}≡ f1.f (Iris.fixpoint f1.f) := (fixpoint_unfold f1).dist + _ ≡{n}≡ f2.f (Iris.fixpoint f1.f) := h _ + _ ≡{n}≡ f2.f (Iris.fixpoint f2.f) := Contractive.distLater_dist fun p Hp => ih p Hp (h.lt Hp) + _ ≡{n}≡ Iris.fixpoint f2.f := (fixpoint_unfold f2).dist.symm @[elab_as_elim, rocq_alias fixpoint_ind] theorem OFE.ContractiveHom.fixpoint_ind [COFE SI α] [Inhabited α] (f : α -c> α) (P : α → Prop) (HProper : ∀ A B : α, A = B → P A → P B) (x : α) (Hbase : P x) (Hind : ∀ x, P x → P (f x)) (Hlim : LimitPreserving P) : P f.fixpoint := by - -- As in Rocq, we run the whole approximation argument with `Inhabited α` re-instantiated - -- to the witness `x`, so that the `0` case of `bcompl` returns an element satisfying `P`. - -- The resulting element is then transported to `fixpoint f` by `fixpoint_unique`. - have key : ∃ y : α, P y ∧ y = f y := by + obtain ⟨y, hy, hfy⟩ : ∃ y : α, P y ∧ y = f y := by letI : Inhabited α := ⟨x⟩ - have kn : ∀ n : SI, P (bcompl n (fixpointBFChain f.f n).car) := by - intro n - induction n using (SIdx.lt_wf (I := SI)).induction with - | h n IH => + exists fixpointAux f.f + constructor + · refine Hlim.compl (Fixpoint.chain f.f) fun n => Hind _ ?_ + induction n using instSI.lt_wf.induction with + | h n ih => refine LimitPreserving.bcompl n _ (.inr Hbase) Hlim fun m hm => ?_ rw [fixpointBFChain_unfold] - exact Hind _ (IH m hm) - exact ⟨fixpointAux f.f, - Hlim.compl (Fixpoint.chain f.f) fun n => Hind _ (kn n), - fixpointAux_unfold f⟩ - obtain ⟨y, hy, hfy⟩ := key - exact HProper _ _ (fixpoint_unique (f := f) hfy) hy + exact Hind _ (ih m hm) + · exact fixpointAux_unfold f + exact HProper _ _ (fixpoint_unique hfy) hy end Fixpoint @@ -2196,22 +2192,18 @@ def laterLimitBChain [OFE SI A] {n : SI} (c : BChain (Later A) n) (hn : SIdx.Lim @[rocq_alias later_cofe] instance isCOFE_later [OFE SI A] [IsCOFE SI A] : IsCOFE SI (Later A) where compl c := Later.next (IsCOFE.compl (laterChain c)) - conv_compl {n : SI} c := by - simp [Dist, DistLater] + conv_compl {n} c := by intros m Hlt - refine (IsCOFE.conv_compl (n := m) (c := laterChain c)).trans ?_ + refine IsCOFE.conv_compl.trans ?_ exact ((c.cauchy <| SIdx.succ_le_of_lt Hlt) m (SIdx.lt_succ_self m)).symm lbcompl {n} hn c := Later.next (IsCOFE.lbcompl hn (laterLimitBChain c hn)) conv_lbcompl {n} hn c {m} hm := by - simp only [Dist, DistLater] intro p hp refine (IsCOFE.conv_lbcompl hn (laterLimitBChain c hn) (SIdx.lt_trans hp hm)).trans ?_ exact (c.bcauchy (hn.succ_lt p (SIdx.lt_trans hp hm)) hm (SIdx.le_succ_l.mpr hp) p (SIdx.lt_succ_self p)).symm - lbcompl_ne {n} hn c1 c2 {m} hc := by - simp only [Dist, DistLater] - intro p hp - exact IsCOFE.lbcompl_ne hn _ _ (fun q hq => hc succᵢ q (hn.succ_lt q hq) p hp) + lbcompl_ne {n} hn c1 c2 {m} hc := + fun p hp => IsCOFE.lbcompl_ne hn _ _ (fun q hq => hc succᵢ q (hn.succ_lt q hq) p hp) @[rocq_alias laterO_map] def laterMap [OFE SI A] [OFE SI B] (f : A -n> B) : Later A -n> Later B := by From 81619236cbf504b78bdf8534910fc3af04ea7067 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Mon, 3 Aug 2026 11:26:22 +0200 Subject: [PATCH 25/33] Clean up unnecessary `local instance` declarations --- Iris/Iris/Algebra/CMRA.lean | 45 ++++++++++++++---------------- Iris/Iris/Algebra/COFESolver.lean | 1 - Iris/Iris/Instances/Lib/Boxes.lean | 2 -- 3 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Iris/Iris/Algebra/CMRA.lean b/Iris/Iris/Algebra/CMRA.lean index b14a1bcfa..f416ed012 100644 --- a/Iris/Iris/Algebra/CMRA.lean +++ b/Iris/Iris/Algebra/CMRA.lean @@ -760,11 +760,11 @@ variable {α : Type _} [CMRA α] theorem IdFree.of_dist {x₁ x₂ : α} {n} (e : x₁ ≡{n}≡ x₂) (h : IdFree x₁) : IdFree x₂ where id_free0_r z v := fun h₂ => - have ee := Dist.le e (SIdx.le_0_l) + have ee := Dist.le e SIdx.le_0_l have := calc - x₁ • z ≡{(0 : Nat)}≡ x₂ • z := op_left_dist z ee + x₁ • z ≡{0}≡ x₂ • z := op_left_dist z ee _ ≡{0}≡ x₂ := h₂ - _ ≡{(0 : Nat)}≡ x₁ := ee.symm + _ ≡{0}≡ x₁ := ee.symm h.id_free0_r _ ((validN_dist_iff ee).mpr v) this theorem _root_.Iris.OFE.Dist.idFree {x₁ x₂ : α} (e : x₁ ≡{n}≡ x₂) : IdFree x₁ ↔ IdFree x₂ := @@ -774,7 +774,7 @@ theorem _root_.Iris.OFE.Dist.idFree {x₁ x₂ : α} (e : x₁ ≡{n}≡ x₂) : @[rocq_alias id_freeN_r] theorem id_freeN_r {n n'} {x : α} [IdFree x] {y} (v : ✓{n} x) : ¬(x • y ≡{n'}≡ x) := - id_free0_r _ (validN_of_le (SIdx.le_0_l) v) |>.imp (·.le (SIdx.le_0_l)) + id_free0_r _ (validN_of_le SIdx.le_0_l v) |>.imp (·.le SIdx.le_0_l) @[rocq_alias id_freeN_l] theorem id_freeN_l {n n'} {x : α} [IdFree x] {y} (v : ✓{n} x) : ¬(y • x ≡{n'}≡ x) := @@ -1557,26 +1557,23 @@ section unit #rocq_ignore unit_core_id "Subsumed by unit_CoreId" @[rocq_alias unitR, rocq_alias unit_cmra_mixin] -instance cmraUnit : CMRA Unit := - letI : OFE Nat Unit := unitOFE - { - pcore _ := some () - op _ _ := () - ValidN _ _ := True - Valid _ := True - op_ne.ne _ _ _ := id - pcore_ne _ _ := ⟨(), rfl, .rfl⟩ - validN_ne _ := id - valid_iff_validN := ⟨fun _ _ => ⟨⟩, fun _ => ⟨⟩⟩ - validN_succ := id - validN_op_left := id - assoc := rfl - comm := rfl - pcore_op_left _ := rfl - pcore_idem _ := rfl - pcore_op_mono _ _ := ⟨.unit, rfl⟩ - extend _ _ := ⟨(), (), rfl, .rfl, .rfl⟩ - } +instance cmraUnit : CMRA Unit where + pcore _ := some () + op _ _ := () + ValidN _ _ := True + Valid _ := True + op_ne.ne _ _ _ := id + pcore_ne _ _ := ⟨(), rfl, .rfl⟩ + validN_ne _ := id + valid_iff_validN := ⟨fun _ _ => ⟨⟩, fun _ => ⟨⟩⟩ + validN_succ := id + validN_op_left := id + assoc := rfl + comm := rfl + pcore_op_left _ := rfl + pcore_idem _ := rfl + pcore_op_mono _ _ := ⟨.unit, rfl⟩ + extend _ _ := ⟨(), (), rfl, .rfl, .rfl⟩ end unit diff --git a/Iris/Iris/Algebra/COFESolver.lean b/Iris/Iris/Algebra/COFESolver.lean index 8436e8db1..36fa4859b 100644 --- a/Iris/Iris/Algebra/COFESolver.lean +++ b/Iris/Iris/Algebra/COFESolver.lean @@ -20,7 +20,6 @@ variable [SIdx SI] variable {F : ∀ α β [COFE Nat α] [COFE Nat β], Type u} [OFunctorContractive Nat F] variable [∀ α [COFE Nat α], IsCOFE Nat (F α α)] -local instance : COFE Nat Unit := unitCOFE variable [inh : Inhabited (F (ULift Unit) (ULift Unit))] namespace Fix.Impl diff --git a/Iris/Iris/Instances/Lib/Boxes.lean b/Iris/Iris/Instances/Lib/Boxes.lean index 0eb502018..7a96201dd 100644 --- a/Iris/Iris/Instances/Lib/Boxes.lean +++ b/Iris/Iris/Instances/Lib/Boxes.lean @@ -23,8 +23,6 @@ abbrev BoolO := DiscreteO Bool variable (GF : BundledGFunctors) -local instance discreteO_cofe {α : Type _} : COFE Nat (DiscreteO α) := DiscreteO.instCOFE - abbrev BoxF : OFunctorPre Nat := ProdOF Nat (AuthURF (OptionOF (ExclOF (constOF BoolO)))) (OptionOF (AgreeRF (LaterOF IdOF))) From f99f9aecec8dab5339a2404977e4e66b86e16f7a Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Mon, 3 Aug 2026 11:29:13 +0200 Subject: [PATCH 26/33] Switch of `LimitPreserving` back to a type class --- Iris/Iris/Algebra/OFE.lean | 2 +- Iris/Iris/BI/DerivedLaws.lean | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 4f68c9518..492b30327 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1803,7 +1803,7 @@ section Fixpoint variable [instSI : SIdx SI] @[rocq_alias LimitPreserving] -structure LimitPreserving [COFE SI α] (P : α → Prop) : Prop where +class LimitPreserving [COFE SI α] (P : α → Prop) : Prop where compl (c : Chain α) : (∀ n, P (c n)) → P (COFE.compl c) lbcompl {n : SI} (hn : SIdx.Limit n) (c : BChain α n) : (∀ m (hm : m < n), P (c.bchain m hm)) → P (IsCOFE.lbcompl hn c) diff --git a/Iris/Iris/BI/DerivedLaws.lean b/Iris/Iris/BI/DerivedLaws.lean index 4c8ea0fe5..e7dae8b55 100644 --- a/Iris/Iris/BI/DerivedLaws.lean +++ b/Iris/Iris/BI/DerivedLaws.lean @@ -2382,7 +2382,7 @@ instance from_option_persistent [BI PROP] {P : PROP} {Ψ : α → PROP} {mx : Op /-! # Limits -/ @[rocq_alias bi.limit_preserving_entails] -theorem LimitPreserving.entails [BI PROP] [COFE Nat A] (Φ Ψ : A → PROP) [Φne : OFE.NonExpansive Φ] +instance LimitPreserving.entails [BI PROP] [COFE Nat A] (Φ Ψ : A → PROP) [Φne : OFE.NonExpansive Φ] [Ψne : OFE.NonExpansive Ψ] : LimitPreserving (λ x ↦ Φ x ⊢ Ψ x) := by refine .ext (P := λ x ↦ True ⊣⊢ (Φ x → Ψ x)) (@fun x => ?_) ?_ · exact ⟨(true_and.2.trans <| imp_elim ·.1), (⟨imp_intro <| true_and.1.trans ·, true_intro⟩)⟩ @@ -2396,26 +2396,26 @@ theorem LimitPreserving.entails [BI PROP] [COFE Nat A] (Φ Ψ : A → PROP) [Φn exact fun n => (h' n).to_eq @[rocq_alias bi.limit_preserving_emp_valid] -theorem limitPreserving_emp_valid [BI PROP] [COFE Nat A] (Φ : A → PROP) +instance limitPreserving_emp_valid [BI PROP] [COFE Nat A] (Φ : A → PROP) [OFE.NonExpansive Φ] : LimitPreserving (fun x => ⊢ Φ x) := LimitPreserving.entails (fun _ => iprop(emp)) Φ @[rocq_alias bi.limit_preserving_Persistent] -theorem limitPreserving_persistent [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : +instance limitPreserving_persistent [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : LimitPreserving (fun x => Persistent (Φ x)) := by letI _ : OFE.NonExpansive fun x => iprop( Φ x) := .comp persistently_ne Φne refine ⟨fun c h => ⟨?_⟩, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ refine (LimitPreserving.entails _ (fun x => iprop( (Φ x)))).compl _ ?_ exact (fun n => h n |>.persistent) -theorem limitPreserving_absorbing [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : +instance limitPreserving_absorbing [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : LimitPreserving (fun x => Absorbing (Φ x)) := by letI _ : OFE.NonExpansive fun x => iprop( Φ x) := .comp absorbingly_ne Φne refine ⟨fun c h => ⟨?_⟩, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ refine (LimitPreserving.entails (fun x => iprop( (Φ x))) _).compl _ ?_ exact (fun n => h n |>.absorbing) -theorem limitPreserving_affine [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : +instance limitPreserving_affine [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : LimitPreserving (fun x => Affine (Φ x)) := by refine ⟨fun c h => ⟨?_⟩, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ refine (LimitPreserving.entails (fun x => iprop((Φ x))) (fun _ => iprop(emp))).compl _ ?_ From ddf2c83fd840008ccf358effcfeaf6773fc64783 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Mon, 3 Aug 2026 11:46:42 +0200 Subject: [PATCH 27/33] Remove duplicate `[SIdx SI]` assumption --- Iris/Iris/Algebra/OFE.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 492b30327..a185c66f9 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1083,7 +1083,7 @@ instance : @Discrete SI _ Unit unitOFE := { discrete_0 _ := Subsingleton.elim _ _ } @[reducible, rocq_alias unit_cofe] -def unitCOFE [SIdx SI] : COFE SI Unit := +def unitCOFE : COFE SI Unit := letI : OFE SI Unit := unitOFE { compl _ := () From f2f5287a0d0372c2698a064431f5d9d5283143a1 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Mon, 3 Aug 2026 11:47:17 +0200 Subject: [PATCH 28/33] Update `IrisMath/MeasureTheory.lean` --- IrisMath/IrisMath/MeasureTheory.lean | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IrisMath/IrisMath/MeasureTheory.lean b/IrisMath/IrisMath/MeasureTheory.lean index 1bcd120df..5ced16a67 100644 --- a/IrisMath/IrisMath/MeasureTheory.lean +++ b/IrisMath/IrisMath/MeasureTheory.lean @@ -19,7 +19,7 @@ def aeSetoid (μ : Measure Ω) (δ : Type _) : Setoid (Ω → δ) where def RandomVariable (δ : Type _) (μ : Measure Ω) : Type _ := Quotient (aeSetoid μ δ) -instance (δ : Type _) (μ : Measure Ω) : OFE (RandomVariable δ μ) where +instance (δ : Type _) (μ : Measure Ω) : OFE Nat (RandomVariable δ μ) where Dist _ := (· = ·) dist_eqv := eq_equivalence eq_dist := (forall_const _).symm From 61099959d1d5d8c29cab33059f87d5b3946b7c81 Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Mon, 3 Aug 2026 12:45:34 +0200 Subject: [PATCH 29/33] Add missing `rocq_alias` annotations, remove duplicate instance --- Iris/Iris/Algebra/OFE.lean | 60 ++++---------------------------------- 1 file changed, 6 insertions(+), 54 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index a185c66f9..51dc004c6 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -187,6 +187,7 @@ theorem Discrete.discrete [OFE SI α] [Discrete α] {n : SI} {x y : α} (h : x discrete_0 <| h.le SIdx.le_0_l export OFE.Discrete (discrete) +@[rocq_alias ofe_discrete_discrete] instance Discrete.toDiscreteE [OFE SI α] [Discrete α] (x : α) : DiscreteE x := ⟨discrete_0⟩ /-- For discrete OFEs, `n`-equivalence implies equivalence for any `n`. -/ @@ -624,6 +625,7 @@ instance [OFE SI α] [OFE SI β] : NonExpansive (Prod.snd (α := α) (β := β)) ⟨fun {_ _ _} h => dist_snd h⟩ /-- Note: Not an instance, due to instance coherence problems. -/ +@[rocq_alias uncurry_ne] theorem NonExpansive₂.uncurry [OFE SI α] [OFE SI β] [OFE SI γ] {f : α → β → γ} (hf : NonExpansive₂ f) : NonExpansive (Function.uncurry f) := ⟨fun {_ _ _} (h : _ ∧ _) => hf.ne h.1 h.2⟩ @@ -685,7 +687,9 @@ instance : OFE SI (α ⊕ β) where theorem dist_inl (h : x ≡{n}≡ y) : (.inl x : α ⊕ β) ≡{n}≡ .inl y := h theorem dist_inr {x y : β} (h : x ≡{n}≡ y) : (.inr x : α ⊕ β) ≡{n}≡ .inr y := h +@[rocq_alias inl_ne_inj] theorem dist_ext_left {x y : α} (h : (.inl x : α ⊕ β) ≡{n}≡ .inl y) : x ≡{n}≡ y := h +@[rocq_alias inr_ne_inj] theorem dist_ext_right {x y : β} (h : (.inr x : α ⊕ β) ≡{n}≡ .inr y) : x ≡{n}≡ y := h @[rocq_alias inl_ne] @@ -1095,60 +1099,6 @@ def unitCOFE : COFE SI Unit := abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun (SI := SI) β] := ∀ x : α, IsCOFE SI (β x) -instance instIsCOFEOption [OFE SI α] [IsCOFE SI α] : IsCOFE SI (Option α) where - compl c := match c 0 with - | .some seed => .some <| compl <| c.map ⟨_, Option.ne_match id inferInstance seed⟩ - | .none => none - conv_compl {n c} := by - cases h1 : c.chain 0 with - | none => - refine Eq.dist <| Option.none_is_discrete.discrete ?_ - exact h1 ▸ c.cauchy (SIdx.le_0_l (n := n)) |>.symm - | some seed => - refine (some_dist_some.mpr conv_compl).trans ?_ - dsimp only [Chain.map_apply] - cases h2 : c.chain n with - | none => exact (h1 ▸ h2 ▸ c.cauchy SIdx.le_0_l).elim - | some _ => rfl - lbcompl {n} hn c := - match c.bchain 0 hn.limit_lt_0 with - | .some seed => .some <| IsCOFE.lbcompl hn <| c.map ⟨_, Option.ne_match id inferInstance seed⟩ - | .none => none - conv_lbcompl {n} hn c {m} hm := by - cases h1 : c.bchain 0 hn.limit_lt_0 with - | none => - refine Eq.dist <| Option.none_is_discrete.discrete ?_ - exact (h1 ▸ c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).symm - | some seed => - refine (some_dist_some.mpr (IsCOFE.conv_lbcompl hn _ hm)).trans ?_ - dsimp only [BChain.map_apply] - cases h2 : c.bchain m hm with - | none => exact (h1 ▸ h2 ▸ c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).elim - | some _ => rfl - lbcompl_ne {n} hn c1 c2 {m} hc := by - have h0 := hc 0 hn.limit_lt_0 - cases h1 : c1.bchain 0 hn.limit_lt_0 with rw [h1] at h0 - | none => - cases h2 : c2.bchain 0 hn.limit_lt_0 with - | none => rfl - | some _ => rw [h2] at h0; exact h0.elim - | some s1 => - cases h2 : c2.bchain 0 hn.limit_lt_0 with rw [h2] at h0 - | none => exact h0.elim - | some s2 => - refine some_dist_some.mpr (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) - dsimp only [BChain.map_apply] - have hp' := hc p hp - cases e1 : c1.bchain p hp with rw [e1] at hp' - | none => - cases e2 : c2.bchain p hp with rw [e2] at hp' - | none => exact h0 - | some _ => exact hp'.elim - | some _ => - cases e2 : c2.bchain p hp with rw [e2] at hp' - | none => exact hp'.elim - | some _ => exact hp' - #rocq_ignore option_compl "Local Compl definition; folded into Lean's IsCOFE instance." @[rocq_alias discrete_fun_cofe] @@ -1949,6 +1899,7 @@ def BFChain.go (n : SI) (rec : ∀ m, m < n → BFChain f m) : BFChain f n where intro q Hq exact ((conv_bcompl (BFChain.goChain f n rec) Hp).lt Hq).trans ((rec p Hp).fixpoint q Hq) +@[rocq_alias fixpoint_bchain] def fixpointBFChain (n : SI) : BFChain f n := instSI.lt_wf.fix (BFChain.go f) n theorem fixpointBFChain_unfold (n : SI) : @@ -1957,6 +1908,7 @@ theorem fixpointBFChain_unfold (n : SI) : end BFChain +@[rocq_alias fixpoint_chain] def Fixpoint.chain [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where chain n := f (bcompl n (fixpointBFChain f n).car) cauchy {n i : SI} H := by From 366c6bfc7512a2f8ed69a2731cec78beeb32dded Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Mon, 3 Aug 2026 19:26:58 +0200 Subject: [PATCH 30/33] `ProdOF` and `SumOF`: `SI` as an implicit parameter --- Iris/Iris/Algebra/CMRA.lean | 4 ++-- Iris/Iris/Algebra/Lib/DFracAgree.lean | 2 +- Iris/Iris/Algebra/Lib/FracAuth.lean | 4 ++-- Iris/Iris/Algebra/Lib/UFracAuth.lean | 4 ++-- Iris/Iris/Algebra/OFE.lean | 14 ++++++++------ Iris/Iris/Examples/Fix.lean | 2 +- Iris/Iris/Instances/Lib/Boxes.lean | 2 +- Iris/Iris/Instances/Lib/CInvariants.lean | 2 +- Iris/Iris/Instances/Lib/NaInvariants.lean | 2 +- 9 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Iris/Iris/Algebra/CMRA.lean b/Iris/Iris/Algebra/CMRA.lean index f416ed012..bc368d122 100644 --- a/Iris/Iris/Algebra/CMRA.lean +++ b/Iris/Iris/Algebra/CMRA.lean @@ -1722,7 +1722,7 @@ section ProdRF open RFunctor @[rocq_alias prodRF] -instance instRFunctorProdOF [RFunctor F1] [RFunctor F2] : RFunctor (ProdOF Nat F1 F2) where +instance instRFunctorProdOF [RFunctor F1] [RFunctor F2] : RFunctor (ProdOF F1 F2) where map f g := Prod.mapC (map f g) (map f g) map_ne.ne _ _ _ Hx _ _ Hy _ := Prod.map_ne (fun _ => map_ne.ne Hx Hy _) (fun _ => map_ne.ne Hx Hy _) @@ -1733,7 +1733,7 @@ instance instRFunctorProdOF [RFunctor F1] [RFunctor F2] : RFunctor (ProdOF Nat F @[rocq_alias prodRF_contractive] instance instRFunctorContractiveProdOF [RFunctorContractive F1] [RFunctorContractive F2] : - RFunctorContractive (ProdOF Nat F1 F2) where + RFunctorContractive (ProdOF F1 F2) where map_contractive.1 H _ := Prod.map_ne (fun _ => RFunctorContractive.map_contractive.1 H _) (fun _ => RFunctorContractive.map_contractive.1 H _) diff --git a/Iris/Iris/Algebra/Lib/DFracAgree.lean b/Iris/Iris/Algebra/Lib/DFracAgree.lean index 660a438fb..9cb893286 100644 --- a/Iris/Iris/Algebra/Lib/DFracAgree.lean +++ b/Iris/Iris/Algebra/Lib/DFracAgree.lean @@ -173,7 +173,7 @@ end Frac @[rocq_alias dfrac_agreeRF] abbrev DFracAgreeRF (T : COFE.OFunctorPre Nat) [COFE.OFunctor Nat T] : COFE.OFunctorPre Nat := - ProdOF Nat (constOF DFrac) (AgreeRF T) + ProdOF (constOF DFrac) (AgreeRF T) end DFracAgree diff --git a/Iris/Iris/Algebra/Lib/FracAuth.lean b/Iris/Iris/Algebra/Lib/FracAuth.lean index 8dff2e53b..dd3152646 100644 --- a/Iris/Iris/Algebra/Lib/FracAuth.lean +++ b/Iris/Iris/Algebra/Lib/FracAuth.lean @@ -272,10 +272,10 @@ theorem updateP_both_unpersist {q : Qp} {a b : A} : @[rocq_alias frac_authURF] abbrev FracAuthURF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := - AuthURF (OptionOF (ProdOF Nat (constOF (Qp)) T)) + AuthURF (OptionOF (ProdOF (constOF (Qp)) T)) @[rocq_alias frac_authRF] abbrev FracAuthF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := - AuthRF (OptionOF (ProdOF Nat (constOF (Qp)) T)) + AuthRF (OptionOF (ProdOF (constOF (Qp)) T)) end FracAuth diff --git a/Iris/Iris/Algebra/Lib/UFracAuth.lean b/Iris/Iris/Algebra/Lib/UFracAuth.lean index 444769c83..db67a2f9d 100644 --- a/Iris/Iris/Algebra/Lib/UFracAuth.lean +++ b/Iris/Iris/Algebra/Lib/UFracAuth.lean @@ -214,13 +214,13 @@ theorem update_surplus_cancel {p q : Qp} {a b : A} [CMRA.Cancelable b] : @[rocq_alias ufrac_authURF] abbrev UFracAuthURF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := - AuthURF (OptionOF (ProdOF Nat (constOF UFrac) T)) + AuthURF (OptionOF (ProdOF (constOF UFrac) T)) #rocq_ignore ufrac_authURF_contractive "Contractiveness is bundled into Lean's RFunctor class" @[rocq_alias ufrac_authRF] abbrev UFracAuthRF (T : COFE.OFunctorPre Nat) [RFunctor T] : COFE.OFunctorPre Nat := - AuthRF (OptionOF (ProdOF Nat (constOF UFrac) T)) + AuthRF (OptionOF (ProdOF (constOF UFrac) T)) #rocq_ignore ufrac_authRF_contractive "Contractiveness is bundled into Lean's RFunctor class" diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 51dc004c6..38f2db0de 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1545,11 +1545,13 @@ def Prod.mapO (f : A -n> A') (g : B -n> B') : A × B -n> A' × B' where instance Prod.mapO_ne : NonExpansive₂ (Prod.mapO (A := A) (A' := A') (B := B) (B' := B')) where ne _ _ _ Hf _ _ Hg _ := Prod.map_ne Hf Hg -abbrev ProdOF SI [SIdx SI] (F1 F2 : OFunctorPre SI) : OFunctorPre SI := fun A B => (F1 A B) × (F2 A B) +abbrev ProdOF {SI} [SIdx SI] (F1 F2 : OFunctorPre SI) : + OFunctorPre SI := + fun A B => (F1 A B) × (F2 A B) open OFunctor in @[rocq_alias prodOF] -instance instOFunctorProdOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (ProdOF SI F1 F2) where +instance instOFunctorProdOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (ProdOF F1 F2) where ofe := inferInstance map f g := Prod.mapO (map f g) (map f g) map_ne.ne _ _ _ Hx _ _ Hy _ := ⟨map_ne.ne Hx Hy _, map_ne.ne Hx Hy _⟩ @@ -1559,7 +1561,7 @@ instance instOFunctorProdOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (Pro open OFunctorContractive in @[rocq_alias prodOF_contractive] instance instOFunctorContractiveProdOF [OFunctorContractive SI F1] [OFunctorContractive SI F2] : - OFunctorContractive SI (ProdOF SI F1 F2) where + OFunctorContractive SI (ProdOF F1 F2) where map_contractive.1 H _ := Prod.map_ne (fun _ => map_contractive.1 H _) (fun _ => map_contractive.1 H _) @@ -1601,11 +1603,11 @@ def Sum.mapO (f : A -n> A') (g : B -n> B') : A ⊕ B -n> A' ⊕ B' where instance Sum.mapO_ne : NonExpansive₂ (Sum.mapO (A := A) (A' := A') (B := B) (B' := B')) where ne _ _ _ Hf _ _ Hg _ := Sum.map_ne Hf Hg -abbrev SumOF SI [SIdx SI] (F1 F2 : OFunctorPre SI) : OFunctorPre SI := fun A B => (F1 A B) ⊕ (F2 A B) +abbrev SumOF {SI} [SIdx SI] (F1 F2 : OFunctorPre SI) : OFunctorPre SI := fun A B => (F1 A B) ⊕ (F2 A B) open OFunctor in @[rocq_alias sumOF] -instance instOFunctorSumOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (SumOF SI F1 F2) where +instance instOFunctorSumOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (SumOF F1 F2) where ofe := inferInstance map f g := Sum.mapO (map f g) (map f g) map_ne.ne _ _ _ Hx _ _ Hy x := match x with @@ -1621,7 +1623,7 @@ instance instOFunctorSumOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (SumO open OFunctorContractive in @[rocq_alias sumOF_contractive] instance instOFunctorContractiveSumOF [OFunctorContractive SI F1] [OFunctorContractive SI F2] : - OFunctorContractive SI (SumOF SI F1 F2) where + OFunctorContractive SI (SumOF F1 F2) where map_contractive.1 H _ := Sum.map_ne (fun _ => map_contractive.1 H _) (fun _ => map_contractive.1 H _) diff --git a/Iris/Iris/Examples/Fix.lean b/Iris/Iris/Examples/Fix.lean index c7ca47f69..f104c5c14 100644 --- a/Iris/Iris/Examples/Fix.lean +++ b/Iris/Iris/Examples/Fix.lean @@ -28,7 +28,7 @@ open Iris OFE COFE variable [OFE Nat Val] [OFE Nat Err] [IsCOFE Nat Val] [IsCOFE Nat Err] [Inhabited Err] abbrev DomF : OFunctorPre Nat := - SumOF Nat (constOF Val) (SumOF Nat (constOF Err) (SumOF Nat (LaterOF IdOF) (LaterOF (HomOF IdOF IdOF)))) + SumOF (constOF Val) (SumOF (constOF Err) (SumOF (LaterOF IdOF) (LaterOF (HomOF IdOF IdOF)))) instance : Inhabited (DomF (Val := Val) (Err := Err) (ULift Unit) (ULift Unit)) := ⟨.inr (.inr (.inr ⟨id, inferInstance⟩))⟩ diff --git a/Iris/Iris/Instances/Lib/Boxes.lean b/Iris/Iris/Instances/Lib/Boxes.lean index 7a96201dd..0be4f369e 100644 --- a/Iris/Iris/Instances/Lib/Boxes.lean +++ b/Iris/Iris/Instances/Lib/Boxes.lean @@ -24,7 +24,7 @@ abbrev BoolO := DiscreteO Bool variable (GF : BundledGFunctors) abbrev BoxF : OFunctorPre Nat := - ProdOF Nat (AuthURF (OptionOF (ExclOF (constOF BoolO)))) + ProdOF (AuthURF (OptionOF (ExclOF (constOF BoolO)))) (OptionOF (AgreeRF (LaterOF IdOF))) @[rocq_alias boxG] diff --git a/Iris/Iris/Instances/Lib/CInvariants.lean b/Iris/Iris/Instances/Lib/CInvariants.lean index bd6ccd2ed..0fedb3044 100644 --- a/Iris/Iris/Instances/Lib/CInvariants.lean +++ b/Iris/Iris/Instances/Lib/CInvariants.lean @@ -25,7 +25,7 @@ open BI CMRA OFE Iris Std LawfulSet Excl COFE ProofMode /-! # Cancelable Invariants -/ abbrev CInvF : OFunctorPre Nat := - ProdOF Nat (constOF (Option (Excl Unit))) (constOF (Option Qp)) + ProdOF (constOF (Option (Excl Unit))) (constOF (Option Qp)) @[rocq_alias cinvG] class CInvG (GF : BundledGFunctors) where diff --git a/Iris/Iris/Instances/Lib/NaInvariants.lean b/Iris/Iris/Instances/Lib/NaInvariants.lean index fd6e50653..a1599ad6a 100644 --- a/Iris/Iris/Instances/Lib/NaInvariants.lean +++ b/Iris/Iris/Instances/Lib/NaInvariants.lean @@ -20,7 +20,7 @@ namespace Iris open BI CMRA OFE Iris Std LawfulSet DisjointLeibnizSet COFE ProofMode abbrev NaInvF : OFunctorPre Nat := - ProdOF Nat (constOF CoPsetDisjL) (constOF (DisjointLeibnizSet PosSet)) + ProdOF (constOF CoPsetDisjL) (constOF (DisjointLeibnizSet PosSet)) @[rocq_alias na_invG] class NaInvG (GF : BundledGFunctors) where From e370972867fb7aa816cebce40b6262788c71384f Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Mon, 3 Aug 2026 19:36:16 +0200 Subject: [PATCH 31/33] Remove redundant `rocq_alias` entry --- Iris/Iris/Algebra/OFE.lean | 1 - 1 file changed, 1 deletion(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 38f2db0de..c5b951518 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -187,7 +187,6 @@ theorem Discrete.discrete [OFE SI α] [Discrete α] {n : SI} {x y : α} (h : x discrete_0 <| h.le SIdx.le_0_l export OFE.Discrete (discrete) -@[rocq_alias ofe_discrete_discrete] instance Discrete.toDiscreteE [OFE SI α] [Discrete α] (x : α) : DiscreteE x := ⟨discrete_0⟩ /-- For discrete OFEs, `n`-equivalence implies equivalence for any `n`. -/ From b41c97c74a7d17f33b7ab366764292e795582d01 Mon Sep 17 00:00:00 2001 From: Markus de Medeiros Date: Mon, 3 Aug 2026 16:10:17 -0400 Subject: [PATCH 32/33] chore: minor cleanup in GhostMap and StepIndexFinite --- Iris/Iris/Algebra/StepIndexFinite.lean | 37 +++++++++----------------- Iris/Iris/Instances/Lib/GhostMap.lean | 2 +- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/Iris/Iris/Algebra/StepIndexFinite.lean b/Iris/Iris/Algebra/StepIndexFinite.lean index bd68f84db..355d6aa7d 100644 --- a/Iris/Iris/Algebra/StepIndexFinite.lean +++ b/Iris/Iris/Algebra/StepIndexFinite.lean @@ -16,42 +16,28 @@ namespace Iris @[rocq_alias natSI, rocq_alias nat_sidx_mixin] instance natSIdx : SIdx Nat where - toLT := instLTNat - toLE := instLENat zero := 0 succ := Nat.succ lt_trans := Nat.lt_trans lt_wf := Nat.lt_wfRel.wf lt_trichotomyT n m := - if h : n < m then by left; exact h - else if he : n = m then by right; left; exact he - else by - right; right; apply Nat.lt_of_not_ge - change ¬n ≤ m - rw [Nat.le_iff_lt_or_eq] - intro h' - exact h'.elim h he - le_lteq {n m} := Nat.le_iff_lt_or_eq + if h : n < m then .inl h + else if he : n = m then .inr <| .inl he + else .inr <| .inr (by omega) + le_lteq {_ _} := Nat.le_iff_lt_or_eq not_lt_zero n := by simp lt_succ_self n := by simp succ_le_of_lt h := h - weak_case n := - match n with - | 0 => by right; intro m h; exact absurd h (Nat.not_lt_zero m) - | m + 1 => by left; constructor; rfl + weak_case + | 0 => .inr (by omega) + | m + 1 => .inl ⟨_, rfl⟩ @[rocq_alias nat_sidx_finite] instance natSIdxFinite : SIdxFinite Nat where - finite_index := by - intro n - cases n with - | zero => left; rfl - | succ n => right; exists n + finite_index | 0 => .inl rfl | n + 1 => .inr ⟨n, rfl⟩ def SIdx.Limit.elim {I : Type u} [SIdx I] [SIdxFinite I] {n : I} {C : Sort v} - (h : SIdx.Limit n) : C := by - exfalso - exact SIdx.limit_finite n h + (h : SIdx.Limit n) : C := SIdx.limit_finite n h |>.elim namespace OFE @@ -63,7 +49,10 @@ theorem Contractive.succNat [OFE Nat α] [OFE Nat β] (f : α → β) [Contracti Contractive.distLater_dist <| distLater_succ.mpr h instance DiscreteO.instCOFE_Nat {α : Type _} : COFE Nat (DiscreteO α) := DiscreteO.instCOFE -instance DiscreteO.discrete_Nat {α : Type _} : OFE.Discrete (SI := Nat) (DiscreteO α) := DiscreteO.OFE + +instance DiscreteO.discrete_Nat {α : Type _} : OFE.Discrete (SI := Nat) (DiscreteO α) := + DiscreteO.OFE + instance unitCOFE_Nat : COFE Nat Unit := COFE.unitCOFE end OFE diff --git a/Iris/Iris/Instances/Lib/GhostMap.lean b/Iris/Iris/Instances/Lib/GhostMap.lean index 1b8bb1eea..651db162d 100644 --- a/Iris/Iris/Instances/Lib/GhostMap.lean +++ b/Iris/Iris/Instances/Lib/GhostMap.lean @@ -228,7 +228,7 @@ theorem ghost_map_alloc_strong_empty [DecidableEq K] (P : GName → Prop) theorem ghost_map_alloc [DecidableEq K] (m : H V) : ⊢@{IProp GF} |==> ∃ γ, (γ ↪●MAP m) ∗ [∗map] k ↦ v ∈ m, γ ↪◯MAP[k] v := by imod (ghost_map_alloc_strong (fun _ => True) m) with ⟨%γ, -, H1, H2⟩ - · intro N; exists N -- ; simp + · intro N; exists N · iexists γ iframe H1 H2 From da2bfbaa07a03be5b921a1acf7dfe612d64a3ae2 Mon Sep 17 00:00:00 2001 From: Markus de Medeiros Date: Mon, 3 Aug 2026 16:37:02 -0400 Subject: [PATCH 33/33] cleanup OFE --- Iris/Iris/Algebra/OFE.lean | 106 +++++++++++-------------------------- 1 file changed, 32 insertions(+), 74 deletions(-) diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index c5b951518..e41ce5a0b 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -372,7 +372,6 @@ def unitOFE : OFE SI Unit where #rocq_ignore unitO "Use the unit type" #rocq_ignore unit_dist "Local Dist instance; folded into Lean's OFE Unit instance." --- set_option trace.Meta.synthInstance true in instance : @DiscreteE SI _ Unit unitOFE (() : Unit) := letI := unitOFE ⟨fun _ => Subsingleton.elim _ _⟩ @@ -1161,55 +1160,24 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : | .inr seed => .inr (IsCOFE.lbcompl hn (c.map ⟨Sum.elim (Function.const _ seed) id, inferInstance⟩)) conv_lbcompl {n} hn c {m} hm := by - cases h1 : c.bchain 0 hn.limit_lt_0 with - | inl seed => - refine (dist_inl (IsCOFE.conv_lbcompl hn _ hm)).trans ?_ - dsimp only [BChain.map_apply] - cases h2 : c.bchain m hm with - | inl _ => simp - | inr _ => exact (h1 ▸ h2 ▸ c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).elim - | inr seed => - refine (dist_inr (IsCOFE.conv_lbcompl hn _ hm)).trans ?_ - dsimp only [BChain.map_apply] - cases h2 : c.bchain m hm with - | inl _ => exact (h1 ▸ h2 ▸ c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).elim - | inr _ => simp + have hb := c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l + cases h1 : c.bchain 0 hn.limit_lt_0 <;> cases h2 : c.bchain m hm <;> + rw [h1, h2] at hb <;> + first + | exact hb.elim + | (refine (dist_inl (IsCOFE.conv_lbcompl hn _ hm)).trans ?_; simp [h2]) + | (refine (dist_inr (IsCOFE.conv_lbcompl hn _ hm)).trans ?_; simp [h2]) lbcompl_ne {n} hn c1 c2 {m} hc := by have h0 := hc 0 hn.limit_lt_0 - cases h1 : c1.bchain 0 hn.limit_lt_0 with - | inl s1 => - cases h2 : c2.bchain 0 hn.limit_lt_0 with rw [h1, h2] at h0 - | inr _ => exact h0.elim - | inl s2 => - refine dist_inl (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) - simp only [BChain.map_apply] - have hp' := hc p hp - cases e1 : c1.bchain p hp with rw [e1] at hp' - | inl _ => - cases e2 : c2.bchain p hp with rw [e2] at hp' - | inl _ => exact hp' - | inr _ => exact hp'.elim - | inr _ => - cases e2 : c2.bchain p hp with rw [e2] at hp' - | inl _ => exact hp'.elim - | inr _ => exact h0 - | inr s1 => - cases h2 : c2.bchain 0 hn.limit_lt_0 with - | inl _ => rw [h1, h2] at h0; exact h0.elim - | inr s2 => - rw [h1, h2] at h0 - refine dist_inr (IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_)) - simp only [BChain.map_apply] - have hp' := hc p hp - cases e1 : c1.bchain p hp with rw [e1] at hp' - | inr _ => - cases e2 : c2.bchain p hp with rw [e2] at hp' - | inr _ => exact hp' - | inl _ => exact hp'.elim - | inl _ => - cases e2 : c2.bchain p hp with rw [e2] at hp' - | inr _ => exact hp'.elim - | inl _ => exact h0 + cases h1 : c1.bchain 0 hn.limit_lt_0 <;> cases h2 : c2.bchain 0 hn.limit_lt_0 <;> + rw [h1, h2] at h0 <;> + first + | exact h0.elim + | refine IsCOFE.lbcompl_ne hn _ _ (fun p hp => ?_) <;> + · simp only [BChain.map_apply] + have hp' := hc p hp + cases e1 : c1.bchain p hp <;> cases e2 : c2.bchain p hp <;> + rw [e1, e2] at hp' <;> first | exact hp' | exact hp'.elim | exact h0 #rocq_ignore inl_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." #rocq_ignore inr_chain "Local helper for `sum_compl`; folded into Lean's IsCOFE instance." @@ -1226,19 +1194,24 @@ theorem Sigma.bchain_const_proj1 {P : α → Type _} [∀ x, OFE SI (P x)] (c.bchain m hm).fst = (c.bchain 0 hn.limit_lt_0).fst := (c.bcauchy hn.limit_lt_0 hm SIdx.le_0_l).choose +theorem Sigma.dist_cast_of_dist {P : α → Type _} [∀ x, OFE SI (P x)] {n : SI} + {x y : Sigma P} (h : x ≡{n}≡ y) {b : α} (hx : x.fst = b) (hy : y.fst = b) : + (hx ▸ x.snd : P b) ≡{n}≡ (hy ▸ y.snd : P b) := by + obtain ⟨h1, h2⟩ := h + obtain ⟨x1, x2⟩ := x + obtain ⟨y1, y2⟩ := y + simp only at h1 hx + subst h1; subst hx + exact h2 + @[rocq_alias bchain_map_snd] def Sigma.bchain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] {n : SI} (hn : SIdx.Limit n) (c : BChain (Sigma P) n) : BChain (P (c.bchain 0 hn.limit_lt_0).fst) n where bchain m hm := Sigma.bchain_const_proj1 hn c hm ▸ (c.bchain m hm).snd - bcauchy {m p} hm hp hle := by - obtain ⟨heq, hequiv⟩ := c.bcauchy hm hp hle - rw [show Sigma.bchain_const_proj1 hn c hp - = heq.trans (Sigma.bchain_const_proj1 hn c hm) from rfl] - generalize Sigma.bchain_const_proj1 hn c hm = heq' - revert heq' hequiv heq; cases c.bchain p hp; cases c.bchain m hm - rintro ⟨⟩ hequiv ⟨⟩ - exact hequiv + bcauchy _ hp hle := + Sigma.dist_cast_of_dist (c.bcauchy _ hp hle) + (Sigma.bchain_const_proj1 hn c hp) (Sigma.bchain_const_proj1 hn c _) theorem Sigma.lbcompl_cast {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] {a b : α} (eq : a = b) {n : SI} (hn : SIdx.Limit n) (c : BChain (P a) n) : @@ -1255,28 +1228,13 @@ theorem Sigma.cast_cast {P : α → Type _} {a b c : α} (h1 : a = b) (h2 : b = (h2 ▸ (h1 ▸ x : P b) : P c) = (h1.trans h2) ▸ x := by subst h1; subst h2; rfl -theorem Sigma.dist_cast_of_dist {P : α → Type _} [∀ x, OFE SI (P x)] {n : SI} - {x y : Sigma P} (h : x ≡{n}≡ y) {b : α} (hx : x.fst = b) (hy : y.fst = b) : - (hx ▸ x.snd : P b) ≡{n}≡ (hy ▸ y.snd : P b) := by - obtain ⟨h1, h2⟩ := h - obtain ⟨x1, x2⟩ := x - obtain ⟨y1, y2⟩ := y - simp only at h1 hx hy - subst h1; subst hx - exact h2 - @[rocq_alias chain_map_snd] def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] (c : Chain (Sigma P)) : Chain (P (c 0).fst) where chain n := Sigma.chain_const_proj1 c n ▸ (c n).snd - cauchy {n i} hle := by - obtain ⟨heq, hequiv⟩ := c.cauchy hle - clear hle - rw [show Sigma.chain_const_proj1 c i = heq.trans (Sigma.chain_const_proj1 c n) by rfl] - generalize Sigma.chain_const_proj1 c n = heq' - revert heq' hequiv heq; cases c.chain i; cases c.chain n - rintro ⟨⟩ hequiv ⟨⟩ - exact hequiv + cauchy {n i} hle := + Sigma.dist_cast_of_dist (c.cauchy hle) + (Sigma.chain_const_proj1 c i) (Sigma.chain_const_proj1 c n) @[rocq_alias sigT_cofe] instance {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] : IsCOFE SI (Sigma P) where