From 1e369681512c3b8af82cbedf0a4345aafc8d486b Mon Sep 17 00:00:00 2001 From: Alvin Tang Date: Tue, 28 Jul 2026 11:51:00 +0200 Subject: [PATCH 01/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] =?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/37] `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/37] 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/37] 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/37] 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/37] 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/37] 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/37] `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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] 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/37] `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/37] 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/37] 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/37] 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 From ec25c6a80420bbeab228f4004ac110226e9e9e71 Mon Sep 17 00:00:00 2001 From: Markus de Medeiros Date: Wed, 5 Aug 2026 16:05:47 -0400 Subject: [PATCH 34/37] new OFE --- Iris/Iris/Algebra/OFE.lean | 637 ++++++++++--------- Iris/Iris/Algebra/StepIndexRegistry.lean | 50 ++ Iris/Iris/Tests/StepIndexRegistry.lean | 219 +++++++ Iris/Iris/Tests/StepIndexRegistryImport.lean | 71 +++ 4 files changed, 666 insertions(+), 311 deletions(-) create mode 100644 Iris/Iris/Algebra/StepIndexRegistry.lean create mode 100644 Iris/Iris/Tests/StepIndexRegistry.lean create mode 100644 Iris/Iris/Tests/StepIndexRegistryImport.lean diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index e41ce5a0b..8de7028ef 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -7,14 +7,17 @@ module public import Iris.Algebra.StepIndex public meta import Iris.Std.RocqPorting +public meta import Iris.Algebra.StepIndexRegistry @[expose] public section namespace Iris +local stepindex SI + /-- Ordered family of equivalences -/ @[rocq_alias ofe] -class OFE (SI : outParam <| Type _) [SIdx SI] (α : Type _) where +class OFE (α : Type _) (SI : Type _ := by infer_stepindex) [SIdx SI] where Dist : SI → α → α → Prop dist_eqv : Equivalence (Dist n) eq_dist : x = y ↔ ∀ n, Dist n x y @@ -30,135 +33,138 @@ class OFE (SI : outParam <| Type _) [SIdx SI] (α : Type _) where open OFE -scoped notation:40 x " ≡{" n "}≡ " y:41 => OFE.Dist n x y +scoped notation:40 x " ≡{" n "}≡ " y:41 => OFE.Dist (SI := by infer_stepindex) n x y namespace OFE variable [instSI : SIdx SI] @[rocq_alias dist_equivalence] -theorem dist_equivalence [OFE SI α] {n : SI} : Equivalence (Dist (α := α) n) := dist_eqv +theorem dist_equivalence [OFE α] {n : SI} : Equivalence (Dist (α := α) n) := dist_eqv @[rocq_alias dist_lt] -theorem Dist.lt [OFE SI α] {m n : SI} {x y : α} : x ≡{n}≡ y → m < n → x ≡{m}≡ y := dist_lt +theorem Dist.lt [OFE α] {m n : SI} {x y : α} : x ≡{n}≡ y → m < n → x ≡{m}≡ y := dist_lt @[rocq_alias dist_le] -theorem Dist.le [OFE SI α] {m n : SI} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := +theorem Dist.le [OFE α] {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 (SIdx.le_neq.mpr ⟨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 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) +@[simp, refl] theorem Dist.rfl [OFE α] {n : SI} {x : α} : x ≡{n}≡ x := dist_eqv.1 _ +@[symm] theorem Dist.symm [OFE α] {n : SI} {x : α} : x ≡{n}≡ y → y ≡{n}≡ x := dist_eqv.2 +theorem Dist.trans [OFE α] {n : SI} {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) #rocq_ignore ofe_equivalence "OFE is Leibniz; use equality" -theorem _root_.Eq.dist [OFE SI α] {x y : α} (h : x = y) : x ≡{n}≡ y := h ▸ .rfl +theorem _root_.Eq.dist [OFE α] {x y : α} (h : x = y) : x ≡{n}≡ y := h ▸ .rfl -instance [OFE SI α] {n : SI} : Trans (OFE.Dist n) (OFE.Dist n) (OFE.Dist n : α → α → Prop) where +instance [OFE α] {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 SI α] [OFE SI β] (f : α → β) where +class NonExpansive {α β : Type _} (f : α → β) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] [OFE β] where ne : ∀ ⦃n x₁ x₂⦄, x₁ ≡{n}≡ x₂ → f x₁ ≡{n}≡ f x₂ -instance id_ne [OFE SI α] : NonExpansive (@id α) := ⟨fun _ _ _ h => h⟩ +instance id_ne [OFE α] : NonExpansive (@id α) := ⟨fun _ _ _ h => h⟩ -instance const_ne [OFE SI α] [OFE SI β] {x : α} : NonExpansive (Function.const β x) := ⟨fun _ _ _ _ => .rfl⟩ +instance const_ne [OFE α] [OFE β] {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 SI α] [OFE SI β] [OFE SI γ] {g : β → γ} {f : α → β} +theorem NonExpansive.comp [OFE α] [OFE β] [OFE γ] {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 SI α] [OFE SI β] [OFE SI γ] (f : α → β → γ) where +class NonExpansive₂ {α β γ : Type _} (f : α → β → γ) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] [OFE β] [OFE γ] 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 SI α] [OFE SI β] [OFE SI γ] (f : α → β → γ) [NonExpansive₂ f] +theorem NonExpansive₂.ne_right [OFE α] [OFE β] [OFE γ] (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 SI α] [OFE SI β] [OFE SI γ] (f : α → β → γ) [NonExpansive₂ f] +theorem NonExpansive₂.ne_left [OFE α] [OFE β] [OFE γ] (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 SI α] (n : SI) (x y : α) : Prop := ∀ m, m < n → x ≡{m}≡ y +def DistLater [OFE α] (n : SI) (x y : α) : Prop := ∀ m, m < n → x ≡{m}≡ y -@[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 := +@[simp, refl] theorem DistLater.rfl [OFE α] {n : SI} {x : α} : DistLater n x x := fun _ _ => .rfl +@[symm] theorem DistLater.symm [OFE α] {n : SI} {x : α} (h : DistLater n x y) : DistLater n y x := fun _ hm => (h _ hm).symm -theorem DistLater.trans [OFE SI α] {n : SI} {x : α} (h1 : DistLater n x y) (h2 : DistLater n y z) : +theorem DistLater.trans [OFE α] {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 SI α] {n : SI} : Equivalence (α := α) (DistLater n) where +theorem distLater_eqv [OFE α] {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 SI α] {n : SI} {x y : α} (h : x ≡{n}≡ y) : DistLater n x y := +theorem Dist.distLater [OFE α] {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 SI α] {m n : SI} {x y : α} (h : DistLater n x y) (hm : m < n) : x ≡{m}≡ y := +theorem DistLater.dist_lt [OFE α] {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 SI α] {x y : α} : DistLater 0 x y := +@[simp, rocq_alias dist_later_0] theorem distLater_zero [OFE α] {x y : α} : DistLater (0 : SI) 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] -theorem distLater_succ [OFE SI α] {n : SI} {x y : α} : DistLater (SIdx.succ n) x y ↔ x ≡{n}≡ y := +theorem distLater_succ [OFE α] {n : SI} {x y : α} : DistLater (SIdx.succ n) x y ↔ x ≡{n}≡ y := ⟨(·.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 => ?_ +theorem distLater_soundness [OFE α] {x y : α} (H : ∀ n : SI, DistLater n x y → x ≡{n}≡ y) : x = y := by + refine (eq_dist (SI := SI)).mpr fun n => ?_ 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. -/ -class Contractive [OFE SI α] [OFE SI β] (f : α → β) where +class Contractive {α β : Type _} (f : α → β) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] [OFE β] where distLater_dist : DistLater n x y → f x ≡{n}≡ f y -@[simp, rocq_alias contractive_0] theorem Contractive.zero [OFE SI α] [OFE SI β] (f : α → β) - [Contractive f] {x y} : f x ≡{0}≡ f y := +@[simp, rocq_alias contractive_0] theorem Contractive.zero [OFE α] [OFE β] (f : α → β) + [Contractive f] {x y} : f x ≡{(0 : SI)}≡ f y := Contractive.distLater_dist distLater_zero @[rocq_alias contractive_S] -theorem Contractive.succ [OFE SI α] [OFE SI β] (f : α → β) [Contractive f] {n x y} +theorem Contractive.succ [OFE α] [OFE β] (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 SI α] [OFE SI β] (f : α → β) [Contractive f] : NonExpansive f where +instance ne_of_contractive [OFE α] [OFE β] (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 SI α] [OFE SI β] {x : β} : Contractive (fun _ : α => x) where +instance [OFE α] [OFE β] {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 SI α where +def ofDiscrete (α : Type _) : OFE α where Dist _ := Eq dist_eqv := ⟨congrFun rfl, (Eq.symm ·), (· ▸ ·)⟩ eq_dist := (forall_const _).symm @@ -166,40 +172,40 @@ def ofDiscrete (α : Type _) : OFE SI α where /-- A discrete element in an OFE -/ @[rocq_alias Discrete] -class DiscreteE {α : Type _} [OFE SI α] (x : α) : Prop where - discrete : x ≡{0}≡ y → x = y +class DiscreteE {α : Type _} (x : α) (SI : Type _ := by infer_stepindex) [SIdx SI] [OFE α] : Prop where + discrete : x ≡{(0 : SI)}≡ y → x = y /-- A discrete OFE is one where equivalence is implied by `0`-equivalence. -/ @[rocq_alias OfeDiscrete] -class Discrete (α : Type _) [OFE SI α] where - discrete_0 {x y : α} : x ≡{0}≡ y → x = y +class Discrete (α : Type _) (SI : Type _ := by infer_stepindex) [SIdx SI] [OFE α] where + discrete_0 {x y : α} : x ≡{(0 : SI)}≡ y → x = y export OFE.Discrete (discrete_0) @[rocq_alias Discrete_proper] -theorem discreteE_eqv [OFE SI α] {x y : α} (h : x = y) : DiscreteE x ↔ DiscreteE y := h ▸ Iff.rfl +theorem discreteE_eqv [OFE α] {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 SI α] [Discrete α] {n : SI} {x y : α} (h : x ≡{n}≡ y) : x = y := +theorem Discrete.discrete [OFE α] [Discrete α] {n : SI} {x y : α} (h : x ≡{n}≡ y) : x = y := discrete_0 <| h.le SIdx.le_0_l export OFE.Discrete (discrete) -instance Discrete.toDiscreteE [OFE SI α] [Discrete α] (x : α) : DiscreteE x := ⟨discrete_0⟩ +instance Discrete.toDiscreteE [OFE α] [Discrete α] (x : α) : DiscreteE x := ⟨discrete_0⟩ /-- For discrete OFEs, `n`-equivalence implies equivalence for any `n`. -/ -theorem Discrete.discrete_n [OFE SI α] [Discrete α] {n : SI} {x y : α} (h : x ≡{0}≡ y) : x ≡{n}≡ y := +theorem Discrete.discrete_n [OFE α] [Discrete α] {n : SI} {x y : α} (h : x ≡{(0 : SI)}≡ y) : x ≡{n}≡ y := (discrete h).dist export OFE.Discrete (discrete_n) @[rocq_alias discrete_iff] -theorem Discrete.discrete_iff [OFE SI α] [Discrete α] (n) {x y : α} : x = y ↔ x ≡{n}≡ y := +theorem Discrete.discrete_iff [OFE α] [Discrete α] (n) {x y : α} : x = y ↔ x ≡{n}≡ y := ⟨Eq.dist, discrete⟩ @[rocq_alias discrete_iff_0] -theorem Discrete.discrete_iff_0 [OFE SI α] [Discrete α] (n) {x y : α} : x ≡{0}≡ y ↔ x ≡{n}≡ y := +theorem Discrete.discrete_iff_0 [OFE α] [Discrete α] (n : SI) {x y : α} : x ≡{(0 : SI)}≡ y ↔ x ≡{n}≡ y := ⟨discrete_n, fun h => h.le SIdx.le_0_l⟩ #rocq_ignore boolO "Canonical Leibniz OFE on `bool`; Lean uses `ofDiscrete Bool`." @@ -232,7 +238,7 @@ by quotienting the carrier `X` by the OFE equivalence `fun x y => ∀ n, dist n @[reducible] def mkQuotient {X : Type u} (dist : SI → X → X → Prop) (heqv : ∀ {n}, Equivalence (dist n)) (hlt : ∀ {n m : SI} {x y : X}, dist n x y → m < n → dist m x y) : - OFE SI (Quotient (QuotientO dist heqv)) := + OFE (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), @@ -301,7 +307,8 @@ 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 SI α] [OFE SI β] where +@[ext, rocq_alias ofe_mor] structure Hom (α β : Type _) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] [OFE β] where f : α → β ne : NonExpansive f #rocq_ignore ofe_mor_proper "Derived from nonexpansivity" @@ -310,52 +317,58 @@ non-expansive. -/ @[inherit_doc] infixr:25 " -n> " => Hom -instance [OFE SI α] [OFE SI β] : CoeFun (α -n> β) (fun _ => α → β) := ⟨Hom.f⟩ -instance [OFE SI α] [OFE SI β] (f : α -n> β) : NonExpansive f := f.ne +@[inherit_doc] +notation:25 α:26 " -n>@{" SI "} " β:25 => Hom α β SI + +instance [OFE α] [OFE β] : CoeFun (α -n> β) (fun _ => α → β) := ⟨Hom.f⟩ +instance [OFE α] [OFE β] (f : α -n> β) : NonExpansive f := f.ne /-- The identity morphism on an OFE. -/ @[rocq_alias cid] -protected def Hom.id [OFE SI α] : α -n> α where +protected def Hom.id [OFE α] : α -n> α where f := id ne.ne _ _ _ := id /-- The composition of two morphisms between OFEs. -/ @[rocq_alias ccompose] -protected def Hom.comp [OFE SI α] [OFE SI β] [OFE SI γ] (g : β -n> γ) (f : α -n> β) : α -n> γ where +protected def Hom.comp [OFE α] [OFE β] [OFE γ] (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 SI α] {x} : (Hom.id : α -n> α) x = x := rfl -@[simp] theorem Hom.comp_apply [OFE SI α] [OFE SI β] [OFE SI γ] {g : β -n> γ} {f : α -n> β} {x} : +@[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} : (g.comp f) x = g (f x) := 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 +@[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 -theorem Hom.comp_assoc [OFE SI α] [OFE SI β] [OFE SI γ] [OFE SI δ] +theorem Hom.comp_assoc [OFE α] [OFE β] [OFE γ] [OFE δ] (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 SI α] [OFE SI β] (f : { f : α → β // NonExpansive f }) : α -n> β := +def Hom.ofSubtype [OFE α] [OFE β] (f : { f : α → β // NonExpansive f }) : α -n> β := ⟨f.val, f.property⟩ -@[ext] structure ContractiveHom (α β : Type _) [OFE SI α] [OFE SI β] extends Hom α β where +@[ext] structure ContractiveHom (α β : Type _) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] [OFE β] extends Hom α β SI where [contractive : Contractive f] ne := ne_of_contractive f infixr:25 " -c> " => ContractiveHom -instance [OFE SI α] [OFE SI β] : CoeFun (α -c> β) (fun _ => α → β) := ⟨fun x => x.toHom.f⟩ -instance [OFE SI α] [OFE SI β] (f : α -c> β) : Contractive f := f.contractive +notation:25 α:26 " -c>@{" SI "} " β:25 => ContractiveHom α β SI -def _root_.Function.toContractiveHom (f : α → β) [OFE SI α] [OFE SI β] [ι : OFE.Contractive f] : α -c> β where +instance [OFE α] [OFE β] : CoeFun (α -c> β) (fun _ => α → β) := ⟨fun x => x.toHom.f⟩ +instance [OFE α] [OFE β] (f : α -c> β) : Contractive f := f.contractive + +def _root_.Function.toContractiveHom (f : α → β) [OFE α] [OFE β] [ι : OFE.Contractive f SI] : α -c> β where f := f contractive := ι -@[simp] theorem _root_.Function.toContractiveHom_apply {f : α → β} [OFE SI α] [OFE SI β] [ι : OFE.Contractive f] {x} : - f.toContractiveHom x = f x := by rfl +@[simp] theorem _root_.Function.toContractiveHom_apply {f : α → β} [OFE α] [OFE β] [ι : OFE.Contractive f SI] {x} : + f.toContractiveHom (SI := SI) x = f x := by rfl theorem InvImage.equivalence {α : Sort u} {β : Sort v} {r : β → β → Prop} {f : α → β} (H : Equivalence r) : Equivalence (InvImage r f) where @@ -364,7 +377,7 @@ theorem InvImage.equivalence {α : Sort u} {β : Sort v} trans := H.trans @[reducible, rocq_alias unit_ofe_mixin] -def unitOFE : OFE SI Unit where +def unitOFE : OFE Unit where Dist _ _ _ := True dist_eqv := ⟨fun _ => ⟨⟩, id, fun _ => id⟩ eq_dist := by simp @@ -372,21 +385,21 @@ 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." -instance : @DiscreteE SI _ Unit unitOFE (() : Unit) := - letI := unitOFE +instance : @DiscreteE Unit (() : Unit) SI instSI (unitOFE ) := + letI := unitOFE (SI := SI) ⟨fun _ => Subsingleton.elim _ _⟩ -instance [OFE SI α] : OFE SI (ULift α) where +instance [OFE α] : OFE (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 SI α] : α -n> ULift α where +def uliftUpHom [OFE α] : α -n> ULift α where f := .up ne.1 _ _ _ := id -def uliftDownHom [OFE SI α] : ULift α -n> α where +def uliftDownHom [OFE α] : ULift α -n> α where f := ULift.down ne.1 _ _ _ := id @@ -402,45 +415,45 @@ 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 SI α] : OFE SI (Option α) where +instance [OFE α] : OFE (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] + eq_dist {x y} := by cases x <;> cases y <;> simp [Option.Forall₂, eq_dist (SI := SI)] dist_lt {_ x y _} := by cases x <;> cases y <;> simp [Option.Forall₂]; apply dist_lt #rocq_ignore optionO "Use Option" #rocq_ignore option_dist "Local Dist instance; folded into Lean's OFE (Option α) instance." #rocq_ignore option_dist_Forall2 "Local Dist unfolding lemma; trivial in Lean." @[rocq_alias option_ofe_discrete] -instance [OFE SI α] [OFE.Discrete α] : OFE.Discrete (Option α) where +instance [OFE α] [OFE.Discrete α] : OFE.Discrete (Option α) where discrete_0 {mx my} e := match mx, my with - | none, none => rfl - | none, some _ => e.elim - | some _, none => e.elim + | none, none => rfl + | none, some _ => e.elim + | some _, none => e.elim | some _, some _ => congrArg some (discrete_0 e) -@[simp] theorem some_eqv_some [OFE SI α] {x y : α} : (some x = some y) ↔ x = y := +@[simp] theorem some_eqv_some {α : Type _} {x y : α} : (some x = some y) ↔ x = y := ⟨Option.some.inj, congrArg some⟩ -@[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] theorem not_some_eqv_none {α : Type _} {x : α} : ¬some x = none := Option.some_ne_none x +@[simp] theorem not_none_eqv_some {α : Type _} {x : α} : ¬none = some x := fun h => Option.some_ne_none x h.symm @[simp, rocq_alias dist_Some] -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 some_dist_some [OFE α] {n : SI} {x y : α} : (some x ≡{n}≡ some y) ↔ x ≡{n}≡ y := .rfl +@[simp] theorem not_some_dist_none [OFE α] {n : SI} {x : α} : ¬some x ≡{n}≡ none := id +@[simp] theorem not_none_dist_some [OFE α] {n : SI} {x : α} : ¬none ≡{n}≡ some x := id -theorem equiv_some [OFE SI α] {o : Option α} {y : α} (e : o = some y) : +theorem equiv_some {α : Type _} {o : Option α} {y : α} (e : o = some y) : ∃ z, o = some z ∧ z = y := ⟨y, e, rfl⟩ -theorem equiv_none [OFE SI α] {o : Option α} : o = none ↔ o = none := Iff.rfl +theorem equiv_none {α : Type _} {o : Option α} : o = none ↔ o = none := Iff.rfl @[rocq_alias dist_None] -theorem dist_none [OFE SI α] {o : Option α} : o ≡{n}≡ none ↔ o = none := +theorem dist_none [OFE α] {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 SI α] {n mx y} (h : mx ≡{n}≡ some y) : +theorem dist_some [OFE α] {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⟩) @@ -449,7 +462,7 @@ theorem dist_some [OFE SI α] {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 SI α] [Discrete α] : Discrete (Option α) where +instance [OFE α] [Discrete α] : Discrete (Option α) where discrete_0 {x y} H := match x, y with | none, none => rfl @@ -458,58 +471,58 @@ instance [OFE SI α] [Discrete α] : Discrete (Option α) where | some _, none => H.elim @[rocq_alias Some_ne] -instance OFE.Option.some.ne [OFE SI α] : OFE.NonExpansive (some : α → Option α) := ⟨fun _ _ _ => id⟩ +instance OFE.Option.some.ne [OFE α] : OFE.NonExpansive (some : α → Option α) := ⟨fun _ _ _ => id⟩ @[rocq_alias Some_discrete] -instance Option.some_is_discrete [OFE SI α] {e : α} [OFE.DiscreteE e] : OFE.DiscreteE (some e) where +instance Option.some_is_discrete [OFE α] {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 SI α] {B : Type _} [OFE SI B] +theorem Option.ne_match [OFE α] {B : Type _} [OFE 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 SI α] : DiscreteE (none : Option α) := by +instance Option.none_is_discrete [OFE α] : DiscreteE (none : Option α) := by constructor; rintro (_|_) <;> simp -instance Option.merge_ne [OFE SI α] {op : α → α → α} [NonExpansive₂ op] : +instance Option.merge_ne [OFE α] {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 SI α] [OFE SI β] (f : α → Option β) [NonExpansive f] : NonExpansive (flip Option.bind f) where +instance Option.bind_fun_ne [OFE α] [OFE β] (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 SI α] [OFE SI β] {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 α] [OFE β] {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 SI α] [OFE SI β] {x : Option α} {f g : α → Option β} (H : ∀ x, f x = g x) : Option.bind x f = Option.bind x g := +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 := match x with | some _ => H _ | none => rfl -abbrev OFEFun {α : Type _} (β : α → Type _) := ∀ a, OFE SI (β a) +abbrev OFEFun {α : Type _} (β : α → Type _) := ∀ a, OFE (β a) SI @[rocq_alias discrete_fun_ofe_mixin] -instance [OFEFun (SI := SI) (β : α → _)] : OFE SI ((x : α) → β x) where +instance [OFEFun (SI := SI) (β : α → _)] : OFE ((x : α) → β x) where Dist n f g := ∀ x, f x ≡{n}≡ g x dist_eqv := { refl _ _ := dist_eqv.refl _ symm h _ := dist_eqv.symm (h _) trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _) } - eq_dist {_ _} := by rw [funext_iff]; simpa only [eq_dist] using forall_comm + eq_dist {_ _} := by rw [funext_iff]; simpa only [eq_dist (SI := SI)] using forall_comm dist_lt h1 h2 _ := dist_lt (h1 _) h2 #rocq_ignore discrete_funO "Use a function type" #rocq_ignore discrete_fun "Lean uses `(x : α) → β x` directly with `OFEFun`." @@ -517,7 +530,7 @@ instance [OFEFun (SI := SI) (β : α → _)] : OFE SI ((x : α) → β x) where #rocq_ignore discrete_fun_dist "Local Dist instance; folded into Lean's instance." @[rocq_alias ofe_mor_ofe_mixin] -instance [OFE SI α] [OFE SI β] : OFE SI (α -n> β) where +instance [OFE α] [OFE β] : OFE (α -n> β) where Dist n f g := f.f ≡{n}≡ g.f dist_eqv := { refl _ := dist_eqv.refl _ @@ -532,20 +545,20 @@ instance [OFE SI α] [OFE SI β] : OFE SI (α -n> β) where #rocq_ignore ofe_mor_chain "Inlined in IsCOFE instance" @[rocq_alias ofe_mor_car_ne] -instance ofe_mor_car_ne [OFE SI α] [OFE SI β] : +instance ofe_mor_car_ne [OFE α] [OFE β] : 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 SI α] [OFE SI β] ⦃f g : α -n> β⦄ (hfg : f = g) +theorem ofe_mor_car_proper [OFE α] [OFE β] ⦃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 SI α] [OFE SI β] [Inhabited β] : Inhabited (α -n> β) where +instance [OFE α] [OFE β] [Inhabited β] : Inhabited (α -n> β) where default := { f := Function.const α default, ne := const_ne } -instance [OFE SI α] [OFE SI β] : OFE SI (α -c> β) where +instance [OFE α] [OFE β] : OFE (α -c> β) where Dist n f g := Dist n f.toHom g.toHom dist_eqv := { refl _ := dist_eqv.refl _ @@ -559,15 +572,15 @@ def applyHom [OFEFun (SI := SI) (β : α → _)] (x : α) : ((x : α) → β x) f f := f x ne.1 _ _ _ H := H x -def applyNe [OFE SI α] [OFE SI β] (x : α) : (α -n> β) -n> β where +def applyNe [OFE α] [OFE β] (x : α) : (α -n> β) -n> β where f f := f x ne.1 _ _ _ H := H x -instance [OFE SI α] [OFE SI β] : NonExpansive (applyNe (α := α) (β := β)) where +instance [OFE α] [OFE β] : NonExpansive (applyNe (SI := SI) (α := α) (β := β)) where ne _ _ _ H f := f.ne.1 H @[rocq_alias discrete_funO_map] -def mapCodHom [OFEFun (β₁ : α → _)] [OFEFun (SI := SI) β₂] +def mapCodHom [OFEFun (SI := SI) (β₁ : α → _)] [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) @@ -578,64 +591,64 @@ def mapCodHom [OFEFun (β₁ : α → _)] [OFEFun (SI := SI) β₂] #rocq_ignore discrete_funO_map_ne "Implicit in type of mapCodHom" @[rocq_alias prod_ofe_mixin] -instance [OFE SI α] [OFE SI β] : OFE SI (α × β) where +instance [OFE α] [OFE β] : OFE (α × β) where Dist n a b := a.1 ≡{n}≡ b.1 ∧ a.2 ≡{n}≡ b.2 dist_eqv := { refl _ := ⟨dist_eqv.refl _, dist_eqv.refl _⟩ symm h := ⟨dist_eqv.symm h.1, dist_eqv.symm h.2⟩ trans h1 h2 := ⟨dist_eqv.trans h1.1 h2.1, dist_eqv.trans h1.2 h2.2⟩ } - eq_dist {_ _} := by rw [Prod.ext_iff]; simp only [eq_dist, forall_and] + eq_dist {_ _} := by rw [Prod.ext_iff]; simp only [eq_dist (SI := SI), forall_and] dist_lt h1 h2 := ⟨dist_lt h1.1 h2, dist_lt h1.2 h2⟩ #rocq_ignore prodO "Use product type" #rocq_ignore prod_dist "Implicit in Prod OFE" -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₂ : β} +theorem equiv_fst {α β : Type _} {x y : α × β} (h : x = y) : x.fst = y.fst := congrArg Prod.fst h +theorem equiv_snd {α β : Type _} {x y : α × β} (h : x = y) : x.snd = y.snd := congrArg Prod.snd h +theorem equiv_prod_ext {α β : Type _} {x₁ x₂ : α} {y₁ y₂ : β} (ex : x₁ = x₂) (ey : y₁ = y₂) : (x₁, y₁) = (x₂, y₂) := by subst ex; subst ey; rfl -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 +theorem dist_fst {n : SI} [OFE α] [OFE β] {x y : α × β} (h : x ≡{n}≡ y) : x.fst ≡{n}≡ y.fst := h.left +theorem dist_snd {n : SI} [OFE α] [OFE β] {x y : α × β} (h : x ≡{n}≡ y) : x.snd ≡{n}≡ y.snd := h.right @[rocq_alias pair_dist] -theorem dist_prod_ext {n : SI} [OFE SI α] [OFE SI β] {x₁ x₂ : α} {y₁ y₂ : β} +theorem dist_prod_ext {n : SI} [OFE α] [OFE β] {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 SI α] [OFE SI β] : NonExpansive₂ (Prod.mk (α := α) (β := β)) where +instance Prod.mk_ne [OFE α] [OFE β] : 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 SI α] [OFE SI β] (b : β) : NonExpansive (β := α × β) (·, b) := +theorem prod_mk_ne_left [OFE α] [OFE β] (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 SI α] [OFE SI β] (a : α) : NonExpansive (β := α × β) (a, ·) := +theorem prod_mk_ne_right [OFE α] [OFE β] (a : α) : NonExpansive (β := α × β) (a, ·) := ⟨fun {_ _ _} h => dist_prod_ext Dist.rfl h⟩ @[rocq_alias fst_ne] -instance [OFE SI α] [OFE SI β] : NonExpansive (Prod.fst (α := α) (β := β)) := +instance [OFE α] [OFE β] : NonExpansive (Prod.fst (α := α) (β := β)) := ⟨fun {_ _ _} h => dist_fst h⟩ @[rocq_alias snd_ne] -instance [OFE SI α] [OFE SI β] : NonExpansive (Prod.snd (α := α) (β := β)) := +instance [OFE α] [OFE β] : 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) : +theorem NonExpansive₂.uncurry [OFE α] [OFE β] [OFE γ] {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 SI α] [OFE SI β] {a : α} {b : β} [DiscreteE a] [DiscreteE b] : +instance prod.is_discrete [OFE α] [OFE β] {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 SI α] [OFE SI β] [Discrete α] [Discrete β] : Discrete (α × β) where +instance instDiscreteProd [OFE α] [OFE β] [Discrete α] [Discrete β] : Discrete (α × β) where discrete_0 H := Prod.ext (discrete_0 H.1) (discrete_0 H.2) section sum @@ -645,13 +658,13 @@ 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 SI α] [OFE SI β] +variable [OFE α] [OFE β] @[rocq_alias sum_ofe_mixin] -instance : OFE SI (α ⊕ β) where +instance : OFE (α ⊕ β) where Dist n - | .inl a, .inl b => a ≡{n}≡ b - | .inr a, .inr b => a ≡{n}≡ b + | .inl a, .inl b => Dist n a b + | .inr a, .inr b => Dist n a b | _, _ => False dist_eqv := { refl @@ -698,7 +711,7 @@ instance instNonExpansiveInl: NonExpansive (Sum.inl (α := α) (β := β)) where instance instNonExpansiveInr : NonExpansive (Sum.inr (α := α) (β := β)) where ne {_ _ _} H := dist_inr H -instance instNonExpansiveElim [OFE SI γ] {f₁ : α → γ} {f₂ : β → γ} [NonExpansive f₁] [NonExpansive f₂] : +instance instNonExpansiveElim [OFE γ] {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 ·) @@ -731,7 +744,7 @@ instance instDiscreteSum [Discrete α] [Discrete β] : Discrete (α ⊕ β) wher end sum @[rocq_alias sig_ofe_mixin] -instance [OFE SI α] (P : α → Prop) : OFE SI (Subtype P) where +instance [OFE α] (P : α → Prop) : OFE (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 @@ -743,26 +756,26 @@ instance [OFE SI α] (P : α → Prop) : OFE SI (Subtype P) where #rocq_ignore sig_dist_def "Trivial unfolding lemma; definitional in Lean." @[rocq_alias sig_discrete] -instance [OFE SI α] [Discrete α] (P : α → Prop) : Discrete (Subtype P) where +instance [OFE α] [Discrete α] (P : α → Prop) : Discrete (Subtype P) where 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 +instance [OFE α] (P : α → Prop) : NonExpansive (Subtype.val : Subtype P → α) where ne {_ _ _} := id -instance Hom.ofSubtype_ne [OFE SI α] [OFE SI β] : NonExpansive (Hom.ofSubtype (α := α) (β := β)) := +instance Hom.ofSubtype_ne [OFE α] [OFE β] : NonExpansive (Hom.ofSubtype (SI := SI) (α := α) (β := β)) := ⟨fun {_ _ _} h => h⟩ /-- Extract the underlying subtype from a `Hom`. -/ -def Hom.toSubtype [OFE SI α] [OFE SI β] (f : α -n> β) : { f : α → β // NonExpansive f } := +def Hom.toSubtype [OFE α] [OFE β] (f : α -n> β) : { f : α → β // NonExpansive f } := ⟨f.f, f.ne⟩ -instance Hom.toSubtype_ne [OFE SI α] [OFE SI β] : NonExpansive (Hom.toSubtype (α := α) (β := β)) := +instance Hom.toSubtype_ne [OFE α] [OFE β] : NonExpansive (Hom.toSubtype (SI := SI) (α := α) (β := β)) := ⟨fun {_ _ _} h => h⟩ @[rocq_alias sigT_ofe_mixin] -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 +instance instOFESigma (P : α → Type _) [∀ x, OFE (P x) SI] : OFE (Sigma P) where + Dist n x y := ∃ heq : x.fst = y.fst, Dist n (heq ▸ x.snd) y.snd dist_eqv := { refl _ := ⟨rfl, .rfl⟩ symm {x y} := match x, y with @@ -778,7 +791,7 @@ instance instOFESigma (P : α → Type _) [∀ x, OFE SI (P x)] : OFE SI (Sigma obtain ⟨heq, _⟩ := h 0 obtain ⟨xf, xs⟩ := x; obtain ⟨yf, ys⟩ := y simp only at heq; subst heq - exact congrArg _ (eq_dist.mpr fun n => (h n).2) + exact congrArg _ ((eq_dist ).mpr fun n => (h n).2) dist_lt {_ x y} := match x, y with | ⟨x, xH⟩, ⟨y, yH⟩ => fun | ⟨heq, H⟩ => fun hlt => ⟨heq, by simp only at heq; subst heq; exact dist_lt H hlt⟩ @@ -787,7 +800,7 @@ instance instOFESigma (P : α → Type _) [∀ x, OFE SI (P x)] : OFE SI (Sigma #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 SI (P x)] {x : Sigma P} [inst : DiscreteE x.snd] : +instance instDiscreteESigma {P : α → Type _} [∀ x, OFE (P x) SI] {x : Sigma P} [inst : DiscreteE x.snd] : DiscreteE x where discrete {y} := by rcases x, y with ⟨⟨x, xH⟩, ⟨y, yH⟩⟩; rintro ⟨heq, H⟩ @@ -795,51 +808,52 @@ instance instDiscreteESigma {P : α → Type _} [∀ x, OFE SI (P x)] {x : Sigma exact congrArg _ (inst.discrete H) @[rocq_alias sigT_ofe_discrete] -instance instDiscreteSigma {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, Discrete (P x)] : +instance instDiscreteSigma {P : α → Type _} [∀ x, OFE (P x) SI] [∀ x, Discrete (P x) SI] : 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 SI (P x)] {x1 x2 : Sigma P} : +theorem Sigma.equiv_eq_alt {P : α → Type _} [∀ x, OFE (P x) SI] {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 SI α] [∀ x, OFE SI (P x)] : +instance Sigma.fst_ne {P : α → Type _} [OFE α] [∀ x, OFE (P x) SI] : 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 SI (P x)] {n : SI} {x y : Sigma P} - (h : x ≡{n}≡ y) : h.1 ▸ x.snd ≡{n}≡ y.snd := h.2 +theorem Sigma.dist_snd {P : α → Type _} [∀ x, OFE (P x) SI] {n : SI} {x y : Sigma P} + (h : Dist n x y) : h.1 ▸ x.snd ≡{n}≡ y.snd := h.2 @[rocq_alias projT2_proper] -theorem Sigma.equiv_snd {P : α → Type _} [∀ x, OFE SI (P x)] {x y : Sigma P} +theorem Sigma.equiv_snd {P : α → Type _} [∀ x, OFE (P x) SI] {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 SI (P x)] {n : SI} {i1 i2 : α} {v1 : P i1} {v2 : P i2} +theorem Sigma.mk_dist {P : α → Type _} [∀ x, OFE (P x) SI] {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 SI (P x)] {i1 i2 : α} {v1 : P i1} {v2 : P i2} +theorem Sigma.mk_equiv {P : α → Type _} [∀ x, OFE (P x) SI] {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 SI (P x)] (a : α) : +instance Sigma.mk_ne {P : α → Type _} [∀ x, OFE (P x) SI] (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 SI α] [OFE SI β] where +@[ext, rocq_alias ofe_iso] structure Iso (α β : Type _) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] [OFE β] where hom : α -n> β inv : β -n> α hom_inv : hom (inv x) = x @@ -850,55 +864,55 @@ identity morphism. -/ attribute [simp] Iso.hom_inv Iso.inv_hom -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 +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 -@[simp] theorem Iso.hom_inv_dist [OFE SI α] [OFE SI β] (iso : Iso α β) {n : SI} {x} : +@[simp] theorem Iso.hom_inv_dist [OFE α] [OFE β] (iso : Iso α β) {n : SI} {x} : iso.hom (iso.inv x) ≡{n}≡ x := (Iso.hom_inv iso).dist -@[simp] theorem Iso.inv_hom_dist [OFE SI α] [OFE SI β] (iso : Iso α β) {n : SI} {x} : +@[simp] theorem Iso.inv_hom_dist [OFE α] [OFE β] (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 SI α] [OFE SI β] (iso : Iso α β) ⦃x y⦄ : +theorem Iso.hom_eqv [OFE α] [OFE β] (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 SI α] [OFE SI β] (iso : Iso α β) ⦃x y⦄ : +theorem Iso.inv_eqv [OFE α] [OFE β] (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 SI α] [OFE SI β] (iso : Iso α β) {n : SI} ⦃x y⦄ : +theorem Iso.hom_dist [OFE α] [OFE β] (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 SI α] [OFE SI β] (iso : Iso α β) {n : SI} ⦃x y⦄ : +theorem Iso.inv_dist [OFE α] [OFE β] (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 SI α] : Iso α α where +def Iso.id [OFE α] : 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 SI α] {x} : ((Iso.id : Iso α α) : α -n> α) x = x := rfl +@[simp] theorem Iso.id_apply [OFE α] {x} : ((Iso.id : Iso α α) : α -n> α) x = x := rfl /-- The inverse of an OFE isomorphism -/ @[rocq_alias iso_ofe_sym] -def Iso.symm [OFE SI α] [OFE SI β] (iso : Iso α β) : Iso β α where +def Iso.symm [OFE α] [OFE β] (iso : Iso α β) : Iso β α where hom := iso.inv inv := iso.hom hom_inv := by intro x; simp @@ -908,7 +922,7 @@ def Iso.symm [OFE SI α] [OFE SI β] (iso : Iso α β) : Iso β α where /-- Composition of OFE isomorphisms -/ @[rocq_alias iso_ofe_trans] -def Iso.comp [OFE SI α] [OFE SI β] [OFE SI γ] (iso1 : Iso β γ) (iso2 : Iso α β) : Iso α γ where +def Iso.comp [OFE α] [OFE β] [OFE γ] (iso1 : Iso β γ) (iso2 : Iso α β) : Iso α γ where hom := iso1.hom.comp iso2.hom inv := iso2.inv.comp iso1.inv hom_inv := by intro x; simp @@ -918,11 +932,12 @@ 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 {SI} (α : Type _) [SIdx SI] [OFE SI α] where +@[rocq_alias chain] structure Chain (α : Type _) (SI : Type _ := by infer_stepindex) + [SIdx SI] [OFE α] where chain : SI → α cauchy : n ≤ i → chain i ≡{n}≡ chain n -instance [SIdx SI] [OFE SI α] : CoeFun (Chain α) (fun _ => SI → α) := ⟨Chain.chain⟩ +instance [SIdx SI] [OFE α] : CoeFun (Chain α) (fun _ => SI → α) := ⟨Chain.chain⟩ namespace Chain @@ -930,32 +945,32 @@ variable {SI : Type _} [SIdx SI] /-- The constant chain. -/ @[rocq_alias chain_const] -def const [OFE SI α] (a : α) : Chain α where +def const [OFE α] (a : α) : Chain α where chain := fun _ => a cauchy _ := OFE.Dist.rfl -@[simp] theorem const_apply [OFE SI α] {a : α} {n : SI} : const a n = a := rfl +@[simp] theorem const_apply [OFE α] {a : α} {n : SI} : const a n = a := rfl /-- Mapping a chain through a non-expansive function. -/ @[rocq_alias chain_map] -def map [OFE SI α] [OFE SI β] (f : α -n> β) (c : Chain α) : Chain β where +def map [OFE α] [OFE β] (f : α -n> β) (c : Chain α) : Chain β where chain n := f (c n) cauchy h := f.ne.1 (c.cauchy h) -@[simp] theorem map_apply [OFE SI α] [OFE SI β] {f : α -n> β} {c : Chain α} {n : SI} : +@[simp] theorem map_apply [OFE α] [OFE β] {f : α -n> β} {c : Chain α} {n : SI} : map f c n = f (c n) := rfl -@[simp] theorem map_id [OFE SI α] {c : Chain α} : map (Hom.id : α -n> α) c = c := by +@[simp] theorem map_id [OFE α] {c : Chain α} : map (Hom.id : α -n> α) c = c := by simp [map] -theorem map_comp [OFE SI α] [OFE SI β] [OFE SI γ] {f : α -n> β} {g : β -n> γ} {c : Chain α} : +theorem map_comp [OFE α] [OFE β] [OFE γ] {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 [SIdx SI] [OFE SI V] {c : Chain (Option V)} (H : c n = none) : +theorem chain_none_const [SIdx SI] [OFE 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 => ?_) @@ -966,7 +981,7 @@ theorem chain_none_const [SIdx SI] [OFE SI V] {c : Chain (Option V)} (H : c n = exact (Hc Hnk).symm /-- If a chain of Option is ever some, it is the lift a chain by some. -/ -theorem chain_option_some [SIdx SI] [OFE SI V] {c : Chain (Option V)} (H : c n = some v) : +theorem chain_option_some [SIdx SI] [OFE 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') @@ -989,13 +1004,13 @@ theorem chain_option_some [SIdx SI] [OFE SI V] {c : Chain (Option V)} (H : c n = simp [hcc] @[rocq_alias bchain] -structure BChain (α : Type _) [SIdx SI] [OFE SI α] (n : SI) where +structure BChain (α : Type _) [SIdx SI] [OFE α] (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 β] +variable [SIdx SI] [OFE α] [OFE β] @[rocq_alias bchain_map] def map (f : α -n> β) {n : SI} (c : BChain α n) : BChain β n where @@ -1022,7 +1037,7 @@ end BChain /-- Complete ordered family of equivalences -/ @[rocq_alias Cofe] -class IsCOFE (SI : outParam <| Type _) (α : Type _) [SIdx SI] [OFE SI α] where +class IsCOFE (α : Type _) (SI : Type _ := by infer_stepindex) [SIdx SI] [OFE α SI] where compl : Chain α → α conv_compl {c : Chain α} : compl c ≡{n}≡ c n lbcompl {n : SI} : SIdx.Limit n → BChain α n → α @@ -1033,7 +1048,7 @@ class IsCOFE (SI : outParam <| Type _) (α : Type _) [SIdx SI] [OFE SI α] where 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 α +class abbrev COFE (α : Type _) (SI : Type _ := by infer_stepindex) [SIdx SI] := OFE α SI, IsCOFE α SI namespace COFE export IsCOFE (compl conv_compl) @@ -1041,29 +1056,29 @@ export IsCOFE (compl conv_compl) variable {SI : Type _} [SIdx SI] @[rocq_alias conv_compl_le] -theorem conv_compl' [COFE SI α] {c : Chain α} {n i} (h : n ≤ i) : compl c ≡{n}≡ c i := +theorem conv_compl' [COFE α] {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 SI α] [COFE SI β] (f : α -n> β) (c : Chain α) : +theorem compl_map [COFE α] [COFE β] (f : α -n> β) (c : Chain α) : compl (Chain.map f c) = f (compl c) := by - refine OFE.eq_dist.mpr (fun n => ?_) + refine (OFE.eq_dist (SI := SI)).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 SI α] (a : α) : compl (Chain.const a) = a := - OFE.eq_dist.mpr (fun _ => conv_compl) +theorem compl_const [COFE α] (a : α) : compl (Chain.const (SI := SI) a) = a := + (OFE.eq_dist ).mpr (fun _ => conv_compl) /-- Completion of discrete COFEs is the constant value. -/ -@[simp] theorem discrete_cofe_compl [COFE SI α] [OFE.Discrete α] (c : Chain α) : compl c = c 0 := +@[simp] theorem discrete_cofe_compl [COFE α] [OFE.Discrete α] (c : Chain α) : compl c = c (0 : SI) := Discrete.discrete_0 conv_compl /-- The discrete COFE obtained from an equivalence relation `Equiv` -/ @[reducible, rocq_alias discrete_cofe] -def ofDiscrete (α : Type _) : COFE SI α := - letI : OFE SI α := OFE.ofDiscrete α +def ofDiscrete (α : Type _) : COFE α := + letI : OFE α := OFE.ofDiscrete α { compl c := c 0 conv_compl {_ c} := (c.cauchy SIdx.le_0_l).symm @@ -1072,7 +1087,7 @@ def ofDiscrete (α : Type _) : COFE SI α := lbcompl_ne hn _ _ _ hc := hc 0 hn.limit_lt_0 } -instance [COFE SI α] : COFE SI (ULift α) where +instance [COFE α] : COFE (ULift α) where compl c := ⟨compl (c.map uliftDownHom)⟩ conv_compl := conv_compl lbcompl hn c := ⟨IsCOFE.lbcompl hn (c.map uliftDownHom)⟩ @@ -1080,13 +1095,13 @@ instance [COFE SI α] : COFE SI (ULift α) where lbcompl_ne hn _ _ _ hc := IsCOFE.lbcompl_ne hn _ _ (fun p hp => hc p hp) @[rocq_alias unit_ofe_discrete] -instance : @Discrete SI _ Unit unitOFE := - letI : OFE SI Unit := unitOFE +instance : @Discrete Unit SI _ unitOFE := + letI : OFE Unit := unitOFE { discrete_0 _ := Subsingleton.elim _ _ } @[reducible, rocq_alias unit_cofe] -def unitCOFE : COFE SI Unit := - letI : OFE SI Unit := unitOFE +def unitCOFE : COFE Unit := + letI : OFE Unit := unitOFE { compl _ := () conv_compl := ⟨⟩ @@ -1095,12 +1110,12 @@ def unitCOFE : COFE SI Unit := lbcompl_ne _ _ _ _ _ := ⟨⟩ } -abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun (SI := SI) β] := ∀ x : α, IsCOFE SI (β x) +abbrev IsCOFEFun {α : Type _} (β : α → Type _) [OFEFun (SI := SI) β] := ∀ x : α, IsCOFE (β x) #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 +instance {α : Type _} (β : α → Type _) [∀ x, COFE (β x) SI] : COFE ((x : α) → β x) where compl c x := compl (c.map (applyHom x)) conv_compl _ := IsCOFE.conv_compl lbcompl hn c x := IsCOFE.lbcompl hn (c.map (applyHom x)) @@ -1109,7 +1124,7 @@ instance {α : Type _} (β : α → Type _) [∀ x, COFE SI (β x)] : COFE SI (( #rocq_ignore discrete_fun_chain "Local helper; folded into Lean's IsCOFE instance." @[rocq_alias ofe_mor_cofe] -instance instIsCOFEHom [OFE SI α] [OFE SI β] [IsCOFE SI β] : IsCOFE SI (α -n> β) where +instance instIsCOFEHom [OFE α] [OFE β] [IsCOFE β] : IsCOFE (α -n> β) where compl c := by refine ⟨(compl <| c.map <| applyNe ·), ⟨fun n _ _ H => ?_⟩⟩ refine conv_compl.trans (.trans ?_ conv_compl.symm) @@ -1123,7 +1138,7 @@ instance instIsCOFEHom [OFE SI α] [OFE SI β] [IsCOFE SI β] : IsCOFE SI (α -n #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 +instance instIsCOFEProd [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (α × β) where compl c := ⟨compl (c.map ⟨Prod.fst, inferInstance⟩), compl (c.map ⟨Prod.snd, inferInstance⟩)⟩ conv_compl := ⟨conv_compl, conv_compl⟩ lbcompl hn c := @@ -1135,7 +1150,7 @@ instance instIsCOFEProd [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : 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 +instance instIsCOFESum [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (α ⊕ β) 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⟩)) @@ -1184,17 +1199,17 @@ instance instIsCOFESum [OFE SI α] [OFE SI β] [IsCOFE SI α] [IsCOFE SI β] : #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 SI (P x)] [∀ x, IsCOFE SI (P x)] - (c : Chain (Sigma P)) n : (c n).fst = (c 0).fst := +theorem Sigma.chain_const_proj1 {P : α → Type _} [∀ x, OFE (P x) SI] [∀ x, IsCOFE (P x) SI] + (c : Chain (Sigma P)) n : (c n).fst = (c (0 : SI)).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)] +theorem Sigma.bchain_const_proj1 {P : α → Type _} [∀ x, OFE (P x) SI] {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 -theorem Sigma.dist_cast_of_dist {P : α → Type _} [∀ x, OFE SI (P x)] {n : SI} +theorem Sigma.dist_cast_of_dist {P : α → Type _} [∀ x, OFE (P x) SI] {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 @@ -1205,7 +1220,7 @@ theorem Sigma.dist_cast_of_dist {P : α → Type _} [∀ x, OFE SI (P x)] {n : S exact h2 @[rocq_alias bchain_map_snd] -def Sigma.bchain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] +def Sigma.bchain_map_snd {P : α → Type _} [∀ x, OFE (P x) SI] {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 @@ -1213,13 +1228,13 @@ def Sigma.bchain_map_snd {P : α → Type _} [∀ x, OFE SI (P x)] 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)] +theorem Sigma.lbcompl_cast {P : α → Type _} [∀ x, OFE (P x) SI] [∀ x, IsCOFE (P x) SI] {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) +theorem Sigma.bchain_cast_apply {P : α → Type _} [∀ x, OFE (P x) SI] {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 @@ -1229,15 +1244,15 @@ theorem Sigma.cast_cast {P : α → Type _} {a b c : α} (h1 : a = b) (h2 : b = subst h1; subst h2; rfl @[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 +def Sigma.chain_map_snd {P : α → Type _} [∀ x, OFE (P x) SI] [∀ x, IsCOFE (P x) SI] (c : Chain (Sigma P)) : + Chain (P (c (0 : SI)).fst) where chain n := Sigma.chain_const_proj1 c n ▸ (c n).snd 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 +instance {P : α → Type _} [∀ x, OFE (P x) SI] [∀ x, IsCOFE (P x) SI] : IsCOFE (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, ?_⟩ @@ -1272,24 +1287,24 @@ instance {P : α → Type _} [∀ x, OFE SI (P x)] [∀ x, IsCOFE SI (P x)] : Is #rocq_ignore sigT_compl "Local Compl definition; folded into Lean's IsCOFE instance." set_option linter.checkUnivs false in -abbrev OFunctorPre (SI : outParam <| Type _) [SIdx SI] := ∀ α β [COFE SI α] [COFE SI β], Type _ +abbrev OFunctorPre (SI : Type _ := by infer_stepindex) [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 (SI) [SIdx SI] (F : OFunctorPre SI) where - ofe [COFE SI α] [COFE SI β] : OFE SI (F α β) - map [COFE SI α₁] [COFE SI α₂] [COFE SI β₁] [COFE SI β₂] : + ofe [COFE α] [COFE β] : OFE (F α β) + map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -n> F α₂ β₂ - map_ne [COFE SI α₁] [COFE SI α₂] [COFE SI β₁] [COFE SI β₂] : + map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - 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 β₃] + map_id [COFE α] [COFE β] (x : F α β) : map (Hom.id (α := α)) (Hom.id (α := β)) x = x + map_comp [COFE α₁] [COFE α₂] [COFE α₃] [COFE β₁] [COFE β₂] [COFE β₃] (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 SI [SIdx SI] (F : OFunctorPre SI) extends OFunctor SI F where - map_contractive [COFE SI α₁] [COFE SI α₂] [COFE SI β₁] [COFE SI β₂] : + map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) attribute [reducible, instance] OFunctor.ofe @@ -1301,11 +1316,11 @@ end COFE car : α @[reducible] -def DiscreteO.instCOFE [SIdx SI] {α : Type _} : COFE SI (DiscreteO α) := COFE.ofDiscrete _ +def DiscreteO.instCOFE [SIdx SI] {α : Type _} : COFE (DiscreteO α) := COFE.ofDiscrete _ theorem DiscreteO.OFE [SIdx SI] {α : Type _} : - @OFE.Discrete SI _ (DiscreteO α) (OFE.ofDiscrete _) := - letI := OFE.ofDiscrete + @OFE.Discrete (DiscreteO α) SI _ (OFE.ofDiscrete _) := + letI : Iris.OFE (DiscreteO α) := Iris.OFE.ofDiscrete _ ⟨id⟩ #rocq_ignore leibnizO_leibniz "Not needed" @@ -1314,7 +1329,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 : COFE SI (DiscreteO α) := DiscreteO.instCOFE + letI : COFE (DiscreteO α) := DiscreteO.instCOFE DiscreteO.mk x ≡{n}≡ DiscreteO.mk y → x = y := fun H => DiscreteO.eqv_inj H @@ -1344,7 +1359,7 @@ end DiscreteFunOF section Option -variable [SIdx SI] [OFE SI α] +variable [SIdx SI] [OFE α] @[rocq_alias option_chain] def optionChain (c : Chain (Option α)) (x : α) : Chain α := by @@ -1359,7 +1374,7 @@ def optionBChain {n : SI} (c : BChain (Option α) n) (x : α) : BChain α n := b 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 +instance isCOFE_option [IsCOFE α] : IsCOFE (Option α) where compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x) conv_compl {n : SI} c := by have := c.cauchy (SIdx.le_0_l (n := n)); revert this @@ -1397,27 +1412,27 @@ instance isCOFE_option [IsCOFE SI α] : IsCOFE SI (Option α) where | some _ => exact hp' @[rocq_alias optionO_map] -def optionMap {α β : Type _} [OFE SI α] [OFE SI β] (f : α -n> β) : Option α -n> Option β := by +def optionMap {α β : Type _} [OFE α] [OFE β] (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 SI β] {f g : α → β} {x y : Option α} {n : SI} : +theorem Option.map_ne [OFE β] {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 SI α] [OFE SI β] (f : α → β) +theorem Option.map_forall₂ {α β : Type _} [OFE α] [OFE β] (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 SI β] : NonExpansive (optionMap (α := α) (β := β)) where +instance optionMap_ne [OFE β] : NonExpansive (optionMap (SI := SI) (α := α) (β := β)) 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 SI β] {f g : α → Option β} {x y : Option α} {n} +theorem Option.bind_ne [OFE β] {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₂] @@ -1471,7 +1486,7 @@ section ProdOF open COFE -variable [SIdx SI] [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] +variable [SIdx SI] [OFE A] [OFE A'] [OFE B] [OFE B'] @[rocq_alias prod_map_ne] instance instNonExpansiveProdMap (f : A → A') (g : B → B') [NonExpansive f] [NonExpansive g] : @@ -1483,12 +1498,12 @@ instance instNonExpansiveProdMap (f : A → A') (g : B → B') [NonExpansive f] · rw [Prod.map_snd] exact NonExpansive.ne H.2 -omit [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] in +omit [OFE A] [OFE A'] [OFE B] [OFE 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 SI A] [OFE SI B] in +omit [OFE A] [OFE 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⟩ @@ -1499,7 +1514,7 @@ def Prod.mapO (f : A -n> A') (g : B -n> B') : A × B -n> A' × B' where ne := inferInstance @[rocq_alias prodO_map_ne] -instance Prod.mapO_ne : NonExpansive₂ (Prod.mapO (A := A) (A' := A') (B := B) (B' := B')) where +instance Prod.mapO_ne : NonExpansive₂ (Prod.mapO (SI := SI) (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) : @@ -1528,7 +1543,7 @@ section SumOF open COFE -variable [SIdx SI] [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] +variable [SIdx SI] [OFE A] [OFE A'] [OFE B] [OFE B'] @[rocq_alias sum_map_ne] instance instNonExpansiveSumMap (f : A → A') (g : B → B') [NonExpansive f] [NonExpansive g] : @@ -1537,14 +1552,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 SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] in +omit [OFE A] [OFE A'] [OFE B] [OFE 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 SI A] [OFE SI B] in +omit [OFE A] [OFE 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 @@ -1557,7 +1572,7 @@ def Sum.mapO (f : A -n> A') (g : B -n> B') : A ⊕ B -n> A' ⊕ B' where ne := inferInstance @[rocq_alias sumO_map_ne] -instance Sum.mapO_ne : NonExpansive₂ (Sum.mapO (A := A) (A' := A') (B := B) (B' := B')) where +instance Sum.mapO_ne : NonExpansive₂ (Sum.mapO (SI := SI) (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) @@ -1593,7 +1608,7 @@ open COFE variable [SIdx SI] @[rocq_alias sigT_map] -def Sigma.mapO {P1 P2 : A → Type _} [∀ x, OFE SI (P1 x)] [∀ x, OFE SI (P2 x)] : +def Sigma.mapO {P1 P2 : A → Type _} [∀ x, OFE (P1 x) SI] [∀ x, OFE (P2 x) SI] : ((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 _ _⟩⟩ @@ -1629,7 +1644,7 @@ variable [SIdx SI] abbrev constOF (B : Type) : OFunctorPre SI := fun _ _ _ _ => B @[rocq_alias constOF] -instance oFunctorConstOF [COFE SI B] : OFunctor SI (constOF B) where +instance oFunctorConstOF [COFE B] : OFunctor SI (constOF B) where ofe := _ map _ _ := ⟨id, id_ne⟩ map_ne := by intros; constructor; simp @@ -1637,7 +1652,7 @@ instance oFunctorConstOF [COFE SI B] : OFunctor SI (constOF B) where map_comp := by simp @[rocq_alias constOF_contractive] -instance OFunctor.constOF_contractive [COFE SI B] : OFunctorContractive SI (constOF B) where +instance OFunctor.constOF_contractive [COFE B] : OFunctorContractive SI (constOF B) where map_contractive.1 := by simp [OFunctor.map] end constOF @@ -1648,7 +1663,7 @@ open COFE variable [SIdx SI] -abbrev IdOF : OFunctorPre SI := fun (_ : Type _) (B : Type _) (_ : COFE SI _) (_ : COFE SI B) => B +abbrev IdOF : OFunctorPre SI := fun (_ : Type _) (B : Type _) (_ : COFE _) (_ : COFE B) => B open OFunctor in @[rocq_alias idOF] @@ -1665,7 +1680,7 @@ section HomOF open COFE -variable [SIdx SI] [OFE SI A] [OFE SI A'] [OFE SI B] [OFE SI B'] +variable [SIdx SI] [OFE A] [OFE A'] [OFE B] [OFE 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 @@ -1676,12 +1691,12 @@ def Hom.map (pre : A' -n> A) (post : B -n> B') : (A -n> B) -n> (A' -n> B') where @[rocq_alias ofe_morO_map_ne] instance instNonExpansive₂HomMap : - NonExpansive₂ (Hom.map (A := A) (A' := A') (B := B) (B' := B')) where + NonExpansive₂ (Hom.map (SI := SI) (A := A) (A' := A') (B := B) (B' := B')) where ne {_ _ _} Hx {y₁ _} Hy f g := (NonExpansive.ne (f := y₁) (NonExpansive.ne (f := f) (Hx g))).trans (Hy _) 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 _ _ + fun (A : Type _) (B : Type _) (_ : COFE A) (_ : COFE B) => @F1 B A _ _ -n> @F2 A B _ _ open OFunctor in @[rocq_alias ofe_morOF] @@ -1689,8 +1704,8 @@ instance instOFunctorHomOF [OFunctor SI F1] [OFunctor SI F2] : OFunctor SI (HomO 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) - map_id x := OFE.eq_dist.mpr fun _ a => ((map_id _).trans (congrArg x.f (map_id a))).dist - map_comp _ _ _ _ x := OFE.eq_dist.mpr fun _ _ => + map_id x := (OFE.eq_dist (SI := SI)).mpr fun _ a => ((map_id _).trans (congrArg x.f (map_id a))).dist + map_comp _ _ _ _ x := (OFE.eq_dist (SI := SI)).mpr fun _ _ => ((map_comp _ _ _ _ _).trans (congrArg _ (congrArg _ (congrArg x.f (map_comp _ _ _ _ _))))).dist open OFunctorContractive in @@ -1712,24 +1727,24 @@ section Fixpoint variable [instSI : SIdx SI] @[rocq_alias LimitPreserving] -class LimitPreserving [COFE SI α] (P : α → Prop) : Prop where +class LimitPreserving {α : Type _} (P : α → Prop) (SI : Type _ := by infer_stepindex) [SIdx SI] [COFE α] : 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 where +theorem LimitPreserving.const [COFE α] {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} - (hdiscrete : ∀ {x y : α}, x ≡{0}≡ y → (P x → P y)) : LimitPreserving P where +theorem LimitPreserving.discrete [COFE α] {P : α → Prop} + (hdiscrete : ∀ {x y : α}, x ≡{(0 : SI)}≡ 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) +theorem LimitPreserving.and [COFE α] {P Q : α → Prop} (HP : LimitPreserving P) (HQ : LimitPreserving Q) : LimitPreserving fun a => P a ∧ Q a where compl c H := by constructor @@ -1741,14 +1756,14 @@ theorem LimitPreserving.and [COFE SI α] {P Q : α → Prop} (HP : LimitPreservi · 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)) : +theorem LimitPreserving.forall [COFE α] (P : β → α → Prop) (Hlim : ∀ y, LimitPreserving (P 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) +theorem LimitPreserving.impl [COFE α] (P1 P2 : α → Prop) + (HP1 : ∀ {x y : α}, x ≡{(0 : SI)}≡ y → P1 x → P1 y) (Hcompl : LimitPreserving P2) : LimitPreserving (fun x => P1 x → P2 x) where compl c Hc HP1c := @@ -1758,39 +1773,39 @@ theorem LimitPreserving.impl [COFE SI α] (P1 P2 : α → Prop) 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} : +theorem LimitPreserving.of_sidx_finite [SIdxFinite SI] [COFE α] {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 [SIdxFinite SI] [COFE SI α] [COFE SI β] (f g : α -n> β) : +theorem LimitPreserving.equiv [SIdxFinite SI] [COFE α] [COFE β] (f g : α -n> β) : LimitPreserving (fun x => f x = g x) := by apply of_sidx_finite.mp intro c Hfg - refine eq_dist.mpr fun n => ?_ + refine (eq_dist (SI := SI)).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)) +theorem LimitPreserving.ext {α} [COFE α] {P Q : α -> Prop} (he : ∀ {x}, (P x ↔ Q x)) (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 -variable [COFE SI α] [Inhabited α] +variable [COFE α] [Inhabited α] @[rocq_alias bcompl] def bcompl (n : SI) (c : BChain α n) : α := match SIdx.case n with - | .inl _ => default + | .inl _ => default | .inr (.inl ⟨m, hm⟩) => c.bchain m (SIdx.lt_succ_diag_r' hm) - | .inr (.inr hlim) => IsCOFE.lbcompl hlim c + | .inr (.inr hlim) => IsCOFE.lbcompl hlim c @[rocq_alias conv_bcompl] theorem conv_bcompl {n : SI} (c : BChain α n) {m} (hm : m < n) : @@ -1825,7 +1840,7 @@ end BCompl section BFChain -variable [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] +variable [COFE α] [Inhabited α] (f : α → α) [Contractive f] @[rocq_alias bfchain] structure BFChain (n : SI) where @@ -1868,7 +1883,7 @@ theorem fixpointBFChain_unfold (n : SI) : end BFChain @[rocq_alias fixpoint_chain] -def Fixpoint.chain [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where +def Fixpoint.chain [COFE α] [Inhabited α] (f : α → α) [Contractive f] : Chain α where chain n := f (bcompl n (fixpointBFChain f n).car) cauchy {n i : SI} H := by rcases SIdx.le_lteq.mp H with (Hni | rfl) @@ -1879,12 +1894,12 @@ def Fixpoint.chain [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : /-- The chain construction of the Banach fixpoint. `fixpointP` packages it, together with its unfolding equation, behind an opaque constant. -/ -def fixpointAux [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : α := - COFE.compl <| Fixpoint.chain f +def fixpointAux [COFE α] [Inhabited α] (f : α → α) [Contractive f] : α := + COFE.compl <| Fixpoint.chain (SI := SI) f -theorem fixpointAux_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : - fixpointAux f = f (fixpointAux f) := by - refine eq_dist.mpr fun n => ?_ +theorem fixpointAux_unfold [COFE α] [Inhabited α] (f : α -c> α) : + fixpointAux (SI := SI) f = f (fixpointAux (SI := SI) f) := by + refine (eq_dist (SI := SI)).mpr fun n => ?_ apply COFE.conv_compl.trans refine .trans ?_ (NonExpansive.ne COFE.conv_compl.symm) exact Contractive.distLater_dist fun p Hp => ((fixpointBFChain f.f n).fixpoint p Hp).symm @@ -1892,54 +1907,52 @@ theorem fixpointAux_unfold [COFE SI α] [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 SI α] [Inhabited α] (f : α → α) [Contractive f] : { x : α // x = f x } := - ⟨fixpointAux f, fixpointAux_unfold f.toContractiveHom⟩ +opaque fixpointP [COFE α] [Inhabited α] (f : α → α) [Contractive f] : { x : α // x = f x } := + ⟨fixpointAux (SI := SI) f, fixpointAux_unfold f.toContractiveHom⟩ /-- Fixpoints inside of a COFE -/ @[rocq_alias fixpoint] -def fixpoint [COFE SI α] [Inhabited α] (f : α → α) [Contractive f] : α := - (fixpointP f).val +def fixpoint [COFE α] [Inhabited α] (f : α → α) [Contractive f] : α := + (fixpointP (SI := SI) 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 SI α] [Inhabited α] (f : α -c> α) : α := fixpoint f.f +nonrec abbrev OFE.ContractiveHom.fixpoint [COFE α] [Inhabited α] (f : α -c> α) : α := fixpoint (SI := SI) f.f @[rocq_alias fixpoint_unfold] -theorem fixpoint_unfold [COFE SI α] [Inhabited α] (f : α -c> α) : - fixpoint f = f (fixpoint f) := +theorem fixpoint_unfold [COFE α] [Inhabited α] (f : α -c> α) : + fixpoint (SI := SI) f = f (fixpoint (SI := SI) f) := (fixpointP f).property @[rocq_alias fixpoint_unique] -theorem fixpoint_unique [COFE SI α] [Inhabited α] {f : α -c> α} {x : α} (h : x = f x) : - x = fixpoint f := by - refine eq_dist.mpr fun n => ?_ +theorem fixpoint_unique [COFE α] [Inhabited α] {f : α -c> α} {x : α} (h : x = f x) : + x = fixpoint (SI := SI) f := by + refine (eq_dist (SI := SI)).mpr fun n => ?_ 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 +instance OFE.ContractiveHom.fixpoint_ne [COFE α] [Inhabited α] : + NonExpansive (ContractiveHom.fixpoint (SI := SI) (α := α)) where 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 + exact (fixpoint_unfold f1).dist.trans <| (h _).trans <| + (Contractive.distLater_dist fun p Hp => ih p Hp (h.lt Hp)).trans + (fixpoint_unfold f2).dist.symm @[elab_as_elim, rocq_alias fixpoint_ind] -theorem OFE.ContractiveHom.fixpoint_ind [COFE SI α] [Inhabited α] (f : α -c> α) +theorem OFE.ContractiveHom.fixpoint_ind [COFE α] [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 obtain ⟨y, hy, hfy⟩ : ∃ y : α, P y ∧ y = f y := by letI : Inhabited α := ⟨x⟩ - exists fixpointAux f.f + exists fixpointAux (SI := SI) f.f constructor · refine Hlim.compl (Fixpoint.chain f.f) fun n => Hind _ ?_ induction n using instSI.lt_wf.induction with @@ -1958,23 +1971,23 @@ open OFE 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⟩ +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⟩ /-- A Contractive function with NonExpansive function codomain is NonExpansive₂. -/ -instance ne₂_of_contractive_ne [OFE SI α] [OFE SI β] [OFE SI γ] (fA : α -c> β -n> γ) : NonExpansive₂ fA where +instance ne₂_of_contractive_ne [OFE α] [OFE β] [OFE γ] (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 SI α] [OFE SI β] [OFE SI γ] (fB : α -c> β -c> γ) : NonExpansive₂ fB where +instance ne₂_of_contractive [OFE α] [OFE β] [OFE γ] (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 SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fB : α -c> β -c> β) (x : α) : β := by +def fixpointAB [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fB : α -c> β -c> β) (x : α) : β := by let con_hom : β -c> β := { f := fB x, contractive := ⟨fB.f x |>.contractive.distLater_dist⟩ @@ -1982,7 +1995,7 @@ def fixpointAB [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fB : α exact con_hom.fixpoint @[rocq_alias fixpoint_AB_contractive] -theorem fixpointAB_contractive [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fB : α -c> β -c> β) : +theorem fixpointAB_contractive [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fB : α -c> β -c> β) : Contractive (fixpointAB fB) where distLater_dist {n _ _} Dl := by apply ContractiveHom.fixpoint_ne.ne @@ -1990,20 +2003,20 @@ theorem fixpointAB_contractive [COFE SI α] [COFE SI β] [Inhabited α] [Inhabit exact Dl @[rocq_alias fixpoint_AA] -def fixpointAA [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) +def fixpointAA [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) (x : α) : α := fA x (fixpointAB fB x) @[rocq_alias fixpoint_AA_contractive] -theorem fixpointAA_contractive [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) : Contractive (fixpointAA fA fB) where +theorem fixpointAA_contractive [COFE α] [COFE β] [Inhabited α] [Inhabited β] + (fA : α -c>@{SI} β -n>@{SI} α) (fB : α -c>@{SI} β -c>@{SI} β) : Contractive (fixpointAA fA fB) where distLater_dist {_ _ x₂} Dl := by refine .trans ?_ ((fA.f x₂).ne.ne ((fixpointAB_contractive fB).distLater_dist Dl)) apply fA.contractive.distLater_dist exact Dl @[rocq_alias fixpoint_A] -def fixpointA [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) +def fixpointA [COFE α] [COFE β] [Inhabited α] [Inhabited β] (fA : α -c> β -n> α) (fB : α -c> β -c> β) : α := by let con_hom : α -c> α := { f := fixpointAA fA fB, @@ -2012,38 +2025,40 @@ def fixpointA [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] (fA : α - exact con_hom.fixpoint @[rocq_alias fixpoint_B] -def fixpointB [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) : β := +def fixpointB [COFE α] [COFE β] [Inhabited α] [Inhabited β] + (fA : α -c>@{SI} β -n>@{SI} α) (fB : α -c>@{SI} β -c>@{SI} β) : β := fixpointAB fB <| fixpointA fA fB @[rocq_alias fixpoint_A_unfold] -theorem fixpointA_unfold [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) : +theorem fixpointA_unfold [COFE α] [COFE β] [Inhabited α] [Inhabited β] + (fA : α -c>@{SI} β -n>@{SI} α) (fB : α -c>@{SI} β -c>@{SI} β) : fA (fixpointA fA fB) (fixpointB fA fB) = (fixpointA fA fB) := by exact .symm (fixpoint_unfold _) @[rocq_alias fixpoint_B_unfold] -theorem fixpointB_unfold [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) : +theorem fixpointB_unfold [COFE α] [COFE β] [Inhabited α] [Inhabited β] + (fA : α -c>@{SI} β -n>@{SI} α) (fB : α -c>@{SI} β -c>@{SI} β) : fB (fixpointA fA fB) (fixpointB fA fB) = (fixpointB fA fB) := by exact .symm (fixpoint_unfold _) @[rocq_alias fixpoint_A_unique] -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) : +theorem fixpointA_unique [COFE α] [COFE β] [Inhabited α] [Inhabited β] + (fA : α -c>@{SI} β -n>@{SI} α) (fB : α -c>@{SI} β -c>@{SI} β) + (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 SI α] [COFE SI β] [Inhabited α] [Inhabited β] - (fA : α -c> β -n> α) (fB : α -c> β -c> β) (Hp : fA p q = p) (Hq : fB p q = q) : +theorem fixpointB_unique [COFE α] [COFE β] [Inhabited α] [Inhabited β] + (fA : α -c>@{SI} β -n>@{SI} α) (fB : α -c>@{SI} β -c>@{SI} β) + (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 SI α] [COFE SI β] [Inhabited α] [Inhabited β] : - NonExpansive₂ (fixpointA (α := α) (β := β)) where +instance fixpointA_ne [COFE α] [COFE β] [Inhabited α] [Inhabited β] : + NonExpansive₂ (fixpointA (SI := SI) (α := α) (β := β)) where ne n fA fA' HfA fB fB' HfB := by apply OFE.ContractiveHom.fixpoint_ne.ne intro z₁ @@ -2051,8 +2066,8 @@ instance fixpointA_ne [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] : exact ContractiveHom.fixpoint_ne.ne (HfB z₁) @[rocq_alias fixpoint_B_ne] -instance fixpointB_ne [COFE SI α] [COFE SI β] [Inhabited α] [Inhabited β] : - NonExpansive₂ (fixpointB (α := α) (β := β)) where +instance fixpointB_ne [COFE α] [COFE β] [Inhabited α] [Inhabited β] : + NonExpansive₂ (fixpointB (SI := SI) (α := α) (β := β)) where ne n fA fA' HfA fB fB' HfB := by apply ContractiveHom.fixpoint_ne.ne intro z₁ @@ -2069,12 +2084,12 @@ variable [SIdx SI] next :: car : A @[rocq_alias later_ofe_mixin] -instance isOFE_later [OFE SI A] : OFE SI (Later A) where +instance isOFE_later [OFE A] : OFE (Later A) where Dist n x y := DistLater n x.car y.car dist_eqv := ⟨fun _ => .rfl, .symm, .trans⟩ eq_dist {x y} := by obtain ⟨a⟩ := x; obtain ⟨b⟩ := y - simp only [Later.next.injEq, eq_dist] + simp only [Later.next.injEq, eq_dist (SI := SI)] 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" @@ -2084,24 +2099,24 @@ instance isOFE_later [OFE SI A] : OFE SI (Later A) where @[rocq_alias Next_contractive] -instance NextContractive {A : Type _} [OFE SI A] : Contractive (@Later.next A) where +instance NextContractive {A : Type _} [OFE A] : Contractive (@Later.next A) where distLater_dist := id @[rocq_alias later_chain] -def laterChain [OFE SI A] (c : Chain (Later A)) : Chain A where +def laterChain [OFE 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) : +def laterLimitBChain [OFE 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 +instance isCOFE_later [OFE A] [IsCOFE A] : IsCOFE (Later A) where compl c := Later.next (IsCOFE.compl (laterChain c)) conv_compl {n} c := by intros m Hlt @@ -2117,7 +2132,7 @@ instance isCOFE_later [OFE SI A] [IsCOFE SI A] : IsCOFE SI (Later A) where 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 +def laterMap [OFE A] [OFE 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) @@ -2154,7 +2169,7 @@ instance instOFunctorContractiveLater [OFunctor SI F] : OFunctorContractive SI ( end LaterOF -theorem OFE.cast_dist [SIdx SI] [Iα : OFE SI α] [Iβ : OFE SI β] {x y : α} - (Ht : α = β) (HIt : Iα = Ht ▸ Iβ) (H : x ≡{n}≡ y) : +theorem OFE.cast_dist [SIdx SI] [Iα : OFE α] [Iβ : OFE β] {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/StepIndexRegistry.lean b/Iris/Iris/Algebra/StepIndexRegistry.lean new file mode 100644 index 000000000..54112990e --- /dev/null +++ b/Iris/Iris/Algebra/StepIndexRegistry.lean @@ -0,0 +1,50 @@ +/- +Copyright (c) 2026 Markus de Medeiros. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Markus de Medeiros +-/ +module + +import Lean +public meta import Lean + +/-! +# Step Index Registry + +An attribute holding a default type for step indices that can be registered per-section. +-/ + +open Lean Elab Command Tactic + +/-- Extension used to track the current default type for step indices -/ +public meta initialize siExt : SimpleScopedEnvExtension Name Name ← + registerSimpleScopedEnvExtension { + addEntry _ n := n + initial := Name.anonymous + } + +/-- +`stepindex T` declares `T` to be the default step index type used by Iris notation. It is +required to be scoped as either `local` or `scoped`: `global` indices are not permitted. +-/ +@[expose] elab kind:Lean.Parser.Term.attrKind "stepindex" x:ident : command => do + let attrK := (← liftMacroM <| toAttributeKind kind) + match attrK with + | .local | .scoped => siExt.add x.getId attrK + | _ => throwError "stepindex must be either `scoped` or `local`." + +/-- Query the type of step indices -/ +@[expose] elab "#stepindex?" : command => do logInfo m!"{siExt.getState (← getEnv)}" + +/-- +Close a goal with the step index type in scope, resolved at the use site. + +Does nothing when there is no goal left: as the default value of a parameter this tactic runs +even if that parameter was already determined by unification, which must not be an error. +-/ +@[expose] elab "infer_stepindex" : tactic => do + if (← getGoals).isEmpty then return + match siExt.getState (← getEnv) with + | .anonymous => + throwError "infer_stepindex: no step index in scope; declare one with `local stepindex T`" + | n => evalTactic (← `(tactic| exact $(mkIdent n))) diff --git a/Iris/Iris/Tests/StepIndexRegistry.lean b/Iris/Iris/Tests/StepIndexRegistry.lean new file mode 100644 index 000000000..d927303a6 --- /dev/null +++ b/Iris/Iris/Tests/StepIndexRegistry.lean @@ -0,0 +1,219 @@ +/- +Copyright (c) 2026 Markus de Medeiros. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Markus de Medeiros +-/ +module + +public meta import Iris.Algebra.StepIndexRegistry + +@[expose] public section + +namespace Iris.Tests + +/-- info: [anonymous] -/ +#guard_msgs in +#stepindex? + +/-- error: infer_stepindex: no step index in scope; declare one with `local stepindex T` -/ +#guard_msgs in +example : Type := by infer_stepindex + +local stepindex Nat + +/-- info: Nat -/ +#guard_msgs in +#stepindex? + +/-- info: Nat : Type -/ +#guard_msgs in +#check (by infer_stepindex : Type) + +section +variable {SI : Type} +local stepindex SI + +/-- info: SI -/ +#guard_msgs in +#stepindex? + +/-- info: SI : Type -/ +#guard_msgs in +#check (by infer_stepindex : Type) + +def sectionIndex : Type := by infer_stepindex + +/-- info: @sectionIndex : {SI : Type} → Type -/ +#guard_msgs in +#check @sectionIndex + +end + +/-- info: Nat -/ +#guard_msgs in +#stepindex? + +namespace ScopedTest +scoped stepindex Unit +end ScopedTest + +/-- info: Nat -/ +#guard_msgs in +#stepindex? + +/-- info: Unit -/ +#guard_msgs in +open ScopedTest in +#stepindex? + +/-- error: stepindex must be either `scoped` or `local`. -/ +#guard_msgs in +stepindex Nat + +/-- info: Nat -/ +#guard_msgs in +#stepindex? + +class Pointwise {α β : Type} (f : α → β) (SI : Type := by infer_stepindex) where + ok : SI → True + +instance instAmbient (f : Nat → Nat) : Pointwise f := ⟨fun _ => trivial⟩ + +/-- info: instAmbient : ∀ (f : Nat → Nat), Pointwise f Nat -/ +#guard_msgs in +#check @instAmbient + +instance instOverride (f : Nat → Nat) : Pointwise f (SI := Unit) := ⟨fun _ => trivial⟩ + +-- Test that we can explicitly override the step index type in a class instance + +/-- info: instOverride : ∀ (f : Nat → Nat), Pointwise f Unit -/ +#guard_msgs in +#check @instOverride + +theorem binderPosition (f : Nat → Nat) [Pointwise f] : True := trivial + +-- Test that the auto_param will correctly infer the current step index type in a class instance + +/-- info: binderPosition : ∀ (f : Nat → Nat) [Pointwise f Nat], True -/ +#guard_msgs in +#check @binderPosition + +structure Bundle (α : Type) (SI : Type := by infer_stepindex) where + car : SI → α + +def natBundle : Bundle Nat := ⟨fun n => n⟩ + +/-- info: Iris.Tests.natBundle : Bundle Nat Nat -/ +#guard_msgs in +#check natBundle + +section +variable {SI α : Type} +local stepindex SI + +instance instSection (f : α → α) : Pointwise f := ⟨fun _ => trivial⟩ + +-- Test that local overrides also work for the step index type + +/-- info: @instSection : ∀ {SI α : Type} (f : α → α), Pointwise f SI -/ +#guard_msgs in +#check @instSection + +def mkBundle (f : SI → α) : Bundle α := ⟨f⟩ + +-- Test that a declaration made under a parametric index stays polymorphic in it + +/-- info: @mkBundle : {SI α : Type} → (SI → α) → Bundle α SI -/ +#guard_msgs in +#check @mkBundle + +end + +-- Test that a caller specializes the index by unification, not from the ambient index + +/-- info: mkBundle fun x => 0 : Bundle Nat Unit -/ +#guard_msgs in +#check mkBundle (fun _ : Unit => (0 : Nat)) + +section +local stepindex Unit + +def unitBundle : Bundle Nat := mkBundle (fun _ => 0) + +-- Test that a fresh application of `Bundle` takes the caller's ambient index + +/-- info: Iris.Tests.unitBundle : Bundle Nat Unit -/ +#guard_msgs in +#check unitBundle + +end + +-- Still works outside the section + +/-- info: @instSection : ∀ {SI α : Type} (f : α → α), Pointwise f SI -/ +#guard_msgs in +#check @instSection + +section +variable {SI : Type} +local stepindex SI + +def onlyIndex : Bundle Nat := ⟨fun _ => 0⟩ + +-- Test that the index is bound even when it is the only variable the declaration uses + +/-- info: @onlyIndex : {SI : Type} → Bundle Nat SI -/ +#guard_msgs in +#check @onlyIndex + +end + +section +universe u v +variable {SIu : Type u} {β : Type v} +local stepindex SIu + +structure UBundle (α : Type v) (SI : Type u := by infer_stepindex) where + ucar : SI → α + +def uMk (f : SIu → β) : UBundle β := ⟨f⟩ + +-- Test that the index is inferred when its universe differs from the carrier's + +/-- info: @uMk : {SIu : Type u_1} → {β : Type u_2} → (SIu → β) → UBundle β SIu -/ +#guard_msgs in +#check @uMk + +end + +section +local stepindex Unit + +-- Test that a fresh application commits to the ambient index rather than unifying + +/-- +error: Type mismatch + b +has type + Bundle Nat Nat +but is expected to have type + Bundle Nat Unit +-/ +#guard_msgs in +example (b : Bundle Nat Nat) : Bundle Nat := b + +end + +section +local stepindex Nonexistant + +-- Test the error from an index name that does not resolve + +/-- error: Unknown identifier `Nonexistant` -/ +#guard_msgs in +example : Type := by infer_stepindex + +end + +end Iris.Tests diff --git a/Iris/Iris/Tests/StepIndexRegistryImport.lean b/Iris/Iris/Tests/StepIndexRegistryImport.lean new file mode 100644 index 000000000..9c6364436 --- /dev/null +++ b/Iris/Iris/Tests/StepIndexRegistryImport.lean @@ -0,0 +1,71 @@ +/- +Copyright (c) 2026 Markus de Medeiros. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Markus de Medeiros +-/ +module + +import Iris.Tests.StepIndexRegistry +public meta import Iris.Tests.StepIndexRegistry + +@[expose] public section + +namespace Iris.Tests + +-- Test that a `local` index does not leak into an importing module + +/-- info: [anonymous] -/ +#guard_msgs in +#stepindex? + +-- Test that an importing module inherits no index, so `infer_stepindex` fails + +/-- error: infer_stepindex: no step index in scope; declare one with `local stepindex T` -/ +#guard_msgs in +example : Type := by infer_stepindex + +section +open ScopedTest + +-- Test that a `scoped` index activates across modules when its namespace is opened + +/-- info: Unit -/ +#guard_msgs in +#stepindex? + +def importedBundle : Bundle Nat := ⟨fun _ => 0⟩ + +-- Test that the auto_param uses the index of the opened scope on an imported structure + +/-- info: Iris.Tests.importedBundle : Bundle Nat Unit -/ +#guard_msgs in +#check importedBundle + +end + +-- Test that closing the scope restores the absence of an index + +/-- info: [anonymous] -/ +#guard_msgs in +#stepindex? + +section +local stepindex Nat + +def reexportedBundle : Bundle Nat := ⟨fun n => n⟩ + +-- Test that an importing module can declare its own index + +/-- info: Iris.Tests.reexportedBundle : Bundle Nat Nat -/ +#guard_msgs in +#check reexportedBundle + +-- Test that a polymorphic declaration from the imported module specializes here + +/-- info: mkBundle fun x => 0 : Bundle Nat Nat -/ +#guard_msgs in +#check mkBundle (fun _ : Nat => (0 : Nat)) + +end + +end Iris.Tests From feb328e93507f71b63c1c11db8ef13ca6c949980 Mon Sep 17 00:00:00 2001 From: Markus de Medeiros Date: Wed, 5 Aug 2026 17:45:43 -0400 Subject: [PATCH 35/37] done --- Iris/Iris/Algebra.lean | 2 + Iris/Iris/Algebra/Agree.lean | 20 ++-- Iris/Iris/Algebra/Auth.lean | 4 +- Iris/Iris/Algebra/BigOp.lean | 32 +++--- Iris/Iris/Algebra/CMRA.lean | 92 ++++++++-------- Iris/Iris/Algebra/COFESolver.lean | 41 ++++--- Iris/Iris/Algebra/Csum.lean | 60 +++++----- Iris/Iris/Algebra/DFrac.lean | 4 +- Iris/Iris/Algebra/DynReservationMap.lean | 38 ++++--- Iris/Iris/Algebra/Excl.lean | 60 +++++----- Iris/Iris/Algebra/Frac.lean | 4 +- Iris/Iris/Algebra/Functions.lean | 4 +- Iris/Iris/Algebra/GenMap.lean | 44 ++++---- Iris/Iris/Algebra/Heap.lean | 100 ++++++++--------- Iris/Iris/Algebra/HeapView.lean | 9 +- Iris/Iris/Algebra/IProp.lean | 4 +- Iris/Iris/Algebra/IsOp.lean | 2 + Iris/Iris/Algebra/LeibnizSet.lean | 6 +- Iris/Iris/Algebra/Lib.lean | 2 + Iris/Iris/Algebra/Lib/DFracAgree.lean | 12 +- Iris/Iris/Algebra/Lib/ExclAuth.lean | 4 +- Iris/Iris/Algebra/Lib/FracAuth.lean | 2 + Iris/Iris/Algebra/Lib/MonoNat.lean | 4 +- Iris/Iris/Algebra/Lib/UFracAuth.lean | 2 + Iris/Iris/Algebra/LocalUpdates.lean | 14 ++- Iris/Iris/Algebra/Monoid.lean | 10 +- Iris/Iris/Algebra/Numbers.lean | 8 +- Iris/Iris/Algebra/OFE.lean | 3 +- Iris/Iris/Algebra/ReservationMap.lean | 40 +++---- Iris/Iris/Algebra/StepIndexFinite.lean | 12 +- Iris/Iris/Algebra/StepIndexRegistry.lean | 15 +++ Iris/Iris/Algebra/UFrac.lean | 4 +- Iris/Iris/Algebra/UPred.lean | 10 +- Iris/Iris/Algebra/Updates.lean | 26 +++-- Iris/Iris/Algebra/View.lean | 40 +++---- Iris/Iris/BI.lean | 2 + Iris/Iris/BI/Algebra.lean | 6 +- Iris/Iris/BI/BI.lean | 4 +- Iris/Iris/BI/BigOp.lean | 2 + Iris/Iris/BI/BigOp/BigAndList.lean | 2 + Iris/Iris/BI/BigOp/BigAndMap.lean | 2 + Iris/Iris/BI/BigOp/BigOp.lean | 6 +- Iris/Iris/BI/BigOp/BigOrList.lean | 2 + Iris/Iris/BI/BigOp/BigSepList.lean | 6 +- Iris/Iris/BI/BigOp/BigSepMSet.lean | 2 + Iris/Iris/BI/BigOp/BigSepMap.lean | 2 + Iris/Iris/BI/BigOp/BigSepSet.lean | 2 + Iris/Iris/BI/Classes.lean | 2 + Iris/Iris/BI/Cmra.lean | 2 + Iris/Iris/BI/DerivedLaws.lean | 12 +- Iris/Iris/BI/DerivedLawsLater.lean | 2 + Iris/Iris/BI/Embedding.lean | 4 +- Iris/Iris/BI/Extensions.lean | 2 + Iris/Iris/BI/Instances.lean | 2 + Iris/Iris/BI/InternalEq.lean | 104 +++++++++--------- Iris/Iris/BI/Lib/BUpdPlain.lean | 2 + Iris/Iris/BI/Lib/Core.lean | 2 + Iris/Iris/BI/Lib/Fixpoint.lean | 16 +-- Iris/Iris/BI/Lib/FixpointBanach.lean | 18 +-- Iris/Iris/BI/Lib/Fractional.lean | 2 + Iris/Iris/BI/Lib/GenHeap.lean | 2 + Iris/Iris/BI/Lib/MonoNat.lean | 2 + Iris/Iris/BI/Lib/ProphMap.lean | 2 + Iris/Iris/BI/MonPred.lean | 14 ++- Iris/Iris/BI/Plainly.lean | 8 +- Iris/Iris/BI/SIProp.lean | 28 ++--- Iris/Iris/BI/Sbi.lean | 2 + Iris/Iris/BI/Updates.lean | 2 + Iris/Iris/BI/WeakestPre.lean | 2 + Iris/Iris/Examples.lean | 2 + Iris/Iris/Examples/ClosedProofs.lean | 2 + Iris/Iris/Examples/Fix.lean | 8 +- Iris/Iris/Examples/HeapLang.lean | 2 + Iris/Iris/Examples/IProp.lean | 12 +- Iris/Iris/Examples/Namesets.lean | 2 + Iris/Iris/Examples/Proofs.lean | 2 + Iris/Iris/Examples/Resources.lean | 2 + Iris/Iris/HeapLang.lean | 2 + Iris/Iris/HeapLang/Completeness.lean | 2 + Iris/Iris/HeapLang/Instances.lean | 2 + Iris/Iris/HeapLang/Lib/LandinsKnot.lean | 2 + Iris/Iris/HeapLang/Lib/Lock.lean | 2 + Iris/Iris/HeapLang/Lib/Par.lean | 2 + Iris/Iris/HeapLang/Lib/Quicksort.lean | 2 + Iris/Iris/HeapLang/Lib/Spawn.lean | 2 + Iris/Iris/HeapLang/Lib/SpinLock.lean | 2 + Iris/Iris/HeapLang/Linter.lean | 2 + Iris/Iris/HeapLang/Notation.lean | 2 + Iris/Iris/HeapLang/PrimitiveLaws.lean | 2 + Iris/Iris/HeapLang/ProofMode.lean | 2 + Iris/Iris/HeapLang/Semantics.lean | 2 + Iris/Iris/HeapLang/Syntax.lean | 2 + Iris/Iris/HeapLang/Tactic.lean | 2 + Iris/Iris/Instances.lean | 2 + Iris/Iris/Instances/Classical.lean | 2 + Iris/Iris/Instances/Classical/Instance.lean | 4 +- Iris/Iris/Instances/Classical/Notation.lean | 2 + Iris/Iris/Instances/IProp.lean | 2 + Iris/Iris/Instances/IProp/Instance.lean | 46 ++++---- Iris/Iris/Instances/Lib/Boxes.lean | 2 + Iris/Iris/Instances/Lib/CInvariants.lean | 2 + Iris/Iris/Instances/Lib/FUpd.lean | 4 +- .../Iris/Instances/Lib/FUpdFromViewShift.lean | 2 + Iris/Iris/Instances/Lib/GhostMap.lean | 2 + Iris/Iris/Instances/Lib/Invariants.lean | 4 +- Iris/Iris/Instances/Lib/LaterCredits.lean | 6 +- Iris/Iris/Instances/Lib/NaInvariants.lean | 2 + Iris/Iris/Instances/Lib/SavedProp.lean | 2 + Iris/Iris/Instances/Lib/Token.lean | 2 + Iris/Iris/Instances/Lib/WSat.lean | 2 + Iris/Iris/Instances/UPred.lean | 2 + Iris/Iris/Instances/UPred/Instance.lean | 76 ++++++------- .../AbstractEctxLangCompleteness.lean | 2 + .../AbstractLangCompleteness.lean | 2 + .../Iris/ProgramLogic/AbstractWeakestPre.lean | 2 + Iris/Iris/ProgramLogic/Adequacy.lean | 2 + Iris/Iris/ProgramLogic/EctxLanguage.lean | 2 + Iris/Iris/ProgramLogic/EctxLifting.lean | 2 + Iris/Iris/ProgramLogic/EctxiLanguage.lean | 2 + Iris/Iris/ProgramLogic/Language.lean | 2 + Iris/Iris/ProgramLogic/Lifting.lean | 2 + Iris/Iris/ProgramLogic/ThreadPool.lean | 2 + Iris/Iris/ProgramLogic/WeakestPre.lean | 8 +- Iris/Iris/ProofMode.lean | 2 + Iris/Iris/ProofMode/Classes.lean | 4 +- Iris/Iris/ProofMode/ClassesMake.lean | 2 + Iris/Iris/ProofMode/Display.lean | 2 + Iris/Iris/ProofMode/Expr.lean | 2 + Iris/Iris/ProofMode/Instances.lean | 2 + Iris/Iris/ProofMode/InstancesCmra.lean | 2 + Iris/Iris/ProofMode/InstancesEmbedding.lean | 2 + Iris/Iris/ProofMode/InstancesFrame.lean | 2 + Iris/Iris/ProofMode/InstancesInternalEq.lean | 24 ++-- Iris/Iris/ProofMode/InstancesLater.lean | 2 + Iris/Iris/ProofMode/InstancesMake.lean | 2 + Iris/Iris/ProofMode/InstancesPlainly.lean | 2 + Iris/Iris/ProofMode/InstancesUpdates.lean | 2 + Iris/Iris/ProofMode/Modalities.lean | 2 + Iris/Iris/ProofMode/ModalityInstances.lean | 2 + Iris/Iris/ProofMode/Patterns.lean | 2 + .../Iris/ProofMode/Patterns/IntroPattern.lean | 2 + Iris/Iris/ProofMode/Patterns/SelPattern.lean | 2 + Iris/Iris/ProofMode/ProofModeM.lean | 2 + Iris/Iris/ProofMode/SynthInstance.lean | 2 + Iris/Iris/ProofMode/Tactics.lean | 2 + Iris/Iris/ProofMode/Tactics/Accu.lean | 2 + Iris/Iris/ProofMode/Tactics/Apply.lean | 2 + Iris/Iris/ProofMode/Tactics/Assumption.lean | 2 + Iris/Iris/ProofMode/Tactics/Basic.lean | 2 + Iris/Iris/ProofMode/Tactics/Cases.lean | 2 + Iris/Iris/ProofMode/Tactics/Clear.lean | 2 + Iris/Iris/ProofMode/Tactics/Combine.lean | 2 + Iris/Iris/ProofMode/Tactics/Eval.lean | 2 + Iris/Iris/ProofMode/Tactics/ExFalso.lean | 2 + Iris/Iris/ProofMode/Tactics/Exact.lean | 2 + Iris/Iris/ProofMode/Tactics/Exists.lean | 2 + Iris/Iris/ProofMode/Tactics/Frame.lean | 2 + Iris/Iris/ProofMode/Tactics/Have.lean | 2 + Iris/Iris/ProofMode/Tactics/HaveCore.lean | 2 + Iris/Iris/ProofMode/Tactics/Induction.lean | 2 + Iris/Iris/ProofMode/Tactics/Intro.lean | 2 + Iris/Iris/ProofMode/Tactics/Inv.lean | 2 + Iris/Iris/ProofMode/Tactics/LeftRight.lean | 2 + Iris/Iris/ProofMode/Tactics/Loeb.lean | 2 + Iris/Iris/ProofMode/Tactics/Mod.lean | 2 + Iris/Iris/ProofMode/Tactics/ModIntro.lean | 2 + Iris/Iris/ProofMode/Tactics/Pure.lean | 2 + Iris/Iris/ProofMode/Tactics/Rename.lean | 2 + Iris/Iris/ProofMode/Tactics/Revert.lean | 2 + Iris/Iris/ProofMode/Tactics/RevertIntro.lean | 2 + Iris/Iris/ProofMode/Tactics/Rewrite.lean | 8 +- Iris/Iris/ProofMode/Tactics/Specialize.lean | 2 + Iris/Iris/ProofMode/Tactics/Split.lean | 2 + Iris/Iris/ProofMode/Tactics/Trivial.lean | 2 + Iris/Iris/ProofMode/UnifHints.lean | 2 + Iris/Iris/Tests.lean | 2 + Iris/Iris/Tests/HeapLang.lean | 2 + Iris/Iris/Tests/HeapLang/HeapTactics.lean | 2 + Iris/Iris/Tests/HeapLang/Linter.lean | 2 + Iris/Iris/Tests/HeapLang/Notation.lean | 2 + Iris/Iris/Tests/HeapLang/WeakestPre.lean | 2 + Iris/Iris/Tests/Instances.lean | 2 + Iris/Iris/Tests/InstancesImport.lean | 2 + Iris/Iris/Tests/Language.lean | 2 + Iris/Iris/Tests/Notation.lean | 2 + Iris/Iris/Tests/StepIndexRegistry.lean | 52 +++++++++ Iris/Iris/Tests/Tactics.lean | 4 +- Iris/Iris/Tests/Updates.lean | 2 + Iris/Iris/Tests/WeakestPre.lean | 2 + 189 files changed, 956 insertions(+), 520 deletions(-) diff --git a/Iris/Iris/Algebra.lean b/Iris/Iris/Algebra.lean index b2b5182d6..eda9875f9 100644 --- a/Iris/Iris/Algebra.lean +++ b/Iris/Iris/Algebra.lean @@ -20,3 +20,5 @@ public import Iris.Algebra.Heap public import Iris.Algebra.View public import Iris.Algebra.HeapView public import Iris.Algebra.Lib + +local stepindex Nat diff --git a/Iris/Iris/Algebra/Agree.lean b/Iris/Iris/Algebra/Agree.lean index aaf303ce3..06da492f9 100644 --- a/Iris/Iris/Algebra/Agree.lean +++ b/Iris/Iris/Algebra/Agree.lean @@ -12,6 +12,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris /-! @@ -80,7 +82,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 Nat α] +variable [OFE α] def dist (n : Nat) (x y : Raw α) : Prop := (∀ a ∈ x.car, ∃ b ∈ y.car, a ≡{n}≡ b) ∧ @@ -227,7 +229,7 @@ theorem toAgree_uninj {x : Raw α} : x.valid → ∃ a, ∀ n, dist n (toAgree a · exists a; simp_all [toAgree] · simp_all [toAgree] -variable [OFE Nat β] {f : α → β} +variable [OFE β] {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 +349,14 @@ end Agree namespace Agree -variable [OFE Nat α] [OFE Nat β] +variable [OFE α] [OFE β] @[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 Nat (Agree α) where +instance instOFE : OFE (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 +526,7 @@ theorem toAgree_def {a : α} : toAgree a = Agree.mk (Agree.Raw.toAgree a) := rfl section -variable [OFE Nat α] +variable [OFE α] @[rocq_alias to_agree_ne] instance instNonExpansive_toAgree : OFE.NonExpansive (@toAgree α) where @@ -576,7 +578,7 @@ theorem toAgree_includedN {a b : α} : toAgree a ≼{n} toAgree b ↔ a ≡{n} · exists toAgree a calc toAgree b ≡{n}≡ toAgree a := OFE.NonExpansive.ne h.symm - _ ≡{n}≡ toAgree a • toAgree a := idemp.dist.symm + _ ≡{n}≡ toAgree a • toAgree a := idemp.dist.symm @[simp, rocq_alias to_agree_included] theorem toAgree_included {a b : α} : toAgree a ≼ toAgree b ↔ a = b := by @@ -585,7 +587,7 @@ theorem toAgree_included {a b : α} : toAgree a ≼ toAgree b ↔ a = b := by · exists toAgree a calc toAgree b = toAgree a := congrArg toAgree h.symm - _ = toAgree a • toAgree a := (CMRA.pcore_op_left rfl).symm + _ = toAgree a • toAgree a := (CMRA.pcore_op_left rfl).symm #rocq_ignore to_agree_included_L "Use toAgree_included" @@ -610,7 +612,7 @@ end Agree @[rocq_alias to_agree_op_valid_L] theorem toAgree_op_valid_iff_eq {a : α} : ✓ (toAgree a • toAgree b) ↔ a = b := by - rw [OFE.eq_dist] + rw [OFE.eq_dist (SI := Nat)] simp [CMRA.valid_iff_validN, Agree.toAgree_op_validN_iff_dist] #rocq_ignore to_agree_op_inv_L "Use toAgree_op_valid_iff_eq" @@ -640,7 +642,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 Nat α] [OFE Nat β] [OFE Nat γ] {f : α → β} [hne : OFE.NonExpansive f] +variable {α β γ : Type _} [OFE α] [OFE β] [OFE γ] {f : α → β} [hne : OFE.NonExpansive f] @[rocq_alias agree_map_ne] instance instNonExpansive_AgreeMap' : OFE.NonExpansive (Agree.map' f) where diff --git a/Iris/Iris/Algebra/Auth.lean b/Iris/Iris/Algebra/Auth.lean index e59e9dd1a..a9c22bc41 100644 --- a/Iris/Iris/Algebra/Auth.lean +++ b/Iris/Iris/Algebra/Auth.lean @@ -19,6 +19,8 @@ The authoritative camera has 2 types of elements: @[expose] public section +local stepindex Nat + open Iris open OFE CMRA UCMRA View @@ -71,7 +73,7 @@ abbrev Auth (A : Type _) [UCMRA A] := namespace Auth variable [UCMRA A] -instance : OFE Nat (Auth A) := View.instOFE +instance : OFE (Auth A) := View.instOFE instance : CMRA (Auth A) := View.instCMRA instance : UCMRA (Auth A) := View.instUCMRA diff --git a/Iris/Iris/Algebra/BigOp.lean b/Iris/Iris/Algebra/BigOp.lean index 166197f42..914abc27d 100644 --- a/Iris/Iris/Algebra/BigOp.lean +++ b/Iris/Iris/Algebra/BigOp.lean @@ -16,6 +16,8 @@ public import Iris.Std.Positives public import Iris.Std.Equivalence meta import Iris.Std.RocqPorting +local stepindex Nat + namespace Iris.Algebra /-! # Big Operators @@ -26,13 +28,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 Nat 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 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 Nat M] (op : M → M → M) {unit : M} [MonoidOps op unit] {K : Type _} +@[rocq_alias big_opM, expose] public def bigOpM {M : Type u} [OFE 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 +42,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 Nat M] (op : M → M → M) {unit : M} [MonoidOps op unit] +@[rocq_alias big_opS, expose] public def bigOpS {M : Type u} [OFE 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 +50,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 Nat M] (op : M → M → M) +@[rocq_alias big_opMS, expose] public def bigOpMS {M : Type u} [OFE 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 +86,7 @@ scoped macro_rules public section namespace BigOpL -variable {M : Type _} {A : Type _} [OFE Nat M] {op : M → M → M} {unit : M} [MonoidOps op unit] +variable {M : Type _} {A : Type _} [OFE M] {op : M → M → M} {unit : M} [MonoidOps op unit] open MonoidOps @@ -216,7 +218,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 Nat A] {Φ Ψ : Nat → A → M} {l₁ l₂ : List A} (hlen : l₁.length = l₂.length) +theorem bigOpL_proper_2 [OFE 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 +289,7 @@ end CMRA section Hom -variable {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] +variable {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE 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 +321,7 @@ namespace BigOpM open scoped PartialMap -variable {M : Type u} [OFE Nat M] {op : M → M → M} {unit : M} [MonoidOps op unit] +variable {M : Type u} [OFE M] {op : M → M → M} {unit : M} [MonoidOps op unit] variable {M' : Type _ → Type _} {K : Type _} {V : Type _} variable [LawfulFiniteMap M' K] @@ -401,7 +403,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 Nat A] {Φ Ψ : K → A → M} {m1 m2 : M' A} (hm : ∀ k, get? m1 k = get? m2 k) +theorem bigOpM_eq_strong [OFE 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 +579,8 @@ theorem bigOpM_none {f : K → V → Option M} {m : M' V} : end CMRA -variable {M₁} [OFE Nat M₁] -variable {M₂} [OFE Nat M₂] +variable {M₁} [OFE M₁] +variable {M₂} [OFE M₂] variable {op₁ : M₁ → M₁ → M₁} {op₂ : M₂ → M₂ → M₂} {unit₁ : M₁} {unit₂ : M₂} variable [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] @@ -604,7 +606,7 @@ end BigOpM namespace BigOpS -variable {M : Type _} {A : Type _} {S : Type _} [OFE Nat M] {op : M → M → M} {unit : M} +variable {M : Type _} {A : Type _} {S : Type _} [OFE M] {op : M → M → M} {unit : M} [MonoidOps op unit] [LawfulFiniteSet S A] open BigOpL MonoidOps LawfulSet FiniteSet @@ -717,7 +719,7 @@ end CMRA section Homomorphism -variable {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] +variable {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE M₂] variable {op₁ : M₁ → M₁ → M₁} {op₂ : M₂ → M₂ → M₂} {unit₁ : M₁} {unit₂ : M₂} variable [MonoidOps op₁ unit₁] [MonoidOps op₂ unit₂] @@ -747,7 +749,7 @@ end BigOpS namespace BigOpMS -variable {M : Type _} {A : Type _} {MS : Type _} [OFE Nat M] {op : M → M → M} {unit : M} +variable {M : Type _} {A : Type _} {MS : Type _} [OFE M] {op : M → M → M} {unit : M} [MonoidOps op unit] [LawfulFiniteMultiSet MS A] open BigOpL MonoidOps @@ -856,7 +858,7 @@ end CMRA section Homomorphism -variable {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] +variable {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE 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/CMRA.lean b/Iris/Iris/Algebra/CMRA.lean index bc368d122..3bb281db3 100644 --- a/Iris/Iris/Algebra/CMRA.lean +++ b/Iris/Iris/Algebra/CMRA.lean @@ -12,11 +12,13 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris open OFE @[rocq_alias cmra] -class CMRA (α : Type _) extends OFE Nat α where +class CMRA (α : Type _) extends OFE α where pcore : α → Option α op : α → α → α ValidN : Nat → α → Prop @@ -50,7 +52,7 @@ class CMRA (α : Type _) extends OFE Nat α where #rocq_ignore cmra_ofeO "Not needed." /-- Reduction of `pcore_op_mono` to regular monotonicity -/ -theorem pcore_op_mono_of_core_op_mono [OFE Nat α] (op : α → α → α) (pcore : α → Option α) +theorem pcore_op_mono_of_core_op_mono [OFE α] (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) := @@ -216,9 +218,9 @@ instance : NonExpansive (pcore (α := α)) where | .some a, .some b => let ⟨w, hw, ew⟩ := pcore_ne e ex calc - pcore x ≡{n}≡ some a := .of_eq ex - _ ≡{n}≡ some w := ew - _ ≡{n}≡ pcore y := .of_eq hw.symm + pcore x ≡{n}≡ some a := .of_eq ex + _ ≡{n}≡ some w := ew + _ ≡{n}≡ pcore y := .of_eq hw.symm | .some a, .none => let ⟨w, hw, ew⟩ := pcore_ne e ex cases hw.symm ▸ ey @@ -283,7 +285,7 @@ theorem _root_.Iris.OFE.Dist.validN : (x : α) ≡{n}≡ y → (✓{n} x ↔ ✓ @[rocq_alias cmra_validN_le] theorem validN_of_le {n n'} {x : α} (le : n' ≤ n) : ✓{n} x → ✓{n'} x := - le.recOn id fun _ ih vs => ih (validN_succ vs) + le.recOn id fun _ ih vs => ih (validN_succ vs) @[rocq_alias cmra_validN_lt] theorem validN_of_lt {n n'} {x : α} (lt : n' < n): ✓{n} x → ✓{n'} x := @@ -305,11 +307,11 @@ theorem valid_op_left {x y : α} : ✓ (x • y) → ✓ x := theorem validN_opM {x : α} {my : Option α} : ✓{n} (x •? my) → ✓{n} x := match my with - | none => id | some _ => validN_op_left + | none => id | some _ => validN_op_left theorem valid_opM {x : α} {my : Option α} : ✓ (x •? my) → ✓ x := match my with - | none => id | some _ => valid_op_left + | none => id | some _ => valid_op_left theorem validN_op_opM_left {mz : Option α} : ✓{n} (x • y : α) •? mz → ✓{n} x •? mz := match mz with @@ -317,8 +319,8 @@ theorem validN_op_opM_left {mz : Option α} : ✓{n} (x • y : α) •? mz → | .some z => fun h => have := calc (x • y) • z ≡{n}≡ x • (y • z) := op_assocN.symm - _ ≡{n}≡ x • (z • y) := op_right_dist x op_commN - _ ≡{n}≡ (x • z) • y := op_assocN + _ ≡{n}≡ x • (z • y) := op_right_dist x op_commN + _ ≡{n}≡ (x • z) • y := op_assocN validN_op_left ((Dist.validN this).mp h) theorem validN_op_opM_right {mz : Option α} (h : ✓{n} (x • y : α) •? mz) : ✓{n} y •? mz := @@ -524,8 +526,8 @@ theorem pcore_monoN' {n} {x y : α} {cx} : suffices h : cx ≼{n} r from ⟨r, hr, h⟩ calc cx ≡{n}≡ w := ew - w ≼{n} t := incN_of_inc n et - t ≡{n}≡ r := er + w ≼{n} t := incN_of_inc n et + t ≡{n}≡ r := er @[rocq_alias cmra_included_pcore] theorem pcore_inc_self {x : α} {cx} (e : pcore x = some cx) : cx ≼ x := @@ -751,8 +753,8 @@ variable {α : Type _} [CMRA α] -- Global Instance id_free_ne n : Proper (dist n ==> iff) (@IdFree A). -- Proof. --- intros x x' EQ%(dist_le _ 0); last lia. rewrite /IdFree. --- split=> y ?; (rewrite -EQ || rewrite EQ); eauto. +-- intros x x' EQ%(dist_le _ 0); last lia. rewrite /IdFree. +-- split=> y ?; (rewrite -EQ || rewrite EQ); eauto. -- Qed. -- Global Instance id_free_proper : Proper (equiv ==> iff) (@IdFree A). @@ -763,8 +765,8 @@ theorem IdFree.of_dist {x₁ x₂ : α} {n} (e : x₁ ≡{n}≡ x₂) (h : IdFre have ee := Dist.le e SIdx.le_0_l have := calc x₁ • z ≡{0}≡ x₂ • z := op_left_dist z ee - _ ≡{0}≡ x₂ := h₂ - _ ≡{0}≡ x₁ := ee.symm + _ ≡{0}≡ x₂ := h₂ + _ ≡{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₂ := @@ -954,7 +956,7 @@ infixr:25 " -C> " => Hom instance [CMRA β] : CoeFun (α -C> β) (fun _ => α → β) := ⟨fun F => F.f⟩ -instance [CMRA β] : OFE Nat (α -C> β) where +instance [CMRA β] : OFE (α -C> β) where Dist n f g := f.toHom ≡{n}≡ g.toHom dist_eqv := { refl _ := dist_eqv.refl _ @@ -972,11 +974,11 @@ protected def Hom.id [CMRA α] : α -C> α where op _ _ := rfl -- protected def Hom.comp [CMRA α] [CMRA β] [CMRA γ] (g : β -C> γ) (f : α -C> β) : α -C> γ where --- toHom := OFE.Hom.comp g.toHom f.toHom --- hom := --- ⟨fun v => g.mor.validN (f.mor.validN v), --- fun x => sorry, --- fun x y => sorry⟩ +-- toHom := OFE.Hom.comp g.toHom f.toHom +-- hom := +-- ⟨fun v => g.mor.validN (f.mor.validN v), +-- fun x => sorry, +-- fun x y => sorry⟩ #rocq_ignore cmra_morphism_proper "OFE is Leibniz; use equality" @@ -1006,19 +1008,19 @@ section rFunctor @[rocq_alias rFunctor] class RFunctor (F : COFE.OFunctorPre Nat) where - [cmra [COFE Nat α] [COFE Nat β] : CMRA (F α β)] - map [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : + [cmra [COFE α] [COFE β] : CMRA (F α β)] + map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -C> F α₂ β₂ - map_ne [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : + map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - 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 β₃] + map_id [COFE α] [COFE β] (x : F α β) : map (Hom.id (α := α)) (Hom.id (α := β)) x = x + map_comp [COFE α₁] [COFE α₂] [COFE α₃] [COFE β₁] [COFE β₂] [COFE β₃] (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 Nat) extends (RFunctor F) where - map_contractive [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : + map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) attribute [reducible, instance] RFunctor.cmra @@ -1026,10 +1028,10 @@ attribute [reducible, instance] RFunctor.cmra @[rocq_alias rFunctor_to_oFunctor] 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 - map_id x := RFunctor.map_id x + ofe := RFunctor.cmra.toOFE + map a b := (RFunctor.map a b).toHom + map_ne.ne := RFunctor.map_ne.ne + map_id x := RFunctor.map_id x map_comp f g f' g' x := RFunctor.map_comp f g f' g' x @[rocq_alias rFunctor_to_oFunctor_contractive] @@ -1043,29 +1045,29 @@ section urFunctor @[rocq_alias urFunctor] class URFunctor (F : COFE.OFunctorPre Nat) where - [cmra [COFE Nat α] [COFE Nat β] : UCMRA (F α β)] - map [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : + [cmra [COFE α] [COFE β] : UCMRA (F α β)] + map [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : (α₂ -n> α₁) → (β₁ -n> β₂) → F α₁ β₁ -C> F α₂ β₂ - map_ne [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : + map_ne [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : NonExpansive₂ (@map α₁ α₂ β₁ β₂ _ _ _ _) - 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 β₃] + map_id [COFE α] [COFE β] (x : F α β) : map (Hom.id (α := α)) (Hom.id (α := β)) x = x + map_comp [COFE α₁] [COFE α₂] [COFE α₃] [COFE β₁] [COFE β₂] [COFE β₃] (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 Nat) extends URFunctor F where - map_contractive [COFE Nat α₁] [COFE Nat α₂] [COFE Nat β₁] [COFE Nat β₂] : + map_contractive [COFE α₁] [COFE α₂] [COFE β₁] [COFE β₂] : Contractive (Function.uncurry (@map α₁ α₂ β₁ β₂ _ _ _ _)) attribute [reducible, instance] URFunctor.cmra @[rocq_alias urFunctor_to_rFunctor] instance URFunctor.toRFunctor [UF : URFunctor F] : RFunctor F where - cmra := URFunctor.cmra.toCMRA - map f g := URFunctor.map f g - map_ne := URFunctor.map_ne - map_id := URFunctor.map_id + cmra := URFunctor.cmra.toCMRA + map f g := URFunctor.map f g + map_ne := URFunctor.map_ne + map_id := URFunctor.map_id map_comp := URFunctor.map_comp @[rocq_alias urFunctor_to_rFunctor_contractive] @@ -1466,7 +1468,7 @@ theorem eqv_of_inc_exclusive [Exclusive (a : α)] {b : α} (H : some a ≼ some · exact not_valid_of_excl_inc H Hv |>.elim @[rocq_alias Some_includedN_exclusive] -theorem dist_of_inc_exclusive [Exclusive (a : α)] {b : α} (H : some a ≼{n} some b) (Hv : ✓{n} b) : +theorem dist_of_inc_exclusive [Exclusive (a : α)] {b : α} (H : some a ≼{n} some b) (Hv : ✓{n} b) : a ≡{n}≡ b := by rcases incN_iff.mp H with (Hcontra|H) · simp at Hcontra @@ -1614,7 +1616,7 @@ instance cmraProd : CMRA (α × β) where suffices g : cx ≡{n}≡ (cy₁, cy₂) by simp [hcy₁, hcy₂, g, pcore] calc cx ≡{n}≡ (cx₁, cx₂) := Dist.of_eq (Option.some.inj hcx).symm - _ ≡{n}≡ (cy₁, cy₂) := dist_prod_ext hxy₁ hxy₂ + _ ≡{n}≡ (cy₁, cy₂) := dist_prod_ext hxy₁ hxy₂ validN_ne {_} x y H := fun ⟨vx1, vx2⟩ => ⟨H.1.validN.mp vx1, H.2.validN.mp vx2⟩ valid_iff_validN {x} := by refine ⟨fun ⟨va, vb⟩ n => ⟨va.validN, vb.validN⟩, fun h => ⟨?_, ?_⟩⟩ @@ -1682,7 +1684,7 @@ instance instCmraDistreteProd [CMRA.Discrete α] [CMRA.Discrete β] : CMRA.Discr @[rocq_alias pair_core_id] instance instCoreIdPair {x : α} {y : β} [CMRA.CoreId x] [CMRA.CoreId y] : CMRA.CoreId (α := α × β) ⟨x, y⟩ where core_id := by - refine (OFE.eq_dist.mpr (fun _ => ?_)) + refine ((OFE.eq_dist (SI := Nat)).mpr (fun _ => ?_)) simp only [CMRA.pcore, pcore] haveI : NonExpansive (fun b : β => some (x, b)) := ⟨fun _ _ _ H => some_dist_some.mpr (dist_prod_ext .rfl H)⟩ haveI : NonExpansive ((fun a : α => (CMRA.pcore y).bind fun b : β => pure (a, b))) := diff --git a/Iris/Iris/Algebra/COFESolver.lean b/Iris/Iris/Algebra/COFESolver.lean index 36fa4859b..06011178a 100644 --- a/Iris/Iris/Algebra/COFESolver.lean +++ b/Iris/Iris/Algebra/COFESolver.lean @@ -11,30 +11,30 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + #rocq_ignore solution "Use OFE.iso + Inhabited + COFE." namespace Iris.COFE.OFunctor open OFE -variable [SIdx SI] - -variable {F : ∀ α β [COFE Nat α] [COFE Nat β], Type u} [OFunctorContractive Nat F] -variable [∀ α [COFE Nat α], IsCOFE Nat (F α α)] +variable {F : ∀ α β [COFE α] [COFE β], Type u} [OFunctorContractive Nat F] +variable [∀ α [COFE α], IsCOFE (F α α)] variable [inh : Inhabited (F (ULift Unit) (ULift Unit))] namespace Fix.Impl variable (F) in @[rocq_alias solver.A'] -def A' : Nat → Σ α : Type u, COFE Nat α +def A' : Nat → Σ α : Type u, COFE α | 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 Nat (A' F n).1 := (A' F n).2 -instance instA (n) : COFE Nat (A F n) := (A' F n).2 +instance instA' (n) : COFE (A' F n).1 := (A' F n).2 +instance instA (n) : COFE (A F n) := (A' F n).2 #rocq_ignore solver.A_cofe "Inference succeeds automatically via `instA`/`instA'`" variable (F) in @@ -59,7 +59,7 @@ def down (k : Nat) : A F (k+1) -n> A F k := (updown F k).2 @[rocq_alias solver.gf] theorem down_up : ∀ {k} x, down F k (up F k x) = x | 0, ⟨()⟩ => rfl - | _+1, x => OFE.eq_dist.mpr fun _ => (map_comp _ _ _ _ _).dist.symm.trans <| + | _+1, x => OFE.eq_dist (SI := Nat) |>.mpr fun _ => (map_comp _ _ _ _ _).dist.symm.trans <| Dist.trans (map_ne.ne (fun y => (down_up y).dist) (fun y => (down_up y).dist) x) (map_id _).dist @@ -80,14 +80,14 @@ structure Tower : Type u where instance : CoeFun (Tower F) (fun _ => ∀ k, A F k) := ⟨Tower.val⟩ @[rocq_alias solver.T] -instance : OFE Nat (Tower F) where +instance : OFE (Tower F) where Dist n f g := ∀ k, f k ≡{n}≡ g k dist_eqv := { refl _ _ := dist_eqv.refl _ symm h _ := dist_eqv.symm (h _) trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _) } - eq_dist {_ _} := by rw [Tower.ext_iff, funext_iff]; simpa only [eq_dist] using forall_comm + eq_dist {_ _} := by rw [Tower.ext_iff, funext_iff]; simpa only [eq_dist (SI := Nat)] using forall_comm dist_lt h1 h2 _ := dist_lt (h1 _) h2 #rocq_ignore solver.tower_equiv "Included in OFE (Tower F) instance" @@ -95,14 +95,14 @@ instance : OFE Nat (Tower F) where #rocq_ignore solver.tower_ofe_mixin "Not needed" @[rocq_alias solver.tower_chain] -def towerChain (c : Chain (SI := Nat) (Tower F)) (k : Nat) : Chain (A F k) where +def towerChain (c : Chain (Tower F)) (k : Nat) : Chain (A F k) where chain i := c.1 i k cauchy h := c.cauchy h k -instance : COFE Nat (Tower F) where +instance : COFE (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 OFE.eq_dist (SI := Nat) |>.mpr (fun n => ?_) refine ((down ..).ne.1 conv_compl).trans <| .trans ?_ conv_compl.symm exact (c.chain n).down.dist conv_compl _ := conv_compl @@ -207,7 +207,7 @@ protected def Tower.embed (k) : A F k -n> Tower F := by @[rocq_alias solver.embed_f] theorem Tower.embed_up (x : A F k) : Tower.embed (k+1) (up F k x) = Tower.embed k x := by - refine OFE.eq_dist.mpr (fun n i => ?_) + refine OFE.eq_dist (SI := Nat) |>.mpr (fun n i => ?_) dsimp [Tower.embed, embed]; split <;> rename_i h₁ · simp [Nat.le_of_succ_le h₁] suffices ∀ a b (e₁ : k + 1 + a = i) (e₂ : k+b = i), @@ -266,7 +266,7 @@ def unfoldChain (X : Tower F) : Chain (F (Tower F) (Tower F)) where def Tower.isoAux : OFE.Iso (F (Tower F) (Tower F)) (Tower F) where hom.f X := { val n := (down F n).comp (map (Tower.embed _) (Tower.proj _)) X - down {n} := OFE.eq_dist.mpr fun m => (down ..).ne.1 <| + down {n} := OFE.eq_dist (SI := Nat) |>.mpr fun m => (down ..).ne.1 <| (map_comp _ _ _ _ _).dist.symm.trans <| map_ne.ne (fun Y => (Tower.embed_up Y).dist) (fun Y => Y.down.dist) _ } @@ -275,7 +275,7 @@ def Tower.isoAux : OFE.Iso (F (Tower F) (Tower F)) (Tower F) where inv.ne.1 n _ _ h := by refine conv_compl.trans <| .trans ?_ conv_compl.symm exact (map ..).ne.1 (h (n+1)) - hom_inv {X} := OFE.eq_dist.mpr fun n => by + hom_inv {X} := OFE.eq_dist (SI := Nat) |>.mpr fun n => by intro k refine ((down ..).ne.1 (.trans ?_ (X.downN n).dist)).trans X.down.dist refine ((map ..).ne.1 (conv_compl.trans @@ -301,10 +301,9 @@ def Tower.isoAux : OFE.Iso (F (Tower F) (Tower F)) (Tower F) where induction n with | zero => exact (map_id _).dist | succ n ih => - refine (map_comp _ _ _ _ _).dist.trans <| - (ih (Nat.succ.inj e) _).trans (congrArg (fun a => (downN ..) a) ?_).dist - exact (down_eqToHom _).symm - inv_hom := OFE.eq_dist.mpr fun n => by + refine (map_comp _ _ _ _ _).dist.trans <| (ih (Nat.succ.inj e) _).trans ?_ + exact Dist.of_eq (congrArg (fun a => (downN ..) a) (down_eqToHom _).symm) + inv_hom := OFE.eq_dist (SI := Nat) |>.mpr fun n => by refine (conv_compl' n.le_succ).trans ?_ dsimp [unfoldChain]; rw [down] refine ((map_comp _ _ _ _ _).trans @@ -324,7 +323,7 @@ variable (F) in def Fix : Type u := Tower F instance : Inhabited (Fix F) := inferInstanceAs (Inhabited (Tower F)) -instance : COFE Nat (Fix F) := inferInstanceAs (COFE Nat (Tower F)) +instance : COFE (Fix F) := inferInstanceAs (COFE (Tower F)) def Fix.iso : OFE.Iso (F (Fix F) (Fix F)) (Fix F) := Tower.iso diff --git a/Iris/Iris/Algebra/Csum.lean b/Iris/Iris/Algebra/Csum.lean index 158a78b40..0a27ec731 100644 --- a/Iris/Iris/Algebra/Csum.lean +++ b/Iris/Iris/Algebra/Csum.lean @@ -12,6 +12,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris @[rocq_alias csum] @@ -28,13 +30,13 @@ namespace Csum #rocq_ignore csum_equiv "OFE is Leibniz; use equality" -@[simp, rocq_alias csum_dist] def Dist [OFE Nat α] [OFE Nat β] (n : Nat) : Csum α β → Csum α β → Prop +@[simp, rocq_alias csum_dist] def Dist [OFE α] [OFE β] (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 Nat α] [OFE Nat β] {n} : Equivalence (Csum.Dist (α := α) (β := β) n) where +theorem dist_eqv [OFE α] [OFE β] {n} : Equivalence (Csum.Dist (α := α) (β := β) n) where refl {x} := by cases x with | inl => exact Dist.rfl | inr => exact Dist.rfl @@ -45,44 +47,44 @@ theorem dist_eqv [OFE Nat α] [OFE Nat β] {n} : Equivalence (Csum.Dist (α := first | trivial | exact h₁.trans h₂ | exact h₂.elim | exact h₁.elim @[rocq_alias csumO] -instance [OFE Nat α] [OFE Nat β] : OFE Nat (Csum α β) where +instance [OFE α] [OFE β] : OFE (Csum α β) where Dist := Csum.Dist dist_eqv := dist_eqv eq_dist {x y} := by - cases x <;> cases y <;> simp [Csum.Dist, eq_dist] + cases x <;> cases y <;> simp [Csum.Dist, eq_dist (SI := Nat)] dist_lt {n x y m} hn hlt := by cases x <;> cases y <;> first | exact OFE.Dist.lt hn hlt | exact hn.elim | trivial #rocq_ignore csum_ofe_mixin "Not needed" @[rocq_alias Cinl_ne] -instance [OFE Nat α] [OFE Nat β] : NonExpansive (inl (α := α) (β := β)) where +instance [OFE α] [OFE β] : NonExpansive (inl (α := α) (β := β)) where ne _ _ _ := id #rocq_ignore Cinl_proper "Derivable using NonExpansive.eqv" @[rocq_alias Cinr_ne] -instance [OFE Nat α] [OFE Nat β] : NonExpansive (inr (α := α) (β := β)) where +instance [OFE α] [OFE β] : NonExpansive (inr (α := α) (β := β)) where ne _ _ _ := id #rocq_ignore Cinr_proper "Derivable using NonExpansive.eqv" @[rocq_alias Cinl_inj] -theorem inl_inj [OFE Nat α] [OFE Nat β] {a a' : α} (h : (inl (β := β) a) = inl a') : a = a' := +theorem inl_inj [OFE α] [OFE β] {a a' : α} (h : (inl (β := β) a) = inl a') : a = a' := Csum.inl.inj h @[rocq_alias Cinl_inj_dist] -theorem inl_injN [OFE Nat α] [OFE Nat β] {a a' : α} (h : inl (β := β) a ≡{n}≡ inl a') : a ≡{n}≡ a' := h +theorem inl_injN [OFE α] [OFE β] {a a' : α} (h : inl (β := β) a ≡{n}≡ inl a') : a ≡{n}≡ a' := h @[rocq_alias Cinr_inj] -theorem inr_inj [OFE Nat α] [OFE Nat β] {b b' : β} (h : (inr (α := α) b) = inr b') : b = b' := +theorem inr_inj [OFE α] [OFE β] {b b' : β} (h : (inr (α := α) b) = inr b') : b = b' := Csum.inr.inj h @[rocq_alias Cinr_inj_dist] -theorem inr_injN [OFE Nat α] [OFE Nat β] {b b' : β} (h : inr (α := α) b ≡{n}≡ inr b') : b ≡{n}≡ b' := h +theorem inr_injN [OFE α] [OFE β] {b b' : β} (h : inr (α := α) b ≡{n}≡ inr b') : b ≡{n}≡ b' := h @[rocq_alias csum_ofe_discrete] -instance [OFE Nat α] [OFE Nat β] [OFE.Discrete α] [OFE.Discrete β] : OFE.Discrete (Csum α β) where +instance [OFE α] [OFE β] [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 +92,7 @@ instance [OFE Nat α] [OFE Nat β] [OFE.Discrete α] [OFE.Discrete β] : OFE.Dis | exact h.elim | trivial @[rocq_alias Cinl_discrete] -instance [OFE Nat α] [OFE Nat β] {a : α} [DiscreteE a] : DiscreteE (inl (β := β) a) where +instance [OFE α] [OFE β] {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 +100,14 @@ instance [OFE Nat α] [OFE Nat β] {a : α} [DiscreteE a] : DiscreteE (inl (β : | invalid => exact h.elim @[rocq_alias Cinr_discrete] -instance [OFE Nat α] [OFE Nat β] {b : β} [DiscreteE b] : DiscreteE (inr (α := α) b) where +instance [OFE α] [OFE β] {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 Nat α] [OFE Nat β] : DiscreteE (@invalid α β) where +instance [OFE α] [OFE β] : DiscreteE (@invalid α β) where discrete {x} h := by cases x with | inl => exact h.elim @@ -121,21 +123,21 @@ instance [OFE Nat α] [OFE Nat β] : DiscreteE (@invalid α β) where match x with | inr b => b | _ => d @[rocq_alias csum_chain_l] -def chainL [OFE Nat α] [OFE Nat β] (c : Chain (Csum α β)) (a : α) : Chain α where +def chainL [OFE α] [OFE β] (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 Nat α] [OFE Nat β] (c : Chain (Csum α β)) (b : β) : Chain β where +def chainR [OFE α] [OFE β] (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 Nat α] [OFE Nat β] [IsCOFE Nat α] [IsCOFE Nat β] : IsCOFE Nat (Csum α β) where +instance [OFE α] [OFE β] [IsCOFE α] [IsCOFE β] : IsCOFE (Csum α β) where compl c := match c 0 with | inl a => inl (IsCOFE.compl (chainL c a)) @@ -232,23 +234,23 @@ instance [CMRA α] [CMRA β] : CMRA (Csum α β) where pcore_idem {x cx} hpx := by cases x with | inl a => obtain ⟨ca, hpa, rfl⟩ := pcore_map_inl_eq hpx - exact Option.map_forall₂ inl (CMRA.pcore_idem hpa) + exact Option.map_forall₂ (SI := Nat) inl (CMRA.pcore_idem hpa) | inr b => obtain ⟨cb, hpb, rfl⟩ := pcore_map_inr_eq hpx - exact Option.map_forall₂ inr (CMRA.pcore_idem hpb) + exact Option.map_forall₂ (SI := Nat) inr (CMRA.pcore_idem hpb) | invalid => simp only [Csum.pcore, Option.some.injEq] at hpx; exact hpx ▸ rfl pcore_op_mono {x cx} hpx y := by cases x with | inl a => obtain ⟨ca, hpa, rfl⟩ := pcore_map_inl_eq hpx; cases y with | inl a' => obtain ⟨cy, hcy⟩ := CMRA.pcore_op_mono hpa a' - exact ⟨inl cy, Option.map_forall₂ inl hcy⟩ + exact ⟨inl cy, Option.map_forall₂ (SI := Nat) inl hcy⟩ | _ => exact ⟨invalid, rfl⟩ | inr b => obtain ⟨cb, hpb, rfl⟩ := pcore_map_inr_eq hpx; cases y with | inr b' => obtain ⟨cy, hcy⟩ := CMRA.pcore_op_mono hpb b' - exact ⟨inr cy, Option.map_forall₂ inr hcy⟩ + exact ⟨inr cy, Option.map_forall₂ (SI := Nat) inr hcy⟩ | _ => exact ⟨invalid, rfl⟩ | invalid => simp only [Csum.pcore, Option.some.injEq] at hpx; exact hpx ▸ ⟨invalid, rfl⟩ @@ -289,11 +291,11 @@ instance [CMRA α] [CMRA β] [CMRA.Discrete α] [CMRA.Discrete β] : CMRA.Discre @[rocq_alias Cinl_core_id] instance [CMRA α] [CMRA β] {a : α} [CoreId a] : CoreId (inl (β := β) a) where - core_id := Option.map_forall₂ inl core_id + core_id := Option.map_forall₂ (SI := Nat) inl core_id @[rocq_alias Cinr_core_id] instance [CMRA α] [CMRA β] {b : β} [CoreId b] : CoreId (inr (α := α) b) where - core_id := Option.map_forall₂ inr core_id + core_id := Option.map_forall₂ (SI := Nat) inr core_id /-! ## Exclusive -/ @@ -510,7 +512,7 @@ theorem map_compose (f : α → α') (f' : α' → α'') (g : β → β') (g' : cases x <;> simp @[rocq_alias csum_map_ext] -theorem map_ext [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] (f f' : α → α') (g g' : β → β') +theorem map_ext [OFE α] [OFE α'] [OFE β] [OFE β'] (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 @@ -519,7 +521,7 @@ theorem map_ext [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] (f f' : α | invalid => trivial @[rocq_alias csum_map_cmra_ne] -theorem map_ne [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] {n} +theorem map_ne [OFE α] [OFE α'] [OFE β] [OFE β'] {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) : @@ -530,14 +532,14 @@ theorem map_ne [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] {n} | invalid => cases y with | invalid => trivial | _ => exact hxy @[rocq_alias csumO_map] -def oMap [OFE Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] (f : α -n> α') (g : β -n> β') : +def oMap [OFE α] [OFE α'] [OFE β] [OFE β'] (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 Nat α] [OFE Nat α'] [OFE Nat β] [OFE Nat β'] : +theorem oMap_ne [OFE α] [OFE α'] [OFE β] [OFE β'] : NonExpansive₂ (oMap (α := α) (α' := α') (β := β) (β' := β')) where ne _ _ _ hf _ _ hg x := by cases x with @@ -566,14 +568,14 @@ def cMap [CMRA α] [CMRA α'] [CMRA β] [CMRA β'] show (CMRA.pcore a).map (inl ∘ ⇑fa) = _ rw [show (CMRA.pcore a).map (inl ∘ ⇑fa) = ((CMRA.pcore a).map fa).map inl from (Option.map_map ..).symm] - exact Option.map_forall₂ inl (fa.pcore a) + exact Option.map_forall₂ (SI := Nat) inl (fa.pcore a) | inr b => show ((CMRA.pcore b).map inr).map (map fa fb) = (CMRA.pcore (fb b)).map inr rw [Option.map_map] show (CMRA.pcore b).map (inr ∘ ⇑fb) = _ rw [show (CMRA.pcore b).map (inr ∘ ⇑fb) = ((CMRA.pcore b).map fb).map inr from (Option.map_map ..).symm] - exact Option.map_forall₂ inr (fb.pcore b) + exact Option.map_forall₂ (SI := Nat) inr (fb.pcore b) | invalid => trivial op x y := by cases x <;> cases y <;> first | exact congrArg _ (fa.op _ _) | exact congrArg _ (fb.op _ _) | trivial diff --git a/Iris/Iris/Algebra/DFrac.lean b/Iris/Iris/Algebra/DFrac.lean index 8727555ab..6d4b9ac0a 100644 --- a/Iris/Iris/Algebra/DFrac.lean +++ b/Iris/Iris/Algebra/DFrac.lean @@ -15,6 +15,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris /-- Knowledge about a discardable fraction. -/ @@ -30,7 +32,7 @@ inductive DFrac where #rocq_ignore DfracOwn_inj "Not needed" #rocq_ignore DfracBoth_inj "Not needed" -@[simp] instance : COFE Nat DFrac := COFE.ofDiscrete _ +@[simp] instance : COFE 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 90c08dd10..b7f7d52fb 100644 --- a/Iris/Iris/Algebra/DynReservationMap.lean +++ b/Iris/Iris/Algebra/DynReservationMap.lean @@ -18,6 +18,8 @@ namespace Iris @[expose] public section +local stepindex Nat + open Std PartialMap universe u v @@ -52,12 +54,12 @@ section OFE open OFE -variable [LawfulPartialMap H Pos] [OFE Nat A] +variable [LawfulPartialMap H Pos] [OFE A] #rocq_ignore dyn_reservation_map_ofe_mixin "Not needed" @[rocq_alias dyn_reservation_mapO] -instance : OFE Nat (DynReservationMap A H) where +instance : OFE (DynReservationMap A H) where Dist n x y := x.data ≡{n}≡ y.data ∧ x.token ≡{n}≡ y.token dist_eqv := { refl _ := ⟨.rfl, rfl⟩, @@ -73,7 +75,7 @@ instance : OFE Nat (DynReservationMap A H) where @[rocq_alias dyn_reservation_map_ofe_discrete] instance instDiscreteDynReservationMap [Discrete A] : Discrete (DynReservationMap A H) where - discrete_0 h := OFE.eq_dist.mpr <| by + discrete_0 h := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n exact ⟨(discrete_0 h.left).dist, (discrete_0 h.right).dist⟩ @@ -87,7 +89,7 @@ instance instNonExpansiveDynReservationMapSingleton : @[rocq_alias DynReservationMap_discrete] instance instDiscreteEDynReservationMapMk {a : H A} [DiscreteE a] : DiscreteE (DynReservationMap.mk a b) where - discrete := fun h => OFE.eq_dist.mpr <| by + discrete := fun h => OFE.eq_dist (SI := Nat) |>.mpr <| by intro n exact ⟨(DiscreteE.discrete h.1).dist, (DiscreteE.discrete h.2).dist⟩ @@ -281,9 +283,9 @@ instance instUCMRADynReservationMap : UCMRA (DynReservationMap A H) where refine .inr fun HK => bb ?_ refine (mem_iff_of_validN_union (validN_token_of_validN v) i).mpr ?_ exact .inl HK - assoc := eq_dist.mpr <| by refine fun _ => ⟨?_, ?_⟩ <;> exact CMRA.assoc.dist - comm := eq_dist.mpr <| by refine fun _ => ⟨?_, ?_⟩ <;> exact CMRA.comm.dist - pcore_op_left {x cx} h := eq_dist.mpr <| by + assoc := eq_dist (SI := Nat) |>.mpr <| by refine fun _ => ⟨?_, ?_⟩ <;> exact CMRA.assoc.dist + comm := eq_dist (SI := Nat) |>.mpr <| by refine fun _ => ⟨?_, ?_⟩ <;> exact CMRA.comm.dist + pcore_op_left {x cx} h := eq_dist (SI := Nat) |>.mpr <| by refine fun n => ⟨?_, ?_⟩ · simp only [←Option.some_inj.mp h, op_data', core_data] exact (core_op x.data).dist @@ -295,7 +297,7 @@ instance instUCMRADynReservationMap : UCMRA (DynReservationMap A H) where pcore_op_mono {x cx} h y := by obtain ⟨z, hz⟩ := core_op_mono x.data y.data obtain ⟨w, hw⟩ := core_op_mono x.token y.token - refine ⟨mk z w, eq_dist.mpr ?_⟩ + refine ⟨mk z w, eq_dist (SI := Nat) |>.mpr ?_⟩ refine fun n => ⟨?_, ?_⟩ · simp only [op_data', core_data, (Option.some_inj.mp h.symm)] exact hz.dist @@ -303,16 +305,16 @@ instance instUCMRADynReservationMap : UCMRA (DynReservationMap A H) where exact hw.dist extend {n x y₁ y₂} v exy := by obtain ⟨z₁, z₂, xzz, zy₁, zy₂⟩ := CMRA.extend (validN_data_of_validN v) exy.left - refine ⟨mk z₁ y₁.token, mk z₂ y₂.token, eq_dist.mpr ?_, ⟨zy₁, rfl⟩, ⟨zy₂, rfl⟩⟩ + refine ⟨mk z₁ y₁.token, mk z₂ y₂.token, eq_dist (SI := Nat) |>.mpr ?_, ⟨zy₁, rfl⟩, ⟨zy₂, rfl⟩⟩ exact fun m => ⟨xzz.dist, exy.right⟩ unit := mk ∅ ∅ unit_valid := valid_iff.mpr ⟨Heap.valid_empty, valid_set, show setInfinite ((⊤ : CoPset) \ ∅) by rw [diff_empty]; exact top_infinite, fun _ => .inr (mem_empty _)⟩ - unit_left_id {x} := OFE.eq_dist.mpr <| by + unit_left_id {x} := OFE.eq_dist (SI := Nat) |>.mpr <| by exact fun n => ⟨(Algebra.MonoidOps.op_left_id : (∅ : H A) • x.data = x.data).dist, (pcore_op_left' rfl).dist⟩ - pcore_unit := eq_dist.mpr <| by exact fun n => ⟨Heap.core_empty.dist, .rfl⟩ + pcore_unit := eq_dist (SI := Nat) |>.mpr <| by exact fun n => ⟨Heap.core_empty.dist, .rfl⟩ @[simp] theorem op_data (x y : DynReservationMap A H) : (x • y).data = x.data • y.data := rfl @@ -326,7 +328,7 @@ theorem included {x y : DynReservationMap A H} : refine ⟨fun ⟨z, hz⟩ => ⟨⟨z.data, congrArg (·.data) hz⟩, ⟨z.token, congrArg (·.token) hz⟩⟩, ?_⟩ exact fun ⟨⟨z₁, hz₁⟩, ⟨z₂, hz₂⟩⟩ => - ⟨mk z₁ z₂, eq_dist.mpr (by exact fun n => ⟨hz₁.dist, hz₂.dist⟩)⟩ + ⟨mk z₁ z₂, eq_dist (SI := Nat) |>.mpr (by exact fun n => ⟨hz₁.dist, hz₂.dist⟩)⟩ @[rocq_alias dyn_reservation_map_data_proj_validN] theorem data_proj_validN {n} {x : DynReservationMap A H} (h : ✓{n} x) : ✓{n} x.data := @@ -353,7 +355,7 @@ theorem split_validN {x : DynReservationMap A H} (vx : ✓{n} x) : | error => exact (not_validN_invalid (S := CoPset) (validN_token_of_validN vx)).elim | valid t => refine ⟨xd, t, ?_⟩ - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr refine fun m => ⟨?_, ?_⟩ · exact (show xd = xd • (∅ : H A) from Algebra.MonoidOps.op_right_id.symm).dist · exact (pcore_op_left' rfl).symm.dist @@ -382,7 +384,7 @@ theorem valid_token {e : CoPset} : @[rocq_alias dyn_reservation_map_data_op] theorem mkData_op k (a b : A) : mkData (H := H) k (a • b) = mkData (H := H) k a • mkData k b := by - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr refine fun _ => ⟨(fun i => Dist.of_eq (Heap.singleton_op_singleton i).symm), Dist.of_eq (pcore_op_right_L rfl).symm⟩ @@ -401,7 +403,7 @@ instance {d : IsOp.Direction} {a b₁ b₂ : A} [hv : IsOp d a b₁ b₂] : @[rocq_alias dyn_reservation_map_token_union] theorem token_union {e₁ e₂} (he : e₁ ## e₂) : mkToken (H := H) (A := A) (e₁ ∪ e₂) = mkToken (H := H) (A := A) e₁ • mkToken e₂ := by - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr refine fun n => ⟨fun i => ?_, ?_⟩ · simpa only [mkToken, get?_empty, op_data, Heap.get?_op] using .rfl · simp [mkToken, CMRA.op, he] @@ -504,7 +506,7 @@ theorem alloc {e k} {a : A} (hke : k ∈ e) (va : ✓ a) : validN_op_left ((assoc' (α := DynReservationMap A H)) ▸ vedt)) change ✓{n} mkData k a • z rw [ze, assoc', ← (show mk ({[k := a]} • d) ∅ = mkData k a • mk d ∅ from - OFE.eq_dist.mpr <| by exact fun n => ⟨.rfl, Dist.of_eq (pcore_op_right_L rfl).symm⟩)] + OFE.eq_dist (SI := Nat) |>.mpr <| by exact fun n => ⟨.rfl, Dist.of_eq (pcore_op_right_L rfl).symm⟩)] refine validN_data_op_token ?_ (infinite_data_op_token vdt) ?_ · refine validN_data_of_validN <| valid_mkData_op_data_of_valid_op? ?_ ?_ · exact validN_data_of_validN @@ -537,7 +539,7 @@ theorem updateP {P} {Q : DynReservationMap A H → Prop} k a (ap : a ~~>: P) refine ⟨mkData k y, apq y py, ?_⟩ simp only [CMRA.op?] at vaz ⊢ rw [ze, assoc', ← (show mk ({[k := y]} • d) ∅ = mkData k y • mk d ∅ from - OFE.eq_dist.mpr <| by exact fun n => ⟨.rfl, Dist.of_eq (pcore_op_right_L rfl).symm⟩)] + OFE.eq_dist (SI := Nat) |>.mpr <| by exact fun n => ⟨.rfl, Dist.of_eq (pcore_op_right_L rfl).symm⟩)] refine validN_data_op_token ?_ (infinite_data_op_token vdt) ?_ · exact validN_data_of_validN <| valid_mkData_op_data_of_valid_op? (validN_data_of_validN (validN_op_left vdt)) vy @@ -582,7 +584,7 @@ theorem reserve (Q : DynReservationMap A H → Prop) ∀ i, get? mf i = none ∨ i ∉ Ef := by match mz with | none => - exact ⟨∅, ∅, OFE.eq_dist.mpr (by exact fun n => + exact ⟨∅, ∅, OFE.eq_dist (SI := Nat) |>.mpr (by exact fun n => ⟨(CMRA.unit_left_id_dist (∅ : H A)).symm, Dist.of_eq (pcore_op_left_L rfl).symm⟩), Heap.valid_empty.validN, top_infinite, fun i => .inl (get?_empty i)⟩ diff --git a/Iris/Iris/Algebra/Excl.lean b/Iris/Iris/Algebra/Excl.lean index e59b81e09..e61523746 100644 --- a/Iris/Iris/Algebra/Excl.lean +++ b/Iris/Iris/Algebra/Excl.lean @@ -10,6 +10,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris section excl @@ -26,12 +28,12 @@ open OFE #rocq_ignore excl_equiv "OFE is Leibniz; use equality" -@[simp, rocq_alias excl_dist] protected def Dist [OFE Nat α] (n : Nat) : Excl α → Excl α → Prop +@[simp, rocq_alias excl_dist] protected def Dist [OFE α] (n : Nat) : Excl α → Excl α → Prop | excl a, excl b => a ≡{n}≡ b | invalid, invalid => True | _, _ => False -theorem dist_eqv [OFE Nat α] {n} : Equivalence (Excl.Dist (α := α) n) where +theorem dist_eqv [OFE α] {n} : Equivalence (Excl.Dist (α := α) n) where refl {x} := by cases x with | excl a => exact Dist.of_eq rfl @@ -46,21 +48,21 @@ theorem dist_eqv [OFE Nat α] {n} : Equivalence (Excl.Dist (α := α) n) where #rocq_ignore excl_ofe_mixin "Not needed" @[rocq_alias exclO] -instance [OFE Nat α] : OFE Nat (Excl α) where +instance [OFE α] : OFE (Excl α) where Dist := Excl.Dist dist_eqv eq_dist {x y} := by - cases x <;> cases y <;> simp [Excl.Dist, eq_dist] + cases x <;> cases y <;> simp [Excl.Dist, eq_dist (SI := Nat)] dist_lt {n x y m} hn hlt := by cases x <;> cases y <;> simp at * exact Dist.lt hn hlt @[rocq_alias Excl_ne] -instance [OFE Nat α] : NonExpansive excl (α := α) where +instance [OFE α] : NonExpansive excl (α := α) where ne _ _ _ a := a /-- Note: Not an instance, due to instance coherence problems. -/ -theorem ne_match [OFE Nat α] {B : Type _} [OFE Nat B] +theorem ne_match [OFE α] {B : Type _} [OFE 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 +73,7 @@ theorem ne_match [OFE Nat α] {B : Type _} [OFE Nat B] | .invalid, .invalid, _ => Dist.rfl⟩ @[rocq_alias excl_ofe_discrete] -instance [OFE Nat α] [Discrete α] : Discrete (Excl α) where +instance [OFE α] [Discrete α] : Discrete (Excl α) where discrete_0 {x y} h' := by cases x <;> cases y · exact congrArg excl (discrete_0 (α := α) h') @@ -82,14 +84,14 @@ instance [OFE Nat α] [Discrete α] : Discrete (Excl α) where #rocq_ignore excl_leibniz "Not needed" @[rocq_alias Excl_discrete] -instance [OFE Nat α] {a : α} [h : DiscreteE a] : DiscreteE (excl a) where +instance [OFE α] {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 Nat α] : DiscreteE (@invalid α) where +instance [OFE α] : DiscreteE (@invalid α) where discrete {x} h := by cases x · exact h.elim @@ -106,13 +108,13 @@ instance [OFE Nat α] : DiscreteE (@invalid α) where | excl a => excl (f a) | invalid => invalid -def exclChain [OFE Nat α] (c : Chain (Excl α)) (a : α) : Chain α := by +def exclChain [OFE α] (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 Nat α] [IsCOFE Nat α] : IsCOFE Nat (Excl α) where +instance [OFE α] [IsCOFE α] : IsCOFE (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 @@ -135,7 +137,7 @@ instance [OFE Nat α] [IsCOFE Nat α] : IsCOFE Nat (Excl α) where #rocq_ignore excl_cmra_mixin "Not needed" @[rocq_alias exclR] -instance [OFE Nat α] : CMRA (Excl α) where +instance [OFE α] : CMRA (Excl α) where pcore _ := none op _ _ := invalid ValidN _ := Valid @@ -157,7 +159,7 @@ instance [OFE Nat α] : CMRA (Excl α) where extend {n x y₁ y₂} h₁ h₂ := by cases x <;> trivial @[rocq_alias excl_included] -theorem inc_iff [OFE Nat α] {x y : Excl α} : x ≼ y ↔ y = invalid := by +theorem inc_iff [OFE α] {x y : Excl α} : x ≼ y ↔ y = invalid := by constructor · rintro ⟨z, hz⟩ exact hz @@ -165,31 +167,31 @@ theorem inc_iff [OFE Nat α] {x y : Excl α} : x ≼ y ↔ y = invalid := by exact ⟨invalid, h⟩ @[rocq_alias excl_includedN] -theorem incN_iff [OFE Nat α] {x y : Excl α} (n) : x ≼{n} y ↔ y = invalid := by +theorem incN_iff [OFE α] {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 Nat α] {a b : α} (h : (some (excl a) : Option (Excl α)) = some (excl b)) : +theorem excl_inj [OFE α] {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 Nat α] {a b : α} {n} +theorem excl_dist_inj [OFE α] {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 Nat α] {a b : α} : +theorem excl_included [OFE α] {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⟩⟩ rcases z with _|z · exact (excl_inj hz).symm - · exact (hz.dist (n := 0)).elim + · exact (hz.dist (SI := Nat) (n := 0)).elim @[rocq_alias Excl_includedN] -theorem excl_includedN [OFE Nat α] {a b : α} {n} : +theorem excl_includedN [OFE α] {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 @@ -197,28 +199,28 @@ theorem excl_includedN [OFE Nat α] {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 Nat α] {n} {mx : Option (Excl α)} {a : α} +theorem validN_inv_some_l [OFE α] {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 Nat α] {n} {mx : Option (Excl α)} {a : α} +theorem validN_inv_some_r [OFE α] {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 Nat α] {x : Excl α} : CMRA.Exclusive x where exclusive0_l := fun _ a => a +instance [OFE α] {x : Excl α} : CMRA.Exclusive x where exclusive0_l := fun _ a => a @[rocq_alias excl_cmra_discrete] -instance [OFE Nat α] [OFE.Discrete α] : CMRA.Discrete (Excl α) where +instance [OFE α] [OFE.Discrete α] : CMRA.Discrete (Excl α) where discrete_valid a := a @[rocq_alias ExclInvalid_included] -theorem invalid_inc [OFE Nat α] (ea : Excl α) : ea ≼ invalid := by exists invalid +theorem invalid_inc [OFE α] (ea : Excl α) : ea ≼ invalid := by exists invalid /-! ## Functors -/ @[rocq_alias excl_map_id] @@ -231,11 +233,11 @@ theorem map_comp (f : α → β) (g : β → γ) : cases x <;> simp @[rocq_alias excl_map_ext] -theorem map_ext [OFE Nat α] [OFE Nat β] (f g : α → β) (h : ∀ x, f x = g x) : map f x = map g x := by +theorem map_ext [OFE α] [OFE β] (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 Nat α] [OFE Nat β] (f : α -n> β) : NonExpansive (map f) where +theorem map_ne [OFE α] [OFE β] (f : α -n> β) : NonExpansive (map f) where ne n x₁ x₂ h := by cases x₁ <;> cases x₂ <;> try trivial have ⟨hne⟩ := f.ne @@ -244,17 +246,17 @@ theorem map_ne [OFE Nat α] [OFE Nat β] (f : α -n> β) : NonExpansive (map f) #rocq_ignore Excl_proper "Derivable from NonExpansive.eqv" @[rocq_alias excl_map_cmra_morphism] -def hom [OFE Nat α] [OFE Nat β] (f : α -n> β) : Excl α -C> Excl β := by +def hom [OFE α] [OFE β] (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 Nat α] [OFE Nat β] (f : α -n> β) : Excl α -n> Excl β := ⟨map f, map_ne f⟩ +def oMap [OFE α] [OFE β] (f : α -n> β) : Excl α -n> Excl β := ⟨map f, map_ne f⟩ @[rocq_alias exclO_map_ne] -instance oMap_ne [OFE Nat α] [OFE Nat β] : NonExpansive (oMap (α := α) (β := β)) where +instance oMap_ne [OFE α] [OFE β] : NonExpansive (oMap (α := α) (β := β)) where ne _ _ _ h x := by cases x with | excl _ => exact h _ | invalid => exact .rfl diff --git a/Iris/Iris/Algebra/Frac.lean b/Iris/Iris/Algebra/Frac.lean index e842a183d..17f99d37b 100644 --- a/Iris/Iris/Algebra/Frac.lean +++ b/Iris/Iris/Algebra/Frac.lean @@ -19,6 +19,8 @@ This version follows Iris Rocq in fixing the underlying type of fractions to be @[expose] public section +local stepindex Nat + namespace Rat /-- ## Helper lemmas for Rat -/ @@ -62,7 +64,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 Nat Qp := COFE.ofDiscrete _ +instance instCOFEQp : COFE Qp := COFE.ofDiscrete _ instance instCMRAQp : CMRA Qp where pcore _ := none diff --git a/Iris/Iris/Algebra/Functions.lean b/Iris/Iris/Algebra/Functions.lean index a69901757..b6717f179 100644 --- a/Iris/Iris/Algebra/Functions.lean +++ b/Iris/Iris/Algebra/Functions.lean @@ -10,6 +10,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris open OFE CMRA @@ -49,7 +51,7 @@ end insert section OFE -variable {ι : Type _} [DecidableEq ι] {β : ι → Type _} [∀ i, OFE Nat (β i)] +variable {ι : Type _} [DecidableEq ι] {β : ι → Type _} [∀ i, OFE (β i)] @[rocq_alias discrete_funO_ofe_discrete] instance instDiscreteFunOfeDiscrete [∀ i, OFE.Discrete (β i)] : diff --git a/Iris/Iris/Algebra/GenMap.lean b/Iris/Iris/Algebra/GenMap.lean index b54657064..29edfabbf 100644 --- a/Iris/Iris/Algebra/GenMap.lean +++ b/Iris/Iris/Algebra/GenMap.lean @@ -11,6 +11,8 @@ public import Iris.Algebra.Updates @[expose] public section +local stepindex Nat + namespace Iris open OFE @@ -89,9 +91,9 @@ def IsFree {β : α → Type _} (f : (a : α) → Option (β a)) : α → Prop : /-! ## OFE -/ section OFE -variable (β : Type _) [OFE Nat β] +variable (β : Type _) [OFE β] -instance instOFE_GenMap : OFE Nat (GenMap β) where +instance instOFE_GenMap : OFE (GenMap β) where Dist n := (·.car ≡{n}≡ ·.car) dist_eqv.refl _ := Dist.of_eq rfl dist_eqv.symm := Dist.symm @@ -104,9 +106,9 @@ instance instOFE_GenMap : OFE Nat (GenMap β) where dist_lt := Dist.lt end OFE -theorem GenMap.singleton_discreteE {v : β} [OFE Nat β] [DiscreteE v] : +theorem GenMap.singleton_discreteE {v : β} [OFE β] [DiscreteE v] : DiscreteE (GenMap.singleton (β := β) k v) where - discrete {y} H := OFE.eq_dist.mpr <| by + discrete {y} H := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n γ' specialize H γ' simp only [GenMap.singleton, GenMap.alter, GenMap.empty, Iris.alter] at H ⊢ @@ -114,8 +116,8 @@ theorem GenMap.singleton_discreteE {v : β} [OFE Nat β] [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 Nat β] : DiscreteE (GenMap.empty (β := β)) where - discrete {y} H := OFE.eq_dist.mpr <| by +theorem GenMap.empty_discreteE [OFE β] : DiscreteE (GenMap.empty (β := β)) where + discrete {y} H := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n γ' specialize H γ' simp only [GenMap.empty] at H ⊢ @@ -190,22 +192,22 @@ instance instCMRA_GenMap : CMRA (GenMap β) where ⟨fun Hv n => Hv.validN, fun H => valid_iff_validN.mpr (H ·)⟩ validN_succ {x n} := validN_succ validN_op_left {n x y} := validN_op_left - assoc {x y z} := OFE.eq_dist.mpr fun _ a => by + assoc {x y z} := OFE.eq_dist (SI := Nat) |>.mpr fun _ a => by cases _ : x.car a <;> cases _ : y.car a <;> cases _ : z.car a <;> simp_all [op, optionOp] exact assoc.dist - comm {x y} := OFE.eq_dist.mpr fun _ a => by + comm {x y} := OFE.eq_dist (SI := Nat) |>.mpr fun _ a => by cases _ : x.car a <;> cases _ : y.car a <;> simp_all [op, optionOp] exact comm.dist - pcore_op_left {x cx} H := OFE.eq_dist.mpr <| by + pcore_op_left {x cx} H := OFE.eq_dist (SI := Nat) |>.mpr <| by have hcx : cx.car = fun k => CMRA.core (x.car k) := by simp [pcore_genmap] at H; exact (congrArg GenMap.car H).symm intro n k have H : cx.car k = CMRA.core (x.car k) := congrFun hcx k simp only [CMRA.op, optionOp, H] exact (core_op (x.car k)).dist - pcore_idem {x cx} H := OFE.eq_dist.mpr <| by + pcore_idem {x cx} H := OFE.eq_dist (SI := Nat) |>.mpr <| by have hcx : cx.car = fun k => CMRA.core (x.car k) := by simp [pcore_genmap] at H; exact (congrArg GenMap.car H).symm simp only [pcore_genmap] @@ -218,7 +220,7 @@ instance instCMRA_GenMap : CMRA (GenMap β) where simp [pcore_genmap] at H; exact (congrArg GenMap.car H).symm have hpc_fun : CMRA.pcore x.car = some cx.car := by rw [hcx]; rfl obtain ⟨cy, Hcy⟩ := pcore_op_mono hpc_fun y.car - refine ⟨⟨cy, ?_⟩, OFE.eq_dist.mpr ?_⟩ + refine ⟨⟨cy, ?_⟩, OFE.eq_dist (SI := Nat) |>.mpr ?_⟩ · obtain ⟨N, hN⟩ := op_bound β x y refine ⟨N, fun k hk => ?_⟩ have hxyk := hN k hk @@ -226,7 +228,7 @@ instance instCMRA_GenMap : CMRA (GenMap β) where cases hx : x.car k <;> cases hy : y.car k <;> simp_all have hcxy : CMRA.core (x.car • y.car) k = none := by simp [CMRA.core, CMRA.pcore, optionCore, hx, hy, CMRA.op, optionOp] - have hHeqk := (OFE.eq_dist.mp Hcy) 0 k + have hHeqk := (OFE.eq_dist (SI := Nat) |>.mp Hcy) 0 k simp only [CMRA.core, CMRA.pcore, optionCore, CMRA.op, optionOp, hx, hy, Option.bind] at hHeqk cases hcy : cy k <;> simp_all @@ -239,15 +241,15 @@ instance instCMRA_GenMap : CMRA (GenMap β) where have eb := extend_bound β Hv H let F k := CMRA.extend (Hv k) (H k) exact ⟨⟨fun k => (F k).1, eb.1⟩, ⟨fun k => (F k).2.1, eb.2⟩, - OFE.eq_dist.mpr fun _ k => ((F k).2.2.1).dist, fun k => (F k).2.2.2.1, fun k => (F k).2.2.2.2⟩ + OFE.eq_dist (SI := Nat) |>.mpr fun _ k => ((F k).2.2.1).dist, fun k => (F k).2.2.2.1, fun k => (F k).2.2.2.2⟩ instance instUCMRA_GenMap : UCMRA (GenMap β) where unit := GenMap.empty unit_valid _ := trivial - unit_left_id {x} := OFE.eq_dist.mpr fun _ k => by + unit_left_id {x} := OFE.eq_dist (SI := Nat) |>.mpr fun _ k => by simp only [CMRA.op, optionOp, empty] cases x.car k <;> simp - pcore_unit := OFE.eq_dist.mpr fun _ => by + pcore_unit := OFE.eq_dist (SI := Nat) |>.mpr fun _ => by refine OFE.some_dist_some.mpr fun k => ?_ simp [empty, CMRA.core, CMRA.pcore, optionCore] @@ -291,7 +293,7 @@ theorem GenMap.validN_singleton_map_in (x : Nat) (y : β) (n : Nat) : theorem GenMap.op_singleton_comm {mf : GenMap β} {x : Nat} (y : β) (H_free : IsFree mf.car x) : GenMap.singleton x y • mf = mf.alter x (some y) := by - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr intro n k simp only [IsFree] at H_free by_cases heq : k = x @@ -325,7 +327,7 @@ open COFE CMRA abbrev GenMapOF (F : OFunctorPre Nat) : OFunctorPre Nat := fun A B _ _ => GenMap (F A B) -abbrev GenMap.lift [OFE Nat α] [OFE Nat β] (f : α -n> β) : GenMap α -n> GenMap β where +abbrev GenMap.lift [OFE α] [OFE β] (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]⟩⟩ @@ -343,11 +345,11 @@ instance instOFunctor_GenMapOF (F : OFunctorPre Nat) [OFunctor Nat F] : simp only [OFE.Dist, Option.Forall₂, Option.map] cases _ : k.car γ <;> simp exact OFunctor.map_ne.ne Hx Hy _ - map_id {α β _ _} x := OFE.eq_dist.mpr <| by + map_id {α β _ _} x := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ γ simp only [Option.map]; cases _ : x.car γ <;> simp exact (OFunctor.map_id _).dist - map_comp _ _ _ _ x := OFE.eq_dist.mpr <| by + map_comp _ _ _ _ x := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ γ simp only [Option.map]; cases _ : x.car γ <;> simp exact (OFunctor.map_comp _ _ _ _ _).dist @@ -366,7 +368,7 @@ instance instURFunctor_GenMapOF (F : COFE.OFunctorPre Nat) [RFunctor F] : have hv' := hv z simp only [h, CMRA.ValidN, optionValidN] at hv' exact Hvalid hv' - pcore x := OFE.eq_dist.mpr <| by + pcore x := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ γ have Hcore := @(URFunctor.map (F := OptionOF F) f g).pcore (x.car γ) simp only [CMRA.pcore, optionCore, Option.bind, Option.map, URFunctor.map, @@ -377,7 +379,7 @@ instance instURFunctor_GenMapOF (F : COFE.OFunctorPre Nat) [RFunctor F] : revert Hcore cases h' : pcore v <;> cases h'' : pcore ((OFunctor.map f g).f v) <;> simp_all <;> exact (·.dist) - op z x := OFE.eq_dist.mpr <| by + op z x := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ γ have Hop := @(URFunctor.map (F := OptionOF F) f g).op (z.car γ) (x.car γ) simp only [Option.map, CMRA.op, optionOp, URFunctor.map] at Hop ⊢ diff --git a/Iris/Iris/Algebra/Heap.lean b/Iris/Iris/Algebra/Heap.lean index 9a17004fe..59b3c2822 100644 --- a/Iris/Iris/Algebra/Heap.lean +++ b/Iris/Iris/Algebra/Heap.lean @@ -12,6 +12,8 @@ public import Iris.Std.PartialMap @[expose] public section +local stepindex Nat + open Iris Std section OFE @@ -20,49 +22,49 @@ open OFE namespace PartialMap -instance instOFE [LawfulPartialMap M K] [OFE Nat V] : OFE Nat (M V) where +instance instOFE [LawfulPartialMap M K] [OFE V] : OFE (M V) where Dist n s0 s1 := get? s0 ≡{n}≡ get? s1 - dist_eqv := ⟨fun _ => .of_eq rfl, (·.symm), (·.trans ·)⟩ + dist_eqv := ⟨fun _ => .of_eq rfl, (·.symm), (·.trans ·)⟩ eq_dist {s0 s1} := by rw [← LawfulPartialMap.equiv_iff_eq] 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 + dist_lt := dist_lt -@[simp] def toMap [LawfulPartialMap M K] [OFE Nat V] : (M V) -n> (K → Option V) where +@[simp] def toMap [LawfulPartialMap M K] [OFE 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 Nat V] : (K → Option V) -n> (M V) where +@[simp] def ofMap [LawfulPartialMap M K] [R : RepFunMap M K] [OFE 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 Nat V] (k : K) : NonExpansive (get? · k : M V → Option V) where +instance get?_ne [LawfulPartialMap M K] [OFE V] (k : K) : NonExpansive (get? · k : M V → Option V) where ne {_ _ _} Ht := Ht k -instance [LawfulPartialMap M K] [OFE Nat V] (k : K) : NonExpansive₂ (insert · k · : M V → V → M V) where +instance [LawfulPartialMap M K] [OFE 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 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) +theorem eqv_of_Equiv [OFE V] [LawfulPartialMap M K] {t1 t2 : M V} (H : PartialMap.equiv t1 t2) : t1 = t2 := + eq_dist (SI := Nat) |>.mpr fun _ k => Dist.of_eq (H k) -instance [LawfulPartialMap M K] [OFE Nat V] (op : K → V → V → V) [∀ k, NonExpansive₂ (op k)] : +instance [LawfulPartialMap M K] [OFE 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 Nat V] (k : K) (c : Chain (M V)) : Chain (Option V) where +def chain [LawfulPartialMap M K] [OFE 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 Nat V] (k : K) (c : Chain (M V)) : +theorem chain_get [LawfulPartialMap M K] [OFE 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 Nat V] : COFE Nat (M V) where +instance Heap.instCOFE [LawfulPartialMap M K] [COFE V] : COFE (M V) where compl c := bindAlter (fun _ => COFE.compl <| c.map ⟨_, PartialMap.get?_ne ·⟩) (c 0) conv_compl {_ c} k := by rw [get?_bindAlter] @@ -73,14 +75,14 @@ instance Heap.instCOFE [LawfulPartialMap M K] [COFE Nat V] : COFE Nat (M V) wher 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 +instance instDiscreteHeap [LawfulPartialMap M K] [OFE V] [Discrete V] : Discrete (M V) where + discrete_0 h := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ k exact (Discrete.discrete_0 (h k)).dist -instance instDiscreteESingleton [LawfulPartialMap M K] [DecidableEq K] [OFE Nat V] {v : V} +instance instDiscreteESingleton [LawfulPartialMap M K] [DecidableEq K] [OFE V] {v : V} [ha : DiscreteE v] {k : K} : DiscreteE (PartialMap.singleton (M := M) k v) where - discrete {y} h := OFE.eq_dist.mpr <| by + discrete {y} h := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n k' by_cases hh : k = k' · simp only [LawfulPartialMap.get?_singleton, hh, ↓reduceIte] @@ -90,14 +92,14 @@ instance instDiscreteESingleton [LawfulPartialMap M K] [DecidableEq K] [OFE Nat refine (Option.none_is_discrete.discrete (.trans ?_ (h k'))).dist simp [LawfulPartialMap.get?_singleton, hh, ↓reduceIte] -instance instDiscreteEEmpty [LawfulPartialMap M K] [OFE Nat V] : DiscreteE (∅ : M V) where - discrete {y} h := OFE.eq_dist.mpr <| by +instance instDiscreteEEmpty [LawfulPartialMap M K] [OFE V] : DiscreteE (∅ : M V) where + discrete {y} h := OFE.eq_dist (SI := Nat) |>.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 Nat V] {n : Nat} {x y : V} +theorem singleton_dist [LawfulPartialMap M K] [DecidableEq K] [OFE 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] @@ -147,7 +149,7 @@ theorem lookup_inc {m1 m2 : M V} : cases get? m1 i <;> cases get? z i <;> simp · obtain ⟨f, Hf⟩ := Classical.axiomOfChoice H exists bindAlter (fun k _ => f k) m2 - refine OFE.eq_dist.mpr fun n i => ((Hf i).trans ?_).dist + refine OFE.eq_dist (SI := Nat) |>.mpr fun n i => ((Hf i).trans ?_).dist specialize Hf i; revert Hf simp [CMRA.op, optionOp, get?_merge, get?_bindAlter] cases get? m2 i <;> cases get? m1 i <;> cases f i <;> simp <;> @@ -182,15 +184,15 @@ instance instStoreCMRA : CMRA (M V) where specialize H k; revert H simp only [op, get?_merge, Option.merge] cases get? x1 k <;> cases get? x2 k <;> simp [optionOp, CMRA.op] - assoc {x y z} := eq_dist.mpr fun _ k => by + assoc {x y z} := eq_dist (SI := Nat) |>.mpr fun _ k => by simp only [op, get?_merge] cases get? x k <;> cases get? y k <;> cases get? z k <;> simp exact assoc.dist - comm {x y} := eq_dist.mpr fun _ k => by + comm {x y} := eq_dist (SI := Nat) |>.mpr fun _ k => by simp [op, get?_merge] cases get? x k <;> cases get? y k <;> simp exact comm.dist - pcore_op_left {x cx} H := eq_dist.mpr fun _ k => by + pcore_op_left {x cx} H := eq_dist (SI := Nat) |>.mpr fun _ k => by simp only [← Option.getD_some (a := cx) (b := cx), op, get?_merge] cases Hcx : get? cx k <;> cases hx : get? x k <;> simp <;> @@ -199,7 +201,7 @@ instance instStoreCMRA : CMRA (M V) where cases Hcx · refine (pcore_op_left ?_).dist simp [← Hcx, ← H, get?_bindAlter, hx] - pcore_idem {x cx} H := eq_dist.mpr <| by + pcore_idem {x cx} H := eq_dist (SI := Nat) |>.mpr <| by simp only [pcore, Option.some.injEq] at H simp only [pcore, ← H] intro n k @@ -215,10 +217,10 @@ instance instStoreCMRA : CMRA (M V) where simp only [pcore, Option.some.injEq, op, exists_eq_left'] rcases this with ⟨z', Hz'⟩ exists z' - refine Hz'.trans (OFE.eq_dist.mpr fun n i => ?_) + refine Hz'.trans (OFE.eq_dist (SI := Nat) |>.mpr fun n i => ?_) cases get? z' i <;> cases get? x i <;> simp_all refine lookup_inc.mpr (fun i => ?_) - obtain ⟨v', Hv'⟩ : (core (get? x i)) ≼ (core (get? y i)) := by + obtain ⟨v', Hv'⟩ : (core (get? x i)) ≼ (core (get? y i)) := by apply core_mono exists get? z i have Hz := congrArg (get? · i) Hz; revert Hz @@ -235,7 +237,7 @@ instance instStoreCMRA : CMRA (M V) where exists bindAlter (fun k (_ : V) => extendF k |>.fst) y1 exists bindAlter (fun k (_ : V) => extendF k |>.snd.fst) y2 simp [op] - refine ⟨eq_dist.mpr fun _ i => ?_, fun i => ?_, fun i => ?_⟩ + refine ⟨eq_dist (SI := Nat) |>.mpr fun _ i => ?_, fun i => ?_, fun i => ?_⟩ all_goals rcases hF : extendF i with ⟨z1, z2, Hm, Hz1, Hz2⟩ · refine Hm.dist.trans ?_ simp [get?_merge, CMRA.op, optionOp, Option.merge, get?_bindAlter] @@ -261,8 +263,8 @@ instance instStoreCMRA : CMRA (M V) where instance instStoreUCMRA : UCMRA (M V) where unit := unit unit_valid := by simp [CMRA.Valid, get?_empty] - unit_left_id := OFE.eq_dist.mpr fun _ k => by simp [CMRA.op, get?_merge, get?_empty] - pcore_unit := OFE.eq_dist.mpr fun _ => by + unit_left_id := OFE.eq_dist (SI := Nat) |>.mpr fun _ k => by simp [CMRA.op, get?_merge, get?_empty] + pcore_unit := OFE.eq_dist (SI := Nat) |>.mpr fun _ => by refine OFE.some_dist_some.mpr fun k => ?_ simp [get?_bindAlter, get?_empty] @@ -348,7 +350,7 @@ theorem insert_eq_singleton_op_singleton [IsoFunMap M K] {m : M V} (Hemp : get? insert m i x = singleton i x • m := IsoFunMap.ext (insert_equiv_singleton_op_singleton Hemp) -theorem core_empty : core (∅ : M V) = ∅ := OFE.eq_dist.mpr <| by +theorem core_empty : core (∅ : M V) = ∅ := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n k simp [core, CMRA.pcore, get?_empty, get?_bindAlter] @@ -360,12 +362,12 @@ theorem core_singleton_equiv {i : K} {x : V} {cx : V} (Hpcore : CMRA.pcore x = s split <;> rfl theorem singleton_core_eq [IsoFunMap M K] {i : K} {x : V} {cx} (Hpcore : CMRA.pcore x = some cx) : - core (singleton i x : M V) = singleton i cx := + core (singleton i x : M V) = singleton i cx := IsoFunMap.ext (core_singleton_equiv Hpcore) open Classical in theorem singleton_core_eqv {i : K} {x : V} {cx} (Hpcore : CMRA.pcore x = some cx) : - core (singleton i x : M V) = singleton i cx := OFE.eq_dist.mpr <| by + core (singleton i x : M V) = singleton i cx := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n k simp [core, CMRA.pcore, get?_singleton, get?_bindAlter] split <;> first | exact Hpcore.dist | trivial @@ -390,7 +392,7 @@ theorem singleton_op_singleton_eq [IsoFunMap M K] {i : K} {x y : V} : IsoFunMap.ext singleton_op_singleton instance {m : M V} [I : ∀ x : V, CoreId x] : CoreId m where - core_id := OFE.eq_dist.mpr fun _ => by + core_id := OFE.eq_dist (SI := Nat) |>.mpr fun _ => by refine OFE.some_dist_some.mpr fun k => ?_ rw [get?_bindAlter] cases get? m k <;> simp @@ -398,7 +400,7 @@ instance {m : M V} [I : ∀ x : V, CoreId x] : CoreId m where open Classical in instance [CoreId (x : V)] : CoreId (singleton i x : M V) where - core_id := OFE.eq_dist.mpr fun _ => by + core_id := OFE.eq_dist (SI := Nat) |>.mpr fun _ => by refine OFE.some_dist_some.mpr fun k => ?_ simp [get?_bindAlter, get?_singleton] split <;> simp @@ -449,7 +451,7 @@ theorem singleton_inc_iff {m : M V} : exists v · cases z · exists (PartialMap.delete m i) - refine OFE.eq_dist.mpr fun _ j => ?_ + refine OFE.eq_dist (SI := Nat) |>.mpr fun _ j => ?_ simp [CMRA.op, get?_merge, get?_singleton, get?_delete] split · rename_i h @@ -459,7 +461,7 @@ theorem singleton_inc_iff {m : M V} : · simp · rename_i z exists (PartialMap.insert m i z) - refine OFE.eq_dist.mpr fun _ j => ?_ + refine OFE.eq_dist (SI := Nat) |>.mpr fun _ j => ?_ simp [CMRA.op, get?_merge, get?_singleton, get?_insert] split · rename_i h @@ -563,7 +565,7 @@ theorem inc_dom_inc {m1 m2 : M V} (Hinc : m1 ≼ m2) : Set.Included (dom m1) (do exact fun h => (OFE.not_none_eqv_some h).elim nonrec instance [HD : CMRA.Discrete V] [LawfulPartialMap M K] : Discrete (M V) where - discrete_0 {_ _} H := OFE.eq_dist.mpr fun _ k => (OFE.Discrete.discrete_0 (H k)).dist + discrete_0 {_ _} H := OFE.eq_dist (SI := Nat) |>.mpr fun _ k => (OFE.Discrete.discrete_0 (H k)).dist discrete_valid {_} := (CMRA.Discrete.discrete_valid <| · ·) end Heap @@ -576,31 +578,31 @@ namespace PartialMap def map (f : α → β) : H α → H β := PartialMap.bindAlter (fun _ a => some <| f a) -instance [OFE Nat α] [OFE Nat β] {f : α → β} [hne : OFE.NonExpansive f] : OFE.NonExpansive (map H f) where +instance [OFE α] [OFE β] {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 Nat α] (a : H α) : - PartialMap.map H id a = a := OFE.eq_dist.mpr <| by +theorem map_id [OFE α] (a : H α) : + PartialMap.map H id a = a := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n x simp [PartialMap.map, get?_bindAlter, Option.bind] rcases get? a x <;> simp -def mapO [OFE Nat α] [OFE Nat β] (f : α -n> β) : OFE.Hom (H α) (H β) where +def mapO [OFE α] [OFE β] (f : α -n> β) : OFE.Hom (H α) (H β) where f := map H f ne := inferInstance -theorem map_ne [OFE Nat α] [OFE Nat β] (f g : α -> β) {heq : f ≡{n}≡ g} : map H f m ≡{n}≡ map H g m := by +theorem map_ne [OFE α] [OFE β] (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 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 +theorem map_compose [OFE α] [OFE β] [OFE γ] (f : α -> β) (g : β -> γ) m : + map H (g.comp f) m = map H g (map H f m) := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n k simp [map, get?_bindAlter] cases get? m k <;> simp @@ -615,7 +617,7 @@ def mapC [CMRA α] [CMRA β] (f : α -C> β) : CMRA.Hom (H α) (H β) where rw [get?_bindAlter] cases (get? x k) <;> simp apply CMRA.Hom.validN - pcore m := OFE.eq_dist.mpr <| by + pcore m := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ x simp [map, get?_bindAlter] rcases get? m x with _|v <;> simp @@ -624,7 +626,7 @@ def mapC [CMRA α] [CMRA β] (f : α -C> β) : CMRA.Hom (H α) (H β) where rfl rw [h] exact (CMRA.Hom.pcore f v).dist - op m1 m2 := OFE.eq_dist.mpr <| by + op m1 m2 := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ k simp [CMRA.op, map, get?_bindAlter, get?_merge, Option.merge] cases get? m1 k <;> cases get? m2 k <;> simp @@ -644,7 +646,7 @@ instance {F} [COFE.OFunctor Nat F] : COFE.OFunctor Nat (PartialMapOF H F) where map_id x := by refine .trans ?_ (map_id H x) exact congrArg (map H · x) (funext fun a => COFE.OFunctor.map_id a) - map_comp f g f' g' m := OFE.eq_dist.mpr <| by + map_comp f g f' g' m := OFE.eq_dist (SI := Nat) |>.mpr <| by simp [mapO, map] intro n x simp [get?_bindAlter] @@ -661,7 +663,7 @@ instance {F} [RFunctor F] : URFunctor (PartialMapOF H F) where map_id x := by refine .trans ?_ (map_id H x) exact congrArg (map H · x) (funext fun a => RFunctor.map_id a) - map_comp f g f' g' m := OFE.eq_dist.mpr <| by + map_comp f g f' g' m := OFE.eq_dist (SI := Nat) |>.mpr <| by simp [mapC, map] intro n x simp [get?_bindAlter] diff --git a/Iris/Iris/Algebra/HeapView.lean b/Iris/Iris/Algebra/HeapView.lean index cb53c2edf..2f1ee4c33 100644 --- a/Iris/Iris/Algebra/HeapView.lean +++ b/Iris/Iris/Algebra/HeapView.lean @@ -33,6 +33,8 @@ It provides authoritative and fragmental ownership over heap elements with fract @[expose] public section +local stepindex Nat + open Iris section heapView @@ -143,7 +145,6 @@ 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} @@ -264,7 +265,7 @@ theorem auth_op_frag_valid_total_discrete_iff [IsTotal V] [CMRA.Discrete V] · exact ⟨x.snd, congrArg Prod.snd (some_eqv_some.mp Hx)⟩ theorem auth_op_frag_one_valid_iff : - ✓ Auth dp m1 • Frag k (.own one) v1 ↔ ✓ dp ∧ ✓ v1 ∧ Std.PartialMap.get? m1 k = some v1 := by + ✓ Auth dp m1 • Frag k (.own one) v1 ↔ ✓ dp ∧ ✓ v1 ∧ Std.PartialMap.get? m1 k = some v1 := by refine valid_iff_validN.trans ?_ refine forall_congr' (fun _ => auth_op_frag_one_validN_iff) |>.trans ?_ refine ⟨fun Hv => ?_, ?_⟩ @@ -417,7 +418,7 @@ theorem update_auth_op_frag · simp [get?_insert_ne h] intro Hbf have Hrel' := Hrel j (df, va) - simp only [CMRA.op, Heap.op, get?_merge, get?_singleton_ne h, exists_and_left] at Hrel' + simp only [CMRA.op, Heap.op, get?_merge, get?_singleton_ne h, exists_and_left] at Hrel' refine Hrel' ?_ rw [← Hbf] simp [get?_singleton_ne h] @@ -497,7 +498,7 @@ section heapViewFunctor open Iris.Std PartialMap -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') +theorem heapR_map_eq [COFE A] [COFE B] [COFE A'] [COFE 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 diff --git a/Iris/Iris/Algebra/IProp.lean b/Iris/Iris/Algebra/IProp.lean index 30da51f26..5ba5a5981 100644 --- a/Iris/Iris/Algebra/IProp.lean +++ b/Iris/Iris/Algebra/IProp.lean @@ -14,6 +14,8 @@ public import Init.Data.Vector @[expose] public section +local stepindex Nat + namespace Iris open COFE @@ -64,7 +66,7 @@ variable (GF : BundledGFunctors) def IPre : Type _ := OFunctor.Fix (UPredOF (IResF GF)) @[rocq_alias iProp_solution.iPreProp_cofe] -instance : COFE Nat (IPre GF) := inferInstanceAs (COFE Nat (OFunctor.Fix _)) +instance : COFE (IPre GF) := inferInstanceAs (COFE (OFunctor.Fix (UPredOF (IResF GF)))) @[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/IsOp.lean b/Iris/Iris/Algebra/IsOp.lean index 685fa77ca..5558b2b1a 100644 --- a/Iris/Iris/Algebra/IsOp.lean +++ b/Iris/Iris/Algebra/IsOp.lean @@ -11,6 +11,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris open CMRA ProofMode diff --git a/Iris/Iris/Algebra/LeibnizSet.lean b/Iris/Iris/Algebra/LeibnizSet.lean index 018427e2c..8957a7c07 100644 --- a/Iris/Iris/Algebra/LeibnizSet.lean +++ b/Iris/Iris/Algebra/LeibnizSet.lean @@ -16,6 +16,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + /-! ## Leibniz Set algebras This file defines generic set algebras. This generic construction specializes to both the union and disjoint-union set CMRAs. @@ -29,7 +31,7 @@ inductive DisjointLeibnizSet (S : Type _) where | valid : S → DisjointLeibnizSet S | error : DisjointLeibnizSet S -instance : COFE Nat (DisjointLeibnizSet S) := COFE.ofDiscrete _ +instance : COFE (DisjointLeibnizSet S) := COFE.ofDiscrete _ instance inst_disjointLeibnizSet_DiscreteE {S : Type _} (x : DisjointLeibnizSet S) : DiscreteE x := ⟨fun h => h⟩ @@ -300,7 +302,7 @@ end DisjointLeibnizSet inductive LeibnizSet (S : Type _) where | valid (s : S) -instance : COFE Nat (LeibnizSet S) := COFE.ofDiscrete _ +instance : COFE (LeibnizSet S) := COFE.ofDiscrete _ namespace LeibnizSet diff --git a/Iris/Iris/Algebra/Lib.lean b/Iris/Iris/Algebra/Lib.lean index d1014c6f6..29ed1869c 100644 --- a/Iris/Iris/Algebra/Lib.lean +++ b/Iris/Iris/Algebra/Lib.lean @@ -4,3 +4,5 @@ public import Iris.Algebra.Lib.DFracAgree public import Iris.Algebra.Lib.ExclAuth public import Iris.Algebra.Lib.FracAuth public import Iris.Algebra.Lib.UFracAuth + +local stepindex Nat diff --git a/Iris/Iris/Algebra/Lib/DFracAgree.lean b/Iris/Iris/Algebra/Lib/DFracAgree.lean index 9cb893286..4e7dc56ab 100644 --- a/Iris/Iris/Algebra/Lib/DFracAgree.lean +++ b/Iris/Iris/Algebra/Lib/DFracAgree.lean @@ -18,6 +18,8 @@ convenience definitions and lemmas. @[expose] public section +local stepindex Nat + namespace Iris open OFE CMRA DFrac @@ -25,12 +27,12 @@ open OFE CMRA DFrac namespace DFracAgree @[rocq_alias dfrac_agreeR] -abbrev DFracAgreeR (A : Type _) [OFE Nat A] := DFrac × Agree A +abbrev DFracAgreeR (A : Type _) [OFE A] := DFrac × Agree A @[rocq_alias to_dfrac_agree] -def mk [OFE Nat A] (d : DFrac) (a : A) : DFracAgreeR A := (d, toAgree a) +def mk [OFE A] (d : DFrac) (a : A) : DFracAgreeR A := (d, toAgree a) -variable {A : Type _} [OFE Nat A] +variable {A : Type _} [OFE A] instance mk_discarded_coreId {a : A} : CoreId (mk .discard a) := inferInstanceAs (CoreId (DFrac.discard, toAgree a)) @@ -133,9 +135,9 @@ theorem unpersist {a : A} : namespace Frac @[rocq_alias to_frac_agree] -def mk [OFE Nat A] (q : Qp) (a : A) : DFracAgreeR A := DFracAgree.mk (.own q) a +def mk [OFE A] (q : Qp) (a : A) : DFracAgreeR A := DFracAgree.mk (.own q) a -variable {A : Type _} [OFE Nat A] +variable {A : Type _} [OFE A] @[rocq_alias frac_agree_op] theorem mk_op {q₁ q₂ : Qp} {a : A} : mk (q₁ + q₂) a = mk q₁ a • mk q₂ a := diff --git a/Iris/Iris/Algebra/Lib/ExclAuth.lean b/Iris/Iris/Algebra/Lib/ExclAuth.lean index 01ad2d36f..4ab76b1d7 100644 --- a/Iris/Iris/Algebra/Lib/ExclAuth.lean +++ b/Iris/Iris/Algebra/Lib/ExclAuth.lean @@ -9,6 +9,8 @@ public import Iris.Algebra.Auth public import Iris.Algebra.Excl meta import Iris.Std.RocqPorting +local stepindex Nat + public section /-! @@ -25,7 +27,7 @@ open OFE CMRA Auth Excl Option namespace ExclAuth -variable [OFE Nat A] +variable [OFE A] @[rocq_alias excl_authR] abbrev ExclAuthR := Auth (Option (Excl A)) diff --git a/Iris/Iris/Algebra/Lib/FracAuth.lean b/Iris/Iris/Algebra/Lib/FracAuth.lean index dd3152646..6f5eded4f 100644 --- a/Iris/Iris/Algebra/Lib/FracAuth.lean +++ b/Iris/Iris/Algebra/Lib/FracAuth.lean @@ -10,6 +10,8 @@ public import Iris.Algebra.IsOp import Iris.Algebra.LocalUpdates meta import Iris.Std.RocqPorting +local stepindex Nat + /-! # Fractional Authoritative Camera diff --git a/Iris/Iris/Algebra/Lib/MonoNat.lean b/Iris/Iris/Algebra/Lib/MonoNat.lean index 75163c6e7..4b20594ea 100644 --- a/Iris/Iris/Algebra/Lib/MonoNat.lean +++ b/Iris/Iris/Algebra/Lib/MonoNat.lean @@ -10,6 +10,8 @@ public import Iris.Algebra.Numbers @[expose] public section +local stepindex Nat + namespace Iris open _root_.Std (Associative Commutative LeftIdentity LawfulLeftIdentity) @@ -28,7 +30,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 Nat MaxNat := COFE.ofDiscrete _ +scoped instance : COFE 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/Lib/UFracAuth.lean b/Iris/Iris/Algebra/Lib/UFracAuth.lean index db67a2f9d..56ddade9d 100644 --- a/Iris/Iris/Algebra/Lib/UFracAuth.lean +++ b/Iris/Iris/Algebra/Lib/UFracAuth.lean @@ -22,6 +22,8 @@ fragment's resource to its payload. @[expose] public section +local stepindex Nat + namespace Iris open OFE CMRA UCMRA Auth Option UFrac diff --git a/Iris/Iris/Algebra/LocalUpdates.lean b/Iris/Iris/Algebra/LocalUpdates.lean index 31bf2452a..edc2f18a2 100644 --- a/Iris/Iris/Algebra/LocalUpdates.lean +++ b/Iris/Iris/Algebra/LocalUpdates.lean @@ -10,6 +10,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris @[rocq_alias local_update] @@ -41,7 +43,7 @@ theorem LocalUpdate.op {x y z : α} refine fun n mz vx e => ⟨h n vx, ?_⟩ calc (z • x) ≡{n}≡ z • (y •? mz) := e.op_r - _ ≡{n}≡ (z • y) •? mz := OFE.Dist.symm (CMRA.op_opM_assoc_dist z y mz) + _ ≡{n}≡ (z • y) •? mz := OFE.Dist.symm (CMRA.op_opM_assoc_dist z y mz) @[rocq_alias op_local_update_discrete] theorem LocalUpdate.op_discrete [CMRA.Discrete α] (x y z : α) @@ -58,7 +60,7 @@ theorem LocalUpdate.op_frame (x y x' y' yf : α) exists h1 calc x' ≡{n}≡ y' •? (some yf • mz) := h2 - _ ≡{n}≡ (y' • yf) •? mz := Option.op_some_opM_assoc_dist.symm + _ ≡{n}≡ (y' • yf) •? mz := Option.op_some_opM_assoc_dist.symm @[rocq_alias cancel_local_update] theorem LocalUpdate.cancel (x y z : α) [CMRA.Cancelable x] : (x • y, x • z) ~l~> (y, z) := @@ -68,7 +70,7 @@ theorem LocalUpdate.cancel (x y z : α) [CMRA.Cancelable x] : (x • y, x • z) theorem LocalUpdate.replace (x y : α) [CMRA.IdFree x] (h : ✓ y) : (x, x) ~l~> (y, y) := by intro _ mz vx e match mz with - | none => exact ⟨h.validN, .rfl⟩ + | none => exact ⟨h.validN, .rfl⟩ | some _ => cases CMRA.id_freeN_r vx e.symm @[rocq_alias core_id_local_update] @@ -78,11 +80,11 @@ theorem LocalUpdate.core_id (x y z : α) [CMRA.CoreId y] (inc : y ≼ x) : (x, z match mz with | none => calc y • x ≡{n}≡ y • z := e.op_r - _ ≡{n}≡ z • y := CMRA.op_commN + _ ≡{n}≡ z • y := CMRA.op_commN | some w => calc y • x ≡{n}≡ y • (z • w) := CMRA.op_right_dist y e - _ ≡{n}≡ (y • z) • w := CMRA.op_assocN - _ ≡{n}≡ (z • y) • w := CMRA.op_commN.op_l + _ ≡{n}≡ (y • z) • w := CMRA.op_assocN + _ ≡{n}≡ (z • y) • w := CMRA.op_commN.op_l @[rocq_alias local_update_discrete] theorem LocalUpdate.discrete [CMRA.Discrete α] (x y x' y' : α) : diff --git a/Iris/Iris/Algebra/Monoid.lean b/Iris/Iris/Algebra/Monoid.lean index a73acbd16..42101b697 100644 --- a/Iris/Iris/Algebra/Monoid.lean +++ b/Iris/Iris/Algebra/Monoid.lean @@ -9,6 +9,8 @@ public import Iris.Algebra.OFE public import Iris.Algebra.StepIndexFinite meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.Algebra @@ -24,7 +26,7 @@ open OFE /-- 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 Nat M] (op : M → M → M) (unit : outParam M) where +class MonoidOps {M : Type u} [OFE M] (op : M → M → M) (unit : outParam M) where /-- The operation is non-expansive in both arguments -/ op_ne : NonExpansive₂ op /-- Associativity -/ @@ -41,7 +43,7 @@ namespace MonoidOps attribute [instance] op_ne -variable {M : Type u} [OFE Nat M] {unit : M} {op : M → M → M} +variable {M : Type u} [OFE M] {unit : M} {op : M → M → M} #rocq_ignore monoid_proper "OFE is Leibniz; use equality" @@ -78,7 +80,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 Nat M₁] [OFE Nat M₂] +class WeakMonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE 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 @@ -97,7 +99,7 @@ class WeakMonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE /-- A monoid homomorphism preserves both the operation and the unit. -/ @[rocq_alias MonoidHomomorphism] -class MonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE Nat M₁] [OFE Nat M₂] +class MonoidHomomorphism {M₁ : Type u} {M₂ : Type v} [OFE M₁] [OFE 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 787aae38d..a2a31bdd4 100644 --- a/Iris/Iris/Algebra/Numbers.lean +++ b/Iris/Iris/Algebra/Numbers.lean @@ -21,6 +21,8 @@ There are three variants: @[expose] public section +local stepindex Nat + open Std class IdentityFree (α : Type _) [Add α] where @@ -40,7 +42,7 @@ namespace CommMonoidLike open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA -variable [OFE Nat α] [Discrete α] +variable [OFE α] [OFE.Discrete α] variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))] variable [Zero α] [LawfulLeftIdentity (add (α := α)) zero] variable {x y x' y' : α} @@ -132,7 +134,7 @@ namespace OrdCommMonoidLike open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA IdempotentOp -variable [OFE Nat α] [OFE.Discrete α] +variable [OFE α] [OFE.Discrete α] variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))] variable [IdempotentOp (add (α := α))] variable [Zero α] @@ -226,7 +228,7 @@ namespace PosCommMonoidLike open Iris Iris.OFE Add Zero One Associative Commutative LawfulLeftIdentity CMRA IdempotentOp -variable [OFE Nat α] [Discrete α] +variable [OFE α] [Discrete α] variable [Add α] [Associative (add (α := α))] [Commutative (add (α := α))] variable [IdempotentOp (add (α := α))] diff --git a/Iris/Iris/Algebra/OFE.lean b/Iris/Iris/Algebra/OFE.lean index 8de7028ef..e60fd04dd 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -33,7 +33,8 @@ class OFE (α : Type _) (SI : Type _ := by infer_stepindex) [SIdx SI] where open OFE -scoped notation:40 x " ≡{" n "}≡ " y:41 => OFE.Dist (SI := by infer_stepindex) n x y +scoped notation:40 x " ≡{" n "}≡ " y:41 => OFE.Dist (SI := stepindex%) n x y +scoped notation:40 x " ≡{" n "}≡@{" S "} " y:41 => OFE.Dist (SI := S) n x y namespace OFE diff --git a/Iris/Iris/Algebra/ReservationMap.lean b/Iris/Iris/Algebra/ReservationMap.lean index 9a8e38d2b..992bbbc79 100644 --- a/Iris/Iris/Algebra/ReservationMap.lean +++ b/Iris/Iris/Algebra/ReservationMap.lean @@ -13,6 +13,8 @@ namespace Iris @[expose] public section +local stepindex Nat + open Iris Std PartialMap /-! @@ -56,12 +58,12 @@ section OFE open OFE -variable [LawfulPartialMap H Pos] [OFE Nat A] +variable [LawfulPartialMap H Pos] [OFE A] #rocq_ignore reservation_map_ofe_mixin "Not needed" @[rocq_alias reservation_mapO] -instance : OFE Nat (ReservationMap A H) where +instance : OFE (ReservationMap A H) where Dist n x y := x.data ≡{n}≡ y.data ∧ x.token ≡{n}≡ y.token dist_eqv := { refl _ := ⟨.rfl, rfl⟩, @@ -77,7 +79,7 @@ instance : OFE Nat (ReservationMap A H) where @[rocq_alias reservation_map_ofe_discrete] instance instDiscreteReservationMap [Discrete A] : Discrete (ReservationMap A H) where - discrete_0 h := OFE.eq_dist.mpr <| by + discrete_0 h := OFE.eq_dist (SI := Nat) |>.mpr <| by intro n exact ⟨(discrete_0 h.left).dist, (discrete_0 h.right).dist⟩ @@ -95,7 +97,7 @@ instance instNonExpansiveReservationMapSingleton : @[rocq_alias ReservationMap_discrete] instance instDiscreteEReservationMapMk {a : H A} [DiscreteE a] : DiscreteE (ReservationMap.mk a b) where - discrete := fun h => OFE.eq_dist.mpr <| by + discrete := fun h => OFE.eq_dist (SI := Nat) |>.mpr <| by intro n exact ⟨(DiscreteE.discrete h.1).dist, (DiscreteE.discrete h.2).dist⟩ @@ -246,33 +248,33 @@ instance : UCMRA (ReservationMap A H) where refine .inr fun HK => bb ?_ refine (mem_iff_of_validN_union (validN_token_of_validN v) i).mpr ?_ exact .inl HK - assoc := OFE.eq_dist.mpr <| by refine fun _ => ⟨?_, ?_⟩ <;> exact CMRA.assoc.dist - comm := OFE.eq_dist.mpr <| by refine fun _ => ⟨?_, ?_⟩ <;> exact CMRA.comm.dist - pcore_op_left {x cx} h := OFE.eq_dist.mpr <| by + assoc := OFE.eq_dist (SI := Nat) |>.mpr <| by refine fun _ => ⟨?_, ?_⟩ <;> exact CMRA.assoc.dist + comm := OFE.eq_dist (SI := Nat) |>.mpr <| by refine fun _ => ⟨?_, ?_⟩ <;> exact CMRA.comm.dist + pcore_op_left {x cx} h := OFE.eq_dist (SI := Nat) |>.mpr <| by refine fun n => ⟨?_, ?_⟩ · simp only [←Option.some_inj.mp h, op_data', core_data]; exact (core_op x.data).dist · simp [←Option.some_inj.mp h, op_token', core_token, core_op_L] - pcore_idem {x cx} h := OFE.eq_dist.mpr <| by + pcore_idem {x cx} h := OFE.eq_dist (SI := Nat) |>.mpr <| by refine fun n => ⟨?_, ?_⟩ · simp only [←Option.some_inj.mp h, core_data]; exact (core_idem x.data).dist · simp [←Option.some_inj.mp h, core_token, core_idem_L] pcore_op_mono {x cx} h y := by obtain ⟨z, hz⟩ := core_op_mono x.data y.data obtain ⟨w, hw⟩ := core_op_mono x.token y.token - refine ⟨mk z w, OFE.eq_dist.mpr ?_⟩ + refine ⟨mk z w, OFE.eq_dist (SI := Nat) |>.mpr ?_⟩ refine fun n => ⟨?_, ?_⟩ · simp only [op_data', core_data, (Option.some_inj.mp h.symm)]; exact hz.dist · simp only [core_token, op_token', (Option.some_inj.mp h.symm)]; exact hw.dist extend {n x y₁ y₂} v exy := by obtain ⟨z₁, z₂, xzz, zy₁, zy₂⟩ := CMRA.extend (validN_data_of_validN v) exy.left - refine ⟨mk z₁ y₁.token, mk z₂ y₂.token, OFE.eq_dist.mpr ?_, ⟨zy₁, rfl⟩, ⟨zy₂, rfl⟩⟩ + refine ⟨mk z₁ y₁.token, mk z₂ y₂.token, OFE.eq_dist (SI := Nat) |>.mpr ?_, ⟨zy₁, rfl⟩, ⟨zy₂, rfl⟩⟩ exact fun m => ⟨xzz.dist, exy.right⟩ unit := mk ∅ ∅ unit_valid := ⟨Heap.valid_empty, fun _ => .inr CoPset.mem_empty⟩ - unit_left_id {x} := OFE.eq_dist.mpr <| by + unit_left_id {x} := OFE.eq_dist (SI := Nat) |>.mpr <| by refine fun n => ⟨?_, (pcore_op_left' rfl).dist⟩ exact (Algebra.MonoidOps.op_left_id : (∅ : H A) • x.data = x.data).dist - pcore_unit := OFE.eq_dist.mpr <| by exact fun n => ⟨Heap.core_empty.dist, .rfl⟩ + pcore_unit := OFE.eq_dist (SI := Nat) |>.mpr <| by exact fun n => ⟨Heap.core_empty.dist, .rfl⟩ @[simp] theorem op_data (x y : ReservationMap A H): (x • y).data = x.data • y.data := rfl @@ -289,7 +291,7 @@ instance [CMRA.Discrete A] : CMRA.Discrete (ReservationMap A H) where · exact validN_disj v instance instCoreIdSingleton {a : A} [CoreId a] : CoreId (singleton (H := H) k a) where - core_id := OFE.eq_dist.mpr <| by + core_id := OFE.eq_dist (SI := Nat) |>.mpr <| by refine fun n => OFE.some_dist_some.mpr ⟨?_, .rfl⟩ exact (core_eqv_self (PartialMap.singleton k a : H A)).dist @@ -301,7 +303,7 @@ theorem split_valid {x : ReservationMap A H} (vx : ✓ x) : exact ((not_valid_invalid (S := CoPset)) (hh ▸ (valid_token_of_valid vx))).elim | .valid t => refine ⟨xd, t, ?_⟩ - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr refine fun n => ⟨?_, ?_⟩ · simp only [mkData, mkToken, op_data] exact Algebra.MonoidOps.op_right_id.symm.dist @@ -316,7 +318,7 @@ theorem split_validN {x : ReservationMap A H} (vx : ✓{n} x) : | .error => exact ((not_valid_invalid (S := CoPset)) (hh ▸ H)).elim | .valid t => refine ⟨xd, t, ?_⟩ - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr refine fun m => ⟨?_, ?_⟩ · simp only [mkData, mkToken, op_data] exact Algebra.MonoidOps.op_right_id.symm.dist @@ -340,7 +342,7 @@ theorem valid_token : ✓ (mkToken (H := H) (A := A) e) := ⟨Heap.valid_empty, fun i => .inl (get?_empty i)⟩ theorem data_op (a b : H A) : mkData (a • b) = mkData a • mkData b := by - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr refine fun n => ⟨?_, ?_⟩ · simp only [mkData, op_data]; exact .rfl · simp only [mkData, op_token] @@ -350,12 +352,12 @@ theorem data_op (a b : H A) : mkData (a • b) = mkData a • mkData b := by theorem singleton_op k (a b : A) : singleton (H := H) k (a • b) = singleton (H := H) k a • singleton k b := by have he : (({[k := a]} : H A) • {[k := b]}) = {[k := a • b]} := - OFE.eq_dist.mpr fun n i => Dist.of_eq (Heap.singleton_op_singleton i) + OFE.eq_dist (SI := Nat) |>.mpr fun n i => Dist.of_eq (Heap.singleton_op_singleton i) exact (congrArg mkData he.symm).trans (data_op _ _) theorem token_op (a b : CoPset) (h : a ## b) : mkToken (H := H) (A := A) (a ∪ b) = mkToken (H := H) (A := A) a • mkToken b := by - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr refine fun n => ⟨?_, ?_⟩ · simp only [mkToken, op_data] exact Algebra.MonoidOps.op_left_id.symm.dist @@ -416,7 +418,7 @@ instance {d : IsOp.Direction} {a b₁ b₂ : A} [hv : IsOp d a b₁ b₂] : @[rocq_alias reservation_map_token_union] theorem token_union {e₁ e₂} (he : e₁ ## e₂) : mkToken (H := H) (A := A) (e₁ ∪ e₂) = mkToken (H := H) (A := A) e₁ • mkToken e₂ := by - apply OFE.eq_dist.mpr + apply OFE.eq_dist (SI := Nat) |>.mpr refine fun n => ⟨fun i => ?_, ?_⟩ · simpa only [mkToken, get?_empty, op_data, Heap.get?_op] using .rfl · simp [mkToken, CMRA.op, he] diff --git a/Iris/Iris/Algebra/StepIndexFinite.lean b/Iris/Iris/Algebra/StepIndexFinite.lean index 355d6aa7d..eefc6b496 100644 --- a/Iris/Iris/Algebra/StepIndexFinite.lean +++ b/Iris/Iris/Algebra/StepIndexFinite.lean @@ -12,6 +12,8 @@ public meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris @[rocq_alias natSI, rocq_alias nat_sidx_mixin] @@ -41,18 +43,18 @@ def SIdx.Limit.elim {I : Type u} [SIdx I] [SIdxFinite I] {n : I} {C : Sort v} namespace OFE -theorem Dist.leNat [OFE Nat α] {m n} {x y : α} (h : x ≡{n}≡ y) (h' : m ≤ n) : x ≡{m}≡ y := +theorem Dist.leNat [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 -theorem Contractive.succNat [OFE Nat α] [OFE Nat β] (f : α → β) [Contractive f] {n x y} +theorem Contractive.succNat [OFE α] [OFE β] (f : α → β) [Contractive f] {n : Nat} {x y} (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.instCOFE_Nat {α : Type _} : COFE (DiscreteO α) := DiscreteO.instCOFE -instance DiscreteO.discrete_Nat {α : Type _} : OFE.Discrete (SI := Nat) (DiscreteO α) := +instance DiscreteO.discrete_Nat {α : Type _} : OFE.Discrete (DiscreteO α) := DiscreteO.OFE -instance unitCOFE_Nat : COFE Nat Unit := COFE.unitCOFE +instance unitCOFE_Nat : COFE Unit := COFE.unitCOFE end OFE diff --git a/Iris/Iris/Algebra/StepIndexRegistry.lean b/Iris/Iris/Algebra/StepIndexRegistry.lean index 54112990e..096eec0fb 100644 --- a/Iris/Iris/Algebra/StepIndexRegistry.lean +++ b/Iris/Iris/Algebra/StepIndexRegistry.lean @@ -36,6 +36,21 @@ required to be scoped as either `local` or `scoped`: `global` indices are not pe /-- Query the type of step indices -/ @[expose] elab "#stepindex?" : command => do logInfo m!"{siExt.getState (← getEnv)}" +/-- +`stepindex%` elaborates to the step index type in scope, resolved **eagerly** as a term. + +Unlike the `infer_stepindex` tactic this introduces no metavariable. A `by` block becomes a +synthetic *opaque* metavariable that is only solved once elaboration is otherwise finished, so +instance resolution that needs the index — `Trans` for `calc`, `CoeFun` to apply a morphism, +projections on a `Dist` hypothesis — never gets to see it. Resolving here instead makes the +index concrete from the start. +-/ +@[expose] elab "stepindex%" : term => do + let n := siExt.getState (← getEnv) + if n.isAnonymous then + throwError "stepindex%: no step index in scope; declare one with `local stepindex T`" + Term.elabTerm (mkIdent n) none + /-- Close a goal with the step index type in scope, resolved at the use site. diff --git a/Iris/Iris/Algebra/UFrac.lean b/Iris/Iris/Algebra/UFrac.lean index 8035932af..6569d80c3 100644 --- a/Iris/Iris/Algebra/UFrac.lean +++ b/Iris/Iris/Algebra/UFrac.lean @@ -19,6 +19,8 @@ A variant of the Frac CMRA with unbounded validity (>1). @[expose] public section +local stepindex Nat + namespace Iris @[rocq_alias ufrac] @@ -36,7 +38,7 @@ namespace UFrac #rocq_ignore ufrac_pcore_instance "Use CMRA instance" #rocq_ignore ufrac_valid_instance "Use CMRA instance" -@[simp] instance : COFE Nat UFrac := COFE.ofDiscrete _ +@[simp] instance : COFE 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 c21ee3a11..0961c3c8c 100644 --- a/Iris/Iris/Algebra/UPred.lean +++ b/Iris/Iris/Algebra/UPred.lean @@ -10,6 +10,8 @@ public import Iris.Algebra.OFE @[expose] public section +local stepindex Nat + namespace Iris open CMRA @@ -63,7 +65,7 @@ variable [UCMRA M] open UPred @[rocq_alias uPredO] -instance : OFE Nat (UPred M) where +instance : OFE (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 +97,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 Nat (UPred M) where +instance : IsCOFE (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 @@ -132,11 +134,11 @@ instance [URFunctor F] : COFE.OFunctor Nat (UPredOF F) where map_ne.ne _ _ _ Hx _ _ Hy _ _ z2 Hn _ := by simp only [uPred_map] exact uPred_ne <| URFunctor.map_ne.ne (Hy.le Hn) (Hx.le Hn) z2 - map_id x := OFE.eq_dist.mpr <| by + map_id x := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ _ z _ _ simp only [uPred_map] simp only [URFunctor.map_id] - map_comp f g f' g' x := OFE.eq_dist.mpr <| by + map_comp f g f' g' x := OFE.eq_dist (SI := Nat) |>.mpr <| by intro _ _ H _ _ simp only [uPred_map] simp only [URFunctor.map_comp] diff --git a/Iris/Iris/Algebra/Updates.lean b/Iris/Iris/Algebra/Updates.lean index 6b51adcb8..50abc8aff 100644 --- a/Iris/Iris/Algebra/Updates.lean +++ b/Iris/Iris/Algebra/Updates.lean @@ -10,6 +10,8 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris @[rocq_alias cmra_updateP] @@ -77,9 +79,9 @@ theorem UpdateP.op {P Q R : α → Prop} {x y} (CMRA.opM_left_dist mz CMRA.op_commN).trans (CMRA.op_opM_assoc_dist _ _ mz) let ⟨w, pw, vw⟩ := uyq n (some (x •? mz)) (CMRA.validN_ne e₁ v) have e₂ : w •? some (x •? mz) ≡{n}≡ x •? some (w •? mz) := calc - w •? some (x •? mz) ≡{n}≡ (w • x) •? mz := (CMRA.op_opM_assoc_dist w x mz).symm - _ ≡{n}≡ (x • w) •? mz := (CMRA.opM_left_dist mz CMRA.op_commN) - _ ≡{n}≡ x •? some (w •? mz) := CMRA.op_opM_assoc_dist x w mz + w •? some (x •? mz) ≡{n}≡ (w • x) •? mz := (CMRA.op_opM_assoc_dist w x mz).symm + _ ≡{n}≡ (x • w) •? mz := (CMRA.opM_left_dist mz CMRA.op_commN) + _ ≡{n}≡ x •? some (w •? mz) := CMRA.op_opM_assoc_dist x w mz let ⟨z, pz, vz⟩ := uxp n (some (w •? mz)) (CMRA.validN_ne e₂ vw) exact ⟨z • w, pqr z w pz pw, CMRA.validN_ne (CMRA.op_opM_assoc_dist z w mz).symm vz⟩ @@ -165,15 +167,15 @@ theorem Update.discrete_total [CMRA.Discrete α] [CMRA.IsTotal α] : -- (** * Transport *) -- Section cmra_transport. --- Context {SI : sidx} {A B : cmra} (H : A = B). --- Notation T := (cmra_transport H). --- Lemma cmra_transport_updateP (P : A → Prop) (Q : B → Prop) x : --- x ~~>: P → (∀ y, P y → Q (T y)) → T x ~~>: Q. --- Proof. Admitted. - --- Lemma cmra_transport_updateP' (P : A → Prop) x : --- x ~~>: P → T x ~~>: λ y, ∃ y', y = cmra_transport H y' ∧ P y'. --- Proof. Admitted. +-- Context {SI : sidx} {A B : cmra} (H : A = B). +-- Notation T := (cmra_transport H). +-- Lemma cmra_transport_updateP (P : A → Prop) (Q : B → Prop) x : +-- x ~~>: P → (∀ y, P y → Q (T y)) → T x ~~>: Q. +-- Proof. Admitted. + +-- Lemma cmra_transport_updateP' (P : A → Prop) x : +-- x ~~>: P → T x ~~>: λ y, ∃ y', y = cmra_transport H y' ∧ P y'. +-- Proof. Admitted. -- End cmra_transport. diff --git a/Iris/Iris/Algebra/View.lean b/Iris/Iris/Algebra/View.lean index 90d695f54..0e8e98404 100644 --- a/Iris/Iris/Algebra/View.lean +++ b/Iris/Iris/Algebra/View.lean @@ -16,24 +16,26 @@ meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + open Iris abbrev ViewRel (A B : Type _) := Nat → A → B → Prop @[rocq_alias view_rel] -class IsViewRel [OFE Nat A] [UCMRA B] (R : ViewRel A B) where +class IsViewRel [OFE 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 Nat A] [UCMRA B] (R : ViewRel A B) extends IsViewRel R where +class IsViewRelDiscrete [OFE 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 Nat A] [UCMRA B] {R : ViewRel A B} [IsViewRel R] +variable [OFE 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 +64,7 @@ notation "◯V " b => View.Frag b namespace View section OFE open OFE UCMRA -variable [OFE Nat A] [OFE Nat B] {R : ViewRel A B} +variable [OFE A] [OFE B] {R : ViewRel A B} #rocq_ignore view_equiv "OFE is Leibniz; use equality" @@ -70,7 +72,7 @@ variable [OFE Nat A] [OFE Nat 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 instOFE : OFE Nat (View R) where +instance instOFE : OFE (View R) where Dist := dist dist_eqv := { refl _ := ⟨.of_eq rfl, .of_eq rfl⟩ @@ -125,12 +127,12 @@ theorem auth_dist_inj [UCMRA B] {q1 q2 : DFrac} {a1 a2 : A} {n} @[rocq_alias view_auth_inj] theorem auth_eqv_inj [UCMRA B] {q1 q2 : DFrac} {a1 a2 : A} (H : (●V{q1} a1 : View R) = ●V{q2} a2) : q1 = q2 ∧ a1 = a2 := by - refine ⟨(auth_dist_inj (n := 0) H.dist).1, OFE.eq_dist.mpr fun n => ?_⟩ + refine ⟨(auth_dist_inj (n := 0) H.dist).1, OFE.eq_dist (SI := Nat) |>.mpr fun n => ?_⟩ exact (auth_dist_inj H.dist).2 @[rocq_alias view_frag_inj] theorem frag_eqv_inj [UCMRA B] {b1 b2 : B} - (H : (◯V b1 : View R) = ◯V b2) : b1 = b2 := OFE.eq_dist.mpr fun _ => H.dist.2 + (H : (◯V b1 : View R) = ◯V b2) : b1 = b2 := OFE.eq_dist.mpr fun _ => (H.dist (SI := Nat)).2 @[rocq_alias view_frag_dist_inj] theorem dist_of_frag_dist [UCMRA B] {b1 b2 : B} {n} (H : (◯V b1 : View R) ≡{n}≡ ◯V b2) : @@ -151,7 +153,7 @@ end OFE section CMRA open IsViewRel toAgree OFE DFrac -variable [OFE Nat A] [UCMRA B] {R : ViewRel A B} [IsViewRel R] +variable [OFE 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 @@ -212,7 +214,7 @@ instance : CMRA (View R) where op_ne.ne n x1 x2 H := by refine mk.ne.ne ?_ ?_ · exact cmraOption.op_ne.ne <| NonExpansive.ne H - · exact CMRA.op_ne.ne <| NonExpansive.ne H + · exact CMRA.op_ne.ne <| NonExpansive.ne H pcore_ne {n x y} cx H := by simp only [Pcore, Option.some.injEq] rintro ⟨rfl⟩ @@ -514,7 +516,7 @@ open CMRA in theorem auth_inc_auth_op_frag_iff : ((●V{dq1} a1 : View R) ≼ (●V{dq2} a2 : View R) • ◯V b) ↔ (dq1 ≼ dq2 ∨ dq1 = dq2) ∧ a1 = a2 := by refine ⟨fun H => ⟨?_, ?_⟩, fun H => ?_⟩ · exact auth_incN_auth_op_frag_iff (n := 0) |>.mp (CMRA.incN_of_inc _ H) |>.1 - · refine OFE.eq_dist.mpr (fun n => ?_) + · refine OFE.eq_dist (SI := Nat) |>.mpr (fun n => ?_) exact auth_incN_auth_op_frag_iff |>.mp (CMRA.incN_of_inc _ H) |>.2 · rcases H with ⟨(⟨q, Hq⟩|Hq), Ha⟩ · calc (●V{dq1} a1 : View R) @@ -582,10 +584,10 @@ theorem auth_op_frag_incN_auth_op_frag_iff : · calc ((●V{dq1} a1) • ◯V b1 : View R) _ ≼{n} ((●V{dq2} a2) • ◯V bf) • ◯V b1 := op_monoN_left _ <| auth_incN_auth_op_frag_iff.mpr ⟨H0, H1⟩ - _ ≼{n} (●V{dq2} a2) • ((◯V bf) • ◯V b1) := incN_of_incN_of_dist .rfl op_assocN.symm + _ ≼{n} (●V{dq2} a2) • ((◯V bf) • ◯V b1) := incN_of_incN_of_dist .rfl op_assocN.symm _ ≼{n} (●V{dq2} a2) • ◯V bf • b1 := by rw [frag_op_eq] _ ≼{n} (●V{dq2} a2) • ◯V b2 := by - refine incN_of_incN_of_dist .rfl ?_ + refine incN_of_incN_of_dist .rfl ?_ refine CMRA.op_ne.ne (NonExpansive.ne ?_) exact H2.trans comm'.dist |>.symm @@ -628,7 +630,7 @@ end CMRA section Updates -variable [OFE Nat A] [IB : UCMRA B] {R : ViewRel A B} [IsViewRel R] +variable [OFE A] [IB : UCMRA B] {R : ViewRel A B} [IsViewRel R] open CMRA DFrac @@ -774,7 +776,7 @@ theorem auth_alloc (Hup : ∀ n bf, R n a bf → R n a (b • bf)) : refine ⟨Hv, ?_⟩ exists a0 refine ⟨Hag, ?_⟩ - have Heq := Agree.toAgree_includedN.mp ⟨ag, Hag.symm⟩ + have Heq := Agree.toAgree_includedN.mp ⟨ag, Hag.symm⟩ have HR' := IsViewRel.mono Hrel Heq.symm (CMRA.incN_op_right n UCMRA.unit bf) n.le_refl apply IsViewRel.mono (Hup _ _ HR') Heq ?_ n.le_refl apply Iris.OFE.Dist.to_incN @@ -822,16 +824,16 @@ theorem map_compose {R : ViewRel A B} {R' : ViewRel A' B'} {R'' : ViewRel A'' B' section mapO -variable [OFE Nat A] [OFE Nat B] [OFE Nat A'] [OFE Nat B'] {R : ViewRel A B} {R' : ViewRel A' B'} +variable [OFE A] [OFE B] [OFE A'] [OFE B'] {R : ViewRel A 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) : +theorem map_compose' [OFE A''] [OFE B''] {R'' : ViewRel A'' B''} + (f : A -n> A') (g : B -n> B') (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 Nat B] in +omit [OFE 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 +861,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 Nat A] [UCMRA B] [OFE Nat A'] [UCMRA B'] +def mapC [OFE A] [UCMRA B] [OFE 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.lean b/Iris/Iris/BI.lean index 39d03adec..ab8228361 100644 --- a/Iris/Iris/BI.lean +++ b/Iris/Iris/BI.lean @@ -11,3 +11,5 @@ public import Iris.BI.Updates public import Iris.BI.Cmra public import Iris.BI.Embedding public import Iris.BI.MonPred + +local stepindex Nat diff --git a/Iris/Iris/BI/Algebra.lean b/Iris/Iris/BI/Algebra.lean index 3386357e1..d224113e6 100644 --- a/Iris/Iris/BI/Algebra.lean +++ b/Iris/Iris/BI/Algebra.lean @@ -11,6 +11,8 @@ This file provides introduction rules (BI entailments) for (some) CMRA operation @[expose] public section +local stepindex Nat + -- TODO: Need sbi_unfold to make these proofs less horrific namespace Iris @@ -207,7 +209,7 @@ section agree_inclusion open Iris BI Agree OFE -variable [Sbi PROP] [OFE Nat A] +variable [Sbi PROP] [OFE A] @[rocq_alias agree_equivI] theorem agree_equivI {a b : A} : toAgree a ≡ toAgree b ⊣⊢@{PROP} a ≡ b := by @@ -351,7 +353,7 @@ theorem auth_both_validI (a b : A) : end auth section dfrac_agree -variable [Sbi PROP] {A : Type _} [OFE Nat A] +variable [Sbi PROP] {A : Type _} [OFE A] open BI diff --git a/Iris/Iris/BI/BI.lean b/Iris/Iris/BI/BI.lean index 469c1595b..9e676fb2b 100644 --- a/Iris/Iris/BI/BI.lean +++ b/Iris/Iris/BI/BI.lean @@ -11,6 +11,8 @@ public import Iris.BI.BIBase @[expose] public section +local stepindex Nat + namespace Iris open Iris.Std OFE open Lean @@ -22,7 +24,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 Nat PROP, BI.BIBase PROP where +class BI (PROP : Type _) extends COFE 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.lean b/Iris/Iris/BI/BigOp.lean index 82a4f22d9..08334b0fa 100644 --- a/Iris/Iris/BI/BigOp.lean +++ b/Iris/Iris/BI/BigOp.lean @@ -6,3 +6,5 @@ public import Iris.BI.BigOp.BigOrList public import Iris.BI.BigOp.BigSepList public import Iris.BI.BigOp.BigSepMap public import Iris.BI.BigOp.BigSepMSet + +local stepindex Nat diff --git a/Iris/Iris/BI/BigOp/BigAndList.lean b/Iris/Iris/BI/BigOp/BigAndList.lean index a9de797da..696189f9c 100644 --- a/Iris/Iris/BI/BigOp/BigAndList.lean +++ b/Iris/Iris/BI/BigOp/BigAndList.lean @@ -9,6 +9,8 @@ public import Iris.BI.BigOp.BigOp import Iris.BI.DerivedLawsLater meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.BI diff --git a/Iris/Iris/BI/BigOp/BigAndMap.lean b/Iris/Iris/BI/BigOp/BigAndMap.lean index 897393887..f1dbb7aa2 100644 --- a/Iris/Iris/BI/BigOp/BigAndMap.lean +++ b/Iris/Iris/BI/BigOp/BigAndMap.lean @@ -9,6 +9,8 @@ public import Iris.BI.BigOp.BigOp import Iris.BI.DerivedLawsLater meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.BI diff --git a/Iris/Iris/BI/BigOp/BigOp.lean b/Iris/Iris/BI/BigOp/BigOp.lean index 13a7270fb..360005ed0 100644 --- a/Iris/Iris/BI/BigOp/BigOp.lean +++ b/Iris/Iris/BI/BigOp/BigOp.lean @@ -10,6 +10,8 @@ public import Iris.Algebra.BigOp public import Iris.BI.DerivedLaws import Lean +local stepindex Nat + namespace Iris.BI public section List @@ -39,7 +41,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 Nat PROP] {op₁ op₂ : PROP → PROP → PROP} +theorem MonoidHomomorphism.ofEq [OFE 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 +53,7 @@ theorem MonoidHomomorphism.ofEq [OFE Nat PROP] {op₁ op₂ : PROP → PROP → map_unit := hunit /-- Build a `WeakMonoidHomomorphism` for Leibniz equality from just the essential fields. -/ -theorem WeakMonoidHomomorphism.ofEq [OFE Nat PROP] {op₁ op₂ : PROP → PROP → PROP} +theorem WeakMonoidHomomorphism.ofEq [OFE 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/BigOrList.lean b/Iris/Iris/BI/BigOp/BigOrList.lean index 44cee8f63..04300eaa3 100644 --- a/Iris/Iris/BI/BigOp/BigOrList.lean +++ b/Iris/Iris/BI/BigOp/BigOrList.lean @@ -9,6 +9,8 @@ public import Iris.BI.BigOp.BigOp import Iris.BI.DerivedLawsLater meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.BI diff --git a/Iris/Iris/BI/BigOp/BigSepList.lean b/Iris/Iris/BI/BigOp/BigSepList.lean index 28e9f7c60..0e5bb890a 100644 --- a/Iris/Iris/BI/BigOp/BigSepList.lean +++ b/Iris/Iris/BI/BigOp/BigSepList.lean @@ -11,6 +11,8 @@ import Iris.BI.Instances import Iris.Std.TC meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.BI @@ -1193,7 +1195,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 Nat A] [OFE Nat B] +theorem bigSepL2_dist_2 [OFE A] [OFE 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 +1212,7 @@ theorem bigSepL2_dist_2 [OFE Nat A] [OFE Nat 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 Nat A] [OFE Nat B] +theorem bigSepL2_proper_2 [OFE A] [OFE 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/BigOp/BigSepMSet.lean b/Iris/Iris/BI/BigOp/BigSepMSet.lean index 03f7ef92d..4846217ff 100644 --- a/Iris/Iris/BI/BigOp/BigSepMSet.lean +++ b/Iris/Iris/BI/BigOp/BigSepMSet.lean @@ -14,6 +14,8 @@ import Iris.BI.Instances import Iris.Std.TC meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.BI diff --git a/Iris/Iris/BI/BigOp/BigSepMap.lean b/Iris/Iris/BI/BigOp/BigSepMap.lean index 7b01b0a6c..553a09c77 100644 --- a/Iris/Iris/BI/BigOp/BigSepMap.lean +++ b/Iris/Iris/BI/BigOp/BigSepMap.lean @@ -14,6 +14,8 @@ import Iris.Std.TC import Batteries.Data.List.Perm meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.BI diff --git a/Iris/Iris/BI/BigOp/BigSepSet.lean b/Iris/Iris/BI/BigOp/BigSepSet.lean index 8ca47cdcc..88c4a45ab 100644 --- a/Iris/Iris/BI/BigOp/BigSepSet.lean +++ b/Iris/Iris/BI/BigOp/BigSepSet.lean @@ -12,6 +12,8 @@ import Iris.BI.Instances import Iris.Std.TC meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris.BI diff --git a/Iris/Iris/BI/Classes.lean b/Iris/Iris/BI/Classes.lean index 7ed65fc8c..5a78ba7f3 100644 --- a/Iris/Iris/BI/Classes.lean +++ b/Iris/Iris/BI/Classes.lean @@ -9,6 +9,8 @@ public import Iris.BI.BI @[expose] public section +local stepindex Nat + namespace Iris.BI /-- Require that the proposition `P` is persistent. -/ diff --git a/Iris/Iris/BI/Cmra.lean b/Iris/Iris/BI/Cmra.lean index 498e9def3..0f64499e9 100644 --- a/Iris/Iris/BI/Cmra.lean +++ b/Iris/Iris/BI/Cmra.lean @@ -12,6 +12,8 @@ public import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + /-! # Generic CMRA validity in a BI logic diff --git a/Iris/Iris/BI/DerivedLaws.lean b/Iris/Iris/BI/DerivedLaws.lean index e7dae8b55..6034dd800 100644 --- a/Iris/Iris/BI/DerivedLaws.lean +++ b/Iris/Iris/BI/DerivedLaws.lean @@ -16,6 +16,8 @@ import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris.BI open Iris.Std BI @@ -2382,7 +2384,7 @@ instance from_option_persistent [BI PROP] {P : PROP} {Ψ : α → PROP} {mx : Op /-! # Limits -/ @[rocq_alias bi.limit_preserving_entails] -instance LimitPreserving.entails [BI PROP] [COFE Nat A] (Φ Ψ : A → PROP) [Φne : OFE.NonExpansive Φ] +instance LimitPreserving.entails [BI PROP] [COFE 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 +2398,26 @@ instance LimitPreserving.entails [BI PROP] [COFE Nat A] (Φ Ψ : A → PROP) [Φ exact fun n => (h' n).to_eq @[rocq_alias bi.limit_preserving_emp_valid] -instance limitPreserving_emp_valid [BI PROP] [COFE Nat A] (Φ : A → PROP) +instance limitPreserving_emp_valid [BI PROP] [COFE A] (Φ : A → PROP) [OFE.NonExpansive Φ] : LimitPreserving (fun x => ⊢ Φ x) := LimitPreserving.entails (fun _ => iprop(emp)) Φ @[rocq_alias bi.limit_preserving_Persistent] -instance limitPreserving_persistent [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : +instance limitPreserving_persistent [BI PROP] [COFE 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) -instance limitPreserving_absorbing [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : +instance limitPreserving_absorbing [BI PROP] [COFE 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) -instance limitPreserving_affine [BI PROP] [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : +instance limitPreserving_affine [BI PROP] [COFE 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 _ ?_ diff --git a/Iris/Iris/BI/DerivedLawsLater.lean b/Iris/Iris/BI/DerivedLawsLater.lean index 31d4d7c24..0afe10d1d 100644 --- a/Iris/Iris/BI/DerivedLawsLater.lean +++ b/Iris/Iris/BI/DerivedLawsLater.lean @@ -17,6 +17,8 @@ public import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris.BI open Iris.Std BI diff --git a/Iris/Iris/BI/Embedding.lean b/Iris/Iris/BI/Embedding.lean index 99eb6daab..a5303e752 100644 --- a/Iris/Iris/BI/Embedding.lean +++ b/Iris/Iris/BI/Embedding.lean @@ -21,6 +21,8 @@ public import Iris.Algebra.Monoid @[expose] public section +local stepindex Nat + namespace Iris.BI open Iris Iris.Std OFE Iris.Algebra Iris.Algebra.BigOpL Iris.Algebra.BigOpM @@ -428,7 +430,7 @@ theorem embed_si_pure (Pi : SiProp) : siPure_siEmpValid_elim⟩ @[rocq_alias embed_internal_eq] -theorem embed_internal_eq {A : Type _} [OFE Nat A] (x y : A) : +theorem embed_internal_eq {A : Type _} [OFE 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/Extensions.lean b/Iris/Iris/BI/Extensions.lean index f45bfd0b1..278839cdf 100644 --- a/Iris/Iris/BI/Extensions.lean +++ b/Iris/Iris/BI/Extensions.lean @@ -11,6 +11,8 @@ public import Iris.BI.BI @[expose] public section +local stepindex Nat + namespace Iris.BI /-- Require that a separation logic with the carrier type `PROP` is an affine separation logic. -/ diff --git a/Iris/Iris/BI/Instances.lean b/Iris/Iris/BI/Instances.lean index b9e330ed0..8dcf584f7 100644 --- a/Iris/Iris/BI/Instances.lean +++ b/Iris/Iris/BI/Instances.lean @@ -13,6 +13,8 @@ public import Iris.Std.Classes @[expose] public section +local stepindex Nat + namespace Iris.BI open Iris.Std open BI diff --git a/Iris/Iris/BI/InternalEq.lean b/Iris/Iris/BI/InternalEq.lean index 00d7eb9df..e8a78d5c4 100644 --- a/Iris/Iris/BI/InternalEq.lean +++ b/Iris/Iris/BI/InternalEq.lean @@ -11,13 +11,15 @@ public import Iris.Algebra.Excl @[expose] public section +local stepindex Nat + namespace Iris 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 Nat A] (a b : A) : PROP := +def internalEq [Sbi PROP] {A : Type _} [OFE A] (a b : A) : PROP := iprop( (SiProp.internalEq a b)) syntax:40 term:40 " ≡ " term:41 : term @@ -36,35 +38,35 @@ variable {PROP : Type u} [Sbi PROP] {P Q : PROP} namespace internalEq @[rocq_alias internal_eq_ne] -instance instInternalEq_ne (A : Type _) [OFE Nat A] : +instance instInternalEq_ne (A : Type _) [OFE 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 Nat A] (a : A) : +theorem ne_l {A : Type _} [OFE A] (a : A) : NonExpansive (internalEq (PROP := PROP) · a) := NonExpansive₂.ne_left internalEq a -theorem ne_r {A : Type _} [OFE Nat A] (a : A) : +theorem ne_r {A : Type _} [OFE A] (a : A) : NonExpansive (internalEq (PROP := PROP) a ·) := NonExpansive₂.ne_right internalEq a @[rocq_alias internal_eq_refl] -theorem refl {A : Type _} [OFE Nat A] {P : PROP} {a : A} : P ⊢ a ≡ a := +theorem refl {A : Type _} [OFE 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 Nat A] {P : PROP} {a b : A} (h : a = b) : +theorem of_equiv {A : Type _} [OFE 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 Nat A] {x y : A} : ⌜x = y⌝ ⊢@{PROP} iprop(x ≡ y) := +theorem of_pure {A : Type _} [OFE A] {x y : A} : ⌜x = y⌝ ⊢@{PROP} iprop(x ≡ y) := pure_elim' of_equiv @[rocq_alias internal_eq_rewrite] -theorem rewrite {A : Type _} [OFE Nat A] {a b : A} (Ψ : A → PROP) [hΨ : NonExpansive Ψ] : +theorem rewrite {A : Type _} [OFE 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 +83,23 @@ theorem rewrite {A : Type _} [OFE Nat A] {a b : A} (Ψ : A → PROP) [hΨ : NonE _ ⊢ Ψ 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 Nat A] {a b : A} (Ψ : A → PROP) [NonExpansive Ψ] +theorem rewrite' {A : Type _} [OFE 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 Nat A] {a b : A} : a ≡ b ⊢@{PROP} b ≡ a := +theorem symm {A : Type _} [OFE 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 Nat A] {a b c : A} : +theorem trans {A : Type _} [OFE 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 Nat A] [OFE Nat B] (f : A → B) [hf : NonExpansive f] {x y : A} : +theorem of_internalEquiv_ne {A B : Type _} [OFE A] [OFE 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,27 +111,27 @@ section datatypes open internalEq @[rocq_alias discrete_eq_1] -theorem discrete_eq_mp {A : Type _} [OFE Nat A] {a b : A} [TCOr (DiscreteE a) (DiscreteE b)] : +theorem discrete_eq_mp {A : Type _} [OFE 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 Nat A] {a b : A} [TCOr (DiscreteE a) (DiscreteE b)] : +theorem discrete_eq {A : Type _} [OFE A] {a b : A} [TCOr (DiscreteE a) (DiscreteE b)] : a ≡ b ⊣⊢@{PROP} ⌜a = b⌝ := ⟨discrete_eq_mp, of_pure⟩ @[rocq_alias fun_extI] -theorem fun_extI {A : Type _} {B : A → Type _} [OFEFun B] {f g : (x : A) → B x} : +theorem fun_extI {A : Type _} {B : A → Type _} [OFEFun (SI := Nat) B] {f g : (x : A) → B x} : (∀ x, f x ≡ g x) ⊢@{PROP} f ≡ g := siPure_forall_mpr.trans <| siPure_mono (SiProp.fun_ext_internalEq f g) @[rocq_alias sig_equivI_1] -theorem sig_equivI_mp {A : Type _} [OFE Nat A] {P : A → Prop} {x y : Subtype P} : +theorem sig_equivI_mp {A : Type _} [OFE 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 Nat A] (P : A → Prop) (x y : Subtype P) : +theorem sig_equivI {A : Type _} [OFE 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 +139,7 @@ theorem sig_equivI {A : Type _} [OFE Nat 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 Nat A] [OFE Nat B] (x y : A × B) : +theorem prod_equivI {A B : Type _} [OFE A] [OFE 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 +151,7 @@ theorem prod_equivI {A B : Type _} [OFE Nat A] [OFE Nat 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 Nat A] (a b : A) : +theorem option_some_equivI {A : Type _} [OFE 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 +159,11 @@ theorem option_some_equivI {A : Type _} [OFE Nat A] (a b : A) : have : NonExpansive Ψ := Option.ne_match _ (ne_r a) _ exact rewrite' Ψ .rfl refl -theorem option_none_equivI (A : Type _) [OFE Nat A] : +theorem option_none_equivI (A : Type _) [OFE A] : (none : Option A) ≡ none ⊣⊢@{PROP} True := ⟨true_intro, refl⟩ -theorem option_some_none_equivI {A : Type _} [OFE Nat A] (a : A) : +theorem option_some_none_equivI {A : Type _} [OFE A] (a : A) : some a ≡ (none : Option A) ⊣⊢@{PROP} False := by refine ⟨?_, false_elim⟩ let Ψ : Option A → PROP := fun y => @@ -169,12 +171,12 @@ theorem option_some_none_equivI {A : Type _} [OFE Nat A] (a : A) : have : NonExpansive Ψ := Option.ne_match _ ⟨fun {_ _ _} _ => Dist.rfl⟩ _ exact rewrite' Ψ .rfl true_intro -theorem option_none_some_equivI {A : Type _} [OFE Nat A] (a : A) : +theorem option_none_some_equivI {A : Type _} [OFE 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 Nat O] (a b : O) : +theorem excl_equivI_excl {O : Type _} [OFE 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 +184,11 @@ theorem excl_equivI_excl {O : Type _} [OFE Nat O] (a b : O) : have : NonExpansive Ψ := Excl.ne_match _ (ne_r a) _ exact rewrite' Ψ .rfl refl -theorem excl_equivI_invalid (O : Type _) [OFE Nat O] : +theorem excl_equivI_invalid (O : Type _) [OFE O] : (Excl.invalid : Excl O) ≡ Excl.invalid ⊣⊢@{PROP} True := ⟨true_intro, refl⟩ -theorem excl_equivI_excl_invalid {O : Type _} [OFE Nat O] (a : O) : +theorem excl_equivI_excl_invalid {O : Type _} [OFE O] (a : O) : Excl.excl a ≡ (Excl.invalid : Excl O) ⊣⊢@{PROP} False := by refine ⟨?_, false_elim⟩ let Ψ : Excl O → PROP := fun y => @@ -194,12 +196,12 @@ theorem excl_equivI_excl_invalid {O : Type _} [OFE Nat O] (a : O) : have : NonExpansive Ψ := Excl.ne_match _ ⟨fun {_ _ _} _ => Dist.rfl⟩ _ exact rewrite' Ψ .rfl true_intro -theorem excl_equivI_invalid_excl {O : Type _} [OFE Nat O] (a : O) : +theorem excl_equivI_invalid_excl {O : Type _} [OFE 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 Nat A] [OFE Nat B] (sx sy : Csum A B) : +theorem csum_equivI {A B : Type _} [OFE A] [OFE B] (sx sy : Csum A B) : sx ≡ sy ⊣⊢@{PROP} match sx, sy with | .inl x, .inl y => iprop(x ≡ y) @@ -226,7 +228,7 @@ theorem csum_equivI {A B : Type _} [OFE Nat A] [OFE Nat B] (sx sy : Csum A B) : | exact refl | exact false_elim -theorem discreteFun_equivI_mp {A : Type _} {B : A → Type _} [OFEFun B] (f g : (x : A) → B x) : +theorem discreteFun_equivI_mp {A : Type _} {B : A → Type _} [OFEFun (SI := Nat) B] (f g : (x : A) → B x) : f ≡ g ⊢@{PROP} ∀ x, f x ≡ g x := by let Ψ : ((x : A) → B x) → PROP := fun g => iprop(∀ x, f x ≡ g x) have : NonExpansive Ψ := ⟨fun {_ _ _} h => sForall_ne ⟨ @@ -235,11 +237,11 @@ theorem discreteFun_equivI_mp {A : Type _} {B : A → Type _} [OFEFun B] (f g : exact rewrite' Ψ .rfl (forall_intro fun _ => refl) @[rocq_alias discrete_fun_equivI] -theorem discreteFun_equivI {A : Type _} {B : A → Type _} [OFEFun B] (f g : (x : A) → B x) : +theorem discreteFun_equivI {A : Type _} {B : A → Type _} [OFEFun (SI := Nat) B] (f g : (x : A) → B x) : f ≡ g ⊣⊢@{PROP} ∀ x, f x ≡ g x := ⟨discreteFun_equivI_mp f g, fun_extI⟩ -theorem ofeMorO_equivI_mp {A B : Type _} [OFE Nat A] [OFE Nat B] (f g : A -n> B) : +theorem ofeMorO_equivI_mp {A B : Type _} [OFE A] [OFE 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 +249,76 @@ theorem ofeMorO_equivI_mp {A B : Type _} [OFE Nat A] [OFE Nat 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 Nat A] [OFE Nat B] (f g : A -n> B) : +theorem ofeMorO_equivI_mpr {A B : Type _} [OFE A] [OFE 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 Nat A] [OFE Nat B] (f g : A -n> B) : +theorem ofeMorO_equivI {A B : Type _} [OFE A] [OFE 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 Nat A] (x y : A) : +theorem absorbingly_internalEq {A : Type _} [OFE A] (x y : A) : x ≡ y ⊣⊢@{PROP} x ≡ y := absorbingly_siPure @[rocq_alias persistently_internal_eq] -theorem persistently_internalEq {A : Type _} [OFE Nat A] (a b : A) : +theorem persistently_internalEq {A : Type _} [OFE A] (a b : A) : a ≡ b ⊣⊢@{PROP} a ≡ b := persistently_siPure @[rocq_alias internal_eq_absorbing] -instance internalEq_absorbing {A : Type _} [OFE Nat A] (x y : A) : +instance internalEq_absorbing {A : Type _} [OFE 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 Nat A] (a b : A) : +instance internalEq_persistent {A : Type _} [OFE 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 Nat A] (x y : A) : +theorem later_equivI_mp {A : Type _} [OFE 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 Nat A] (x y : A) : +theorem later_equivI_mpr {A : Type _} [OFE 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 Nat A] (x y : A) : +theorem later_equivI {A : Type _} [OFE 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 Nat A] [OFE Nat B] (f : A → B) [hf : Contractive f] +theorem f_equivI_contractive {A B : Type _} [OFE A] [OFE 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 Nat A] (a b : A) (Ψ : A → PROP) +theorem internalEq_rewrite_contractive {A : Type _} [OFE 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 Nat A] (a b : A) (Ψ : A → PROP) +theorem internalEq_rewrite_contractive' {A : Type _} [OFE 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 Nat A] (a b : A) [TCOr (DiscreteE a) (DiscreteE b)] : +instance eq_timeless {A : Type _} [OFE A] (a b : A) [TCOr (DiscreteE a) (DiscreteE b)] : Timeless (PROP := PROP) iprop(a ≡ b) where timeless := calc iprop(▷ a ≡ b) @@ -328,12 +330,12 @@ instance eq_timeless {A : Type _} [OFE Nat A] (a b : A) [TCOr (DiscreteE a) (Dis @[rocq_alias internal_eq_iff] theorem internalEq_iff (P Q : PROP) : P ≡ Q ⊢ iprop(P ↔ Q) := - letI _ := NonExpansive₂.ne_right (BIBase.iff (PROP := PROP)) P + letI _ := NonExpansive₂.ne_right (SI := Nat) (BIBase.iff (PROP := PROP)) P rewrite' (BIBase.iff P) .rfl (and_intro (imp_intro and_elim_r) (imp_intro and_elim_r)) @[rocq_alias affinely_internal_eq_wand_iff] theorem affinely_internalEq_wandIff (P Q : PROP) : (P ≡ Q) ⊢ P ∗-∗ Q := - letI _ := NonExpansive₂.ne_right (wandIff (PROP := PROP)) P + letI _ := NonExpansive₂.ne_right (SI := Nat) (wandIff (PROP := PROP)) P rewrite' (wandIff P) (affinely_elim.trans .rfl) (affinely_elim_emp.trans wandIff_refl) @[rocq_alias internal_eq_wand_iff] @@ -341,7 +343,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 Nat A] (x y : A) : +theorem siPure_internalEq {A : Type _} [OFE A] (x y : A) : SiProp.internalEq x y ⊣⊢@{PROP} x ≡ y := .rfl @[rocq_alias prop_ext_si_emp_valid_2] @@ -376,25 +378,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 Nat A] (x y : A) : +theorem internalEq_soundness {A : Type _} [OFE 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 Nat A] [OFE Nat B] {a₁ a₂ : A} {b₁ b₂ : B} : +theorem internalEq_entails {A B : Type _} [OFE A] [OFE 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 Nat A] [OFE Nat B] (f : A → B) : +theorem ne_internalEq {A B : Type _} [OFE A] [OFE 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 Nat A] [OFE Nat B] [OFE Nat C] (f : A → B → C) : +theorem ne_2_internalEq {A B C : Type _} [OFE A] [OFE B] [OFE 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 +408,7 @@ theorem ne_2_internalEq {A B C : Type _} [OFE Nat A] [OFE Nat B] [OFE Nat C] (f 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 Nat A] [OFE Nat B] (f : A → B) : +theorem contractive_internalEq {A B : Type _} [OFE A] [OFE 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/BUpdPlain.lean b/Iris/Iris/BI/Lib/BUpdPlain.lean index ec66ca1ba..4f3b7fa66 100644 --- a/Iris/Iris/BI/Lib/BUpdPlain.lean +++ b/Iris/Iris/BI/Lib/BUpdPlain.lean @@ -10,6 +10,8 @@ public import Iris.ProofMode.InstancesUpdates @[expose] public section +local stepindex Nat + namespace Iris open Iris.Std BI diff --git a/Iris/Iris/BI/Lib/Core.lean b/Iris/Iris/BI/Lib/Core.lean index 533565113..69e1a1fae 100644 --- a/Iris/Iris/BI/Lib/Core.lean +++ b/Iris/Iris/BI/Lib/Core.lean @@ -11,6 +11,8 @@ public import Iris.ProofMode @[expose] public section +local stepindex Nat + namespace Iris section Core diff --git a/Iris/Iris/BI/Lib/Fixpoint.lean b/Iris/Iris/BI/Lib/Fixpoint.lean index 105b63667..37e979ab0 100644 --- a/Iris/Iris/BI/Lib/Fixpoint.lean +++ b/Iris/Iris/BI/Lib/Fixpoint.lean @@ -10,12 +10,14 @@ public import Iris.ProofMode @[expose] public section +local stepindex Nat + namespace Iris open Iris.Std BI OFE @[rocq_alias BiMonoPred] -class BIMonoPred [BI PROP] [OFE Nat A] (F : (A → PROP) → (A → PROP)) where +class BIMonoPred [BI PROP] [OFE 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 +26,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 Nat A] (F : (A → PROP) → (A → PROP)) (x : A) : PROP := +abbrev bi_least_fixpoint [BI PROP] [OFE 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 Nat A] (F : (A → PROP) → (A → PROP)) (x : A) : PROP := +abbrev bi_greatest_fixpoint [BI PROP] [OFE 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 Nat A] {F : (A → PROP) → (A → PROP)} : +instance [BI PROP] [OFE A] {F : (A → PROP) → (A → PROP)} : NonExpansive (bi_least_fixpoint F) where ne {_ _ _} Hx := by refine forall_ne fun _ => ?_ @@ -42,7 +44,7 @@ instance [BI PROP] [OFE Nat A] {F : (A → PROP) → (A → PROP)} : exact NonExpansive.ne Hx @[rocq_alias greatest_fixpoint_ne'] -instance [BI PROP] [OFE Nat A] {F : (A → PROP) → (A → PROP)} : +instance [BI PROP] [OFE A] {F : (A → PROP) → (A → PROP)} : NonExpansive (bi_greatest_fixpoint F) where ne {_ _ _} Hx := by refine exists_ne fun _ => ?_ @@ -51,7 +53,7 @@ instance [BI PROP] [OFE Nat A] {F : (A → PROP) → (A → PROP)} : section LeastFixpoint -variable [BI PROP] [OFE Nat A] (F : (A → PROP) → (A → PROP)) +variable [BI PROP] [OFE A] (F : (A → PROP) → (A → PROP)) @[rocq_alias least_fixpoint_unfold_2] theorem least_fixpoint_unfold_mpr [BIMonoPred F] {x} : @@ -224,7 +226,7 @@ end LeastFixpoint section GreatestFixpoint -variable [BI PROP] [OFE Nat A] (F : (A → PROP) → (A → PROP)) +variable [BI PROP] [OFE 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/FixpointBanach.lean b/Iris/Iris/BI/Lib/FixpointBanach.lean index e36afcd0c..a4128d4d3 100644 --- a/Iris/Iris/BI/Lib/FixpointBanach.lean +++ b/Iris/Iris/BI/Lib/FixpointBanach.lean @@ -8,6 +8,8 @@ public import Iris.BI @[expose] public section +local stepindex Nat + namespace Iris open Iris.Std BI BI.BIBase OFE @@ -15,7 +17,7 @@ section Laws @[rocq_alias fixpoint_plain] theorem fixpoint_plain [Sbi PROP] {A : Type _} (F : (A → PROP) → A → PROP) [Contractive F] : - (∀ Φ, (∀ x, Plain (Φ x)) → (∀ x, Plain (F Φ x))) → ∀ x, Plain (fixpoint F x) := by + (∀ Φ, (∀ x, Plain (Φ x)) → (∀ x, Plain (F Φ x))) → ∀ x, Plain (fixpoint (SI := Nat) F x) := by intro HΦ refine ContractiveHom.fixpoint_ind ⟨F, inferInstance⟩ (fun f => ∀ x, Plain (f x)) ?_ (fun _ => iprop(emp)) inferInstance HΦ ?_ @@ -28,7 +30,7 @@ theorem fixpoint_plain [Sbi PROP] {A : Type _} (F : (A → PROP) → A → PROP) @[rocq_alias fixpoint_persistent] theorem fixpoint_persistent [BI PROP] {A : Type _} (F : (A → PROP) → A → PROP) [Contractive F] : (∀ Φ, (∀ x, Persistent (Φ x)) → (∀ x, Persistent (F Φ x))) → - ∀ x, Persistent (fixpoint F x) := by + ∀ x, Persistent (fixpoint (SI := Nat) F x) := by intro HΦ refine ContractiveHom.fixpoint_ind ⟨F, inferInstance⟩ (fun f => ∀ x, Persistent (f x)) ?_ (fun _ => iprop(emp)) inferInstance HΦ ?_ @@ -41,7 +43,7 @@ theorem fixpoint_persistent [BI PROP] {A : Type _} (F : (A → PROP) → A → P @[rocq_alias fixpoint_absorbing] theorem fixpoint_absorbing [BI PROP] {A : Type _} (F : (A → PROP) → A → PROP) [Contractive F] : (∀ Φ, (∀ x, Absorbing (Φ x)) → (∀ x, Absorbing (F Φ x))) → - ∀ x, Absorbing (fixpoint F x) := by + ∀ x, Absorbing (fixpoint (SI := Nat) F x) := by intro HΦ refine ContractiveHom.fixpoint_ind ⟨F, inferInstance⟩ (fun f => ∀ x, Absorbing (f x)) ?_ (fun _ => iprop(True)) inferInstance HΦ ?_ @@ -53,7 +55,7 @@ theorem fixpoint_absorbing [BI PROP] {A : Type _} (F : (A → PROP) → A → PR @[rocq_alias fixpoint_affine] theorem fixpoint_affine [BI PROP] {A : Type _} (F : (A → PROP) → A → PROP) [Contractive F] : - (∀ Φ, (∀ x, Affine (Φ x)) → (∀ x, Affine (F Φ x))) → ∀ x, Affine (fixpoint F x) := by + (∀ Φ, (∀ x, Affine (Φ x)) → (∀ x, Affine (F Φ x))) → ∀ x, Affine (fixpoint (SI := Nat) F x) := by intro HΦ refine ContractiveHom.fixpoint_ind ⟨F, inferInstance⟩ (fun f => ∀ x, Affine (f x)) ?_ (fun _ => iprop(emp)) inferInstance HΦ ?_ @@ -68,7 +70,7 @@ theorem fixpoint_persistent_absorbing [BI PROP] {A : Type _} (F : (A → PROP) → A → PROP) [Contractive F] : (∀ Φ, (∀ x, Persistent (Φ x)) → (∀ x, Absorbing (Φ x)) → (∀ x, Persistent (F Φ x) ∧ Absorbing (F Φ x))) → - ∀ x, Persistent (fixpoint F x) ∧ Absorbing (fixpoint F x) := by + ∀ x, Persistent (fixpoint (SI := Nat) F x) ∧ Absorbing (fixpoint (SI := Nat) F x) := by intro HΦ refine ContractiveHom.fixpoint_ind ⟨F, inferInstance⟩ (fun f => ∀ x, Persistent (f x) ∧ Absorbing (f x)) ?_ @@ -90,7 +92,7 @@ theorem fixpoint_persistent_affine [BI PROP] {A : Type _} (F : (A → PROP) → A → PROP) [Contractive F] : (∀ Φ, (∀ x, Persistent (Φ x)) → (∀ x, Affine (Φ x)) → (∀ x, Persistent (F Φ x) ∧ Affine (F Φ x))) → - ∀ x, Persistent (fixpoint F x) ∧ Affine (fixpoint F x) := by + ∀ x, Persistent (fixpoint (SI := Nat) F x) ∧ Affine (fixpoint (SI := Nat) F x) := by intro HΦ refine ContractiveHom.fixpoint_ind ⟨F, inferInstance⟩ (fun f => ∀ x, Persistent (f x) ∧ Affine (f x)) ?_ @@ -112,7 +114,7 @@ theorem fixpoint_plain_absorbing [Sbi PROP] {A : Type _} (F : (A → PROP) → A → PROP) [Contractive F] : (∀ Φ, (∀ x, Plain (Φ x)) → (∀ x, Absorbing (Φ x)) → (∀ x, Plain (F Φ x) ∧ Absorbing (F Φ x))) → - ∀ x, Plain (fixpoint F x) ∧ Absorbing (fixpoint F x) := by + ∀ x, Plain (fixpoint (SI := Nat) F x) ∧ Absorbing (fixpoint (SI := Nat) F x) := by intro HΦ refine ContractiveHom.fixpoint_ind ⟨F, inferInstance⟩ (fun f => ∀ x, Plain (f x) ∧ Absorbing (f x)) ?_ @@ -134,7 +136,7 @@ theorem fixpoint_plain_affine [Sbi PROP] {A : Type _} (F : (A → PROP) → A → PROP) [Contractive F] : (∀ Φ, (∀ x, Plain (Φ x)) → (∀ x, Affine (Φ x)) → (∀ x, Plain (F Φ x) ∧ Affine (F Φ x))) → - ∀ x, Plain (fixpoint F x) ∧ Affine (fixpoint F x) := by + ∀ x, Plain (fixpoint (SI := Nat) F x) ∧ Affine (fixpoint (SI := Nat) F x) := by intro HΦ refine ContractiveHom.fixpoint_ind ⟨F, inferInstance⟩ (fun f => ∀ x, Plain (f x) ∧ Affine (f x)) ?_ diff --git a/Iris/Iris/BI/Lib/Fractional.lean b/Iris/Iris/BI/Lib/Fractional.lean index fda22384e..b372a7262 100644 --- a/Iris/Iris/BI/Lib/Fractional.lean +++ b/Iris/Iris/BI/Lib/Fractional.lean @@ -11,6 +11,8 @@ public import Iris.ProofMode @[expose] public section +local stepindex Nat + namespace Iris open Iris.Std BI OFE ProofMode diff --git a/Iris/Iris/BI/Lib/GenHeap.lean b/Iris/Iris/BI/Lib/GenHeap.lean index 859d98d52..cfab362b3 100644 --- a/Iris/Iris/BI/Lib/GenHeap.lean +++ b/Iris/Iris/BI/Lib/GenHeap.lean @@ -9,6 +9,8 @@ public import Iris.Std.Namespaces @[expose] public section +local stepindex Nat + namespace Iris open Std Iris.Algebra CMRA BI ProofMode diff --git a/Iris/Iris/BI/Lib/MonoNat.lean b/Iris/Iris/BI/Lib/MonoNat.lean index ee883240d..8462f84a3 100644 --- a/Iris/Iris/BI/Lib/MonoNat.lean +++ b/Iris/Iris/BI/Lib/MonoNat.lean @@ -13,6 +13,8 @@ public import Iris.Instances.IProp @[expose] public section +local stepindex Nat + namespace Iris open Auth BI MonoNat diff --git a/Iris/Iris/BI/Lib/ProphMap.lean b/Iris/Iris/BI/Lib/ProphMap.lean index 2d3306553..ec7ecad10 100644 --- a/Iris/Iris/BI/Lib/ProphMap.lean +++ b/Iris/Iris/BI/Lib/ProphMap.lean @@ -10,6 +10,8 @@ public import Iris.Std.GenSets @[expose] public section +local stepindex Nat + namespace Iris open Std PartialMap LawfulPartialMap LawfulSet Iris.Algebra CMRA BI ProofMode diff --git a/Iris/Iris/BI/MonPred.lean b/Iris/Iris/BI/MonPred.lean index b3d117ea3..34a26f2cc 100644 --- a/Iris/Iris/BI/MonPred.lean +++ b/Iris/Iris/BI/MonPred.lean @@ -34,6 +34,8 @@ The following Rocq names from `monpred.v` are not yet ported: @[expose] public section +local stepindex Nat + namespace Iris.BI open Iris Iris.Std OFE @@ -95,7 +97,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 Nat (MonPred I PROP) where +instance : OFE (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,12 +152,12 @@ 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 Nat (MonPred I PROP) where +instance : IsCOFE (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)).compl cf (fun n => (c n).monPred_mono h) } + (LimitPreserving.entails (applyHom (SI := Nat) i) (applyHom (SI := Nat) 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)) @@ -1480,12 +1482,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 Nat A] : +theorem monPred_internal_eq_unfold {A : Type _} [OFE 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 Nat A] (i : I.car) (a b : A) : +theorem monPred_at_internal_eq {A : Type _} [OFE A] (i : I.car) (a b : A) : (iprop(a ≡ b) : MonPred I PROP).monPred_at i ⊣⊢ a ≡ b := .rfl @@ -1521,7 +1523,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 Nat A] (x y : A) : +instance internal_eq_objective {A : Type _} [OFE 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 dc961bae0..08e71c435 100644 --- a/Iris/Iris/BI/Plainly.lean +++ b/Iris/Iris/BI/Plainly.lean @@ -18,6 +18,8 @@ public import Iris.Std.Positives @[expose] public section +local stepindex Nat + namespace Iris open BI @@ -417,7 +419,7 @@ instance wand_persistent [Plain P] [Persistent Q] [Absorbing Q] : _ ⊢ (P -∗ Q) := persistently_mono (wand_mono plain .rfl) @[rocq_alias limit_preserving_Plain] -theorem limitPreserving_plain {A} [COFE Nat A] (Φ : A → PROP) [Φne : OFE.NonExpansive Φ] : +theorem limitPreserving_plain {A} [COFE 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 => ⟨?_⟩, fun hn _ _ => absurd hn (SIdx.limit_finite _)⟩ @@ -722,7 +724,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 Nat A] {a b : A} : +theorem plainly_internalEq {A} [OFE A] {a b : A} : iprop(■ (a ≡ b) ⊣⊢@{PROP} a ≡ b) := by refine ⟨plainly_elim, ?_⟩ have : OFE.NonExpansive (β := PROP) (λ x ↦ iprop(■ (a ≡ x))) := { @@ -736,7 +738,7 @@ theorem plainly_internalEq {A} [OFE Nat A] {a b : A} : _ ⊢ ■ (a ≡ a) := plainly_mono internalEq.refl @[rocq_alias internal_eq_plain] -instance internalEq_plain {A} [OFE Nat A] (a b : A) : Plain (PROP := PROP) iprop(a ≡ b) where +instance internalEq_plain {A} [OFE 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 002a2925d..eaf9a50f4 100644 --- a/Iris/Iris/BI/SIProp.lean +++ b/Iris/Iris/BI/SIProp.lean @@ -14,6 +14,8 @@ public meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + /-! # Step-Indexed Propositions (siProp) @@ -109,7 +111,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 Nat SiProp where +instance : OFE 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,7 +127,7 @@ instance : OFE Nat SiProp where #rocq_ignore siProp_ofe_mixin "Not needed in Lean." @[rocq_alias siProp_cofe] -instance : IsCOFE Nat SiProp where +instance : IsCOFE SiProp where compl c := { holds n := (c n).holds n closed {n₁ _} h hle := (c.cauchy hle .refl).mp (c n₁ |>.closed h hle) @@ -287,7 +289,7 @@ instance instPersistent (P : SiProp) : Persistent P where /-! ## Internal equality -/ @[rocq_alias siProp_internal_eq] -def internalEq [OFE Nat A] (a₁ a₂ : A) : SiProp where +def internalEq [OFE A] (a₁ a₂ : A) : SiProp where holds n := a₁ ≡{n}≡ a₂ closed h hle := Dist.le h hle @@ -296,17 +298,17 @@ def internalEq [OFE Nat 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 Nat A] : NonExpansive₂ (internalEq (A := A)) where +instance instNonExpansive₂InternalEq [OFE 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 Nat A] (P : SiProp) (a : A) : P ⊢ internalEq a a := +theorem internalEq_refl [OFE A] (P : SiProp) (a : A) : P ⊢ internalEq a a := fun _ _ => Dist.rfl @[rocq_alias siProp_primitive.internal_eq_rewrite] -theorem internalEq_rewrite [OFE Nat A] (a b : A) (Ψ : A → SiProp) [HΨ : NonExpansive Ψ] : +theorem internalEq_rewrite [OFE A] (a b : A) (Ψ : A → SiProp) [HΨ : NonExpansive Ψ] : internalEq a b ⊢ Ψ a → Ψ b := fun _ hab _ hle => (HΨ.ne (.le hab hle) .refl).mp @@ -315,34 +317,34 @@ 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 Nat A] [OFE Nat B] (a₁ a₂ : A) (b₁ b₂ : B) : +theorem internalEq_entails [OFE A] [OFE B] (a₁ a₂ : A) (b₁ b₂ : B) : (internalEq a₁ a₂ ⊢ internalEq b₁ b₂) ↔ (∀ n, a₁ ≡{n}≡ a₂ → b₁ ≡{n}≡ b₂) := Iff.rfl @[rocq_alias siProp_primitive.fun_extI] -theorem fun_ext_internalEq [OFEFun (B : A → _)] (g₁ g₂ : (x : A) → B x) : +theorem fun_ext_internalEq [OFEFun (SI := Nat) (B : A → _)] (g₁ g₂ : (x : A) → B x) : (∀ (i : A), internalEq (g₁ i) (g₂ i)) ⊢ internalEq g₁ g₂ := fun _ h x => h _ ⟨x, rfl⟩ @[rocq_alias siProp_primitive.sig_equivI_1] -theorem sig_equiv_internalEq [OFE Nat A] (P : A → Prop) (x y : { a : A // P a }) : +theorem sig_equiv_internalEq [OFE 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 Nat A] (a b : A) [Idisc : Std.TCOr (DiscreteE a) (DiscreteE b)] : +theorem discrete_eq_internalEq [OFE 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 Nat A] (x y : A) : +theorem later_equiv_internalEq_mp [OFE 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 Nat A] (x y : A) : +theorem later_equiv_internalEq_mpr [OFE A] (x y : A) : ▷ internalEq x y ⊢ internalEq (Later.next x) (Later.next y) := by intro n hP m hlt cases n with @@ -397,7 +399,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 Nat A] {x y : A} (h : True ⊢@{SiProp} internalEq x y) : x = y := +theorem internalEq_soundness [OFE 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/BI/Sbi.lean b/Iris/Iris/BI/Sbi.lean index aacba3def..0d4410208 100644 --- a/Iris/Iris/BI/Sbi.lean +++ b/Iris/Iris/BI/Sbi.lean @@ -15,6 +15,8 @@ public meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + /-! # Step-indexed BI (SBI) diff --git a/Iris/Iris/BI/Updates.lean b/Iris/Iris/BI/Updates.lean index 97264e83c..837332989 100644 --- a/Iris/Iris/BI/Updates.lean +++ b/Iris/Iris/BI/Updates.lean @@ -15,6 +15,8 @@ public import Iris.Std.CoPset @[expose] public section +local stepindex Nat + namespace Iris open Iris.Std BI diff --git a/Iris/Iris/BI/WeakestPre.lean b/Iris/Iris/BI/WeakestPre.lean index 10bef1426..72f9145e7 100644 --- a/Iris/Iris/BI/WeakestPre.lean +++ b/Iris/Iris/BI/WeakestPre.lean @@ -17,6 +17,8 @@ public import Iris.BI.Extensions public import Iris.BI.SIProp public meta import Iris.Std.RocqPorting +local stepindex Nat + public section namespace Iris diff --git a/Iris/Iris/Examples.lean b/Iris/Iris/Examples.lean index 8abfb8e7e..c472b49b0 100644 --- a/Iris/Iris/Examples.lean +++ b/Iris/Iris/Examples.lean @@ -6,3 +6,5 @@ public import Iris.Examples.Proofs public import Iris.Examples.Resources public import Iris.Examples.HeapLang public import Iris.Examples.ClosedProofs + +local stepindex Nat diff --git a/Iris/Iris/Examples/ClosedProofs.lean b/Iris/Iris/Examples/ClosedProofs.lean index 08fc68aaa..7e1d07648 100644 --- a/Iris/Iris/Examples/ClosedProofs.lean +++ b/Iris/Iris/Examples/ClosedProofs.lean @@ -16,6 +16,8 @@ public import Iris.Std.HeapInstances @[expose] public section +local stepindex Nat + namespace Iris.Examples.ClosedProofs open Iris.BI COFE HeapView Auth Std.LawfulSet diff --git a/Iris/Iris/Examples/Fix.lean b/Iris/Iris/Examples/Fix.lean index f104c5c14..30865b531 100644 --- a/Iris/Iris/Examples/Fix.lean +++ b/Iris/Iris/Examples/Fix.lean @@ -9,6 +9,8 @@ public import Iris.Algebra.COFESolver @[expose] public section +local stepindex Nat + /-! Every OFE is Leibniz, so the fold/unfold isomorphisms of the recursive domain equation solver's fixed point can be stated as propositional equalities rather than OFE equivalences. @@ -25,7 +27,7 @@ tactics for simplification/rewriting. section Fix open Iris OFE COFE -variable [OFE Nat Val] [OFE Nat Err] [IsCOFE Nat Val] [IsCOFE Nat Err] [Inhabited Err] +variable [OFE Val] [OFE Err] [IsCOFE Val] [IsCOFE Err] [Inhabited Err] abbrev DomF : OFunctorPre Nat := SumOF (constOF Val) (SumOF (constOF Err) (SumOF (LaterOF IdOF) (LaterOF (HomOF IdOF IdOF)))) @@ -36,13 +38,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 Nat Val] [OFE Nat Err] [IsCOFE Nat Val] [IsCOFE Nat Err] [Inhabited Err] := +abbrev Dom (Val : Type _) (Err : Type _) [OFE Val] [OFE Err] [IsCOFE Val] [IsCOFE Err] [Inhabited Err] := OFunctor.Fix (DomF (Val := Val) (Err := Err)) namespace Dom open Iris OFE COFE -variable [OFE Nat V] [OFE Nat E] [IsCOFE Nat V] [IsCOFE Nat E] [Inhabited E] +variable [OFE V] [OFE E] [IsCOFE V] [IsCOFE 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/HeapLang.lean b/Iris/Iris/Examples/HeapLang.lean index a5c317b36..56e2bd858 100644 --- a/Iris/Iris/Examples/HeapLang.lean +++ b/Iris/Iris/Examples/HeapLang.lean @@ -7,6 +7,8 @@ module public import Iris.HeapLang @[expose] public section + +local stepindex Nat namespace Iris.Examples.HeapLang open Iris.HeapLang diff --git a/Iris/Iris/Examples/IProp.lean b/Iris/Iris/Examples/IProp.lean index e320ea4b3..a157fe721 100644 --- a/Iris/Iris/Examples/IProp.lean +++ b/Iris/Iris/Examples/IProp.lean @@ -13,14 +13,16 @@ public import Iris.Std.HeapInstances @[expose] public section +local stepindex Nat + namespace Iris.Examples open Iris.BI COFE section Example1 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 +instance discreteO_cofe {α : Type _} : COFE (DiscreteO α) := DiscreteO.instCOFE +instance discreteO_discrete {α : Type _} : OFE.Discrete (DiscreteO α) := DiscreteO.OFE variable {GF} [E0 : ElemG GF F0] @@ -135,7 +137,7 @@ instance wp_F_contractive : Contractive (@wp_F Expr State Value _ GF _) where exact HL m Hm v Φ def wp {Expr State Value : Type _} [@Ex3WP Expr State Value GF] (e : Expr) (Φ : Value → IProp GF) : IProp GF := - (fixpoint <| @wp_F Expr State Value _ GF _) e Φ + (fixpoint (SI := Nat) <| @wp_F Expr State Value _ GF _) e Φ theorem wp_unfold (e : Expr) (Φ : Value → IProp GF) : wp e Φ = iprop( @@ -143,8 +145,8 @@ theorem wp_unfold (e : Expr) (Φ : Value → IProp GF) : ∀ s, @state_interp State _ _ s -∗ ∃ 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 Φ + exact OFE.eq_dist (SI := Nat) |>.mpr fun _n => (fixpoint_unfold (f := ⟨(@wp_F Expr State Value _ GF _), + @OFE.ne_of_contractive _ _ _ _ _ _ (@wp_F Expr State Value _ GF _) _⟩)).dist (SI := Nat) 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/Examples/Namesets.lean b/Iris/Iris/Examples/Namesets.lean index 0df03154a..d41372959 100644 --- a/Iris/Iris/Examples/Namesets.lean +++ b/Iris/Iris/Examples/Namesets.lean @@ -15,6 +15,8 @@ public import Iris.Std.GenSets @[expose] public section +local stepindex Nat + namespace Iris.Examples.Set open Iris.BI COFE Std.LawfulSet Iris.Std DisjointLeibnizSet diff --git a/Iris/Iris/Examples/Proofs.lean b/Iris/Iris/Examples/Proofs.lean index 251e7a578..b466d8587 100644 --- a/Iris/Iris/Examples/Proofs.lean +++ b/Iris/Iris/Examples/Proofs.lean @@ -10,6 +10,8 @@ public import Iris.ProofMode @[expose] public section +local stepindex Nat + namespace Iris.Examples open Iris.BI diff --git a/Iris/Iris/Examples/Resources.lean b/Iris/Iris/Examples/Resources.lean index 39d02e574..df070c0d5 100644 --- a/Iris/Iris/Examples/Resources.lean +++ b/Iris/Iris/Examples/Resources.lean @@ -13,6 +13,8 @@ public import Iris.Algebra.Agree @[expose] public section +local stepindex Nat + namespace Iris.Examples open Iris.BI COFE diff --git a/Iris/Iris/HeapLang.lean b/Iris/Iris/HeapLang.lean index 5e0789512..587269bb0 100644 --- a/Iris/Iris/HeapLang.lean +++ b/Iris/Iris/HeapLang.lean @@ -3,3 +3,5 @@ module public import Iris.HeapLang.Syntax public import Iris.HeapLang.Notation public import Iris.HeapLang.Linter + +local stepindex Nat diff --git a/Iris/Iris/HeapLang/Completeness.lean b/Iris/Iris/HeapLang/Completeness.lean index 15e81417f..9aa4f75d4 100644 --- a/Iris/Iris/HeapLang/Completeness.lean +++ b/Iris/Iris/HeapLang/Completeness.lean @@ -21,6 +21,8 @@ Note: this is not a port. Upstream Iris has no completeness proof, so there are no `rocq_alias` annotations in this file. -/ @[expose] public section + +local stepindex Nat namespace Iris.HeapLang open Iris ProgramLogic Iris.BI Language Language.Notation Std diff --git a/Iris/Iris/HeapLang/Instances.lean b/Iris/Iris/HeapLang/Instances.lean index 106d0dc85..b9b4ddd5b 100644 --- a/Iris/Iris/HeapLang/Instances.lean +++ b/Iris/Iris/HeapLang/Instances.lean @@ -15,6 +15,8 @@ public import Iris.Std.FromMathlib public import Iris.Std.GenSetsInstances @[expose] public section + +local stepindex Nat namespace Iris.HeapLang open ProgramLogic ProgramLogic.Language FromMathlib EctxItemLanguage EctxLanguage diff --git a/Iris/Iris/HeapLang/Lib/LandinsKnot.lean b/Iris/Iris/HeapLang/Lib/LandinsKnot.lean index 7a1c9e687..ee1529c5e 100644 --- a/Iris/Iris/HeapLang/Lib/LandinsKnot.lean +++ b/Iris/Iris/HeapLang/Lib/LandinsKnot.lean @@ -16,6 +16,8 @@ open BI Iris ProgramLogic @[expose] public section +local stepindex Nat + namespace LandinKnot def landinsKnot : Val := hl_val% diff --git a/Iris/Iris/HeapLang/Lib/Lock.lean b/Iris/Iris/HeapLang/Lib/Lock.lean index d87a1e1f1..a9c3bc81f 100644 --- a/Iris/Iris/HeapLang/Lib/Lock.lean +++ b/Iris/Iris/HeapLang/Lib/Lock.lean @@ -10,6 +10,8 @@ open BI @[expose] public section +local stepindex Nat + class Lock (GF : BundledGFunctors) [IrisGS_gen hlc Exp GF] where newlock : Val acquire : Val diff --git a/Iris/Iris/HeapLang/Lib/Par.lean b/Iris/Iris/HeapLang/Lib/Par.lean index ea391abb2..c3b4bb9f6 100644 --- a/Iris/Iris/HeapLang/Lib/Par.lean +++ b/Iris/Iris/HeapLang/Lib/Par.lean @@ -16,6 +16,8 @@ open BI Iris ProgramLogic Spawn @[expose] public section +local stepindex Nat + namespace Par def parN : Namespace := ndot nroot "par" diff --git a/Iris/Iris/HeapLang/Lib/Quicksort.lean b/Iris/Iris/HeapLang/Lib/Quicksort.lean index ada195e90..14324b62c 100644 --- a/Iris/Iris/HeapLang/Lib/Quicksort.lean +++ b/Iris/Iris/HeapLang/Lib/Quicksort.lean @@ -14,6 +14,8 @@ open BI Iris ProgramLogic List @[expose] public section +local stepindex Nat + namespace Quicksort def nil : Val := hl_val% λ _, none() diff --git a/Iris/Iris/HeapLang/Lib/Spawn.lean b/Iris/Iris/HeapLang/Lib/Spawn.lean index 27bc366e7..477d0780e 100644 --- a/Iris/Iris/HeapLang/Lib/Spawn.lean +++ b/Iris/Iris/HeapLang/Lib/Spawn.lean @@ -17,6 +17,8 @@ open BI Iris ProgramLogic @[expose] public section +local stepindex Nat + namespace Spawn def spawn : Val := hl_val% diff --git a/Iris/Iris/HeapLang/Lib/SpinLock.lean b/Iris/Iris/HeapLang/Lib/SpinLock.lean index f634739c3..abbaead93 100644 --- a/Iris/Iris/HeapLang/Lib/SpinLock.lean +++ b/Iris/Iris/HeapLang/Lib/SpinLock.lean @@ -18,6 +18,8 @@ open BI Iris ProgramLogic @[expose] public section +local stepindex Nat + namespace SpinLock def newlock : Val := hl_val( diff --git a/Iris/Iris/HeapLang/Linter.lean b/Iris/Iris/HeapLang/Linter.lean index 5b8e2e740..e8d0eb57b 100644 --- a/Iris/Iris/HeapLang/Linter.lean +++ b/Iris/Iris/HeapLang/Linter.lean @@ -8,6 +8,8 @@ public import Iris.HeapLang.Notation public meta import Lean.Elab.Command public meta import Lean.Linter.Util +local stepindex Nat + public meta section namespace Iris.HeapLang.Linter diff --git a/Iris/Iris/HeapLang/Notation.lean b/Iris/Iris/HeapLang/Notation.lean index 9aa141c24..73dd7beb7 100644 --- a/Iris/Iris/HeapLang/Notation.lean +++ b/Iris/Iris/HeapLang/Notation.lean @@ -8,6 +8,8 @@ module public import Iris.HeapLang.Syntax public meta import Lean.PrettyPrinter.Parenthesizer +local stepindex Nat + public meta section namespace Iris.HeapLang diff --git a/Iris/Iris/HeapLang/PrimitiveLaws.lean b/Iris/Iris/HeapLang/PrimitiveLaws.lean index f94174b15..63dfefe77 100644 --- a/Iris/Iris/HeapLang/PrimitiveLaws.lean +++ b/Iris/Iris/HeapLang/PrimitiveLaws.lean @@ -14,6 +14,8 @@ public import Iris.ProofMode public import Std.Data.ExtTreeMap @[expose] public section + +local stepindex Nat namespace Iris.HeapLang open Iris ProgramLogic Language.Notation Std FromMathlib diff --git a/Iris/Iris/HeapLang/ProofMode.lean b/Iris/Iris/HeapLang/ProofMode.lean index e3b34e4c9..08c322db5 100644 --- a/Iris/Iris/HeapLang/ProofMode.lean +++ b/Iris/Iris/HeapLang/ProofMode.lean @@ -18,6 +18,8 @@ public import Lean public import Lean.Elab.Tactic.Simp public import Qq +local stepindex Nat + namespace Iris.ProofMode open Lean hiding Expr diff --git a/Iris/Iris/HeapLang/Semantics.lean b/Iris/Iris/HeapLang/Semantics.lean index faed75d25..2349bb556 100644 --- a/Iris/Iris/HeapLang/Semantics.lean +++ b/Iris/Iris/HeapLang/Semantics.lean @@ -15,6 +15,8 @@ public import Iris.Std.HeapInstances import Iris.Std.List @[expose] public section + +local stepindex Nat namespace Iris.HeapLang open Std diff --git a/Iris/Iris/HeapLang/Syntax.lean b/Iris/Iris/HeapLang/Syntax.lean index 0db3fd4a6..bd83ef75e 100644 --- a/Iris/Iris/HeapLang/Syntax.lean +++ b/Iris/Iris/HeapLang/Syntax.lean @@ -10,6 +10,8 @@ public import Iris.ProgramLogic.Language meta import Iris.Std.RocqPorting @[expose] public section + +local stepindex Nat namespace Iris.HeapLang @[ext, rocq_alias heap_lang.loc] diff --git a/Iris/Iris/HeapLang/Tactic.lean b/Iris/Iris/HeapLang/Tactic.lean index d4af74158..402e21932 100644 --- a/Iris/Iris/HeapLang/Tactic.lean +++ b/Iris/Iris/HeapLang/Tactic.lean @@ -13,6 +13,8 @@ public import Iris.ProgramLogic.EctxLanguage public import Iris.HeapLang.Instances public import Qq +local stepindex Nat + namespace Iris.HeapLang open Lean hiding Expr diff --git a/Iris/Iris/Instances.lean b/Iris/Iris/Instances.lean index 52446176e..afd98dcec 100644 --- a/Iris/Iris/Instances.lean +++ b/Iris/Iris/Instances.lean @@ -2,3 +2,5 @@ module public import Iris.Instances.Classical public import Iris.Instances.Data + +local stepindex Nat diff --git a/Iris/Iris/Instances/Classical.lean b/Iris/Iris/Instances/Classical.lean index d31ec3b2f..33379b6ef 100644 --- a/Iris/Iris/Instances/Classical.lean +++ b/Iris/Iris/Instances/Classical.lean @@ -2,3 +2,5 @@ module public import Iris.Instances.Classical.Instance public import Iris.Instances.Classical.Notation + +local stepindex Nat diff --git a/Iris/Iris/Instances/Classical/Instance.lean b/Iris/Iris/Instances/Classical/Instance.lean index 995d6584b..3d1c46fd0 100644 --- a/Iris/Iris/Instances/Classical/Instance.lean +++ b/Iris/Iris/Instances/Classical/Instance.lean @@ -11,6 +11,8 @@ public import Iris.Std.Equivalence @[expose] public section +local stepindex Nat + namespace Iris.Instances.Classical open Iris.BI Iris.Instances.Data Std @@ -42,7 +44,7 @@ instance heapPropPreorder : Std.IsPreorder (HeapProp Val) where apply h_xy σ exact h_x -instance : COFE Nat (HeapProp Val) := COFE.ofDiscrete _ +instance : COFE (HeapProp Val) := COFE.ofDiscrete _ instance : BI (HeapProp Val) where entails_refl := heapPropPreorder.le_refl _ diff --git a/Iris/Iris/Instances/Classical/Notation.lean b/Iris/Iris/Instances/Classical/Notation.lean index 1d21dd449..21ec508a3 100644 --- a/Iris/Iris/Instances/Classical/Notation.lean +++ b/Iris/Iris/Instances/Classical/Notation.lean @@ -9,6 +9,8 @@ public import Iris.Instances.Classical.Instance @[expose] public section +local stepindex Nat + namespace Iris.Instances.Classical open Iris.Instances.Data diff --git a/Iris/Iris/Instances/IProp.lean b/Iris/Iris/Instances/IProp.lean index 30a27a1be..f6a5fd790 100644 --- a/Iris/Iris/Instances/IProp.lean +++ b/Iris/Iris/Instances/IProp.lean @@ -1,3 +1,5 @@ module public import Iris.Instances.IProp.Instance + +local stepindex Nat diff --git a/Iris/Iris/Instances/IProp/Instance.lean b/Iris/Iris/Instances/IProp/Instance.lean index f9b469be7..2369e614f 100644 --- a/Iris/Iris/Instances/IProp/Instance.lean +++ b/Iris/Iris/Instances/IProp/Instance.lean @@ -13,25 +13,27 @@ public import Iris.Instances.UPred public meta import Iris.Std.RocqPorting @[expose] public section + +local stepindex Nat namespace Iris open COFE Std CMRA /-- Apply an OFunctor at a fixed type -/ -abbrev COFE.OFunctorPre.ap (F : OFunctorPre Nat) (T : Type _) [COFE Nat T] := +abbrev COFE.OFunctorPre.ap (F : OFunctorPre Nat) (T : Type _) [COFE T] := F T T /-- Apply a list of OFunctors at a fixed type and index -/ -abbrev BundledGFunctors.api (FF : BundledGFunctors) (τ : GType) (T : Type _) [COFE Nat T] := +abbrev BundledGFunctors.api (FF : BundledGFunctors) (τ : GType) (T : Type _) [COFE T] := FF τ |>.fst |>.ap T -/-- Transport an OFunctorPre application along equality of the OFunctorPre. -/ -theorem transpAp {F1 F2 : OFunctorPre Nat} (H : F1 = F2) {T} [COFE Nat T] : F1.ap T = F2.ap T := +/-- Transport an OFunctorPre application along equality of the OFunctorPre. -/ +theorem transpAp {F1 F2 : OFunctorPre Nat} (H : F1 = F2) {T} [COFE T] : F1.ap T = F2.ap T := congrArg (OFunctorPre.ap · T) H section TranspAp -variable [RF₁ : RFunctorContractive F₁] [RF₂ : RFunctorContractive F₂] [COFE Nat T] +variable [RF₁ : RFunctorContractive F₁] [RF₂ : RFunctorContractive F₂] [COFE 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 @@ -71,29 +73,29 @@ open OFE variable [I : RFunctorContractive F] -theorem ElemG.transpMap (E : ElemG GF F) T [OFE Nat T] : (GF E.τ).fst = F := +theorem ElemG.transpMap (E : ElemG GF F) T [OFE T] : (GF E.τ).fst = F := Sigma.mk.inj E.transp |>.1 -theorem ElemG.transpClass (E : ElemG GF F) T [OFE Nat T] : (GF E.τ).snd ≍ I := +theorem ElemG.transpClass (E : ElemG GF F) T [OFE T] : (GF E.τ).snd ≍ I := Sigma.mk.inj E.transp |>.2 -def ElemG.bundle (E : ElemG GF F) [COFE Nat T] : F.ap T → GF.api E.τ T := +def ElemG.bundle (E : ElemG GF F) [COFE T] : F.ap T → GF.api E.τ T := transpAp (E.transpMap T) |>.mpr -def ElemG.unbundle (E : ElemG GF F) [COFE Nat T] : GF.api E.τ T → F.ap T := +def ElemG.unbundle (E : ElemG GF F) [COFE T] : GF.api E.τ T → F.ap T := transpAp (E.transpMap T) |>.mp -theorem ElemG.bundle_unbundle (E : ElemG GF F) [COFE Nat T] (x : GF.api E.τ T) : +theorem ElemG.bundle_unbundle (E : ElemG GF F) [COFE 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 Nat T] (x : F.ap T) : +theorem ElemG.unbundle_bundle (E : ElemG GF F) [COFE T] (x : F.ap T) : E.unbundle (E.bundle x) = x := by simp [bundle, unbundle] -instance ElemG.bundle.ne {E : ElemG GF F} [COFE Nat T] : +instance ElemG.bundle.ne {E : ElemG GF F} [COFE 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 Nat T] : +instance ElemG.unbundle.ne {E : ElemG GF F} [COFE T] : OFE.NonExpansive (E.unbundle (T := T)) where ne {_ _ _} H := OFE.transpAp_eqv_mp (E.transpMap T) (E.transpClass T) H @@ -170,14 +172,14 @@ def IProp.foldi : FF.api τ (IPre FF) -n> FF.api τ (IProp FF) := @[rocq_alias inG_unfold_fold] theorem IProp.unfoldi_foldi (x : FF.api τ (IPre FF)) : unfoldi (foldi x) = x := by - refine OFE.eq_dist.mpr fun n => ?_ + refine OFE.eq_dist (SI := Nat) |>.mpr fun n => ?_ refine .trans (OFunctor.map_comp (F := FF τ |>.fst) ..).symm.dist ?_ refine .trans ?_ (OFunctor.map_id (F := FF τ |>.fst) x).dist apply OFunctor.map_ne.ne <;> intro _ <;> simp [IProp.unfold, IProp.fold] @[rocq_alias inG_fold_unfold] theorem IProp.foldi_unfoldi (x : FF.api τ (IProp FF)) : foldi (unfoldi x) = x := by - refine OFE.eq_dist.mpr fun n => ?_ + refine OFE.eq_dist (SI := Nat) |>.mpr fun n => ?_ refine .trans (OFunctor.map_comp (F := FF τ |>.fst) ..).symm.dist ?_ refine .trans ?_ (OFunctor.map_id (F := FF τ |>.fst) x).dist apply OFunctor.map_ne.ne <;> intro _ <;> simp [IProp.unfold, IProp.fold] @@ -226,7 +228,7 @@ theorem IProp.unfoldi_unit {τ : GType} {x : FF.api τ (IProp FF)} [IsUnit x] : _ = (CMRA.pcore x).map unfoldi.f := ((RFunctor.map (IProp.fold FF) (IProp.unfold FF)).pcore x).symm _ = (some x).map unfoldi.f := - Option.map_forall₂ _ IsUnit.pcore_unit + Option.map_forall₂ (SI := Nat) _ IsUnit.pcore_unit _ = some (unfoldi.f x) := by simp [Option.map] @@ -261,7 +263,7 @@ instance : OFE.NonExpansive (iSingleton F γ (GF := GF)) where @[rocq_alias iRes_singleton_op] theorem iSingleton_op (x y : F.ap (IProp GF)) : (iSingleton F γ x) • iSingleton F γ y = iSingleton F γ (x • y) := by - refine OFE.eq_dist.mpr fun n => ?_ + refine OFE.eq_dist (SI := Nat) |>.mpr fun n => ?_ intro τ' γ' simp only [iSingleton] split @@ -303,13 +305,13 @@ theorem unfoldi_bundle_coreId {a : F.ap (IProp GF)} [CMRA.CoreId a] : calc CMRA.pcore (E.bundle a) = (CMRA.pcore a).map E.bundle := (OFE.transpAp_pcore_mp (E.transpMap (F.ap (IProp GF))).symm (E.transpClass (F.ap (IProp GF))).symm).symm - _ = (some a).map E.bundle := Option.map_forall₂ _ CMRA.CoreId.core_id + _ = (some a).map E.bundle := Option.map_forall₂ (SI := Nat) _ CMRA.CoreId.core_id _ = some (E.bundle a) := by rfl calc CMRA.pcore ((RFunctor.map (IProp.fold GF) (IProp.unfold GF)).toHom.f (E.bundle a)) = (CMRA.pcore (E.bundle a)).map (RFunctor.map (IProp.fold GF) (IProp.unfold GF)).toHom.f := ((RFunctor.map (IProp.fold GF) (IProp.unfold GF)).pcore (E.bundle a)).symm _ = (some (E.bundle a)).map (RFunctor.map (IProp.fold GF) (IProp.unfold GF)).toHom.f := - Option.map_forall₂ _ bundle_coreId.core_id + Option.map_forall₂ (SI := Nat) _ bundle_coreId.core_id _ = some ((RFunctor.map (IProp.fold GF) (IProp.unfold GF)).toHom.f (E.bundle a)) := by rfl @[rocq_alias iRes_singleton_core_id] @@ -446,7 +448,7 @@ theorem iSingleton_op_validN_at_γ {a : F.ap (IProp GF)} (Hv : ✓{n} mf) : 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 τ => ?_ + refine OFE.eq_dist (SI := Nat) |>.mpr fun n τ => ?_ simp only [iSingleton] at ⊢ split next h => @@ -814,8 +816,8 @@ instance fromAndOwn_persistent {γ} {a b1 b2 : F.ap (IProp GF)} [h : IsOp .split · infer_instance calc _ ⊢ iOwn γ b1 ∗ iOwn γ b2 := persistent_and_sep_mp - _ ⊢ iOwn γ (b1 • b2) := iOwn_op.mpr - _ ⊢ iOwn γ a := by rw [h.is_op] + _ ⊢ iOwn γ (b1 • b2) := iOwn_op.mpr + _ ⊢ iOwn γ a := by rw [h.is_op] end iOwn diff --git a/Iris/Iris/Instances/Lib/Boxes.lean b/Iris/Iris/Instances/Lib/Boxes.lean index 0be4f369e..1fd39f2e3 100644 --- a/Iris/Iris/Instances/Lib/Boxes.lean +++ b/Iris/Iris/Instances/Lib/Boxes.lean @@ -15,6 +15,8 @@ public import Iris.Std.Namespaces @[expose] public section +local stepindex Nat + namespace Iris open BI CMRA Agree OFE UPred IProp Std ProofMode COFE Auth ExclAuth Excl PartialMap BigSepM diff --git a/Iris/Iris/Instances/Lib/CInvariants.lean b/Iris/Iris/Instances/Lib/CInvariants.lean index 0fedb3044..ac6b99c5b 100644 --- a/Iris/Iris/Instances/Lib/CInvariants.lean +++ b/Iris/Iris/Instances/Lib/CInvariants.lean @@ -18,6 +18,8 @@ public import Iris.Std.List @[expose] public section +local stepindex Nat + namespace Iris open BI CMRA OFE Iris Std LawfulSet Excl COFE ProofMode diff --git a/Iris/Iris/Instances/Lib/FUpd.lean b/Iris/Iris/Instances/Lib/FUpd.lean index 599c96c08..a36ff370e 100644 --- a/Iris/Iris/Instances/Lib/FUpd.lean +++ b/Iris/Iris/Instances/Lib/FUpd.lean @@ -17,6 +17,8 @@ public import Iris.BI.Plainly @[expose] public section +local stepindex Nat + namespace Iris open Iris OFE COFE BI Auth @@ -62,7 +64,7 @@ instance {E1 E2 : CoPset} : NonExpansive (uPred_fupd (GF := GF) (hlc := hlc) E1 ne {_ _ _} h := by simp only [uPred_fupd] refine wand_ne.ne .rfl ?_ - refine (inferInstance : NonExpansive le_upd).ne ?_ + refine (inferInstance : NonExpansive (le_upd (GF := GF) (hlc := hlc))).ne ?_ refine sep_ne.ne .rfl ?_ refine sep_ne.ne .rfl h diff --git a/Iris/Iris/Instances/Lib/FUpdFromViewShift.lean b/Iris/Iris/Instances/Lib/FUpdFromViewShift.lean index 3c3e1b9c4..6bb9661eb 100644 --- a/Iris/Iris/Instances/Lib/FUpdFromViewShift.lean +++ b/Iris/Iris/Instances/Lib/FUpdFromViewShift.lean @@ -17,6 +17,8 @@ public import Iris.BI.Plainly @[expose] public section +local stepindex Nat + namespace Iris open Iris OFE BI diff --git a/Iris/Iris/Instances/Lib/GhostMap.lean b/Iris/Iris/Instances/Lib/GhostMap.lean index 651db162d..8b2b62b64 100644 --- a/Iris/Iris/Instances/Lib/GhostMap.lean +++ b/Iris/Iris/Instances/Lib/GhostMap.lean @@ -12,6 +12,8 @@ public import Iris.ProofMode @[expose] public section +local stepindex Nat + namespace Iris open Std HeapView PartialMap Iris.Algebra CMRA BI ProofMode diff --git a/Iris/Iris/Instances/Lib/Invariants.lean b/Iris/Iris/Instances/Lib/Invariants.lean index a44728626..3a8078d14 100644 --- a/Iris/Iris/Instances/Lib/Invariants.lean +++ b/Iris/Iris/Instances/Lib/Invariants.lean @@ -15,6 +15,8 @@ import Iris.Instances.Lib.WSat @[expose] public section +local stepindex Nat + /-! ## Invariants -/ namespace Iris @@ -53,7 +55,7 @@ instance inv_contractive (N : Namespace) : Contractive (inv (GF := GF) N) where refine forall_ne (fun i => ?_) refine imp_ne.ne .rfl ?_ refine wand_ne.ne .rfl ?_ - refine (inferInstance : NonExpansive le_upd).ne ?_ + refine (inferInstance : NonExpansive (le_upd (GF := GF) (hlc := hlc))).ne ?_ refine sep_ne.ne .rfl ?_ refine sep_ne.ne .rfl ?_ refine sep_ne.ne ?_ ?_ diff --git a/Iris/Iris/Instances/Lib/LaterCredits.lean b/Iris/Iris/Instances/Lib/LaterCredits.lean index 294e1511a..2f2bd1416 100644 --- a/Iris/Iris/Instances/Lib/LaterCredits.lean +++ b/Iris/Iris/Instances/Lib/LaterCredits.lean @@ -15,6 +15,8 @@ public import Iris.Instances.IProp @[expose] public section +local stepindex Nat + /-! ## Later credits -/ namespace Iris @@ -37,7 +39,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 Nat Credit := COFE.ofDiscrete _ +scoped instance : COFE Credit := COFE.ofDiscrete _ scoped instance : Discrete Credit := ⟨fun h => h⟩ scoped instance : UCMRA Credit := CommMonoidLike.instUCMRA scoped instance : CMRA.Discrete Credit := CommMonoidLike.instDiscrete @@ -245,7 +247,7 @@ instance {P : IProp GF} : Contractive (le_upd_pre P) where #rocq_ignore le_upd.le_upd_unseal "`le_upd` is defined directly without `seal`/`unseal`." @[rocq_alias le_upd.le_upd] -def le_upd (P : IProp GF) : IProp GF := fixpoint (le_upd_pre P) +def le_upd (P : IProp GF) : IProp GF := fixpoint (SI := Nat) (le_upd_pre P) syntax:max "|==£> " term:40 : term diff --git a/Iris/Iris/Instances/Lib/NaInvariants.lean b/Iris/Iris/Instances/Lib/NaInvariants.lean index a1599ad6a..191f55be8 100644 --- a/Iris/Iris/Instances/Lib/NaInvariants.lean +++ b/Iris/Iris/Instances/Lib/NaInvariants.lean @@ -15,6 +15,8 @@ public import Iris.Std.CoPset @[expose] public section +local stepindex Nat + namespace Iris open BI CMRA OFE Iris Std LawfulSet DisjointLeibnizSet COFE ProofMode diff --git a/Iris/Iris/Instances/Lib/SavedProp.lean b/Iris/Iris/Instances/Lib/SavedProp.lean index ac54bd7d8..a5812ec43 100644 --- a/Iris/Iris/Instances/Lib/SavedProp.lean +++ b/Iris/Iris/Instances/Lib/SavedProp.lean @@ -14,6 +14,8 @@ public import Iris.ProofMode @[expose] public section +local stepindex Nat + namespace Iris open BI CMRA Agree OFE UPred IProp Std ProofMode COFE diff --git a/Iris/Iris/Instances/Lib/Token.lean b/Iris/Iris/Instances/Lib/Token.lean index 1fa767354..6eabdd909 100644 --- a/Iris/Iris/Instances/Lib/Token.lean +++ b/Iris/Iris/Instances/Lib/Token.lean @@ -10,6 +10,8 @@ public import Iris.Instances.IProp.Instance @[expose] public section +local stepindex Nat + namespace Iris open BI CMRA Excl OFE UPred IProp Std ProofMode diff --git a/Iris/Iris/Instances/Lib/WSat.lean b/Iris/Iris/Instances/Lib/WSat.lean index 265fc61ae..df8126b0b 100644 --- a/Iris/Iris/Instances/Lib/WSat.lean +++ b/Iris/Iris/Instances/Lib/WSat.lean @@ -15,6 +15,8 @@ public import Iris.Instances.IProp @[expose] public section +local stepindex Nat + /-! ## World satisfaction This file defines the world satisfaction (wsat) predicate for Iris. -/ diff --git a/Iris/Iris/Instances/UPred.lean b/Iris/Iris/Instances/UPred.lean index 68821abe0..47a827a9a 100644 --- a/Iris/Iris/Instances/UPred.lean +++ b/Iris/Iris/Instances/UPred.lean @@ -1,3 +1,5 @@ module public import Iris.Instances.UPred.Instance + +local stepindex Nat diff --git a/Iris/Iris/Instances/UPred/Instance.lean b/Iris/Iris/Instances/UPred/Instance.lean index f4f085b39..87a534f9a 100644 --- a/Iris/Iris/Instances/UPred/Instance.lean +++ b/Iris/Iris/Instances/UPred/Instance.lean @@ -15,6 +15,8 @@ public meta import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + section UPredInstance open Iris BI CMRA @@ -62,12 +64,12 @@ protected def imp (P Q : UPred M) : UPred M where holds n x := ∀ {n'} (x' : ValidAt M n'), x.val ≼ x'.val → n' ≤ n → P n' x' → Q n' x' mono {_ _ x₁ x₂} H := fun ⟨m₁, Hle⟩ Hn n ⟨x, xP⟩ ⟨m₂, Hxle⟩ Hnle HP => by have Hx := - calc x ≡{n}≡ x₂ • m₂ := Hxle.dist - _ ≡{n}≡ (x₁ • m₁) • m₂ := (Hle.le Hnle).op_l + calc x ≡{n}≡ x₂ • m₂ := Hxle.dist + _ ≡{n}≡ (x₁ • m₁) • m₂ := (Hle.le Hnle).op_l refine (uPred_ne (m₂ := ⟨(x₁.val • m₁) • m₂, Hx.validN.mp xP⟩) Hx).mpr (H _ ?_ ?_ ?_) - · calc x₁.val = CMRA.op x₁.val unit := unit_right_id.symm - _ ≼ x₁.val • (m₁ • m₂) := op_mono_right _ inc_unit - _ = CMRA.op (CMRA.op x₁.val m₁) m₂ := assoc' + · calc x₁.val = CMRA.op x₁.val unit := unit_right_id.symm + _ ≼ x₁.val • (m₁ • m₂) := op_mono_right _ inc_unit + _ = CMRA.op (CMRA.op x₁.val m₁) m₂ := assoc' · exact Nat.le_trans Hnle Hn · exact (uPred_ne Hx).mp HP @@ -93,7 +95,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 Nat O] (o1 o2 : O) : UPred M where +protected def eq [OFE O] (o1 o2 : O) : UPred M where holds n _ := o1 ≡{n}≡ o2 mono H1 _ H2 := H1.le H2 @@ -105,8 +107,8 @@ protected def sep (P Q : UPred M) : UPred M where mono {_ n₂ m₁ m₂} := fun ⟨x₁, x₂, Hx, HP, HQ⟩ ⟨m, Hm⟩ Hn => by refine ⟨x₁, x₂ • m, ?_, ?_, ?_⟩ · calc m₂.val ≡{n₂}≡ m₁ • m := Hm - _ ≡{n₂}≡ (x₁ • x₂) • m := (Hx.le Hn).op_l - _ ≡{n₂}≡ x₁ • (x₂ • m) := assoc.symm.dist + _ ≡{n₂}≡ (x₁ • x₂) • m := (Hx.le Hn).op_l + _ ≡{n₂}≡ x₁ • (x₂ • m) := assoc.symm.dist · exact P.mono HP (incN_refl x₁) Hn · exact Q.mono HQ (incN_op_left n₂ x₂ m) Hn @@ -157,8 +159,8 @@ def ownM (m : M) : UPred M where mono {_ n₂ x₁ x₂} := fun ⟨m₁, Hm₁⟩ ⟨m₂, Hm₂⟩ Hn => by exists m₁ • m₂ calc x₂.val ≡{n₂}≡ x₁ • m₂ := Hm₂ - _ ≡{n₂}≡ (m • m₁) • m₂ := (Hm₁.le Hn).op_l - _ ≡{n₂}≡ m • (m₁ • m₂) := assoc.symm.dist + _ ≡{n₂}≡ (m • m₁) • m₂ := (Hm₁.le Hn).op_l + _ ≡{n₂}≡ m • (m₁ • m₂) := assoc.symm.dist #rocq_ignore uPred_ownM_unseal "`UPred.ownM` is defined directly without `seal`/`unseal`." #rocq_ignore uPred_ownM_def "`UPred.ownM` is defined directly without `seal`/`unseal`." @@ -233,18 +235,18 @@ instance bupd_ne : OFE.NonExpansive (bupd : UPred M → UPred M) where exact OFE.Dist.le Hx (Nat.le_trans Hk Hm) instance : BIBase (UPred M) where - Entails := UPred.Entails - emp := UPred.emp - pure := UPred.pure - and := UPred.and - or := UPred.or - imp := UPred.imp - sForall := UPred.sForall - sExists := UPred.sExists - sep := UPred.sep - wand := UPred.wand + Entails := UPred.Entails + emp := UPred.emp + pure := UPred.pure + and := UPred.and + or := UPred.or + imp := UPred.imp + sForall := UPred.sForall + sExists := UPred.sExists + sep := UPred.sep + wand := UPred.wand persistently := UPred.persistently - later := UPred.later + later := UPred.later #rocq_ignore uPred.uPred_emp_unseal "Connectives are defined directly without `seal`/`unseal`." @@ -283,7 +285,7 @@ instance : BI (UPred M) where entails_refl := uPred_entails_preorder.le_refl _ entails_trans := uPred_entails_preorder.le_trans _ _ _ equiv_iff {_ _} := by - rw [OFE.eq_dist] + rw [OFE.eq_dist (SI := Nat)] constructor <;> intro HE · exact ⟨fun n ⟨x, Hv⟩ H => (HE n n x .refl Hv).mp H, fun n ⟨x, Hv⟩ H => (HE n n x .refl Hv).mpr H⟩ @@ -298,7 +300,7 @@ instance : BI (UPred M) where · exact (H.symm _ _ Hn' Hv').mp H1 · exact (H'.symm _ _ Hn' Hv').mp H2 or_ne.ne _ _ _ H _ _ H' _ _ Hn' Hv := by - constructor <;> intro H'' <;> rcases H'' with H'' | H'' + constructor <;> intro H'' <;> rcases H'' with H'' | H'' · left; exact (H _ _ Hn' Hv).mp H'' · right; exact (H' _ _ Hn' Hv).mp H'' · left; exact (H.symm _ _ Hn' Hv).mp H'' @@ -328,7 +330,7 @@ instance : BI (UPred M) where refine HE _ _ Hn Hv ?_ exact (H _ _ (Nat.le_trans Hn Hn') (validN_op_right Hv)).mp H'' persistently_ne := persistently_ne - later_ne := inferInstanceAs (OFE.NonExpansive UPred.later) + later_ne := inferInstanceAs (OFE.NonExpansive (UPred.later (M := M))) sForall_ne := fun ⟨HR1, HR2⟩ n' _ Hn' Hx' => by constructor · intro H p Hp @@ -375,8 +377,8 @@ instance : BI (UPred M) where sep_assoc_l n x := fun ⟨x1, x2, Hx, ⟨y1, y2, Hy, h1, h2⟩, h3⟩ => by refine ⟨y1, y2 • x2, ?_, h1, y2, x2, .rfl, h2, h3⟩ calc x.val ≡{n}≡ x1 • x2 := Hx - _ ≡{n}≡ (y1 • y2) • x2 := Hy.op_l - _ ≡{n}≡ y1 • (y2 • x2) := assoc.symm.dist + _ ≡{n}≡ (y1 • y2) • x2 := Hy.op_l + _ ≡{n}≡ y1 • (y2 • x2) := assoc.symm.dist wand_intro H _ x HP _ x' Hn _ HQ := H _ _ ⟨x, x', .rfl, UPred.mono _ HP .rfl Hn, HQ⟩ wand_elim H n x := fun ⟨y1, y2, Hy, HP, HQ⟩ => by @@ -672,12 +674,12 @@ theorem ownM_op (m1 m2 : M) : ownM (m1 • m2) ⊣⊢ ownM m1 ∗ ownM m2 := by exists w1 • w2 calc x.val ≡{n}≡ y1 • y2 := H - _ ≡{n}≡ (m1 • w1) • (m2 • w2) := Hw1.op Hw2 - _ ≡{n}≡ m1 • (w1 • (m2 • w2)) := assoc.symm.dist - _ ≡{n}≡ m1 • ((m2 • w2) • w1) := comm'.dist.op_r - _ ≡{n}≡ m1 • (m2 • (w2 • w1)) := assoc'.symm.dist.op_r - _ ≡{n}≡ (m1 • m2) • (w2 • w1) := assoc.dist - _ ≡{n}≡ (m1 • m2) • (w1 • w2) := comm'.dist.op_r + _ ≡{n}≡ (m1 • w1) • (m2 • w2) := Hw1.op Hw2 + _ ≡{n}≡ m1 • (w1 • (m2 • w2)) := assoc.symm.dist + _ ≡{n}≡ m1 • ((m2 • w2) • w1) := comm'.dist.op_r + _ ≡{n}≡ m1 • (m2 • (w2 • w1)) := assoc'.symm.dist.op_r + _ ≡{n}≡ (m1 • m2) • (w2 • w1) := assoc.dist + _ ≡{n}≡ (m1 • m2) • (w1 • w2) := comm'.dist.op_r theorem ownM_always_invalid_elim (m : M) (H : ∀ n, ¬✓{n} m) : internalCmraValid m ⊢@{UPred M} False := fun n _ => H n @@ -809,11 +811,11 @@ theorem intuitionistically_valid {A} [CMRA A] (a : A) : · exact intuitionistically_elim · exact (persistently_valid_mpr a).trans intuitionistically_iff_persistently.mpr -theorem discrete_valid [CMRA A] [Discrete A] (a : A) : +theorem discrete_valid [CMRA A] [CMRA.Discrete A] (a : A) : internalCmraValid a ⊣⊢@{UPred M} ⌜✓ a⌝ := ⟨fun n _ hv => (valid_iff_validN' n).mpr hv, fun _ _ hv => hv.validN⟩ -instance valid_timeless [CMRA A] [Discrete A] {a : A} : +instance valid_timeless [CMRA A] [CMRA.Discrete A] {a : A} : Timeless (internalCmraValid a : UPred M) where timeless := by refine (later_mono (discrete_valid a).mp).trans ?_ @@ -861,13 +863,13 @@ theorem ownM_updateP [UCMRA M] {x : M} {R : UPred M} (Φ : M → Prop) (Hup : x show ✓{n} (x • (z1 • z2)) refine validN_ne ?_ z.property calc z.val ≡{n}≡ x1 • z2 := Hx - _ ≡{n}≡ (x • z1) • z2 := Hz1.op_l - _ ≡{n}≡ x • (z1 • z2) := assoc.symm.dist + _ ≡{n}≡ (x • z1) • z2 := Hz1.op_l + _ ≡{n}≡ x • (z1 • z2) := assoc.symm.dist have ⟨y, HΦy, Hvalid_y⟩ := Hup n (some (z1 • z2)) Hvalid have Hp := HR (iprop(⌜Φ y⌝ -∗ (UPred.ownM y -∗ UPred.plainly R))) ⟨y, rfl⟩ have Hcomm : y •? some (z1 • z2) ≡{n}≡ (z2 • z1) • y := calc y • (z1 • z2) ≡{n}≡ y • (z2 • z1) := comm.dist.op_r - _ ≡{n}≡ (z2 • z1) • y := comm.symm.dist + _ ≡{n}≡ (z2 • z1) • y := comm.symm.dist exact Hp n z1 .refl (validN_ne comm.dist (validN_op_right Hvalid)) HΦy n y .refl (validN_ne Hcomm Hvalid_y) (incN_refl y) diff --git a/Iris/Iris/ProgramLogic/AbstractEctxLangCompleteness.lean b/Iris/Iris/ProgramLogic/AbstractEctxLangCompleteness.lean index 951b33f61..b5c82d146 100644 --- a/Iris/Iris/ProgramLogic/AbstractEctxLangCompleteness.lean +++ b/Iris/Iris/ProgramLogic/AbstractEctxLangCompleteness.lean @@ -26,6 +26,8 @@ open Language Language.Notation @[expose] public section +local stepindex Nat + section AbstractEctxCompleteness variable {Expr State Obs Val Ectx : Type _} diff --git a/Iris/Iris/ProgramLogic/AbstractLangCompleteness.lean b/Iris/Iris/ProgramLogic/AbstractLangCompleteness.lean index b87d7a3ff..54667436c 100644 --- a/Iris/Iris/ProgramLogic/AbstractLangCompleteness.lean +++ b/Iris/Iris/ProgramLogic/AbstractLangCompleteness.lean @@ -24,6 +24,8 @@ open Language Language.Notation @[expose] public section +local stepindex Nat + section AbstractCompleteness variable {Expr State Obs Val : Type _} [Language Expr State Obs Val] diff --git a/Iris/Iris/ProgramLogic/AbstractWeakestPre.lean b/Iris/Iris/ProgramLogic/AbstractWeakestPre.lean index a32c0928b..af461478f 100644 --- a/Iris/Iris/ProgramLogic/AbstractWeakestPre.lean +++ b/Iris/Iris/ProgramLogic/AbstractWeakestPre.lean @@ -21,6 +21,8 @@ open ProgramLogic Language Language.Notation Std @[expose] public section +local stepindex Nat + abbrev AbstractWP (Expr Val : Type _) (GF : BundledGFunctors) := CoPset → Expr → (Val → IProp GF) → IProp GF diff --git a/Iris/Iris/ProgramLogic/Adequacy.lean b/Iris/Iris/ProgramLogic/Adequacy.lean index 74a2e961d..ab8232ef5 100644 --- a/Iris/Iris/ProgramLogic/Adequacy.lean +++ b/Iris/Iris/ProgramLogic/Adequacy.lean @@ -19,6 +19,8 @@ open Language.Notation @[expose] public section +local stepindex Nat + variable {hlc : HasLC} {Expr State Obs Val : Type _} variable [Language Expr State Obs Val] variable {GF : BundledGFunctors} [iG : IrisGS_gen hlc Expr GF] diff --git a/Iris/Iris/ProgramLogic/EctxLanguage.lean b/Iris/Iris/ProgramLogic/EctxLanguage.lean index 6964c1f6d..d39079c19 100644 --- a/Iris/Iris/ProgramLogic/EctxLanguage.lean +++ b/Iris/Iris/ProgramLogic/EctxLanguage.lean @@ -14,6 +14,8 @@ open Language.Notation @[expose] public section +local stepindex Nat + variable {Expr Val State Obs Ectx : Type _} /-- Whether a type `Ectx` has the `comp` and `empty` operations expected diff --git a/Iris/Iris/ProgramLogic/EctxLifting.lean b/Iris/Iris/ProgramLogic/EctxLifting.lean index 20a498365..109d9671d 100644 --- a/Iris/Iris/ProgramLogic/EctxLifting.lean +++ b/Iris/Iris/ProgramLogic/EctxLifting.lean @@ -7,6 +7,8 @@ module public import Iris.ProgramLogic.Lifting public import Iris.ProgramLogic.EctxiLanguage +local stepindex Nat + namespace Iris.ProgramLogic open Language.Notation EctxLanguage EctxLanguage.Notation diff --git a/Iris/Iris/ProgramLogic/EctxiLanguage.lean b/Iris/Iris/ProgramLogic/EctxiLanguage.lean index 74e23d39a..1f1604ecf 100644 --- a/Iris/Iris/ProgramLogic/EctxiLanguage.lean +++ b/Iris/Iris/ProgramLogic/EctxiLanguage.lean @@ -14,6 +14,8 @@ open Language.Notation EctxLanguage.Notation FromMathlib @[expose] public section +local stepindex Nat + variable {Expr Val State Obs EctxItem : Type _} class EctxItemLanguage (Expr : Type _) (EctxItem State Obs Val : outParam (Type _)) diff --git a/Iris/Iris/ProgramLogic/Language.lean b/Iris/Iris/ProgramLogic/Language.lean index 0e2a17858..07e874b02 100644 --- a/Iris/Iris/ProgramLogic/Language.lean +++ b/Iris/Iris/ProgramLogic/Language.lean @@ -15,6 +15,8 @@ namespace Iris.ProgramLogic @[expose] public section +local stepindex Nat + open FromMathlib variable {Expr Val State Obs : Type _} diff --git a/Iris/Iris/ProgramLogic/Lifting.lean b/Iris/Iris/ProgramLogic/Lifting.lean index 28ce47eba..bab3b3390 100644 --- a/Iris/Iris/ProgramLogic/Lifting.lean +++ b/Iris/Iris/ProgramLogic/Lifting.lean @@ -7,6 +7,8 @@ module public import Iris.ProofMode public import Iris.ProgramLogic.WeakestPre +local stepindex Nat + public section namespace Iris.ProgramLogic diff --git a/Iris/Iris/ProgramLogic/ThreadPool.lean b/Iris/Iris/ProgramLogic/ThreadPool.lean index 8fef08936..b3be16a0a 100644 --- a/Iris/Iris/ProgramLogic/ThreadPool.lean +++ b/Iris/Iris/ProgramLogic/ThreadPool.lean @@ -18,6 +18,8 @@ open Language Language.Notation Relation FromMathlib.Relation.TransGen @[expose] public section +local stepindex Nat + variable {Expr State Obs Val : Type _} [Λ : Language Expr State Obs Val] /-! ### Multi-step prim reduction on a single thread -/ diff --git a/Iris/Iris/ProgramLogic/WeakestPre.lean b/Iris/Iris/ProgramLogic/WeakestPre.lean index 059a13a44..5f0c2e015 100644 --- a/Iris/Iris/ProgramLogic/WeakestPre.lean +++ b/Iris/Iris/ProgramLogic/WeakestPre.lean @@ -19,6 +19,8 @@ open ProgramLogic Language.Notation Std Iris.BI @[expose] public section +local stepindex Nat + /-! TODO: AddModal, ElimAcc instances -/ @@ -113,7 +115,7 @@ instance wp.pre.contractive s : OFE.Contractive (wp.pre s (ι := ι)) where @[rocq_alias wp_def] instance wp.def : Wp (IProp GF) (Expr) (Val) Stuckness where - wp s := fixpoint (wp.pre s) + wp s := fixpoint (SI := Nat) (wp.pre s) #rocq_ignore wp_aux "We do not use Iris' custom seal/unseal visibility control" #rocq_ignore wp' "We do not use Iris' custom seal/unseal visibility control" @@ -124,8 +126,8 @@ section Wp @[rocq_alias wp_unfold] theorem wp_unfold {s E} {e : Expr} {Φ : Val → IProp GF} : WP e @ s ; E {{ Φ }} ⊣⊢ wp.pre s (Wp.wp (PROP := IProp GF) s) E e Φ := - BI.equiv_iff.1 <| OFE.eq_dist.mpr <| - fun _n => (fixpoint_unfold (f := (wp.pre s).toContractiveHom)).dist E e Φ + BI.equiv_iff.1 <| OFE.eq_dist (SI := Nat) |>.mpr <| + fun _n => (fixpoint_unfold (f := (wp.pre s).toContractiveHom)).dist (SI := Nat) E e Φ @[rocq_alias wp_ne] instance wp_ne {s : Stuckness} {E} {e : Expr} : diff --git a/Iris/Iris/ProofMode.lean b/Iris/Iris/ProofMode.lean index 9ae274987..5f5acac33 100644 --- a/Iris/Iris/ProofMode.lean +++ b/Iris/Iris/ProofMode.lean @@ -16,3 +16,5 @@ public import Iris.ProofMode.InstancesUpdates public import Iris.ProofMode.Patterns public meta import Iris.ProofMode.Tactics public import Iris.ProofMode.UnifHints + +local stepindex Nat diff --git a/Iris/Iris/ProofMode/Classes.lean b/Iris/Iris/ProofMode/Classes.lean index e9c0b3176..ec97a0ba5 100644 --- a/Iris/Iris/ProofMode/Classes.lean +++ b/Iris/Iris/ProofMode/Classes.lean @@ -12,6 +12,8 @@ public import Iris.Std.Namespaces @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI @@ -138,7 +140,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 Nat A] (P : PROP) (x y : outParam A) where +class IntoInternalEq {PROP} [BI PROP] [Sbi PROP] {A : outParam $ Type _} [ofe : outParam $ OFE 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/ClassesMake.lean b/Iris/Iris/ProofMode/ClassesMake.lean index 246683754..5c28bccb3 100644 --- a/Iris/Iris/ProofMode/ClassesMake.lean +++ b/Iris/Iris/ProofMode/ClassesMake.lean @@ -10,6 +10,8 @@ public meta import Iris.ProofMode.SynthInstance @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI diff --git a/Iris/Iris/ProofMode/Display.lean b/Iris/Iris/ProofMode/Display.lean index 10cf597b5..256e0e030 100644 --- a/Iris/Iris/ProofMode/Display.lean +++ b/Iris/Iris/ProofMode/Display.lean @@ -10,6 +10,8 @@ public meta import Iris.ProofMode.Expr public meta import Lean.PrettyPrinter.Delaborator +local stepindex Nat + public meta section namespace Iris.ProofMode diff --git a/Iris/Iris/ProofMode/Expr.lean b/Iris/Iris/ProofMode/Expr.lean index 30573c2f9..951e2f905 100644 --- a/Iris/Iris/ProofMode/Expr.lean +++ b/Iris/Iris/ProofMode/Expr.lean @@ -11,6 +11,8 @@ public import Iris.ProofMode.Classes public import Iris.Std public meta import Iris.Std.Expr +local stepindex Nat + public meta section namespace Iris.ProofMode diff --git a/Iris/Iris/ProofMode/Instances.lean b/Iris/Iris/ProofMode/Instances.lean index eea57e00d..7a0a97810 100644 --- a/Iris/Iris/ProofMode/Instances.lean +++ b/Iris/Iris/ProofMode/Instances.lean @@ -17,6 +17,8 @@ public import Iris.ProofMode.Display @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI Iris.Std diff --git a/Iris/Iris/ProofMode/InstancesCmra.lean b/Iris/Iris/ProofMode/InstancesCmra.lean index 870b41917..35099f6dc 100644 --- a/Iris/Iris/ProofMode/InstancesCmra.lean +++ b/Iris/Iris/ProofMode/InstancesCmra.lean @@ -11,6 +11,8 @@ import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris diff --git a/Iris/Iris/ProofMode/InstancesEmbedding.lean b/Iris/Iris/ProofMode/InstancesEmbedding.lean index c4c36756a..6772e9173 100644 --- a/Iris/Iris/ProofMode/InstancesEmbedding.lean +++ b/Iris/Iris/ProofMode/InstancesEmbedding.lean @@ -11,6 +11,8 @@ public import Iris.ProofMode.ModalityInstances @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open BI diff --git a/Iris/Iris/ProofMode/InstancesFrame.lean b/Iris/Iris/ProofMode/InstancesFrame.lean index f239bd004..170ef9ce2 100644 --- a/Iris/Iris/ProofMode/InstancesFrame.lean +++ b/Iris/Iris/ProofMode/InstancesFrame.lean @@ -25,6 +25,8 @@ end @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Qq Iris.BI Iris.Std diff --git a/Iris/Iris/ProofMode/InstancesInternalEq.lean b/Iris/Iris/ProofMode/InstancesInternalEq.lean index 73ea4e2dc..bb85faf62 100644 --- a/Iris/Iris/ProofMode/InstancesInternalEq.lean +++ b/Iris/Iris/ProofMode/InstancesInternalEq.lean @@ -12,6 +12,8 @@ import Iris.Std.RocqPorting @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI Iris.Std @@ -20,30 +22,30 @@ section internalEq variable {PROP} [Sbi PROP] @[rocq_alias from_pure_internal_eq] -instance fromPure_internalEq [Sbi PROP] [OFE Nat A] (a b : A) : +instance fromPure_internalEq [Sbi PROP] [OFE 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 Nat A] (a b : A) +instance intoPure_internalEq [Sbi PROP] [OFE 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 Nat A] +instance (priority := default + 10) intoPure_internalEq_leibniz [Sbi PROP] [OFE 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 Nat A] (x y : A) : +instance fromModal_internalEq_next [Sbi PROP] [OFE 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 Nat A] (x y : A) +instance intoLaterN_internalEq_next [Sbi PROP] [OFE 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 +56,36 @@ instance intoLaterN_internalEq_next [Sbi PROP] [OFE Nat A] (x y : A) -- IntoInternalEq @[rocq_alias into_internal_eq_internal_eq] -instance intoInternalEq_internalEq [Sbi PROP] [OFE Nat A] (x y : A) : +instance intoInternalEq_internalEq [Sbi PROP] [OFE 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 Nat A] (x y : A) (P : PROP) +instance intoInternalEq_affinely [Sbi PROP] [OFE 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 Nat A] (x y : A) (P : PROP) +instance intoInternalEq_intuitionistically [Sbi PROP] [OFE 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 Nat A] (x y : A) (P : PROP) +instance intoInternalEq_absorbingly [Sbi PROP] [OFE 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 Nat A] (x y : A) (P : PROP) +instance intoInternalEq_plainly [Sbi PROP] [OFE 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 Nat A] (x y : A) (P : PROP) +instance intoInternalEq_persistently [Sbi PROP] [OFE 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/InstancesLater.lean b/Iris/Iris/ProofMode/InstancesLater.lean index 2d80151e8..4510cbd50 100644 --- a/Iris/Iris/ProofMode/InstancesLater.lean +++ b/Iris/Iris/ProofMode/InstancesLater.lean @@ -13,6 +13,8 @@ public import Iris.Std.TC @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI Iris.Std diff --git a/Iris/Iris/ProofMode/InstancesMake.lean b/Iris/Iris/ProofMode/InstancesMake.lean index d8e526e82..39a18a583 100644 --- a/Iris/Iris/ProofMode/InstancesMake.lean +++ b/Iris/Iris/ProofMode/InstancesMake.lean @@ -10,6 +10,8 @@ public import Iris.ProofMode.ClassesMake @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI diff --git a/Iris/Iris/ProofMode/InstancesPlainly.lean b/Iris/Iris/ProofMode/InstancesPlainly.lean index 23f464f52..889153671 100644 --- a/Iris/Iris/ProofMode/InstancesPlainly.lean +++ b/Iris/Iris/ProofMode/InstancesPlainly.lean @@ -12,6 +12,8 @@ public import Iris.Std.TC @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI Iris.Std diff --git a/Iris/Iris/ProofMode/InstancesUpdates.lean b/Iris/Iris/ProofMode/InstancesUpdates.lean index 34786e4ad..13ca02a09 100644 --- a/Iris/Iris/ProofMode/InstancesUpdates.lean +++ b/Iris/Iris/ProofMode/InstancesUpdates.lean @@ -14,6 +14,8 @@ public import Iris.ProofMode.Display @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI Iris.Std diff --git a/Iris/Iris/ProofMode/Modalities.lean b/Iris/Iris/ProofMode/Modalities.lean index ee2113fc7..5d307b979 100644 --- a/Iris/Iris/ProofMode/Modalities.lean +++ b/Iris/Iris/ProofMode/Modalities.lean @@ -9,6 +9,8 @@ public import Iris.BI @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI diff --git a/Iris/Iris/ProofMode/ModalityInstances.lean b/Iris/Iris/ProofMode/ModalityInstances.lean index 91c395d56..5c704d229 100644 --- a/Iris/Iris/ProofMode/ModalityInstances.lean +++ b/Iris/Iris/ProofMode/ModalityInstances.lean @@ -9,6 +9,8 @@ public import Iris.ProofMode.Classes @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI diff --git a/Iris/Iris/ProofMode/Patterns.lean b/Iris/Iris/ProofMode/Patterns.lean index a204abd27..86abc7380 100644 --- a/Iris/Iris/ProofMode/Patterns.lean +++ b/Iris/Iris/ProofMode/Patterns.lean @@ -5,3 +5,5 @@ public import Iris.ProofMode.Patterns.IntroPattern public import Iris.ProofMode.Patterns.ProofModeTerm public import Iris.ProofMode.Patterns.SelPattern public import Iris.ProofMode.Patterns.SpecPattern + +local stepindex Nat diff --git a/Iris/Iris/ProofMode/Patterns/IntroPattern.lean b/Iris/Iris/ProofMode/Patterns/IntroPattern.lean index c5e8506fd..e1eaf8bc1 100644 --- a/Iris/Iris/ProofMode/Patterns/IntroPattern.lean +++ b/Iris/Iris/ProofMode/Patterns/IntroPattern.lean @@ -12,6 +12,8 @@ public import Lean.Syntax @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Lean diff --git a/Iris/Iris/ProofMode/Patterns/SelPattern.lean b/Iris/Iris/ProofMode/Patterns/SelPattern.lean index 8449df66a..760a00671 100644 --- a/Iris/Iris/ProofMode/Patterns/SelPattern.lean +++ b/Iris/Iris/ProofMode/Patterns/SelPattern.lean @@ -9,6 +9,8 @@ public meta import Iris.ProofMode.ProofModeM @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Lean Meta Std diff --git a/Iris/Iris/ProofMode/ProofModeM.lean b/Iris/Iris/ProofMode/ProofModeM.lean index a021a13ed..f626c1e00 100644 --- a/Iris/Iris/ProofMode/ProofModeM.lean +++ b/Iris/Iris/ProofMode/ProofModeM.lean @@ -8,6 +8,8 @@ module public meta import Iris.ProofMode.Expr public import Iris.ProofMode.Classes +local stepindex Nat + public meta section namespace Iris.ProofMode diff --git a/Iris/Iris/ProofMode/SynthInstance.lean b/Iris/Iris/ProofMode/SynthInstance.lean index fa24d8ecc..842debf86 100644 --- a/Iris/Iris/ProofMode/SynthInstance.lean +++ b/Iris/Iris/ProofMode/SynthInstance.lean @@ -9,6 +9,8 @@ public import Qq public import Iris.BI public import Iris.ProofMode.SynthInstanceAttr +local stepindex Nat + public meta section /- diff --git a/Iris/Iris/ProofMode/Tactics.lean b/Iris/Iris/ProofMode/Tactics.lean index 274bacd90..345c9d887 100644 --- a/Iris/Iris/ProofMode/Tactics.lean +++ b/Iris/Iris/ProofMode/Tactics.lean @@ -29,3 +29,5 @@ public meta import Iris.ProofMode.Tactics.Rewrite public meta import Iris.ProofMode.Tactics.Specialize public meta import Iris.ProofMode.Tactics.Split public meta import Iris.ProofMode.Tactics.Trivial + +local stepindex Nat diff --git a/Iris/Iris/ProofMode/Tactics/Accu.lean b/Iris/Iris/ProofMode/Tactics/Accu.lean index 76c3d6dc1..4b0c6767a 100644 --- a/Iris/Iris/ProofMode/Tactics/Accu.lean +++ b/Iris/Iris/ProofMode/Tactics/Accu.lean @@ -7,6 +7,8 @@ module public meta import Iris.ProofMode.ProofModeM +local stepindex Nat + namespace Iris.ProofMode public meta section diff --git a/Iris/Iris/ProofMode/Tactics/Apply.lean b/Iris/Iris/ProofMode/Tactics/Apply.lean index dfaa859c8..667a234cb 100644 --- a/Iris/Iris/ProofMode/Tactics/Apply.lean +++ b/Iris/Iris/ProofMode/Tactics/Apply.lean @@ -11,6 +11,8 @@ meta import Iris.ProofMode.Patterns.ProofModeTerm meta import Iris.ProofMode.Tactics.Assumption public meta import Iris.ProofMode.Tactics.HaveCore +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Assumption.lean b/Iris/Iris/ProofMode/Tactics/Assumption.lean index 0302477b3..fa9f4b79c 100644 --- a/Iris/Iris/ProofMode/Tactics/Assumption.lean +++ b/Iris/Iris/ProofMode/Tactics/Assumption.lean @@ -9,6 +9,8 @@ import Iris.BI import Iris.ProofMode.Classes public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section open BI Std diff --git a/Iris/Iris/ProofMode/Tactics/Basic.lean b/Iris/Iris/ProofMode/Tactics/Basic.lean index 4b6a20b1d..9e588f787 100644 --- a/Iris/Iris/ProofMode/Tactics/Basic.lean +++ b/Iris/Iris/ProofMode/Tactics/Basic.lean @@ -10,6 +10,8 @@ meta import Iris.ProofMode.Expr meta import Iris.ProofMode.SynthInstance public meta import Iris.ProofMode.ProofModeM +local stepindex Nat + public meta section namespace Iris.ProofMode diff --git a/Iris/Iris/ProofMode/Tactics/Cases.lean b/Iris/Iris/ProofMode/Tactics/Cases.lean index 46bd4523d..bf52b6136 100644 --- a/Iris/Iris/ProofMode/Tactics/Cases.lean +++ b/Iris/Iris/ProofMode/Tactics/Cases.lean @@ -14,6 +14,8 @@ public meta import Iris.ProofMode.Tactics.Basic public meta import Iris.ProofMode.Tactics.HaveCore public meta import Iris.ProofMode.Tactics.Frame +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Clear.lean b/Iris/Iris/ProofMode/Tactics/Clear.lean index c111d5ab5..10f3bc093 100644 --- a/Iris/Iris/ProofMode/Tactics/Clear.lean +++ b/Iris/Iris/ProofMode/Tactics/Clear.lean @@ -10,6 +10,8 @@ import Iris.ProofMode.Classes public meta import Iris.ProofMode.Patterns.SelPattern public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Combine.lean b/Iris/Iris/ProofMode/Tactics/Combine.lean index 7fc64b1f8..48f954d15 100644 --- a/Iris/Iris/ProofMode/Tactics/Combine.lean +++ b/Iris/Iris/ProofMode/Tactics/Combine.lean @@ -10,6 +10,8 @@ public meta import Iris.ProofMode.Tactics.Cases public meta import Iris.ProofMode.Patterns.CasesPattern public meta import Iris.ProofMode.ClassesMake +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Eval.lean b/Iris/Iris/ProofMode/Tactics/Eval.lean index ea1693689..9d9529186 100644 --- a/Iris/Iris/ProofMode/Tactics/Eval.lean +++ b/Iris/Iris/ProofMode/Tactics/Eval.lean @@ -8,6 +8,8 @@ module public meta import Iris.ProofMode.Patterns.SelPattern public meta import Iris.ProofMode.ProofModeM +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/ExFalso.lean b/Iris/Iris/ProofMode/Tactics/ExFalso.lean index 3428c7fa1..22087e1b9 100644 --- a/Iris/Iris/ProofMode/Tactics/ExFalso.lean +++ b/Iris/Iris/ProofMode/Tactics/ExFalso.lean @@ -8,6 +8,8 @@ module import Iris.BI public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Exact.lean b/Iris/Iris/ProofMode/Tactics/Exact.lean index 664285558..fb5721468 100644 --- a/Iris/Iris/ProofMode/Tactics/Exact.lean +++ b/Iris/Iris/ProofMode/Tactics/Exact.lean @@ -7,6 +7,8 @@ module public meta import Iris.ProofMode.Tactics.Assumption +local stepindex Nat + namespace Iris.ProofMode public meta section diff --git a/Iris/Iris/ProofMode/Tactics/Exists.lean b/Iris/Iris/ProofMode/Tactics/Exists.lean index 2338658b4..49c195268 100644 --- a/Iris/Iris/ProofMode/Tactics/Exists.lean +++ b/Iris/Iris/ProofMode/Tactics/Exists.lean @@ -9,6 +9,8 @@ import Iris.BI import Iris.ProofMode.Classes public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Frame.lean b/Iris/Iris/ProofMode/Tactics/Frame.lean index 30a4e7dad..15ebded1c 100644 --- a/Iris/Iris/ProofMode/Tactics/Frame.lean +++ b/Iris/Iris/ProofMode/Tactics/Frame.lean @@ -10,6 +10,8 @@ import Iris.ProofMode.Classes public meta import Iris.ProofMode.Patterns.SelPattern public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Have.lean b/Iris/Iris/ProofMode/Tactics/Have.lean index abe101fdf..aa411c269 100644 --- a/Iris/Iris/ProofMode/Tactics/Have.lean +++ b/Iris/Iris/ProofMode/Tactics/Have.lean @@ -10,6 +10,8 @@ public meta import Iris.ProofMode.Patterns.CasesPattern public meta import Iris.ProofMode.Tactics.HaveCore public meta import Iris.ProofMode.Tactics.Cases +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/HaveCore.lean b/Iris/Iris/ProofMode/Tactics/HaveCore.lean index fdba78313..aa01408a1 100644 --- a/Iris/Iris/ProofMode/Tactics/HaveCore.lean +++ b/Iris/Iris/ProofMode/Tactics/HaveCore.lean @@ -11,6 +11,8 @@ public meta import Iris.ProofMode.Patterns.ProofModeTerm public meta import Iris.ProofMode.Tactics.Basic public meta import Iris.ProofMode.Tactics.Specialize +local stepindex Nat + /- This file contains the `iHave` function for asserting a ProofModeTerm. It is separate from the implementation of `ihave` in `Have.lean` since the `ihave` tactic in (`Have.lean`) depends on `Cases.lean`, which in turn diff --git a/Iris/Iris/ProofMode/Tactics/Induction.lean b/Iris/Iris/ProofMode/Tactics/Induction.lean index de8fbacd6..40db8dbe7 100644 --- a/Iris/Iris/ProofMode/Tactics/Induction.lean +++ b/Iris/Iris/ProofMode/Tactics/Induction.lean @@ -14,6 +14,8 @@ public meta import Iris.ProofMode.Tactics.RevertIntro public meta import Iris.ProofMode.Tactics.Revert public meta import Lean.Meta.Tactic.TryThis +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Intro.lean b/Iris/Iris/ProofMode/Tactics/Intro.lean index 8e9d62d66..51dd9e4db 100644 --- a/Iris/Iris/ProofMode/Tactics/Intro.lean +++ b/Iris/Iris/ProofMode/Tactics/Intro.lean @@ -11,6 +11,8 @@ public meta import Iris.ProofMode.Tactics.Pure public meta import Iris.ProofMode.Tactics.ModIntro public meta import Iris.ProofMode.Tactics.Trivial +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Inv.lean b/Iris/Iris/ProofMode/Tactics/Inv.lean index 38b1ebd57..446ac429a 100644 --- a/Iris/Iris/ProofMode/Tactics/Inv.lean +++ b/Iris/Iris/ProofMode/Tactics/Inv.lean @@ -13,6 +13,8 @@ public meta import Iris.ProofMode.Patterns.IntroPattern public meta import Iris.ProofMode.Patterns.SelPattern public meta import Iris.ProofMode.ClassesMake +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/LeftRight.lean b/Iris/Iris/ProofMode/Tactics/LeftRight.lean index 32fdbaa6a..23beaa69c 100644 --- a/Iris/Iris/ProofMode/Tactics/LeftRight.lean +++ b/Iris/Iris/ProofMode/Tactics/LeftRight.lean @@ -9,6 +9,8 @@ import Iris.BI import Iris.ProofMode.Classes public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Loeb.lean b/Iris/Iris/ProofMode/Tactics/Loeb.lean index f3c2fe820..059720972 100644 --- a/Iris/Iris/ProofMode/Tactics/Loeb.lean +++ b/Iris/Iris/ProofMode/Tactics/Loeb.lean @@ -8,6 +8,8 @@ module public import Iris.ProofMode.Tactics.Revert public import Iris.ProofMode.Tactics.RevertIntro +local stepindex Nat + namespace Iris.ProofMode open Lean Meta Elab.Tactic Qq diff --git a/Iris/Iris/ProofMode/Tactics/Mod.lean b/Iris/Iris/ProofMode/Tactics/Mod.lean index 46c9c3b85..d6727a1e8 100644 --- a/Iris/Iris/ProofMode/Tactics/Mod.lean +++ b/Iris/Iris/ProofMode/Tactics/Mod.lean @@ -9,6 +9,8 @@ import Iris.BI public import Iris.ProofMode.Classes public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/ModIntro.lean b/Iris/Iris/ProofMode/Tactics/ModIntro.lean index 7a1efb109..da0af4089 100644 --- a/Iris/Iris/ProofMode/Tactics/ModIntro.lean +++ b/Iris/Iris/ProofMode/Tactics/ModIntro.lean @@ -8,6 +8,8 @@ module import Iris.ProofMode.Modalities public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Pure.lean b/Iris/Iris/ProofMode/Tactics/Pure.lean index 2d4e3e006..ae5fa6293 100644 --- a/Iris/Iris/ProofMode/Tactics/Pure.lean +++ b/Iris/Iris/ProofMode/Tactics/Pure.lean @@ -7,6 +7,8 @@ module public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Rename.lean b/Iris/Iris/ProofMode/Tactics/Rename.lean index 875664339..249602438 100644 --- a/Iris/Iris/ProofMode/Tactics/Rename.lean +++ b/Iris/Iris/ProofMode/Tactics/Rename.lean @@ -7,6 +7,8 @@ module public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public meta section diff --git a/Iris/Iris/ProofMode/Tactics/Revert.lean b/Iris/Iris/ProofMode/Tactics/Revert.lean index 704529f9b..63e82402e 100644 --- a/Iris/Iris/ProofMode/Tactics/Revert.lean +++ b/Iris/Iris/ProofMode/Tactics/Revert.lean @@ -14,6 +14,8 @@ public meta import Iris.ProofMode.Tactics.Cases public meta import Iris.ProofMode.Patterns.CasesPattern public meta import Lean.Meta.Tactic.TryThis +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/RevertIntro.lean b/Iris/Iris/ProofMode/Tactics/RevertIntro.lean index 8fa5b36da..f1d307b5f 100644 --- a/Iris/Iris/ProofMode/Tactics/RevertIntro.lean +++ b/Iris/Iris/ProofMode/Tactics/RevertIntro.lean @@ -7,6 +7,8 @@ module public import Iris.ProofMode.Tactics.Intro public import Iris.ProofMode.Tactics.Revert +local stepindex Nat + namespace Iris.ProofMode open Lean Meta Elab.Tactic Qq diff --git a/Iris/Iris/ProofMode/Tactics/Rewrite.lean b/Iris/Iris/ProofMode/Tactics/Rewrite.lean index 03bdfb20a..0e26f6b38 100644 --- a/Iris/Iris/ProofMode/Tactics/Rewrite.lean +++ b/Iris/Iris/ProofMode/Tactics/Rewrite.lean @@ -13,12 +13,14 @@ public meta import Iris.ProofMode.Patterns.ProofModeTerm public meta import Iris.ProofMode.Tactics.HaveCore meta import Lean.Parser.Tactic +local stepindex Nat + namespace Iris.ProofMode public section open BI Std -theorem rewrite_tac [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE Nat A] {a b : A} {p} +theorem rewrite_tac [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE 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 +32,7 @@ theorem rewrite_tac [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE Nat A] {a b : A _ ⊢ Ψ 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 Nat A] {a b : A} {p} +theorem rewrite_tac_symm [Sbi PROP] {P P' Q : PROP} {A : Type _} [OFE 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 +130,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 Nat $A) ← mkFreshExprMVarQ q(OFE Nat $A) + let _ofe : Q(OFE $A) ← mkFreshExprMVarQ q(OFE $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/ProofMode/Tactics/Specialize.lean b/Iris/Iris/ProofMode/Tactics/Specialize.lean index 9f6b0fb2d..f084c7afc 100644 --- a/Iris/Iris/ProofMode/Tactics/Specialize.lean +++ b/Iris/Iris/ProofMode/Tactics/Specialize.lean @@ -11,6 +11,8 @@ public meta import Iris.ProofMode.Tactics.Basic public import Iris.ProofMode.Tactics.Trivial public import Iris.ProofMode.Tactics.Frame +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Split.lean b/Iris/Iris/ProofMode/Tactics/Split.lean index 41986e1c2..0907e3ae3 100644 --- a/Iris/Iris/ProofMode/Tactics/Split.lean +++ b/Iris/Iris/ProofMode/Tactics/Split.lean @@ -9,6 +9,8 @@ import Iris.BI import Iris.ProofMode.Classes public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public section diff --git a/Iris/Iris/ProofMode/Tactics/Trivial.lean b/Iris/Iris/ProofMode/Tactics/Trivial.lean index d4bc61d80..91810ae2b 100644 --- a/Iris/Iris/ProofMode/Tactics/Trivial.lean +++ b/Iris/Iris/ProofMode/Tactics/Trivial.lean @@ -9,6 +9,8 @@ import Iris.BI public import Iris.ProofMode.Classes public meta import Iris.ProofMode.Tactics.Basic +local stepindex Nat + namespace Iris.ProofMode public meta section diff --git a/Iris/Iris/ProofMode/UnifHints.lean b/Iris/Iris/ProofMode/UnifHints.lean index f3a5fa1b7..2700ab582 100644 --- a/Iris/Iris/ProofMode/UnifHints.lean +++ b/Iris/Iris/ProofMode/UnifHints.lean @@ -9,6 +9,8 @@ public import Iris.BI @[expose] public section +local stepindex Nat + namespace Iris.ProofMode open Iris.BI diff --git a/Iris/Iris/Tests.lean b/Iris/Iris/Tests.lean index 9c46a845a..280b5a36c 100644 --- a/Iris/Iris/Tests.lean +++ b/Iris/Iris/Tests.lean @@ -7,3 +7,5 @@ public import Iris.Tests.Tactics public import Iris.Tests.HeapLang public import Iris.Tests.Language public import Iris.Tests.WeakestPre + +local stepindex Nat diff --git a/Iris/Iris/Tests/HeapLang.lean b/Iris/Iris/Tests/HeapLang.lean index 2acd7f17e..30cbead40 100644 --- a/Iris/Iris/Tests/HeapLang.lean +++ b/Iris/Iris/Tests/HeapLang.lean @@ -4,3 +4,5 @@ public import Iris.Tests.HeapLang.Notation public import Iris.Tests.HeapLang.WeakestPre public import Iris.Tests.HeapLang.HeapTactics public import Iris.Tests.HeapLang.Linter + +local stepindex Nat diff --git a/Iris/Iris/Tests/HeapLang/HeapTactics.lean b/Iris/Iris/Tests/HeapLang/HeapTactics.lean index 20d83276c..f144f5522 100644 --- a/Iris/Iris/Tests/HeapLang/HeapTactics.lean +++ b/Iris/Iris/Tests/HeapLang/HeapTactics.lean @@ -12,6 +12,8 @@ public import Iris.HeapLang.ProofMode public import Iris.HeapLang.Instances public import Iris.ProgramLogic.WeakestPre +local stepindex Nat + /-! Tests for the heap-operation tactics (`wp_load`, ...). Unlike the tests in `Tests.HeapLang.WeakestPre`, these need the `IrisGS_gen` instance to be the one derived from `HeapLangGS`, so no generic `IrisGS_gen` variable is in scope. -/ diff --git a/Iris/Iris/Tests/HeapLang/Linter.lean b/Iris/Iris/Tests/HeapLang/Linter.lean index ba4d0fd07..56d87b35a 100644 --- a/Iris/Iris/Tests/HeapLang/Linter.lean +++ b/Iris/Iris/Tests/HeapLang/Linter.lean @@ -7,6 +7,8 @@ module public import Iris.HeapLang @[expose] public section + +local stepindex Nat namespace Iris.Tests.HeapLang.Linter open Iris.HeapLang diff --git a/Iris/Iris/Tests/HeapLang/Notation.lean b/Iris/Iris/Tests/HeapLang/Notation.lean index 219433cd7..d4f5add33 100644 --- a/Iris/Iris/Tests/HeapLang/Notation.lean +++ b/Iris/Iris/Tests/HeapLang/Notation.lean @@ -7,6 +7,8 @@ module public import Iris.HeapLang @[expose] public section + +local stepindex Nat namespace Iris.Tests.HeapLang open Iris.HeapLang diff --git a/Iris/Iris/Tests/HeapLang/WeakestPre.lean b/Iris/Iris/Tests/HeapLang/WeakestPre.lean index 62477bfb5..772cb7e1b 100644 --- a/Iris/Iris/Tests/HeapLang/WeakestPre.lean +++ b/Iris/Iris/Tests/HeapLang/WeakestPre.lean @@ -12,6 +12,8 @@ public import Iris.HeapLang.ProofMode public import Iris.HeapLang.Instances public import Iris.ProgramLogic.WeakestPre +local stepindex Nat + namespace Iris.HeapLang variable {hlc} {GF : BundledGFunctors} [ι : IrisGS_gen hlc HeapLang.Exp GF] diff --git a/Iris/Iris/Tests/Instances.lean b/Iris/Iris/Tests/Instances.lean index 882876713..ead216e79 100644 --- a/Iris/Iris/Tests/Instances.lean +++ b/Iris/Iris/Tests/Instances.lean @@ -12,6 +12,8 @@ public import Iris.ProofMode.InstancesMake @[expose] public section +local stepindex Nat + namespace Iris.Tests open Lean Qq BI ProofMode diff --git a/Iris/Iris/Tests/InstancesImport.lean b/Iris/Iris/Tests/InstancesImport.lean index 61db2f808..e369c3381 100644 --- a/Iris/Iris/Tests/InstancesImport.lean +++ b/Iris/Iris/Tests/InstancesImport.lean @@ -11,6 +11,8 @@ import Iris.Tests.Instances @[expose] public section +local stepindex Nat + namespace Iris.Tests open Lean Qq BI ProofMode diff --git a/Iris/Iris/Tests/Language.lean b/Iris/Iris/Tests/Language.lean index 28afb5ec5..b9a1b7e3e 100644 --- a/Iris/Iris/Tests/Language.lean +++ b/Iris/Iris/Tests/Language.lean @@ -8,6 +8,8 @@ public import Iris.ProgramLogic.Language @[expose] public section +local stepindex Nat + namespace Iris.Tests open Iris ProgramLogic Language Notation diff --git a/Iris/Iris/Tests/Notation.lean b/Iris/Iris/Tests/Notation.lean index 8fe4bb166..841d63aa4 100644 --- a/Iris/Iris/Tests/Notation.lean +++ b/Iris/Iris/Tests/Notation.lean @@ -10,6 +10,8 @@ public import Iris.BI.Updates @[expose] public section +local stepindex Nat + namespace Iris.Tests open Iris.BI diff --git a/Iris/Iris/Tests/StepIndexRegistry.lean b/Iris/Iris/Tests/StepIndexRegistry.lean index d927303a6..02944b8b3 100644 --- a/Iris/Iris/Tests/StepIndexRegistry.lean +++ b/Iris/Iris/Tests/StepIndexRegistry.lean @@ -19,12 +19,24 @@ namespace Iris.Tests #guard_msgs in example : Type := by infer_stepindex +-- Test the error from `stepindex%` when no index is declared + +/-- error: stepindex%: no step index in scope; declare one with `local stepindex T` -/ +#guard_msgs in +#check (stepindex% : Type) + local stepindex Nat /-- info: Nat -/ #guard_msgs in #stepindex? +-- Test that `stepindex%` resolves eagerly to a global constant + +/-- info: Nat : Type -/ +#guard_msgs in +#check (stepindex% : Type) + /-- info: Nat : Type -/ #guard_msgs in #check (by infer_stepindex : Type) @@ -41,6 +53,12 @@ local stepindex SI #guard_msgs in #check (by infer_stepindex : Type) +-- Test that `stepindex%` also resolves to a section variable + +/-- info: SI : Type -/ +#guard_msgs in +#check (stepindex% : Type) + def sectionIndex : Type := by infer_stepindex /-- info: @sectionIndex : {SI : Type} → Type -/ @@ -216,4 +234,38 @@ example : Type := by infer_stepindex end +section EagerVsLate +local stepindex Nat + +class TD (α : Type) (SI : Type) where d : SI → α → α → Prop +instance : TD Nat Nat := ⟨fun _ _ _ => True⟩ +instance {n : Nat} : Trans (TD.d (α := Nat) (SI := Nat) n) (TD.d (α := Nat) (SI := Nat) n) + (TD.d (α := Nat) (SI := Nat) n) := ⟨fun _ _ => trivial⟩ + +notation:40 x " ~[" k "]~ " y:41 => TD.d (SI := stepindex%) k x y +notation:40 x " ~?[" k "]~ " y:41 => TD.d (SI := by infer_stepindex) k x y + +-- Test that an eagerly resolved index can be used in `calc`: `Trans` needs the index during +-- elaboration, so this is the property that `stepindex%` exists to provide + +example (a b c : Nat) (n : Nat) (h1 : a ~[n]~ b) (h2 : b ~[n]~ c) : a ~[n]~ c := calc + a ~[n]~ b := h1 + _ ~[n]~ c := h2 + +-- Test that the tactic form cannot: a `by` block is a synthetic *opaque* metavariable, so +-- `Trans` is unresolvable even though `n : Nat`. Guards the two against being swapped. + +/-- +error: invalid 'calc' step, failed to synthesize `Trans` instance + Trans (TD.d ?m.16) (TD.d ?m.22) ?m.25 + +Hint: Additional diagnostic information may be available using the `set_option diagnostics true` command. +-/ +#guard_msgs in +example (a b c : Nat) (n : Nat) (h1 : a ~?[n]~ b) (h2 : b ~?[n]~ c) : a ~?[n]~ c := calc + a ~?[n]~ b := h1 + _ ~?[n]~ c := h2 + +end EagerVsLate + end Iris.Tests diff --git a/Iris/Iris/Tests/Tactics.lean b/Iris/Iris/Tests/Tactics.lean index e853d0acf..7bfc1a2a4 100644 --- a/Iris/Iris/Tests/Tactics.lean +++ b/Iris/Iris/Tests/Tactics.lean @@ -19,6 +19,8 @@ public import Iris.ProgramLogic.WeakestPre @[expose] public section +local stepindex Nat + namespace Iris.Tests open BI CMRA DFrac CancelableInvariant NonAtomicInvariant ProgramLogic @@ -2338,7 +2340,7 @@ end inext section irewrite variable {PROP : Type _} [Sbi PROP] -variable {A B : Type _} [OFE Nat A] [OFE Nat B] +variable {A B : Type _} [OFE A] [OFE B] /- Tests `irewrite` rewriting in goal -/ example (a b : A) (P : A → PROP) [OFE.NonExpansive P] [Absorbing (P a)] : diff --git a/Iris/Iris/Tests/Updates.lean b/Iris/Iris/Tests/Updates.lean index 70a227b61..408b46362 100644 --- a/Iris/Iris/Tests/Updates.lean +++ b/Iris/Iris/Tests/Updates.lean @@ -6,6 +6,8 @@ module public import Iris.BI.Updates +local stepindex Nat + open Iris variable [BI PROP] [BUpd PROP] [FUpd PROP] (P Q : PROP) (E₁ E₂ : CoPset) diff --git a/Iris/Iris/Tests/WeakestPre.lean b/Iris/Iris/Tests/WeakestPre.lean index 71874d0b1..1bbb14e12 100644 --- a/Iris/Iris/Tests/WeakestPre.lean +++ b/Iris/Iris/Tests/WeakestPre.lean @@ -9,6 +9,8 @@ public import Iris.HeapLang @[expose] public section +local stepindex Nat + namespace Iris.Tests open Iris From 400d6ba8eaecb0d78ba9d222e5958803ead89b3e Mon Sep 17 00:00:00 2001 From: Markus de Medeiros Date: Wed, 5 Aug 2026 17:47:49 -0400 Subject: [PATCH 36/37] update --- Iris/Iris/Algebra/StepIndexRegistry.lean | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Iris/Iris/Algebra/StepIndexRegistry.lean b/Iris/Iris/Algebra/StepIndexRegistry.lean index 096eec0fb..7eb94088a 100644 --- a/Iris/Iris/Algebra/StepIndexRegistry.lean +++ b/Iris/Iris/Algebra/StepIndexRegistry.lean @@ -38,12 +38,6 @@ required to be scoped as either `local` or `scoped`: `global` indices are not pe /-- `stepindex%` elaborates to the step index type in scope, resolved **eagerly** as a term. - -Unlike the `infer_stepindex` tactic this introduces no metavariable. A `by` block becomes a -synthetic *opaque* metavariable that is only solved once elaboration is otherwise finished, so -instance resolution that needs the index — `Trans` for `calc`, `CoeFun` to apply a morphism, -projections on a `Dist` hypothesis — never gets to see it. Resolving here instead makes the -index concrete from the start. -/ @[expose] elab "stepindex%" : term => do let n := siExt.getState (← getEnv) From f4fc42dab04262b1690a600ace10cea91d0bb1cd Mon Sep 17 00:00:00 2001 From: Markus de Medeiros Date: Wed, 5 Aug 2026 17:49:19 -0400 Subject: [PATCH 37/37] update --- 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 e60fd04dd..85cfc6349 100644 --- a/Iris/Iris/Algebra/OFE.lean +++ b/Iris/Iris/Algebra/OFE.lean @@ -1,7 +1,7 @@ /- Copyright (c) 2023 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. -Authors: Mario Carneiro, Sebastian Graf, Sergei Stepanenko +Authors: Mario Carneiro, Sebastian Graf, Sergei Stepanenko, Markus de Medeiros -/ module